@@ -29,8 +29,14 @@ static void SaveReal_AIPL(int *index_ptr
CompanyID index = (CompanyID)*index_ptr;
AIConfig *config = AIConfig::GetConfig(index);
ttd_strlcpy(_ai_saveload_name, config->GetName(), lengthof(_ai_saveload_name));
_ai_saveload_version = config->GetVersion();
if (config->HasAI()) {
} 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';
config->SettingsToString(_ai_saveload_settings, lengthof(_ai_saveload_settings));
@@ -54,18 +60,23 @@ static void Load_AIPL()
SlObject(NULL, _ai_company);
config->ChangeAI(_ai_saveload_name, _ai_saveload_version);
if (!config->HasAI()) {
if (strcmp(_ai_saveload_name, "%_dummy") != 0) {
DEBUG(ai, 0, "The savegame has an AI by the name '%s', version %d which is no longer available.", _ai_saveload_name, _ai_saveload_version);
DEBUG(ai, 0, "A random other AI will be loaded in its place.");
DEBUG(ai, 0, "The savegame had no AIs available at the time of saving.");
DEBUG(ai, 0, "A random available AI will be loaded now.");
if (StrEmpty(_ai_saveload_name)) {
/* A random AI. */
config->ChangeAI(NULL);
/* Make sure the AI doesn't get the saveload data, as he was not the
* writer of the saveload data in the first place */
config->StringToSettings(_ai_saveload_settings);
@@ -81,8 +92,6 @@ static void Load_AIPL()
static void Save_AIPL()
{
for (int i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
if (!AIConfig::GetConfig((CompanyID)i)->HasAI()) continue;
SlSetArrayIndex(i);
SlAutolength((AutolengthProc *)SaveReal_AIPL, &i);
@@ -1716,8 +1716,10 @@ static void AILoadConfig(IniFile *ini, c
config->ChangeAI(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;
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);
config->StringToSettings(item->value);
@@ -1801,12 +1803,11 @@ static void AISaveConfig(IniFile *ini, c
AIConfig *config = AIConfig::GetConfig(c, true);
const char *name;
char value[1024];
config->SettingsToString(value, lengthof(value));
name = config->GetName();
value[0] = '\0';
name = "none";
Status change: