Skip to content

Commit

Permalink
add unit test for an object-based "feeding" ability
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 22, 2014
1 parent 0f7b06c commit 14808e1
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 0 deletions.
162 changes: 162 additions & 0 deletions data/test/scenarios/feeding.cfg
@@ -0,0 +1,162 @@
# This unit test defines a WML object based implementation of the "feeding" ability
# and checks that it works. What is being tested here, beyond what is tested in
# test_unit_map and other scenarios that test the attack pathway, is that
# - the die event works
# - objects attach to units by id correctly
# - abilities can be properly detected in filters
# - abillities which add other objects works
# - this impl of feeding works

#define STR_FEEDING
foo
#enddef

#define STR_FEEDING_EFFECT
bar
#enddef

#define STR_FEEDING_DESCRIPTION
baz
#enddef

#define TEST_FEEDING ID EXPECTED_INCREASE
[store_unit]
[filter]
id={ID}
[/filter]
variable=Killer
[/store_unit]

{VARIABLE victim_x $Killer.x}
{VARIABLE_OP victim_x sub 1}
{VARIABLE victim_y $Killer.y}

{VARIABLE victim_side 3}
{VARIABLE_OP victim_side sub $Killer.side|}

{VARIABLE Killer_start_hp $Killer.hitpoints}

[terrain_mask]
x,y=$victim_x|,$victim_y|
mask="Xv"
[/terrain_mask]
{UNIT $victim_side| "Elvish Archer" $victim_x| $victim_y| (hitpoints=1)}
[do_command]
[attack]
weapon = 0
defender_weapon = 0
[source]
x,y=$Killer.x|,$Killer.y|
[/source]
[destination]
x,y=$victim_x|,$victim_y|
[/destination]
[/attack]
[/do_command]

[store_unit]
[filter]
id={ID}
[/filter]
variable=Killer
[/store_unit]

{VARIABLE_OP Killer_start_hp add {EXPECTED_INCREASE}}

{ASSERT ({VARIABLE_CONDITIONAL Killer.hitpoints equals $Killer_start_hp})}
#enddef

{GENERIC_UNIT_TEST "feeding" (
[event]
id=ability_feeding_die
name=die
first_time_only=no
[filter]
[not]
[filter_wml]
[status]
not_living="yes"
[/status]
[/filter_wml]
[/not]
[/filter]
[filter_second]
ability=feeding
[/filter_second]
[unstore_unit]
variable=second_unit
{COLOR_HEAL}
text= {STR_FEEDING_EFFECT}
find_vacant=no
[/unstore_unit]
[object]
silent=yes
duration=forever
[filter]
x,y=$x2|,$y2|
[/filter]
[effect]
apply_to=hitpoints
increase_total=1
increase=1
[/effect]
[/object]
[/event]
[event]
name=start
[object]
id=feeding_object
silent=yes
[effect]
apply_to=new_ability
[abilities]
[dummy]
id=feeding
name= {STR_FEEDING}
female_name= {STR_FEEDING}
description= {STR_FEEDING_DESCRIPTION}
[/dummy]
[/abilities]
[/effect]
[filter]
id=bob
[/filter]
[/object]
[/event]
[event]
name=start

{TEST_FEEDING alice 0}
{TEST_FEEDING alice 0}
{TEST_FEEDING alice 0}

[end_turn]
[/end_turn]
[/event]
[event]
name = side 2 turn 1

{TEST_FEEDING bob 1}
{TEST_FEEDING bob 1}
{TEST_FEEDING bob 1}

[store_unit]
[filter]
id=bob
[/filter]
variable=Bob
[/store_unit]

{VARIABLE_OP Bob.experience add 50}

[unstore_unit]
variable=Bob
[/unstore_unit]

{TEST_FEEDING bob 1}
{TEST_FEEDING bob 1}
{TEST_FEEDING bob 1}

{RETURN ([true][/true])}
[/event]
)}
1 change: 1 addition & 0 deletions wml_test_schedule
Expand Up @@ -102,6 +102,7 @@
0 alice_kills_bob_on_retal_levelup
0 test_grunt_tod_damage
0 test_berzerk_firststrike
0 feeding
#
# Deterministic unit facing tests
0 recruit_facing_enemy_one
Expand Down

0 comments on commit 14808e1

Please sign in to comment.