summary refs log tree commit diff stats
path: root/regions.py
diff options
context:
space:
mode:
Diffstat (limited to 'regions.py')
-rw-r--r--regions.py48
1 files changed, 30 insertions, 18 deletions
diff --git a/regions.py b/regions.py index e5f947d..c24144a 100644 --- a/regions.py +++ b/regions.py
@@ -1,11 +1,11 @@
1from typing import Dict, TYPE_CHECKING 1from typing import Dict, Optional, TYPE_CHECKING
2 2
3from BaseClasses import ItemClassification, Region 3from BaseClasses import Entrance, ItemClassification, Region
4from .items import LingoItem 4from .items import LingoItem
5from .locations import LingoLocation 5from .locations import LingoLocation
6from .player_logic import LingoPlayerLogic 6from .player_logic import LingoPlayerLogic
7from .rules import lingo_can_use_entrance, lingo_can_use_pilgrimage, make_location_lambda 7from .rules import lingo_can_use_entrance, lingo_can_use_pilgrimage, make_location_lambda
8from .static_logic import ALL_ROOMS, PAINTINGS, Room 8from .static_logic import ALL_ROOMS, PAINTINGS, Room, RoomAndDoor
9 9
10if TYPE_CHECKING: 10if TYPE_CHECKING:
11 from . import LingoWorld 11 from . import LingoWorld
@@ -13,12 +13,12 @@ if TYPE_CHECKING:
13 13
14def create_region(room: Room, world: "LingoWorld", player_logic: LingoPlayerLogic) -> Region: 14def create_region(room: Room, world: "LingoWorld", player_logic: LingoPlayerLogic) -> Region:
15 new_region = Region(room.name, world.player, world.multiworld) 15 new_region = Region(room.name, world.player, world.multiworld)
16 for location in player_logic.LOCATIONS_BY_ROOM.get(room.name, {}): 16 for location in player_logic.locations_by_room.get(room.name, {}):
17 new_location = LingoLocation(world.player, location.name, location.code, new_region) 17 new_location = LingoLocation(world.player, location.name, location.code, new_region)
18 new_location.access_rule = make_location_lambda(location, room.name, world, player_logic) 18 new_location.access_rule = make_location_lambda(location, world, player_logic)
19 new_region.locations.append(new_location) 19 new_region.locations.append(new_location)
20 if location.name in player_logic.EVENT_LOC_TO_ITEM: 20 if location.name in player_logic.event_loc_to_item:
21 event_name = player_logic.EVENT_LOC_TO_ITEM[location.name] 21 event_name = player_logic.event_loc_to_item[location.name]
22 event_item = LingoItem(event_name, ItemClassification.progression, None, world.player) 22 event_item = LingoItem(event_name, ItemClassification.progression, None, world.player)
23 new_location.place_locked_item(event_item) 23 new_location.place_locked_item(event_item)
24 24
@@ -31,7 +31,22 @@ def handle_pilgrim_room(regions: Dict[str, Region], world: "LingoWorld", player_
31 source_region.connect( 31 source_region.connect(
32 target_region, 32 target_region,
33 "Pilgrimage", 33 "Pilgrimage",
34 lambda state: lingo_can_use_pilgrimage(state, world.player, player_logic)) 34 lambda state: lingo_can_use_pilgrimage(state, world, player_logic))
35
36
37def connect_entrance(regions: Dict[str, Region], source_region: Region, target_region: Region, description: str,
38 door: Optional[RoomAndDoor], world: "LingoWorld", player_logic: LingoPlayerLogic):
39 connection = Entrance(world.player, description, source_region)
40 connection.access_rule = lambda state: lingo_can_use_entrance(state, target_region.name, door, world, player_logic)
41
42 source_region.exits.append(connection)
43 connection.connect(target_region)
44
45 if door is not None:
46 effective_room = target_region.name if door.room is None else door.room
47 if door.door not in player_logic.item_by_door.get(effective_room, {}):
48 for region in player_logic.calculate_door_requirements(effective_room, door.door, world).rooms:
49 world.multiworld.register_indirect_condition(regions[region], connection)
35 50
36 51
37def connect_painting(regions: Dict[str, Region], warp_enter: str, warp_exit: str, world: "LingoWorld", 52def connect_painting(regions: Dict[str, Region], warp_enter: str, warp_exit: str, world: "LingoWorld",
@@ -41,11 +56,10 @@ def connect_painting(regions: Dict[str, Region], warp_enter: str, warp_exit: str
41 56
42 target_region = regions[target_painting.room] 57 target_region = regions[target_painting.room]
43 source_region = regions[source_painting.room] 58 source_region = regions[source_painting.room]
44 source_region.connect( 59
45 target_region, 60 entrance_name = f"{source_painting.room} to {target_painting.room} ({source_painting.id} Painting)"
46 f"{source_painting.room} to {target_painting.room} ({source_painting.id} Painting)", 61 connect_entrance(regions, source_region, target_region, entrance_name, source_painting.required_door, world,
47 lambda state: lingo_can_use_entrance(state, target_painting.room, source_painting.required_door, world.player, 62 player_logic)
48 player_logic))
49 63
50 64
51def create_regions(world: "LingoWorld", player_logic: LingoPlayerLogic) -> None: 65def create_regions(world: "LingoWorld", player_logic: LingoPlayerLogic) -> None:
@@ -74,10 +88,8 @@ def create_regions(world: "LingoWorld", player_logic: LingoPlayerLogic) -> None:
74 else: 88 else:
75 entrance_name += f" (through {room.name} - {entrance.door.door})" 89 entrance_name += f" (through {room.name} - {entrance.door.door})"
76 90
77 regions[entrance.room].connect( 91 connect_entrance(regions, regions[entrance.room], regions[room.name], entrance_name, entrance.door, world,
78 regions[room.name], entrance_name, 92 player_logic)
79 lambda state, r=room, e=entrance: lingo_can_use_entrance(state, r.name, e.door, world.player,
80 player_logic))
81 93
82 handle_pilgrim_room(regions, world, player_logic) 94 handle_pilgrim_room(regions, world, player_logic)
83 95
@@ -85,7 +97,7 @@ def create_regions(world: "LingoWorld", player_logic: LingoPlayerLogic) -> None:
85 regions["Starting Room"].connect(regions["Outside The Undeterred"], "Early Color Hallways") 97 regions["Starting Room"].connect(regions["Outside The Undeterred"], "Early Color Hallways")
86 98
87 if painting_shuffle: 99 if painting_shuffle:
88 for warp_enter, warp_exit in player_logic.PAINTING_MAPPING.items(): 100 for warp_enter, warp_exit in player_logic.painting_mapping.items():
89 connect_painting(regions, warp_enter, warp_exit, world, player_logic) 101 connect_painting(regions, warp_enter, warp_exit, world, player_logic)
90 102
91 world.multiworld.regions += regions.values() 103 world.multiworld.regions += regions.values()