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:
Charles Peyrat
2021-01-08 07:38:47 +01:00
parent 605696dddd
commit 641f5c7872
2 changed files with 10 additions and 3 deletions

View File

@ -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