From 019c13ea5527bd8e7bfc99216b3116318cac6af6 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 21 Jan 2023 20:01:19 +0200 Subject: [PATCH 23/23] Drop dev-save-compat code from S3_1 The branch is transitioning to beta soon, and is expected to be about stable save formats at that point. See osdn #45449 Signed-off-by: Marko Lindqvist --- configure.ac | 16 -- server/savegame/savecompat.c | 443 +---------------------------------- 2 files changed, 2 insertions(+), 457 deletions(-) diff --git a/configure.ac b/configure.ac index 9beba65492..824f23b9f9 100644 --- a/configure.ac +++ b/configure.ac @@ -395,22 +395,6 @@ AC_ARG_WITH([metainfodir], [ METAINFODIR=${withval} ], [ METAINFODIR="\$(prefix)/share/metainfo" ]) AC_SUBST([METAINFODIR]) -dnl try to support this development version's previous save games formats -AC_ARG_ENABLE([dev-save-compat], - AS_HELP_STRING([--enable-dev-save-compat=yes/no], - [enable development version save game compatibility]), - [case "${enableval}" in - yes) dev_save_compat=1 ;; - no) dev_save_compat=0 ;; - *) AC_MSG_ERROR([bad value ${enableval} for --enable-dev-save-compat]) ;; - esac], - [dev_save_compat=$IS_DEVEL_VERSION]) -AS_IF([test $dev_save_compat != 0], - [AC_DEFINE([FREECIV_DEV_SAVE_COMPAT], [1], - [Development version save game compatibility]) - AC_DEFINE([FREECIV_DEV_SAVE_COMPAT_3_1], [1], - [Development version save game compatibility - 3.1 development])]) - AC_ARG_ENABLE([patient-connect], AS_HELP_STRING([--enable-patient-connect=yes/no], [enable client to be very patient in connecting spawned server]), diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c index 866880b248..944b86965e 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -65,8 +65,8 @@ static char *special_names[] = | * "known" info format change | | 2.5.0 | 2.5.0 release | 201./../.. | 20 2.6.0 | 2.6.0 release | 201./../.. | 30 - 3.0.0 | 3.0.0 release | 201./../.. | 40 - 3.1.0 | 3.0.0 release (development) | 201./../.. | 50 + 3.0.0 | 3.0.0 release | 202./../.. | 40 + 3.1.0 | 3.1.0 release | 202./../.. | 50 | | | */ @@ -78,11 +78,6 @@ static void compat_load_030100(struct loaddata *loading, enum sgf_version format static void compat_post_load_030100(struct loaddata *loading, enum sgf_version format_class); -#ifdef FREECIV_DEV_SAVE_COMPAT -static void compat_load_dev(struct loaddata *loading); -static void compat_post_load_dev(struct loaddata *loading); -#endif /* FREECIV_DEV_SAVE_COMPAT */ - typedef void (*load_version_func_t) (struct loaddata *loading, enum sgf_version format_class); struct compatibility { @@ -167,12 +162,6 @@ void sg_load_compat(struct loaddata *loading, enum sgf_version format_class) compat[i].load(loading, format_class); } } - -#ifdef FREECIV_DEV_SAVE_COMPAT - if (loading->version == compat[compat_current].version) { - compat_load_dev(loading); - } -#endif /* FREECIV_DEV_SAVE_COMPAT */ } /************************************************************************//** @@ -202,12 +191,6 @@ void sg_load_post_load_compat(struct loaddata *loading, compat[i].post_load(loading, format_class); } } - -#ifdef FREECIV_DEV_SAVE_COMPAT - if (loading->version == compat[compat_current].version) { - compat_post_load_dev(loading); - } -#endif /* FREECIV_DEV_SAVE_COMPAT */ } /************************************************************************//** @@ -1893,428 +1876,6 @@ static void compat_post_load_030100(struct loaddata *loading, } players_iterate_alive_end; } -/************************************************************************//** - Translate savegame secfile data from earlier development version format - to current one. -****************************************************************************/ -#ifdef FREECIV_DEV_SAVE_COMPAT -static void compat_load_dev(struct loaddata *loading) -{ - int game_version; - - /* Check status and return if not OK (sg_success FALSE). */ - sg_check_ret(); - - log_debug("Upgrading data between development revisions"); - - if (!secfile_lookup_int(loading->file, &game_version, "scenario.game_version")) { - game_version = 2060000; - } - -#ifdef FREECIV_DEV_SAVE_COMPAT_3_1 - - if (game_version < 3009200) { - /* Before version number bump to 3.0.92, beginning of 2020 */ - - /* Renamed actions. */ - loading->action.size = secfile_lookup_int_default(loading->file, 0, - "savefile.action_size"); - if (loading->action.size) { - const char **modname; - int j; - - modname = secfile_lookup_str_vec(loading->file, &loading->action.size, - "savefile.action_vector"); - - for (j = 0; j < loading->action.size; j++) { - if (fc_strcasecmp(modname[j], "Targeted Steal Tech Escape") == 0) { - secfile_replace_str(loading->file, "Targeted Steal Tech Escape Expected", - "savefile.action_vector,%d", j); - } else if (fc_strcasecmp(modname[j], "Steal Tech Escape") == 0) { - secfile_replace_str(loading->file, "Steal Tech Escape Expected", - "savefile.action_vector,%d", j); - } else if (fc_strcasecmp(modname[j], "Road") == 0) { - secfile_replace_str(loading->file, "Build Road", - "savefile.action_vector,%d", j); - } - } - - free(modname); - } - - /* Old unit order tgt_vec refers to order sub targets */ - player_slots_iterate(pslot) { - int unit; - int units_num; - int plrno = player_slot_index(pslot); - - if (secfile_section_lookup(loading->file, "player%d", plrno) - == NULL) { - continue; - } - - /* Number of units the player has. */ - units_num = secfile_lookup_int_default(loading->file, 0, - "player%d.nunits", - plrno); - - for (unit = 0; unit < units_num; unit++) { - size_t old_tgt_size; - int *old_tgt_vec; - - if ((old_tgt_vec = secfile_lookup_int_vec(loading->file, &old_tgt_size, - "player%d.u%d.tgt_vec", - plrno, unit))) { - secfile_insert_int_vec(loading->file, old_tgt_vec, old_tgt_size, - "player%d.u%d.sub_tgt_vec", plrno, unit); - free(old_tgt_vec); - } - } - } player_slots_iterate_end; - - /* Unit order extra sub targets was for a while stored separate from tech - * and building sub targets. */ - player_slots_iterate(pslot) { - int unit; - int units_num; - int plrno = player_slot_index(pslot); - - if (secfile_section_lookup(loading->file, "player%d", plrno) - == NULL) { - continue; - } - - /* Number of units the player has. */ - units_num = secfile_lookup_int_default(loading->file, 0, - "player%d.nunits", - plrno); - - for (unit = 0; unit < units_num; unit++) { - size_t extra_vec_size; - int *extra_vec; - - if ((extra_vec = secfile_lookup_int_vec(loading->file, - &extra_vec_size, - "player%d.u%d.extra_vec", - plrno, unit))) { - int order_num; - - for (order_num = 0; order_num < extra_vec_size; order_num++) { - if (extra_vec[order_num] != -1) { - if (order_num) { - secfile_replace_int(loading->file, extra_vec[order_num], - "player%d.u%d.sub_tgt_vec,%d", - plrno, unit, order_num); - } else { - secfile_replace_int(loading->file, extra_vec[order_num], - "player%d.u%d.sub_tgt_vec", - plrno, unit); - } - } - } - free(extra_vec); - } - } - } player_slots_iterate_end; - - player_slots_iterate(pslot) { - int plrno = player_slot_index(pslot); - int history; - - history = secfile_lookup_int_default(loading->file, 0, - "player%d.culture", - plrno); - - if (history > 0) { - /* Savefile had player history value saved to field named 'culture'. - * Save it to 'history'. */ - secfile_insert_int(loading->file, history, "player%d.history", plrno); - } - } 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 **modname_new; - const char *plant_name = "Plant"; - const char *cultivate_name = "Cultivate"; - int j; - - modname = secfile_lookup_str_vec(loading->file, &loading->action.size, - "savefile.action_vector"); - - modname_new = fc_calloc(action_count, sizeof(*modname_new)); - - for (j = 0; j < action_count; j++) { - const char *aname = modname[j]; - - if (!fc_strcasecmp("Mine TF", aname)) { - modname_new[j] = plant_name; - } else if (!fc_strcasecmp("Irrigate TF", aname)) { - modname_new[j] = cultivate_name; - } else { - modname_new[j] = aname; - } - } - - secfile_replace_str_vec(loading->file, modname_new, action_count, - "savefile.action_vector"); - - free(modname_new); - } - } - - /* Actions are now stored by number. */ - player_slots_iterate(pslot) { - int unit; - int units_num; - int plrno = player_slot_index(pslot); - - if (secfile_section_lookup(loading->file, "player%d", plrno) - == NULL) { - continue; - } - - /* Number of units the player has. */ - units_num = secfile_lookup_int_default(loading->file, 0, - "player%d.nunits", - plrno); - - for (unit = 0; unit < units_num; unit++) { - const char *action_unitstr; - int order_len; - - order_len = secfile_lookup_int_default(loading->file, 0, - "player%d.u%d.orders_length", - plrno, unit); - - if ((action_unitstr = secfile_lookup_str_default(loading->file, "", - "player%d.u%d.action_list", - plrno, unit))) { - int order_num; - - if (order_len > strlen(action_unitstr)) { - order_len = strlen(action_unitstr); - } - - for (order_num = 0; order_num < order_len; order_num++) { - int unconverted_action_id; - - if (action_unitstr[order_num] == '?') { - unconverted_action_id = -1; - } else { - unconverted_action_id = char2num(action_unitstr[order_num]); - } - - if (order_num == 0) { - /* The start of a vector has no number. */ - secfile_insert_int(loading->file, unconverted_action_id, - "player%d.u%d.action_vec", - plrno, unit); - } else { - secfile_insert_int(loading->file, unconverted_action_id, - "player%d.u%d.action_vec,%d", - plrno, unit, order_num); - } - } - } - } - } player_slots_iterate_end; - player_slots_iterate(pslot) { - int city; - int city_num; - int plrno = player_slot_index(pslot); - - if (secfile_section_lookup(loading->file, "player%d", plrno) - == NULL) { - continue; - } - - /* Number of cities the player has. */ - city_num = secfile_lookup_int_default(loading->file, 0, - "player%d.ncities", - plrno); - - for (city = 0; city < city_num; city++) { - const char *action_citystr; - int order_len; - - order_len = secfile_lookup_int_default(loading->file, 0, - "player%d.c%d.rally_point_length", - plrno, city); - - if ((action_citystr = secfile_lookup_str_default(loading->file, "", - "player%d.c%d.rally_point_actions", - plrno, city))) { - int order_num; - - if (order_len > strlen(action_citystr)) { - order_len = strlen(action_citystr); - } - - for (order_num = 0; order_num < order_len; order_num++) { - int unconverted_action_id; - - if (action_citystr[order_num] == '?') { - unconverted_action_id = -1; - } else { - unconverted_action_id = char2num(action_citystr[order_num]); - } - - if (order_num == 0) { - /* The start of a vector has no number. */ - secfile_insert_int(loading->file, unconverted_action_id, - "player%d.c%d.rally_point_action_vec", - plrno, city); - } else { - secfile_insert_int(loading->file, unconverted_action_id, - "player%d.c%d.rally_point_action_vec,%d", - plrno, city, order_num); - } - } - } - } - } player_slots_iterate_end; - } /* Version < 3.0.92 */ - - if (game_version < 3009300) { - /* Before version number bump to 3.0.93, beginning of 2021 */ - - /* Explicit server side agent was new in 3.1 */ - insert_server_side_agent(loading, SAVEGAME_3); - } /* Version < 3.0.93 */ - - /* There was no relevant format changes between 3.0.93 and 3.0.94 */ - - if (game_version < 3009500) { - /* Before version number bump to 3.0.95 */ - - { - 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 *dur_name = "Disband Unit Recover"; - - 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("Recycle Unit", modname[j])) { - savemod[j] = dur_name; - } else { - savemod[j] = modname[j]; - } - } - - secfile_replace_str_vec(loading->file, savemod, action_count, - "savefile.action_vector"); - - free(savemod); - } - } - - player_slots_iterate(pslot) { - int plrno = player_slot_index(pslot); - int wonder_city = secfile_lookup_int_default(loading->file, -1, - "player%d.adv.wonder_city", - plrno); - if (wonder_city < 0) { - /* No wonder_city saved with the new name. Check for the old name */ - wonder_city = secfile_lookup_int_default(loading->file, -1, - "player%d.wonder_city", - plrno); - if (wonder_city >= 0) { - secfile_replace_int(loading->file, wonder_city, - "player%d.adv.wonder_city", plrno); - } - } - } player_slots_iterate_end; - } /* Version < 3.0.95 */ - -#endif /* FREECIV_DEV_SAVE_COMPAT_3_1 */ -} - -/************************************************************************//** - Update loaded game data from earlier development version to something - usable by current Freeciv. -****************************************************************************/ -static void compat_post_load_dev(struct loaddata *loading) -{ - int game_version; - - /* Check status and return if not OK (sg_success FALSE). */ - sg_check_ret(); - - if (!secfile_lookup_int(loading->file, &game_version, "scenario.game_version")) { - game_version = 2060000; - } - - if (game_version < 3009300) { - players_iterate_alive(pplayer) { - unit_list_iterate(pplayer->units, punit) { - int i; - - if (!punit->has_orders) { - continue; - } - - fc_assert_action(punit->orders.length == 0 - || punit->orders.list != NULL, continue); - - for (i = 0; i < punit->orders.length; i++) { - /* "Attack" was split in "Suicide Attack" and "Attack" in 3.1. */ - if (punit->orders.list[i].order == ORDER_PERFORM_ACTION - && punit->orders.list[i].action == ACTION_ATTACK - && !unit_can_do_action(punit, ACTION_ATTACK) - && unit_can_do_action(punit, ACTION_SUICIDE_ATTACK)) { - punit->orders.list[i].action = ACTION_SUICIDE_ATTACK; - } - } - } unit_list_iterate_end; - } players_iterate_alive_end; - - /* Explicit server side agent was new in 3.1 */ - upgrade_server_side_agent(loading); - - /* Some activities should only be ordered in action orders. */ - players_iterate_alive(pplayer) { - unit_list_iterate(pplayer->units, punit) { - unit_order_activity_to_action(punit); - } unit_list_iterate_end; - } players_iterate_alive_end; - - /* Unit order action target isn't dir anymore */ - players_iterate_alive(pplayer) { - unit_list_iterate(pplayer->units, punit) { - upgrade_unit_order_targets(punit); - } unit_list_iterate_end; - } players_iterate_alive_end; - - /* Backward compatibility: if we had any open-ended orders (pillage) - * in the savegame, assign specific targets now */ - players_iterate_alive(pplayer) { - unit_list_iterate(pplayer->units, punit) { - unit_assign_specific_activity_target(punit, - &punit->activity, - &punit->activity_target); - } unit_list_iterate_end; - } players_iterate_alive_end; - } /* Version < 3.0.93 */ -} -#endif /* FREECIV_DEV_SAVE_COMPAT */ - /************************************************************************//** Convert old ai level value to ai_level ****************************************************************************/ -- 2.39.0