1 -- Vet LOS for symmetry.
3 local FAILMAP
= 'losfail.map'
6 local function test_losight_symmetry()
7 -- Send the player to a random spot on the level.
11 local you_x
, you_y
= you
.pos()
13 local visible_spots
= { }
16 if x
~= 0 or y
~= 0 then
17 local px
, py
= x
+ you_x
, y
+ you_y
18 -- It makes sense to check visibility of a cell on the border, but
19 -- we'd be unable to test the reverse.
20 if dgn
.in_bounds(px
, py
) and you
.see_cell(px
, py
) then
21 table.insert(visible_spots
, { px
, py
})
27 -- For each position in LOS, jump to that position and make sure we
28 -- can see the original spot.
29 for _
, spot
in ipairs(visible_spots
) do
30 local x
, y
= unpack(spot
)
32 if not you
.see_cell(you_x
, you_y
) then
33 -- Draw the view to show the problem.
35 local this_p
= dgn
.point(x
, y
)
36 local you_p
= dgn
.point(you_x
, you_y
)
37 dgn
.fprop_changed(you_x
, you_y
, "highlight")
38 debug
.dump_map(FAILMAP
)
40 "LOS asymmetry detected (iter #" .. checks
.. "): " .. you_p
..
41 " sees " .. this_p
.. ", but not vice versa." ..
42 " Map saved to " .. FAILMAP
)
47 local function run_los_tests(depth
, nlevels
, tests_per_level
)
48 local place
= "D:" .. depth
49 crawl
.message("Running LOS tests on " .. place
)
50 debug
.goto_place(place
)
52 for lev_i
= 1, nlevels
do
53 debug
.flush_map_memory()
54 debug
.generate_level()
55 for t_i
= 1, tests_per_level
do
56 test_losight_symmetry()
62 run_los_tests(depth
, 1, 3)