From 5921678a249491700655cb3893374ea6f461a219 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 11 Dec 2021 21:16:56 +0200 Subject: [PATCH 48/48] Make research got_tech_multi mandatory in new savegames See osdn #43385 Signed-off-by: Marko Lindqvist --- server/savegame/savecompat.c | 35 +++++++++++++++++++++++++++++++++-- server/savegame/savegame3.c | 10 +++------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c index 8d08389bce..589c92c7e9 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -1855,6 +1855,9 @@ static void compat_post_load_030100(struct loaddata *loading, static void compat_load_030200(struct loaddata *loading, enum sgf_version format_class) { + int i; + int count; + /* Check status and return if not OK (sg_success != TRUE). */ sg_check_ret(); @@ -1865,7 +1868,6 @@ static void compat_load_030200(struct loaddata *loading, int set_count; if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) { - int i; bool gamestart_valid = secfile_lookup_bool_default(loading->file, FALSE, "settings.gamestart_valid"); @@ -1914,6 +1916,20 @@ static void compat_load_030200(struct loaddata *loading, } } } + + /* Older savegames had a bug that got_tech_multi was not saved. + * Insert the entry to such savegames */ + + /* May be unsaved (e.g. scenario case). */ + count = secfile_lookup_int_default(loading->file, 0, "research.count"); + for (i = 0; i < count; i++) { + if (secfile_entry_lookup(loading->file, + "research.r%d.got_tech_multi", i) == NULL) { + /* Default to FALSE */ + secfile_insert_bool(loading->file, FALSE, + "research.r%d.got_tech_multi", i); + } + } } /************************************************************************//** @@ -2222,7 +2238,22 @@ static void compat_load_dev(struct loaddata *loading) if (game_version < 3019100) { /* Before version number bump to 3.1.91 */ - + int i; + int count; + + /* Older savegames had a bug that got_tech_multi was not saved. + * Insert the entry to such savegames */ + + /* May be unsaved (e.g. scenario case). */ + count = secfile_lookup_int_default(loading->file, 0, "research.count"); + for (i = 0; i < count; i++) { + if (secfile_entry_lookup(loading->file, + "research.r%d.got_tech_multi", i) == NULL) { + /* Default to FALSE */ + secfile_insert_bool(loading->file, FALSE, + "research.r%d.got_tech_multi", i); + } + } } /* Version < 3.1.91 */ #endif /* FREECIV_DEV_SAVE_COMPAT_3_2 */ diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 1d874799fb..97504e0aa4 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -7082,13 +7082,9 @@ static void sg_load_researches(struct loaddata *loading) &presearch->got_tech, "research.r%d.got_tech", i), "%s", secfile_error()); - - /* Older savegames (3.0 betas) had a bug that got_tech_multi was not saved. - * Have to live with such savegames, so can't make it an error if value - * is not found from the savegame. */ - presearch->got_tech_multi = secfile_lookup_bool_default(loading->file, FALSE, - "research.r%d.got_tech_multi", - i); + sg_failure_ret(secfile_lookup_bool(loading->file, &presearch->got_tech_multi, + "research.r%d.got_tech_multi", i), + "%s", secfile_error()); str = secfile_lookup_str(loading->file, "research.r%d.done", i); sg_failure_ret(str != NULL, "%s", secfile_error()); -- 2.33.0