Skip to content

Commit

Permalink
add a 'type' and 'added_type' attribute in [damage] special or abilit…
Browse files Browse the repository at this point in the history
…y who modify the type of attack used

At the suggestion of @stevecotton, I propose a special 'type' and 'added_type' attribute capable of modifying the type of attack used when the conditions are met.
  • Loading branch information
newfrenchy83 committed Sep 26, 2023
1 parent 29777d3 commit 5ecaf34
Show file tree
Hide file tree
Showing 14 changed files with 444 additions and 22 deletions.
2 changes: 2 additions & 0 deletions changelog_entries/[damage]_special_changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### WML Engine
* Add a 'type' and 'added_type' attribute to [damage] to change the type of attack under specific conditions (terrain, time of day, leadership etc...)
9 changes: 8 additions & 1 deletion data/schema/filters/weapon.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

[tag]
name="$filter_weapon"
name="$filter_weapon_common"
max=0
{SIMPLE_KEY range string_list}
{SIMPLE_KEY name string_list}
Expand All @@ -21,3 +21,10 @@
{FILTER_BOOLEAN_OPS weapon}
[/tag]

[tag]
name="$filter_weapon"
max=0
super="$filter_weapon_common"
{SIMPLE_KEY added_type string_list}
{SIMPLE_KEY modified_damage s_unsigned_range_list}
[/tag]
2 changes: 1 addition & 1 deletion data/schema/units/abilities.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name={NAME}
max=infinite
super="units/unit_type/abilities/~generic~,units/unit_type/attack/specials/" + {NAME}
{FILTER_TAG "filter_student" unit {FILTER_TAG "filter_weapon" weapon ()}}
{FILTER_TAG "filter_student" unit {FILTER_TAG "filter_weapon" weapon_common ()}}
{DEFAULT_KEY overwrite_specials ability_overwrite none}
[/tag]
#enddef
Expand Down
10 changes: 6 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_common ()}}
{FILTER_TAG "filter_opponent" unit {FILTER_TAG "filter_weapon" weapon_common ()}}
{FILTER_TAG "filter_attacker" unit {FILTER_TAG "filter_weapon" weapon_common ()}}
{FILTER_TAG "filter_defender" unit {FILTER_TAG "filter_weapon" weapon_common ()}}
{WML_MERGE_KEYS}
[/tag]
# A few specials inheriting from ~generic~ are included here so that unit abilities can then inherit from them.
Expand Down Expand Up @@ -69,6 +69,8 @@
name="damage"
max=infinite
super="units/unit_type/attack/specials/~value~"
{SIMPLE_KEY type string}
{SIMPLE_KEY added_type string}
[/tag]
[tag]
name="drains"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@

{GENERIC_UNIT_TEST "damage_type_test" (
[event]
name=start
[modify_unit]
[filter]
[/filter]
max_hitpoints=100
hitpoints=100
attacks_left=1
[/modify_unit]
[object]
silent=yes
[effect]
apply_to=resistance
replace=yes
[resistance]
arcane=50
fire=200
[/resistance]
[/effect]
[effect]
apply_to=attack
[set_specials]
mode=append
[attacks]
value=1
[/attacks]
[damage]
value=12
[/damage]
[damage]
type=fire
[/damage]
[damage]
type=cold
[/damage]
[damage]
type=cold
[/damage]
[chance_to_hit]
value=100
[/chance_to_hit]
[/set_specials]
[/effect]
[filter]
id=bob
[/filter]
[/object]
[object]
silent=yes
[effect]
apply_to=resistance
replace=yes
[resistance]
cold=200
fire=50
[/resistance]
[/effect]
[effect]
apply_to=attack
[set_specials]
mode=append
[attacks]
value=1
[/attacks]
[damage]
value=12
[/damage]
[damage]
type=cold
[/damage]
[damage]
type=arcane
[/damage]
[damage]
type=arcane
[/damage]
[damage]
type=fire
[/damage]
[damage]
type=fire
[/damage]
[damage]
type=fire
[/damage]
[chance_to_hit]
value=100
[/chance_to_hit]
[/set_specials]
[/effect]
[filter]
id=alice
[/filter]
[/object]

[store_unit]
[filter]
id=alice
[/filter]
variable=a
kill=yes
[/store_unit]
[store_unit]
[filter]
id=bob
[/filter]
variable=b
[/store_unit]
[unstore_unit]
variable=a
find_vacant=yes
x,y=$b.x,$b.y
[/unstore_unit]
[store_unit]
[filter]
id=alice
[/filter]
variable=a
[/store_unit]

[do_command]
[attack]
weapon=0
defender_weapon=0
[source]
x,y=$a.x,$a.y
[/source]
[destination]
x,y=$b.x,$b.y
[/destination]
[/attack]
[/do_command]
[store_unit]
[filter]
id=alice
[/filter]
variable=a
[/store_unit]
[store_unit]
[filter]
id=bob
[/filter]
variable=b
[/store_unit]
#damage without modification are 12, if test fail hitpoints !=76
#if succed then damage by alice 24(bob vulnerable to fire and fire prioritized)
#if succed then damage by bob 24(alice vulnerable to cold, cold priority is 1)
{ASSERT ({VARIABLE_CONDITIONAL a.hitpoints equals 76})}
{ASSERT ({VARIABLE_CONDITIONAL b.hitpoints equals 76})}
{SUCCEED}
[/event]
)}

{GENERIC_UNIT_TEST "damage_secondary_type_test" (
[event]
name=start
[modify_unit]
[filter]
[/filter]
max_hitpoints=100
hitpoints=100
attacks_left=1
[/modify_unit]
[object]
silent=yes
[effect]
apply_to=resistance
replace=yes
[resistance]
blade=200
fire=100
[/resistance]
[/effect]
[effect]
apply_to=attack
[set_specials]
mode=append
[attacks]
value=1
[/attacks]
[damage]
value=12
[/damage]
[damage]
added_type=cold
[/damage]
[chance_to_hit]
value=100
[/chance_to_hit]
[/set_specials]
[/effect]
[filter]
id=bob
[/filter]
[/object]
[object]
silent=yes
[effect]
apply_to=resistance
replace=yes
[resistance]
cold=200
blade=100
[/resistance]
[/effect]
[effect]
apply_to=attack
[set_specials]
mode=append
[attacks]
value=1
[/attacks]
[damage]
value=12
[/damage]
[damage]
added_type=fire
[/damage]
[chance_to_hit]
value=100
[/chance_to_hit]
[/set_specials]
[/effect]
[filter]
id=alice
[/filter]
[/object]

[store_unit]
[filter]
id=alice
[/filter]
variable=a
kill=yes
[/store_unit]
[store_unit]
[filter]
id=bob
[/filter]
variable=b
[/store_unit]
[unstore_unit]
variable=a
find_vacant=yes
x,y=$b.x,$b.y
[/unstore_unit]
[store_unit]
[filter]
id=alice
[/filter]
variable=a
[/store_unit]

[do_command]
[attack]
weapon=0
defender_weapon=0
[source]
x,y=$a.x,$a.y
[/source]
[destination]
x,y=$b.x,$b.y
[/destination]
[/attack]
[/do_command]
[store_unit]
[filter]
id=alice
[/filter]
variable=a
[/store_unit]
[store_unit]
[filter]
id=bob
[/filter]
variable=b
[/store_unit]
#damage without modification are 12, if test fail hitpoints !=76
#if succed then damage by alice 24(bob more vulnerable to blade)
#if succed then damage by bob 24(alice vulnerable to cold, cold [damage] is used)
{ASSERT ({VARIABLE_CONDITIONAL a.hitpoints equals 76})}
{ASSERT ({VARIABLE_CONDITIONAL b.hitpoints equals 76})}
{SUCCEED}
[/event]
)}
7 changes: 6 additions & 1 deletion src/gui/dialogs/attack_predictions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ void attack_predictions::set_data(window& window, const combatant_data& attacker
}
}

ss << string_table["type_" + weapon->type()];
std::pair<std::string, std::string> types = weapon->damage_type();
std::string type_bis = types.second;
if (!type_bis.empty()) {
type_bis = ", " + string_table["type_" + type_bis];
}
ss << string_table["type_" + types.first] + type_bis;

set_label_helper("resis_label", ss.str());

Expand Down
Loading

0 comments on commit 5ecaf34

Please sign in to comment.