Skip to content

Commit

Permalink
some change for type value and affect_allies
Browse files Browse the repository at this point in the history
  • Loading branch information
newfrenchy83 committed Oct 10, 2023
1 parent 7b742b4 commit b1e9e5c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions data/schema/filters/abilities.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
{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}
{SIMPLE_KEY type_value value_type}
{FILTER_BOOLEAN_OPS abilities}
[/tag]
11 changes: 8 additions & 3 deletions data/schema/game_config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@
[/type]
[type]
name="value_type"
value="|value|add|sub|multiply|divide"
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|is_empty"
[/element]
[/list]
[/type]
[type]
name="addon_type"
Expand Down Expand Up @@ -431,6 +435,7 @@
{SUBST_TYPE anim_hits}
{SUBST_TYPE f_int}
{SUBST_TYPE alignment}
{SUBST_TYPE bool_or_empty}
[type]
name="global"
value="global"
Expand Down
37 changes: 26 additions & 11 deletions src/units/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,20 +1429,40 @@ static bool type_value_if_present(const config& filter, const config& cfg)

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

bool 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)){
cfg_bool_value = "is_empty";
} else if(cfg.has_attribute(attribute)){
if(!cfg[attribute].to_bool()){
cfg_bool_value = "no";
} else if(cfg[attribute].to_bool()){
cfg_bool_value = "yes";
}
}
return ( std::find(filter_attribute.begin(), filter_attribute.end(), cfg_bool_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 +1477,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

0 comments on commit b1e9e5c

Please sign in to comment.