Index: src/newgrf.cpp =================================================================== --- src/newgrf.cpp (Revision 24958) +++ src/newgrf.cpp (Arbeitskopie) @@ -48,6 +48,7 @@ #include "vehicle_func.h" #include "language.h" #include "vehicle_base.h" +#include "core/random_func.hpp" #include "table/strings.h" #include "table/build_industry.h" @@ -70,6 +71,9 @@ /** 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */ static uint32 _ttdpatch_flags[8]; +/** Randomizer for GRF-local random bits */ +static Randomizer _grf_randomizer; + /** Indicates which are the newgrf features currently loaded ingame */ GRFLoadedFeatures _loaded_newgrf_features; @@ -5737,6 +5741,14 @@ *value = _cur_year; return true; + case 0x26: // global random bits + *value = _settings_game.game_creation.generation_seed; + return true; + + case 0x27: // local random bits + *value = grffile->random_bits; + return true; + default: return false; } } @@ -7883,6 +7895,12 @@ } } +/** Reset the randomizer */ +static void ResetRandomizer() +{ + _grf_randomizer.SetSeed(_settings_game.game_creation.generation_seed); +} + /** Reset and clear all NewGRFs */ static void ResetNewGRF() { @@ -7975,6 +7993,9 @@ /* Reset the snowline table. */ ClearSnowLine(); + /* Reset the randomizer */ + ResetRandomizer(); + /* Reset NewGRF files */ ResetNewGRF(); @@ -8083,6 +8104,9 @@ * 'Uninitialised' parameters are zeroed as that is their default value when dynamically creating them. */ assert_compile(lengthof(this->param) == lengthof(config->param) && lengthof(this->param) == 0x80); + /* Set the random bits */ + this->random_bits = _grf_randomizer.Next(); + assert(config->num_params <= lengthof(config->param)); this->param_end = config->num_params; if (this->param_end > 0) { Index: src/newgrf.h =================================================================== --- src/newgrf.h (Revision 24958) +++ src/newgrf.h (Arbeitskopie) @@ -137,6 +137,7 @@ uint32 grf_features; ///< Bitset of GrfSpecFeature the grf uses PriceMultipliers price_base_multipliers; ///< Price base multipliers as set by the grf. + uint32 random_bits; ///< Local random bits of this grf GRFFile(const struct GRFConfig *config); ~GRFFile();