diff --git a/worlds/pokemon_rb/regions.py b/worlds/pokemon_rb/regions.py index 1816d010..f8449765 100644 --- a/worlds/pokemon_rb/regions.py +++ b/worlds/pokemon_rb/regions.py @@ -1594,7 +1594,7 @@ def create_regions(self): connect(multiworld, player, "Menu", "Pallet Town", one_way=True) connect(multiworld, player, "Menu", "Pokedex", one_way=True) connect(multiworld, player, "Menu", "Evolution", one_way=True) - connect(multiworld, player, "Menu", "Fossil", lambda state: logic.fossil_checks(state, + connect(multiworld, player, "Menu", "Fossil", lambda state: logic.fossil_checks(state, state.multiworld.second_fossil_check_condition[player].value, player), one_way=True) connect(multiworld, player, "Pallet Town", "Route 1") connect(multiworld, player, "Route 1", "Viridian City") @@ -2269,23 +2269,28 @@ def create_regions(self): event_locations = self.multiworld.get_filled_locations(player) - def adds_reachable_entrances(entrances_copy, item): + def adds_reachable_entrances(entrances_copy, item, dead_end_cache): + ret = dead_end_cache.get(item.name) + if (ret != None): + return ret + state_copy = state.copy() 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) + dead_end_cache[item.name] = ret return ret - def dead_end(entrances_copy, e): + def dead_end(entrances_copy, e, dead_end_cache): region = e.parent_region check_warps = set() checked_regions = {region} check_warps.update(region.exits) check_warps.remove(e) for location in region.locations: - if location.item and location.item.name in relevant_events and adds_reachable_entrances(entrances_copy, - location.item): + if location.item and location.item.name in relevant_events and \ + adds_reachable_entrances(entrances_copy, location.item, dead_end_cache): return False while check_warps: warp = check_warps.pop() @@ -2302,7 +2307,7 @@ def create_regions(self): check_warps.update(warp.connected_region.exits) for location in warp.connected_region.locations: if (location.item and location.item.name in relevant_events and - adds_reachable_entrances(entrances_copy, location.item)): + adds_reachable_entrances(entrances_copy, location.item, dead_end_cache)): return False return True @@ -2332,6 +2337,8 @@ 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) + dead_end_cache = {} + # 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": @@ -2342,10 +2349,10 @@ def create_regions(self): elif len(reachable_entrances) > (1 if multiworld.door_shuffle[player] == "insanity" else 8) and len( entrances) <= (starting_entrances - 3): entrances.sort(key=lambda e: 0 if e in reachable_entrances else 2 if - dead_end(entrances_copy, e) else 1) + dead_end(entrances_copy, e, dead_end_cache) else 1) else: entrances.sort(key=lambda e: 0 if e in reachable_entrances else 1 if - dead_end(entrances_copy, e) else 2) + dead_end(entrances_copy, e, dead_end_cache) else 2) if multiworld.door_shuffle[player] == "full": outdoor = outdoor_map(entrances[0].parent_region.name) if len(entrances) < 48 and not outdoor: