From 462a547f78080fbd371c318945352bf9a08001bb Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 16 Sep 2025 16:59:51 -0400 Subject: [Apworld] Fix indirect conditions for deep reqs --- apworld/player_logic.py | 23 +++++++++++++++++++++++ apworld/regions.py | 23 ++++++++++++----------- 2 files changed, 35 insertions(+), 11 deletions(-) (limited to 'apworld') diff --git a/apworld/player_logic.py b/apworld/player_logic.py index ce6ae24..4aa481d 100644 --- a/apworld/player_logic.py +++ b/apworld/player_logic.py @@ -144,6 +144,29 @@ class AccessRequirements: if resimplify: self.simplify() + def get_referenced_rooms(self): + result = set(self.rooms) + + for disjunction in self.or_logic: + for sub_req in disjunction: + result = result.union(sub_req.get_referenced_rooms()) + + for sub_req in self.possibilities: + result = result.union(sub_req.get_referenced_rooms()) + + return result + + def remove_room(self, room: str): + if room in self.rooms: + self.rooms.remove(room) + + for disjunction in self.or_logic: + for sub_req in disjunction: + sub_req.remove_room(room) + + for sub_req in self.possibilities: + sub_req.remove_room(room) + def __repr__(self): parts = [] if len(self.items) > 0: diff --git a/apworld/regions.py b/apworld/regions.py index 4f1dd55..fad9bc7 100644 --- a/apworld/regions.py +++ b/apworld/regions.py @@ -17,8 +17,7 @@ def create_region(room, world: "Lingo2World") -> Region: def create_locations(room, new_region: Region, world: "Lingo2World", regions: dict[str, Region]): for location in world.player_logic.locations_by_room.get(room.id, {}): reqs = location.reqs.copy() - if new_region.name in reqs.rooms: - reqs.rooms.remove(new_region.name) + reqs.remove_room(new_region.name) new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], location.code, new_region) @@ -58,6 +57,10 @@ def create_regions(world: "Lingo2World"): from_region = world.static_logic.get_room_region_name(connection.from_room) to_region = world.static_logic.get_room_region_name(connection.to_room) + + if from_region not in regions or to_region not in regions: + continue + connection_name = f"{from_region} -> {to_region}" reqs = AccessRequirements() @@ -95,17 +98,15 @@ def create_regions(world: "Lingo2World"): connection_name = f"{connection_name} (via panel {panel.name})" reqs.simplify() + reqs.remove_room(from_region) - if from_region in regions and to_region in regions: - connection = Entrance(world.player, connection_name, regions[from_region]) - connection.access_rule = make_location_lambda(reqs, world, regions) + connection = Entrance(world.player, connection_name, regions[from_region]) + connection.access_rule = make_location_lambda(reqs, world, regions) - regions[from_region].exits.append(connection) - connection.connect(regions[to_region]) + regions[from_region].exits.append(connection) + connection.connect(regions[to_region]) - for region in reqs.rooms: - if region == from_region: - continue - world.multiworld.register_indirect_condition(regions[region], connection) + for region in reqs.get_referenced_rooms(): + world.multiworld.register_indirect_condition(regions[region], connection) world.multiworld.regions += regions.values() -- cgit 1.4.1