mirror of https://github.com/OpenTTD/OpenTTD
(svn r20251) -Add: [NewGRF] allow grfs to specify the number of valid parameters
parent
897818c198
commit
75c4a2d2fb
|
@ -5919,6 +5919,18 @@ static bool ChangeGRFDescription(byte langid, const char *str)
|
||||||
return true;
|
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 (*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 (*TextHandler)(byte, const char *str); ///< Type of callback function for text nodes
|
||||||
typedef bool (*BranchHandler)(ByteReader *); ///< Type of callback function for branch nodes
|
typedef bool (*BranchHandler)(ByteReader *); ///< Type of callback function for branch nodes
|
||||||
|
@ -6005,6 +6017,7 @@ struct AllowedSubtags {
|
||||||
AllowedSubtags _tags_info[] = {
|
AllowedSubtags _tags_info[] = {
|
||||||
AllowedSubtags('NAME', ChangeGRFName),
|
AllowedSubtags('NAME', ChangeGRFName),
|
||||||
AllowedSubtags('DESC', ChangeGRFDescription),
|
AllowedSubtags('DESC', ChangeGRFDescription),
|
||||||
|
AllowedSubtags('NPAR', ChangeGRFNumUsedParams),
|
||||||
AllowedSubtags()
|
AllowedSubtags()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
* @param filename Set the filename of this GRFConfig to filename. The argument
|
* @param filename Set the filename of this GRFConfig to filename. The argument
|
||||||
* is copied so the original string isn't needed after the constructor.
|
* 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);
|
if (filename != NULL) this->filename = strdup(filename);
|
||||||
}
|
}
|
||||||
|
@ -41,6 +42,7 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
|
||||||
status(config.status),
|
status(config.status),
|
||||||
grf_bugs(config.grf_bugs),
|
grf_bugs(config.grf_bugs),
|
||||||
num_params(config.num_params),
|
num_params(config.num_params),
|
||||||
|
num_valid_params(config.num_valid_params),
|
||||||
windows_paletted(config.windows_paletted)
|
windows_paletted(config.windows_paletted)
|
||||||
{
|
{
|
||||||
MemCpyT<uint8>(this->original_md5sum, config.original_md5sum, lengthof(this->original_md5sum));
|
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 grf_bugs; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
|
||||||
uint32 param[0x80]; ///< GRF parameters
|
uint32 param[0x80]; ///< GRF parameters
|
||||||
uint8 num_params; ///< Number of used 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
|
bool windows_paletted; ///< Whether the NewGRF is Windows paletted or not
|
||||||
|
|
||||||
struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
|
struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
|
||||||
|
|
Loading…
Reference in New Issue