Changeset - r28736:cf6dcf707eb1
[Not reviewed]
master
0 4 0
Loïc Guilloux - 10 months ago 2024-02-11 18:58:41
glx22@users.noreply.github.com
Change: [Script] Use company randomizer when adding random deviation (#12065)
4 files changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_core.cpp
Show inline comments
 
@@ -47,25 +47,25 @@
 
	if (config == nullptr) {
 
		c->ai_config = std::make_unique<AIConfig>(AIConfig::GetConfig(company, AIConfig::SSS_FORCE_GAME));
 
		config = c->ai_config.get();
 
	}
 

	
 
	AIInfo *info = config->GetInfo();
 
	if (info == nullptr) {
 
		info = AI::scanner_info->SelectRandomAI();
 
		assert(info != nullptr);
 
		/* Load default data and store the name in the settings */
 
		config->Change(info->GetName(), -1, false);
 
	}
 
	if (deviate) config->AddRandomDeviation();
 
	if (deviate) config->AddRandomDeviation(company);
 
	config->AnchorUnchangeableSettings();
 

	
 
	c->ai_info = info;
 
	assert(c->ai_instance == nullptr);
 
	c->ai_instance = new AIInstance();
 
	c->ai_instance->Initialize(info);
 
	c->ai_instance->LoadOnStack(config->GetToLoadData());
 
	config->SetToLoadData(nullptr);
 

	
 
	cur_company.Restore();
 

	
 
	InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1);
src/game/game_core.cpp
Show inline comments
 
@@ -74,25 +74,25 @@
 
	if (Game::instance != nullptr) return;
 

	
 
	/* Don't start GameScripts in intro */
 
	if (_game_mode == GM_MENU) return;
 

	
 
	/* Clients shouldn't start GameScripts */
 
	if (_networking && !_network_server) return;
 

	
 
	GameConfig *config = GameConfig::GetConfig(GameConfig::SSS_FORCE_GAME);
 
	GameInfo *info = config->GetInfo();
 
	if (info == nullptr) return;
 

	
 
	if (deviate) config->AddRandomDeviation();
 
	if (deviate) config->AddRandomDeviation(OWNER_DEITY);
 
	config->AnchorUnchangeableSettings();
 

	
 
	Backup<CompanyID> cur_company(_current_company, FILE_LINE);
 
	cur_company.Change(OWNER_DEITY);
 

	
 
	Game::info = info;
 
	Game::instance = new GameInstance();
 
	Game::instance->Initialize(info);
 
	Game::instance->LoadOnStack(config->GetToLoadData());
 
	config->SetToLoadData(nullptr);
 

	
 
	cur_company.Restore();
src/script/script_config.cpp
Show inline comments
 
@@ -114,29 +114,29 @@ void ScriptConfig::ResetEditableSettings
 

	
 
		bool editable = yet_to_start || (config_item->flags & SCRIPTCONFIG_INGAME) != 0;
 
		bool visible = _settings_client.gui.ai_developer_tools || (config_item->flags & SCRIPTCONFIG_DEVELOPER) == 0;
 

	
 
		if (editable && visible) {
 
			it = this->settings.erase(it);
 
		} else {
 
			it++;
 
		}
 
	}
 
}
 

	
 
void ScriptConfig::AddRandomDeviation()
 
void ScriptConfig::AddRandomDeviation(CompanyID owner)
 
{
 
	for (const auto &item : *this->GetConfigList()) {
 
		if (item.random_deviation != 0) {
 
			this->SetSetting(item.name, ScriptObject::GetRandomizer(OWNER_NONE).Next(item.random_deviation * 2 + 1) - item.random_deviation + this->GetSetting(item.name));
 
			this->SetSetting(item.name, ScriptObject::GetRandomizer(owner).Next(item.random_deviation * 2 + 1) - item.random_deviation + this->GetSetting(item.name));
 
		}
 
	}
 
}
 

	
 
bool ScriptConfig::HasScript() const
 
{
 
	return this->info != nullptr;
 
}
 

	
 
const std::string &ScriptConfig::GetName() const
 
{
 
	return this->name;
src/script/script_config.hpp
Show inline comments
 
@@ -126,25 +126,25 @@ public:
 
	 * Reset all settings to their default value.
 
	 */
 
	void ResetSettings();
 

	
 
	/**
 
	 * Reset only editable and visible settings to their default value.
 
	 */
 
	void ResetEditableSettings(bool yet_to_start);
 

	
 
	/**
 
	 * Randomize all settings the Script requested to be randomized.
 
	 */
 
	void AddRandomDeviation();
 
	void AddRandomDeviation(CompanyID owner);
 

	
 
	/**
 
	 * Is this config attached to an Script? In other words, is there a Script
 
	 *  that is assigned to this slot.
 
	 */
 
	bool HasScript() const;
 

	
 
	/**
 
	 * Get the name of the Script.
 
	 */
 
	const std::string &GetName() const;
 

	
0 comments (0 inline, 0 general)