(svn r20251) -Add: [NewGRF] allow grfs to specify the number of valid parameters

pull/155/head
yexo 14 years ago
parent 15976c5deb
commit eacf65598f

@ -5919,6 +5919,18 @@ static bool ChangeGRFDescription(byte langid, const char *str)
return true;
}
/** Callback function for 'INFO'->'NPAR' to set the number of valid parameters. */
static bool ChangeGRFNumUsedParams(size_t len, ByteReader *buf)
{
if (len != 1) {
grfmsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got " PRINTF_SIZE ", ignoring this field", len);
buf->Skip(len);
} else {
_cur_grfconfig->num_valid_params = min(buf->ReadByte(), lengthof(_cur_grfconfig->param));
}
return true;
}
typedef bool (*DataHandler)(size_t, ByteReader *); ///< Type of callback function for binary nodes
typedef bool (*TextHandler)(byte, const char *str); ///< Type of callback function for text nodes
typedef bool (*BranchHandler)(ByteReader *); ///< Type of callback function for branch nodes
@ -6005,6 +6017,7 @@ struct AllowedSubtags {
AllowedSubtags _tags_info[] = {
AllowedSubtags('NAME', ChangeGRFName),
AllowedSubtags('DESC', ChangeGRFDescription),
AllowedSubtags('NPAR', ChangeGRFNumUsedParams),
AllowedSubtags()
};

@ -26,7 +26,8 @@
* @param filename Set the filename of this GRFConfig to filename. The argument
* is copied so the original string isn't needed after the constructor.
*/
GRFConfig::GRFConfig(const char *filename)
GRFConfig::GRFConfig(const char *filename) :
num_valid_params(lengthof(param))
{
if (filename != NULL) this->filename = strdup(filename);
}
@ -41,6 +42,7 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
status(config.status),
grf_bugs(config.grf_bugs),
num_params(config.num_params),
num_valid_params(config.num_valid_params),
windows_paletted(config.windows_paletted)
{
MemCpyT<uint8>(this->original_md5sum, config.original_md5sum, lengthof(this->original_md5sum));

@ -99,6 +99,7 @@ struct GRFConfig : ZeroedMemoryAllocator {
uint32 grf_bugs; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
uint32 param[0x80]; ///< GRF parameters
uint8 num_params; ///< Number of used parameters
uint8 num_valid_params; ///< Number of valid parameters (action 0x14)
bool windows_paletted; ///< Whether the NewGRF is Windows paletted or not
struct GRFConfig *next; ///< NOSAVE: Next item in the linked list

Loading…
Cancel
Save