This commit is contained in:
Yohann D'ANELLO 2021-01-10 23:49:43 +01:00
parent 2031d7fa67
commit 588357e5bf
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 21 additions and 24 deletions

View File

@ -26,9 +26,11 @@ DEFAULT_PARAMS = {
"spawn_per_region": [1, 2], "spawn_per_region": [1, 2],
} }
def dist(level, y1, x1, y2, x2):
def dist(level: List[List[Tile]], y1: int, x1: int, y2: int, x2: int) -> int:
""" """
Compute the minimum walking distance between points (y1, x1) and (y2, x2) on a Tile grid Compute the minimum walking distance between points (y1, x1) and (y2, x2)
on a Tile grid
""" """
# simple breadth first search # simple breadth first search
copy = [[t for t in row] for row in level] copy = [[t for t in row] for row in level]
@ -247,8 +249,8 @@ class Generator:
if room[y][x] == Tile.EMPTY and \ if room[y][x] == Tile.EMPTY and \
Generator.build_door(room, y, x, dy, dx, length): Generator.build_door(room, y, x, dy, dx, length):
break break
else: else: # pragma: no cover
return None, None return None, None, None, None
return y + length * dy, x + length * dx, dy, dx return y + length * dy, x + length * dx, dy, dx
@ -323,7 +325,7 @@ class Generator:
top left corner of the room on the level, then log them as a top left corner of the room on the level, then log them as a
spawnable region spawnable region
""" """
if self.queued_area != None: if self.queued_area is not None:
translated_area = [[y + ry, x + rx] for ry, rx in self.queued_area] translated_area = [[y + ry, x + rx] for ry, rx in self.queued_area]
self.spawn_areas.append(translated_area) self.spawn_areas.append(translated_area)
self.queued_area = None self.queued_area = None
@ -333,11 +335,6 @@ class Generator:
Populate every spawnable area with some randomly chosen, randomly Populate every spawnable area with some randomly chosen, randomly
placed entity placed entity
""" """
if self.queued_area is not None:
translated_area = [[y + ry, x + rx] for ry, rx in self.queued_area]
self.spawn_areas.append(translated_area)
self.queued_area = None
min_c, max_c = self.params["spawn_per_region"] min_c, max_c = self.params["spawn_per_region"]
for region in self.spawn_areas: for region in self.spawn_areas:
entity_count = randint(min_c, max_c) entity_count = randint(min_c, max_c)