Skip to content

Commit

Permalink
fix affect_allies can have 3 value true,false and noexistent
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
newfrenchy83 committed Oct 12, 2023
1 parent 2bed16b commit 25a7d8f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/schema/filters/abilities.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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]
9 changes: 9 additions & 0 deletions data/schema/game_config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/units/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
23 changes: 23 additions & 0 deletions src/utils/config_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(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<std::string> 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;
}
2 changes: 2 additions & 0 deletions src/utils/config_filters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 25a7d8f

Please sign in to comment.