Fix: [Script] Apply random deviation only at script start (#11944)

pull/661/head
Loïc Guilloux 4 months ago committed by GitHub
parent e28edf6945
commit ab1407fc43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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<CompanyID> cur_company(_current_company, company, FILE_LINE);

@ -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.

@ -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<CompanyID> cur_company(_current_company, FILE_LINE);

@ -553,7 +553,7 @@ static void StartScripts()
}
/* Start the GameScript. */
Game::StartNew();
Game::StartNew(false);
ShowScriptDebugWindowIfScriptError();
}

@ -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.

@ -32,10 +32,6 @@ void ScriptConfig::Change(std::optional<const std::string> 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()

Loading…
Cancel
Save