File: v_debug.lua

package info (click to toggle)
crawl 2%3A0.33.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,264 kB
  • sloc: cpp: 358,145; ansic: 27,203; javascript: 9,491; python: 8,359; perl: 3,327; java: 2,667; xml: 2,191; makefile: 1,830; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (105 lines) | stat: -rw-r--r-- 3,401 bytes parent folder | download | duplicates (7)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
------------------------------------------------------------------------------
-- v_debug.lua:
--
-- When things go wrong ...
------------------------------------------------------------------------------
function print_vector(caption,v)
  if v == nil then
   print(caption .. ": nil")
  else
    print(caption .. ": " .. v.x .. ", " .. v.y)
  end
end

function dump_layout_grid(layout_grid)
    local gxm,gym = layout_grid.width,layout_grid.height

    if gxm==nil or gym==nil then gxm,gym = dgn.max_bounds() end

  for i = 0, gym-1, 1 do
    local maprow = ""
    for j = 0, gxm-1, 1 do
      local cell = layout_grid[i][j]
      if cell.space then maprow = maprow .. " "
      elseif cell.solid == false then maprow = maprow .. "."
      elseif cell.solid == true then maprow = maprow .. "x"
      else maprow = maprow .. "?" end
    end
    print (maprow)
  end
end

function dump_usage_grid(usage_grid)

    local gxm,gym = dgn.max_bounds()

  for i = 0, gym-1, 1 do
    local maprow = ""
    for j = 0, gxm-1, 1 do
      local cell = usage_grid[i][j]
      if cell.usage == "none" then maprow = maprow .. " "
      elseif cell.usage == "restricted" then
        if cell.reason == "vault" then maprow = maprow .. ","
        elseif cell.reason == "door" then maprow = maprow .. "="
        else maprow = maprow .. "!" end
      elseif cell.usage == "empty" then maprow = maprow .. "."
      elseif cell.usage == "eligible" or cell.usage == "eligible_open" then
        if cell.normal == nil then maprow = maprow .. "!"
        elseif cell.normal.x == -1 then maprow = maprow .. "<"
        elseif cell.normal.x == 1 then maprow = maprow .. ">"
        elseif cell.normal.y == -1 then maprow = maprow .. "^"
        elseif cell.normal.y == 1 then maprow = maprow .. "v" end
      elseif cell.usage == "open" then maprow = maprow .. "_"  -- Easier to see the starting room
      else maprow = maprow .. "?" end
    end
    print (maprow)
  end

end

function dump_mask_grid(room)

  for y = -1, room.size.y, 1 do
    maprow = ""
    for x = -1, room.size.x, 1 do
      cell = room.mask_grid[y][x]
      local char = " "
      if cell.wall then
        if cell.dir == 0 then char = "^"
        elseif cell.dir == 1 then char = "<"
        elseif cell.dir == 2 then char = "v"
        elseif cell.dir == 3 then char = ">"
        elseif cell.dir == nil then char = "x"
        else char = "?" end
      end
      maprow = maprow .. char
    end
    print(maprow)
  end
end

function dump_usage_grid_pretty(usage_grid)

    local gxm,gym = dgn.max_bounds()

  for i = 0, gym-1, 1 do
    local maprow = ""
    for j = 0, gxm-1, 1 do
      local cell = usage_grid[i][j]
      if cell.usage == "none" then maprow = maprow .. " "
      elseif cell.usage == "restricted" then
        if cell.reason == "vault" then maprow = maprow .. ","
        elseif cell.reason == "door" then maprow = maprow .. "+"
        else maprow = maprow .. "." end
      elseif cell.usage == "empty" then maprow = maprow .. "."
      elseif cell.usage == "eligible" or cell.usage == "eligible_open" then
        if cell.normal == nil then maprow = maprow .. "!"
        elseif cell.normal.x == 0 then maprow = maprow .. "-"
        elseif cell.normal.y == 0 then maprow = maprow .. "|" end
      elseif cell.usage == "open" then maprow = maprow .. "."
      else maprow = maprow .. "?" end
    end
    print (maprow)
  end

end