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.py189
1 files changed, 178 insertions, 11 deletions
diff --git a/apworld/regions.py b/apworld/regions.py index 993eec8..313fd02 100644 --- a/apworld/regions.py +++ b/apworld/regions.py
@@ -1,10 +1,12 @@
1from typing import TYPE_CHECKING 1from typing import TYPE_CHECKING
2 2
3import BaseClasses
3from BaseClasses import Region, ItemClassification, Entrance 4from BaseClasses import Region, ItemClassification, Entrance
5from entrance_rando import randomize_entrances
4from .items import Lingo2Item 6from .items import Lingo2Item
5from .locations import Lingo2Location 7from .locations import Lingo2Location, LetterPlacementType, Lingo2Entrance
8from .options import FastTravelAccess
6from .player_logic import AccessRequirements 9from .player_logic import AccessRequirements
7from .rules import make_location_lambda
8 10
9if TYPE_CHECKING: 11if TYPE_CHECKING:
10 from . import Lingo2World 12 from . import Lingo2World
@@ -19,17 +21,39 @@ def create_locations(room, new_region: Region, world: "Lingo2World", regions: di
19 reqs = location.reqs.copy() 21 reqs = location.reqs.copy()
20 reqs.remove_room(new_region.name) 22 reqs.remove_room(new_region.name)
21 23
22 new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], 24 new_location = Lingo2Location.non_event_location(world, location.code, new_region)
23 location.code, new_region) 25 new_location.set_access_rule(reqs, regions)
24 new_location.access_rule = make_location_lambda(reqs, world, regions) 26 if world.options.restrict_letter_placements:
27 if location.is_letter:
28 new_location.set_up_letter_rule(LetterPlacementType.FORCE)
29 else:
30 new_location.set_up_letter_rule(LetterPlacementType.DISALLOW)
25 new_region.locations.append(new_location) 31 new_region.locations.append(new_location)
26 32
27 for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items(): 33 for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items():
28 new_location = Lingo2Location(world.player, event_name, None, new_region) 34 new_location = Lingo2Location.event_location(world, event_name, new_region)
35 if world.for_tracker and item_name == "Victory":
36 new_location.goal = True
37
29 event_item = Lingo2Item(item_name, ItemClassification.progression, None, world.player) 38 event_item = Lingo2Item(item_name, ItemClassification.progression, None, world.player)
30 new_location.place_locked_item(event_item) 39 new_location.place_locked_item(event_item)
31 new_region.locations.append(new_location) 40 new_region.locations.append(new_location)
32 41
42 if world.for_tracker and world.options.shuffle_worldports:
43 for port_id in room.ports:
44 port = world.static_logic.objects.ports[port_id]
45 if port.no_shuffle:
46 continue
47
48 new_location = Lingo2Location.event_location(world, f"Worldport {port.id} Entered", new_region)
49 new_location.port_id = port.id
50
51 if port.HasField("required_door"):
52 new_location.set_access_rule(world.player_logic.get_door_open_reqs(port.required_door), regions)
53
54 new_region.locations.append(new_location)
55
56
33def create_regions(world: "Lingo2World"): 57def create_regions(world: "Lingo2World"):
34 regions = { 58 regions = {
35 "Menu": Region("Menu", world.player, world.multiworld) 59 "Menu": Region("Menu", world.player, world.multiworld)
@@ -41,6 +65,9 @@ def create_regions(world: "Lingo2World"):
41 # locations. This allows us to reference the actual region objects in the access rules for the locations, which is 65 # locations. This allows us to reference the actual region objects in the access rules for the locations, which is
42 # faster than having to look them up during access checking. 66 # faster than having to look them up during access checking.
43 for room in world.static_logic.objects.rooms: 67 for room in world.static_logic.objects.rooms:
68 if not world.player_logic.should_shuffle_room(room.id):
69 continue
70
44 region = create_region(room, world) 71 region = create_region(room, world)
45 regions[region.name] = region 72 regions[region.name] = region
46 region_and_room.append((region, room)) 73 region_and_room.append((region, room))
@@ -48,13 +75,18 @@ def create_regions(world: "Lingo2World"):
48 for (region, room) in region_and_room: 75 for (region, room) in region_and_room:
49 create_locations(room, region, world, regions) 76 create_locations(room, region, world, regions)
50 77
51 regions["Menu"].connect(regions["The Entry - Starting Room"], "Start Game") 78 if world.options.daedalus_only:
79 regions["Menu"].connect(regions["Daedalus - Starting Room"], "Start Game")
80 else:
81 regions["Menu"].connect(regions["The Entry - Starting Room"], "Start Game")
52 82
53 # TODO: The requirements of the opposite trigger also matter.
54 for connection in world.static_logic.objects.connections: 83 for connection in world.static_logic.objects.connections:
55 if connection.roof_access and not world.options.daedalus_roof_access: 84 if connection.roof_access and not world.options.daedalus_roof_access:
56 continue 85 continue
57 86
87 if connection.vanilla_only and world.options.shuffle_doors:
88 continue
89
58 from_region = world.static_logic.get_room_region_name(connection.from_room) 90 from_region = world.static_logic.get_room_region_name(connection.from_room)
59 to_region = world.static_logic.get_room_region_name(connection.to_room) 91 to_region = world.static_logic.get_room_region_name(connection.to_room)
60 92
@@ -74,7 +106,10 @@ def create_regions(world: "Lingo2World"):
74 106
75 if connection.HasField("port"): 107 if connection.HasField("port"):
76 port = world.static_logic.objects.ports[connection.port] 108 port = world.static_logic.objects.ports[connection.port]
77 connection_name = f"{connection_name} (via port {port.name})" 109 connection_name = f"{connection_name} (via {port.display_name})"
110
111 if world.options.shuffle_worldports and not port.no_shuffle:
112 continue
78 113
79 if port.HasField("required_door"): 114 if port.HasField("required_door"):
80 reqs.merge(world.player_logic.get_door_open_reqs(port.required_door)) 115 reqs.merge(world.player_logic.get_door_open_reqs(port.required_door))
@@ -103,11 +138,21 @@ def create_regions(world: "Lingo2World"):
103 if connection.HasField("cyan_ending") and connection.cyan_ending and world.options.strict_cyan_ending: 138 if connection.HasField("cyan_ending") and connection.cyan_ending and world.options.strict_cyan_ending:
104 world.player_logic.add_solution_reqs(reqs, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz") 139 world.player_logic.add_solution_reqs(reqs, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
105 140
141 if (connection.HasField("mint_ending") and connection.mint_ending
142 and world.player_logic.custom_mint_ending is not None):
143 world.player_logic.add_solution_reqs(reqs, world.player_logic.custom_mint_ending)
144
106 reqs.simplify() 145 reqs.simplify()
107 reqs.remove_room(from_region) 146 reqs.remove_room(from_region)
108 147
109 connection = Entrance(world.player, connection_name, regions[from_region]) 148 if to_region in reqs.rooms:
110 connection.access_rule = make_location_lambda(reqs, world, regions) 149 # This connection can't ever increase access because you're required to have access to the other side in
150 # order for it to be usable. We will just not create the connection at all, in order to help GER figure out
151 # what regions are dead ends.
152 continue
153
154 connection = Lingo2Entrance(world, connection_name, regions[from_region])
155 connection.set_access_rule(reqs, regions)
111 156
112 regions[from_region].exits.append(connection) 157 regions[from_region].exits.append(connection)
113 connection.connect(regions[to_region]) 158 connection.connect(regions[to_region])
@@ -115,4 +160,126 @@ def create_regions(world: "Lingo2World"):
115 for region in reqs.get_referenced_rooms(): 160 for region in reqs.get_referenced_rooms():
116 world.multiworld.register_indirect_condition(regions[region], connection) 161 world.multiworld.register_indirect_condition(regions[region], connection)
117 162
163 if world.options.fast_travel_access != FastTravelAccess.option_vanilla:
164 for rte_map_id in world.player_logic.rte_mapping:
165 rte_map = world.static_logic.objects.maps[rte_map_id]
166 to_region = world.static_logic.get_room_region_name(rte_map.rte_room)
167
168 if to_region not in regions:
169 continue
170
171 connection_name = f"Return to {to_region}"
172 connection = Lingo2Entrance(world, connection_name, regions["Menu"])
173 regions["Menu"].exits.append(connection)
174 connection.connect(regions[to_region])
175
176 if world.options.fast_travel_access == FastTravelAccess.option_items:
177 reqs = AccessRequirements()
178 reqs.items.add(world.static_logic.get_map_rte_item_name(rte_map_id))
179
180 connection.set_access_rule(reqs, regions)
181
118 world.multiworld.regions += regions.values() 182 world.multiworld.regions += regions.values()
183
184
185def shuffle_entrances(world: "Lingo2World"):
186 er_entrances: list[Entrance] = []
187 er_exits: list[Entrance] = []
188
189 port_id_by_name: dict[str, int] = {}
190
191 shuffleable_ports = [port for port in world.static_logic.objects.ports
192 if not port.no_shuffle and world.player_logic.should_shuffle_room(port.room_id)]
193
194 if len(shuffleable_ports) % 2 == 1:
195 # We have an odd number of shuffleable ports! Pick a port from a room that has more than one, and make it a
196 # redundant warp to another port.
197 redundant_rooms = set(room.id for room in world.static_logic.objects.rooms if len(room.ports) > 1)
198 redundant_ports = [port for port in shuffleable_ports if port.room_id in redundant_rooms]
199 chosen_port = world.random.choice(redundant_ports)
200
201 shuffleable_ports.remove(chosen_port)
202
203 chosen_destination = world.random.choice(shuffleable_ports)
204
205 world.port_pairings[chosen_port.id] = chosen_destination.id
206
207 from_region_name = world.static_logic.get_room_region_name(chosen_port.room_id)
208 to_region_name = world.static_logic.get_room_region_name(chosen_destination.room_id)
209
210 from_region = world.multiworld.get_region(from_region_name, world.player)
211 to_region = world.multiworld.get_region(to_region_name, world.player)
212
213 connection = Lingo2Entrance(world, f"{from_region_name} - {chosen_port.display_name}", from_region)
214 from_region.exits.append(connection)
215 connection.connect(to_region)
216
217 if chosen_port.HasField("required_door"):
218 door_reqs = world.player_logic.get_door_open_reqs(chosen_port.required_door)
219 connection.set_access_rule(door_reqs, None)
220
221 for region in door_reqs.get_referenced_rooms():
222 world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player),
223 connection)
224
225 for port in shuffleable_ports:
226 port_region_name = world.static_logic.get_room_region_name(port.room_id)
227 port_region = world.multiworld.get_region(port_region_name, world.player)
228
229 connection_name = f"{port_region_name} - {port.display_name}"
230 port_id_by_name[connection_name] = port.id
231
232 entrance = port_region.create_er_target(connection_name)
233 entrance.randomization_type = BaseClasses.EntranceType.TWO_WAY
234
235 er_exit = Lingo2Entrance(world, connection_name, port_region)
236 port_region.exits.append(er_exit)
237 er_exit.randomization_type = BaseClasses.EntranceType.TWO_WAY
238
239 if port.HasField("required_door"):
240 door_reqs = world.player_logic.get_door_open_reqs(port.required_door)
241 er_exit.set_access_rule(door_reqs, None)
242
243 for region in door_reqs.get_referenced_rooms():
244 world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player),
245 er_exit)
246
247 er_entrances.append(entrance)
248 er_exits.append(er_exit)
249
250 result = randomize_entrances(world, True, {0:[0]}, False, er_entrances,
251 er_exits)
252
253 for (f, to) in result.pairings:
254 world.port_pairings[port_id_by_name[f]] = port_id_by_name[to]
255
256
257def connect_ports_from_ut(port_pairings: dict[int, int], world: "Lingo2World"):
258 for fpid, tpid in port_pairings.items():
259 from_port = world.static_logic.objects.ports[fpid]
260 to_port = world.static_logic.objects.ports[tpid]
261
262 from_region_name = world.static_logic.get_room_region_name(from_port.room_id)
263 to_region_name = world.static_logic.get_room_region_name(to_port.room_id)
264
265 from_region = world.multiworld.get_region(from_region_name, world.player)
266 to_region = world.multiworld.get_region(to_region_name, world.player)
267
268 connection = Lingo2Entrance(world, f"{from_region_name} - {from_port.display_name}", from_region)
269
270 reqs = AccessRequirements()
271 if from_port.HasField("required_door"):
272 reqs = world.player_logic.get_door_open_reqs(from_port.required_door).copy()
273
274 if world.for_tracker:
275 reqs.items.add(f"Worldport {fpid} Entered")
276
277 if not reqs.is_empty():
278 connection.set_access_rule(reqs, None)
279
280 for region in reqs.get_referenced_rooms():
281 world.multiworld.register_indirect_condition(world.multiworld.get_region(region, world.player),
282 connection)
283
284 from_region.exits.append(connection)
285 connection.connect(to_region)