Changeset - r28630:fe3c5717ad2b
[Not reviewed]
master
0 6 0
Loïc Guilloux - 10 months ago 2024-02-01 09:48:40
glx22@users.noreply.github.com
Fix: [Script] Apply random deviation only at script start (#11944)
6 files changed with 8 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_core.cpp
Show inline comments
 
@@ -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);
src/game/game.hpp
Show inline comments
 
@@ -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.
src/game/game_core.cpp
Show inline comments
 
@@ -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);
src/saveload/afterload.cpp
Show inline comments
 
@@ -553,7 +553,7 @@ static void StartScripts()
 
	}
 

	
 
	/* Start the GameScript. */
 
	Game::StartNew();
 
	Game::StartNew(false);
 

	
 
	ShowScriptDebugWindowIfScriptError();
 
}
src/script/api/script_info_docs.hpp
Show inline comments
 
@@ -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.
src/script/script_config.cpp
Show inline comments
 
@@ -32,10 +32,6 @@ void ScriptConfig::Change(std::optional<
 
	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 ScriptC
 
	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()
0 comments (0 inline, 0 general)