Skip to content

Commit adef99b

Browse files
ScipioWrightqwint
authored andcommitted
TUNIC: Error catching for logic bugs in ER (ArchipelagoMW#3082)
1 parent 95e78ca commit adef99b

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

worlds/tunic/__init__.py

+25-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Dict, List, Any
2-
2+
from logging import warning
33
from BaseClasses import Region, Location, Item, Tutorial, ItemClassification
44
from .items import item_name_to_id, item_table, item_name_groups, fool_tiers, filler_items, slot_data_item_names
55
from .locations import location_table, location_name_groups, location_name_to_id, hexagon_locations
@@ -123,7 +123,7 @@ def create_items(self) -> None:
123123
# Filler items in the item pool
124124
available_filler: List[str] = [filler for filler in items_to_create if items_to_create[filler] > 0 and
125125
item_table[filler].classification == ItemClassification.filler]
126-
126+
127127
# Remove filler to make room for other items
128128
def remove_filler(amount: int):
129129
for _ in range(0, amount):
@@ -150,7 +150,7 @@ def remove_filler(amount: int):
150150
hexagon_goal = self.options.hexagon_goal
151151
extra_hexagons = self.options.extra_hexagon_percentage
152152
items_to_create[gold_hexagon] += int((Decimal(100 + extra_hexagons) / 100 * hexagon_goal).to_integral_value(rounding=ROUND_HALF_UP))
153-
153+
154154
# Replace pages and normal hexagons with filler
155155
for replaced_item in list(filter(lambda item: "Pages" in item or item in hexagon_locations, items_to_create)):
156156
filler_name = self.get_filler_item_name()
@@ -184,7 +184,7 @@ def create_regions(self) -> None:
184184
self.tunic_portal_pairs = {}
185185
self.er_portal_hints = {}
186186
self.ability_unlocks = randomize_ability_unlocks(self.random, self.options)
187-
187+
188188
# stuff for universal tracker support, can be ignored for standard gen
189189
if hasattr(self.multiworld, "re_gen_passthrough"):
190190
if "TUNIC" in self.multiworld.re_gen_passthrough:
@@ -245,17 +245,27 @@ def extend_hint_information(self, hint_data: Dict[int, Dict[int, str]]):
245245
continue
246246
path_to_loc = []
247247
previous_name = "placeholder"
248-
name, connection = paths[location.parent_region]
249-
while connection != ("Menu", None):
250-
name, connection = connection
251-
# for LS entrances, we just want to give the portal name
252-
if "(LS)" in name:
253-
name, _ = name.split(" (LS) ")
254-
# was getting some cases like Library Grave -> Library Grave -> other place
255-
if name in portal_names and name != previous_name:
256-
previous_name = name
257-
path_to_loc.append(name)
258-
hint_text = " -> ".join(reversed(path_to_loc))
248+
try:
249+
name, connection = paths[location.parent_region]
250+
except KeyError:
251+
# logic bug, proceed with warning since it takes a long time to update AP
252+
warning(f"{location.name} is not logically accessible for "
253+
f"{self.multiworld.get_file_safe_player_name(self.player)}. "
254+
"Creating entrance hint Inaccessible. "
255+
"Please report this to the TUNIC rando devs.")
256+
hint_text = "Inaccessible"
257+
else:
258+
while connection != ("Menu", None):
259+
name, connection = connection
260+
# for LS entrances, we just want to give the portal name
261+
if "(LS)" in name:
262+
name, _ = name.split(" (LS) ")
263+
# was getting some cases like Library Grave -> Library Grave -> other place
264+
if name in portal_names and name != previous_name:
265+
previous_name = name
266+
path_to_loc.append(name)
267+
hint_text = " -> ".join(reversed(path_to_loc))
268+
259269
if hint_text:
260270
hint_data[self.player][location.address] = hint_text
261271

0 commit comments

Comments
 (0)