Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
326daeb
FRLG AutoStory stage 2: player name, SID Helper and Starter RNG
dayfine Nov 3, 2026
6096678
Merge commit '482067e9260d33b88c73405822bccfc8b753ac47' into HEAD
dayfine Nov 5, 2026
247e089
Merge remote-tracking branch 'origin/frlg/stage1-core' into frlg/stag…
dayfine Nov 5, 2026
bf06cf6
Merge remote-tracking branch 'origin/frlg/stage1-core' into frlg/stag…
dayfine Nov 6, 2026
fb423d7
FRLG AutoStory stage 2: align with PR #231 lint conventions
dayfine Nov 6, 2026
4f70cf0
Merge origin/frlg/stage1-core into frlg/stage2-rng
dayfine Nov 6, 2026
d633063
Type RNG search top-bit literals explicitly for MSVC
dayfine Nov 7, 2026
175ca10
Merge origin/frlg/stage1-core into frlg/stage2-rng
dayfine Nov 7, 2026
6782fff
Merge remote-tracking branch 'origin/frlg/stage1-core' into frlg/stag…
dayfine Nov 8, 2026
22cebce
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 8, 2026
0500ea2
Merge remote-tracking branch 'origin/frlg/stage1-core' into HEAD
dayfine Nov 9, 2026
2af21c7
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 9, 2026
c388ace
Merge frlg/stage1-core (story action table) into frlg/stage2-rng
dayfine Nov 9, 2026
15630b1
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 9, 2026
8234107
Merge frlg/stage1-core: check the save stands at the checkpoint's sta…
dayfine Nov 9, 2026
ee33eda
Merge frlg/stage1-core: add the start pose check to a checkpoint alre…
dayfine Nov 9, 2026
2fa4ad4
Merge frlg/stage1-core: shorten the start pose sim test
dayfine Nov 9, 2026
ed0f087
Merge frlg/stage1-core: time an interrupt's step from its screen events
dayfine Nov 9, 2026
b0a1dea
Merge frlg/stage1-core: check a loaded save's start against a kept frame
dayfine Nov 9, 2026
05f09d6
Merge frlg/stage1-core: check a loaded save's start against a kept frame
dayfine Nov 9, 2026
87f96a6
Merge frlg/stage1-core: check a loaded save's start against a kept frame
dayfine Nov 9, 2026
dbfce06
Merge b51bddfd1 (#122 via parent) into frlg/stage2-rng
dayfine Nov 9, 2026
994d3a2
Merge FRLG between-step interrupts (bde6bacbc) into #214
dayfine Nov 9, 2026
dc47456
Merge FRLG between-step interrupts (3876fbd4e) into #214
dayfine Nov 9, 2026
bada010
Merge FRLG interrupt actions move (40ee31f86) into #214
dayfine Nov 9, 2026
079747d
Merge frlg/stage1-core into frlg/stage2-rng (hold watchers for the wa…
dayfine Nov 9, 2026
3670827
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 9, 2026
1360bea
Merge frlg/stage1-core into frlg/stage2-rng (wait for a battle's open…
dayfine Nov 9, 2026
d8b2eab
Merge frlg/stage1-core into frlg/stage2-rng (scene ends after its fad…
dayfine Nov 9, 2026
350d783
Merge frlg/stage1-core into frlg/stage2-rng: a step on the Switch HOM…
dayfine Nov 9, 2026
9d6d1a8
[FRLG RNG] Check free party slots in applicable RNG programs
dayfine Nov 10, 2026
e3f232c
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 10, 2026
801dd92
Merge origin/frlg/stage1-core into frlg/stage2-rng
dayfine Nov 10, 2026
636f021
Merge frlg/stage1-json (#330) into frlg/stage2-json: stage 2's rows a…
dayfine Nov 10, 2026
9d54f1b
FRLG AutoStory: delete stage 2's C++ story rows, parity proven
dayfine Nov 10, 2026
b9ac130
Merge pull request #331 from dayfine/frlg/stage2-json
dayfine Nov 10, 2026
1a669e5
Merge frlg/stage1-core (#341) into frlg/stage2-metadata: stage 2's ch…
dayfine Nov 10, 2026
a9839b6
Merge pull request #342 from dayfine/frlg/stage2-metadata
dayfine Nov 10, 2026
0c9bc31
Merge frlg/stage1-core (maps from pinned Packages resources) into frl…
dayfine Nov 10, 2026
6e89c52
Merge frlg/stage1-core (battle sim removed, headers split) into frlg/…
dayfine Nov 10, 2026
eb565cb
FRLG RNG stage: string_view for char*, split the large RNG and naming…
dayfine Nov 10, 2026
e111970
Merge frlg/stage1-core (trimmed battle data, plans name their foes) i…
dayfine Nov 10, 2026
b00eba4
Merge branch 'frlg/stage1-core' into frlg/stage2-rng
dayfine Nov 11, 2026
56785e3
Merge branch 'frlg/stage1-core' into frlg/stage2-rng
dayfine Nov 11, 2026
34a59de
FRLG party check: image-backed tests; keep the original slots formatting
dayfine Nov 12, 2026
8274309
FRLG party check: one image-backed test for the slot reader and the c…
dayfine Nov 12, 2026
1e4bac1
Merge upstream/main; drop the party check test seam per #1896
dayfine Nov 12, 2026
055c5a4
FRLG RNG: run the party check from RngProgramInstance, not a SingleSw…
dayfine Nov 12, 2026
f33000c
FRLG RNG: run_precheck() runs the party check and the black border check
dayfine Nov 12, 2026
986e7fd
FRLG RNG: run the black border check before the free party slots check
dayfine Nov 12, 2026
5d1fc80
FRLG EggRng: free party slots check depends on STARTING_POINT
dayfine Nov 12, 2026
c09beca
FRLG RNG: remove start_menu_context; all save locations use standard …
dayfine Nov 12, 2026
8b64af9
Merge origin/frlg/stage1-core into frlg/stage2-rng
dayfine Nov 12, 2026
2786942
Merge upstream/frlg-free-party-slots (#1881 free party slots check) i…
dayfine Nov 13, 2026
e79ba2c
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 14, 2026
09f071d
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 14, 2026
925ca4a
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 14, 2026
3a3013b
Merge frlg/stage1-core into frlg/stage2-rng
dayfine Nov 14, 2026
e0fa264
Merge origin/frlg/stage1-core into frlg/stage2-rng
dayfine Nov 14, 2026
009109b
Merge origin/frlg/stage1-core into frlg/stage2-rng
dayfine Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <fstream>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/Filesystem/Filesystem.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/StaticGlobals.h"
Expand Down Expand Up @@ -44,9 +45,18 @@
#include "Overworld/PokemonFRLG_OverworldRoute.h"
#include "Overworld/PokemonFRLG_OverworldWalk.h"
#include "Overworld/PokemonFRLG_PlayerFacingReader.h"
#include "Programs/PokemonFRLG_NamingScreenKeyboard_Tests.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h"
#include "Programs/RngManipulation/PokemonFRLG_RngPlanInputs_Tests.h"
#include "Programs/RngManipulation/PokemonFRLG_RngPlanLog_Tests.h"
#include "Programs/RngManipulation/PokemonFRLG_RngPlanTracker_Tests.h"
#include "Programs/RngManipulation/PokemonFRLG_RngPlan_Tests.h"
#include "Programs/RngManipulation/PokemonFRLG_RngSteps_Tests.h"
#include "Programs/RngManipulation/PokemonFRLG_RngTargetSearch_Tests.h"
#include "Programs/RngManipulation/PokemonFRLG_StarterRngLoop_Tests.h"
#include "Tests/TestUtils.h"

#include "PokemonFRLG_Tests.h"
Expand All @@ -67,7 +77,18 @@
add_tests_AutoStoryScreenEvents(database);
}

// The RNG plan: its targets, attempts and the Starter RNG loop.
static void add_tests_RngPlanning(UnitTestDatabase& database){
add_tests_RngTargetSearch(database);
add_tests_RngPlanInputs(database);
add_tests_RngPlan(database);
add_tests_RngPlanTracker(database);
add_tests_RngPlanLog(database);
add_tests_RngSteps(database);
add_tests_StarterRngLoop(database);
}

void add_tests(UnitTestDatabase& database){

Check warning on line 91 in SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::add_tests( UnitTestDatabase & database): function_lines=45 (advisory above 25, limit 50)
add_tests_AdvanceWhiteDialogDetector(database);
add_tests_AdvanceBattleDialogDetector(database);
add_tests_BagDetector(database);
Expand Down Expand Up @@ -108,6 +129,9 @@
add_tests_AutoStoryExport(database);
add_tests_AutoStorySimulation(database);
add_tests_AutoStoryItems(database);
add_tests_AutoStoryRngLoop(database);
add_tests_NamingScreen(database);
add_tests_RngPlanning(database);
}


Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
#ifndef PokemonAutomation_PokemonFRLG_AutoStory_H
#define PokemonAutomation_PokemonFRLG_AutoStory_H

#include <optional>
#include <string>
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/EnumDropdownOption.h"
#include "Common/Cpp/Options/StringOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "Pokemon/Options/Pokemon_StoryRunOptions.h"
#include "PokemonFRLG_AutoStoryActions.h"
#include "PokemonFRLG_AutoStoryEvents.h"
#include "PokemonFRLG_AutoStoryRngLoop.h"
#include "PokemonFRLG_AutoStoryRngOptions.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -43,10 +49,31 @@ class AutoStory : public SingleSwitchProgramInstance{
) override{}

private:
// The RNG programs' handoffs the run takes, from the options.
StoryHandoffs story_handoffs() const;
// After 00.04 saved under Squirtle's ball (row `ball_row`): the stop
// for Starter RNG, or its attempts run here and, for a shiny, the run
// on to the end checkpoint. Returns the last checkpoint run, or nothing
// once the run has stopped.
std::optional<std::string> after_starter_ball(
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
StoryEnv& story, StoryExecutor& executor, const StarterRngPlanned& planned, size_t ball_row
);

// The start and end checkpoints, attempts, checks and language, as in
// every game's AutoStory.
Pokemon::StoryRunOptions RUN;
BooleanCheckBoxOption NEW_GAME_FROM_TITLE;
StringOption PLAYER_NAME;
// The RNG programs the run stops for (StoryHandoff).
BooleanCheckBoxOption STOP_FOR_SID_HELPER;
BooleanCheckBoxOption STOP_FOR_STARTER_RNG;
// Runs SID Helper's steps and Starter RNG's attempts in the program
// instead of stopping for them.
BooleanCheckBoxOption RUN_STARTER_RNG;
StarterRngPlanOptions RNG_PLAN;
EventNotificationOption NOTIFICATION_SHINY;
EventNotificationOption NOTIFICATION_STATUS_UPDATE;
// The save loaded was made by hand: keep the screen as its start frame.
BooleanCheckBoxOption KEEP_START_FRAME;
EventNotificationsOption NOTIFICATIONS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "CommonTools/Async/InferenceRoutines.h"
#include "CommonTools/Images/SolidColorTest.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h"
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h"
#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h"
Expand All @@ -26,6 +28,7 @@
#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h"
#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h"
#include "VideoGames/PokemonFRLG/Programs/PokemonFRLG_NamingScreen.h"
#include "VideoGames/PokemonFRLG/Programs/PokemonFRLG_StartMenuNavigation.h"
#include "PokemonFRLG_AutoStoryActions.h"

Expand Down Expand Up @@ -168,18 +171,28 @@ void open_start_menu_row(ConsoleHandle& console, ProControllerContext& context,
// without an arrow, and the arrow at the end of Oak's lines may be missed,
// so a message box gets A every 1.5 s whatever it shows. The player's name
// is asked on the keyboard straight away: B deletes whatever a stray A
// typed and START jumps to OK, which confirms the empty name as the
// default. The rival's is asked on a list with NEW NAME first, where A
// would open the keyboard: the cursor goes to the first preset name (the
// game's default rival, GREEN in FireRed, RED in LeafGreen) and A picks
// it, then YES confirms it (pokefirered oak_speech.c). If the keyboard
// opens anyway, the list was missed, and the empty name is confirmed
// there instead, which also names the rival GREEN.
// typed, then the name is typed, or START jumps to OK, which confirms the
// empty name as the default. The rival's is asked on a list with NEW NAME
// first, where A would open the keyboard: the cursor goes to the first
// preset name (the game's default rival, GREEN in FireRed, RED in
// LeafGreen) and A picks it, then YES confirms it (pokefirered
// oak_speech.c). If the keyboard opens anyway, the list was missed, and
// the empty name is confirmed there instead, which also names the rival
// GREEN.
class NewGameIntro{
public:
NewGameIntro(ConsoleHandle& console, ProControllerContext& context)
// Where the intro stops: the bedroom, or the player's keyboard with the
// name typed and OK not pressed (for SID Helper).
enum class End{
BEDROOM,
PLAYER_NAME_TYPED,
};

NewGameIntro(ConsoleHandle& console, ProControllerContext& context, std::string player_name, End end)
: m_console(console)
, m_context(context)
, m_player_name(std::move(player_name))
, m_end(end)
{}

void run(){
Expand All @@ -189,7 +202,7 @@ class NewGameIntro{
m_last_press = m_last_dialog;
while (current_time() < deadline){
if (step()){
m_console.log("New game: the bedroom.");
m_console.log(m_end == End::BEDROOM ? "New game: the bedroom." : "New game: the player's name is typed, OK not pressed.");
return;
}
}
Expand Down Expand Up @@ -228,6 +241,12 @@ class NewGameIntro{
pbf_wait(m_context, POLL);
return false;
}
if (m_end == End::PLAYER_NAME_TYPED && m_keyboards_seen == 0 && NamingScreenDetector(COLOR_RED).detect(screen)){
m_keyboards_seen++;
clear_stray_keys();
type_player_name(false);
return true;
}
if (names(screen)){
m_last_dialog = current_time();
m_last_press = m_last_dialog;
Expand Down Expand Up @@ -262,12 +281,12 @@ class NewGameIntro{
switch (intro_name_step(shown, m_keyboards_seen, m_presets_picked)){
case IntroNameStep::PLAYER_KEYBOARD:
m_keyboards_seen++;
enter_empty_name();
enter_name(true);
return true;
case IntroNameStep::RIVAL_KEYBOARD:
m_keyboards_seen++;
m_console.log("New game: the rival's keyboard opened, so the name list was missed.", COLOR_ORANGE);
enter_empty_name();
enter_name(false);
return true;
case IntroNameStep::RIVAL_PRESET:
pick_rival_preset(*list_row);
Expand Down Expand Up @@ -317,18 +336,46 @@ class NewGameIntro{
return false;
}

void enter_empty_name(){
m_console.log("New game: the keyboard, confirming an empty name.");
// B deletes whatever a stray A typed; the cursor stays on its key.
void clear_stray_keys(){
for (int c = 0; c < 8; c++){
press(m_context, BUTTON_B, 340ms);
}
press(m_context, BUTTON_PLUS, 500ms);
press(m_context, BUTTON_A, 2000ms);
}

void enter_name(bool player){
clear_stray_keys();
if (!player || m_player_name.empty()){
m_console.log("New game: the keyboard, confirming an empty name.");
press(m_context, BUTTON_PLUS, 500ms);
press(m_context, BUTTON_A, 2000ms);
m_context.wait_for_all_requests();
return;
}
type_player_name(true);
// Past the keyboard's fade, so it isn't taken for the rival's.
pbf_wait(m_context, 2000ms);
m_context.wait_for_all_requests();
}

void type_player_name(bool confirm){
if (m_player_name.empty()){
return;
}
const bool typed = confirm
? type_name(m_console, m_context, m_player_name, NamingScreenKind::PLAYER)
: type_name_without_confirming(m_console, m_context, m_player_name, NamingScreenKind::PLAYER);
if (!typed){
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT, "play_new_game_intro(): the keyboard closed before the name was typed.", m_console
);
}
}

ConsoleHandle& m_console;
ProControllerContext& m_context;
const std::string m_player_name;
const End m_end;
WallClock m_last_dialog;
WallClock m_last_press;
bool m_dialog_seen = false;
Expand Down Expand Up @@ -834,9 +881,25 @@ void buy_items(
mash_until_overworld(console, context, 20000ms);
}

void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context){
void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context, const std::string& player_name){
console.log("New game: from the title screen.");
NewGameIntro(console, context).run();
NewGameIntro(console, context, player_name, NewGameIntro::End::BEDROOM).run();
}

void play_new_game_to_player_name(ConsoleHandle& console, ProControllerContext& context, const std::string& player_name){
console.log("New game: from the title screen to the player's keyboard, for SID Helper.");
NewGameIntro(console, context, player_name, NewGameIntro::End::PLAYER_NAME_TYPED).run();
}

void close_trainer_card(ConsoleHandle& console, ProControllerContext& context){
context.wait_for_all_requests();
VideoSnapshot screen = console.video().snapshot();
if (screen && HomeMenuDetector(console, COLOR_RED).detect(screen)){
console.log("After SID Helper: on HOME, back to the game.");
resume_game_from_home(console, context);
}
// B closes the card, then the START menu.
mash_until_overworld(console, context, 20000ms);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,58 @@ namespace NintendoSwitch{
namespace PokemonFRLG{


// An upstream RNG program the user may run part-way through the story.
// Each is off unless its option is on.
enum class StoryHandoff{
NONE,
// The checkpoint's new game stops on the player's keyboard, the name
// typed and OK not pressed, which is where SID Helper starts.
SID_HELPER,
// The checkpoint saves south of the table, facing the starter's ball,
// which is where Starter RNG starts. With the handoff off, it runs on
// into the next checkpoint as one, as the story did before the split.
STARTER_RNG,
};

// A shared checkpoint with what FRLG adds to it.
struct StoryCheckpoint : public Pokemon::StoryCheckpoint{
// The healing items at its start, for a run that loads its save.
Supplies supplies;
// The START menu at its end, when it saves.
StartMenu menu = StartMenu::FULL;
// Starts from the game as another program left it, loading no save:
// the way back into the story after an RNG program. A run that starts
// before it passes over it.
bool live_start = false;
// The RNG program the user may run at this checkpoint.
StoryHandoff handoff = StoryHandoff::NONE;
};

// The handoffs a run stops for (AutoStory's options).
struct StoryHandoffs{
bool sid_helper = false;
bool starter_rng = false;
};

// What a run from table row `first` to `last` does.
struct StoryRunPlan{
// The checkpoints to run, in order.
std::vector<StoryCheckpoint> rows;
// NONE: the run ends after `rows`. SID_HELPER: `rows` is empty; the run
// plays the new game to the player's keyboard and stops there.
// STARTER_RNG: the run stops after `rows`, the last of which saves at
// the starter's ball.
StoryHandoff stop = StoryHandoff::NONE;
};

// The rows of `checkpoints` from `first` to `last`, both inclusive, as a
// run with `handoffs` takes them: live-start rows only when the run
// starts there, a run that reaches a handoff that is on stops for it, and
// a STARTER_RNG row whose handoff is off is joined with the row after it,
// under its own id.
StoryRunPlan plan_story_run(
const std::vector<StoryCheckpoint>& checkpoints, size_t first, size_t last, const StoryHandoffs& handoffs
);
// `legs` from `start` as route steps for the walker, each checked against
// the map: nothing if a step is blocked or leaves the map. A leg ends "to
// wall" if the next step its way is blocked.
Expand Down
Loading
Loading