diff options
Diffstat (limited to 'apworld/regions.py')
-rw-r--r-- | apworld/regions.py | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/apworld/regions.py b/apworld/regions.py index d388678..2a850ef 100644 --- a/apworld/regions.py +++ b/apworld/regions.py | |||
@@ -2,17 +2,20 @@ from typing import TYPE_CHECKING | |||
2 | 2 | ||
3 | from BaseClasses import Region | 3 | from BaseClasses import Region |
4 | from .locations import Lingo2Location | 4 | from .locations import Lingo2Location |
5 | from .player_logic import AccessRequirements | ||
6 | from .rules import make_location_lambda | ||
5 | 7 | ||
6 | if TYPE_CHECKING: | 8 | if TYPE_CHECKING: |
7 | from . import Lingo2World | 9 | from . import Lingo2World |
8 | 10 | ||
9 | 11 | ||
10 | def create_region(room, world: "Lingo2World") -> Region: | 12 | def create_region(room, world: "Lingo2World") -> Region: |
11 | new_region = Region(room.name, world.player, world.multiworld) | 13 | new_region = Region(world.static_logic.get_room_region_name(room.id), world.player, world.multiworld) |
12 | 14 | ||
13 | for location in world.player_logic.locations_by_room.get(room.id, {}): | 15 | for location in world.player_logic.locations_by_room.get(room.id, {}): |
14 | new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], | 16 | new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], |
15 | location.code, new_region) | 17 | location.code, new_region) |
18 | new_location.access_rule = make_location_lambda(location.reqs, world) | ||
16 | new_region.locations.append(new_location) | 19 | new_region.locations.append(new_location) |
17 | 20 | ||
18 | return new_region | 21 | return new_region |
@@ -24,6 +27,52 @@ def create_regions(world: "Lingo2World"): | |||
24 | } | 27 | } |
25 | 28 | ||
26 | for room in world.static_logic.objects.rooms: | 29 | for room in world.static_logic.objects.rooms: |
27 | regions[room.name] = create_region(room, world) | 30 | region = create_region(room, world) |
31 | regions[region.name] = region | ||
32 | |||
33 | regions["Menu"].connect(regions["the_entry - Starting Room"], "Start Game") | ||
34 | |||
35 | # TODO: The requirements of the opposite trigger also matter. | ||
36 | for connection in world.static_logic.objects.connections: | ||
37 | from_region = world.static_logic.get_room_region_name(connection.from_room) | ||
38 | to_region = world.static_logic.get_room_region_name(connection.to_room) | ||
39 | connection_name = f"{from_region} -> {to_region}" | ||
40 | |||
41 | reqs = AccessRequirements() | ||
42 | |||
43 | if connection.HasField("required_door"): | ||
44 | reqs.merge(world.player_logic.get_door_reqs(connection.required_door)) | ||
45 | |||
46 | door = world.static_logic.objects.doors[connection.required_door] | ||
47 | wmap = world.static_logic.objects.maps[door.map_id] | ||
48 | connection_name = f"{connection_name} (using {wmap.name} - {door.name})" | ||
49 | |||
50 | if connection.HasField("port"): | ||
51 | port = world.static_logic.objects.ports[connection.port] | ||
52 | connection_name = f"{connection_name} (via port {port.name})" | ||
53 | |||
54 | if port.HasField("required_door"): | ||
55 | reqs.merge(world.player_logic.get_door_reqs(port.required_door)) | ||
56 | |||
57 | if connection.HasField("painting"): | ||
58 | painting = world.static_logic.objects.paintings[connection.painting] | ||
59 | connection_name = f"{connection_name} (via painting {painting.name})" | ||
60 | |||
61 | if painting.HasField("required_door"): | ||
62 | reqs.merge(world.player_logic.get_door_reqs(painting.required_door)) | ||
63 | |||
64 | if connection.HasField("panel"): | ||
65 | proxy = connection.panel | ||
66 | reqs.merge(world.player_logic.get_panel_reqs(proxy.panel, | ||
67 | proxy.answer if proxy.HasField("answer") else None)) | ||
68 | |||
69 | panel = world.static_logic.objects.panels[proxy.panel] | ||
70 | if proxy.HasField("answer"): | ||
71 | connection_name = f"{connection_name} (via panel {panel.name}/{proxy.answer})" | ||
72 | else: | ||
73 | connection_name = f"{connection_name} (via panel {panel.name})" | ||
74 | |||
75 | if from_region in regions and to_region in regions: | ||
76 | regions[from_region].connect(regions[to_region], connection_name, make_location_lambda(reqs, world)) | ||
28 | 77 | ||
29 | world.multiworld.regions += regions.values() | 78 | world.multiworld.regions += regions.values() |