diff --git a/src/command.cpp b/src/command.cpp index 23f7f31046..4f0cd2942a 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -29,6 +29,7 @@ #include "newgrf_text.h" #include "string_func.h" #include "scope_info.h" +#include "core/random_func.hpp" #include #include "table/strings.h" @@ -921,6 +922,8 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0; + GameRandomSeedChecker random_state; + /* Test the command. */ _cleared_object_areas.clear(); SetTownRatingTestMode(true); @@ -929,6 +932,11 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, BasePersistentStorageArray::SwitchMode(PSM_LEAVE_TESTMODE); SetTownRatingTestMode(false); + if (!random_state.Check()) { + DEBUG(desync, 0, "Random seed changed in test command: date{%08x; %02x; %02x}; company: %02x; tile: %06x (%u x %u); p1: %08x; p2: %08x; cmd: %08x; \"%s\" %X (%s)", + _date, _date_fract, _tick_skip_counter, (int)_current_company, tile, TileX(tile), TileY(tile), p1, p2, cmd & ~CMD_NETWORK_COMMAND, text, binary_length, GetCommandName(cmd)); + } + /* Make sure we're not messing things up here. */ assert(exec_as_spectator ? _current_company == COMPANY_SPECTATOR : cur_company.Verify()); diff --git a/src/core/random_func.hpp b/src/core/random_func.hpp index ae476624e8..934703d6fb 100644 --- a/src/core/random_func.hpp +++ b/src/core/random_func.hpp @@ -49,7 +49,7 @@ static inline void SaveRandomSeeds(SavedRandomSeeds *storage) /** * Restores previously saved seeds - * @param storage Storage where SaveRandomSeeds() stored th seeds + * @param storage Storage where SaveRandomSeeds() stored the seeds */ static inline void RestoreRandomSeeds(const SavedRandomSeeds &storage) { @@ -57,6 +57,22 @@ static inline void RestoreRandomSeeds(const SavedRandomSeeds &storage) _interactive_random = storage.interactive_random; } +struct GameRandomSeedChecker { +private: + Randomizer random; + +public: + GameRandomSeedChecker() + { + this->random = _random; + } + + bool Check() const + { + return (this->random.state[0] == _random.state[0] && this->random.state[1] == _random.state[1]); + } +}; + void SetRandomSeed(uint32 seed); #ifdef RANDOM_DEBUG #ifdef __APPLE__