Skip to content

Commit

Permalink
some change for affect_allies and remove type_value
Browse files Browse the repository at this point in the history
  • Loading branch information
newfrenchy83 committed Oct 10, 2023
1 parent 7b742b4 commit 9887e79
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 42 deletions.
3 changes: 1 addition & 2 deletions data/schema/filters/abilities.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
{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}
{FILTER_BOOLEAN_OPS abilities}
[/tag]
13 changes: 7 additions & 6 deletions data/schema/game_config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
value="none|one_side|both_sides"
[/type]
[type]
name="value_type"
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"
Expand Down Expand Up @@ -431,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
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
overwrite_specials=both_sides
[overwrite]
[filter_specials]
[not]
type_value=value
[/not]
add=1-14
[/filter_specials]
[/overwrite]
[/damage]
Expand Down
32 changes: 1 addition & 31 deletions src/units/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,28 +1421,6 @@ void unit::remove_ability_by_id(const std::string& ability)
}
}

static bool type_value_if_present(const config& filter, const config& cfg)
{
if(filter["type_value"].empty()) {
return true;
}

std::string cfg_type_value;
const std::vector<std::string> filter_attribute = utils::split(filter["type_value"]);
if(!cfg["value"].empty()){
cfg_type_value ="value";
} else if(!cfg["add"].empty()){
cfg_type_value ="add";
} else if(!cfg["sub"].empty()){
cfg_type_value ="sub";
} else if(!cfg["multiply"].empty()){
cfg_type_value ="multiply";
} else if(!cfg["divide"].empty()){
cfg_type_value ="divide";
}
return ( std::find(filter_attribute.begin(), filter_attribute.end(), cfg_type_value) != filter_attribute.end() );
}

static bool matches_ability_filter(const config & cfg, const std::string& tag_name, const config & filter)
{
using namespace utils::config_filters;
Expand All @@ -1457,13 +1435,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;
Expand Down Expand Up @@ -1520,9 +1493,6 @@ static bool matches_ability_filter(const config & cfg, const std::string& tag_na
if(!double_matches_if_present(filter, cfg, "divide"))
return false;

if(!type_value_if_present(filter, cfg))
return false;

// Passed all tests.
return true;
}
Expand Down
20 changes: 20 additions & 0 deletions src/utils/config_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,23 @@ bool utils::config_filters::double_matches_if_present(const config& filter, cons

return in_ranges<double>(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<std::string> 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() );
}
2 changes: 2 additions & 0 deletions src/utils/config_filters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9887e79

Please sign in to comment.