Skip to content

Commit

Permalink
extent can_bool to resistance and leadership and using 'type_changed_…
Browse files Browse the repository at this point in the history
…by_special' in replacement to type for check type changed by damage

The addition of 'type_changed_by_special' is a temporary solution to allow wml authors to be able to check types modified by damage ([filter_opponent)) in specials without systematically risking infinite recursion. The introduction in wesnoth 1.19 of [filter_specials] in [filter_attack/weapon] should make it obsolete.
  • Loading branch information
newfrenchy83 committed Oct 31, 2023
1 parent 3ac9891 commit bfaf432
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
8 changes: 8 additions & 0 deletions data/schema/filters/weapon.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@
{FILTER_BOOLEAN_OPS weapon}
[/tag]

[tag]
name="$filter_weapon_by_special"
max=0
super="$filter_weapon"
{SIMPLE_KEY type_changed_by_special string_list}
{FILTER_BOOLEAN_OPS weapon}
[/tag]

8 changes: 4 additions & 4 deletions data/schema/units/abilities.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
name="resistance"
max=infinite
super="units/unit_type/abilities/~value~"
{FILTER_TAG "filter_weapon" weapon ()}
{FILTER_TAG "filter_second_weapon" weapon ()}
{FILTER_TAG "filter_weapon" weapon_by_special ()}
{FILTER_TAG "filter_second_weapon" weapon_by_special ()}
[/tag]
[tag]
name="leadership"
Expand All @@ -95,8 +95,8 @@
{SIMPLE_KEY sub f_int}
{SIMPLE_KEY multiply f_int}
{SIMPLE_KEY divide f_int}
{FILTER_TAG "filter_weapon" weapon ()}
{FILTER_TAG "filter_second_weapon" weapon ()}
{FILTER_TAG "filter_weapon" weapon_by_special ()}
{FILTER_TAG "filter_second_weapon" weapon_by_special ()}
[/tag]
[tag]
name="illuminates"
Expand Down
8 changes: 4 additions & 4 deletions data/schema/units/specials.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

{FILTER_TAG "filter_adjacent" adjacent ()}
{FILTER_TAG "filter_adjacent_location" adjacent_location ()}
{FILTER_TAG "filter_self" unit {FILTER_TAG "filter_weapon" weapon ()}}
{FILTER_TAG "filter_opponent" unit {FILTER_TAG "filter_weapon" weapon ()}}
{FILTER_TAG "filter_attacker" unit {FILTER_TAG "filter_weapon" weapon ()}}
{FILTER_TAG "filter_defender" unit {FILTER_TAG "filter_weapon" weapon ()}}
{FILTER_TAG "filter_self" unit {FILTER_TAG "filter_weapon" weapon_by_special ()}}
{FILTER_TAG "filter_opponent" unit {FILTER_TAG "filter_weapon" weapon_by_special ()}}
{FILTER_TAG "filter_attacker" unit {FILTER_TAG "filter_weapon" weapon_by_special ()}}
{FILTER_TAG "filter_defender" unit {FILTER_TAG "filter_weapon" weapon_by_special ()}}
{WML_MERGE_KEYS}
[/tag]
# A few specials inheriting from ~generic~ are included here so that unit abilities can then inherit from them.
Expand Down
2 changes: 1 addition & 1 deletion src/units/abilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ bool unit::ability_affects_weapon(const config& cfg, const_attack_ptr weapon, bo
if(!weapon) {
return false;
}
return weapon->matches_filter(filter);
return weapon->matches_filter(filter, true);
}

bool unit::has_ability_type(const std::string& ability) const
Expand Down
12 changes: 11 additions & 1 deletion src/units/attack_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil
if ( !filter_name.empty() && std::find(filter_name.begin(), filter_name.end(), attack.id()) == filter_name.end() )
return false;

if ( !filter_type.empty()){
if (!filter_type.empty()){
if(can_loop){
if (std::find(filter_type.begin(), filter_type.end(), attack.type()) == filter_type.end() ){
return false;
Expand All @@ -157,6 +157,16 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil
}
}

if(can_loop){
const std::vector<std::string> filter_modified_type = utils::split(filter["type_changed_by_special"]);
if (!filter_modified_type.empty()){
std::pair<std::string, std::string> damage_type = attack.damage_type();
if ((std::find(filter_modified_type.begin(), filter_modified_type.end(), damage_type.first) == filter_modified_type.end()) && (std::find(filter_modified_type.begin(), filter_modified_type.end(), damage_type.second) == filter_modified_type.end())){
return false;
}
}
}

if(!filter_special.empty()) {
deprecated_message("special=", DEP_LEVEL::PREEMPTIVE, {1, 17, 0}, "Please use special_id or special_type instead");
bool found = false;
Expand Down

0 comments on commit bfaf432

Please sign in to comment.