From 195cf60e8ab2bc3674850044a85def0a416a111e Mon Sep 17 00:00:00 2001 From: Alchav <59858495+Alchav@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:28:16 -0400 Subject: [PATCH] =?UTF-8?q?Pok=C3=A9mon=20R/B:=20Door=20Shuffle=20efficien?= =?UTF-8?q?cy=20improvement=20and=20crash=20fix=20(#2347)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sweep only current player's locations so that more players does not slow it down. Fix a slight possibility of Full door shuffle crash by only sorting for outdoor dead ends only when connecting from a non-dead end. --- worlds/pokemon_rb/regions.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/worlds/pokemon_rb/regions.py b/worlds/pokemon_rb/regions.py index 431b23f4..1816d010 100644 --- a/worlds/pokemon_rb/regions.py +++ b/worlds/pokemon_rb/regions.py @@ -2267,9 +2267,12 @@ def create_regions(self): "Defeat Viridian Gym Giovanni", ] + event_locations = self.multiworld.get_filled_locations(player) + def adds_reachable_entrances(entrances_copy, item): state_copy = state.copy() - state_copy.collect(item, False) + state_copy.collect(item, True) + state.sweep_for_events(locations=event_locations) ret = len([entrance for entrance in entrances_copy if entrance in reachable_entrances or entrance.parent_region.can_reach(state_copy)]) > len(reachable_entrances) return ret @@ -2305,7 +2308,6 @@ def create_regions(self): starting_entrances = len(entrances) dc_connected = [] - event_locations = self.multiworld.get_filled_locations(player) rock_tunnel_entrances = [entrance for entrance in entrances if "Rock Tunnel" in entrance.name] entrances = [entrance for entrance in entrances if entrance not in rock_tunnel_entrances] while entrances: @@ -2330,10 +2332,6 @@ def create_regions(self): if multiworld.door_shuffle[player] == "full" or len(entrances) != len(reachable_entrances): entrances.sort(key=lambda e: e.name not in entrance_only) - if len(entrances) < 48 and multiworld.door_shuffle[player] == "full": - # Prevent a situation where the only remaining outdoor entrances are ones that cannot be reached - # except by connecting directly to it. - entrances.sort(key=lambda e: e.name in unreachable_outdoor_entrances) # entrances list is empty while it's being sorted, must pass a copy to iterate through entrances_copy = entrances.copy() if multiworld.door_shuffle[player] == "decoupled": @@ -2350,6 +2348,11 @@ def create_regions(self): dead_end(entrances_copy, e) else 2) if multiworld.door_shuffle[player] == "full": outdoor = outdoor_map(entrances[0].parent_region.name) + if len(entrances) < 48 and not outdoor: + # Prevent a situation where the only remaining outdoor entrances are ones that cannot be reached + # except by connecting directly to it. + entrances.sort(key=lambda e: e.name in unreachable_outdoor_entrances) + entrances.sort(key=lambda e: outdoor_map(e.parent_region.name) != outdoor) assert entrances[0] in reachable_entrances, \ "Ran out of valid reachable entrances in Pokemon Red and Blue door shuffle"