Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
18df05d
FRLG AutoStory: run Starter RNG in the program
dayfine Nov 3, 2026
e160dc2
FRLG AutoStory: log the Starter RNG loop's state
dayfine Nov 3, 2026
afcfbd4
Merge branch 'frlg/rng-callable-steps' into frlg/autostory-rng-loop
dayfine Nov 3, 2026
3b2e851
FRLG AutoStory: a shiny off the target doesn't confirm a SID; misses …
dayfine Nov 3, 2026
c9e3ad6
Merge branch 'frlg/rng-callable-steps' into frlg/autostory-rng-loop
dayfine Nov 3, 2026
5bbd983
FRLG AutoStory: skip an RNG attempt whose timings Starter RNG refuses
dayfine Nov 3, 2026
cde5f57
FRLG AutoStory: stop the RNG loop on a setup error other than refused…
dayfine Nov 3, 2026
8ff380d
Merge branch 'frlg/rng-callable-steps' into frlg/autostory-rng-loop
dayfine Nov 3, 2026
9f01402
FRLG: move the Starter RNG loop into RngManipulation
dayfine Nov 3, 2026
a56668e
Merge remote-tracking branch 'origin/frlg/rng-callable-steps' into HEAD
dayfine Nov 3, 2026
5cf2e1b
FRLG AutoStory: save the SID Starter RNG confirms in the RNG plan
dayfine Nov 3, 2026
4b9c682
Merge frlg/rng-callable-steps into frlg/autostory-rng-loop
dayfine Nov 3, 2026
84bff15
Merge branch 'frlg/rng-callable-steps' into frlg/autostory-rng-loop
dayfine Nov 3, 2026
3de6b2b
Merge branch 'frlg/rng-callable-steps' into frlg/autostory-rng-loop
dayfine Nov 3, 2026
4679e2e
Merge branch 'frlg/rng-callable-steps' into frlg/autostory-rng-loop
dayfine Nov 3, 2026
bfeb986
Merge branch 'frlg/rng-callable-steps' into frlg/autostory-rng-loop
dayfine Nov 3, 2026
972718a
Merge remote-tracking branch 'origin/frlg/rng-callable-steps' into HEAD
dayfine Nov 3, 2026
0bbbace
Merge frlg/rng-callable-steps into frlg/autostory-rng-loop
dayfine Nov 3, 2026
ae9dde5
Merge frlg/rng-callable-steps into frlg/autostory-rng-loop
dayfine Nov 3, 2026
074eaea
Merge frlg/rng-callable-steps into frlg/autostory-rng-loop
dayfine Nov 3, 2026
698713c
FRLG AutoStory: start Starter RNG from the stored calibration, save i…
dayfine Nov 3, 2026
e5eda2a
Merge remote-tracking branch 'origin/frlg/rng-callable-steps' into rn…
dayfine Nov 3, 2026
7f8661a
FRLG AutoStory: one short line per Starter RNG reset on the overlay log
dayfine Nov 3, 2026
9d485c1
Merge frlg/rng-callable-steps into frlg/autostory-rng-loop
dayfine Nov 3, 2026
d935888
Merge frlg/rng-callable-steps into frlg/autostory-rng-loop
dayfine Nov 3, 2026
33bc04d
Merge remote-tracking branch 'origin/frlg/rng-callable-steps' into HEAD
dayfine Nov 3, 2026
bc220d7
Merge frlg/rng-callable-steps into frlg/autostory-rng-loop
dayfine Nov 3, 2026
abb18f7
Merge frlg/rng-callable-steps (battle loop: end on the overworld afte…
dayfine Nov 3, 2026
d4594fa
Merge frlg/rng-callable-steps (a disabled move, and a move list that …
dayfine Nov 3, 2026
963b8f1
Merge frlg/autostory-mvp (matchup attacks in every battle) into frlg/…
dayfine Nov 3, 2026
f6df19d
Merge frlg/autostory-mvp (HP bar share, nurse for yellow HP, move pro…
dayfine Nov 3, 2026
b401bab
Merge frlg/rng-callable-steps (86195974b: verify mode from #122) into…
dayfine Nov 3, 2026
3961dd7
Merge frlg/rng-callable-steps (9959dbb23: battle sim from #120) into …
dayfine Nov 3, 2026
3620cfa
Merge frlg/rng-callable-steps into frlg/autostory-rng-loop
dayfine Nov 3, 2026
9feebb4
Merge frlg/rng-callable-steps (TM moves in the summary reader) into f…
dayfine Nov 3, 2026
b7f5b90
Merge frlg/rng-callable-steps (bag rows below an item the reader can'…
dayfine Nov 3, 2026
07819f4
FRLG AutoStory: program() within code health's 50 lines
dayfine Nov 3, 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Pokemon FRLG Tests

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=785 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -41,13 +41,15 @@
#include "Programs/PokemonFRLG_NamingScreenKeyboard.h"
#include "PokemonFRLG_Navigation.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.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 Down Expand Up @@ -680,7 +682,7 @@
add_tests_SummaryMovesReader(database);
}

void add_tests(UnitTestDatabase& database){

Check warning on line 685 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=48 (advisory above 25, limit 50)
add_tests_AdvanceWhiteDialogDetector(database);
add_tests_BoxCellOccupiedDetector(database);
add_tests_BoxCellReader(database);
Expand Down Expand Up @@ -715,6 +717,7 @@
add_tests_AutoStory(database);
add_tests_AutoStorySimulation(database);
add_tests_AutoStoryItems(database);
add_tests_AutoStoryRngLoop(database);
add_tests_NamingCursor(database);
add_tests_NamingPlan(database);
add_tests_NamingKeys(database);
Expand All @@ -725,6 +728,7 @@
add_tests_RngPlanTracker(database);
add_tests_RngPlanLog(database);
add_tests_RngSteps(database);
add_tests_StarterRngLoop(database);
}


Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
#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{
Expand All @@ -43,6 +47,17 @@ 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;
Expand All @@ -51,7 +66,12 @@ class AutoStory : public SingleSwitchProgramInstance{
// 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;
EventNotificationsOption NOTIFICATIONS;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* AutoStory RNG Loop
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <algorithm>
#include <format>
#include "Common/Cpp/Exceptions.h"
#include "PokemonFRLG_AutoStoryRngLoop.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


namespace{

// "-" for none.
std::string join_sids(const std::vector<uint16_t>& sids){
std::string text;
for (uint16_t sid : sids){
text += (text.empty() ? "" : ",") + std::to_string(sid);
}
return text.empty() ? "-" : text;
}

}

std::string starter_rng_loop_message(const StarterRngLoopResult& result){

Check warning on line 30 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::starter_rng_loop_message( const StarterRngLoopResult & result): function_lines=35 (advisory above 25, limit 50)
const std::string sids = join_sids(result.remaining_sids);
switch (result.end){
case StarterRngLoopEnd::SHINY:
if (result.sid){
return std::format("Starter RNG: shiny Squirtle. The SID is {}: saved as the RNG plan's SID, so AutoStory skips SID Helper's steps next time.", *result.sid);
}
if (result.remaining_sids.empty()){
return "Starter RNG: shiny Squirtle, for none of the SID candidates left: the SID isn't one of SID Helper's candidates.";
}
return std::format("Starter RNG: shiny Squirtle. The SID is one of {}.", sids);
case StarterRngLoopEnd::SHINY_OFF_TARGET:
return std::format(
"Starter RNG: shiny Squirtle, but not the planned target, so it doesn't tell the SID. SIDs left: {}.", sids
);
case StarterRngLoopEnd::TARGET:
return "Starter RNG hit the target (shiny not required). Nothing was saved after it: the game is where "
"Starter RNG's calibration left it. Play to the rival's battle and save by hand, then start AutoStory at 00.05.";
case StarterRngLoopEnd::OUT_OF_ATTEMPTS:
return std::format(
"Starter RNG: every planned attempt hit its target and none was shiny. SIDs left: {}. "
"The save is still south of the table: raise the RNG plan's max attempts and start AutoStory at 00.04 again.", sids
);
case StarterRngLoopEnd::MISSED_EVERY_ATTEMPT_LEFT:
return "Starter RNG: every attempt left missed its target more often than the retries allow, or Starter RNG "
"refused its timings (see the log). The save is still south of the table: check the RNG plan's sound setting "
"and start AutoStory at 00.04 again.";
case StarterRngLoopEnd::OUT_OF_TIME:
return std::format(
"Starter RNG: out of time after {} attempts. The save is still south of the table: start AutoStory at 00.04 again.",
result.attempts_run
);
}
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown Starter RNG loop end.");
}


CalibrationSavingSteps::CalibrationSavingSteps(
StarterRngLoopSteps& steps, RngStopCalibrationOptions& calibration, FloatingPointOption& ingame
)
: m_steps(steps)
, m_calibration(calibration)
, m_ingame(ingame)
{}

WallClock CalibrationSavingSteps::now(){
return m_steps.now();
}

StarterRngResult CalibrationSavingSteps::run_attempt(const RngAttempt& attempt, const StarterRngAttemptCall& call){
StarterRngAttemptCall saving = call;
saving.on_reset = [&](const StarterRngProgress& progress){
m_calibration.save(progress.calibrations, m_ingame);
if (call.on_reset){
call.on_reset(progress);
}
};
return m_steps.run_attempt(attempt, saving);
}


std::vector<StoryCheckpoint> rows_after_starter_rng(
const std::vector<StoryCheckpoint>& checkpoints, size_t ball_row, size_t last
){
if (ball_row + 1 >= checkpoints.size()){
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No checkpoint after the starter's ball.");
}
StoryCheckpoint row = checkpoints[ball_row + 1];
auto taken = std::find_if(row.steps.begin(), row.steps.end(), [](const StoryStep& step){
return step.name == "rival_takes_bulbasaur";
});
if (taken == row.steps.end()){
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, row.id + " has no rival_takes_bulbasaur step.");
}
row.steps.erase(row.steps.begin(), taken + 1);
row.title = "after Starter RNG in AutoStory: the rival's battle";

std::vector<StoryCheckpoint> rows{std::move(row)};
if (last > ball_row + 1){
StoryRunPlan rest = plan_story_run(checkpoints, ball_row + 2, last, StoryHandoffs{});
rows.insert(rows.end(), rest.rows.begin(), rest.rows.end());
}
return rows;
}



}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* AutoStory RNG Loop
*
* From: https://github.com/PokemonAutomation/
*
* AutoStory's Starter RNG stop, run in the program with the Starter RNG
* loop (RngManipulation/PokemonFRLG_StarterRngLoop.h) from the save under
* Squirtle's ball: the plan it runs, what the run says when the loop
* ends, and the rows it takes after a shiny.
*
*/

#ifndef PokemonAutomation_PokemonFRLG_AutoStoryRngLoop_H
#define PokemonAutomation_PokemonFRLG_AutoStoryRngLoop_H

#include <cstdint>
#include <string>
#include <vector>
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngPlan.h"
#include "VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngLoop.h"
#include "PokemonFRLG_AutoStoryEvents.h"
#include "PokemonFRLG_AutoStoryRngOptions.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


// The Starter RNG plan, for the TID it was made for.
struct StarterRngPlanned{
uint16_t tid = 0;
std::vector<RngAttempt> attempts;
};

// What the run says when the loop ends with `result`.
std::string starter_rng_loop_message(const StarterRngLoopResult& result);


// `steps`, with the calibration of each reset also kept in the RNG plan's
// calibration, with `ingame` as the stop's in-game advances offset, so the
// next run starts from it.
class CalibrationSavingSteps : public StarterRngLoopSteps{
public:
CalibrationSavingSteps(StarterRngLoopSteps& steps, RngStopCalibrationOptions& calibration, FloatingPointOption& ingame);

virtual WallClock now() override;
virtual StarterRngResult run_attempt(const RngAttempt& attempt, const StarterRngAttemptCall& call) override;

private:
StarterRngLoopSteps& m_steps;
RngStopCalibrationOptions& m_calibration;
FloatingPointOption& m_ingame;
};


// The rows a run takes after a shiny from the loop, which leaves the player
// under Squirtle's ball with the rival's ball taken: the row after
// `ball_row` (00.04b) from its step after "rival_takes_bulbasaur", then
// the rows after it to `last` as plan_story_run() takes them. Throws
// InternalProgramError for a table without that row or step.
std::vector<StoryCheckpoint> rows_after_starter_rng(
const std::vector<StoryCheckpoint>& checkpoints, size_t ball_row, size_t last
);


void add_tests_AutoStoryRngLoop(UnitTestDatabase& database);



}
}
}
#endif
Loading
Loading