diff options
Diffstat (limited to 'src/newgrf_config.cpp')
-rw-r--r-- | src/newgrf_config.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index ea5a68c39..41be0c1c0 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -17,6 +17,7 @@ #include "network/network_func.h" #include "gfx_func.h" #include "newgrf_text.h" +#include "window_func.h" #include "fileio_func.h" #include "fios.h" @@ -196,6 +197,35 @@ GRFParameterInfo::~GRFParameterInfo() } /** + * Get the value of this user-changeable parameter from the given config. + * @param config The GRFConfig to get the value from. + * @return The value of this parameter. + */ +uint32 GRFParameterInfo::GetValue(struct GRFConfig *config) const +{ + /* GB doesn't work correctly with nbits == 32, so handle that case here. */ + if (this->num_bit == 32) return config->param[this->param_nr]; + return GB(config->param[this->param_nr], this->first_bit, this->num_bit); +} + +/** + * Set the value of this user-changeable parameter in the given config. + * @param config The GRFConfig to set the value in. + * @param value The new value. + */ +void GRFParameterInfo::SetValue(struct GRFConfig *config, uint32 value) +{ + /* SB doesn't work correctly with nbits == 32, so handle that case here. */ + if (this->num_bit == 32) { + config->param[this->param_nr] = value; + } else { + SB(config->param[this->param_nr], this->first_bit, this->num_bit, value); + } + config->num_params = max<uint>(config->num_params, this->param_nr + 1); + SetWindowClassesDirty(WC_GAME_OPTIONS); // Is always the newgrf window +} + +/** * 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 |