diff options
Diffstat (limited to 'apworld/regions.py')
| -rw-r--r-- | apworld/regions.py | 59 |
1 files changed, 53 insertions, 6 deletions
| diff --git a/apworld/regions.py b/apworld/regions.py index 9f44682..1118603 100644 --- a/apworld/regions.py +++ b/apworld/regions.py | |||
| @@ -28,6 +28,9 @@ def create_locations(room, new_region: Region, world: "Lingo2World", regions: di | |||
| 28 | 28 | ||
| 29 | for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items(): | 29 | for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items(): |
| 30 | new_location = Lingo2Location(world.player, event_name, None, new_region) | 30 | new_location = Lingo2Location(world.player, event_name, None, new_region) |
| 31 | if world.for_tracker and item_name == "Victory": | ||
| 32 | new_location.goal = True | ||
| 33 | |||
| 31 | event_item = Lingo2Item(item_name, ItemClassification.progression, None, world.player) | 34 | event_item = Lingo2Item(item_name, ItemClassification.progression, None, world.player) |
| 32 | new_location.place_locked_item(event_item) | 35 | new_location.place_locked_item(event_item) |
| 33 | new_region.locations.append(new_location) | 36 | new_region.locations.append(new_location) |
| @@ -59,6 +62,9 @@ def create_regions(world: "Lingo2World"): | |||
| 59 | # 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 |
| 60 | # faster than having to look them up during access checking. | 63 | # faster than having to look them up during access checking. |
| 61 | 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 | |||
| 62 | region = create_region(room, world) | 68 | region = create_region(room, world) |
| 63 | regions[region.name] = region | 69 | regions[region.name] = region |
| 64 | region_and_room.append((region, room)) | 70 | region_and_room.append((region, room)) |
| @@ -72,6 +78,9 @@ def create_regions(world: "Lingo2World"): | |||
| 72 | if connection.roof_access and not world.options.daedalus_roof_access: | 78 | if connection.roof_access and not world.options.daedalus_roof_access: |
| 73 | continue | 79 | continue |
| 74 | 80 | ||
| 81 | if connection.vanilla_only and world.options.shuffle_doors: | ||
| 82 | continue | ||
| 83 | |||
| 75 | from_region = world.static_logic.get_room_region_name(connection.from_room) | 84 | from_region = world.static_logic.get_room_region_name(connection.from_room) |
| 76 | to_region = world.static_logic.get_room_region_name(connection.to_room) | 85 | to_region = world.static_logic.get_room_region_name(connection.to_room) |
| 77 | 86 | ||
| @@ -91,7 +100,7 @@ def create_regions(world: "Lingo2World"): | |||
| 91 | 100 | ||
| 92 | if connection.HasField("port"): | 101 | if connection.HasField("port"): |
| 93 | port = world.static_logic.objects.ports[connection.port] | 102 | port = world.static_logic.objects.ports[connection.port] |
| 94 | connection_name = f"{connection_name} (via port {port.name})" | 103 | connection_name = f"{connection_name} (via {port.display_name})" |
| 95 | 104 | ||
| 96 | if world.options.shuffle_worldports and not port.no_shuffle: | 105 | if world.options.shuffle_worldports and not port.no_shuffle: |
| 97 | continue | 106 | continue |
| @@ -126,6 +135,12 @@ def create_regions(world: "Lingo2World"): | |||
| 126 | reqs.simplify() | 135 | reqs.simplify() |
| 127 | reqs.remove_room(from_region) | 136 | reqs.remove_room(from_region) |
| 128 | 137 | ||
| 138 | if to_region in reqs.rooms: | ||
| 139 | # This connection can't ever increase access because you're required to have access to the other side in | ||
| 140 | # order for it to be usable. We will just not create the connection at all, in order to help GER figure out | ||
| 141 | # what regions are dead ends. | ||
| 142 | continue | ||
| 143 | |||
| 129 | connection = Entrance(world.player, connection_name, regions[from_region]) | 144 | connection = Entrance(world.player, connection_name, regions[from_region]) |
| 130 | connection.access_rule = make_location_lambda(reqs, world, regions) | 145 | connection.access_rule = make_location_lambda(reqs, world, regions) |
| 131 | 146 | ||
| @@ -144,14 +159,46 @@ def shuffle_entrances(world: "Lingo2World"): | |||
| 144 | 159 | ||
| 145 | port_id_by_name: dict[str, int] = {} | 160 | port_id_by_name: dict[str, int] = {} |
| 146 | 161 | ||
| 147 | for port in world.static_logic.objects.ports: | 162 | shuffleable_ports = [port for port in world.static_logic.objects.ports |
| 148 | if port.no_shuffle: | 163 | if not port.no_shuffle |
| 149 | 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) | ||
| 150 | 196 | ||
| 197 | for port in shuffleable_ports: | ||
| 151 | 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) |
| 152 | port_region = world.multiworld.get_region(port_region_name, world.player) | 199 | port_region = world.multiworld.get_region(port_region_name, world.player) |
| 153 | 200 | ||
| 154 | connection_name = f"{port_region_name} - {port.name}" | 201 | connection_name = f"{port_region_name} - {port.display_name}" |
| 155 | port_id_by_name[connection_name] = port.id | 202 | port_id_by_name[connection_name] = port.id |
| 156 | 203 | ||
| 157 | entrance = port_region.create_er_target(connection_name) | 204 | entrance = port_region.create_er_target(connection_name) |
| @@ -189,7 +236,7 @@ def connect_ports_from_ut(port_pairings: dict[int, int], world: "Lingo2World"): | |||
| 189 | from_region = world.multiworld.get_region(from_region_name, world.player) | 236 | from_region = world.multiworld.get_region(from_region_name, world.player) |
| 190 | to_region = world.multiworld.get_region(to_region_name, world.player) | 237 | to_region = world.multiworld.get_region(to_region_name, world.player) |
| 191 | 238 | ||
| 192 | connection = Entrance(world.player, f"{from_region_name} - {from_port.name}", from_region) | 239 | connection = Entrance(world.player, f"{from_region_name} - {from_port.display_name}", from_region) |
| 193 | 240 | ||
| 194 | reqs = AccessRequirements() | 241 | reqs = AccessRequirements() |
| 195 | if from_port.HasField("required_door"): | 242 | if from_port.HasField("required_door"): |
