summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/test/los_maps.lua
blob: f72a6382fdb78d37bb6b6b655ba07d27418f6de6 (plain) (blame)
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
-- check LOS according to pre-defined maps

local checks = 0

-- visible:
local rock_wall = dgn.find_feature_number("rock_wall")
local floor = dgn.find_feature_number("floor")
-- invisible (not needed):
local stone_wall = dgn.find_feature_number("stone_wall")
local water = dgn.find_feature_number("deep_water")

local function test_los_map(map)
  crawl.mesclr()
  dgn.reset_level()
  -- choose random debug map; better choose all
  dgn.tags(map, "no_rotate no_vmirror no_hmirror no_pool_fixup")
  local name = dgn.name(map)
  -- local width, height = dgn.mapsize(map) -- returns (0,0)
  local function place_map()
    return dgn.place_map(map, true, true)
  end
  dgn.with_map_anchors(30, 30, place_map)
  you.moveto(30, 30)
  you.losight()
  crawl.redraw_view()
  for x = 0, 9 do
    for y = 0, 9 do
      local xa = 30 + x
      local ya = 30 + y
      local p = dgn.point(x, y)
      local feat = dgn.grid(xa, ya)
      local should_see = ((x == 0 and y == 0) or
                          feat == rock_wall or
                          feat == floor)
      local should_not_see = (x ~= 0 or y ~= 0) and
                              (feat == stone_wall or feat == water)
      if (not (should_see or should_not_see)) then
        assert(false, "Illegal feature " .. dgn.feature_name(feat) .. " (" ..
                      feat .. ") at " .. p .. " in " .. name .. ".")
      end
      local can_see = you.see_cell(xa, ya)
      local err = can_see and (not should_see) or (not can_see) and should_see
      if err then
        local cans = can_see and "can" or "can't"
        local shoulds = should_see and "should" or "shouldn't"
        local errstr = "LOS error in " .. name .. ": " .. shoulds ..
                       " see " .. p .. " (" .. feat .. ") but " .. cans .. "."
        assert(false, errstr)
      end
    end
  end
end

local function test_los_maps()
  dgn.load_des_file("test/des/debug-diamond-los.des")
  local map = dgn.map_by_tag("debug_los")
  assert(map, "Could not find debug-los maps (tag 'debug_los')")
  while map do
    test_los_map(map)
    checks = checks + 1
    map = dgn.map_by_tag("debug_los")
  end
end

test_los_maps()