diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-07 22:17:12 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-07 22:21:14 +0200 |
commit | 0b21b9fcf0a01574cf1be84dd9900e32d95a1e79 (patch) | |
tree | 6c5258d598068ab30cb9446555430113b9a573e8 /crawl-ref/source/test/los_symm.lua | |
parent | ed0614af8d97a0ffd10f6d55017ca0ee8f6c5175 (diff) | |
download | crawl-ref-0b21b9fcf0a01574cf1be84dd9900e32d95a1e79.tar.gz crawl-ref-0b21b9fcf0a01574cf1be84dd9900e32d95a1e79.zip |
Add test to compare LOS against sample maps.
New test cases can be added by adding appropriate maps to
debug-los.des.
Also separate the LOS tests into three separate files.
Diffstat (limited to 'crawl-ref/source/test/los_symm.lua')
-rw-r--r-- | crawl-ref/source/test/los_symm.lua | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/crawl-ref/source/test/los_symm.lua b/crawl-ref/source/test/los_symm.lua new file mode 100644 index 0000000000..beb809beee --- /dev/null +++ b/crawl-ref/source/test/los_symm.lua @@ -0,0 +1,67 @@ +-- Vet LOS for symmetry. + +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 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, jump to that position and make sure we + -- can see the original spot. + for _, spot in ipairs(visible_spots) do + local x, y = unpack(spot) + you.moveto(x, y) + you.losight() + if not you.see_grid(you_x, you_y) then + -- Draw the view to show the problem. + crawl.redraw_view() + local this_p = dgn.point(x, y) + local you_p = dgn.point(you_x, you_y) + dgn.grid(you_x, you_y, "floor_special") + dgn.dbg_dump_map(FAILMAP) + assert(false, + "LOS asymmetry detected (iter #" .. checks .. "): " .. you_p .. + " sees " .. this_p .. ", but not vice versa." .. + " Map saved to " .. FAILMAP) + 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 |