From a55886ca7bebf763cd164b7a158eb776e331132a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 9 Apr 2023 09:24:00 +0300 Subject: [PATCH 43/43] 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 edb5b7cc76..09a57f8de4 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -1954,6 +1954,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"); @@ -1963,6 +1964,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]; } @@ -1975,6 +1979,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")) { @@ -2920,6 +2957,72 @@ static void compat_load_dev(struct loaddata *loading) } player_slots_iterate_end; } + { + 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.2.91 */ #endif /* FREECIV_DEV_SAVE_COMPAT_3_3 */ -- 2.39.2