From 6ce943d32a5735a2abfe0d5089643ccc712463a8 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 9 Apr 2023 09:30:16 +0300 Subject: [PATCH 50/50] Savecompat: Convert Clean Pollution/Fallout to Clean It's still possible that old actions and activities end to fresh saves. That's not a problem, as long as we keep on converting as recently (freeciv version wise) saved games as where those old ones still might appear. See osdn #47816 Signed-off-by: Marko Lindqvist --- server/savegame/savecompat.c | 103 +++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c index d1c6934b00..dec392759e 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -1950,6 +1950,7 @@ static void compat_load_030200(struct loaddata *loading, const char **savemod; int j; const char *dur_name = "Transport Deboard"; + const char *clean_name = "Clean"; modname = secfile_lookup_str_vec(loading->file, &loading->action.size, "savefile.action_vector"); @@ -1959,6 +1960,9 @@ static void compat_load_030200(struct loaddata *loading, for (j = 0; j < action_count; j++) { if (!fc_strcasecmp("Transport Alight", modname[j])) { savemod[j] = dur_name; + } else if (!fc_strcasecmp("Clean Pollution", modname[j]) + || !fc_strcasecmp("Clean Fallout", modname[j])) { + savemod[j] = clean_name; } else { savemod[j] = modname[j]; } @@ -1971,6 +1975,39 @@ static void compat_load_030200(struct loaddata *loading, } } + { + int activities_count; + + activities_count = secfile_lookup_int_default(loading->file, 0, + "savefile.activities_size"); + + if (activities_count > 0) { + const char **modname; + const char **savemod; + int j; + const char *clean_name = "Clean"; + + modname = secfile_lookup_str_vec(loading->file, &loading->activities.size, + "savefile.activities_vector"); + + savemod = fc_calloc(activities_count, sizeof(*savemod)); + + for (j = 0; j < activities_count; j++) { + if (!fc_strcasecmp("Pollution", modname[j]) + || !fc_strcasecmp("Fallout", modname[j])) { + savemod[j] = clean_name; + } else { + savemod[j] = modname[j]; + } + } + + secfile_replace_str_vec(loading->file, savemod, activities_count, + "savefile.activities_vector"); + + free(savemod); + } + } + /* Server setting migration. */ { if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) { @@ -2882,6 +2919,72 @@ static void compat_load_dev(struct loaddata *loading) if (game_version < 3019400) { /* Before version number bump to 3.1.94 */ + { + int action_count; + + action_count = secfile_lookup_int_default(loading->file, 0, + "savefile.action_size"); + + if (action_count > 0) { + const char **modname; + const char **savemod; + int j; + const char *clean_name = "Clean"; + + modname = secfile_lookup_str_vec(loading->file, &loading->action.size, + "savefile.action_vector"); + + savemod = fc_calloc(action_count, sizeof(*savemod)); + + for (j = 0; j < action_count; j++) { + if (!fc_strcasecmp("Clean Pollution", modname[j]) + || !fc_strcasecmp("Clean Fallout", modname[j])) { + savemod[j] = clean_name; + } else { + savemod[j] = modname[j]; + } + } + + secfile_replace_str_vec(loading->file, savemod, action_count, + "savefile.action_vector"); + + free(savemod); + } + } + + { + int activities_count; + + activities_count = secfile_lookup_int_default(loading->file, 0, + "savefile.activities_size"); + + if (activities_count > 0) { + const char **modname; + const char **savemod; + int j; + const char *clean_name = "Clean"; + + modname = secfile_lookup_str_vec(loading->file, &loading->activities.size, + "savefile.activities_vector"); + + savemod = fc_calloc(activities_count, sizeof(*savemod)); + + for (j = 0; j < activities_count; j++) { + if (!fc_strcasecmp("Pollution", modname[j]) + || !fc_strcasecmp("Fallout", modname[j])) { + savemod[j] = clean_name; + } else { + savemod[j] = modname[j]; + } + } + + secfile_replace_str_vec(loading->file, savemod, activities_count, + "savefile.activities_vector"); + + free(savemod); + } + } + } /* Version < 3.1.94 */ #endif /* FREECIV_DEV_SAVE_COMPAT_3_2 */ -- 2.39.2