Skip to content

Commit

Permalink
Move out some transition-related data
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jul 16, 2024
1 parent 31a8029 commit 3b9096b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Dolphin scripts/Entrance Randomizer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from lib.constants import * # noqa: F403
from lib.constants import __version__
from lib.entrance_rando import (
DISABLED_TRANSITIONS,
highjack_transition_rando,
set_transitions_map,
starting_area,
temp_disabled_exits,
transitions_map,
)
from lib.graph_creation import create_graphml
Expand All @@ -50,7 +50,7 @@

# Dump spoiler logs and graph
dump_spoiler_logs(starting_area_name, transitions_map, seed_string)
create_graphml(transitions_map, temp_disabled_exits, seed_string, starting_area)
create_graphml(transitions_map, DISABLED_TRANSITIONS, seed_string, starting_area)


async def main_loop():
Expand Down
14 changes: 13 additions & 1 deletion Dolphin scripts/Entrance Randomizer/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import CONFIGS
from dolphin import memory # pyright: ignore[reportMissingModuleSource]
from lib.transition_infos import transition_infos
from lib.transition_infos import Transition, transition_infos

__version = "0.4.0"
"""See CHANGELOG.md for version semantics."""
Expand Down Expand Up @@ -256,3 +256,15 @@ class LevelCRC(IntEnum):
}
"""Entrances that can softlock by infinitely running into a door.
Value is the minimum height boost needed to regain control."""


ONE_WAY_TRANSITIONS = (
# the White Valley geyser
Transition(LevelCRC.WHITE_VALLEY, LevelCRC.MOUNTAIN_SLED_RUN),
# the Apu Illapu Shrine geyser
Transition(LevelCRC.APU_ILLAPU_SHRINE, LevelCRC.WHITE_VALLEY),
# the Apu Illapu Shrine one-way door
Transition(LevelCRC.MOUNTAIN_SLED_RUN, LevelCRC.APU_ILLAPU_SHRINE),
# the Jungle Canyon waterfall
Transition(LevelCRC.CAVERN_LAKE, LevelCRC.JUNGLE_CANYON),
)
56 changes: 20 additions & 36 deletions Dolphin scripts/Entrance Randomizer/lib/entrance_rando.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,19 @@
import random
from collections.abc import Iterable, MutableMapping, MutableSequence, Sequence, Sized
from copy import copy
from enum import IntEnum
from enum import IntEnum, auto
from itertools import starmap
from typing import NamedTuple

import CONFIGS
from lib.constants import * # noqa: F403
from lib.transition_infos import Area
from lib.utils import follow_pointer_path, state


class Transition(NamedTuple):
from_: int
to: int


class Choice(IntEnum):
CONNECT = 1
INBETWEEN = 2


temples = (
LevelCRC.MONKEY_TEMPLE,
LevelCRC.SCORPION_TEMPLE,
LevelCRC.PENGUIN_TEMPLE,
)
CONNECT = auto()
INBETWEEN = auto()

one_way_exits = (
# the White Valley geyser
Transition(LevelCRC.WHITE_VALLEY, LevelCRC.MOUNTAIN_SLED_RUN),
# the Apu Illapu Shrine geyser
Transition(LevelCRC.APU_ILLAPU_SHRINE, LevelCRC.WHITE_VALLEY),
# the Apu Illapu Shrine one-way door
Transition(LevelCRC.MOUNTAIN_SLED_RUN, LevelCRC.APU_ILLAPU_SHRINE),
# the Jungle Canyon waterfall
Transition(LevelCRC.CAVERN_LAKE, LevelCRC.JUNGLE_CANYON),
)

_possible_starting_areas = [
area for area in ALL_TRANSITION_AREAS
Expand Down Expand Up @@ -75,7 +52,13 @@ class Choice(IntEnum):
}
]

temp_disabled_exits = [
SHOWN_DISABLED_TRANSITIONS = (
# Until we can set the "previous area id" in memory consistently,
# Crash Site is a risk of progress reset
(LevelCRC.CRASH_SITE, LevelCRC.JUNGLE_CANYON),
(LevelCRC.CRASH_SITE, LevelCRC.PLANE_COCKPIT),
(LevelCRC.JUNGLE_CANYON, LevelCRC.CRASH_SITE),
(LevelCRC.PLANE_COCKPIT, LevelCRC.CRASH_SITE),
# Mouth of Inti has 2 connections with Altar of Huitaca, which causes problems,
# basically it's very easy to get softlocked by the spider web when entering Altar of Huitaca
# So for now just don't randomize it. That way runs don't just end out of nowhere
Expand All @@ -87,10 +70,11 @@ class Choice(IntEnum):
# So for now just don't randomize it. That way we won't have to worry about that yet
(LevelCRC.TWIN_OUTPOSTS, LevelCRC.TWIN_OUTPOSTS_UNDERWATER),
(LevelCRC.TWIN_OUTPOSTS_UNDERWATER, LevelCRC.TWIN_OUTPOSTS),
]
)
"""These disabled exits are to be shown on the graph."""

disabled_exits = (
*temp_disabled_exits,
DISABLED_TRANSITIONS = (
*SHOWN_DISABLED_TRANSITIONS,
# The 3 Spirit Fights are not randomized,
# because that will cause issues with the transformation cutscene trigger.
# Plus it wouldn't really improve anything, given that the Temples are randomized anyway.
Expand Down Expand Up @@ -207,7 +191,7 @@ def remove_disabled_exits():
for area in TRANSITION_INFOS_DICT.values():
for ex in area.exits:
current = (area.area_id, ex.area_id)
if current in one_way_exits or current in disabled_exits:
if current in ONE_WAY_TRANSITIONS or current in DISABLED_TRANSITIONS:
TRANSITION_INFOS_DICT_RANDO[area.area_id] = Area(
area.area_id,
area.name,
Expand All @@ -221,7 +205,7 @@ def remove_disabled_exits():
# remove exits from ALL_POSSIBLE_TRANSITIONS_RANDO
global ALL_POSSIBLE_TRANSITIONS_RANDO
for trans in ALL_POSSIBLE_TRANSITIONS:
if trans in one_way_exits or trans in disabled_exits:
if trans in ONE_WAY_TRANSITIONS or trans in DISABLED_TRANSITIONS:
ALL_POSSIBLE_TRANSITIONS_RANDO = [ # pyright: ignore[reportConstantRedefinition]
x for x in ALL_POSSIBLE_TRANSITIONS_RANDO if x != trans
]
Expand Down Expand Up @@ -415,25 +399,25 @@ def set_transitions_map(): # noqa: PLR0915 # TODO: Break up in smaller function
_possible_redirections_bucket,
)

one_way_redirects = list(one_way_exits)
one_way_redirects = list(ONE_WAY_TRANSITIONS)
random.shuffle(one_way_redirects)
for original in one_way_exits:
for original in ONE_WAY_TRANSITIONS:
if one_way_redirects[0].to == original.from_:
transitions_map[original] = one_way_redirects.pop(1)
else:
transitions_map[original] = one_way_redirects.pop(0)
else:
# Ground rules:
# 1. you can't make a transition from a level to itself
_possible_redirections_bucket.extend(one_way_exits)
_possible_redirections_bucket.extend(ONE_WAY_TRANSITIONS)
for area in TRANSITION_INFOS_DICT_RANDO.values():
for to_og in (exit_.area_id for exit_ in area.exits):
original = Transition(from_=area.area_id, to=to_og)
redirect = get_random_redirection(original, _possible_redirections_bucket)
if redirect is not None:
transitions_map[original] = redirect
_possible_redirections_bucket.remove(redirect)
for original in one_way_exits:
for original in ONE_WAY_TRANSITIONS:
redirect = get_random_redirection(original, _possible_redirections_bucket)
if redirect is not None:
transitions_map[original] = redirect
Expand Down
4 changes: 2 additions & 2 deletions Dolphin scripts/Entrance Randomizer/lib/graph_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def create_edges(transitions_map: Mapping[tuple[int, int], tuple[int, int]]):

def create_graphml(
transitions_map: Mapping[tuple[int, int], tuple[int, int]],
temp_disabled_exits: Sequence[tuple[int, int]],
shown_disabled_transitions: Sequence[tuple[int, int]],
seed_string: SeedType,
starting_area: int,
):
all_transitions = dict(transitions_map) | {item: item for item in temp_disabled_exits}
all_transitions = dict(transitions_map) | {item: item for item in shown_disabled_transitions}

graphml_text = (
'<?xml version="1.0" encoding="UTF-8"?>'
Expand Down
11 changes: 11 additions & 0 deletions Dolphin scripts/Entrance Randomizer/lib/transition_infos.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Expose `transition_infos.json` with static Python classes.
No other information should be found here other than the imported data and helper classes.
"""

from __future__ import annotations

import json
Expand All @@ -6,6 +12,11 @@
from typing import Literal, NamedTuple, TypeAlias, TypedDict


class Transition(NamedTuple):
from_: int
to: int


class ExitJSON(TypedDict):
area_id: str
area_name: str
Expand Down

0 comments on commit 3b9096b

Please sign in to comment.