From c7160d82190ed18eff29a9c4ea0d1029c752bf4a Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 11:27:12 -0800 Subject: [PATCH 1/5] BDSP AutoStory: leave the game where it failed A failed run went to HOME and closed the game, though the segment log says "the game stays where it failed". Keep the game open so the failure can be seen and resumed; the next run reloads the checkpoint's save anyway. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonBDSP_AutoStory.cpp | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp index eb42ad7090..ea2ab71611 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp @@ -99,25 +99,18 @@ Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, ProContro return hooks; } -// Leave the Switch in a known state after a failure: on HOME with the -// game closed, so the next run (or the user) starts from there. -void close_game_after_failure(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ - env.log("AutoStory failed: going to HOME and closing the game.", COLOR_RED); - try{ - go_home(env.console, context); - close_game_from_home(env.console, context); - }catch (OperationFailedException& e){ - env.log("Could not close the game: " + e.message(), COLOR_RED); - } +// A failed run leaves the game where it failed, so the user (or the +// next run from the checkpoint's save) can see and resume from there. +void log_stop_after_failure(SingleSwitchProgramEnvironment& env){ + env.log("AutoStory failed: the game stays where it failed.", COLOR_RED); } -// A run that stopped short throws, closing the game first unless it -// stopped at the first failure as asked. -void throw_if_stopped(SingleSwitchProgramEnvironment& env, ProControllerContext& context, const Pokemon::SegmentReport& report){ +// A run that stopped short throws. +void throw_if_stopped(SingleSwitchProgramEnvironment& env, const Pokemon::SegmentReport& report){ if (report.completed){ return; } - close_game_after_failure(env, context); + log_stop_after_failure(env); throw OperationFailedException( ErrorReportMode::NO_ERROR_REPORT, std::format( @@ -140,7 +133,7 @@ struct VerifyRequest{ // loads the save the first run started from. Throws unless enough runs // pass, closing the game first as after any failure unless `keep_game`. void verify_story_checkpoint( - SingleSwitchProgramEnvironment& env, ProControllerContext& context, Pokemon::RunState& state, + SingleSwitchProgramEnvironment& env, Pokemon::RunState& state, Pokemon::Segment& segment, Pokemon::SegmentHooks& hooks, const VerifyRequest& request ){ if (request.new_game){ @@ -152,14 +145,14 @@ void verify_story_checkpoint( try{ report = Pokemon::verify_checkpoint(id, policy, segment, hooks, state); }catch (OperationFailedException&){ - close_game_after_failure(env, context); + log_stop_after_failure(env); throw; } const std::string summary = std::format( "AutoStory verify: {} {}/{} passed, {} needed.", id, report.passes, policy.runs, policy.passes_needed ); if (!report.verified){ - close_game_after_failure(env, context); + log_stop_after_failure(env); throw OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, summary); } env.console.log(summary); @@ -244,7 +237,7 @@ void BDSPAutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerCo } if (const std::optional verify = RUN.VERIFY.policy()){ const VerifyRequest request{checkpoints[first].id, *verify, first == 0 && NEW_GAME_INTRO}; - verify_story_checkpoint(env, context, state, segment, hooks, request); + verify_story_checkpoint(env, state, segment, hooks, request); send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); return; } @@ -252,13 +245,13 @@ void BDSPAutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerCo try{ report = run_segment(Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), segment, hooks, state); }catch (OperationFailedException&){ - close_game_after_failure(env, context); + log_stop_after_failure(env); throw; } Pokemon::AutoStoryStats& stats = env.current_stats(); Pokemon::record_story_counts(report.story_counts(), stats); env.update_stats(); - throw_if_stopped(env, context, report); + throw_if_stopped(env, report); env.console.log("AutoStory: done through " + checkpoints[last].id + "."); send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); } From 7028e50b52c772eeac000078651f6063686052bd Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 11:40:31 -0800 Subject: [PATCH 2/5] BDSP AutoStory: run on the shared program shell The start at a checkpoint with a save now resets from HOME to load it first, as every retry does, so a run never walks from wherever the game was left (console B, 2026-11-11: 00.04b walked from 00.04d's position). Reload, failure and finish lines come from Pokemon/AutoStory's shell. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonBDSP_AutoStory.cpp | 151 ++++++++---------- 1 file changed, 69 insertions(+), 82 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp index ea2ab71611..8cbf7e448e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp @@ -13,6 +13,7 @@ #include "CommonFramework/Notifications/ProgramNotifications.h" #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "Pokemon/AutoStory/Pokemon_AutoStoryShell.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" #include "Pokemon/AutoStory/Pokemon_StoryLog.h" @@ -76,86 +77,42 @@ std::set rows_that_stop(const std::vector& rows){ return ids; } -// A failed attempt resets the game from HOME, which loads the save the -// row made at its start; the engine's lines go to the console's log. -Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ - Pokemon::SegmentHooks hooks; - hooks.save = [](Pokemon::RunState&){ - return Pokemon::outcome_failed("no_save_hook", "story rows save at their start"); - }; - hooks.reload = [&env, &context](Pokemon::RunState&){ - env.console.log("Resetting game from HOME before retry...", COLOR_ORANGE); +// What BDSP lends the shared shell: a load is a reset from HOME, which +// loads the save the row made at its start; the engine's lines go to the +// console's log. +Pokemon::StoryGameHooks story_game(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + Pokemon::StoryGameHooks game; + game.load_save = [&env, &context](Pokemon::RunState&){ if (!reset_game_from_home(env, env.console, context, true, 1000ms)){ return Pokemon::outcome_failed("reload_failed", "Failed to reset the game from HOME."); } return Pokemon::outcome_ok(); }; - hooks.log = [&env](const std::string& line){ + game.log = [&env](const std::string& line){ env.log(line, COLOR_BLUE); }; - hooks.status = [&env](const std::string& line){ + game.status = [&env](const std::string& line){ env.console.overlay().add_log(line); }; - return hooks; -} - -// A failed run leaves the game where it failed, so the user (or the -// next run from the checkpoint's save) can see and resume from there. -void log_stop_after_failure(SingleSwitchProgramEnvironment& env){ - env.log("AutoStory failed: the game stays where it failed.", COLOR_RED); -} - -// A run that stopped short throws. -void throw_if_stopped(SingleSwitchProgramEnvironment& env, const Pokemon::SegmentReport& report){ - if (report.completed){ - return; - } - log_stop_after_failure(env); - throw OperationFailedException( - ErrorReportMode::NO_ERROR_REPORT, - std::format( - "AutoStory stopped at {} {}: {}", - report.failed_checkpoint, report.failed_event, Pokemon::to_string(report.failure) - ) - ); + return game; } -// Verify mode's checkpoint and runs, and whether the game starts as a new -// game (refused: no save to reload) or stays open after a failure. -struct VerifyRequest{ - std::string id; - Pokemon::VerifyPolicy policy; - bool new_game = false; -}; - -// Verify mode: the checkpoint run as the request's policy says. Rows save -// at their start, never at their end, so the reset from HOME between runs -// loads the save the first run started from. Throws unless enough runs -// pass, closing the game first as after any failure unless `keep_game`. -void verify_story_checkpoint( - SingleSwitchProgramEnvironment& env, Pokemon::RunState& state, - Pokemon::Segment& segment, Pokemon::SegmentHooks& hooks, const VerifyRequest& request +// Verify mode: the checkpoint run as `policy` says, from the save the +// start loaded. Rows save at their start, never at their end, so each +// reload between runs loads that same save. Throws unless enough runs pass. +std::string verify_story_checkpoint( + const std::string& id, const Pokemon::VerifyPolicy& policy, + Pokemon::Segment& segment, Pokemon::StoryGameHooks& game, Pokemon::RunState& state ){ - if (request.new_game){ - throw UserSetupError(env.console, "Verify mode reloads the start's save between runs: turn off \"Start a new game first\"."); - } - const std::string& id = request.id; - const Pokemon::VerifyPolicy& policy = request.policy; + Pokemon::SegmentHooks hooks = Pokemon::story_segment_hooks(game); Pokemon::VerifyReport report; try{ report = Pokemon::verify_checkpoint(id, policy, segment, hooks, state); }catch (OperationFailedException&){ - log_stop_after_failure(env); + Pokemon::log_story_failure(game); throw; } - const std::string summary = std::format( - "AutoStory verify: {} {}/{} passed, {} needed.", id, report.passes, policy.runs, policy.passes_needed - ); - if (!report.verified){ - log_stop_after_failure(env); - throw OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, summary); - } - env.console.log(summary); + return Pokemon::finish_story_verify(id, policy, report, game); } } // namespace @@ -212,6 +169,33 @@ std::set saved_before_the_run(const std::vector& c return {checkpoints[first].id}; } +// The run from `range`'s first checkpoint to its last, its counts in the +// stats. Returns the finish line; throws if it stopped short. +std::string run_story( + const Pokemon::SegmentRange& range, const Pokemon::SegmentPolicy& policy, + Pokemon::Segment& segment, Pokemon::StoryGameHooks& game, Pokemon::RunState& state, + SingleSwitchProgramEnvironment& env +){ + Pokemon::SegmentHooks hooks = Pokemon::story_segment_hooks(game); + Pokemon::SegmentReport report; + try{ + report = run_segment(range, policy, segment, hooks, state); + }catch (OperationFailedException&){ + Pokemon::log_story_failure(game); + throw; + } + Pokemon::AutoStoryStats& stats = env.current_stats(); + std::string done; + try{ + done = Pokemon::finish_story_run(report, range.to.value_or(""), stats, game); + }catch (OperationFailedException&){ + env.update_stats(); + throw; + } + env.update_stats(); + return done; +} + } // namespace void BDSPAutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ @@ -229,31 +213,34 @@ void BDSPAutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerCo executor.set_stop_rows(rows_that_stop(checkpoints)); std::set saved = saved_before_the_run(checkpoints, first, JUST_LOADED && !(first == 0 && NEW_GAME_INTRO)); Pokemon::Segment segment = make_story_segment(checkpoints, executor, saved); - Pokemon::SegmentHooks hooks = story_hooks(env, context); - + Pokemon::StoryGameHooks game = story_game(env, context); + + // A start with a save always loads it first, so the run never walks + // from wherever the game was left (console B, 2026-11-11: a run from + // 00.04b walked from 00.04d's position). + const bool new_game = first == 0 && NEW_GAME_INTRO; + const Pokemon::StoryStart start = new_game ? Pokemon::StoryStart::NEW_GAME : Pokemon::StoryStart::FROM_SAVE; + if (new_game && RUN.VERIFY.policy()){ + throw UserSetupError(env.console, "Verify mode reloads the start's save between runs: turn off \"Start a new game first\"."); + } Pokemon::RunState state; - if (!(first == 0 && NEW_GAME_INTRO)){ - state.flags.insert("save_loaded"); + const Pokemon::Outcome loaded = Pokemon::prepare_story_start(checkpoints[first].id, start, game, state); + if (!loaded.succeeded()){ + Pokemon::log_story_failure(game); + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format("AutoStory could not load the save for {}: {}", checkpoints[first].id, Pokemon::to_string(loaded)) + ); } if (const std::optional verify = RUN.VERIFY.policy()){ - const VerifyRequest request{checkpoints[first].id, *verify, first == 0 && NEW_GAME_INTRO}; - verify_story_checkpoint(env, state, segment, hooks, request); - send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); + const std::string summary = verify_story_checkpoint(checkpoints[first].id, *verify, segment, game, state); + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH, summary); return; } - Pokemon::SegmentReport report; - try{ - report = run_segment(Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), segment, hooks, state); - }catch (OperationFailedException&){ - log_stop_after_failure(env); - throw; - } - Pokemon::AutoStoryStats& stats = env.current_stats(); - Pokemon::record_story_counts(report.story_counts(), stats); - env.update_stats(); - throw_if_stopped(env, report); - env.console.log("AutoStory: done through " + checkpoints[last].id + "."); - send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); + const std::string done = run_story( + Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), segment, game, state, env + ); + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH, done); } From efa2d3ec25f5b108f8c1ec3dcfef270056cd70ad Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 13:51:41 -0800 Subject: [PATCH 3/5] BDSP AutoStory: start gate, no blind save Supplies the shared story run's preflight (read_story_preflight) and a place check for the loaded save (the save card must name the start row's saves_in). Removes "Just loaded the start's save": a run from a save always loads it and the first row's start save is skipped by the shared rule (only a new game saves before it starts). A failed preflight is a setup error with nothing pressed. save_game() no longer saves blind when the save screen can't be confirmed; it stops with a screenshot (console B, 2026-11-11 13:32: X/R/ZL pressed on HOME). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonBDSP_AutoStory_Actions.cpp | 21 +++-- .../Actions/PokemonBDSP_AutoStory_Actions.h | 7 +- .../AutoStory/PokemonBDSP_AutoStory.cpp | 84 +++++++++++++------ .../AutoStory/PokemonBDSP_AutoStory.h | 1 - 4 files changed, 71 insertions(+), 42 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.cpp index 535147f833..884ebfbc35 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.cpp @@ -7,6 +7,7 @@ */ #include +#include #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/PrettyPrint.h" #include "CommonFramework/Exceptions/OperationFailedException.h" @@ -273,7 +274,7 @@ std::string read_location_from_save_screen(VideoStream& stream, ProControllerCon return location; } -bool save_game( +void save_game( SingleSwitchProgramEnvironment& env, ProControllerContext& context, const std::string& expected_location @@ -283,7 +284,7 @@ bool save_game( for (size_t attempt = 0; attempt < MAX_RETRIES; attempt++){ const SaveAttempt result = save_once(env, context, expected_location, attempt); if (result.outcome == SaveOutcome::SAVED){ - return true; + return; } // No blind fallback for the wrong place: it would save there. if (result.outcome == SaveOutcome::WRONG_PLACE){ @@ -291,15 +292,13 @@ bool save_game( } } - // Blind fallback: reuse the non-feedback save_game(context) from GameNavigation - // rather than duplicating the button sequence manually. - env.console.log("All save retries failed. Using blind fallback.", COLOR_ORANGE); - pbf_mash_button(context, BUTTON_B, 1000ms); - save_game(context); // PokemonBDSP_GameNavigation.h - non-feedback overload - pbf_mash_button(context, BUTTON_B, 2000ms); - context.wait_for_all_requests(); - - return false; + // No blind save: presses the screen never confirmed could land anywhere, + // even on the HOME menu (console B, 2026-11-11). Stop instead. + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("Couldn't confirm the save screen in {} attempts; not saving.", MAX_RETRIES), + env.console + ); } void wait_for_dialogue(VideoStream& stream, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h index afeb466640..b7f3235901 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h @@ -24,13 +24,14 @@ namespace NintendoSwitch{ namespace PokemonBDSP{ -// Save the game from the overworld with retries. Returns true if the save was -// verified via overworld detection, false if the blind fallback was used. +// Save the game from the overworld with retries. A save the screen never +// confirmed fails with a screenshot: there is no blind save (console B, +// 2026-11-11: one pressed X/R/ZL on the HOME menu). // With `expected_location`, the map named on the save screen's card must be // it (compared as a location banner is), or the save is backed out of and // the function fails with a screenshot: r124a saved in Sandgem Town after a // walk that was sure it stood on Route 202. -bool save_game( +void save_game( SingleSwitchProgramEnvironment& env, ProControllerContext& context, const std::string& expected_location = "" diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp index cfac8a73e8..ab36f2bfcf 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp @@ -13,6 +13,7 @@ #include "CommonFramework/Notifications/ProgramNotifications.h" #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "Pokemon/AutoStory/Pokemon_StoryConsolePreflight.h" #include "Pokemon/AutoStory/Pokemon_StoryRun.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" @@ -21,6 +22,7 @@ #include "Pokemon/Options/Pokemon_GameLanguages.h" #include "Pokemon/Options/Pokemon_StoryRunOptions.h" #include "PokemonBDSP/Programs/PokemonBDSP_GameEntry.h" +#include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" #include "PokemonBDSP_AutoStory_StoryTable.h" @@ -77,11 +79,14 @@ std::set rows_that_stop(const std::vector& rows){ return ids; } -// What BDSP lends the shared shell: a load is a reset from HOME, which -// loads the save the row made at its start; the engine's lines go to the -// console's log. +// What BDSP lends the shared shell: the console's preflight; a load is a +// reset from HOME, which loads the save the row made at its start; the +// engine's lines go to the console's log. Pokemon::StoryGameHooks story_game(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ Pokemon::StoryGameHooks game; + game.preflight = [&env, &context]{ + return Pokemon::read_story_preflight(env.console, context); + }; game.load_save = [&env, &context](Pokemon::RunState&){ if (!reset_game_from_home(env, env.console, context, true, 1000ms)){ return Pokemon::outcome_failed("reload_failed", "Failed to reset the game from HOME."); @@ -126,12 +131,6 @@ BDSPAutoStory::BDSPAutoStory() "until the player is in control in the bedroom. Only when starting at 00.00.", LockMode::LOCK_WHILE_RUNNING, false ) - , JUST_LOADED( - "Just loaded the start's save:
" - "The game was just loaded from the start checkpoint's save, so its save at the start is skipped (about 10 s). " - "Leave off when the game has moved since its last save.", - LockMode::LOCK_WHILE_RUNNING, false - ) , PLAYER_NAME(false, "Player name:
For a new game. Letters and digits.", LockMode::LOCK_WHILE_RUNNING, "Kosmos", "Kosmos") , STARTER( "Starter Pokemon:", @@ -151,7 +150,6 @@ BDSPAutoStory::BDSPAutoStory() { PA_ADD_OPTION(RUN); PA_ADD_OPTION(NEW_GAME_INTRO); - PA_ADD_OPTION(JUST_LOADED); PA_ADD_OPTION(PLAYER_NAME); PA_ADD_OPTION(STARTER); PA_ADD_OPTION(NOTIFICATIONS); @@ -159,16 +157,56 @@ BDSPAutoStory::BDSPAutoStory() namespace{ -// The checkpoints whose start is already saved: the first one when the game -// was just loaded from its save (saving again cost ~10 s). After play, the -// save is older and the first checkpoint must save its start. -std::set saved_before_the_run(const std::vector& checkpoints, size_t first, bool just_loaded){ - if (!just_loaded){ +// The checkpoints whose start save is skipped: the first one, unless the +// run starts a new game. After a load its save is already there (saving +// again cost ~10 s), and nothing saves before the start is confirmed. +std::set saved_before_the_run(const std::vector& checkpoints, size_t first, Pokemon::StoryStart start){ + if (Pokemon::story_first_save_allowed(start)){ return {}; } return {checkpoints[first].id}; } +// "" when the save screen's card names `place`, the map the start row +// saved in, else why not. Opens the save screen and backs out unsaved. +std::string check_start_place(SingleSwitchProgramEnvironment& env, ProControllerContext& context, const std::string& place){ + if (place.empty()){ + return ""; + } + const std::string read = read_location_from_save_screen(env.console, context); + if (location_banner_matches(read, place)){ + return ""; + } + return std::format("The save is in \"{}\", not {}.", read, place); +} + +// Gets the game to where `row` starts through the shared start gate: +// preflight, then (for a save) the load and the save card's place. Throws a +// setup error when the preflight failed, nothing pressed, and an +// OperationFailedException when the load or place check failed, unsaved. +void start_story( + SingleSwitchProgramEnvironment& env, ProControllerContext& context, const StoryCheckpoint& row, + Pokemon::StoryStart start, Pokemon::StoryGameHooks& game, Pokemon::RunState& state +){ + // The loaded save must be where the start row saved; a retry's reload + // in a later row is checked by that row's own start save. + game.check_save_place = [&env, &context, place = row.saves_in]{ + return check_start_place(env, context, place); + }; + const Pokemon::Outcome loaded = Pokemon::prepare_story_start(row.id, start, game, state); + game.check_save_place = nullptr; + if (loaded.failure == Pokemon::STORY_PRECONDITION_FAILED){ + throw UserSetupError(env.console, std::format("AutoStory did not start, nothing was pressed: {}", loaded.detail)); + } + if (!loaded.succeeded()){ + Pokemon::log_story_failure(game); + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format("AutoStory could not load the save for {}: {}", row.id, Pokemon::to_string(loaded)) + ); + } +} + // The run from `range`'s first checkpoint to its last, its counts in the // stats. Returns the finish line; throws if it stopped short. std::string run_story( @@ -211,10 +249,6 @@ void BDSPAutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerCo StoryEnv story{env, context, STARTER, PLAYER_NAME}; StoryExecutor executor(story); executor.set_stop_rows(rows_that_stop(checkpoints)); - std::set saved = saved_before_the_run(checkpoints, first, JUST_LOADED && !(first == 0 && NEW_GAME_INTRO)); - Pokemon::Segment segment = make_story_segment(checkpoints, executor, saved); - Pokemon::StoryGameHooks game = story_game(env, context); - // A start with a save always loads it first, so the run never walks // from wherever the game was left (console B, 2026-11-11: a run from // 00.04b walked from 00.04d's position). @@ -223,15 +257,11 @@ void BDSPAutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerCo if (new_game && RUN.VERIFY.policy()){ throw UserSetupError(env.console, "Verify mode reloads the start's save between runs: turn off \"Start a new game first\"."); } + std::set saved = saved_before_the_run(checkpoints, first, start); + Pokemon::Segment segment = make_story_segment(checkpoints, executor, saved); + Pokemon::StoryGameHooks game = story_game(env, context); Pokemon::RunState state; - const Pokemon::Outcome loaded = Pokemon::prepare_story_start(checkpoints[first].id, start, game, state); - if (!loaded.succeeded()){ - Pokemon::log_story_failure(game); - throw OperationFailedException( - ErrorReportMode::NO_ERROR_REPORT, - std::format("AutoStory could not load the save for {}: {}", checkpoints[first].id, Pokemon::to_string(loaded)) - ); - } + start_story(env, context, checkpoints[first], start, game, state); if (const std::optional verify = RUN.VERIFY.policy()){ const std::string summary = verify_story_checkpoint(checkpoints[first].id, *verify, segment, game, state); send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH, summary); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h index 9fe9b929a5..154eccade4 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h @@ -47,7 +47,6 @@ class BDSPAutoStory : public SingleSwitchProgramInstance{ // The start and end checkpoints, attempts, checks and language. Pokemon::StoryRunOptions RUN; BooleanCheckBoxOption NEW_GAME_INTRO; - BooleanCheckBoxOption JUST_LOADED; StringOption PLAYER_NAME; EnumDropdownOption STARTER; From 7a8f1c371e0aeaf0d8d597c55d4c01b571b27e4b Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 14:51:00 -0800 Subject: [PATCH 4/5] AutoStory: Use StoryPreflight's FAILURE and check() after the #396 merge Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp index ab36f2bfcf..bba521d1d3 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp @@ -195,7 +195,7 @@ void start_story( }; const Pokemon::Outcome loaded = Pokemon::prepare_story_start(row.id, start, game, state); game.check_save_place = nullptr; - if (loaded.failure == Pokemon::STORY_PRECONDITION_FAILED){ + if (loaded.failure == Pokemon::StoryPreflight::FAILURE){ throw UserSetupError(env.console, std::format("AutoStory did not start, nothing was pressed: {}", loaded.detail)); } if (!loaded.succeeded()){ From fb7e08b7f719b490dda2cfc1ea634d010a638754 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 14:58:06 -0800 Subject: [PATCH 5/5] AutoStory: use StoryPreflight::read after merging nav/story-start-gate Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp index bba521d1d3..9e10c1ac1f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp @@ -13,7 +13,7 @@ #include "CommonFramework/Notifications/ProgramNotifications.h" #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" -#include "Pokemon/AutoStory/Pokemon_StoryConsolePreflight.h" +#include "Pokemon/AutoStory/Pokemon_StoryPreflight.h" #include "Pokemon/AutoStory/Pokemon_StoryRun.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" @@ -85,7 +85,7 @@ std::set rows_that_stop(const std::vector& rows){ Pokemon::StoryGameHooks story_game(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ Pokemon::StoryGameHooks game; game.preflight = [&env, &context]{ - return Pokemon::read_story_preflight(env.console, context); + return Pokemon::StoryPreflight::read(env.console, context); }; game.load_save = [&env, &context](Pokemon::RunState&){ if (!reset_game_from_home(env, env.console, context, true, 1000ms)){