Make generation more sparse by asking for extra space around rooms; also add out of bounds option to Map.neighbourhood
This commit is contained in:
parent
605696dddd
commit
641f5c7872
|
@ -194,7 +194,7 @@ class Map:
|
|||
self.add_entity(dictclasses[entisave["type"]](**entisave))
|
||||
|
||||
@staticmethod
|
||||
def neighbourhood(grid, y, x, large=False):
|
||||
def neighbourhood(grid, y, x, large=False, oob=False):
|
||||
"""
|
||||
Returns up to 8 nearby coordinates, in a 3x3 square around the input coordinate if large is
|
||||
set to True, or in a 5-square cross by default. Does not return coordinates if they are out
|
||||
|
@ -203,12 +203,12 @@ class Map:
|
|||
height, width = len(grid), len(grid[0])
|
||||
neighbours = []
|
||||
if large:
|
||||
dyxs = product([-1, 0, 1], [-1, 0, 1])
|
||||
dyxs = [[dy, dx] for dy, dx in product([-1, 0, 1], [-1, 0, 1])]
|
||||
dyxs = dyxs[:5] + dyxs[6:]
|
||||
else:
|
||||
dyxs = [[0, -1], [0, 1], [-1, 0], [1, 0]]
|
||||
for dy, dx in dyxs:
|
||||
if 0 <= y+dy < height and 0 <= x+dx < width:
|
||||
if oob or (0 <= y+dy < height and 0 <= x+dx < width):
|
||||
neighbours.append([y+dy, x+dx])
|
||||
return neighbours
|
||||
|
||||
|
|
|
@ -39,9 +39,16 @@ class Generator:
|
|||
for rx in range(rw):
|
||||
if room[ry][rx] == Tile.FLOOR:
|
||||
ly, lx = y + ry - door_y, x + rx - door_x
|
||||
# tile must be in bounds and empty
|
||||
if not(0 <= ly < lh and 0 <= lx < lw) or \
|
||||
level[ly][lx] == Tile.FLOOR:
|
||||
return False
|
||||
# so do all neighbouring tiles bc we may
|
||||
# need to place walls there eventually
|
||||
for ny, nx in Map.neighbourhood(level, ly, lx, large=True, oob=True):
|
||||
if not(0 <= ny < lh and 0 <= nx < lw) or \
|
||||
level[ny][nx] != Tile.EMPTY:
|
||||
return False
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in New Issue