Check whether DoCommand test execution changes the random seed
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include "newgrf_text.h"
|
#include "newgrf_text.h"
|
||||||
#include "string_func.h"
|
#include "string_func.h"
|
||||||
#include "scope_info.h"
|
#include "scope_info.h"
|
||||||
|
#include "core/random_func.hpp"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "table/strings.h"
|
#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;
|
bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0;
|
||||||
|
|
||||||
|
GameRandomSeedChecker random_state;
|
||||||
|
|
||||||
/* Test the command. */
|
/* Test the command. */
|
||||||
_cleared_object_areas.clear();
|
_cleared_object_areas.clear();
|
||||||
SetTownRatingTestMode(true);
|
SetTownRatingTestMode(true);
|
||||||
@@ -929,6 +932,11 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
|
|||||||
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_TESTMODE);
|
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_TESTMODE);
|
||||||
SetTownRatingTestMode(false);
|
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. */
|
/* Make sure we're not messing things up here. */
|
||||||
assert(exec_as_spectator ? _current_company == COMPANY_SPECTATOR : cur_company.Verify());
|
assert(exec_as_spectator ? _current_company == COMPANY_SPECTATOR : cur_company.Verify());
|
||||||
|
|
||||||
|
@@ -49,7 +49,7 @@ static inline void SaveRandomSeeds(SavedRandomSeeds *storage)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores previously saved seeds
|
* 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)
|
static inline void RestoreRandomSeeds(const SavedRandomSeeds &storage)
|
||||||
{
|
{
|
||||||
@@ -57,6 +57,22 @@ static inline void RestoreRandomSeeds(const SavedRandomSeeds &storage)
|
|||||||
_interactive_random = storage.interactive_random;
|
_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);
|
void SetRandomSeed(uint32 seed);
|
||||||
#ifdef RANDOM_DEBUG
|
#ifdef RANDOM_DEBUG
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
Reference in New Issue
Block a user