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.py99
1 files changed, 94 insertions, 5 deletions
diff --git a/apworld/regions.py b/apworld/regions.py index d388678..993eec8 100644 --- a/apworld/regions.py +++ b/apworld/regions.py
@@ -1,29 +1,118 @@
1from typing import TYPE_CHECKING 1from typing import TYPE_CHECKING
2 2
3from BaseClasses import Region 3from BaseClasses import Region, ItemClassification, Entrance
4from .items import Lingo2Item
4from .locations import Lingo2Location 5from .locations import Lingo2Location
6from .player_logic import AccessRequirements
7from .rules import make_location_lambda
5 8
6if TYPE_CHECKING: 9if TYPE_CHECKING:
7 from . import Lingo2World 10 from . import Lingo2World
8 11
9 12
10def create_region(room, world: "Lingo2World") -> Region: 13def create_region(room, world: "Lingo2World") -> Region:
11 new_region = Region(room.name, world.player, world.multiworld) 14 return Region(world.static_logic.get_room_region_name(room.id), world.player, world.multiworld)
12 15
16
17def create_locations(room, new_region: Region, world: "Lingo2World", regions: dict[str, Region]):
13 for location in world.player_logic.locations_by_room.get(room.id, {}): 18 for location in world.player_logic.locations_by_room.get(room.id, {}):
19 reqs = location.reqs.copy()
20 reqs.remove_room(new_region.name)
21
14 new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], 22 new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code],
15 location.code, new_region) 23 location.code, new_region)
24 new_location.access_rule = make_location_lambda(reqs, world, regions)
16 new_region.locations.append(new_location) 25 new_region.locations.append(new_location)
17 26
18 return new_region 27 for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items():
19 28 new_location = Lingo2Location(world.player, event_name, None, new_region)
29 event_item = Lingo2Item(item_name, ItemClassification.progression, None, world.player)
30 new_location.place_locked_item(event_item)
31 new_region.locations.append(new_location)
20 32
21def create_regions(world: "Lingo2World"): 33def create_regions(world: "Lingo2World"):
22 regions = { 34 regions = {
23 "Menu": Region("Menu", world.player, world.multiworld) 35 "Menu": Region("Menu", world.player, world.multiworld)
24 } 36 }
25 37
38 region_and_room = []
39
40 # Create the regions in two stages. First, make the actual region objects and memoize them. Then, add all of the
41 # 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.
26 for room in world.static_logic.objects.rooms: 43 for room in world.static_logic.objects.rooms:
27 regions[room.name] = create_region(room, world) 44 region = create_region(room, world)
45 regions[region.name] = region
46 region_and_room.append((region, room))
47
48 for (region, room) in region_and_room:
49 create_locations(room, region, world, regions)
50
51 regions["Menu"].connect(regions["The Entry - Starting Room"], "Start Game")
52
53 # TODO: The requirements of the opposite trigger also matter.
54 for connection in world.static_logic.objects.connections:
55 if connection.roof_access and not world.options.daedalus_roof_access:
56 continue
57
58 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)
60
61 if from_region not in regions or to_region not in regions:
62 continue
63
64 connection_name = f"{from_region} -> {to_region}"
65
66 reqs = AccessRequirements()
67
68 if connection.HasField("required_door"):
69 reqs.merge(world.player_logic.get_door_open_reqs(connection.required_door))
70
71 door = world.static_logic.objects.doors[connection.required_door]
72 wmap = world.static_logic.objects.maps[door.map_id]
73 connection_name = f"{connection_name} (using {wmap.name} - {door.name})"
74
75 if connection.HasField("port"):
76 port = world.static_logic.objects.ports[connection.port]
77 connection_name = f"{connection_name} (via port {port.name})"
78
79 if port.HasField("required_door"):
80 reqs.merge(world.player_logic.get_door_open_reqs(port.required_door))
81
82 if connection.HasField("painting"):
83 painting = world.static_logic.objects.paintings[connection.painting]
84 connection_name = f"{connection_name} (via painting {painting.name})"
85
86 if painting.HasField("required_door"):
87 reqs.merge(world.player_logic.get_door_open_reqs(painting.required_door))
88
89 if connection.HasField("panel"):
90 proxy = connection.panel
91 reqs.merge(world.player_logic.get_panel_reqs(proxy.panel,
92 proxy.answer if proxy.HasField("answer") else None))
93
94 panel = world.static_logic.objects.panels[proxy.panel]
95 if proxy.HasField("answer"):
96 connection_name = f"{connection_name} (via panel {panel.name}/{proxy.answer})"
97 else:
98 connection_name = f"{connection_name} (via panel {panel.name})"
99
100 if connection.HasField("purple_ending") and connection.purple_ending and world.options.strict_purple_ending:
101 world.player_logic.add_solution_reqs(reqs, "abcdefghijklmnopqrstuvwxyz")
102
103 if connection.HasField("cyan_ending") and connection.cyan_ending and world.options.strict_cyan_ending:
104 world.player_logic.add_solution_reqs(reqs, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
105
106 reqs.simplify()
107 reqs.remove_room(from_region)
108
109 connection = Entrance(world.player, connection_name, regions[from_region])
110 connection.access_rule = make_location_lambda(reqs, world, regions)
111
112 regions[from_region].exits.append(connection)
113 connection.connect(regions[to_region])
114
115 for region in reqs.get_referenced_rooms():
116 world.multiworld.register_indirect_condition(regions[region], connection)
28 117
29 world.multiworld.regions += regions.values() 118 world.multiworld.regions += regions.values()