1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
-- Check basic find_ray functionality.
local FAILMAP = 'rayfail.map'
local checks = 0
local function test_findray()
-- Clear messages to prevent them accumulating and forcing a --more--
crawl.mesclr()
-- Send the player to a random spot on the level.
you.random_teleport()
-- Forcibly redo LOS.
you.losight()
local you_x, you_y = you.pos()
local you_p = dgn.point(you_x, you_y)
local visible_spots = { }
for y = -8, 8 do
for x = -8, 8 do
if x ~= 0 or y ~= 0 then
local px, py = x + you_x, y + you_y
if you.see_cell_no_trans(px, py) then
table.insert(visible_spots, { px, py })
end
end
end
end
-- For each position in LOS, shoot a ray there
-- and make sure it doesn't go through an opaque cell.
for _, spot in ipairs(visible_spots) do
checks = checks + 1
local x, y = unpack(spot)
local p = dgn.point(x, y)
local ray = los.findray(you_x, you_y, x, y)
if not ray then
dgn.grid(x, y, "floor_special")
debug.dump_map(FAILMAP)
assert(false, "Can't find ray to " .. p ..
" although it's in unobstructed view. (#" ..
checks .. ")")
end
local rx, ry = ray:pos()
local ray_p = dgn.point(rx, ry)
assert(ray_p == you_p,
"Ray doesn't start at player position " .. you_p ..
" but " .. ray_p .. ".")
ray:advance()
rx, ry = ray:pos()
ray_p = dgn.point(rx, ry)
while(ray_p ~= p) do
if feat.is_opaque(rx, ry) then
dgn.grid(x, y, "floor_special")
debug.dump_map(FAILMAP)
assert(false,
"Ray from " .. you_p .. " to " .. p ..
" passes through opaque cell " .. ray_p
.. ".")
end
ray:advance()
rx, ry = ray:pos()
ray_p = dgn.point(rx, ry)
end
end
end
local function run_findray_tests(depth, nlevels, tests_per_level)
local place = "D:" .. depth
crawl.mpr("Running find_ray tests on " .. place)
debug.goto_place(place)
for lev_i = 1, nlevels do
debug.flush_map_memory()
debug.generate_level()
for t_i = 1, tests_per_level do
test_findray()
end
end
end
for depth = 1, 27 do
run_findray_tests(depth, 1, 10)
end
|