1 -- Check basic find_ray functionality.
3 local FAILMAP
= 'rayfail.map'
6 local function test_findray()
7 -- Send the player to a random spot on the level.
10 local you_x
, you_y
= you
.pos()
11 local you_p
= dgn
.point(you_x
, you_y
)
13 local visible_spots
= { }
16 if x
~= 0 or y
~= 0 then
17 local px
, py
= x
+ you_x
, y
+ you_y
18 if you
.see_cell_no_trans(px
, py
) then
19 table.insert(visible_spots
, { px
, py
})
25 -- For each position in LOS, shoot a ray there
26 -- and make sure it doesn't go through an opaque cell.
27 for _
, spot
in ipairs(visible_spots
) do
29 local x
, y
= unpack(spot
)
30 local p
= dgn
.point(x
, y
)
31 local ray
= los
.findray(you_x
, you_y
, x
, y
)
33 dgn
.fprop_changed(x
, y
, "highlight")
34 debug
.dump_map(FAILMAP
)
35 assert(false, "Can't find ray to " .. p
..
36 " although it's in unobstructed view. (#" ..
39 local rx
, ry
= ray
:pos()
40 local ray_p
= dgn
.point(rx
, ry
)
41 assert(ray_p
== you_p
,
42 "Ray doesn't start at player position " .. you_p
..
43 " but " .. ray_p
.. ".")
46 ray_p
= dgn
.point(rx
, ry
)
48 if feat
.is_opaque(rx
, ry
) then
49 dgn
.fprop_changed(x
, y
, "highlight")
50 debug
.dump_map(FAILMAP
)
52 "Ray from " .. you_p
.. " to " .. p
..
53 " passes through opaque cell " .. ray_p
58 ray_p
= dgn
.point(rx
, ry
)
63 local function run_findray_tests(depth
, nlevels
, tests_per_level
)
64 local place
= "D:" .. depth
65 crawl
.message("Running find_ray tests on " .. place
)
66 debug
.goto_place(place
)
68 for lev_i
= 1, nlevels
do
69 debug
.flush_map_memory()
70 debug
.generate_level()
71 for t_i
= 1, tests_per_level
do
78 run_findray_tests(depth
, 1, 10)