Apply the new ground_level method.
[crawl.git] / crawl-ref / source / test / findray.lua
blob1bb423cdf4a96f1935275dbd3894d30f325edce9
1 -- Check basic find_ray functionality.
3 local FAILMAP = 'rayfail.map'
4 local checks = 0
6 local function test_findray()
7 -- Send the player to a random spot on the level.
8 you.random_teleport()
10 local you_x, you_y = you.pos()
11 local you_p = dgn.point(you_x, you_y)
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 if you.see_cell_no_trans(px, py) then
19 table.insert(visible_spots, { px, py })
20 end
21 end
22 end
23 end
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
28 checks = checks + 1
29 local x, y = unpack(spot)
30 local p = dgn.point(x, y)
31 local ray = los.findray(you_x, you_y, x, y)
32 if not ray then
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. (#" ..
37 checks .. ")")
38 end
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 .. ".")
44 ray:advance()
45 rx, ry = ray:pos()
46 ray_p = dgn.point(rx, ry)
47 while(ray_p ~= p) do
48 if feat.is_opaque(rx, ry) then
49 dgn.fprop_changed(x, y, "highlight")
50 debug.dump_map(FAILMAP)
51 assert(false,
52 "Ray from " .. you_p .. " to " .. p ..
53 " passes through opaque cell " .. ray_p
54 .. ".")
55 end
56 ray:advance()
57 rx, ry = ray:pos()
58 ray_p = dgn.point(rx, ry)
59 end
60 end
61 end
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
72 test_findray()
73 end
74 end
75 end
77 for depth = 1, 27 do
78 run_findray_tests(depth, 1, 10)
79 end