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.py41
1 files changed, 29 insertions, 12 deletions
diff --git a/apworld/regions.py b/apworld/regions.py index e30493c..fad9bc7 100644 --- a/apworld/regions.py +++ b/apworld/regions.py
@@ -11,12 +11,17 @@ if TYPE_CHECKING:
11 11
12 12
13def create_region(room, world: "Lingo2World") -> Region: 13def create_region(room, world: "Lingo2World") -> Region:
14 new_region = Region(world.static_logic.get_room_region_name(room.id), world.player, world.multiworld) 14 return Region(world.static_logic.get_room_region_name(room.id), world.player, world.multiworld)
15 15
16
17def create_locations(room, new_region: Region, world: "Lingo2World", regions: dict[str, Region]):
16 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
17 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],
18 location.code, new_region) 23 location.code, new_region)
19 new_location.access_rule = make_location_lambda(location.reqs, world) 24 new_location.access_rule = make_location_lambda(reqs, world, regions)
20 new_region.locations.append(new_location) 25 new_region.locations.append(new_location)
21 26
22 for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items(): 27 for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items():
@@ -25,17 +30,23 @@ def create_region(room, world: "Lingo2World") -> Region:
25 new_location.place_locked_item(event_item) 30 new_location.place_locked_item(event_item)
26 new_region.locations.append(new_location) 31 new_region.locations.append(new_location)
27 32
28 return new_region
29
30
31def create_regions(world: "Lingo2World"): 33def create_regions(world: "Lingo2World"):
32 regions = { 34 regions = {
33 "Menu": Region("Menu", world.player, world.multiworld) 35 "Menu": Region("Menu", world.player, world.multiworld)
34 } 36 }
35 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.
36 for room in world.static_logic.objects.rooms: 43 for room in world.static_logic.objects.rooms:
37 region = create_region(room, world) 44 region = create_region(room, world)
38 regions[region.name] = region 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)
39 50
40 regions["Menu"].connect(regions["The Entry - Starting Room"], "Start Game") 51 regions["Menu"].connect(regions["The Entry - Starting Room"], "Start Game")
41 52
@@ -46,6 +57,10 @@ def create_regions(world: "Lingo2World"):
46 57
47 from_region = world.static_logic.get_room_region_name(connection.from_room) 58 from_region = world.static_logic.get_room_region_name(connection.from_room)
48 to_region = world.static_logic.get_room_region_name(connection.to_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
49 connection_name = f"{from_region} -> {to_region}" 64 connection_name = f"{from_region} -> {to_region}"
50 65
51 reqs = AccessRequirements() 66 reqs = AccessRequirements()
@@ -82,14 +97,16 @@ def create_regions(world: "Lingo2World"):
82 else: 97 else:
83 connection_name = f"{connection_name} (via panel {panel.name})" 98 connection_name = f"{connection_name} (via panel {panel.name})"
84 99
85 if from_region in regions and to_region in regions: 100 reqs.simplify()
86 connection = Entrance(world.player, connection_name, regions[from_region]) 101 reqs.remove_room(from_region)
87 connection.access_rule = make_location_lambda(reqs, world) 102
103 connection = Entrance(world.player, connection_name, regions[from_region])
104 connection.access_rule = make_location_lambda(reqs, world, regions)
88 105
89 regions[from_region].exits.append(connection) 106 regions[from_region].exits.append(connection)
90 connection.connect(regions[to_region]) 107 connection.connect(regions[to_region])
91 108
92 for region in reqs.rooms: 109 for region in reqs.get_referenced_rooms():
93 world.multiworld.register_indirect_condition(regions[region], connection) 110 world.multiworld.register_indirect_condition(regions[region], connection)
94 111
95 world.multiworld.regions += regions.values() 112 world.multiworld.regions += regions.values()