From 98c21bf7dd2d0c6d0f5524da8b3ef515543fa594 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 3 Dec 2022 12:15:46 +0200 Subject: [PATCH 45/45] Rscompat: Setup "Clean" action enablers See osdn #46166 Signed-off-by: Marko Lindqvist --- common/extras.h | 4 ++- data/alien/terrain.ruleset | 2 +- data/civ1/terrain.ruleset | 2 +- data/civ2/terrain.ruleset | 2 +- data/civ2civ3/terrain.ruleset | 2 +- data/classic/terrain.ruleset | 2 +- data/goldkeep/terrain.ruleset | 2 +- data/granularity/terrain.ruleset | 2 +- data/multiplayer/terrain.ruleset | 2 +- data/sandbox/terrain.ruleset | 2 +- data/stub/terrain.ruleset | 2 +- data/webperimental/terrain.ruleset | 2 +- server/rscompat.c | 52 ++++++++++++++++++++++++++++++ server/rscompat.h | 3 +- server/ruleset.c | 4 +++ 15 files changed, 72 insertions(+), 13 deletions(-) diff --git a/common/extras.h b/common/extras.h index 4ca3ed89e2..e39b506a3d 100644 --- a/common/extras.h +++ b/common/extras.h @@ -68,13 +68,15 @@ struct road_type; #define SPECENUM_VALUE16 EF_USER_FLAG_6 #define SPECENUM_VALUE17 EF_USER_FLAG_7 #define SPECENUM_VALUE18 EF_USER_FLAG_8 +#define SPECENUM_VALUE19 EF_USER_FLAG_9 +#define SPECENUM_VALUE20 EF_USER_FLAG_10 #define SPECENUM_COUNT EF_COUNT #define SPECENUM_NAMEOVERRIDE #define SPECENUM_BITVECTOR bv_extra_flags #include "specenum_gen.h" -#define EF_LAST_USER_FLAG EF_USER_FLAG_8 +#define EF_LAST_USER_FLAG EF_USER_FLAG_10 #define MAX_NUM_USER_EXTRA_FLAGS (EF_LAST_USER_FLAG - EF_USER_FLAG_1 + 1) #define EXTRA_NONE (-1) diff --git a/data/alien/terrain.ruleset b/data/alien/terrain.ruleset index a253eabdb3..b04790b0c1 100644 --- a/data/alien/terrain.ruleset +++ b/data/alien/terrain.ruleset @@ -29,7 +29,7 @@ flags = _("NoFortify"), _("No units can fortify on this terrain.") } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/civ1/terrain.ruleset b/data/civ1/terrain.ruleset index 41adbae7a1..ae7686958c 100644 --- a/data/civ1/terrain.ruleset +++ b/data/civ1/terrain.ruleset @@ -26,7 +26,7 @@ flags = _("NoFortify"), _("No units can fortify on this terrain.") } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/civ2/terrain.ruleset b/data/civ2/terrain.ruleset index 9929d42394..63e47da927 100644 --- a/data/civ2/terrain.ruleset +++ b/data/civ2/terrain.ruleset @@ -26,7 +26,7 @@ flags = _("NoFortify"), _("No units can fortify on this terrain.") } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/civ2civ3/terrain.ruleset b/data/civ2civ3/terrain.ruleset index c60d0a2887..70f00cc65d 100644 --- a/data/civ2civ3/terrain.ruleset +++ b/data/civ2civ3/terrain.ruleset @@ -29,7 +29,7 @@ flags = _("NoFortify"), _("No units can fortify on this terrain.") } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/classic/terrain.ruleset b/data/classic/terrain.ruleset index 20707ad5a0..8644790431 100644 --- a/data/classic/terrain.ruleset +++ b/data/classic/terrain.ruleset @@ -28,7 +28,7 @@ flags = _("NoFortify"), _("No units can fortify on this terrain.") } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/goldkeep/terrain.ruleset b/data/goldkeep/terrain.ruleset index 4132760dbf..b732a02cb6 100644 --- a/data/goldkeep/terrain.ruleset +++ b/data/goldkeep/terrain.ruleset @@ -30,7 +30,7 @@ flags = _("NoFortify"), _("No units can fortify on this terrain.") } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/granularity/terrain.ruleset b/data/granularity/terrain.ruleset index 35f2b6a921..4c992a9060 100644 --- a/data/granularity/terrain.ruleset +++ b/data/granularity/terrain.ruleset @@ -25,7 +25,7 @@ format_version = 30 ; { "name", "helptxt" ; } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/multiplayer/terrain.ruleset b/data/multiplayer/terrain.ruleset index c2490554d7..2888ef1cd7 100644 --- a/data/multiplayer/terrain.ruleset +++ b/data/multiplayer/terrain.ruleset @@ -28,7 +28,7 @@ flags = _("NoFortify"), _("No units can fortify on this terrain.") } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/sandbox/terrain.ruleset b/data/sandbox/terrain.ruleset index fa9923e041..1ff84e9e3f 100644 --- a/data/sandbox/terrain.ruleset +++ b/data/sandbox/terrain.ruleset @@ -30,7 +30,7 @@ flags = _("NoFortify"), _("No units can fortify on this terrain.") } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/stub/terrain.ruleset b/data/stub/terrain.ruleset index 34e657e73c..382e84a082 100644 --- a/data/stub/terrain.ruleset +++ b/data/stub/terrain.ruleset @@ -16,7 +16,7 @@ format_version = 30 ; { "name", "helptxt" ; } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/webperimental/terrain.ruleset b/data/webperimental/terrain.ruleset index b5836eed85..7f4c1d11fd 100644 --- a/data/webperimental/terrain.ruleset +++ b/data/webperimental/terrain.ruleset @@ -28,7 +28,7 @@ flags = _("NoFortify"), _("No units can fortify on this terrain.") } -; Names for custom extra flags. There can be up to 8 of these. +; Names for custom extra flags. There can be up to 10 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/server/rscompat.c b/server/rscompat.c index b8ba4d5c1f..b30751a4d2 100644 --- a/server/rscompat.c +++ b/server/rscompat.c @@ -376,6 +376,31 @@ void rscompat_postprocess(struct rscompat_info *info) action_rule_name(paction))); } action_iterate_end; + action_enablers_iterate(ae) { + if (ae->action == ACTION_CLEAN_POLLUTION) { + /* TODO: Stop making the copy to preserve enabler for + * the original action. */ + action_enabler_add(action_enabler_copy(ae)); + + ae->action = ACTION_CLEAN; + requirement_vector_append(&ae->target_reqs, + req_from_str("ExtraFlag", "Local", + FALSE, TRUE, TRUE, + "CleanAsPollution")); + } + if (ae->action == ACTION_CLEAN_FALLOUT) { + /* TODO: Stop making the copy to preserve enabler for + * the original action. */ + action_enabler_add(action_enabler_copy(ae)); + + ae->action = ACTION_CLEAN; + requirement_vector_append(&ae->target_reqs, + req_from_str("ExtraFlag", "Local", + FALSE, TRUE, TRUE, + "CleanAsFallout")); + } + } 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, @@ -499,6 +524,23 @@ void rscompat_req_adjust_3_2(const struct rscompat_info *compat, } } +/**********************************************************************//** + Add user extra flags needed in ruleset update from 3.1 to 3.2 + + @return Number of flags added +**************************************************************************/ +int add_user_extra_flags_3_2(int start) +{ + int i = 0; + + set_user_extra_flag_name(EF_USER_FLAG_1 + start + i++, + "CleanAsPollution", NULL); + set_user_extra_flag_name(EF_USER_FLAG_1 + start + i++, + "CleanAsFallout", NULL); + + return i; +} + /**********************************************************************//** Adjust values of an extra loaded from a 3.1 ruleset. **************************************************************************/ @@ -516,6 +558,16 @@ void rscompat_extra_adjust_3_2(struct extra_type *pextra) FALSE, TRUE, FALSE, "-980")); } + + if (is_extra_removed_by(pextra, ERM_CLEANPOLLUTION)) { + BV_SET(pextra->flags, + extra_flag_id_by_name("CleanAsPollution", fc_strcasecmp)); + } + + if (is_extra_removed_by(pextra, ERM_CLEANFALLOUT)) { + BV_SET(pextra->flags, + extra_flag_id_by_name("CleanAsFallout", fc_strcasecmp)); + } } /**********************************************************************//** diff --git a/server/rscompat.h b/server/rscompat.h index 0849968be1..1cbb0acf16 100644 --- a/server/rscompat.h +++ b/server/rscompat.h @@ -66,6 +66,7 @@ const char *rscompat_req_range_3_2(struct rscompat_info *compat, void rscompat_req_adjust_3_2(const struct rscompat_info *compat, const char **ptype, const char **pname, bool *ppresent, const char *sec_name); +int add_user_extra_flags_3_2(int start); void rscompat_extra_adjust_3_2(struct extra_type *pextra); bool rscompat_setting_needs_special_handling(const char *name); void rscompat_settings_do_special_handling(struct section_file *file, @@ -75,4 +76,4 @@ void rscompat_settings_do_special_handling(struct section_file *file, } #endif /* __cplusplus */ -#endif /* FC__RSCOMPAT_H */ +#endif /* FC__RSCOMPAT_H */ diff --git a/server/ruleset.c b/server/ruleset.c index 58ba67fd6c..ba79594214 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -2888,6 +2888,10 @@ static bool load_terrain_names(struct section_file *file, set_user_extra_flag_name(EF_USER_FLAG_1 + i, flag, helptxt); } + if (compat->compat_mode && compat->version < RSFORMAT_3_2) { + i += add_user_extra_flags_3_2(i); + } + if (ok) { /* Blank the remaining extra user flag slots. */ for (; i < MAX_NUM_USER_EXTRA_FLAGS; i++) { -- 2.35.1