Changeset - r14828:12f0b09ddc04
[Not reviewed]
master
0 4 0
yexo - 14 years ago 2010-03-15 22:42:43
yexo@openttd.org
(svn r19429) -Fix: when the title game contains an AIPL block the AI settinsg where overwritten by those from the title game
4 files changed with 18 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_config.cpp
Show inline comments
 
@@ -90,19 +90,19 @@ const AIConfigItemList *AIConfig::GetCon
 
		this->config_list = new AIConfigItemList();
 
		this->config_list->push_back(_start_date_config);
 
	}
 
	return this->config_list;
 
}
 

	
 
AIConfig *AIConfig::GetConfig(CompanyID company, bool forceNewgameSetting)
 
AIConfig *AIConfig::GetConfig(CompanyID company, AISettingSource source)
 
{
 
	AIConfig **config;
 
	if (!forceNewgameSetting) {
 
		config = (_game_mode == GM_MENU) ? &_settings_newgame.ai_config[company] : &_settings_game.ai_config[company];
 
	if (source == AISS_FORCE_NEWGAME || (source == AISS_DEFAULT && _game_mode == GM_MENU)) {
 
		config = &_settings_newgame.ai_config[company];
 
	} else {
 
		config = &_settings_newgame.ai_config[company];
 
		config = &_settings_game.ai_config[company];
 
	}
 
	if (*config == NULL) *config = new AIConfig();
 
	return *config;
 
}
 

	
 
int AIConfig::GetSetting(const char *name) const
src/ai/ai_config.hpp
Show inline comments
 
@@ -58,16 +58,24 @@ public:
 

	
 
	/**
 
	 * Get the config list for this AIConfig.
 
	 */
 
	const AIConfigItemList *GetConfigList();
 

	
 
	/* Where to get the config from, either default (depends on current game
 
	 * mode) or force either newgame or normal */
 
	enum AISettingSource {
 
		AISS_DEFAULT,       ///< Get the AI config from the current game mode
 
		AISS_FORCE_NEWGAME, ///< Get the newgame AI config
 
		AISS_FORCE_GAME,    ///< Get the AI config from the current game
 
	};
 

	
 
	/**
 
	 * Get the config of a company.
 
	 */
 
	static AIConfig *GetConfig(CompanyID company, bool forceNewgameSetting = false);
 
	static AIConfig *GetConfig(CompanyID company, AISettingSource source = AISS_DEFAULT);
 

	
 
	/**
 
	 * Get the value of a setting for this config. It might fallback to his
 
	 *  'info' to find the default value (if not set or if not-custom difficulty
 
	 *  level).
 
	 * @return The (default) value of the setting, or -1 if the setting was not
src/saveload/ai_sl.cpp
Show inline comments
 
@@ -58,26 +58,26 @@ static void SaveReal_AIPL(int *index_ptr
 
}
 

	
 
static void Load_AIPL()
 
{
 
	/* Free all current data */
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
		AIConfig::GetConfig(c)->ChangeAI(NULL);
 
		AIConfig::GetConfig(c, AIConfig::AISS_FORCE_GAME)->ChangeAI(NULL);
 
	}
 

	
 
	CompanyID index;
 
	while ((index = (CompanyID)SlIterateArray()) != (CompanyID)-1) {
 
		_ai_saveload_version = -1;
 
		SlObject(NULL, _ai_company);
 

	
 
		if (_networking && !_network_server) {
 
			if (Company::IsValidAiID(index)) AIInstance::LoadEmpty();
 
			continue;
 
		}
 

	
 
		AIConfig *config = AIConfig::GetConfig(index);
 
		AIConfig *config = AIConfig::GetConfig(index, AIConfig::AISS_FORCE_GAME);
 
		if (StrEmpty(_ai_saveload_name)) {
 
			/* A random AI. */
 
			config->ChangeAI(NULL, -1, false, true);
 
		} else {
 
			config->ChangeAI(_ai_saveload_name, _ai_saveload_version, false, _ai_saveload_is_random);
 
			if (!config->HasAI()) {
src/settings.cpp
Show inline comments
 
@@ -1199,21 +1199,21 @@ static void AILoadConfig(IniFile *ini, c
 
#ifdef ENABLE_AI
 
	IniGroup *group = ini->GetGroup(grpname);
 
	IniItem *item;
 

	
 
	/* Clean any configured AI */
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
		AIConfig::GetConfig(c, true)->ChangeAI(NULL);
 
		AIConfig::GetConfig(c, AIConfig::AISS_FORCE_NEWGAME)->ChangeAI(NULL);
 
	}
 

	
 
	/* If no group exists, return */
 
	if (group == NULL) return;
 

	
 
	CompanyID c = COMPANY_FIRST;
 
	for (item = group->item; c < MAX_COMPANIES && item != NULL; c++, item = item->next) {
 
		AIConfig *config = AIConfig::GetConfig(c, true);
 
		AIConfig *config = AIConfig::GetConfig(c, AIConfig::AISS_FORCE_NEWGAME);
 

	
 
		config->ChangeAI(item->name);
 
		if (!config->HasAI()) {
 
			if (strcmp(item->name, "none") != 0) {
 
				DEBUG(ai, 0, "The AI by the name '%s' was no longer found, and removed from the list.", item->name);
 
				continue;
 
@@ -1310,13 +1310,13 @@ static void AISaveConfig(IniFile *ini, c
 
	IniGroup *group = ini->GetGroup(grpname);
 

	
 
	if (group == NULL) return;
 
	group->Clear();
 

	
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
		AIConfig *config = AIConfig::GetConfig(c, true);
 
		AIConfig *config = AIConfig::GetConfig(c, AIConfig::AISS_FORCE_NEWGAME);
 
		const char *name;
 
		char value[1024];
 
		config->SettingsToString(value, lengthof(value));
 

	
 
		if (config->HasAI()) {
 
			name = config->GetName();
0 comments (0 inline, 0 general)