(svn r15239) -Fix [FS#2579]: The start date of random AIs was not stored in the config file or the savegame.

This commit is contained in:
Yexo 2009-01-23 21:52:29 +00:00
parent c57f5ed668
commit 757b11325b
2 changed files with 29 additions and 19 deletions

View File

@ -29,8 +29,14 @@ static void SaveReal_AIPL(int *index_ptr)
CompanyID index = (CompanyID)*index_ptr; CompanyID index = (CompanyID)*index_ptr;
AIConfig *config = AIConfig::GetConfig(index); AIConfig *config = AIConfig::GetConfig(index);
if (config->HasAI()) {
ttd_strlcpy(_ai_saveload_name, config->GetName(), lengthof(_ai_saveload_name)); ttd_strlcpy(_ai_saveload_name, config->GetName(), lengthof(_ai_saveload_name));
_ai_saveload_version = config->GetVersion(); _ai_saveload_version = config->GetVersion();
} else {
/* No AI is configured for this so store an empty string as name. */
_ai_saveload_name[0] = '\0';
_ai_saveload_version = -1;
}
_ai_saveload_settings[0] = '\0'; _ai_saveload_settings[0] = '\0';
config->SettingsToString(_ai_saveload_settings, lengthof(_ai_saveload_settings)); config->SettingsToString(_ai_saveload_settings, lengthof(_ai_saveload_settings));
@ -54,6 +60,10 @@ static void Load_AIPL()
_ai_saveload_version = -1; _ai_saveload_version = -1;
SlObject(NULL, _ai_company); SlObject(NULL, _ai_company);
if (StrEmpty(_ai_saveload_name)) {
/* A random AI. */
config->ChangeAI(NULL);
} else {
config->ChangeAI(_ai_saveload_name, _ai_saveload_version); config->ChangeAI(_ai_saveload_name, _ai_saveload_version);
if (!config->HasAI()) { if (!config->HasAI()) {
if (strcmp(_ai_saveload_name, "%_dummy") != 0) { if (strcmp(_ai_saveload_name, "%_dummy") != 0) {
@ -67,6 +77,7 @@ static void Load_AIPL()
* writer of the saveload data in the first place */ * writer of the saveload data in the first place */
_ai_saveload_version = -1; _ai_saveload_version = -1;
} }
}
config->StringToSettings(_ai_saveload_settings); config->StringToSettings(_ai_saveload_settings);
@ -81,8 +92,6 @@ static void Load_AIPL()
static void Save_AIPL() static void Save_AIPL()
{ {
for (int i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { for (int i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
if (!AIConfig::GetConfig((CompanyID)i)->HasAI()) continue;
SlSetArrayIndex(i); SlSetArrayIndex(i);
SlAutolength((AutolengthProc *)SaveReal_AIPL, &i); SlAutolength((AutolengthProc *)SaveReal_AIPL, &i);
} }

View File

@ -1716,9 +1716,11 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
config->ChangeAI(item->name); config->ChangeAI(item->name);
if (!config->HasAI()) { 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); 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; continue;
} }
}
config->StringToSettings(item->value); config->StringToSettings(item->value);
} }
} }
@ -1801,12 +1803,11 @@ static void AISaveConfig(IniFile *ini, const char *grpname)
AIConfig *config = AIConfig::GetConfig(c, true); AIConfig *config = AIConfig::GetConfig(c, true);
const char *name; const char *name;
char value[1024]; char value[1024];
config->SettingsToString(value, lengthof(value));
if (config->HasAI()) { if (config->HasAI()) {
config->SettingsToString(value, lengthof(value));
name = config->GetName(); name = config->GetName();
} else { } else {
value[0] = '\0';
name = "none"; name = "none";
} }