summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-07-31 09:35:49 +0000
committeryexo <yexo@openttd.org>2010-07-31 09:35:49 +0000
commit75c4a2d2fb4c400eb2eef6e1e1fa1bf3573c5be0 (patch)
tree62647c7494da5efbff57de09eab31dda31ecad18
parent897818c198944e22c0df4fb132f28a8d2b2f32bb (diff)
downloadopenttd-75c4a2d2fb4c400eb2eef6e1e1fa1bf3573c5be0.tar.xz
(svn r20251) -Add: [NewGRF] allow grfs to specify the number of valid parameters
-rw-r--r--src/newgrf.cpp13
-rw-r--r--src/newgrf_config.cpp4
-rw-r--r--src/newgrf_config.h1
3 files changed, 17 insertions, 1 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 60ede9a40..5b967d5ea 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -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()
};
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 74c526b93..d7769a394 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -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));
diff --git a/src/newgrf_config.h b/src/newgrf_config.h
index 58e29afec..56131e766 100644
--- a/src/newgrf_config.h
+++ b/src/newgrf_config.h
@@ -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