From 40ba0b628098d850fa505b2190a56ed2f66ab182 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 01:46:34 -0800 Subject: [PATCH 1/5] PokemonLZA AutoStory: the program and its panel --- .../PokemonLZA/PokemonLZA_Panels.cpp | 3 + .../AutoStory/PokemonLZA_AutoStory.cpp | 243 ++++++++++++++++++ .../Programs/AutoStory/PokemonLZA_AutoStory.h | 72 ++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 4 files changed, 320 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Panels.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Panels.cpp index bd5e98adae..cfc1cd9bd3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Panels.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Panels.cpp @@ -54,6 +54,7 @@ #include "Programs/TestPrograms/PokemonLZA_MoveBoxArrow.h" #include "Programs/TestPrograms/PokemonLZA_TestBoxCellInfo.h" #include "InferenceTraining/PokemonLZA_GenerateLocationNameOCR.h" +#include "Programs/AutoStory/PokemonLZA_AutoStory.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -68,6 +69,7 @@ PanelListFactory::PanelListFactory() ) {} +// code-health: allow function_lines -- the list reads top to bottom as the program menu does; splitting it by section hides that order std::vector PanelListFactory::make_panels() const{ std::vector ret; @@ -121,6 +123,7 @@ std::vector PanelListFactory::make_panels() const{ ret.emplace_back("---- Public Betas ----"); ret.emplace_back(make_SingleSwitchProgram()); + ret.emplace_back(make_SingleSwitchProgram()); if (STATIC_GLOBALS.DEVELOPER_MODE){ ret.emplace_back("---- Developer Tools ----"); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp new file mode 100644 index 0000000000..5cdab5a256 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -0,0 +1,243 @@ +/* PokemonLZA AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/VideoPipeline/VideoOverlay.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" +#include "Pokemon/AutoStory/Pokemon_StoryLog.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" +#include "Pokemon/Options/Pokemon_GameLanguages.h" +#include "Pokemon/Pokemon_Strings.h" +#include "VideoGames/PokemonLZA/Inference/Map/PokemonLZA_LocationNameReader.h" +#include "Actions/PokemonLZA_AutoStoryConfirmChoices.h" +#include "PokemonLZA_AutoStoryGame.h" +#include "PokemonLZA_AutoStoryStoryFiles.h" +#include "PokemonLZA_AutoStoryTable.h" +#include "PokemonLZA_AutoStory.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace Pokemon; + + +AutoStory_Descriptor::AutoStory_Descriptor() + : SingleSwitchProgramDescriptor( + "PokemonLZA:AutoStory", + std::format("{} LZA", STRING_POKEMON), "Auto Story", + "Programs/PokemonLZA/AutoStory.html", + "Play the main story of Pokemon Legends: Z-A. Prototype: Main Missions 01-03 as recorded on a console; plays from a new game to Mable's Rock Smash TM. " + "Start a new game and pick its language, look and name by hand: checkpoint 01.00 starts on the Confirm Choices screen that follows. " + "It checks that screen, presses nothing anywhere else, and picks Ready!. Later checkpoints load their save first. " + "Set Game Language to the language the game is set to: the program reads place names in it.", + PanelQualityStanding::DEVELOPER, + ProgramControllerClass::StandardController_NoRestrictions, + FeedbackType::REQUIRED, + AllowCommandsWhenRunning::DISABLE_COMMANDS + ) +{} + +std::unique_ptr AutoStory_Descriptor::make_stats() const{ + return std::make_unique(); +} + + +namespace{ + +// The start and end dropdowns' entries. The options hold a reference to it. +const StringSelectDatabase& checkpoint_database(){ + static const StringSelectDatabase database = []{ + std::vector labels; + for (const StoryCheckpoint& row : story_checkpoints()){ + labels.push_back(story_checkpoint_label(row)); + } + return story_checkpoint_database(labels); + }(); + return database; +} + +constexpr std::string_view RELOAD_AT_BOUNDARIES_LABEL = + "Reload at Checkpoint Boundaries:
Reload the save before a checkpoint whose plan asks for it " + "when the run comes from the checkpoint before. Off: run straight on. A failed checkpoint's retry reloads either way."; +constexpr std::string_view START_FROM_BACKUP_SAVE_LABEL = + "Start from the Backup Save:
The run starts by loading the backup save " + "(title screen Up + B + X), the save before the latest. Off: it loads the latest save and, when a checkpoint " + "with a start check is not at its start there, the backup save, then saves there (Report) before it starts. " + "Later reloads load the latest save either way.
" + "Warning: a run from the backup save saves over the latest save (the start's Report, " + "the game's autosaves, the checkpoints' saves). The progress in the latest save is lost."; + +} // namespace + + +AutoStory::AutoStory() + : LANGUAGE( + "Game Language:
The language the game is set to. The program reads text in it " + "(the place names in the fast travel menu) and does not check that the game matches.", + LocationNameOCR::instance().languages(), + LockMode::LOCK_WHILE_RUNNING, + true + ) + , RUN(checkpoint_database(), Gen8ToGen9Languages_Database()) + , STARTER( + "Starter Pokemon:", + { + {StarterChoice::CHIKORITA, "chikorita", "Chikorita"}, + {StarterChoice::TEPIG, "tepig", "Tepig"}, + {StarterChoice::TOTODILE, "totodile", "Totodile"}, + }, + LockMode::LOCK_WHILE_RUNNING, + StarterChoice::CHIKORITA + ) + , RELOAD_AT_BOUNDARIES(std::string(RELOAD_AT_BOUNDARIES_LABEL), LockMode::LOCK_WHILE_RUNNING, false) + , START_FROM_BACKUP_SAVE(std::string(START_FROM_BACKUP_SAVE_LABEL), LockMode::LOCK_WHILE_RUNNING, false) + , GO_HOME_WHEN_DONE(false) + , NOTIFICATIONS({ + &NOTIFICATION_PROGRAM_FINISH, + &NOTIFICATION_ERROR_RECOVERABLE, + &NOTIFICATION_ERROR_FATAL, + }) +{ + PA_ADD_OPTION(LANGUAGE); + RUN.LANGUAGE.set_visibility(ConfigOptionState::HIDDEN); + PA_ADD_OPTION(RUN); + PA_ADD_OPTION(STARTER); + PA_ADD_OPTION(BATTLE_AI); + PA_ADD_OPTION(RELOAD_AT_BOUNDARIES); + PA_ADD_OPTION(START_FROM_BACKUP_SAVE); + PA_ADD_OPTION(GO_HOME_WHEN_DONE); + PA_ADD_OPTION(NOTIFICATIONS); +} + +namespace{ + +// Where the run takes its start from: the running game when RELOAD_AT_START +// is off, else the backup or the latest save. Both off-reload and the +// backup save at once is refused: keeping the game loads no save. +StartFrom start_from(ConsoleHandle& console, const Pokemon::StoryRunOptions& run, bool backup_first){ + if (run.RELOAD_AT_START){ + return backup_first ? StartFrom::BACKUP_SAVE : StartFrom::LATEST_SAVE; + } + if (backup_first){ + throw UserSetupError(console, "Start from the Backup Save loads a save: turn on Reload the Save at the Start."); + } + console.log("AutoStory: no reload at the start, keeping the running game."); + return StartFrom::RUNNING_GAME; +} + +// Checkpoints after the new game start from a save (01.01 from the +// platform autosave), so the run loads it first instead of assuming the +// game is already there: the latest save, or the backup save when the +// latest is past the start (load_checkpoint_start()); with `from` +// RUNNING_GAME, the game as it runs. 01.00 starts without one. +void load_start_save( + ConsoleHandle& console, StoryEnv& story, StoryBackend& backend, + const std::vector& rows, size_t first, StartFrom from +){ + if (story_row_starts_without_save(rows[first])){ + return; + } + const Outcome loaded = load_checkpoint_start(story, backend, rows[first].id, from); + if (!loaded.succeeded()){ + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format("AutoStory: could not load the save for {}: {}", rows[first].id, to_string(loaded)) + ); + } + console.log(std::format("AutoStory: loaded the save for {}.", rows[first].id)); +} + +// Connects the controller for a run from `first_row`. 01.00 starts on a +// screen that proves the save is fresh, so it is checked before any press, +// the connect press included. +void connect_controller(ConsoleHandle& console, ProControllerContext& context, const StoryCheckpoint& first_row){ + if (story_row_starts_without_save(first_row)){ + require_confirm_choices(console, context); + } + require_player(console, context, BUTTON_L); +} + +// `run`'s attempts per checkpoint, and the boundary reload `reload_at_boundaries` +// picks; logs which. +StoryRunPolicy run_policy(const Pokemon::StoryRunOptions& run, const BooleanCheckBoxOption& reload_at_boundaries, Logger& logger){ + if (reload_at_boundaries){ + logger.log("AutoStory: reloads the save at checkpoint boundaries whose plan asks for it."); + return {.attempts_per_checkpoint = run.policy().attempts_per_checkpoint, .boundary_reload = StoryRunPolicy::BoundaryReload::AT_PLAN_BOUNDARIES}; + } + logger.log("AutoStory: runs straight through checkpoint boundaries, no reload."); + return {.attempts_per_checkpoint = run.policy().attempts_per_checkpoint, .boundary_reload = StoryRunPolicy::BoundaryReload::STRAIGHT_THROUGH}; +} + +} // namespace + +void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + const StoryData& story_data = builtin_story_data(); + const std::vector& rows = story_data.checkpoints; + const size_t first = RUN.start_index(); + const size_t last = RUN.end_index(); + if (first > last || last >= rows.size()){ + throw UserSetupError(env.console, "The start checkpoint must not come after the end checkpoint."); + } + const StartFrom from = start_from(env.console, RUN, START_FROM_BACKUP_SAVE); + connect_controller(env.console, context, rows[first]); + + StoryEnv story{ + .env = env, .context = context, .language = LANGUAGE, .battle_ai = BATTLE_AI, .checks = RUN.check_level() + }; + PlzaConsoleBackend backend(story); + const StoryGame game = make_plza_story_game(story, STARTER, story_data.autosaves); + StoryEngine engine(game, backend); + RunState state; + load_start_save(env.console, story, backend, rows, first, from); + + if (const std::optional verify = RUN.VERIFY.policy()){ + const VerifyReport report = engine.verify_checkpoint(rows[first], *verify, state); + if (!report.verified){ + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format( + "AutoStory verify: {} {}/{} passed, {} needed{}", report.checkpoint, report.passes, report.runs, + verify->passes_needed, report.failure.succeeded() ? std::string() : std::format(": {}", to_string(report.failure)) + ) + ); + } + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); + return; + } + const std::vector checkpoints = story_run_rows(std::span(rows), first, last); + const SegmentReport report = run_plza_segment(game, story_data, checkpoints, run_policy(RUN, RELOAD_AT_BOUNDARIES, env.console), engine, backend, state); + record_story_counts(report.story_counts(), env.current_stats()); + env.update_stats(); + if (!report.completed){ + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format( + "AutoStory stopped at {} {}: {}", report.failed_checkpoint, report.failed_event, to_string(report.failure) + ) + ); + } + env.console.log(std::format("AutoStory: done through {}.", rows[last].id)); + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); + GO_HOME_WHEN_DONE.run_end_of_program(context); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h new file mode 100644 index 0000000000..a4c246ad1a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -0,0 +1,72 @@ +/* PokemonLZA AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + * Plays Pokemon Legends: Z-A's main story: the story table + * (PokemonLZA_AutoStoryTable.h) run by the shared story engine + * (Pokemon/AutoStory), from the start checkpoint to the end one. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStory_H +#define PokemonAutomation_PokemonLZA_AutoStory_H + +#include "Common/Cpp/Options/BooleanCheckBoxOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "CommonTools/Options/LanguageOCROption.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" +#include "Pokemon/Options/Pokemon_StoryRunOptions.h" +#include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" +#include "PokemonLZA_AutoStoryBackend.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Descriptor for the Pokemon Legends: Z-A AutoStory program. +class AutoStory_Descriptor : public SingleSwitchProgramDescriptor{ +public: + AutoStory_Descriptor(); + + virtual std::unique_ptr make_stats() const override; +}; + + +// Runs the story's checkpoints from the start one to the end one on the +// shared story engine. +class AutoStory : public SingleSwitchProgramInstance{ +public: + using Descriptor = AutoStory_Descriptor; + AutoStory(); + + virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; + +private: + // The language the game is set to, required: the steps that read text + // (the fast travel menu's place names) read it in this language. The + // program does not check that the game matches. + OCR::LanguageOCROption LANGUAGE; + // The start and end checkpoints, attempts and checks. Its own language + // dropdown is hidden: LANGUAGE above is PLZA's. + Pokemon::StoryRunOptions RUN; + EnumDropdownOption STARTER; + BattleAIOption BATTLE_AI; + // Off: a run of several checkpoints runs straight on at the rows whose + // plans say "reload_when_chained"; on: it reloads the save there. + BooleanCheckBoxOption RELOAD_AT_BOUNDARIES; + // On: the run starts from the backup save; off: from the latest, or + // the backup save when the latest is past the start check. + BooleanCheckBoxOption START_FROM_BACKUP_SAVE; + + GoHomeWhenDoneOption GO_HOME_WHEN_DONE; + EventNotificationsOption NOTIFICATIONS; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 7edd775f2c..986c2c8c3c 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2478,6 +2478,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryZoneGateReader_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp From 567dd1259bd33934e9a8413c069191b1dd4673eb Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 03:43:39 -0800 Subject: [PATCH 2/5] PokemonLZA AutoStory program: verify goes home when done; range check split; capture option A verify run returned after its notification without GO_HOME_WHEN_DONE. An out-of-range checkpoint index got the start-after-end message; it now has its own. Save Screen Captures (off by default) turns on the backend's frame captures (StoryEnv::capture_looks). run_policy() builds the policy once, start_from() takes the option rather than a bool, and the includes are sorted. --- .../AutoStory/PokemonLZA_AutoStory.cpp | 31 +++++++++++++------ .../Programs/AutoStory/PokemonLZA_AutoStory.h | 3 ++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 5cdab5a256..d5a71aa463 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -16,8 +16,8 @@ #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" -#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" +#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" #include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" #include "Pokemon/Options/Pokemon_GameLanguages.h" @@ -81,6 +81,10 @@ constexpr std::string_view START_FROM_BACKUP_SAVE_LABEL = "Later reloads load the latest save either way.
" "Warning: a run from the backup save saves over the latest save (the start's Report, " "the game's autosaves, the checkpoints' saves). The progress in the latest save is lost."; +constexpr std::string_view CAPTURE_LOOKS_LABEL = + "Save Screen Captures:
Save a screenshot each time what the program sees on screen changes, " + "and every 2 s, to Screenshots/PLZA-capture/. For finding screens the program misses: a long run writes " + "thousands of images."; } // namespace @@ -106,6 +110,7 @@ AutoStory::AutoStory() ) , RELOAD_AT_BOUNDARIES(std::string(RELOAD_AT_BOUNDARIES_LABEL), LockMode::LOCK_WHILE_RUNNING, false) , START_FROM_BACKUP_SAVE(std::string(START_FROM_BACKUP_SAVE_LABEL), LockMode::LOCK_WHILE_RUNNING, false) + , CAPTURE_LOOKS(std::string(CAPTURE_LOOKS_LABEL), LockMode::LOCK_WHILE_RUNNING, false) , GO_HOME_WHEN_DONE(false) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, @@ -120,6 +125,7 @@ AutoStory::AutoStory() PA_ADD_OPTION(BATTLE_AI); PA_ADD_OPTION(RELOAD_AT_BOUNDARIES); PA_ADD_OPTION(START_FROM_BACKUP_SAVE); + PA_ADD_OPTION(CAPTURE_LOOKS); PA_ADD_OPTION(GO_HOME_WHEN_DONE); PA_ADD_OPTION(NOTIFICATIONS); } @@ -129,11 +135,11 @@ namespace{ // Where the run takes its start from: the running game when RELOAD_AT_START // is off, else the backup or the latest save. Both off-reload and the // backup save at once is refused: keeping the game loads no save. -StartFrom start_from(ConsoleHandle& console, const Pokemon::StoryRunOptions& run, bool backup_first){ +StartFrom start_from(ConsoleHandle& console, const Pokemon::StoryRunOptions& run, const BooleanCheckBoxOption& start_from_backup_save){ if (run.RELOAD_AT_START){ - return backup_first ? StartFrom::BACKUP_SAVE : StartFrom::LATEST_SAVE; + return start_from_backup_save ? StartFrom::BACKUP_SAVE : StartFrom::LATEST_SAVE; } - if (backup_first){ + if (start_from_backup_save){ throw UserSetupError(console, "Start from the Backup Save loads a save: turn on Reload the Save at the Start."); } console.log("AutoStory: no reload at the start, keeping the running game."); @@ -175,12 +181,14 @@ void connect_controller(ConsoleHandle& console, ProControllerContext& context, c // `run`'s attempts per checkpoint, and the boundary reload `reload_at_boundaries` // picks; logs which. StoryRunPolicy run_policy(const Pokemon::StoryRunOptions& run, const BooleanCheckBoxOption& reload_at_boundaries, Logger& logger){ + StoryRunPolicy::BoundaryReload boundary_reload = StoryRunPolicy::BoundaryReload::STRAIGHT_THROUGH; if (reload_at_boundaries){ logger.log("AutoStory: reloads the save at checkpoint boundaries whose plan asks for it."); - return {.attempts_per_checkpoint = run.policy().attempts_per_checkpoint, .boundary_reload = StoryRunPolicy::BoundaryReload::AT_PLAN_BOUNDARIES}; + boundary_reload = StoryRunPolicy::BoundaryReload::AT_PLAN_BOUNDARIES; + }else{ + logger.log("AutoStory: runs straight through checkpoint boundaries, no reload."); } - logger.log("AutoStory: runs straight through checkpoint boundaries, no reload."); - return {.attempts_per_checkpoint = run.policy().attempts_per_checkpoint, .boundary_reload = StoryRunPolicy::BoundaryReload::STRAIGHT_THROUGH}; + return {.attempts_per_checkpoint = run.policy().attempts_per_checkpoint, .boundary_reload = boundary_reload}; } } // namespace @@ -190,14 +198,18 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex const std::vector& rows = story_data.checkpoints; const size_t first = RUN.start_index(); const size_t last = RUN.end_index(); - if (first > last || last >= rows.size()){ + if (last >= rows.size()){ + throw UserSetupError(env.console, "The checkpoint selection is out of range: pick the start and end checkpoints again."); + } + if (first > last){ throw UserSetupError(env.console, "The start checkpoint must not come after the end checkpoint."); } const StartFrom from = start_from(env.console, RUN, START_FROM_BACKUP_SAVE); connect_controller(env.console, context, rows[first]); StoryEnv story{ - .env = env, .context = context, .language = LANGUAGE, .battle_ai = BATTLE_AI, .checks = RUN.check_level() + .env = env, .context = context, .language = LANGUAGE, .battle_ai = BATTLE_AI, .checks = RUN.check_level(), + .capture_looks = CAPTURE_LOOKS, }; PlzaConsoleBackend backend(story); const StoryGame game = make_plza_story_game(story, STARTER, story_data.autosaves); @@ -217,6 +229,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex ); } send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); + GO_HOME_WHEN_DONE.run_end_of_program(context); return; } const std::vector checkpoints = story_run_rows(std::span(rows), first, last); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index a4c246ad1a..1fa002a98b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -59,6 +59,9 @@ class AutoStory : public SingleSwitchProgramInstance{ // On: the run starts from the backup save; off: from the latest, or // the backup save when the latest is past the start check. BooleanCheckBoxOption START_FROM_BACKUP_SAVE; + // On: the backend saves a frame each time the look's events change + // (StoryEnv::capture_looks). + BooleanCheckBoxOption CAPTURE_LOOKS; GoHomeWhenDoneOption GO_HOME_WHEN_DONE; EventNotificationsOption NOTIFICATIONS; From 2e6e1d8c5f8ddcd2b4f86a9cfeb9dc8965091a30 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 03:44:02 -0800 Subject: [PATCH 3/5] PokemonLZA AutoStory program: the checkpoint range check is its own helper --- .../AutoStory/PokemonLZA_AutoStory.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index d5a71aa463..69008aaeb2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -178,6 +178,17 @@ void connect_controller(ConsoleHandle& console, ProControllerContext& context, c require_player(console, context, BUTTON_L); } +// Throws UserSetupError unless rows `first` to `last` are in a table of +// `rows` rows, in order. +void check_checkpoint_range(ConsoleHandle& console, size_t first, size_t last, size_t rows){ + if (last >= rows){ + throw UserSetupError(console, "The checkpoint selection is out of range: pick the start and end checkpoints again."); + } + if (first > last){ + throw UserSetupError(console, "The start checkpoint must not come after the end checkpoint."); + } +} + // `run`'s attempts per checkpoint, and the boundary reload `reload_at_boundaries` // picks; logs which. StoryRunPolicy run_policy(const Pokemon::StoryRunOptions& run, const BooleanCheckBoxOption& reload_at_boundaries, Logger& logger){ @@ -198,12 +209,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex const std::vector& rows = story_data.checkpoints; const size_t first = RUN.start_index(); const size_t last = RUN.end_index(); - if (last >= rows.size()){ - throw UserSetupError(env.console, "The checkpoint selection is out of range: pick the start and end checkpoints again."); - } - if (first > last){ - throw UserSetupError(env.console, "The start checkpoint must not come after the end checkpoint."); - } + check_checkpoint_range(env.console, first, last, rows.size()); const StartFrom from = start_from(env.console, RUN, START_FROM_BACKUP_SAVE); connect_controller(env.console, context, rows[first]); From b9c0210a4b33ac4dc91879fd059bcbdbd5db3ab0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 12:27:22 -0800 Subject: [PATCH 4/5] PokemonLZA AutoStory: attempts from ATTEMPTS_PER_CHECKPOINT; drop verify mode --- .../AutoStory/PokemonLZA_AutoStory.cpp | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 69008aaeb2..703cc81675 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -5,7 +5,6 @@ */ #include -#include #include #include #include @@ -199,7 +198,7 @@ StoryRunPolicy run_policy(const Pokemon::StoryRunOptions& run, const BooleanChec }else{ logger.log("AutoStory: runs straight through checkpoint boundaries, no reload."); } - return {.attempts_per_checkpoint = run.policy().attempts_per_checkpoint, .boundary_reload = boundary_reload}; + return {.attempts_per_checkpoint = run.ATTEMPTS_PER_CHECKPOINT, .boundary_reload = boundary_reload}; } } // namespace @@ -223,21 +222,6 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex RunState state; load_start_save(env.console, story, backend, rows, first, from); - if (const std::optional verify = RUN.VERIFY.policy()){ - const VerifyReport report = engine.verify_checkpoint(rows[first], *verify, state); - if (!report.verified){ - throw OperationFailedException( - ErrorReportMode::NO_ERROR_REPORT, - std::format( - "AutoStory verify: {} {}/{} passed, {} needed{}", report.checkpoint, report.passes, report.runs, - verify->passes_needed, report.failure.succeeded() ? std::string() : std::format(": {}", to_string(report.failure)) - ) - ); - } - send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); - GO_HOME_WHEN_DONE.run_end_of_program(context); - return; - } const std::vector checkpoints = story_run_rows(std::span(rows), first, last); const SegmentReport report = run_plza_segment(game, story_data, checkpoints, run_policy(RUN, RELOAD_AT_BOUNDARIES, env.console), engine, backend, state); record_story_counts(report.story_counts(), env.current_stats()); From 2b7506ecbf65503b55cfd5ba0f995af1ed181a94 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 12:34:02 -0800 Subject: [PATCH 5/5] PokemonLZA AutoStory: StoryRunOptions has no language; drop the hidden RUN.LANGUAGE --- .../PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 703cc81675..515e009ad9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -19,7 +19,7 @@ #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" #include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" -#include "Pokemon/Options/Pokemon_GameLanguages.h" + #include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonLZA/Inference/Map/PokemonLZA_LocationNameReader.h" #include "Actions/PokemonLZA_AutoStoryConfirmChoices.h" @@ -96,7 +96,7 @@ AutoStory::AutoStory() LockMode::LOCK_WHILE_RUNNING, true ) - , RUN(checkpoint_database(), Gen8ToGen9Languages_Database()) + , RUN(checkpoint_database()) , STARTER( "Starter Pokemon:", { @@ -118,7 +118,7 @@ AutoStory::AutoStory() }) { PA_ADD_OPTION(LANGUAGE); - RUN.LANGUAGE.set_visibility(ConfigOptionState::HIDDEN); + PA_ADD_OPTION(RUN); PA_ADD_OPTION(STARTER); PA_ADD_OPTION(BATTLE_AI);