wesnoth/data/test/macros/wml_unit_test_macros.cfg
2023-12-15 09:59:01 -06:00

139 lines
3.1 KiB
INI

#textdomain wesnoth-test
#define RETURN X
[if]
[variable]
name=ended
boolean_not_equals=yes
[/variable]
[then]
[if]
{X}
[then]
{VARIABLE ended yes}
[endlevel]
test_result=pass
linger_mode = yes
[/endlevel]
[/then]
[else]
[test_condition]
result=no
{X}
[/test_condition]
{VARIABLE ended yes}
[endlevel]
test_result=fail
linger_mode = yes
[/endlevel]
[/else]
[/if]
[/then]
[/if]
#enddef
#define ASSERT X
[if]
[variable]
name=ended
boolean_not_equals=yes
[/variable]
[then]
[if]
{X}
[else]
[test_condition]
result=no
{X}
[/test_condition]
{VARIABLE ended yes}
[endlevel]
test_result=fail
linger_mode = yes
[/endlevel]
[/else]
[/if]
[/then]
[/if]
#enddef
#define FAIL
{RETURN ([false][/false])}
#enddef
#define SUCCEED
{RETURN ([true][/true])}
#enddef
#define FAIL_IF_NOT FLAG NOT_EQUALS
[if]
[variable]
name={FLAG}
not_equals={NOT_EQUALS}
[/variable]
[then]
{FAIL}
[/then]
[/if]
#enddef
# have one adjacent unit attack another adjacent unit
# each unit is given 1000 hp and their attack is made to 1x100, with a 100% chance of hitting
#define ATTACK_AND_VALIDATE DAMAGE1
#arg ID1
alice#endarg
#arg ID2
bob#endarg
#arg DAMAGE2
{DAMAGE1}#endarg
[modify_unit]
[filter]
id={ID1},{ID2}
[/filter]
[effect]
apply_to=attack
[set_specials]
mode=append
[attacks]
value=1
[/attacks]
[damage]
value=100
[/damage]
[chance_to_hit]
value=100
[/chance_to_hit]
[/set_specials]
[/effect]
hitpoints = 1000
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}}
#enddef