summaryrefslogtreecommitdiff
path: root/src/newgrf_config.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-07-31 09:51:04 +0000
committeryexo <yexo@openttd.org>2010-07-31 09:51:04 +0000
commitd6eab96a220a9e3c896a4e78831228992446efd5 (patch)
tree574e07278c034fb635ee5e1cb39a2e2fdf0d3abc /src/newgrf_config.cpp
parent4a4f02dc81083b9de6665018ffb06d87b3bfd35e (diff)
downloadopenttd-d6eab96a220a9e3c896a4e78831228992446efd5.tar.xz
(svn r20255) -Add: allow NewGRFs to specify static info about their user-changeable parameters
Diffstat (limited to 'src/newgrf_config.cpp')
-rw-r--r--src/newgrf_config.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 6bdf5117d..ea5a68c39 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -51,6 +51,13 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
this->name = DuplicateGRFText(config.name);
this->info = DuplicateGRFText(config.info);
if (config.error != NULL) this->error = new GRFError(*config.error);
+ for (uint i = 0; i < config.param_info.Length(); i++) {
+ if (config.param_info[i] == NULL) {
+ *this->param_info.Append() = NULL;
+ } else {
+ *this->param_info.Append() = new GRFParameterInfo(*config.param_info[i]);
+ }
+ }
}
/** Cleanup a GRFConfig object. */
@@ -63,6 +70,8 @@ GRFConfig::~GRFConfig()
delete this->error;
}
CleanUpGRFText(this->name);
+
+ for (uint i = 0; i < this->param_info.Length(); i++) delete this->param_info[i];
}
/**
@@ -140,6 +149,53 @@ GRFError::~GRFError()
}
/**
+ * Create a new empty GRFParameterInfo object.
+ * @param nr The newgrf parameter that is changed.
+ */
+GRFParameterInfo::GRFParameterInfo(uint nr) :
+ name(NULL),
+ desc(NULL),
+ type(PTYPE_UINT_ENUM),
+ min_value(0),
+ max_value(UINT32_MAX),
+ param_nr(nr),
+ first_bit(0),
+ num_bit(32)
+{}
+
+/**
+ * Create a new GRFParameterInfo object that is a deep copy of an existing
+ * parameter info object.
+ * @param info The GRFParameterInfo object to make a copy of.
+ */
+GRFParameterInfo::GRFParameterInfo(GRFParameterInfo &info) :
+ name(DuplicateGRFText(info.name)),
+ desc(DuplicateGRFText(info.desc)),
+ type(info.type),
+ min_value(info.min_value),
+ max_value(info.max_value),
+ param_nr(info.param_nr),
+ first_bit(info.first_bit),
+ num_bit(info.num_bit)
+{
+ for (uint i = 0; i < info.value_names.Length(); i++) {
+ SmallPair<uint32, GRFText *> *data = info.value_names.Get(i);
+ this->value_names.Insert(data->first, DuplicateGRFText(data->second));
+ }
+}
+
+/** Cleanup all parameter info. */
+GRFParameterInfo::~GRFParameterInfo()
+{
+ CleanUpGRFText(this->name);
+ CleanUpGRFText(this->desc);
+ for (uint i = 0; i < this->value_names.Length(); i++) {
+ SmallPair<uint32, GRFText *> *data = this->value_names.Get(i);
+ CleanUpGRFText(data->second);
+ }
+}
+
+/**
* Update the palettes of the graphics from the config file.
* This is needed because the config file gets read and parsed
* before the palette is chosen (one can configure the base