From 25a7d8f5aec247291a94d292312a96b2f95a697f Mon Sep 17 00:00:00 2001 From: newfrenchy83 Date: Sat, 7 Oct 2023 17:42:33 +0200 Subject: [PATCH] fix affect_allies can have 3 value true,false and noexistent when abilities don't have affect_allies implemented, then onlyunit same side are affected, if affect_allies=yes, unit of allied side inclus and if falsethen none unit allied or same side are affected. --- data/schema/filters/abilities.cfg | 2 +- data/schema/game_config.cfg | 9 +++++++++ src/units/unit.cpp | 2 +- src/utils/config_filters.cpp | 23 +++++++++++++++++++++++ src/utils/config_filters.hpp | 2 ++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/data/schema/filters/abilities.cfg b/data/schema/filters/abilities.cfg index 0488ea0d73aec..16ccb956d9ce6 100644 --- a/data/schema/filters/abilities.cfg +++ b/data/schema/filters/abilities.cfg @@ -14,7 +14,7 @@ {SIMPLE_KEY divide s_real_range_list} {SIMPLE_KEY affect_adjacent s_bool} {SIMPLE_KEY affect_self s_bool} - {SIMPLE_KEY affect_allies s_bool} + {SIMPLE_KEY affect_allies bool_or_empty} {SIMPLE_KEY affect_enemies s_bool} {FILTER_BOOLEAN_OPS abilities} [/tag] diff --git a/data/schema/game_config.cfg b/data/schema/game_config.cfg index 868f4e95a569e..6b760228b3535 100644 --- a/data/schema/game_config.cfg +++ b/data/schema/game_config.cfg @@ -40,6 +40,14 @@ name="ability_overwrite" value="none|one_side|both_sides" [/type] + [type] + name="bool_or_empty" + [list] + [element] + value="true|false|yes|no|empty" + [/element] + [/list] + [/type] [type] name="addon_type" value="sp|mp|hybrid" @@ -423,6 +431,7 @@ {SUBST_TYPE anim_hits} {SUBST_TYPE f_int} {SUBST_TYPE alignment} + {SUBST_TYPE bool_or_empty} [type] name="global" value="global" diff --git a/src/units/unit.cpp b/src/units/unit.cpp index 2d0f276720f65..b02508ad30f54 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -1435,7 +1435,7 @@ static bool matches_ability_filter(const config & cfg, const std::string& tag_na if(!bool_matches_if_present(filter, cfg, "affect_self", true)) return false; - if(!bool_matches_if_present(filter, cfg, "affect_allies", true)) + if(!bool_or_empty(filter, cfg, "affect_allies")) return false; if(!bool_matches_if_present(filter, cfg, "affect_enemies", false)) diff --git a/src/utils/config_filters.cpp b/src/utils/config_filters.cpp index 683e6912abf98..94760495e6c3d 100644 --- a/src/utils/config_filters.cpp +++ b/src/utils/config_filters.cpp @@ -98,3 +98,26 @@ bool utils::config_filters::double_matches_if_present(const config& filter, cons double value_def = def ? (*def) : 1; return in_ranges(cfg[attribute].to_double(value_def), utils::parse_ranges_real(filter[attribute].str())); } + +bool utils::config_filters::bool_or_empty(const config& filter, const config& cfg, const std::string& attribute) +{ + if(filter[attribute].blank()) { + return true; + } + + std::set filter_attribute = utils::split_set(filter[attribute].str()); + bool is_matches = false; + if(cfg.has_attribute(attribute)){ + if(filter_attribute.count("yes") != 0 || filter_attribute.count("true") != 0){ + is_matches = cfg[attribute].to_bool(); + } + if(!is_matches && (filter_attribute.count("no") != 0 || filter_attribute.count("false") != 0)){ + is_matches = !cfg[attribute].to_bool(); + } + } else { + if(filter_attribute.count("empty") != 0){ + is_matches = true; + } + } + return is_matches; +} diff --git a/src/utils/config_filters.hpp b/src/utils/config_filters.hpp index 058c3e795d71e..a16c7a5a7cf82 100644 --- a/src/utils/config_filters.hpp +++ b/src/utils/config_filters.hpp @@ -67,4 +67,6 @@ bool int_matches_if_present_or_negative( bool string_matches_if_present( const config& filter, const config& cfg, const std::string& attribute, const std::string& def); +bool bool_or_empty(const config& filter, const config& cfg, const std::string& attribute); + } // namespace utils::config_filters