From fb56aba14f6ab40977d966dcca8d5c6c4ff836a5 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 16 Jun 2023 12:25:24 +0300 Subject: [PATCH 28/28] rscompat: Stop relying on ACTION_CLEAN_POLLUTION/ACTION_CLEAN_FALLOUT See osdn #48210 Signed-off-by: Marko Lindqvist --- server/rscompat.c | 68 ++++++++++++++++++++++++++--------------------- server/rscompat.h | 9 +++++-- server/ruleset.c | 9 +++++-- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/server/rscompat.c b/server/rscompat.c index 9efe56c03e..6383612015 100644 --- a/server/rscompat.c +++ b/server/rscompat.c @@ -386,35 +386,6 @@ void rscompat_postprocess(struct rscompat_info *info) action_rule_name(paction))); } action_iterate_end; - action_enablers_iterate(ae) { - if (enabler_get_action_id(ae) == ACTION_CLEAN_POLLUTION) { - /* TODO: Stop making the copy to preserve enabler for - * the original action. */ - struct action_enabler *copy = action_enabler_copy(ae); - - copy->action = ACTION_CLEAN; - requirement_vector_append(©->target_reqs, - req_from_str("ExtraFlag", "Local", - FALSE, TRUE, TRUE, - "CleanAsPollution")); - - action_enabler_add(copy); - } - if (enabler_get_action_id(ae) == ACTION_CLEAN_FALLOUT) { - /* TODO: Stop making the copy to preserve enabler for - * the original action. */ - struct action_enabler *copy = action_enabler_copy(ae); - - copy->action = ACTION_CLEAN; - requirement_vector_append(©->target_reqs, - req_from_str("ExtraFlag", "Local", - FALSE, TRUE, TRUE, - "CleanAsFallout")); - - action_enabler_add(copy); - } - } action_enablers_iterate_end; - /* That Attack and Bombard can't destroy a city * has moved to the ruleset. */ peffect = effect_new(EFT_UNIT_NO_LOSE_POP, @@ -747,11 +718,46 @@ bool rscompat_terrain_extra_rmtime_3_2(struct section_file *file, return ok; } +/**********************************************************************//** + Adjust freeciv-3.1 ruleset action rule name to freeciv-3.2 +**************************************************************************/ +const char *rscompat_action_rule_name_3_2(struct rscompat_info *compat, + const char *orig) +{ + if (compat->compat_mode && compat->version < RSFORMAT_3_2 + && (!fc_strcasecmp("CleanPollution", orig) + || !fc_strcasecmp("CleanFallout", orig))) { + return "Clean"; + } + + return orig; +} + +/**********************************************************************//** + Adjust freeciv-3.1 ruleset action enabler to freeciv-3.2 +**************************************************************************/ +void rscompat_action_enabler_adjust_3_2(struct rscompat_info *compat, + struct action_enabler *enabler, + const char *orig_name) +{ + if (!fc_strcasecmp("CleanAsPollution", orig_name)) { + requirement_vector_append(&enabler->target_reqs, + req_from_str("ExtraFlag", "Local", + FALSE, TRUE, TRUE, + "CleanAsPollution")); + } else if (!fc_strcasecmp("CleanAsFallout", orig_name)) { + requirement_vector_append(&enabler->target_reqs, + req_from_str("ExtraFlag", "Local", + FALSE, TRUE, TRUE, + "CleanAsFallout")); + } +} + /**********************************************************************//** Adjust freeciv-3.1 ruleset action ui_name to freeciv-3.2 **************************************************************************/ -const char *rscompat_action_ui_name_S3_2(struct rscompat_info *compat, - int act_id) +const char *rscompat_action_ui_name_3_2(struct rscompat_info *compat, + int act_id) { if (compat->compat_mode && compat->version < RSFORMAT_3_2) { if (act_id == ACTION_TRANSPORT_DEBOARD) { diff --git a/server/rscompat.h b/server/rscompat.h index bc0229700c..263b43b2d1 100644 --- a/server/rscompat.h +++ b/server/rscompat.h @@ -76,8 +76,13 @@ void rscompat_settings_do_special_handling(struct section_file *file, bool rscompat_terrain_extra_rmtime_3_2(struct section_file *file, const char *tsection, struct terrain *pterrain); -const char *rscompat_action_ui_name_S3_2(struct rscompat_info *compat, - int act_id); +const char *rscompat_action_rule_name_3_2(struct rscompat_info *compat, + const char *orig); +const char *rscompat_action_ui_name_3_2(struct rscompat_info *compat, + int act_id); +void rscompat_action_enabler_adjust_3_2(struct rscompat_info *compat, + struct action_enabler *enabler, + const char *orig_name); /* In ruleset.c, but should not be in public interface - make static again once * rscompat.c no longer needs. */ diff --git a/server/ruleset.c b/server/ruleset.c index fa9267ae5d..4d04464097 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -7824,7 +7824,7 @@ static bool load_ruleset_actions(struct section_file *file, } else { load_action_ui_name(file, act_id, action_ui_name_ruleset_var_name(act_id), - rscompat_action_ui_name_S3_2(compat, act_id)); + rscompat_action_ui_name_3_2(compat, act_id)); } if (!ok) { @@ -7975,10 +7975,13 @@ static bool load_ruleset_actions(struct section_file *file, struct requirement_vector *actor_reqs; struct requirement_vector *target_reqs; const char *action_text; + const char *orig_name; enabler = action_enabler_new(); - action_text = secfile_lookup_str(file, "%s.action", sec_name); + orig_name = secfile_lookup_str(file, "%s.action", sec_name); + + action_text = rscompat_action_rule_name_3_2(compat, orig_name); if (action_text == NULL) { ruleset_error(NULL, LOG_ERROR, @@ -8015,6 +8018,8 @@ static bool load_ruleset_actions(struct section_file *file, requirement_vector_copy(&enabler->target_reqs, target_reqs); + rscompat_action_enabler_adjust_3_2(compat, enabler, orig_name); + action_enabler_add(enabler); } section_list_iterate_end; -- 2.39.2