diff --git a/data/schema/filters/abilities.cfg b/data/schema/filters/abilities.cfg index 55860ca7c5a78..ff8c84be63f73 100644 --- a/data/schema/filters/abilities.cfg +++ b/data/schema/filters/abilities.cfg @@ -14,8 +14,8 @@ {SIMPLE_KEY divide s_real_range_list} {SIMPLE_KEY affect_adjacent s_bool} {SIMPLE_KEY affect_self s_bool} - {DEFAULT_KEY affect_allies affect_allies_filter empty} + {SIMPLE_KEY affect_allies bool_or_empty} {SIMPLE_KEY affect_enemies s_bool} - {DEFAULT_KEY type_value value_type empty} + {SIMPLE_KEY type_value value_type} {FILTER_BOOLEAN_OPS abilities} [/tag] diff --git a/data/schema/game_config.cfg b/data/schema/game_config.cfg index 966017b66c3f1..543a5b504eaef 100644 --- a/data/schema/game_config.cfg +++ b/data/schema/game_config.cfg @@ -42,11 +42,15 @@ [/type] [type] name="value_type" - value="|value|add|sub|multiply|divide" + value="value|add|sub|multiply|divide" [/type] [type] - name="affect_allies_filter" - value="empty|yes|no" + name="bool_or_empty" + [list] + [element] + value="true|false|yes|no|empty" + [/element] + [/list] [/type] [type] name="addon_type" @@ -431,6 +435,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 bee19fc83ec95..0ca44c68df60a 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -1429,15 +1429,15 @@ static bool type_value_if_present(const config& filter, const config& cfg) std::string cfg_type_value; const std::vector filter_attribute = utils::split(filter["type_value"]); - if(!cfg["value"].empty()){ + if(cfg.has_attribute("value")){ cfg_type_value ="value"; - } else if(!cfg["add"].empty()){ + } else if(cfg.has_attribute("add")){ cfg_type_value ="add"; - } else if(!cfg["sub"].empty()){ + } else if(cfg.has_attribute("sub")){ cfg_type_value ="sub"; - } else if(!cfg["multiply"].empty()){ + } else if(cfg.has_attribute("multiply")){ cfg_type_value ="multiply"; - } else if(!cfg["divide"].empty()){ + } else if(cfg.has_attribute("divide")){ cfg_type_value ="divide"; } return ( std::find(filter_attribute.begin(), filter_attribute.end(), cfg_type_value) != filter_attribute.end() ); @@ -1457,13 +1457,8 @@ 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(!filter["affect_allies"].empty() && !cfg["affect_allies"].empty()){ - if(!bool_matches_if_present(filter, cfg, "affect_allies", true)){ - return false; - } - } else if(!filter["affect_allies"].empty() && filter["affect_allies"].str() != "empty"){ + if(!bool_or_empty(filter, cfg, "affect_allies")) return false; - } if(!bool_matches_if_present(filter, cfg, "affect_enemies", false)) return false; diff --git a/src/utils/config_filters.cpp b/src/utils/config_filters.cpp index a5ca9f1d38f91..ce86571793cf4 100644 --- a/src/utils/config_filters.cpp +++ b/src/utils/config_filters.cpp @@ -95,3 +95,23 @@ bool utils::config_filters::double_matches_if_present(const config& filter, cons return in_ranges(cfg[attribute].to_double(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].empty()) { + return true; + } + + std::string cfg_bool_value; + const std::vector filter_attribute = utils::split(filter[attribute]); + if(cfg.has_attribute(attribute)){ + if(!cfg[attribute].to_bool()){ + cfg_bool_value = "no"; + } else if(cfg[attribute].to_bool()){ + cfg_bool_value = "yes"; + } + } else { + cfg_bool_value = "empty"; + } + return ( std::find(filter_attribute.begin(), filter_attribute.end(), cfg_bool_value) != filter_attribute.end() ); +} diff --git a/src/utils/config_filters.hpp b/src/utils/config_filters.hpp index b351cc3604785..e656106192524 100644 --- a/src/utils/config_filters.hpp +++ b/src/utils/config_filters.hpp @@ -61,4 +61,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