Commit 27168ee3323d26273e1bfcd623d01a613090d4ea

Authored by DarkGod
1 parent 1ecb855d

plop

... ... @@ -29,7 +29,7 @@ function _M:init()
29 29 Tilemap.init(self)
30 30 end
31 31
32   -function _M:makeSimple(w, h, floors, walls, enclosed)
  32 +function _M:makeSimple(w, h, floors, walls, enclosed, allow_position)
33 33 if type(floors) == "string" then floors = {floors} end
34 34 if type(walls) == "string" then walls = {walls} end
35 35
... ... @@ -68,16 +68,16 @@ function _M:makeSimple(w, h, floors, walls, enclosed)
68 68 xpos = pick[1]
69 69 ypos = pick[2]
70 70 local dir = {}
71   - if xpos+2>mw and xpos+2<Mw and mazemap[ypos][xpos+2] then
  71 + if xpos+2>mw and xpos+2<Mw and mazemap[ypos][xpos+2] and (not allow_position or allow_position(self:point(xpos+2, ypos))) then
72 72 dir[#dir+1] = 6
73 73 end
74   - if xpos-2>mw and xpos-2<Mw and mazemap[ypos][xpos-2] then
  74 + if xpos-2>mw and xpos-2<Mw and mazemap[ypos][xpos-2] and (not allow_position or allow_position(self:point(xpos-2, ypos))) then
75 75 dir[#dir+1] = 4
76 76 end
77   - if ypos-2>mh and ypos-2<Mh and mazemap[ypos-2][xpos] then
  77 + if ypos-2>mh and ypos-2<Mh and mazemap[ypos-2][xpos] and (not allow_position or allow_position(self:point(xpos, ypos-2))) then
78 78 dir[#dir+1] = 8
79 79 end
80   - if ypos+2>mh and ypos+2<Mh and mazemap[ypos+2][xpos] then
  80 + if ypos+2>mh and ypos+2<Mh and mazemap[ypos+2][xpos] and (not allow_position or allow_position(self:point(xpos, ypos+2))) then
81 81 dir[#dir+1] = 2
82 82 end
83 83
... ...
... ... @@ -120,6 +120,10 @@ point_meta = {
120 120 distance = function(p, p2)
121 121 return core.fov.distance(p.x, p.y, p2.x, p2.y)
122 122 end,
  123 + addDir = function(p, dir)
  124 + local dx, dy = util.dirToCoord(dir)
  125 + return _M:point(p.x + dx, p.y + dy)
  126 + end,
123 127 clone = function(p)
124 128 return _M:point(p)
125 129 end,
... ... @@ -414,7 +418,7 @@ function _M:hasResult()
414 418 end
415 419
416 420 --- Locate a specific tile
417   -function _M:locateTile(char, erase, min_x, min_y, max_x, max_y)
  421 +function _M:locateTile(char, erase, min_x, min_y, max_x, max_y, allow_position)
418 422 local res = {}
419 423 min_x = min_x or 1
420 424 min_y = min_y or 1
... ... @@ -422,7 +426,7 @@ function _M:locateTile(char, erase, min_x, min_y, max_x, max_y)
422 426 max_y = max_y or self.data_h
423 427 for i = min_x, max_x do
424 428 for j = min_y, max_y do
425   - if self.data[j][i] == char then
  429 + if self.data[j][i] == char and (not allow_position or allow_position(self:point(i, j))) then
426 430 res[#res+1] = self:point(i, j)
427 431 if erase then self.data[j][i] = erase end
428 432 end
... ... @@ -524,6 +528,10 @@ group_meta = {
524 528 return ("Group[%s](%d points)"):format(tostring(g.list), #g.list)
525 529 end,
526 530 __index = {
  531 + print = function(g)
  532 + print(g)
  533 + for i, p in ipairs(g.list) do print(" - "..p.x.." x "..p.y) end
  534 + end,
527 535 updateReverse = function(g)
528 536 g.reverse = {}
529 537 for j = 1, #g.list do
... ... @@ -800,7 +808,7 @@ function _M:eliminateByFloodfill(walls)
800 808 if g and #g.list > 0 then
801 809 print("[Tilemap] Ok floodfill with main group size", #g.list)
802 810 self:eliminateGroups(walls[1], groups)
803   - return #g.list
  811 + return #g.list, g
804 812 else
805 813 print("[Tilemap] Floodfill left nothing")
806 814 return 0
... ... @@ -948,9 +956,10 @@ function _M:groupOuterRectangle(group)
948 956 end
949 957
950 958 --- Carve out a simple linear path from coords until a tile is reached
951   -function _M:carveLinearPath(char, from, dir, stop_at, dig_only_into)
  959 +function _M:carveLinearPath(char, from, dir, stop_at, dig_only_into, ignore_first)
952 960 local x, y = math.floor(from.x), math.floor(from.y)
953 961 local dx, dy = util.dirToCoord(dir)
  962 + if ignore_first then x, y = x + dx, y + dy end
954 963 if type(dig_only_into) == "table" then dig_only_into = table.reverse(dig_only_into) end
955 964 while x >= 1 and x <= self.data_w and y >= 1 and y <= self.data_h and self.data[y][x] ~= stop_at do
956 965 if not dig_only_into or (type(dig_only_into) == "table" and dig_only_into[self.data[y][x]]) or (type(dig_only_into) == "function" and dig_only_into(x, y, self.data[y][x])) then
... ...