Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6468: Load correct version of AI as specified during the time of its save. #7193

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/saveload/ai_sl.cpp
Expand Up @@ -81,21 +81,37 @@ static void Load_AIPL()
/* A random AI. */
config->Change(nullptr, -1, false, true);
} else {
config->Change(_ai_saveload_name, _ai_saveload_version, false, _ai_saveload_is_random);
char script_name[1024];
strecpy(script_name, _ai_saveload_name, lastof(script_name));
strtolower(script_name);
int versionParam = _ai_saveload_version;
bool force_match_version = false;
char *e = strrchr(script_name, '.');
if (e != nullptr) {
*e = '\0';
e++;
versionParam = atoi(e);
if (versionParam == _ai_saveload_version) {
versionParam = -1;
force_match_version = true;
}
}
config->Change(_ai_saveload_name, versionParam, force_match_version, _ai_saveload_is_random);
if (!config->HasScript()) {
/* No version of the AI available that can load the data. Try to load the
* latest version of the AI instead. */
config->Change(_ai_saveload_name, -1, false, _ai_saveload_is_random);
config->Change(script_name, -1, false, _ai_saveload_is_random);
if (versionParam == -1) versionParam = _ai_saveload_version;
if (!config->HasScript()) {
if (strcmp(_ai_saveload_name, "%_dummy") != 0) {
DEBUG(script, 0, "The savegame has an AI by the name '%s', version %d which is no longer available.", _ai_saveload_name, _ai_saveload_version);
if (strcmp(script_name, "%_dummy") != 0) {
DEBUG(script, 0, "The savegame has an AI by the name '%s', version %d which is no longer available.", script_name, versionParam);
DEBUG(script, 0, "A random other AI will be loaded in its place.");
} else {
DEBUG(script, 0, "The savegame had no AIs available at the time of saving.");
DEBUG(script, 0, "A random available AI will be loaded now.");
}
} else {
DEBUG(script, 0, "The savegame has an AI by the name '%s', version %d which is no longer available.", _ai_saveload_name, _ai_saveload_version);
DEBUG(script, 0, "The savegame has an AI by the name '%s', version %d which is no longer available.", script_name, versionParam);
DEBUG(script, 0, "The latest version of that AI has been loaded instead, but it'll not get the savegame data as it's incompatible.");
}
/* Make sure the AI doesn't get the saveload data, as he was not the
Expand Down
26 changes: 21 additions & 5 deletions src/saveload/game_sl.cpp
Expand Up @@ -73,21 +73,37 @@ static void Load_GSDT()
GameConfig *config = GameConfig::GetConfig(GameConfig::SSS_FORCE_GAME);
if (StrEmpty(_game_saveload_name)) {
} else {
config->Change(_game_saveload_name, _game_saveload_version, false, _game_saveload_is_random);
char script_name[1024];
strecpy(script_name, _game_saveload_name, lastof(script_name));
strtolower(script_name);
int versionParam = _game_saveload_version;
bool force_match_version = false;
char *e = strrchr(script_name, '.');
if (e != nullptr) {
*e = '\0';
e++;
versionParam = atoi(e);
if (versionParam == _game_saveload_version) {
versionParam = -1;
force_match_version = true;
}
}
config->Change(_game_saveload_name, versionParam, force_match_version, _game_saveload_is_random);
if (!config->HasScript()) {
/* No version of the GameScript available that can load the data. Try to load the
* latest version of the GameScript instead. */
config->Change(_game_saveload_name, -1, false, _game_saveload_is_random);
config->Change(script_name, -1, false, _game_saveload_is_random);
if (versionParam == -1) versionParam = _game_saveload_version;
if (!config->HasScript()) {
if (strcmp(_game_saveload_name, "%_dummy") != 0) {
DEBUG(script, 0, "The savegame has an GameScript by the name '%s', version %d which is no longer available.", _game_saveload_name, _game_saveload_version);
if (strcmp(script_name, "%_dummy") != 0) {
DEBUG(script, 0, "The savegame has a GameScript by the name '%s', version %d which is no longer available.", script_name, versionParam);
DEBUG(script, 0, "This game will continue to run without GameScript.");
} else {
DEBUG(script, 0, "The savegame had no GameScript available at the time of saving.");
DEBUG(script, 0, "This game will continue to run without GameScript.");
}
} else {
DEBUG(script, 0, "The savegame has an GameScript by the name '%s', version %d which is no longer available.", _game_saveload_name, _game_saveload_version);
DEBUG(script, 0, "The savegame has a GameScript by the name '%s', version %d which is no longer available.", script_name, versionParam);
DEBUG(script, 0, "The latest version of that GameScript has been loaded instead, but it'll not get the savegame data as it's incompatible.");
}
/* Make sure the GameScript doesn't get the saveload data, as he was not the
Expand Down
15 changes: 15 additions & 0 deletions src/script/script_config.cpp
Expand Up @@ -22,6 +22,21 @@ void ScriptConfig::Change(const char *name, int version, bool force_exact_match,
this->name = (name == nullptr) ? nullptr : stredup(name);
this->info = (name == nullptr) ? nullptr : this->FindInfo(this->name, version, force_exact_match);
this->version = (info == nullptr) ? -1 : info->GetVersion();
if (this->name != nullptr && info != nullptr && strcasecmp(this->name, this->info->GetName()) != 0 && this->version > -1) {
char script_name[1024];
strecpy(script_name, this->name, lastof(script_name));
strtolower(script_name);
char *e = strrchr(script_name, '.');
if (e != nullptr) {
*e = '\0';
e++;
int versionParam = atoi(e);
if (this->version != versionParam) {
free(this->name);
this->name = stredup(GetInfo()->GetName());
}
}
}
this->is_random = is_random;
if (this->config_list != nullptr) delete this->config_list;
this->config_list = (info == nullptr) ? nullptr : new ScriptConfigItemList();
Expand Down