diff --git a/src/units/unit.cpp b/src/units/unit.cpp index 8bfbab55916c0..4883b373432c2 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -1482,19 +1482,35 @@ static bool matches_ability_filter(const config & cfg, const std::string& tag_na if(!string_matches_if_present(filter, cfg, "active_on", "both")) return false; - if(!int_matches_if_present(filter, cfg, "value")) - return false; + if(!filter["value"].empty()){ + if(tag_name == "drains" || tag_name == "berserk" || tag_name != "heal_on_hit"){ + int def = 0; + if(tag_name == "drains"){ + def = 25; + } + if(tag_name == "berserk"){ + def = 1; + } + if(!int_matches_if_present(filter, cfg, "value" , def)){ + return false; + } + } else if(cfg["value"].empty()){ + return false; + } + if(!int_matches_if_present(filter, cfg, "value")) + return false; + } - if(!int_matches_if_present_or_negative(filter, cfg, "add", "sub")) + if((!filter["add"].empty() && (cfg["add"].empty() && cfg["sub"].empty()) || !int_matches_if_present_or_negative(filter, cfg, "add", "sub"))) return false; - if(!int_matches_if_present_or_negative(filter, cfg, "sub", "add")) + if((!filter["sub"].empty() && (cfg["add"].empty() && cfg["sub"].empty()) || !int_matches_if_present_or_negative(filter, cfg, "sub", "add"))) return false; - if(!double_matches_if_present(filter, cfg, "multiply")) + if(!filter["multiply"].empty() && (cfg["multiply"].empty() || !double_matches_if_present(filter, cfg, "multiply"))) return false; - if(!double_matches_if_present(filter, cfg, "divide")) + if(!filter["divide"].empty() && (cfg["divide"].empty() || !double_matches_if_present(filter, cfg, "divide"))) return false; if(!type_value_if_present(filter, cfg)) diff --git a/src/utils/config_filters.cpp b/src/utils/config_filters.cpp index df7e8faa3b704..d4438e1867843 100644 --- a/src/utils/config_filters.cpp +++ b/src/utils/config_filters.cpp @@ -50,13 +50,13 @@ bool utils::config_filters::unsigned_matches_if_present(const config& filter, co return in_ranges(cfg[attribute].to_int(0), 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) +bool utils::config_filters::int_matches_if_present(const config& filter, const config& cfg, const std::string& attribute, int def) { if(filter[attribute].empty()) { return true; } - 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( diff --git a/src/utils/config_filters.hpp b/src/utils/config_filters.hpp index ba65e3d25fa72..d5e1644eb62c8 100644 --- a/src/utils/config_filters.hpp +++ b/src/utils/config_filters.hpp @@ -35,7 +35,7 @@ namespace utils::config_filters bool bool_matches_if_present(const config& filter, const config& cfg, const std::string& attribute, bool def); bool double_matches_if_present(const config& filter, const config& cfg, const std::string& attribute); -bool int_matches_if_present(const config& filter, const config& cfg, const std::string& attribute); +bool int_matches_if_present(const config& filter, const config& cfg, const std::string& attribute, int def = 0); /** * Restricts filters to only looking for values that are zero or more.