From 39dfbfd3eebe4f0d0097c851ce4b28ad222399ba Mon Sep 17 00:00:00 2001 From: newfrenchy83 Date: Tue, 8 Oct 2024 14:15:20 +0200 Subject: [PATCH] convert [filter_special_active] to [filter_special]active=yes like [has_attack] don't authorize activity check [filter_sepcial] is modified for simple_check or not. --- data/schema/filters/weapon.cfg | 2 +- .../EventWML/events-test_filter_ability.cfg | 63 +++++++++++++++++-- src/units/abilities.cpp | 20 +++++- src/units/attack_type.cpp | 4 +- wml_test_schedule | 1 + 5 files changed, 78 insertions(+), 12 deletions(-) diff --git a/data/schema/filters/weapon.cfg b/data/schema/filters/weapon.cfg index 9592d44875e3d..b2a92c4d922e7 100644 --- a/data/schema/filters/weapon.cfg +++ b/data/schema/filters/weapon.cfg @@ -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] diff --git a/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filter_ability.cfg b/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filter_ability.cfg index 79c050a0dc89c..56854683f3d8e 100644 --- a/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filter_ability.cfg +++ b/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filter_ability.cfg @@ -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. @@ -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})} @@ -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. @@ -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] @@ -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 ## diff --git a/src/units/abilities.cpp b/src/units/abilities.cpp index db8b586181662..01946916dd615 100644 --- a/src/units/abilities.cpp +++ b/src/units/abilities.cpp @@ -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; } @@ -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]); diff --git a/src/units/attack_type.cpp b/src/units/attack_type.cpp index e1b6af5dd25cf..0f878905be07f 100644 --- a/src/units/attack_type.cpp +++ b/src/units/attack_type.cpp @@ -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; } diff --git a/wml_test_schedule b/wml_test_schedule index 6c3f13f8efd54..ef645b9089577 100644 --- a/wml_test_schedule +++ b/wml_test_schedule @@ -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