mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-09 00:56:39 +00:00

Adding this is issue 2 of #4177, changing the behavior when [find_path] is given a SLF which matches multiple hexes. The map and tests here should be easy enough for manually editing them. It duplicates some of the functionality of the existing characterize_pathfinding tests, however those tests need their expected values to be calculated and can't be changed by hand. '''nearest_by''': {DevFeature1.15|2} possible values "movement_cost" (default), "steps", "hexes". If the [destination] SLF matches multiple hexes, the one that would need the least movement points to reach may not be the one that's closest as measured by '''hexes''', or closest as measured by steps, from the starting point. Behavior in 1.14 depended on which hex was checked first.
158 lines
5.0 KiB
INI
158 lines
5.0 KiB
INI
# This test is called "simple" find_path because the expected values are hand-coded by
|
|
# the developer. This is in contrast to the characterize_pathfinding_* tests, which
|
|
# need the expected answers to be generated automatically.
|
|
|
|
#define FIND_ALICES_PATH DESTINATION
|
|
[find_path]
|
|
[traveler]
|
|
id=alice
|
|
[/traveler]
|
|
[destination]
|
|
{DESTINATION}
|
|
[/destination]
|
|
allow_multiple_turns=no
|
|
variable=path
|
|
[/find_path]
|
|
#enddef
|
|
|
|
#define FIND_ALICES_PATH_2 DESTINATION NEAREST_BY
|
|
[find_path]
|
|
[traveler]
|
|
id=alice
|
|
[/traveler]
|
|
[destination]
|
|
{DESTINATION}
|
|
[/destination]
|
|
allow_multiple_turns=no
|
|
variable=path
|
|
nearest_by={NEAREST_BY}
|
|
[/find_path]
|
|
#enddef
|
|
|
|
# A conditional for ASSERT checks
|
|
#define PATH_GOES_TO DESTINATION
|
|
[have_location]
|
|
{DESTINATION}
|
|
[and]
|
|
x,y=$path.to_x, $path.to_y
|
|
[/and]
|
|
[/have_location]
|
|
#enddef
|
|
|
|
[test]
|
|
name = "Unit Test simple_find_path"
|
|
map_data = "{test/maps/simple_find_path.map}"
|
|
turns = 1
|
|
id = simple_find_path
|
|
random_start_time = no
|
|
is_unit_test = yes
|
|
|
|
{DAWN}
|
|
|
|
[side]
|
|
side=1
|
|
controller=human
|
|
name = "Alice"
|
|
type = Elvish Archer
|
|
id=alice
|
|
fog=no
|
|
shroud=no
|
|
share_view=no
|
|
[/side]
|
|
[side]
|
|
side=2
|
|
controller=human
|
|
name = "Bob"
|
|
type = Orcish Grunt
|
|
id=bob
|
|
fog=no
|
|
shroud=no
|
|
share_view=no
|
|
[/side]
|
|
|
|
[event]
|
|
name = side 1 turn 1
|
|
|
|
# If a path needs multiple turns then [find_path] will include the
|
|
# cost of movement points that were left unused at the end of all turns
|
|
# except the last. To avoid that, give Alice enough MP to move anywhere.
|
|
[modify_unit]
|
|
[filter]
|
|
id=alice
|
|
[/filter]
|
|
moves="$({UNREACHABLE} - 1)"
|
|
max_moves="$({UNREACHABLE} - 1)"
|
|
[/modify_unit]
|
|
|
|
# A path can go to the hex that the unit is already on
|
|
{FIND_ALICES_PATH location_id=1}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 0}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.step.length equals 1}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.movement_cost equals 0}}
|
|
|
|
{FIND_ALICES_PATH location_id=lake}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 3}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.step.length equals 4}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.movement_cost equals 7}}
|
|
|
|
{FIND_ALICES_PATH location_id=spur}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 5}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.step.length equals 6}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.movement_cost equals 5}}
|
|
|
|
{FIND_ALICES_PATH location_id=u_turn}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 2}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.step.length equals 9}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.movement_cost equals 8}}
|
|
|
|
{FIND_ALICES_PATH location_id=wet_turn}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 3}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.step.length equals 7}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.movement_cost equals 10}}
|
|
|
|
# There's no route to the in_void village
|
|
{FIND_ALICES_PATH location_id=in_void}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 0}}
|
|
|
|
{FIND_ALICES_PATH_2 terrain=*^V* movement_cost}
|
|
{ASSERT {PATH_GOES_TO location_id=spur}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 5}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.step.length equals 6}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.movement_cost equals 5}}
|
|
|
|
{FIND_ALICES_PATH_2 terrain=*^V* steps}
|
|
{ASSERT {PATH_GOES_TO location_id=lake}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 3}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.step.length equals 4}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.movement_cost equals 7}}
|
|
|
|
{FIND_ALICES_PATH_2 terrain=*^V* hexes}
|
|
{ASSERT {PATH_GOES_TO location_id=u_turn}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 2}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.step.length equals 9}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.movement_cost equals 8}}
|
|
|
|
# Without ignoring units, we can't move to Bob's starting hex
|
|
{FIND_ALICES_PATH location_id=2}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 0}}
|
|
|
|
# If we ignore other units, we can move to Bob's starting hex
|
|
[find_path]
|
|
[traveler]
|
|
id=alice
|
|
[/traveler]
|
|
[destination]
|
|
location_id=2
|
|
[/destination]
|
|
allow_multiple_turns=no
|
|
variable=path
|
|
check_zoc=false
|
|
[/find_path]
|
|
{ASSERT {VARIABLE_CONDITIONAL path.hexes equals 2}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.step.length equals 3}}
|
|
{ASSERT {VARIABLE_CONDITIONAL path.movement_cost equals 2}}
|
|
|
|
{SUCCEED}
|
|
[/event]
|
|
[/test]
|