Skip to content

Commit

Permalink
convert [filter_special_active] to [filter_special]active=yes
Browse files Browse the repository at this point in the history
like [has_attack] don't authorize activity check [filter_sepcial] is modified for simple_check or not.
  • Loading branch information
newfrenchy83 committed Oct 8, 2024
1 parent 67fd95e commit 39dfbfd
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 12 deletions.
2 changes: 1 addition & 1 deletion data/schema/filters/weapon.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
{SIMPLE_KEY accuracy s_unsigned_range_list}
{SIMPLE_KEY movement_used s_unsigned_range_list}
{SIMPLE_KEY attacks_used s_unsigned_range_list}
{FILTER_TAG "filter_special_active" abilities ()}
{FILTER_TAG "filter_special" abilities {SIMPLE_KEY active s_bool}}
{FILTER_BOOLEAN_OPS weapon}
[/tag]
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
)}

#####
# API(s) being tested: [event][filter_attack][filter_special_active]
# API(s) being tested: [event][filter_attack][filter_special]active=yes
##
# Actions:
# Use the common setup from FILTER_ABILITY_TEST.
Expand All @@ -396,10 +396,11 @@
name=attack
first_time_only=no
[filter_attack]
[filter_special_active]
[filter_special]
active=yes
tag_name=drains
value=25
[/filter_special_active]
[/filter_special]
[/filter_attack]
{ASSERT ({VARIABLE_CONDITIONAL side_number equals 1})}
{ASSERT ({VARIABLE_CONDITIONAL triggers equals 0})}
Expand All @@ -412,7 +413,7 @@
)}

#####
# API(s) being tested: [event][filter_attack][filter_special_active]
# API(s) being tested: [event][filter_attack][filter_special]active=yes
##
# Actions:
# Use the common setup from FILTER_ABILITY_TEST.
Expand Down Expand Up @@ -445,10 +446,11 @@
name=attack
first_time_only=no
[filter_attack]
[filter_special_active]
[filter_special]
active=yes
tag_name=drains
value=25
[/filter_special_active]
[/filter_special]
[/filter_attack]
{FAIL}
[/event]
Expand All @@ -459,6 +461,55 @@
[/event]
)}

#####
# API(s) being tested: [event][filter_attack][filter_special]
##
# Actions:
# Use the common setup from FILTER_ABILITY_TEST.
# Add an event with a filter matching Alice's drains ability.
# Give Alice the Illuminates ability, which makes it the wrong time of day for her drains ability.
# The events in FILTER_ABILITY_TEST make Alice attacks Bob and then Bob attack Alice.
##
# Expected end state:
# The filtered event is triggered exactly once.
#####
{GENERIC_UNIT_TEST event_test_filter_special_simple_check (
{FILTER_ABILITY_TEST}
[event]
name=start
[object]
silent=yes
[effect]
apply_to=new_ability
[abilities]
{ABILITY_ILLUMINATES}
[/abilities]
[/effect]
[filter]
id=alice
[/filter]
[/object]
[/event]

[event]
name=attack
first_time_only=no
[filter_attack]
[filter_special]
tag_name=drains
value=25
[/filter_special]
[/filter_attack]
{ASSERT ({VARIABLE_CONDITIONAL side_number equals 1})}
{ASSERT ({VARIABLE_CONDITIONAL triggers equals 0})}
{VARIABLE_OP triggers add 1}
[/event]
[event]
name=turn 2
{RETURN ({VARIABLE_CONDITIONAL triggers equals 1})}
[/event]
)}

#undef FILTER_ABILITY_TEST

##
Expand Down
20 changes: 17 additions & 3 deletions src/units/abilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2057,15 +2057,19 @@ bool attack_type::special_matches_filter(const config & cfg, const std::string&
bool attack_type::has_special_with_filter(const config & filter) const
{
using namespace utils::config_filters;
bool simple_check = !filter["active"].to_bool();
for(const auto [key, cfg] : specials().all_children_range()) {
if(special_matches_filter(cfg, key, filter)){
if(simple_check){
return true;
}
if ( special_active(cfg, AFFECT_SELF, key) ) {
return true;
}
}
}
// Skip checking the opponent's attack?
if(!other_attack_){
if(simple_check || !other_attack_){
return false;
}

Expand All @@ -2082,14 +2086,24 @@ bool attack_type::has_special_with_filter(const config & filter) const

bool attack_type::has_ability_with_filter(const config & filter) const
{
bool simple_check = !filter["active"].to_bool();
const unit_map& units = get_unit_map();
if(self_){
for(const auto [key, cfg] : (*self_).abilities().all_children_range()) {
if(self_->ability_matches_filter(cfg, key, filter) && check_self_abilities(cfg, key)){
return true;
if(self_->ability_matches_filter(cfg, key, filter)){
if(simple_check){
return true;
}
if(check_self_abilities(cfg, key)){
return true;
}
}
}

if(simple_check){
return false;
}

const auto adjacent = get_adjacent_tiles(self_loc_);
for(unsigned i = 0; i < adjacent.size(); ++i) {
const unit_map::const_iterator it = units.find(adjacent[i]);
Expand Down
4 changes: 2 additions & 2 deletions src/units/attack_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ bool matches_simple_filter(const attack_type& attack, const config& filter, cons
}
}

//children filter_special_active are checked later,
//children filter_special are checked later,
//but only when the function doesn't return earlier
if(auto sub_filter_special = filter.optional_child("filter_special_active")) {
if(auto sub_filter_special = filter.optional_child("filter_special")) {
if(!attack.has_special_or_ability_with_filter(*sub_filter_special)) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions wml_test_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
0 event_test_filter_ability_active_inactive
0 event_test_filter_special_active
0 event_test_filter_special_active_inactive
0 event_test_filter_special_simple_check
0 event_test_filter_ability_with_value_by_default
0 event_test_filter_ability_no_match_by_default
0 event_test_filter_ability_apply_to_resistance
Expand Down

0 comments on commit 39dfbfd

Please sign in to comment.