about summary refs log tree commit diff stats
path: root/data/maps/the_sturdy
diff options
context:
space:
mode:
Diffstat (limited to 'data/maps/the_sturdy')
0 files changed, 0 insertions, 0 deletions
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
from typing import TYPE_CHECKING

from BaseClasses import Region, ItemClassification, Entrance
from .items import Lingo2Item
from .locations import Lingo2Location
from .player_logic import AccessRequirements
from .rules import make_location_lambda

if TYPE_CHECKING:
    from . import Lingo2World


def create_region(room, world: "Lingo2World") -> Region:
    new_region = Region(world.static_logic.get_room_region_name(room.id), world.player, world.multiworld)

    for location in world.player_logic.locations_by_room.get(room.id, {}):
        new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code],
                                      location.code, new_region)
        new_location.access_rule = make_location_lambda(location.reqs, world)
        new_region.locations.append(new_location)

    for event_name, item_name in world.player_logic.event_loc_item_by_room.get(room.id, {}).items():
        new_location = Lingo2Location(world.player, event_name, None, new_region)
        event_item = Lingo2Item(item_name, ItemClassification.progression, None, world.player)
        new_location.place_locked_item(event_item)
        new_region.locations.append(new_location)

    return new_region


def create_regions(world: "Lingo2World"):
    regions = {
        "Menu": Region("Menu", world.player, world.multiworld)
    }

    for room in world.static_logic.objects.rooms:
        region = create_region(room, world)
        regions[region.name] = region

    regions["Menu"].connect(regions["The Entry - Starting Room"], "Start Game")

    # TODO: The requirements of the opposite trigger also matter.
    for connection in world.static_logic.objects.connections:
        from_region = world.static_logic.get_room_region_name(connection.from_room)
        to_region = world.static_logic.get_room_region_name(connection.to_room)
        connection_name = f"{from_region} -> {to_region}"

        reqs = AccessRequirements()

        if connection.HasField("required_door"):
            reqs.merge(world.player_logic.get_door_open_reqs(connection.required_door))

            door = world.static_logic.objects.doors[connection.required_door]
            wmap = world.static_logic.objects.maps[door.map_id]
            connection_name = f"{connection_name} (using {wmap.name} - {door.name})"

        if connection.HasField("port"):
            port = world.static_logic.objects.ports[connection.port]
            connection_name = f"{connection_name} (via port {port.name})"

            if port.HasField("required_door"):
                reqs.merge(world.player_logic.get_door_open_reqs(port.required_door))

        if connection.HasField("painting"):
            painting = world.static_logic.objects.paintings[connection.painting]
            connection_name = f"{connection_name} (via painting {painting.name})"

            if painting.HasField("required_door"):
                reqs.merge(world.player_logic.get_door_open_reqs(painting.required_door))

        if connection.HasField("panel"):
            proxy = connection.panel
            reqs.merge(world.player_logic.get_panel_reqs(proxy.panel,
                                                         proxy.answer if proxy.HasField("answer") else None))

            panel = world.static_logic.objects.panels[proxy.panel]
            if proxy.HasField("answer"):
                connection_name = f"{connection_name} (via panel {panel.name}/{proxy.answer})"
            else:
                connection_name = f"{connection_name} (via panel {panel.name})"

        if from_region in regions and to_region in regions:
            connection = Entrance(world.player, connection_name, regions[from_region])
            connection.access_rule = make_location_lambda(reqs, world)

            regions[from_region].exits.append(connection)
            connection.connect(regions[to_region])

            for region in reqs.rooms:
                world.multiworld.register_indirect_condition(regions[region], connection)

    world.multiworld.regions += regions.values()