Apply the new ground_level method.
[crawl.git] / crawl-ref / source / test / los_symm.lua
blob340d3eb63a40acea22f2c36d33053108dd40d413
1 -- Vet LOS for symmetry.
3 local FAILMAP = 'losfail.map'
4 local checks = 0
6 local function test_losight_symmetry()
7 -- Send the player to a random spot on the level.
8 you.random_teleport()
10 checks = checks + 1
11 local you_x, you_y = you.pos()
13 local visible_spots = { }
14 for y = -8, 8 do
15 for x = -8, 8 do
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 })
22 end
23 end
24 end
25 end
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)
31 you.moveto(x, y)
32 if not you.see_cell(you_x, you_y) then
33 -- Draw the view to show the problem.
34 crawl.redraw_view()
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)
39 assert(false,
40 "LOS asymmetry detected (iter #" .. checks .. "): " .. you_p ..
41 " sees " .. this_p .. ", but not vice versa." ..
42 " Map saved to " .. FAILMAP)
43 end
44 end
45 end
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()
57 end
58 end
59 end
61 for depth = 1, 27 do
62 run_los_tests(depth, 1, 3)
63 end