Skip to content

Commit

Permalink
damage ability tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentarctagon committed Jul 27, 2024
1 parent aba0abe commit 374069b
Show file tree
Hide file tree
Showing 37 changed files with 1,212 additions and 26 deletions.
1 change: 1 addition & 0 deletions data/test/_main.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
{test/scenarios/wml_tests/UnitsWML/AbilitiesWML/attacks}
{test/scenarios/wml_tests/UnitsWML/AbilitiesWML/berserk}
{test/scenarios/wml_tests/UnitsWML/AbilitiesWML/chance_to_hit}
{test/scenarios/wml_tests/UnitsWML/AbilitiesWML/damage}
{test/scenarios/wml_tests/UnitsWML/AbilitiesWML/heals}
{test/scenarios/wml_tests/UnitsWML/AbilitiesWML/hides}
{test/scenarios/wml_tests/UnitsWML/AbilitiesWML/illuminates}
Expand Down
78 changes: 52 additions & 26 deletions data/test/macros/wml_unit_test_macros.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
# By default "alice" attacks "bob", these can be overridden with the ID1 and ID2 optional arguments.
# DAMAGE1 is expected hp loss for ID1 (alice).
# DAMAGE2 is expected hp loss for ID2 (bob), it defaults to the same as DAMAGE1.
# WEAPON_COUNT is how many weapons to test, starting from the first.
# DAMAGE_VALUE is the contents of the [damage] ability to set the attack to the default of 100
#define ATTACK_AND_VALIDATE DAMAGE1

#arg ID1
Expand All @@ -93,6 +95,15 @@ bob#endarg
#arg DAMAGE2
{DAMAGE1}#endarg

#arg WEAPON_COUNT
1#endarg

#arg DAMAGE_VALUE
[damage]
value=100
[/damage]
#endarg

[modify_unit]
[filter]
id={ID1},{ID2}
Expand All @@ -104,9 +115,7 @@ bob#endarg
[attacks]
value=1
[/attacks]
[damage]
value=100
[/damage]
{DAMAGE_VALUE}
[chance_to_hit]
value=100
[/chance_to_hit]
Expand All @@ -116,29 +125,46 @@ bob#endarg
max_hitpoints = 1000
[/modify_unit]

[test_do_attack_by_id]
attacker={ID1}
defender={ID2}
[/test_do_attack_by_id]

[store_unit]
[filter]
id={ID1}
[/filter]
variable={ID1}
[/store_unit]
[store_unit]
[filter]
id={ID2}
[/filter]
variable={ID2}
[/store_unit]

{ASSERT {VARIABLE_CONDITIONAL {ID1}.hitpoints numerical_equals "$(${ID1}.max_hitpoints-{DAMAGE1})"}}
{ASSERT {VARIABLE_CONDITIONAL {ID2}.hitpoints numerical_equals "$(${ID2}.max_hitpoints-{DAMAGE2})"}}

{CLEAR_VARIABLE {ID1}}
{CLEAR_VARIABLE {ID2}}
{VARIABLE weapons {WEAPON_COUNT}}
[for]
start=0
end="$($weapons-1)"
step=1
[do]
[test_do_attack_by_id]
attacker={ID1}
defender={ID2}
weapon=$i
resupply_attacks_left=1
[/test_do_attack_by_id]

[store_unit]
[filter]
id={ID1}
[/filter]
variable={ID1}
[/store_unit]
[store_unit]
[filter]
id={ID2}
[/filter]
variable={ID2}
[/store_unit]

{ASSERT {VARIABLE_CONDITIONAL {ID1}.hitpoints numerical_equals "$(${ID1}.max_hitpoints-{DAMAGE1})"}}
{ASSERT {VARIABLE_CONDITIONAL {ID2}.hitpoints numerical_equals "$(${ID2}.max_hitpoints-{DAMAGE2})"}}

[modify_unit]
[filter]
id={ID1},{ID2}
[/filter]
hitpoints = 1000
[/modify_unit]

{CLEAR_VARIABLE {ID1}}
{CLEAR_VARIABLE {ID2}}
[/do]
[/for]
#enddef

# Takes a unit id, and checks that its hitpoints and experience are the expected values.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# wmllint: no translatables

#####
# API(s) being tested: [damage]value=
##
# Actions:
# Give the leaders an damage ability with both the value and add attributes
# Have the side 1 leader attack the side 2 leader with both its weapons
##
# Expected end state:
# The side 1 leader has 2 weapons each of which now has 6 damage (5+1)
#####
{COMMON_KEEP_A_B_UNIT_TEST "damage_add" (
[event]
name = start

[modify_unit]
[filter]
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_ABILITY damage 5 (add=1) SELF=yes}
[/abilities]
[/effect]
[/modify_unit]

{ATTACK_AND_VALIDATE 6 (DAMAGE_VALUE=) WEAPON_COUNT=2}
{SUCCEED}
[/event]
) SIDE2_LEADER="Elvish Archer"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# wmllint: no translatables

#####
# API(s) being tested: [damage]value=
##
# Actions:
# Give the leaders a damage ability with the value, add, and divide attributes
# Have the side 1 leader attack the side 2 leader with both its weapons
##
# Expected end state:
# The side 1 leader has 2 weapons each of which now has 3 damage ((5+1)/2)
#####
{COMMON_KEEP_A_B_UNIT_TEST "damage_add_divide" (
[event]
name = start

[modify_unit]
[filter]
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_ABILITY damage 5 (add=1
divide=2) SELF=yes}
[/abilities]
[/effect]
[/modify_unit]

{ATTACK_AND_VALIDATE 3 (DAMAGE_VALUE=) WEAPON_COUNT=2}
{SUCCEED}
[/event]
) SIDE2_LEADER="Elvish Archer"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# wmllint: no translatables

#####
# API(s) being tested: [damage]value=
##
# Actions:
# Give the leaders a damage ability with the value, add, and multiply attributes
# Have the side 1 leader attack the side 2 leader with both its weapons
##
# Expected end state:
# The side 1 leader has 2 weapons each of which now has 12 damage ((5+1)*2)
#####
{COMMON_KEEP_A_B_UNIT_TEST "damage_add_multiply" (
[event]
name = start

[modify_unit]
[filter]
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_ABILITY damage 5 (add=1
multiply=2) SELF=yes}
[/abilities]
[/effect]
[/modify_unit]

{ATTACK_AND_VALIDATE 12 (DAMAGE_VALUE=) WEAPON_COUNT=2}
{SUCCEED}
[/event]
) SIDE2_LEADER="Elvish Archer"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# wmllint: no translatables

#####
# API(s) being tested: [damage]value=
##
# Actions:
# Give the leaders a damage ability with the value, add, and sub attributes
# Have the side 1 leader attack the side 2 leader with both its weapons
##
# Expected end state:
# The side 1 leader has 2 weapons each of which now has 3 damage (5-2), add is ignored
#####
{COMMON_KEEP_A_B_UNIT_TEST "damage_add_sub" (
[event]
name = start

[modify_unit]
[filter]
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_ABILITY damage 5 (add=1
sub=2) SELF=yes}
[/abilities]
[/effect]
[/modify_unit]

{ATTACK_AND_VALIDATE 3 (DAMAGE_VALUE=) WEAPON_COUNT=2}
{SUCCEED}
[/event]
) SIDE2_LEADER="Elvish Archer"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# wmllint: no translatables

#####
# API(s) being tested: [damage]affect_allies=
##
# Actions:
# Give the side 1 leader a damage ability that only affects adjacent allies
# Have the side 2 leader attack the side 3 leader with both its weapons
# Have the side 1 leader attack the side 4 leader with both its weapons
##
# Expected end state:
# The side 2 leader has 2 weapons each of which now has 2 damage
# The side 1 leader has 2 weapons neither of which has been modified to have 2 damage
#####
{COMMON_KEEP_A_B_C_D_UNIT_TEST "damage_affect_allies" (
[event]
name = start

[modify_side]
side=1,2
team_name=allies
[/modify_side]

[modify_unit]
[filter]
side=1
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_ABILITY damage 2 ([affect_adjacent][/affect_adjacent]) ALLIES=yes}
[/abilities]
[/effect]
[/modify_unit]

{ATTACK_AND_VALIDATE 5 DAMAGE2=2 (DAMAGE_VALUE=) ID1=bob ID2=charlie WEAPON_COUNT=2}
{ATTACK_AND_VALIDATE 5 (DAMAGE_VALUE=) ID1=alice ID2=dave WEAPON_COUNT=2}
{SUCCEED}
[/event]
) SIDE_LEADER="Elvish Archer"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# wmllint: no translatables

#####
# API(s) being tested: [damage]affect_enemies=
##
# Actions:
# Give the side 1 leader a damage ability that only affects adjacent enemies
# Have the side 1 leader attack the side 2 leader with both its weapons
##
# Expected end state:
# The side 2 leader has 2 weapons each of which now has 2 damage
# The side 1 leader has 2 weapons neither of which has been modified to have 2 damage
#####
{COMMON_KEEP_A_B_UNIT_TEST "damage_affect_enemies" (
[event]
name = start

[modify_unit]
[filter]
side=1
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_ABILITY damage 2 ([affect_adjacent][/affect_adjacent]) ENEMIES=yes}
[/abilities]
[/effect]
[/modify_unit]

{ATTACK_AND_VALIDATE 2 DAMAGE2=5 (DAMAGE_VALUE=) WEAPON_COUNT=2}
{SUCCEED}
[/event]
) SIDE2_LEADER="Elvish Archer"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# wmllint: no translatables

#####
# API(s) being tested: [damage]affect_allies=
##
# Actions:
# Give the side 1 leader a damage ability with affect_allies, affect_enemies, and affect_self
# Make side 1 and side 2 allies
# Have the side 1 leader attack the side 3 leader with both its weapons
# Have the side 2 leader attack the side 4 leader with both its weapons
# Have the side 4 leader attack the side 1 leader with both its weapons
##
# Expected end state:
# The side 1 leader has 2 weapons each of which now has 2 damage
# The side 2 leader has 2 weapons each of which now has 2 damage
# The side 4 leader has 2 weapons each of which now has 2 damage
#####
{COMMON_KEEP_A_B_C_D_UNIT_TEST "damage_affect_everybody" (
[event]
name = start

[modify_side]
side=1,2
team_name=allies
[/modify_side]

[modify_unit]
[filter]
side = 1
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_ABILITY damage 2 ([affect_adjacent][/affect_adjacent]) ENEMIES=yes SELF=yes ALLIES=yes}
[/abilities]
[/effect]
[/modify_unit]

{ATTACK_AND_VALIDATE 2 (DAMAGE_VALUE=) ID1=alice ID2=charlie WEAPON_COUNT=2}
{ATTACK_AND_VALIDATE 2 (DAMAGE_VALUE=) ID1=bob ID2=dave WEAPON_COUNT=2}
{ATTACK_AND_VALIDATE 2 (DAMAGE_VALUE=) ID1=dave ID2=alice WEAPON_COUNT=2}
{SUCCEED}
[/event]
) SIDE_LEADER="Elvish Archer"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# wmllint: no translatables

#####
# API(s) being tested: [damage]affect_self=
##
# Actions:
# Give the leaders a damage ability that doesn't affect themselves.
# Have the side 1 leader attack the side 2 leader with both its weapons
##
# Expected end state:
# The side 1 leader has 2 weapons neither of which has 2 damage
#####
{COMMON_KEEP_A_B_UNIT_TEST "damage_affect_self_no" (
[event]
name = start

[modify_unit]
[filter]
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_ABILITY damage 2 ()}
[/abilities]
[/effect]
[/modify_unit]

{ATTACK_AND_VALIDATE 5 (DAMAGE_VALUE=) WEAPON_COUNT=2}
{SUCCEED}
[/event]
) SIDE2_LEADER="Elvish Archer"}
Loading

0 comments on commit 374069b

Please sign in to comment.