about summary refs log tree commit diff stats
path: root/apworld/regions.py
diff options
context:
space:
mode:
Diffstat (limited to 'apworld/regions.py')
-rw-r--r--apworld/regions.py41
1 files changed, 38 insertions, 3 deletions
diff --git a/apworld/regions.py b/apworld/regions.py index 0c3858d..1118603 100644 --- a/apworld/regions.py +++ b/apworld/regions.py
@@ -62,6 +62,9 @@ def create_regions(world: "Lingo2World"):
62 # locations. This allows us to reference the actual region objects in the access rules for the locations, which is 62 # locations. This allows us to reference the actual region objects in the access rules for the locations, which is
63 # faster than having to look them up during access checking. 63 # faster than having to look them up during access checking.
64 for room in world.static_logic.objects.rooms: 64 for room in world.static_logic.objects.rooms:
65 if room.map_id not in world.player_logic.shuffled_maps:
66 continue
67
65 region = create_region(room, world) 68 region = create_region(room, world)
66 regions[region.name] = region 69 regions[region.name] = region
67 region_and_room.append((region, room)) 70 region_and_room.append((region, room))
@@ -156,10 +159,42 @@ def shuffle_entrances(world: "Lingo2World"):
156 159
157 port_id_by_name: dict[str, int] = {} 160 port_id_by_name: dict[str, int] = {}
158 161
159 for port in world.static_logic.objects.ports: 162 shuffleable_ports = [port for port in world.static_logic.objects.ports
160 if port.no_shuffle: 163 if not port.no_shuffle
161 continue 164 and world.static_logic.get_room_object_map_id(port) in world.player_logic.shuffled_maps]
165
166 if len(shuffleable_ports) % 2 == 1:
167 # We have an odd number of shuffleable ports! Pick a port from a room that has more than one, and make it a
168 # redundant warp to another port.
169 redundant_rooms = set(room.id for room in world.static_logic.objects.rooms if len(room.ports) > 1)
170 redundant_ports = [port for port in shuffleable_ports if port.room_id in redundant_rooms]
171 chosen_port = world.random.choice(redundant_ports)
172
173 shuffleable_ports.remove(chosen_port)
174
175 chosen_destination = world.random.choice(shuffleable_ports)
176
177 world.port_pairings[chosen_port.id] = chosen_destination.id
178
179 from_region_name = world.static_logic.get_room_region_name(chosen_port.room_id)
180 to_region_name = world.static_logic.get_room_region_name(chosen_destination.room_id)
181
182 from_region = world.multiworld.get_region(from_region_name, world.player)
183 to_region = world.multiworld.get_region(to_region_name, world.player)
184
185 connection = Entrance(world.player, f"{from_region_name} - {chosen_port.display_name}", from_region)
186 from_region.exits.append(connection)
187 connection.connect(to_region)
188
189 if chosen_port.HasField("required_door"):
190 door_reqs = world.player_logic.get_door_open_reqs(chosen_port.required_door)
191 connection.access_rule = make_location_lambda(door_reqs, world, None)
192
193 for region in door_reqs.get_referenced_rooms():
194 world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player),
195 connection)
162 196
197 for port in shuffleable_ports:
163 port_region_name = world.static_logic.get_room_region_name(port.room_id) 198 port_region_name = world.static_logic.get_room_region_name(port.room_id)
164 port_region = world.multiworld.get_region(port_region_name, world.player) 199 port_region = world.multiworld.get_region(port_region_name, world.player)
165 200