diff options
Diffstat (limited to 'apworld/regions.py')
| -rw-r--r-- | apworld/regions.py | 70 |
1 files changed, 70 insertions, 0 deletions
| diff --git a/apworld/regions.py b/apworld/regions.py index 993eec8..a7d9a1c 100644 --- a/apworld/regions.py +++ b/apworld/regions.py | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | from typing import TYPE_CHECKING | 1 | from typing import TYPE_CHECKING |
| 2 | 2 | ||
| 3 | import BaseClasses | ||
| 3 | from BaseClasses import Region, ItemClassification, Entrance | 4 | from BaseClasses import Region, ItemClassification, Entrance |
| 5 | from entrance_rando import randomize_entrances | ||
| 4 | from .items import Lingo2Item | 6 | from .items import Lingo2Item |
| 5 | from .locations import Lingo2Location | 7 | from .locations import Lingo2Location |
| 6 | from .player_logic import AccessRequirements | 8 | from .player_logic import AccessRequirements |
| @@ -76,6 +78,9 @@ def create_regions(world: "Lingo2World"): | |||
| 76 | port = world.static_logic.objects.ports[connection.port] | 78 | port = world.static_logic.objects.ports[connection.port] |
| 77 | connection_name = f"{connection_name} (via port {port.name})" | 79 | connection_name = f"{connection_name} (via port {port.name})" |
| 78 | 80 | ||
| 81 | if world.options.shuffle_worldports and not port.no_shuffle: | ||
| 82 | continue | ||
| 83 | |||
| 79 | if port.HasField("required_door"): | 84 | if port.HasField("required_door"): |
| 80 | reqs.merge(world.player_logic.get_door_open_reqs(port.required_door)) | 85 | reqs.merge(world.player_logic.get_door_open_reqs(port.required_door)) |
| 81 | 86 | ||
| @@ -116,3 +121,68 @@ def create_regions(world: "Lingo2World"): | |||
| 116 | world.multiworld.register_indirect_condition(regions[region], connection) | 121 | world.multiworld.register_indirect_condition(regions[region], connection) |
| 117 | 122 | ||
| 118 | world.multiworld.regions += regions.values() | 123 | world.multiworld.regions += regions.values() |
| 124 | |||
| 125 | |||
| 126 | def shuffle_entrances(world: "Lingo2World"): | ||
| 127 | er_entrances: list[Entrance] = [] | ||
| 128 | er_exits: list[Entrance] = [] | ||
| 129 | |||
| 130 | port_id_by_name: dict[str, int] = {} | ||
| 131 | |||
| 132 | for port in world.static_logic.objects.ports: | ||
| 133 | if port.no_shuffle: | ||
| 134 | continue | ||
| 135 | |||
| 136 | port_region_name = world.static_logic.get_room_region_name(port.room_id) | ||
| 137 | port_region = world.multiworld.get_region(port_region_name, world.player) | ||
| 138 | |||
| 139 | connection_name = f"{port_region_name} - {port.name}" | ||
| 140 | port_id_by_name[connection_name] = port.id | ||
| 141 | |||
| 142 | entrance = port_region.create_er_target(connection_name) | ||
| 143 | entrance.randomization_type = BaseClasses.EntranceType.TWO_WAY | ||
| 144 | |||
| 145 | er_exit = port_region.create_exit(connection_name) | ||
| 146 | er_exit.randomization_type = BaseClasses.EntranceType.TWO_WAY | ||
| 147 | |||
| 148 | if port.HasField("required_door"): | ||
| 149 | door_reqs = world.player_logic.get_door_open_reqs(port.required_door) | ||
| 150 | er_exit.access_rule = make_location_lambda(door_reqs, world, None) | ||
| 151 | |||
| 152 | for region in door_reqs.get_referenced_rooms(): | ||
| 153 | world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), | ||
| 154 | er_exit) | ||
| 155 | |||
| 156 | er_entrances.append(entrance) | ||
| 157 | er_exits.append(er_exit) | ||
| 158 | |||
| 159 | result = randomize_entrances(world, True, {0:[0]}, False, er_entrances, | ||
| 160 | er_exits) | ||
| 161 | |||
| 162 | for (f, to) in result.pairings: | ||
| 163 | world.port_pairings[port_id_by_name[f]] = port_id_by_name[to] | ||
| 164 | |||
| 165 | |||
| 166 | def connect_ports_from_ut(port_pairings: dict[int, int], world: "Lingo2World"): | ||
| 167 | for fpid, tpid in port_pairings.items(): | ||
| 168 | from_port = world.static_logic.objects.ports[fpid] | ||
| 169 | to_port = world.static_logic.objects.ports[tpid] | ||
| 170 | |||
| 171 | from_region_name = world.static_logic.get_room_region_name(from_port.room_id) | ||
| 172 | to_region_name = world.static_logic.get_room_region_name(to_port.room_id) | ||
| 173 | |||
| 174 | from_region = world.multiworld.get_region(from_region_name, world.player) | ||
| 175 | to_region = world.multiworld.get_region(to_region_name, world.player) | ||
| 176 | |||
| 177 | connection = Entrance(world.player, f"{from_region_name} - {from_port.name}", from_region) | ||
| 178 | |||
| 179 | if from_port.HasField("required_door"): | ||
| 180 | door_reqs = world.player_logic.get_door_open_reqs(from_port.required_door) | ||
| 181 | connection.access_rule = make_location_lambda(door_reqs, world, None) | ||
| 182 | |||
| 183 | for region in door_reqs.get_referenced_rooms(): | ||
| 184 | world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player), | ||
| 185 | connection) | ||
| 186 | |||
| 187 | from_region.exits.append(connection) | ||
| 188 | connection.connect(to_region) | ||
