From fadb63e8e6283b6339e6af10b9b9a2c38e2f9188 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 9 Jan 2021 00:38:24 +0200 Subject: [PATCH 4/4] Clean out 3.0-to-3.1 rscompat code See osdn #41126 Signed-off-by: Marko Lindqvist --- server/rscompat.c | 429 ---------------------------------------------- server/rscompat.h | 17 +- server/ruleset.c | 50 +----- 3 files changed, 5 insertions(+), 491 deletions(-) diff --git a/server/rscompat.c b/server/rscompat.c index 0b80670b13..e8b91ea0c9 100644 --- a/server/rscompat.c +++ b/server/rscompat.c @@ -546,88 +546,6 @@ static bool effect_list_compat_cb(struct effect *peffect, void *data) return TRUE; } -/**********************************************************************//** - Turn old effect to an action enabler. -**************************************************************************/ -static void effect_to_enabler(action_id action, struct section_file *file, - const char *sec_name, struct rscompat_info *compat, - const char *type) -{ - int value = secfile_lookup_int_default(file, 1, "%s.value", sec_name); - char buf[1024]; - - if (value > 0) { - /* It was an enabling effect. Add enabler */ - struct action_enabler *enabler; - struct requirement_vector *reqs; - struct requirement settler_req; - - enabler = action_enabler_new(); - enabler->action = action; - - reqs = lookup_req_list(file, compat, sec_name, "reqs", "old effect"); - - /* TODO: Divide requirements to actor_reqs and target_reqs depending - * their type. */ - requirement_vector_copy(&enabler->actor_reqs, reqs); - - settler_req = req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL, FALSE, TRUE, FALSE, - UTYF_SETTLERS); - requirement_vector_append(&enabler->actor_reqs, settler_req); - - /* Add the enabler to the ruleset. */ - action_enabler_add(enabler); - - if (compat->log_cb != NULL) { - fc_snprintf(buf, sizeof(buf), - "Converted effect %s in %s to an action enabler. Make sure requirements " - "are correctly divided to actor and target requirements.", - type, sec_name); - compat->log_cb(buf); - } - } else if (value < 0) { - if (compat->log_cb != NULL) { - fc_snprintf(buf, sizeof(buf), - "%s effect with negative value in %s can't be automatically converted " - "to an action enabler. Do that manually.", type, sec_name); - compat->log_cb(buf); - } - } -} - -/**********************************************************************//** - Check if effect name refers to one of the removed effects, and handle it - if it does. Returns TRUE iff name was a valid old name. -**************************************************************************/ -bool rscompat_old_effect_3_1(const char *type, struct section_file *file, - const char *sec_name, struct rscompat_info *compat) -{ - if (compat->ver_effects < 20) { - if (!fc_strcasecmp(type, "Transform_Possible")) { - effect_to_enabler(ACTION_TRANSFORM_TERRAIN, file, sec_name, compat, type); - return TRUE; - } - if (!fc_strcasecmp(type, "Irrig_TF_Possible")) { - effect_to_enabler(ACTION_CULTIVATE, file, sec_name, compat, type); - return TRUE; - } - if (!fc_strcasecmp(type, "Mining_TF_Possible")) { - effect_to_enabler(ACTION_PLANT, file, sec_name, compat, type); - return TRUE; - } - if (!fc_strcasecmp(type, "Mining_Possible")) { - effect_to_enabler(ACTION_MINE, file, sec_name, compat, type); - return TRUE; - } - if (!fc_strcasecmp(type, "Irrig_Possible")) { - effect_to_enabler(ACTION_IRRIGATE, file, sec_name, compat, type); - return TRUE; - } - } - - return FALSE; -} - /**********************************************************************//** Do compatibility things after regular ruleset loading. **************************************************************************/ @@ -1076,350 +994,3 @@ void rscompat_postprocess(struct rscompat_info *info) * using it risks an unexpected change on the next load and save. */ autoadjust_ruleset_data(); } - -/**********************************************************************//** - Replace deprecated auto_attack configuration. -**************************************************************************/ -bool rscompat_auto_attack_3_1(struct rscompat_info *compat, - struct action_auto_perf *auto_perf, - size_t psize, - enum unit_type_flag_id *protecor_flag) -{ - int i; - - if (compat->ver_game < 20) { - /* Auto attack happens during war. */ - requirement_vector_append(&auto_perf->reqs, - req_from_values(VUT_DIPLREL, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, DS_WAR)); - - /* Needs a movement point to auto attack. */ - requirement_vector_append(&auto_perf->reqs, - req_from_values(VUT_MINMOVES, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, 1)); - - for (i = 0; i < psize; i++) { - /* Add each protecor_flag as a !present requirement. */ - requirement_vector_append(&auto_perf->reqs, - req_from_values(VUT_UTFLAG, - REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, - protecor_flag[i])); - } - - auto_perf->alternatives[0] = ACTION_CAPTURE_UNITS; - auto_perf->alternatives[1] = ACTION_BOMBARD; - auto_perf->alternatives[2] = ACTION_ATTACK; - auto_perf->alternatives[3] = ACTION_SUICIDE_ATTACK; - } - - return TRUE; -} - -/**********************************************************************//** - Replace slow_invasions and friends. -**************************************************************************/ -bool rscompat_old_slow_invasions_3_1(struct rscompat_info *compat, - bool slow_invasions) -{ - if (compat->ver_effects < 20 && compat->ver_game < 20) { - /* BeachLander and slow_invasions has moved to the ruleset. Use a "fake - * generalized" Transport Disembark and Conquer City to handle it. */ - - struct action_enabler *enabler; - struct requirement e_req; - - enabler = action_enabler_new(); - enabler->action = ACTION_TRANSPORT_DISEMBARK1; - - if (slow_invasions) { - /* Use for disembarking from native terrain so disembarking from - * non native terain is handled by "Transport Disembark 2". */ - e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, USP_NATIVE_TILE); - requirement_vector_append(&enabler->actor_reqs, e_req); - } - - action_enabler_add(enabler); - - if (slow_invasions) { - /* Make disembarking from non native terrain a different action. */ - - struct effect *peffect; - struct action *paction; - - struct action_enabler_list *to_upgrade; - - - /* Add the actions */ - - /* Use "Transport Disembark 2" for disembarking from non native. */ - paction = action_by_number(ACTION_TRANSPORT_DISEMBARK2); - /* "Transport Disembark" and "Transport Disembark 2" won't appear in - * the same action selection dialog given their opposite - * requirements. */ - paction->quiet = TRUE; - /* Make what is happening clear. */ - /* TRANS: _Disembark from non native (100% chance of success). */ - sz_strlcpy(paction->ui_name, N_("%sDisembark from non native%s")); - - - /* Use "Conquer City 2" for conquring from non native. */ - paction = action_by_number(ACTION_CONQUER_CITY2); - /* "Conquer City" and "Conquer City 2" won't appear in - * the same action selection dialog given their opposite - * requirements. */ - paction->quiet = TRUE; - /* Make what is happening clear. */ - /* TRANS: _Conquer City from non native (100% chance of success). */ - sz_strlcpy(paction->ui_name, N_("%sConquer City from non native%s")); - - - /* Enablers for disembark */ - - /* City center counts as native. */ - enabler = action_enabler_new(); - enabler->action = ACTION_TRANSPORT_DISEMBARK1; - e_req = req_from_values(VUT_CITYTILE, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - CITYT_CENTER); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - - - /* No TerrainSpeed sees everything as native. */ - enabler = action_enabler_new(); - enabler->action = ACTION_TRANSPORT_DISEMBARK1; - e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, - UCF_TERRAIN_SPEED); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - - - /* "BeachLander" sees everything as native. */ - enabler = action_enabler_new(); - enabler->action = ACTION_TRANSPORT_DISEMBARK1; - e_req = req_from_str("UnitFlag", "Local", - FALSE, TRUE, TRUE, - "BeachLander"); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - - - /* "Transport Disembark 2" enabler */ - enabler = action_enabler_new(); - enabler->action = ACTION_TRANSPORT_DISEMBARK2; - - /* Native terrain is native. */ - e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, USP_NATIVE_TILE); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* City is native. */ - e_req = req_from_values(VUT_CITYTILE, - REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, - CITYT_CENTER); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* "BeachLander" sees everything as native. */ - e_req = req_from_str("UnitFlag", "Local", - FALSE, FALSE, TRUE, - "BeachLander"); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* No TerrainSpeed sees everything as native. */ - e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - UCF_TERRAIN_SPEED); - requirement_vector_append(&enabler->actor_reqs, e_req); - - action_enabler_add(enabler); - - - /* Take movement for disembarking and conquering native terrain from - * non native terrain */ - - /* Take movement for disembarking from non native terrain */ - peffect = effect_new(EFT_ACTION_SUCCESS_MOVE_COST, - MAX_MOVE_FRAGS, NULL); - - /* The reduction only applies to "Transport Disembark 2". */ - effect_req_append(peffect, req_from_str("Action", "Local", - FALSE, TRUE, TRUE, - "Transport Disembark 2")); - - /* No reduction here unless disembarking to native terrain. */ - effect_req_append(peffect, req_from_values(VUT_UNITSTATE, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - USP_NATIVE_TILE)); - - - /* Take movement for conquering from non native terrain */ - peffect = effect_new(EFT_ACTION_SUCCESS_MOVE_COST, - MAX_MOVE_FRAGS, NULL); - - /* The reduction only applies to "Conquer City 2". */ - effect_req_append(peffect, req_from_str("Action", "Local", - FALSE, TRUE, TRUE, - "Conquer City 2")); - - /* No reduction here unless disembarking to native terrain. */ - effect_req_append(peffect, req_from_values(VUT_UNITSTATE, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - USP_NATIVE_TILE)); - - /* Upgrade exisiting Conquer City action enablers */ - to_upgrade = action_enabler_list_copy( - action_enablers_for_action(ACTION_CONQUER_CITY)); - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* City center counts as native. */ - enabler = action_enabler_copy(conquer_city_enabler); - e_req = req_from_values(VUT_CITYTILE, - REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - CITYT_CENTER); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - } action_enabler_list_iterate_end; - - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* No TerrainSpeed sees everything as native. */ - enabler = action_enabler_copy(conquer_city_enabler); - e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, - UCF_TERRAIN_SPEED); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - } action_enabler_list_iterate_end; - - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* "BeachLander" sees everything as native. */ - enabler = action_enabler_copy(conquer_city_enabler); - e_req = req_from_str("UnitFlag", "Local", - FALSE, TRUE, TRUE, - "BeachLander"); - requirement_vector_append(&enabler->actor_reqs, e_req); - action_enabler_add(enabler); - } action_enabler_list_iterate_end; - - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* Use "Conquer City 2" for conquring from non native. */ - enabler = action_enabler_copy(conquer_city_enabler); - enabler->action = ACTION_CONQUER_CITY2; - - /* Native terrain is native. */ - e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, USP_NATIVE_TILE); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* City is native. */ - e_req = req_from_values(VUT_CITYTILE, - REQ_RANGE_LOCAL, - FALSE, FALSE, TRUE, - CITYT_CENTER); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* No TerrainSpeed sees everything as native. */ - e_req = req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, - UCF_TERRAIN_SPEED); - requirement_vector_append(&enabler->actor_reqs, e_req); - - /* "BeachLander" sees everything as native. */ - e_req = req_from_str("UnitFlag", "Local", - FALSE, FALSE, TRUE, - "BeachLander"); - requirement_vector_append(&enabler->actor_reqs, e_req); - - action_enabler_add(enabler); - } action_enabler_list_iterate_end; - - - action_enabler_list_iterate(to_upgrade, conquer_city_enabler) { - /* Use for conquering from native terrain so conquest from - * non native terain is handled by "Conquer City 2". */ - e_req = req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, - FALSE, TRUE, TRUE, USP_NATIVE_TILE); - requirement_vector_append(&conquer_city_enabler->actor_reqs, e_req); - } action_enabler_list_iterate_end; - - action_enabler_list_destroy(to_upgrade); - } - } - - return TRUE; -} - -/**********************************************************************//** - Replace deprecated requirement type names with currently valid ones. -**************************************************************************/ -const char *rscompat_req_type_name_3_1(const char *old_type) -{ - if (!fc_strcasecmp("BaseFlag", old_type)) { - /* Remaining BaseFlag has been turned to an extra flag */ - return "ExtraFlag"; - } - - return old_type; -} - -/**********************************************************************//** - Replace deprecated requirement type names with currently valid ones. - - The extra arguments are for situation where some, but not all, instances - of a requirement type should become something else. -**************************************************************************/ -const char *rscompat_req_name_3_1(const char *type, - const char *old_name) -{ - if (!fc_strcasecmp("DiplRel", type) - && !fc_strcasecmp("Is foreign", old_name)) { - return "Foreign"; - } - - if (!fc_strcasecmp("AI", type) - && !fc_strcasecmp("Handicapped", old_name)) { - return "Restricted"; - } - - return old_name; -} - -/**********************************************************************//** - Replace deprecated unit type flag names with currently valid ones. -**************************************************************************/ -const char *rscompat_utype_flag_name_3_1(struct rscompat_info *compat, - const char *old_type) -{ - if (compat->compat_mode) { - } - - return old_type; -} - -/**********************************************************************//** - Adjust freeciv-3.0 ruleset extra definitions to freeciv-3.1 -**************************************************************************/ -void rscompat_extra_adjust_3_1(struct rscompat_info *compat, - struct extra_type *pextra) -{ - if (compat->compat_mode && compat->ver_terrain < 20) { - - /* Give remove cause ERM_ENTER for huts */ - if (is_extra_caused_by(pextra, EC_HUT)) { - pextra->rmcauses |= (1 << ERM_ENTER); - extra_to_removed_by_list(pextra, ERM_ENTER); - } - } -} diff --git a/server/rscompat.h b/server/rscompat.h index 587ca66ba8..11cd257e2b 100644 --- a/server/rscompat.h +++ b/server/rscompat.h @@ -61,22 +61,7 @@ struct requirement_vector *lookup_req_list(struct section_file *file, const char *sub, const char *rfor); -/* Functions specific to 3.0 -> 3.1 transition */ -bool rscompat_auto_attack_3_1(struct rscompat_info *compat, - struct action_auto_perf *auto_perf, - size_t psize, - enum unit_type_flag_id *protecor_flag); -const char *rscompat_req_type_name_3_1(const char *old_type); -const char *rscompat_req_name_3_1(const char *type, - const char *old_name); -const char *rscompat_utype_flag_name_3_1(struct rscompat_info *info, - const char *old_type); -bool rscompat_old_effect_3_1(const char *type, struct section_file *file, - const char *sec_name, struct rscompat_info *compat); -void rscompat_extra_adjust_3_1(struct rscompat_info *compat, - struct extra_type *pextra); -bool rscompat_old_slow_invasions_3_1(struct rscompat_info *compat, - bool slow_invasions); +/* Functions specific to 3.1 -> 3.2 transition */ #ifdef __cplusplus } diff --git a/server/ruleset.c b/server/ruleset.c index 71430137d3..b89191678d 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -390,10 +390,6 @@ struct requirement_vector *lookup_req_list(struct section_file *file, struct entry *pentry; struct requirement req; - if (compat->compat_mode) { - type = rscompat_req_type_name_3_1(type); - } - if (!(pentry = secfile_entry_lookup(file, "%s.%s%d.name", sec, sub, j))) { ruleset_error(LOG_ERROR, "%s", secfile_error()); @@ -477,16 +473,6 @@ struct requirement_vector *lookup_req_list(struct section_file *file, "'%s.%s%d'.", filename, sec, sub, j); } - if (compat->compat_mode) { - if (!fc_strcasecmp(type, universals_n_name(VUT_UTFLAG))) { - name = rscompat_utype_flag_name_3_1(compat, name); - } - } - - if (compat->compat_mode) { - name = rscompat_req_name_3_1(type, name); - } - req = req_from_str(type, range, survives, present, quiet, name); if (req.source.kind == universals_n_invalid()) { ruleset_error(LOG_ERROR, "\"%s\" [%s] has invalid or unknown req: " @@ -530,8 +516,7 @@ static bool lookup_cbonus_list(struct rscompat_info *compat, struct combat_bonus *bonus = fc_malloc(sizeof(*bonus)); const char *type; - bonus->flag = unit_type_flag_id_by_name(rscompat_utype_flag_name_3_1(compat, flag), - fc_strcasecmp); + bonus->flag = unit_type_flag_id_by_name(flag, fc_strcasecmp); if (!unit_type_flag_id_is_valid(bonus->flag)) { log_error("\"%s\": unknown flag name \"%s\" in '%s.%s'.", filename, flag, sec, sub); @@ -1506,8 +1491,7 @@ static bool load_unit_names(struct section_file *file, const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt", i); - if (unit_type_flag_id_by_name(rscompat_utype_flag_name_3_1(compat, flag), - fc_strcasecmp) + if (unit_type_flag_id_by_name(flag, fc_strcasecmp) != unit_type_flag_id_invalid()) { ruleset_error(LOG_ERROR, "\"%s\": Duplicate unit flag name '%s'", filename, flag); @@ -1837,8 +1821,7 @@ static bool load_ruleset_units(struct section_file *file, ival = unit_class_flag_id_by_name(sval, fc_strcasecmp); if (!unit_class_flag_id_is_valid(ival)) { ok = FALSE; - ival = unit_type_flag_id_by_name(rscompat_utype_flag_name_3_1(compat, sval), - fc_strcasecmp); + ival = unit_type_flag_id_by_name(sval, fc_strcasecmp); if (unit_type_flag_id_is_valid(ival)) { ruleset_error(LOG_ERROR, "\"%s\" unit_class \"%s\": unit_type flag \"%s\"!", @@ -2234,8 +2217,7 @@ static bool load_ruleset_units(struct section_file *file, if (compat->compat_mode && !fc_strcasecmp("Partial_Invis", sval)) { u->vlayer = V_INVIS; } else { - ival = unit_type_flag_id_by_name(rscompat_utype_flag_name_3_1(compat, sval), - fc_strcasecmp); + ival = unit_type_flag_id_by_name(sval, fc_strcasecmp); if (!unit_type_flag_id_is_valid(ival)) { ok = FALSE; ival = unit_class_flag_id_by_name(sval, fc_strcasecmp); @@ -3533,7 +3515,6 @@ static bool load_ruleset_terrain(struct section_file *file, pextra->helptext = lookup_strvec(file, section, "helptext"); } - rscompat_extra_adjust_3_1(compat, pextra); } extra_type_iterate_end; } @@ -5749,10 +5730,6 @@ static bool load_ruleset_effects(struct section_file *file, break; } - if (compat->compat_mode && rscompat_old_effect_3_1(type, file, sec_name, compat)) { - continue; - } - eff = effect_type_by_name(type, fc_strcasecmp); if (!effect_type_is_valid(eff)) { ruleset_error(LOG_ERROR, "\"%s\" [%s] lists unknown effect type \"%s\".", @@ -6438,15 +6415,6 @@ static bool load_ruleset_game(struct section_file *file, bool act, protecor_flag = NULL; } - if (!rscompat_auto_attack_3_1(compat, auto_perf, - psize, protecor_flag)) { - /* Upgrade failed */ - ruleset_error(LOG_ERROR, - "\"%s\": %s: failed to upgrade.", - filename, "auto_attack"); - ok = FALSE; - } - if (psize) { FC_FREE(protecor_flag); } @@ -6697,16 +6665,6 @@ static bool load_ruleset_game(struct section_file *file, bool act, } } - if (compat->compat_mode) { - bool slow_invasions - = secfile_lookup_bool_default(file, TRUE, - "global_unit_options.slow_invasions"); - - if (!rscompat_old_slow_invasions_3_1(compat, slow_invasions)) { - ok = FALSE; - } - } - if (ok) { const char *tus_text; -- 2.29.2