summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-03-15 22:42:43 +0000
committeryexo <yexo@openttd.org>2010-03-15 22:42:43 +0000
commite3591f8a1d0b0e5a84cc8b9d45bb5809a622d1f2 (patch)
tree93ba6a93348ba5abc5fa64a3ef933a5319f27349
parent30189ff459d08142baa9fac9f67dd6246faeae27 (diff)
downloadopenttd-e3591f8a1d0b0e5a84cc8b9d45bb5809a622d1f2.tar.xz
(svn r19429) -Fix: when the title game contains an AIPL block the AI settinsg where overwritten by those from the title game
-rw-r--r--src/ai/ai_config.cpp8
-rw-r--r--src/ai/ai_config.hpp10
-rw-r--r--src/saveload/ai_sl.cpp4
-rw-r--r--src/settings.cpp6
4 files changed, 18 insertions, 10 deletions
diff --git a/src/ai/ai_config.cpp b/src/ai/ai_config.cpp
index c0ae01848..aab8b1f18 100644
--- a/src/ai/ai_config.cpp
+++ b/src/ai/ai_config.cpp
@@ -93,13 +93,13 @@ const AIConfigItemList *AIConfig::GetConfigList()
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];
- } else {
+ if (source == AISS_FORCE_NEWGAME || (source == AISS_DEFAULT && _game_mode == GM_MENU)) {
config = &_settings_newgame.ai_config[company];
+ } else {
+ config = &_settings_game.ai_config[company];
}
if (*config == NULL) *config = new AIConfig();
return *config;
diff --git a/src/ai/ai_config.hpp b/src/ai/ai_config.hpp
index 314082aa4..98e98263c 100644
--- a/src/ai/ai_config.hpp
+++ b/src/ai/ai_config.hpp
@@ -61,10 +61,18 @@ public:
*/
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
diff --git a/src/saveload/ai_sl.cpp b/src/saveload/ai_sl.cpp
index a9ae30020..6a8fb2b1a 100644
--- a/src/saveload/ai_sl.cpp
+++ b/src/saveload/ai_sl.cpp
@@ -61,7 +61,7 @@ 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;
@@ -74,7 +74,7 @@ static void Load_AIPL()
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);
diff --git a/src/settings.cpp b/src/settings.cpp
index 46da600aa..fc7df844a 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1202,7 +1202,7 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
/* 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 */
@@ -1210,7 +1210,7 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
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()) {
@@ -1313,7 +1313,7 @@ static void AISaveConfig(IniFile *ini, const char *grpname)
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));