Pokemon R/B: Avoid a case of repeatedly checking of state in ER (#2376)
This commit is contained in:
parent
b16804102d
commit
6061bffbb6
|
@ -1594,7 +1594,7 @@ def create_regions(self):
|
||||||
connect(multiworld, player, "Menu", "Pallet Town", one_way=True)
|
connect(multiworld, player, "Menu", "Pallet Town", one_way=True)
|
||||||
connect(multiworld, player, "Menu", "Pokedex", one_way=True)
|
connect(multiworld, player, "Menu", "Pokedex", one_way=True)
|
||||||
connect(multiworld, player, "Menu", "Evolution", 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)
|
state.multiworld.second_fossil_check_condition[player].value, player), one_way=True)
|
||||||
connect(multiworld, player, "Pallet Town", "Route 1")
|
connect(multiworld, player, "Pallet Town", "Route 1")
|
||||||
connect(multiworld, player, "Route 1", "Viridian City")
|
connect(multiworld, player, "Route 1", "Viridian City")
|
||||||
|
@ -2269,23 +2269,28 @@ def create_regions(self):
|
||||||
|
|
||||||
event_locations = self.multiworld.get_filled_locations(player)
|
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 = state.copy()
|
||||||
state_copy.collect(item, True)
|
state_copy.collect(item, True)
|
||||||
state.sweep_for_events(locations=event_locations)
|
state.sweep_for_events(locations=event_locations)
|
||||||
ret = len([entrance for entrance in entrances_copy if entrance in reachable_entrances or
|
ret = len([entrance for entrance in entrances_copy if entrance in reachable_entrances or
|
||||||
entrance.parent_region.can_reach(state_copy)]) > len(reachable_entrances)
|
entrance.parent_region.can_reach(state_copy)]) > len(reachable_entrances)
|
||||||
|
dead_end_cache[item.name] = ret
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def dead_end(entrances_copy, e):
|
def dead_end(entrances_copy, e, dead_end_cache):
|
||||||
region = e.parent_region
|
region = e.parent_region
|
||||||
check_warps = set()
|
check_warps = set()
|
||||||
checked_regions = {region}
|
checked_regions = {region}
|
||||||
check_warps.update(region.exits)
|
check_warps.update(region.exits)
|
||||||
check_warps.remove(e)
|
check_warps.remove(e)
|
||||||
for location in region.locations:
|
for location in region.locations:
|
||||||
if location.item and location.item.name in relevant_events and adds_reachable_entrances(entrances_copy,
|
if location.item and location.item.name in relevant_events and \
|
||||||
location.item):
|
adds_reachable_entrances(entrances_copy, location.item, dead_end_cache):
|
||||||
return False
|
return False
|
||||||
while check_warps:
|
while check_warps:
|
||||||
warp = check_warps.pop()
|
warp = check_warps.pop()
|
||||||
|
@ -2302,7 +2307,7 @@ def create_regions(self):
|
||||||
check_warps.update(warp.connected_region.exits)
|
check_warps.update(warp.connected_region.exits)
|
||||||
for location in warp.connected_region.locations:
|
for location in warp.connected_region.locations:
|
||||||
if (location.item and location.item.name in relevant_events and
|
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 False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -2332,6 +2337,8 @@ def create_regions(self):
|
||||||
if multiworld.door_shuffle[player] == "full" or len(entrances) != len(reachable_entrances):
|
if multiworld.door_shuffle[player] == "full" or len(entrances) != len(reachable_entrances):
|
||||||
entrances.sort(key=lambda e: e.name not in entrance_only)
|
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 list is empty while it's being sorted, must pass a copy to iterate through
|
||||||
entrances_copy = entrances.copy()
|
entrances_copy = entrances.copy()
|
||||||
if multiworld.door_shuffle[player] == "decoupled":
|
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(
|
elif len(reachable_entrances) > (1 if multiworld.door_shuffle[player] == "insanity" else 8) and len(
|
||||||
entrances) <= (starting_entrances - 3):
|
entrances) <= (starting_entrances - 3):
|
||||||
entrances.sort(key=lambda e: 0 if e in reachable_entrances else 2 if
|
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:
|
else:
|
||||||
entrances.sort(key=lambda e: 0 if e in reachable_entrances else 1 if
|
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":
|
if multiworld.door_shuffle[player] == "full":
|
||||||
outdoor = outdoor_map(entrances[0].parent_region.name)
|
outdoor = outdoor_map(entrances[0].parent_region.name)
|
||||||
if len(entrances) < 48 and not outdoor:
|
if len(entrances) < 48 and not outdoor:
|
||||||
|
|
Loading…
Reference in New Issue