diff options
| -rw-r--r-- | apworld/player_logic.py | 23 | ||||
| -rw-r--r-- | apworld/regions.py | 23 |
2 files changed, 35 insertions, 11 deletions
| 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: | |||
| 144 | if resimplify: | 144 | if resimplify: |
| 145 | self.simplify() | 145 | self.simplify() |
| 146 | 146 | ||
| 147 | def get_referenced_rooms(self): | ||
| 148 | result = set(self.rooms) | ||
| 149 | |||
| 150 | for disjunction in self.or_logic: | ||
| 151 | for sub_req in disjunction: | ||
| 152 | result = result.union(sub_req.get_referenced_rooms()) | ||
| 153 | |||
| 154 | for sub_req in self.possibilities: | ||
| 155 | result = result.union(sub_req.get_referenced_rooms()) | ||
| 156 | |||
| 157 | return result | ||
| 158 | |||
| 159 | def remove_room(self, room: str): | ||
| 160 | if room in self.rooms: | ||
| 161 | self.rooms.remove(room) | ||
| 162 | |||
| 163 | for disjunction in self.or_logic: | ||
| 164 | for sub_req in disjunction: | ||
| 165 | sub_req.remove_room(room) | ||
| 166 | |||
| 167 | for sub_req in self.possibilities: | ||
| 168 | sub_req.remove_room(room) | ||
| 169 | |||
| 147 | def __repr__(self): | 170 | def __repr__(self): |
| 148 | parts = [] | 171 | parts = [] |
| 149 | if len(self.items) > 0: | 172 | 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: | |||
| 17 | def create_locations(room, new_region: Region, world: "Lingo2World", regions: dict[str, Region]): | 17 | def create_locations(room, new_region: Region, world: "Lingo2World", regions: dict[str, Region]): |
| 18 | for location in world.player_logic.locations_by_room.get(room.id, {}): | 18 | for location in world.player_logic.locations_by_room.get(room.id, {}): |
| 19 | reqs = location.reqs.copy() | 19 | reqs = location.reqs.copy() |
| 20 | if new_region.name in reqs.rooms: | 20 | reqs.remove_room(new_region.name) |
| 21 | reqs.rooms.remove(new_region.name) | ||
| 22 | 21 | ||
| 23 | new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], | 22 | new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], |
| 24 | location.code, new_region) | 23 | location.code, new_region) |
| @@ -58,6 +57,10 @@ def create_regions(world: "Lingo2World"): | |||
| 58 | 57 | ||
| 59 | from_region = world.static_logic.get_room_region_name(connection.from_room) | 58 | from_region = world.static_logic.get_room_region_name(connection.from_room) |
| 60 | to_region = world.static_logic.get_room_region_name(connection.to_room) | 59 | to_region = world.static_logic.get_room_region_name(connection.to_room) |
| 60 | |||
| 61 | if from_region not in regions or to_region not in regions: | ||
| 62 | continue | ||
| 63 | |||
| 61 | connection_name = f"{from_region} -> {to_region}" | 64 | connection_name = f"{from_region} -> {to_region}" |
| 62 | 65 | ||
| 63 | reqs = AccessRequirements() | 66 | reqs = AccessRequirements() |
| @@ -95,17 +98,15 @@ def create_regions(world: "Lingo2World"): | |||
| 95 | connection_name = f"{connection_name} (via panel {panel.name})" | 98 | connection_name = f"{connection_name} (via panel {panel.name})" |
| 96 | 99 | ||
| 97 | reqs.simplify() | 100 | reqs.simplify() |
| 101 | reqs.remove_room(from_region) | ||
| 98 | 102 | ||
| 99 | if from_region in regions and to_region in regions: | 103 | connection = Entrance(world.player, connection_name, regions[from_region]) |
| 100 | connection = Entrance(world.player, connection_name, regions[from_region]) | 104 | connection.access_rule = make_location_lambda(reqs, world, regions) |
| 101 | connection.access_rule = make_location_lambda(reqs, world, regions) | ||
| 102 | 105 | ||
| 103 | regions[from_region].exits.append(connection) | 106 | regions[from_region].exits.append(connection) |
| 104 | connection.connect(regions[to_region]) | 107 | connection.connect(regions[to_region]) |
| 105 | 108 | ||
| 106 | for region in reqs.rooms: | 109 | for region in reqs.get_referenced_rooms(): |
| 107 | if region == from_region: | 110 | world.multiworld.register_indirect_condition(regions[region], connection) |
| 108 | continue | ||
| 109 | world.multiworld.register_indirect_condition(regions[region], connection) | ||
| 110 | 111 | ||
| 111 | world.multiworld.regions += regions.values() | 112 | world.multiworld.regions += regions.values() |
