diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-14 00:37:43 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-14 00:39:28 +0200 |
commit | 69fb24caca51bd9435051c8e1494f235c5aaeeb0 (patch) | |
tree | ac915c5790b00136e7f0fbc4af985726c9ce535e /crawl-ref | |
parent | 2b69971d7176659fd5de394f4de4dfa99121cb78 (diff) | |
download | crawl-ref-69fb24caca51bd9435051c8e1494f235c5aaeeb0.tar.gz crawl-ref-69fb24caca51bd9435051c8e1494f235c5aaeeb0.zip |
Add test for find_ray.
Tests for the existence of unobstructed rays to points within LOS.
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/test/findray.lua | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/crawl-ref/source/test/findray.lua b/crawl-ref/source/test/findray.lua new file mode 100644 index 0000000000..b98f23e5d4 --- /dev/null +++ b/crawl-ref/source/test/findray.lua @@ -0,0 +1,83 @@ +-- Check basic find_ray functionality. + +local FAILMAP = 'losfail.map' +local checks = 0 + +local function test_losight_symmetry() + -- 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() + + checks = checks + 1 + 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_grid(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 + 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") + dgn.dbg_dump_map(FAILMAP) + assert(false, "Can't find ray to " .. p .. + " although it's in view.") + 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 dgn.is_opaque(rx, ry) then + dgn.grid(x, y, "floor_special") + dgn.dbg_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_los_tests(depth, nlevels, tests_per_level) + local place = "D:" .. depth + crawl.mpr("Running LOS tests on " .. place) + dgn.dbg_goto_place(place) + + for lev_i = 1, nlevels do + dgn.dbg_flush_map_memory() + dgn.dbg_generate_level() + for t_i = 1, tests_per_level do + test_losight_symmetry() + end + end +end + +for depth = 1, 27 do + run_los_tests(depth, 1, 10) +end |