From 434ed0b4207bdff3fa969d6ed6b1454952e78570 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:56:35 +0200 Subject: [PATCH 1/3] Core: Move connection.parent_region assert to can_reach This is how it already works for locations and it feels more correct to me to check in the place where the crash would happen. Also update location error to be a bit more verbose --- BaseClasses.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index a5de1689a7fe..0496918d9d45 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -720,7 +720,6 @@ def _update_reachable_regions_explicit_indirect_conditions(self, player: int, qu if new_region in reachable_regions: blocked_connections.remove(connection) elif connection.can_reach(self): - assert new_region, f"tried to search through an Entrance \"{connection}\" with no Region" reachable_regions.add(new_region) blocked_connections.remove(connection) blocked_connections.update(new_region.exits) @@ -946,6 +945,7 @@ def __init__(self, player: int, name: str = "", parent: Optional[Region] = None) self.player = player def can_reach(self, state: CollectionState) -> bool: + assert self.parent_region, f"called can_reach on an Entrance \"{self}\" with no parent_region" if self.parent_region.can_reach(state) and self.access_rule(state): if not self.hide_path and not self in state.path: state.path[self] = (self.name, state.path.get(self.parent_region, (self.parent_region.name, None))) @@ -1166,7 +1166,7 @@ def can_fill(self, state: CollectionState, item: Item, check_access: bool = True def can_reach(self, state: CollectionState) -> bool: # Region.can_reach is just a cache lookup, so placing it first for faster abort on average - assert self.parent_region, "Can't reach location without region" + assert self.parent_region, f"called can_reach on a Location \"{self}\" with no parent_region" return self.parent_region.can_reach(state) and self.access_rule(state) def place_locked_item(self, item: Item): From f45f16fa3fb956e4a615e1173d7ff4efe84f93bb Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:08:25 +0200 Subject: [PATCH 2/3] Bring back the other assert --- BaseClasses.py | 1 + 1 file changed, 1 insertion(+) diff --git a/BaseClasses.py b/BaseClasses.py index 0496918d9d45..a6399ffb3532 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -720,6 +720,7 @@ def _update_reachable_regions_explicit_indirect_conditions(self, player: int, qu if new_region in reachable_regions: blocked_connections.remove(connection) elif connection.can_reach(self): + assert new_region, f"tried to search through an Entrance \"{connection}\" with no connected region." reachable_regions.add(new_region) blocked_connections.remove(connection) blocked_connections.update(new_region.exits) From 28b728bc5c220ecc4bc2a46466196a283c67c588 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:09:00 +0200 Subject: [PATCH 3/3] Update BaseClasses.py --- BaseClasses.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseClasses.py b/BaseClasses.py index a6399ffb3532..916a5b18042d 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -720,7 +720,7 @@ def _update_reachable_regions_explicit_indirect_conditions(self, player: int, qu if new_region in reachable_regions: blocked_connections.remove(connection) elif connection.can_reach(self): - assert new_region, f"tried to search through an Entrance \"{connection}\" with no connected region." + assert new_region, f"tried to search through an Entrance \"{connection}\" with no connected Region" reachable_regions.add(new_region) blocked_connections.remove(connection) blocked_connections.update(new_region.exits)