mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r19429) -Fix: when the title game contains an AIPL block the AI settinsg where overwritten by those from the title game
This commit is contained in:
parent
30189ff459
commit
e3591f8a1d
|
@ -93,13 +93,13 @@ const AIConfigItemList *AIConfig::GetConfigList()
|
||||||
return this->config_list;
|
return this->config_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
AIConfig *AIConfig::GetConfig(CompanyID company, bool forceNewgameSetting)
|
AIConfig *AIConfig::GetConfig(CompanyID company, AISettingSource source)
|
||||||
{
|
{
|
||||||
AIConfig **config;
|
AIConfig **config;
|
||||||
if (!forceNewgameSetting) {
|
if (source == AISS_FORCE_NEWGAME || (source == AISS_DEFAULT && _game_mode == GM_MENU)) {
|
||||||
config = (_game_mode == GM_MENU) ? &_settings_newgame.ai_config[company] : &_settings_game.ai_config[company];
|
|
||||||
} else {
|
|
||||||
config = &_settings_newgame.ai_config[company];
|
config = &_settings_newgame.ai_config[company];
|
||||||
|
} else {
|
||||||
|
config = &_settings_game.ai_config[company];
|
||||||
}
|
}
|
||||||
if (*config == NULL) *config = new AIConfig();
|
if (*config == NULL) *config = new AIConfig();
|
||||||
return *config;
|
return *config;
|
||||||
|
|
|
@ -61,10 +61,18 @@ public:
|
||||||
*/
|
*/
|
||||||
const AIConfigItemList *GetConfigList();
|
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.
|
* 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
|
* Get the value of a setting for this config. It might fallback to his
|
||||||
|
|
|
@ -61,7 +61,7 @@ static void Load_AIPL()
|
||||||
{
|
{
|
||||||
/* Free all current data */
|
/* Free all current data */
|
||||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
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;
|
CompanyID index;
|
||||||
|
@ -74,7 +74,7 @@ static void Load_AIPL()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
AIConfig *config = AIConfig::GetConfig(index);
|
AIConfig *config = AIConfig::GetConfig(index, AIConfig::AISS_FORCE_GAME);
|
||||||
if (StrEmpty(_ai_saveload_name)) {
|
if (StrEmpty(_ai_saveload_name)) {
|
||||||
/* A random AI. */
|
/* A random AI. */
|
||||||
config->ChangeAI(NULL, -1, false, true);
|
config->ChangeAI(NULL, -1, false, true);
|
||||||
|
|
|
@ -1202,7 +1202,7 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
|
||||||
|
|
||||||
/* Clean any configured AI */
|
/* Clean any configured AI */
|
||||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
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 no group exists, return */
|
||||||
|
@ -1210,7 +1210,7 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
|
||||||
|
|
||||||
CompanyID c = COMPANY_FIRST;
|
CompanyID c = COMPANY_FIRST;
|
||||||
for (item = group->item; c < MAX_COMPANIES && item != NULL; c++, item = item->next) {
|
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);
|
config->ChangeAI(item->name);
|
||||||
if (!config->HasAI()) {
|
if (!config->HasAI()) {
|
||||||
|
@ -1313,7 +1313,7 @@ static void AISaveConfig(IniFile *ini, const char *grpname)
|
||||||
group->Clear();
|
group->Clear();
|
||||||
|
|
||||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
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;
|
const char *name;
|
||||||
char value[1024];
|
char value[1024];
|
||||||
config->SettingsToString(value, lengthof(value));
|
config->SettingsToString(value, lengthof(value));
|
||||||
|
|
Loading…
Reference in New Issue