Skip to content

Commit

Permalink
Core, some worlds: Rename sweep_for_events to sweep_for_advancements (A…
Browse files Browse the repository at this point in the history
…rchipelagoMW#3571)

* Rename sweep_for_events to sweep_for_advancements

* more event->advancement renames

* oops accidentally deleted the deprecation thing in the force push

* Update TestDungeon.py

* Update BaseClasses.py

* Update BaseClasses.py

* oops

* utils.deprecate

* treble, you had no idea how right you were

* Update test_panel_hunt.py

* Update BaseClasses.py

Co-authored-by: Fabian Dill <[email protected]>

---------

Co-authored-by: Fabian Dill <[email protected]>
  • Loading branch information
NewSoupVi and Berserker66 authored Aug 22, 2024
1 parent 74aab81 commit 64b654d
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 48 deletions.
37 changes: 21 additions & 16 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def get_all_state(self, use_cache: bool) -> CollectionState:
subworld = self.worlds[player]
for item in subworld.get_pre_fill_items():
subworld.collect(ret, item)
ret.sweep_for_events()
ret.sweep_for_advancements()

if use_cache:
self._all_state = ret
Expand Down Expand Up @@ -661,7 +661,7 @@ class CollectionState():
multiworld: MultiWorld
reachable_regions: Dict[int, Set[Region]]
blocked_connections: Dict[int, Set[Entrance]]
events: Set[Location]
advancements: Set[Location]
path: Dict[Union[Region, Entrance], PathValue]
locations_checked: Set[Location]
stale: Dict[int, bool]
Expand All @@ -673,7 +673,7 @@ def __init__(self, parent: MultiWorld):
self.multiworld = parent
self.reachable_regions = {player: set() for player in parent.get_all_ids()}
self.blocked_connections = {player: set() for player in parent.get_all_ids()}
self.events = set()
self.advancements = set()
self.path = {}
self.locations_checked = set()
self.stale = {player: True for player in parent.get_all_ids()}
Expand Down Expand Up @@ -722,7 +722,7 @@ def copy(self) -> CollectionState:
self.reachable_regions.items()}
ret.blocked_connections = {player: entrance_set.copy() for player, entrance_set in
self.blocked_connections.items()}
ret.events = self.events.copy()
ret.advancements = self.advancements.copy()
ret.path = self.path.copy()
ret.locations_checked = self.locations_checked.copy()
for function in self.additional_copy_functions:
Expand Down Expand Up @@ -755,19 +755,24 @@ def can_reach_region(self, spot: str, player: int) -> bool:
return self.multiworld.get_region(spot, player).can_reach(self)

def sweep_for_events(self, locations: Optional[Iterable[Location]] = None) -> None:
Utils.deprecate("sweep_for_events has been renamed to sweep_for_advancements. The functionality is the same. "
"Please switch over to sweep_for_advancements.")
return self.sweep_for_advancements(locations)

def sweep_for_advancements(self, locations: Optional[Iterable[Location]] = None) -> None:
if locations is None:
locations = self.multiworld.get_filled_locations()
reachable_events = True
# since the loop has a good chance to run more than once, only filter the events once
locations = {location for location in locations if location.advancement and location not in self.events}

while reachable_events:
reachable_events = {location for location in locations if location.can_reach(self)}
locations -= reachable_events
for event in reachable_events:
self.events.add(event)
assert isinstance(event.item, Item), "tried to collect Event with no Item"
self.collect(event.item, True, event)
reachable_advancements = True
# since the loop has a good chance to run more than once, only filter the advancements once
locations = {location for location in locations if location.advancement and location not in self.advancements}

while reachable_advancements:
reachable_advancements = {location for location in locations if location.can_reach(self)}
locations -= reachable_advancements
for advancement in reachable_advancements:
self.advancements.add(advancement)
assert isinstance(advancement.item, Item), "tried to collect Event with no Item"
self.collect(advancement.item, True, advancement)

# item name related
def has(self, item: str, player: int, count: int = 1) -> bool:
Expand Down Expand Up @@ -871,7 +876,7 @@ def collect(self, item: Item, prevent_sweep: bool = False, location: Optional[Lo
self.stale[item.player] = True

if changed and not prevent_sweep:
self.sweep_for_events()
self.sweep_for_advancements()

return changed

Expand Down
14 changes: 7 additions & 7 deletions Fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def sweep_from_pool(base_state: CollectionState, itempool: typing.Sequence[Item]
new_state = base_state.copy()
for item in itempool:
new_state.collect(item, True)
new_state.sweep_for_events(locations=locations)
new_state.sweep_for_advancements(locations=locations)
return new_state


Expand Down Expand Up @@ -329,8 +329,8 @@ def accessibility_corrections(multiworld: MultiWorld, state: CollectionState, lo
pool.append(location.item)
state.remove(location.item)
location.item = None
if location in state.events:
state.events.remove(location)
if location in state.advancements:
state.advancements.remove(location)
locations.append(location)
if pool and locations:
locations.sort(key=lambda loc: loc.progress_type != LocationProgressType.PRIORITY)
Expand Down Expand Up @@ -363,7 +363,7 @@ def distribute_early_items(multiworld: MultiWorld,
early_priority_locations: typing.List[Location] = []
loc_indexes_to_remove: typing.Set[int] = set()
base_state = multiworld.state.copy()
base_state.sweep_for_events(locations=(loc for loc in multiworld.get_filled_locations() if loc.address is None))
base_state.sweep_for_advancements(locations=(loc for loc in multiworld.get_filled_locations() if loc.address is None))
for i, loc in enumerate(fill_locations):
if loc.can_reach(base_state):
if loc.progress_type == LocationProgressType.PRIORITY:
Expand Down Expand Up @@ -558,7 +558,7 @@ def flood_items(multiworld: MultiWorld) -> None:
progress_done = False

# sweep once to pick up preplaced items
multiworld.state.sweep_for_events()
multiworld.state.sweep_for_advancements()

# fill multiworld from top of itempool while we can
while not progress_done:
Expand Down Expand Up @@ -746,7 +746,7 @@ def item_percentage(player: int, num: int) -> float:
), items_to_test):
reducing_state.collect(location.item, True, location)

reducing_state.sweep_for_events(locations=locations_to_test)
reducing_state.sweep_for_advancements(locations=locations_to_test)

if multiworld.has_beaten_game(balancing_state):
if not multiworld.has_beaten_game(reducing_state):
Expand Down Expand Up @@ -829,7 +829,7 @@ def failed(warning: str, force: typing.Union[bool, str]) -> None:
warn(warning, force)

swept_state = multiworld.state.copy()
swept_state.sweep_for_events()
swept_state.sweep_for_advancements()
reachable = frozenset(multiworld.get_reachable_locations(swept_state))
early_locations: typing.Dict[int, typing.List[str]] = collections.defaultdict(list)
non_early_locations: typing.Dict[int, typing.List[str]] = collections.defaultdict(list)
Expand Down
6 changes: 3 additions & 3 deletions test/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_state(self, items):
for item in items:
item.classification = ItemClassification.progression
state.collect(item, prevent_sweep=True)
state.sweep_for_events()
state.sweep_for_advancements()
state.update_reachable_regions(1)
self._state_cache[self.multiworld, tuple(items)] = state
return state
Expand Down Expand Up @@ -221,8 +221,8 @@ def remove(self, items: typing.Union[Item, typing.Iterable[Item]]) -> None:
if isinstance(items, Item):
items = (items,)
for item in items:
if item.location and item.advancement and item.location in self.multiworld.state.events:
self.multiworld.state.events.remove(item.location)
if item.location and item.advancement and item.location in self.multiworld.state.advancements:
self.multiworld.state.advancements.remove(item.location)
self.multiworld.state.remove(item)

def can_reach_location(self, location: str) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions test/general/test_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_minimal_mixed_fill(self):
location_pool = player1.locations[1:] + player2.locations
item_pool = player1.prog_items[:-1] + player2.prog_items
fill_restrictive(multiworld, multiworld.state, location_pool, item_pool)
multiworld.state.sweep_for_events() # collect everything
multiworld.state.sweep_for_advancements() # collect everything

# all of player2's locations and items should be accessible (not all of player1's)
for item in player2.prog_items:
Expand Down Expand Up @@ -443,8 +443,8 @@ def test_double_sweep(self):
item = player1.prog_items[0]
item.code = None
location.place_locked_item(item)
multiworld.state.sweep_for_events()
multiworld.state.sweep_for_events()
multiworld.state.sweep_for_advancements()
multiworld.state.sweep_for_advancements()
self.assertTrue(multiworld.state.prog_items[item.player][item.name], "Sweep did not collect - Test flawed")
self.assertEqual(multiworld.state.prog_items[item.player][item.name], 1, "Sweep collected multiple times")

Expand Down
6 changes: 3 additions & 3 deletions worlds/alttp/Dungeons.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def fill_dungeons_restrictive(multiworld: MultiWorld):
pass
for item in pre_fill_items:
multiworld.worlds[item.player].collect(all_state_base, item)
all_state_base.sweep_for_events()
all_state_base.sweep_for_advancements()

# Remove completion condition so that minimal-accessibility worlds place keys properly
for player in {item.player for item in in_dungeon_items}:
Expand All @@ -262,8 +262,8 @@ def fill_dungeons_restrictive(multiworld: MultiWorld):
all_state_base.remove(item_factory(key_data[3], multiworld.worlds[player]))
loc = multiworld.get_location(key_loc, player)

if loc in all_state_base.events:
all_state_base.events.remove(loc)
if loc in all_state_base.advancements:
all_state_base.advancements.remove(loc)
fill_restrictive(multiworld, all_state_base, locations, in_dungeon_items, lock=True, allow_excluded=True,
name="LttP Dungeon Items")

Expand Down
4 changes: 2 additions & 2 deletions worlds/alttp/test/dungeons/TestDungeon.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def run_tests(self, access_pool):

for item in items:
item.classification = ItemClassification.progression
state.collect(item, prevent_sweep=True) # prevent_sweep=True prevents running sweep_for_events() and picking up
state.sweep_for_events() # key drop keys repeatedly
state.collect(item, prevent_sweep=True) # prevent_sweep=True prevents running sweep_for_advancements() and picking up
state.sweep_for_advancements() # key drop keys repeatedly

self.assertEqual(self.multiworld.get_location(location, 1).can_reach(state), access, f"failed {self.multiworld.get_location(location, 1)} with: {item_pool}")
2 changes: 1 addition & 1 deletion worlds/lingo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def create_regions(self):
state.collect(self.create_item(self.player_logic.forced_good_item), True)

all_locations = self.multiworld.get_locations(self.player)
state.sweep_for_events(locations=all_locations)
state.sweep_for_advancements(locations=all_locations)

unreachable_locations = [location for location in all_locations
if not state.can_reach_location(location.name, self.player)]
Expand Down
6 changes: 3 additions & 3 deletions worlds/oot/EntranceShuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def shuffle_random_entrances(ootworld):

# Gather locations to keep reachable for validation
all_state = ootworld.get_state_with_complete_itempool()
all_state.sweep_for_events(locations=ootworld.get_locations())
all_state.sweep_for_advancements(locations=ootworld.get_locations())
locations_to_ensure_reachable = {loc for loc in world.get_reachable_locations(all_state, player) if not (loc.type == 'Drop' or (loc.type == 'Event' and 'Subrule' in loc.name))}

# Set entrance data for all entrances
Expand Down Expand Up @@ -791,8 +791,8 @@ def validate_world(ootworld, entrance_placed, locations_to_ensure_reachable, all
all_state = all_state_orig.copy()
none_state = none_state_orig.copy()

all_state.sweep_for_events(locations=ootworld.get_locations())
none_state.sweep_for_events(locations=ootworld.get_locations())
all_state.sweep_for_advancements(locations=ootworld.get_locations())
none_state.sweep_for_advancements(locations=ootworld.get_locations())

if ootworld.shuffle_interior_entrances or ootworld.shuffle_overworld_entrances or ootworld.spawn_positions:
time_travel_state = none_state.copy()
Expand Down
2 changes: 1 addition & 1 deletion worlds/oot/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def set_shop_rules(ootworld):
def set_entrances_based_rules(ootworld):

all_state = ootworld.get_state_with_complete_itempool()
all_state.sweep_for_events(locations=ootworld.get_locations())
all_state.sweep_for_advancements(locations=ootworld.get_locations())

for location in filter(lambda location: location.type == 'Shop', ootworld.get_locations()):
# If a shop is not reachable as adult, it can't have Goron Tunic or Zora Tunic as child can't buy these
Expand Down
6 changes: 3 additions & 3 deletions worlds/oot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def generate_basic(self): # mostly killing locations that shouldn't exist by se
# Make sure to only kill actual internal events, not in-game "events"
all_state = self.get_state_with_complete_itempool()
all_locations = self.get_locations()
all_state.sweep_for_events(locations=all_locations)
all_state.sweep_for_advancements(locations=all_locations)
reachable = self.multiworld.get_reachable_locations(all_state, self.player)
unreachable = [loc for loc in all_locations if
(loc.internal or loc.type == 'Drop') and loc.address is None and loc.locked and loc not in reachable]
Expand Down Expand Up @@ -875,7 +875,7 @@ def prefill_state(base_state):
state = base_state.copy()
for item in self.get_pre_fill_items():
self.collect(state, item)
state.sweep_for_events(locations=self.get_locations())
state.sweep_for_advancements(locations=self.get_locations())
return state

# Prefill shops, songs, and dungeon items
Expand All @@ -887,7 +887,7 @@ def prefill_state(base_state):
state = CollectionState(self.multiworld)
for item in self.itempool:
self.collect(state, item)
state.sweep_for_events(locations=self.get_locations())
state.sweep_for_advancements(locations=self.get_locations())

# Place dungeon items
special_fill_types = ['GanonBossKey', 'BossKey', 'SmallKey', 'HideoutSmallKey', 'Map', 'Compass']
Expand Down
2 changes: 1 addition & 1 deletion worlds/pokemon_rb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def fill_hook(self, progitempool, usefulitempool, filleritempool, fill_locations
if attempt > 1:
for mon in poke_data.pokemon_data.keys():
state.collect(self.create_item(mon), True)
state.sweep_for_events()
state.sweep_for_advancements()
self.multiworld.random.shuffle(badges)
self.multiworld.random.shuffle(badgelocs)
badgelocs_copy = badgelocs.copy()
Expand Down
4 changes: 2 additions & 2 deletions worlds/pokemon_rb/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2439,7 +2439,7 @@ def adds_reachable_entrances(item):

state_copy = state.copy()
state_copy.collect(item, True)
state.sweep_for_events(locations=event_locations)
state.sweep_for_advancements(locations=event_locations)
new_reachable_entrances = len([entrance for entrance in entrances if entrance in reachable_entrances or
entrance.parent_region.can_reach(state_copy)])
return new_reachable_entrances > len(reachable_entrances)
Expand Down Expand Up @@ -2480,7 +2480,7 @@ def dead_end(e):

while entrances:
state.update_reachable_regions(player)
state.sweep_for_events(locations=event_locations)
state.sweep_for_advancements(locations=event_locations)

multiworld.random.shuffle(entrances)

Expand Down
2 changes: 1 addition & 1 deletion worlds/witness/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def create_regions(self) -> None:
# Only sweeps for events because having this behavior be random based on Tutorial Gate would be strange.

state = CollectionState(self.multiworld)
state.sweep_for_events(locations=event_locations)
state.sweep_for_advancements(locations=event_locations)

num_early_locs = sum(1 for loc in self.multiworld.get_reachable_locations(state, self.player) if loc.address)

Expand Down
4 changes: 2 additions & 2 deletions worlds/witness/test/test_panel_hunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_correct_panels_were_picked(self):

for _ in range(100):
state_100.collect(panel_hunt_item, True)
state_100.sweep_for_events([self.world.get_location("Tutorial Gate Open Solved")])
state_100.sweep_for_advancements([self.world.get_location("Tutorial Gate Open Solved")])

self.assertTrue(self.multiworld.completion_condition[self.player](state_100))

Expand All @@ -33,7 +33,7 @@ def test_correct_panels_were_picked(self):

for _ in range(99):
state_99.collect(panel_hunt_item, True)
state_99.sweep_for_events([self.world.get_location("Tutorial Gate Open Solved")])
state_99.sweep_for_advancements([self.world.get_location("Tutorial Gate Open Solved")])

self.assertFalse(self.multiworld.completion_condition[self.player](state_99))

Expand Down

0 comments on commit 64b654d

Please sign in to comment.