Exemplo n.º 1
0
def pretty_print_node_type(node: Node, world_list: WorldList):
    if isinstance(node, DockNode):
        try:
            other = world_list.resolve_dock_connection(
                world_list.nodes_to_world(node), node.default_connection)
            other_name = world_list.node_name(other)
        except IndexError as e:
            other_name = (f"(Asset {node.default_connection.area_asset_id:x}, "
                          f"index {node.default_connection.dock_index}) [{e}]")

        return f"{node.default_dock_weakness.name} to {other_name}"

    elif isinstance(node, TeleporterNode):
        other = world_list.area_by_area_location(node.default_connection)
        return f"Teleporter to {world_list.area_name(other)}"

    elif isinstance(node, PickupNode):
        return f"Pickup {node.pickup_index.index}; Major Location? {node.major_location}"

    elif isinstance(node, EventNode):
        return f"Event {node.event.long_name}"

    elif isinstance(node, TranslatorGateNode):
        return f"Translator Gate ({node.gate})"

    elif isinstance(node, LogbookNode):
        message = ""
        if node.lore_type == LoreType.LUMINOTH_LORE:
            message = f" ({node.required_translator.long_name})"
        return f"Logbook {node.lore_type.long_name}{message} for {node.string_asset_id:x}"

    return ""
Exemplo n.º 2
0
def distances_to_node(
    world_list: WorldList,
    starting_node: Node,
    *,
    ignore_elevators: bool = True,
    cutoff: Optional[int] = None,
    patches: Optional[GamePatches] = None,
) -> Dict[Area, int]:
    """
    Compute the shortest distance from a node to all reachable areas.
    :param world_list:
    :param starting_node:
    :param ignore_elevators:
    :param cutoff: Exclude areas with a length longer that cutoff.
    :param patches:
    :return: Dict keyed by area to shortest distance to starting_node.
    """
    g = networkx.DiGraph()

    dock_connections = patches.dock_connection if patches is not None else {}
    elevator_connections = patches.elevator_connection if patches is not None else {}

    for area in world_list.all_areas:
        g.add_node(area)

    for world in world_list.worlds:
        for area in world.areas:
            new_areas = set()
            for node in area.nodes:
                if isinstance(node, DockNode):
                    connection = dock_connections.get(
                        (area.area_asset_id, node.dock_index),
                        node.default_connection)
                    new_areas.add(
                        world.area_by_asset_id(connection.area_asset_id))
                elif isinstance(node, TeleporterNode) and not ignore_elevators:
                    connection = elevator_connections.get(
                        node.teleporter_instance_id, node.default_connection)
                    new_areas.add(world_list.area_by_area_location(connection))

            for next_area in new_areas:
                g.add_edge(area, next_area)

    return networkx.single_source_shortest_path_length(
        g, world_list.nodes_to_area(starting_node), cutoff)
Exemplo n.º 3
0
def _name_for_location(world_list: WorldList, location: AreaLocation) -> str:
    if location in prime1_elevators.CUSTOM_NAMES:
        return prime1_elevators.CUSTOM_NAMES[location]
    else:
        return world_list.area_name(world_list.area_by_area_location(location),
                                    separator=":")
Exemplo n.º 4
0
def _find_area_with_teleporter(world_list: WorldList,
                               teleporter: Teleporter) -> Area:
    return world_list.area_by_area_location(teleporter.area_location)