LttP: speed up ER shuffling caves

This commit is contained in:
Fabian Dill 2021-05-07 21:01:13 +02:00
parent 9ab5ec426d
commit 5cb2689609
2 changed files with 5 additions and 10 deletions

View File

@ -2027,16 +2027,9 @@ def connect_caves(world, lw_entrances, dw_entrances, caves, player):
world.random.shuffle(lw_entrances)
world.random.shuffle(dw_entrances)
world.random.shuffle(caves)
while caves:
# connect highest exit count caves first, prevent issue where we have 2 or 3 exits accross worlds left to fill
cave_candidate = (None, 0)
for i, cave in enumerate(caves):
if isinstance(cave, str):
cave = (cave,)
if len(cave) > cave_candidate[1]:
cave_candidate = (i, len(cave))
cave = caves.pop(cave_candidate[0])
caves.sort(key=lambda cave: 1 if isinstance(cave, str) else len(cave), reverse=True)
for cave in caves:
target = lw_entrances if world.random.randint(0, 1) == 0 else dw_entrances
if isinstance(cave, str):
cave = (cave,)
@ -2048,6 +2041,7 @@ def connect_caves(world, lw_entrances, dw_entrances, caves, player):
for exit in cave:
connect_two_way(world, target.pop(), exit, player)
caves.clear() # emulating old behaviour of popping caves from the list in-place
def connect_doors(world, doors, targets, player):

View File

@ -511,6 +511,7 @@ class Sprite():
palette_size = 120
glove_size = 4
author_name: Optional[str] = None
base_data: bytes
def __init__(self, filename):
if not hasattr(Sprite, "base_data"):