Skip to content

Commit

Permalink
gt
Browse files Browse the repository at this point in the history
  • Loading branch information
newfrenchy83 committed Sep 29, 2023
1 parent 81d36ad commit 7a42ea8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
33 changes: 18 additions & 15 deletions src/units/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,31 +1483,34 @@ static bool matches_ability_filter(const config & cfg, const std::string& tag_na
return false;

if(!filter["value"].empty()){
int def = 0;
bool by_default = false;
if(tag_name != "drains" && tag_name != "berserk" && tag_name != "heal_on_hit" && tag_name != "regenerate" && tag_name != "heals"){
by_default = true;
}
if(tag_name == "drains"){
def = 25;
}
if(tag_name == "berserk"){
def = 1;
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" , def, by_default))
if(!int_matches_if_present(filter, cfg, "value"))
return false;
}

if(!int_matches_if_present_or_negative(filter, cfg, "add", "sub"))
if((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((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(cfg["multiply"].empty() || !double_matches_if_present(filter, cfg, "multiply"))
return false;

if(!double_matches_if_present(filter, cfg, "divide"))
if(cfg["divide"].empty() || !double_matches_if_present(filter, cfg, "divide"))
return false;

if(!type_value_if_present(filter, cfg))
Expand Down
16 changes: 1 addition & 15 deletions src/utils/config_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,15 @@ bool utils::config_filters::unsigned_matches_if_present(const config& filter, co
return true;
}

if(cfg[attribute].empty()) {
return false;
}
return in_ranges<int>(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, int def , bool by_default)
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;
}

if(cfg[attribute].empty() && !by_default) {
return false;
}

return in_ranges<int>(cfg[attribute].to_int(def), utils::parse_ranges_int(filter[attribute].str()));
}

Expand All @@ -76,9 +69,6 @@ bool utils::config_filters::int_matches_if_present_or_negative(
// 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()) {
return false;
}
return in_ranges<int>(-cfg[opposite].to_int(0), utils::parse_ranges_int(filter[attribute].str()));
}

Expand All @@ -91,9 +81,5 @@ bool utils::config_filters::double_matches_if_present(const config& filter, cons
return true;
}

if(cfg[attribute].empty()) {
return false;
}

return in_ranges<double>(cfg[attribute].to_double(1), utils::parse_ranges_real(filter[attribute].str()));
}
2 changes: 1 addition & 1 deletion src/utils/config_filters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, int def = 0 , bool by_default = false);
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.
Expand Down

0 comments on commit 7a42ea8

Please sign in to comment.