diff --git a/data/schema/filters/abilities.cfg b/data/schema/filters/abilities.cfg index b6071b5711abe..b35ccaa0682d8 100644 --- a/data/schema/filters/abilities.cfg +++ b/data/schema/filters/abilities.cfg @@ -8,10 +8,15 @@ {SIMPLE_KEY apply_to string_list} {SIMPLE_KEY active_on string_list} {SIMPLE_KEY value s_int_range_list} + {SIMPLE_KEY default_value s_int} {SIMPLE_KEY add s_int_range_list} + {SIMPLE_KEY default_add s_int} {SIMPLE_KEY sub s_int_range_list} + {SIMPLE_KEY default_sub s_int} {SIMPLE_KEY multiply s_real_range_list} + {SIMPLE_KEY default_multiply s_real} {SIMPLE_KEY divide s_real_range_list} + {SIMPLE_KEY default_divide s_real} {SIMPLE_KEY affect_adjacent s_bool} {SIMPLE_KEY affect_self s_bool} {SIMPLE_KEY affect_allies s_bool} diff --git a/src/utils/config_filters.cpp b/src/utils/config_filters.cpp index c24ee384e1b06..fc59dcde28688 100644 --- a/src/utils/config_filters.cpp +++ b/src/utils/config_filters.cpp @@ -47,10 +47,12 @@ bool utils::config_filters::unsigned_matches_if_present(const config& filter, co return true; } - if(cfg[attribute].empty()) { + if(cfg[attribute].empty() && filter["default_" + attribute].empty()) { return false; } - return in_ranges(cfg[attribute].to_int(0), utils::parse_ranges_unsigned(filter[attribute].str())); + int def = filter["default_" + attribute].to_int(0); + + return in_ranges(cfg[attribute].to_int(def), utils::parse_ranges_unsigned(filter[attribute].str())); } bool utils::config_filters::int_matches_if_present(const config& filter, const config& cfg, const std::string& attribute) @@ -59,27 +61,30 @@ bool utils::config_filters::int_matches_if_present(const config& filter, const c return true; } - if(cfg[attribute].empty()) { + if(cfg[attribute].empty() && filter["default_" + attribute].empty()) { return false; } + int def = filter["default_" + attribute].to_int(0); - return in_ranges(cfg[attribute].to_int(0), utils::parse_ranges_int(filter[attribute].str())); + return in_ranges(cfg[attribute].to_int(def), utils::parse_ranges_int(filter[attribute].str())); } bool utils::config_filters::int_matches_if_present_or_negative( const config& filter, const config& cfg, const std::string& attribute, const std::string& opposite) { - if(filter[attribute].empty() || in_ranges(cfg[attribute].to_int(0), utils::parse_ranges_int(filter[attribute].str()))) { + if(int_matches_if_present(filter, cfg, attribute)) { return true; } // don't check for !cfg[opposite].empty(), as this assumes a default value of zero (similarly to // int_matches_if_present) if(cfg[attribute].empty()) { - if(cfg[opposite].empty()) { + if(cfg[opposite].empty() && filter["default_" + opposite].empty()) { return false; } - return in_ranges(-cfg[opposite].to_int(0), utils::parse_ranges_int(filter[attribute].str())); + int def = filter["default_" + opposite].to_int(0); + + return in_ranges(-cfg[opposite].to_int(def), utils::parse_ranges_int(filter[attribute].str())); } return false; @@ -91,9 +96,10 @@ bool utils::config_filters::double_matches_if_present(const config& filter, cons return true; } - if(cfg[attribute].empty()) { + if(cfg[attribute].empty() && filter["default_" + attribute].empty()) { return false; } + double def = filter["default_" + attribute].to_double(1); - return in_ranges(cfg[attribute].to_double(1), utils::parse_ranges_real(filter[attribute].str())); + return in_ranges(cfg[attribute].to_double(def), utils::parse_ranges_real(filter[attribute].str())); }