Fill: Priority locks when placing and does not swap. (#1099)

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
Fabian Dill 2022-10-18 01:07:06 +02:00 committed by GitHub
parent 1aa3e431c8
commit af0cfc5a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 67 additions and 54 deletions

25
Fill.py
View File

@ -23,7 +23,8 @@ def sweep_from_pool(base_state: CollectionState, itempool: typing.Sequence[Item]
def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations: typing.List[Location],
itempool: typing.List[Item], single_player_placement: bool = False, lock: bool = False) -> None:
itempool: typing.List[Item], single_player_placement: bool = False, lock: bool = False,
swap: bool = True, on_place: typing.Optional[typing.Callable[[Location], None]] = None) -> None:
unplaced_items: typing.List[Item] = []
placements: typing.List[Location] = []
@ -70,6 +71,7 @@ def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations:
else:
# we filled all reachable spots.
if swap:
# try swapping this item with previously placed items
for (i, location) in enumerate(placements):
placed_item = location.item
@ -120,11 +122,15 @@ def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations:
# Can't place this item, move on to the next
unplaced_items.append(item_to_place)
continue
else:
unplaced_items.append(item_to_place)
continue
world.push_item(spot_to_fill, item_to_place, False)
spot_to_fill.locked = lock
placements.append(spot_to_fill)
spot_to_fill.event = item_to_place.advancement
if on_place:
on_place(spot_to_fill)
if len(unplaced_items) > 0 and len(locations) > 0:
# There are leftover unplaceable items and locations that won't accept them
@ -272,19 +278,26 @@ def distribute_items_restrictive(world: MultiWorld) -> None:
defaultlocations = locations[LocationProgressType.DEFAULT]
excludedlocations = locations[LocationProgressType.EXCLUDED]
prioritylocations_lock = prioritylocations.copy()
# can't lock due to accessibility corrections touching things, so we remember which ones got placed and lock later
lock_later = []
fill_restrictive(world, world.state, prioritylocations, progitempool)
def mark_for_locking(location: Location):
nonlocal lock_later
lock_later.append(location)
# "priority fill"
fill_restrictive(world, world.state, prioritylocations, progitempool, swap=False, on_place=mark_for_locking)
accessibility_corrections(world, world.state, prioritylocations, progitempool)
for location in prioritylocations_lock:
if location.item:
for location in lock_later:
location.locked = True
del mark_for_locking, lock_later
if prioritylocations:
defaultlocations = prioritylocations + defaultlocations
if progitempool:
# "progression fill"
fill_restrictive(world, world.state, defaultlocations, progitempool)
if progitempool:
raise FillError(