diff options
Diffstat (limited to 'regions.py')
| -rw-r--r-- | regions.py | 84 |
1 files changed, 84 insertions, 0 deletions
| diff --git a/regions.py b/regions.py new file mode 100644 index 0000000..c75cf49 --- /dev/null +++ b/regions.py | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | from typing import Dict, TYPE_CHECKING | ||
| 2 | |||
| 3 | from BaseClasses import ItemClassification, Region | ||
| 4 | from .items import LingoItem | ||
| 5 | from .locations import LingoLocation | ||
| 6 | from .player_logic import LingoPlayerLogic | ||
| 7 | from .rules import lingo_can_use_entrance, lingo_can_use_pilgrimage, make_location_lambda | ||
| 8 | from .static_logic import ALL_ROOMS, PAINTINGS, Room | ||
| 9 | |||
| 10 | if TYPE_CHECKING: | ||
| 11 | from . import LingoWorld | ||
| 12 | |||
| 13 | |||
| 14 | def create_region(room: Room, world: "LingoWorld", player_logic: LingoPlayerLogic) -> Region: | ||
| 15 | new_region = Region(room.name, world.player, world.multiworld) | ||
| 16 | for location in player_logic.LOCATIONS_BY_ROOM.get(room.name, {}): | ||
| 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) | ||
| 19 | new_region.locations.append(new_location) | ||
| 20 | if location.name in player_logic.EVENT_LOC_TO_ITEM: | ||
| 21 | event_name = player_logic.EVENT_LOC_TO_ITEM[location.name] | ||
| 22 | event_item = LingoItem(event_name, ItemClassification.progression, None, world.player) | ||
| 23 | new_location.place_locked_item(event_item) | ||
| 24 | |||
| 25 | return new_region | ||
| 26 | |||
| 27 | |||
| 28 | def handle_pilgrim_room(regions: Dict[str, Region], world: "LingoWorld", player_logic: LingoPlayerLogic) -> None: | ||
| 29 | target_region = regions["Pilgrim Antechamber"] | ||
| 30 | source_region = regions["Outside The Agreeable"] | ||
| 31 | source_region.connect( | ||
| 32 | target_region, | ||
| 33 | "Pilgrimage", | ||
| 34 | lambda state: lingo_can_use_pilgrimage(state, world.player, player_logic)) | ||
| 35 | |||
| 36 | |||
| 37 | def connect_painting(regions: Dict[str, Region], warp_enter: str, warp_exit: str, world: "LingoWorld", | ||
| 38 | player_logic: LingoPlayerLogic) -> None: | ||
| 39 | source_painting = PAINTINGS[warp_enter] | ||
| 40 | target_painting = PAINTINGS[warp_exit] | ||
| 41 | |||
| 42 | target_region = regions[target_painting.room] | ||
| 43 | source_region = regions[source_painting.room] | ||
| 44 | source_region.connect( | ||
| 45 | target_region, | ||
| 46 | f"{source_painting.room} to {target_painting.room} (Painting)", | ||
| 47 | lambda state: lingo_can_use_entrance(state, target_painting.room, source_painting.required_door, world.player, | ||
| 48 | player_logic)) | ||
| 49 | |||
| 50 | |||
| 51 | def create_regions(world: "LingoWorld", player_logic: LingoPlayerLogic) -> None: | ||
| 52 | regions = { | ||
| 53 | "Menu": Region("Menu", world.player, world.multiworld) | ||
| 54 | } | ||
| 55 | |||
| 56 | painting_shuffle = world.options.shuffle_paintings | ||
| 57 | early_color_hallways = world.options.early_color_hallways | ||
| 58 | |||
| 59 | # Instantiate all rooms as regions with their locations first. | ||
| 60 | for room in ALL_ROOMS: | ||
| 61 | regions[room.name] = create_region(room, world, player_logic) | ||
| 62 | |||
| 63 | # Connect all created regions now that they exist. | ||
| 64 | for room in ALL_ROOMS: | ||
| 65 | for entrance in room.entrances: | ||
| 66 | # Don't use the vanilla painting connections if we are shuffling paintings. | ||
| 67 | if entrance.painting and painting_shuffle: | ||
| 68 | continue | ||
| 69 | |||
| 70 | regions[entrance.room].connect( | ||
| 71 | regions[room.name], | ||
| 72 | f"{entrance.room} to {room.name}", | ||
| 73 | lambda state, r=room, e=entrance: lingo_can_use_entrance(state, r.name, e.door, world.player, player_logic)) | ||
| 74 | |||
| 75 | handle_pilgrim_room(regions, world, player_logic) | ||
| 76 | |||
| 77 | if early_color_hallways: | ||
| 78 | regions["Starting Room"].connect(regions["Outside The Undeterred"], "Early Color Hallways") | ||
| 79 | |||
| 80 | if painting_shuffle: | ||
| 81 | for warp_enter, warp_exit in player_logic.PAINTING_MAPPING.items(): | ||
| 82 | connect_painting(regions, warp_enter, warp_exit, world, player_logic) | ||
| 83 | |||
| 84 | world.multiworld.regions += regions.values() | ||
