From 95d3cfd1b3a64fb64e6f3a7f9186806348353755 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 13 Aug 2022 04:46:47 +0300 Subject: [PATCH 53/53] Fix conversion of "topology" setting from old savegames See osdn #45338 Signed-off-by: Marko Lindqvist --- server/savegame/savecompat.c | 83 +++++++++++++++++------------------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c index 4587e23e11..308d8f80c6 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -1978,33 +1978,34 @@ static void compat_load_030200(struct loaddata *loading, } } else if (!fc_strcasecmp("topology", name)) { struct setting *pset = setting_by_name(name); - const char *val = secfile_lookup_str(loading->file, - "settings.set%d.value", i); + struct sf_cb_data info = { pset, TRUE }; + int val; - if (setting_bitwise_set(pset, val, NULL, NULL, 0)) { - enum topo_flag otopo = setting_bitwise_get(pset); + if (secfile_lookup_enum_data(loading->file, &val, TRUE, + setting_bitwise_secfile_str, &info, + "settings.set%d.value", i)) { char wrap[100]; char buf[100]; - if (topo_has_flag(otopo, TF_OLD_WRAPX)) { - if (topo_has_flag(otopo, TF_OLD_WRAPY)) { + if (val & TF_OLD_WRAPX) { + if (val & TF_OLD_WRAPY) { fc_strlcpy(wrap, "WrapX|WrapY", sizeof(wrap)); } else { fc_strlcpy(wrap, "WrapX", sizeof(wrap)); } - } else if (topo_has_flag(otopo, TF_OLD_WRAPY)) { + } else if (val & TF_OLD_WRAPY) { fc_strlcpy(wrap, "WrapY", sizeof(wrap)); } else { fc_strlcpy(wrap, "", sizeof(wrap)); } - if (topo_has_flag(otopo, TF_ISO)) { - if (topo_has_flag(otopo, TF_HEX)) { + if (val & TF_ISO) { + if (val & TF_HEX) { setting_bitwise_set(pset, "ISO|HEX", NULL, NULL, 0); } else { setting_bitwise_set(pset, "ISO", NULL, NULL, 0); } - } else if (topo_has_flag(otopo, TF_HEX)) { + } else if (val & TF_HEX) { setting_bitwise_set(pset, "HEX", NULL, NULL, 0); } else { setting_bitwise_set(pset, "", NULL, NULL, 0); @@ -2020,30 +2021,28 @@ static void compat_load_030200(struct loaddata *loading, wrap, "settings.set%d.value", set_count); if (gamestart_valid) { - val = secfile_lookup_str(loading->file, - "settings.set%d.gamestart", i); - if (setting_bitwise_set(pset, val, NULL, NULL, 0)) { - otopo = setting_bitwise_get(pset); - - if (topo_has_flag(otopo, TF_OLD_WRAPX)) { - if (topo_has_flag(otopo, TF_OLD_WRAPY)) { + if (secfile_lookup_enum_data(loading->file, &val, TRUE, + setting_bitwise_secfile_str, &info, + "settings.set%d.gamestart", i)) { + if (val & TF_OLD_WRAPX) { + if (val & TF_OLD_WRAPY) { fc_strlcpy(wrap, "WrapX|WrapY", sizeof(wrap)); } else { fc_strlcpy(wrap, "WrapX", sizeof(wrap)); } - } else if (topo_has_flag(otopo, TF_OLD_WRAPY)) { + } else if (val & TF_OLD_WRAPY) { fc_strlcpy(wrap, "WrapY", sizeof(wrap)); } else { fc_strlcpy(wrap, "", sizeof(wrap)); } - if (topo_has_flag(otopo, TF_ISO)) { - if (topo_has_flag(otopo, TF_HEX)) { + if (val & TF_ISO) { + if (val & TF_HEX) { setting_bitwise_set(pset, "ISO|HEX", NULL, NULL, 0); } else { setting_bitwise_set(pset, "ISO", NULL, NULL, 0); } - } else if (topo_has_flag(otopo, TF_HEX)) { + } else if (val & TF_HEX) { setting_bitwise_set(pset, "HEX", NULL, NULL, 0); } else { setting_bitwise_set(pset, "", NULL, NULL, 0); @@ -2519,20 +2518,21 @@ static void compat_load_dev(struct loaddata *loading) al_set_already = TRUE; } else if (!fc_strcasecmp("topology", name)) { struct setting *pset = setting_by_name(name); - const char *val = secfile_lookup_str(loading->file, - "settings.set%d.value", i); + struct sf_cb_data info = { pset, TRUE }; + int val; - if (setting_bitwise_set(pset, val, NULL, NULL, 0)) { - enum topo_flag otopo = setting_bitwise_get(pset); + if (secfile_lookup_enum_data(loading->file, &val, TRUE, + setting_bitwise_secfile_str, &info, + "settings.set%d.value", i)) { bool topo_changed = TRUE; - if (topo_has_flag(otopo, TF_OLD_WRAPX)) { - if (topo_has_flag(otopo, TF_OLD_WRAPY)) { + if (val & TF_OLD_WRAPX) { + if (val & TF_OLD_WRAPY) { fc_strlcpy(wrap, "WrapX|WrapY", sizeof(wrap)); } else { fc_strlcpy(wrap, "WrapX", sizeof(wrap)); } - } else if (topo_has_flag(otopo, TF_OLD_WRAPY)) { + } else if (val & TF_OLD_WRAPY) { fc_strlcpy(wrap, "WrapY", sizeof(wrap)); } else { fc_strlcpy(wrap, "", sizeof(wrap)); @@ -2542,13 +2542,13 @@ static void compat_load_dev(struct loaddata *loading) if (topo_changed) { char buf[100]; - if (topo_has_flag(otopo, TF_ISO)) { - if (topo_has_flag(otopo, TF_HEX)) { + if (val & TF_ISO) { + if (val & TF_HEX) { setting_bitwise_set(pset, "ISO|HEX", NULL, NULL, 0); } else { setting_bitwise_set(pset, "ISO", NULL, NULL, 0); } - } else if (topo_has_flag(otopo, TF_HEX)) { + } else if (val & TF_HEX) { setting_bitwise_set(pset, "HEX", NULL, NULL, 0); } else { setting_bitwise_set(pset, "", NULL, NULL, 0); @@ -2560,21 +2560,18 @@ static void compat_load_dev(struct loaddata *loading) } if (gamestart_valid) { - val = secfile_lookup_str(loading->file, - "settings.set%d.gamestart", i); - - if (setting_bitwise_set(pset, val, NULL, NULL, 0)) { - otopo = setting_bitwise_get(pset); - + if (secfile_lookup_enum_data(loading->file, &val, TRUE, + setting_bitwise_secfile_str, &info, + "settings.set%d.gamestart", i)) { topo_changed = TRUE; - if (topo_has_flag(otopo, TF_OLD_WRAPX)) { - if (topo_has_flag(otopo, TF_OLD_WRAPY)) { + if (val & TF_OLD_WRAPX) { + if (val & TF_OLD_WRAPY) { fc_strlcpy(wrap_gs, "WrapX|WrapY", sizeof(wrap)); } else { fc_strlcpy(wrap_gs, "WrapX", sizeof(wrap)); } - } else if (topo_has_flag(otopo, TF_OLD_WRAPY)) { + } else if (val & TF_OLD_WRAPY) { fc_strlcpy(wrap_gs, "WrapY", sizeof(wrap)); } else { fc_strlcpy(wrap_gs, "", sizeof(wrap)); @@ -2584,13 +2581,13 @@ static void compat_load_dev(struct loaddata *loading) if (topo_changed) { char buf[100]; - if (topo_has_flag(otopo, TF_ISO)) { - if (topo_has_flag(otopo, TF_HEX)) { + if (val & TF_ISO) { + if (val & TF_HEX) { setting_bitwise_set(pset, "ISO|HEX", NULL, NULL, 0); } else { setting_bitwise_set(pset, "ISO", NULL, NULL, 0); } - } else if (topo_has_flag(otopo, TF_HEX)) { + } else if (val & TF_HEX) { setting_bitwise_set(pset, "HEX", NULL, NULL, 0); } else { setting_bitwise_set(pset, "", NULL, NULL, 0); -- 2.35.1