diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index c910f22a83..ac60b78ad9 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -48,6 +48,7 @@ /* Load default data and store the name in the settings */ config->Change(info->GetName(), -1, false, true); } + if (rerandomise_ai) config->AddRandomDeviation(); config->AnchorUnchangeableSettings(); Backup cur_company(_current_company, company, FILE_LINE); diff --git a/src/game/game.hpp b/src/game/game.hpp index c3664cd696..9d83920024 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -31,8 +31,9 @@ public: /** * Start up a new GameScript. + * @param randomise Whether to randomise the configured GameScript. */ - static void StartNew(); + static void StartNew(bool randomise = true); /** * Uninitialize the Game system. diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp index c7763429ff..51279a742a 100644 --- a/src/game/game_core.cpp +++ b/src/game/game_core.cpp @@ -69,7 +69,7 @@ } } -/* static */ void Game::StartNew() +/* static */ void Game::StartNew(bool randomise) { if (Game::instance != nullptr) return; @@ -83,6 +83,7 @@ GameInfo *info = config->GetInfo(); if (info == nullptr) return; + if (randomise) config->AddRandomDeviation(); config->AnchorUnchangeableSettings(); Backup cur_company(_current_company, FILE_LINE); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index bc9072a3a5..b81c8730d2 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -553,7 +553,7 @@ static void StartScripts() } /* Start the GameScript. */ - Game::StartNew(); + Game::StartNew(false); ShowScriptDebugWindowIfScriptError(); } diff --git a/src/script/api/script_info_docs.hpp b/src/script/api/script_info_docs.hpp index 759bc8a336..3a874cfbf2 100644 --- a/src/script/api/script_info_docs.hpp +++ b/src/script/api/script_info_docs.hpp @@ -235,9 +235,10 @@ public: * is selected. Required. The value will be clamped in the range * [MIN(int32_t), MAX(int32_t)] (inclusive). * - random_deviation If this property has a nonzero value, then the - * actual value of the setting in game will be randomized in the range + * actual value of the setting in game will be randomised in the range * [user_configured_value - random_deviation, user_configured_value + random_deviation] (inclusive). * random_deviation sign is ignored and the value is clamped in the range [0, MAX(int32_t)] (inclusive). + * The randomisation will happen just before the Script start. * Not allowed if the CONFIG_RANDOM flag is set, otherwise optional. * - step_size The increase/decrease of the value every time the user * clicks one of the up/down arrow buttons. Optional, default is 1. diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp index 0814af63b0..852ffa1f43 100644 --- a/src/script/script_config.cpp +++ b/src/script/script_config.cpp @@ -32,10 +32,6 @@ void ScriptConfig::Change(std::optional name, int version, bo this->to_load_data.reset(); this->ClearConfigList(); - - if (_game_mode == GM_NORMAL && this->info != nullptr) { - this->AddRandomDeviation(); - } } ScriptConfig::ScriptConfig(const ScriptConfig *config) @@ -49,9 +45,6 @@ ScriptConfig::ScriptConfig(const ScriptConfig *config) for (const auto &item : config->settings) { this->settings[item.first] = item.second; } - - /* Virtual functions get called statically in constructors, so make it explicit to remove any confusion. */ - this->ScriptConfig::AddRandomDeviation(); } ScriptConfig::~ScriptConfig()