From 191ffa43a9b7768e9d3a17462acdd6364f4384bf Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 06:44:33 -0800 Subject: [PATCH 1/2] PLZA AutoStory: no retry from a save that moved past the checkpoint's start Console B 2026-11-16: 03.04 autosaved in pokedex_app at 03:52 and failed in the step after it (after_pokedex, since folded). The game's latest save was then outside the Pokemon Center, so the 06:36 and 06:38 runs of 03.04 loaded it, logged "off the station platform, as at its start", and walked into_pokemon_center's legs from the wrong place: walk_no_end. AutosaveSightings now keeps the step an autosave showed in. While it has one, run_plza_segments' reload fails as "save_moved" instead of retrying from past the start, and a failed row logs "[Save] : the game autosaved in before the run failed: the latest save is past 's start". The load line now says the row's own start is unchecked. --- .../PokemonLZA_AutoStoryAutosaves.cpp | 33 ++++++++++++++-- .../AutoStory/PokemonLZA_AutoStoryAutosaves.h | 21 +++++++++- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 7 ++-- .../AutoStory/PokemonLZA_AutoStoryGame.h | 3 ++ .../PokemonLZA_AutoStoryGame_Tests.cpp | 38 ++++++++++++++++--- 5 files changed, 90 insertions(+), 12 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp index 3205673a3d..685815c73a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp @@ -85,7 +85,7 @@ class SightingBackend : public PlzaBackend{ void AutosaveSightings::restart(){ m_origin.reset(); m_last_badge.reset(); - m_seen = false; + m_seen_in.reset(); } void AutosaveSightings::note(PlzaBackend& backend, const Pokemon::Observation& look, std::string_view step){ @@ -97,7 +97,9 @@ void AutosaveSightings::note(PlzaBackend& backend, const Pokemon::Observation= AUTOSAVE_DEBOUNCE; m_last_badge = look.when; - m_seen = true; + if (!m_seen_in){ + m_seen_in = std::string(step); + } if (new_sighting){ const double seconds = (double)std::chrono::duration_cast(look.when - *m_origin).count() / 1000; backend.log(std::format("[PLZA] autosave badge at {:.1f}s in {}", seconds, step)); @@ -105,7 +107,7 @@ void AutosaveSightings::note(PlzaBackend& backend, const Pokemon::Observation with_autosave_sightings( return game; } +Pokemon::StoryGame reloading_only_to_start(const Pokemon::StoryGame& game, const AutosaveSightings& sightings){ + Pokemon::StoryGame guarded = game; + if (!game.reload){ + return guarded; + } + guarded.reload = [reload = game.reload, &sightings](Pokemon::StoryBackend& backend){ + if (const std::optional& step = sightings.seen_in()){ + return Pokemon::outcome_failed("save_moved", std::format( + "the game autosaved in {} during the failed run: a reload would load past the checkpoint's start", *step + )); + } + return reload(backend); + }; + return guarded; +} + +void log_moved_save(PlzaBackend& backend, const AutosaveSightings& sightings, std::string_view checkpoint){ + if (const std::optional& step = sightings.seen_in()){ + backend.log(std::format( + "[Save] {}: the game autosaved in {} before the run failed: the latest save is past {}'s start", + checkpoint, *step, checkpoint + )); + } +} + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h index 54d2be8b45..c77a54633a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h @@ -13,6 +13,7 @@ #define PokemonAutomation_PokemonLZA_AutoStoryAutosaves_H #include +#include #include #include "Common/Cpp/Time.h" #include "Pokemon/AutoStory/Data/Pokemon_StoryRowExecution.h" @@ -44,11 +45,16 @@ class AutosaveSightings{ bool last_end_seen() const{ return m_last_end_seen; } + // The step of the checkpoint under way the badge first showed in, if + // it did: the game's latest save is then past the checkpoint's start. + const std::optional& seen_in() const{ + return m_seen_in; + } private: std::optional m_origin; std::optional m_last_badge; - bool m_seen = false; + std::optional m_seen_in; bool m_last_end_seen = false; }; @@ -60,6 +66,19 @@ Pokemon::StoryGame with_autosave_sightings( Pokemon::StoryGame game, const Pokemon::StoryRows& rows, AutosaveSightings& sightings ); +// `game` whose reload fails as "save_moved" while `sightings` has seen an +// autosave in the checkpoint under way: the game's latest save is then +// past that checkpoint's start, and a retry from it would start elsewhere +// (console B 2026-11-16: 03.04 autosaved in pokedex_app, failed after it, +// and the next 03.04 walked from outside the Center). +Pokemon::StoryGame reloading_only_to_start( + const Pokemon::StoryGame& game, const AutosaveSightings& sightings +); + +// After `checkpoint` failed: logs "[Save] : the game autosaved +// in before the run failed" when `sightings` saw an autosave in it. +void log_moved_save(PlzaBackend& backend, const AutosaveSightings& sightings, std::string_view checkpoint); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 03102c1329..44e461032f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -892,7 +892,7 @@ Outcome load_checkpoint_start(const Pokemon::StoryGame& game, PlzaBack case StartCheck::UNCHECKED: break; } - backend.log(std::format("[Checkpoint] {}: off the station platform, as at its start", row.id)); + backend.log(std::format("[Checkpoint] {}: off the station platform; START UNCHECKED: nothing reads this row's own start", row.id)); return Pokemon::outcome_ok(); } @@ -950,7 +950,8 @@ Pokemon::SegmentReport run_plza_segments( std::span rows, size_t attempts_per_checkpoint, PlzaBackend& backend, Pokemon::RunState& state, AutosaveSightings& sightings ){ - Pokemon::StoryEngine engine(game, backend); + const Pokemon::StoryGame retry_game = reloading_only_to_start(game, sightings); + Pokemon::StoryEngine engine(retry_game, backend); Pokemon::SegmentReport total; for (size_t index = 0; index < rows.size(); index++){ const Pokemon::StoryCheckpoint& row = rows[index]; @@ -985,6 +986,7 @@ Pokemon::SegmentReport run_plza_segments( ); add_segment(part, total); if (!part.completed){ + log_moved_save(backend, sightings, row.id); return total; } } @@ -993,7 +995,6 @@ Pokemon::SegmentReport run_plza_segments( } - } // namespace PokemonLZA } // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 36f7b16d5d..51dd55ff44 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -148,6 +148,9 @@ Pokemon::Outcome load_checkpoint_start( // the row's start is loaded if the row before's autosave was seen. // With no autosave seen, a reload would rewind to an older save: the run // fails there as "no_start_save". A failed load fails the run too. +// A row that saw an autosave and then failed is not retried: the save +// moved past its start, so its reload fails as "save_moved", and the run +// logs "[Save] : the game autosaved in before the run failed". Pokemon::SegmentReport run_plza_segments( const Pokemon::StoryGame& game, const Pokemon::StoryRows& story, std::span rows, size_t attempts_per_checkpoint, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp index a773107dea..f3bda15773 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -1077,7 +1077,7 @@ const LoadCase LOAD_CASES[] = { .input = {.checkpoint = "01.02", .looks = {CUTSCENE}}, .expectation = { .verdict = "done", .inputs = "press HOME, wait 300ms, wait 300ms, wait 300ms, wait 300ms", - .line = "[Checkpoint] 01.02: off the station platform, as at its start", + .line = "[Checkpoint] 01.02: off the station platform; START UNCHECKED: nothing reads this row's own start", }, }, { @@ -1130,7 +1130,7 @@ UnitTestResult check_load(const LoadCase& test, CancellableScope& scope){ } -// Two rows: "01.01" waits for the platform, "01.02" runs to a choice. +// Two rows: "01.01" waits for the platform, "01.02" runs `second_action`. // 01.01's autosave shows when a look has both the platform and the badge; // its platform wait then needs two platform looks without the badge. struct ChainCase{ @@ -1138,6 +1138,8 @@ struct ChainCase{ struct Input{ std::set> reload_always; std::vector> looks; + std::string second_action = "text_to_choice"; + size_t attempts = 1; }; Input input; struct Expectation{ @@ -1145,6 +1147,8 @@ struct ChainCase{ std::string verdict; // How many times the reload pressed HOME. size_t reloads = 0; + // A log line the run wrote, if any is checked. + std::string line = {}; }; Expectation expectation; }; @@ -1189,6 +1193,22 @@ const ChainCase CHAIN_CASES[] = { .input = {.reload_always = {"01.02"}, .looks = {PLATFORM_SAVING, PLATFORM}}, .expectation = {.verdict = "failed at 01.02 chain: older_save", .reloads = 1}, }, + { + // console B, 2026-11-16: 03.04 autosaved in pokedex_app and failed + // in the step after it; the next run's 03.04 loaded that save, + // outside the Center, and its walk to the Center found no prompt. + .name = "a run that autosaved and then failed does not reload: the save moved past its start", + .input = { + .reload_always = {}, + .looks = {PLATFORM_SAVING, PLATFORM, PLATFORM, AUTOSAVE, CUTSCENE}, + .second_action = "wait_for_platform", + .attempts = 2, + }, + .expectation = { + .verdict = "failed at 01.02 : reload_failed", .reloads = 0, + .line = "[Save] 01.02: the game autosaved in wait_for_platform before the run failed: the latest save is past 01.02's start", + }, + }, }; UnitTestResult check_chain(const ChainCase& test, CancellableScope& scope){ @@ -1198,9 +1218,9 @@ UnitTestResult check_chain(const ChainCase& test, CancellableScope& scope){ const Pokemon::StoryGame game = game_with_reload(story, sightings); Pokemon::FakeStoryBackend backend({.looks = test.input.looks}, scope); Pokemon::RunState state; - const std::vector rows{one_step_row("01.01", "wait_for_platform"), one_step_row("01.02", "text_to_choice")}; + const std::vector rows{one_step_row("01.01", "wait_for_platform"), one_step_row("01.02", test.input.second_action)}; const Pokemon::SegmentReport report = run_plza_segments( - game, story, rows, /*attempts_per_checkpoint=*/1, backend, state, sightings + game, story, rows, test.input.attempts, backend, state, sightings ); const std::string verdict = report.completed ? "done" @@ -1212,7 +1232,15 @@ UnitTestResult check_chain(const ChainCase& test, CancellableScope& scope){ if (reloads != test.expectation.reloads){ return std::format("expected {} reloads, got {}: {}", test.expectation.reloads, reloads, joined(backend.inputs(), ", ")); } - return true; + if (test.expectation.line.empty()){ + return true; + } + for (const std::string& line : backend.lines()){ + if (line == test.expectation.line){ + return true; + } + } + return std::format("expected the line \"{}\" in:\n{}", test.expectation.line, joined(backend.lines(), "\n")); } From d9180d994ee4fa492688a345a99ae62c6639893e Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 07:11:27 -0800 Subject: [PATCH 2/2] PLZA autosaves: a checkpoint saves only on an autosave in its last step A checkpoint's autosave is the next checkpoint's start, so an autosave seen before the last step no longer counts as the checkpoint's save: the run logs "[Save] : the game autosaved in , before " and the next row has no start save. Plans name the step the badge shows in (execution "autosave_step", required with "save": "autosave"), and the plan fails to load when that step is not the checkpoint's last, so a mid-checkpoint autosave fails in the unit tests, not on the console (console B, 2026-11-16: 03.07 reloaded 03.06's autosave from before the run to Wild Zone 1's gate). --- .../PokemonLZA_AutoStoryAutosaves.cpp | 57 ++++++++- .../AutoStory/PokemonLZA_AutoStoryAutosaves.h | 40 +++++-- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 1 - .../PokemonLZA_AutoStoryGame_Tests.cpp | 110 +++++++++++++++++- .../PokemonLZA_AutoStoryStoryFiles.cpp | 26 ++++- .../AutoStory/StoryData/plza-01.00.plan.json | 3 +- .../AutoStory/StoryData/plza-02.06.plan.json | 3 +- .../AutoStory/StoryData/plza-03.02.plan.json | 3 +- .../AutoStory/StoryData/plza-03.03.plan.json | 3 +- .../AutoStory/StoryData/plza-03.04.plan.json | 3 +- .../AutoStory/StoryData/plza-03.05.plan.json | 3 +- .../AutoStory/StoryData/plza-03.06.plan.json | 3 +- .../AutoStory/StoryData/plza-03.07.plan.json | 3 +- .../AutoStory/StoryData/plza-03.08.plan.json | 3 +- .../AutoStory/StoryData/plza-03.10.plan.json | 3 +- 15 files changed, 234 insertions(+), 30 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp index 685815c73a..fd25618c86 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp @@ -27,6 +27,16 @@ namespace{ // the same autosave. constexpr Milliseconds AUTOSAVE_DEBOUNCE = 5000ms; +// The step after the step named `step` in `row`, if there is one. +std::optional step_after(const Pokemon::StoryCheckpoint& row, std::string_view step){ + for (size_t index = 0; index + 1 < row.steps.size(); index++){ + if (row.steps[index].name == step){ + return row.steps[index + 1].name; + } + } + return std::nullopt; +} + // `inner` with every look noted in `sightings` as taken in step `step`. // code-health: allow public_methods -- forwards every call of the engine's backend to the wrapped one unchanged class SightingBackend : public PlzaBackend{ @@ -86,6 +96,7 @@ void AutosaveSightings::restart(){ m_origin.reset(); m_last_badge.reset(); m_seen_in.reset(); + m_last_seen_in.reset(); } void AutosaveSightings::note(PlzaBackend& backend, const Pokemon::Observation& look, std::string_view step){ @@ -100,16 +111,44 @@ void AutosaveSightings::note(PlzaBackend& backend, const Pokemon::Observation(look.when - *m_origin).count() / 1000; backend.log(std::format("[PLZA] autosave badge at {:.1f}s in {}", seconds, step)); } } -bool AutosaveSightings::finish(){ - m_last_end_seen = m_seen_in.has_value(); +std::optional AutosaveSightings::finish(std::string_view last_step){ + std::optional seen_in = std::move(m_last_seen_in); + m_last_end_seen = seen_in == last_step; restart(); - return m_last_end_seen; + return seen_in; +} + + +std::optional autosave_step_error( + const Pokemon::StoryCheckpoint& row, Pokemon::StoryRowSave save, std::optional autosave_step +){ + if (!autosave_step){ + if (save == Pokemon::StoryRowSave::AUTOSAVE){ + return std::format("{}: \"save\": \"autosave\" needs \"autosave_step\", the step a run log showed the badge in", row.id); + } + return std::nullopt; + } + bool found = false; + for (const Pokemon::StoryStep& step : row.steps){ + found = found || step.name == *autosave_step; + } + if (!found){ + return std::format("{}: autosave_step {} is not one of its steps", row.id, *autosave_step); + } + if (const std::optional next = step_after(row, *autosave_step)){ + return std::format( + "{}: the game autosaves in {}, before {}: the next checkpoint reloads that save, so end {} at {} and start the next one with {}", + row.id, *autosave_step, *next, row.id, *autosave_step, *next + ); + } + return std::nullopt; } @@ -125,10 +164,20 @@ Pokemon::StoryGame with_autosave_sightings( }; } game.save = [rows, &sightings](Pokemon::StoryBackend& backend, const Pokemon::StoryCheckpoint& checkpoint){ - if (sightings.finish()){ + const std::string_view last_step = checkpoint.steps.empty() ? std::string_view() : std::string_view(checkpoint.steps.back().name); + const std::optional seen_in = sightings.finish(last_step); + if (sightings.last_end_seen()){ backend.log(std::format("[Save] {}: the game autosaved (seen)", checkpoint.id)); return Pokemon::outcome_ok(); } + if (seen_in){ + const std::string_view next = step_after(checkpoint, *seen_in).value_or(last_step); + backend.log(std::format( + "[Save] {}: the game autosaved in {}, before {}: not saved, a reload would skip {}", + checkpoint.id, *seen_in, next, next + )); + return Pokemon::outcome_not_saved("autosaved before the last step"); + } if (rows.unverified_autosaves.contains(checkpoint.id)){ return Pokemon::outcome_not_saved("save unverified"); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h index c77a54633a..8baa2c0086 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h @@ -4,8 +4,12 @@ * * The game's own autosaves, as a run sees them: the badge (a pencil and * "Saving...", top right) on any look of any step of a checkpoint. A - * checkpoint whose badge showed is saved for that run; a chained run - * reloads only onto such a save (run_plza_segments()). + * checkpoint whose badge showed in its last step is saved for that run; a + * chained run reloads only onto such a save (run_plza_segments()). The + * next checkpoint starts where that save reloads, so a checkpoint ends on + * its autosave: the plan names the step it shows in ("autosave_step"), + * and the plan check (autosave_step_error()) fails a checkpoint with steps + * after it. * */ @@ -18,6 +22,7 @@ #include "Common/Cpp/Time.h" #include "Pokemon/AutoStory/Data/Pokemon_StoryRowExecution.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryGame.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" #include "PokemonLZA_AutoStoryBackend.h" namespace PokemonAutomation{ @@ -27,8 +32,11 @@ namespace PokemonLZA{ // The game's autosave badges (AUTOSAVE_READING) a run sees in the // checkpoint under way. The story game made with it notes every look of -// every step, and its save counts a checkpoint saved when the badge showed -// during it: the save is verified for this run. +// every step, and its save counts a checkpoint saved when the badge last +// showed in its last step: the save is verified for this run. A badge in +// an earlier step saves the game short of the checkpoint's end, where a +// reload would skip the steps after it (console B, 2026-11-16: 03.07 +// reloaded 03.06's autosave from before the run to Wild Zone 1's gate). class AutosaveSightings{ public: // A checkpoint starts: no badge seen in it yet. @@ -38,10 +46,12 @@ class AutosaveSightings{ // "[PLZA] autosave badge at s in ", t from the checkpoint's // first look. void note(PlzaBackend& backend, const Pokemon::Observation& look, std::string_view step); - // The checkpoint ends: whether a badge showed during it, kept for + // The checkpoint ends with step `last_step`: the step the badge last + // showed in, if it did. Whether that is `last_step` is kept for // last_end_seen(). - bool finish(); - // Whether the badge showed during the checkpoint that last ended. + std::optional finish(std::string_view last_step); + // Whether the badge showed in the last step of the checkpoint that + // last ended. bool last_end_seen() const{ return m_last_end_seen; } @@ -55,13 +65,25 @@ class AutosaveSightings{ std::optional m_origin; std::optional m_last_badge; std::optional m_seen_in; + std::optional m_last_seen_in; bool m_last_end_seen = false; }; +// Why `row` cannot end on the game's autosave in its step `autosave_step` +// (the plan's "autosave_step"; `save` is the plan's "save"), none when it +// can: the step must be one of its steps and its last, and an "autosave" +// row must name it. Checked when the plan loads, so a checkpoint that +// would start the next one mid-way fails there, not on the console. +std::optional autosave_step_error( + const Pokemon::StoryCheckpoint& row, Pokemon::StoryRowSave save, std::optional autosave_step +); + // `game` with every action's looks noted in `sightings`, which must // outlive it, and its save counting the autosave `sightings` saw in the -// checkpoint ("[Save] : the game autosaved (seen)"); else nothing -// saved (Pokemon::NOT_SAVED), worded by the plan's "save" in `rows`. +// checkpoint's last step ("[Save] : the game autosaved (seen)"); one +// seen only before it saves nothing ("[Save] : the game autosaved in +// , before "); else nothing saved (Pokemon::NOT_SAVED), +// worded by the plan's "save" in `rows`. Pokemon::StoryGame with_autosave_sightings( Pokemon::StoryGame game, const Pokemon::StoryRows& rows, AutosaveSightings& sightings ); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index a81550c236..ebb6f8c893 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -995,7 +995,6 @@ Pokemon::SegmentReport run_plza_segments( return total; } - } // namespace PokemonLZA } // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp index 6ded2a6dc9..d920e2f87d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -247,6 +247,75 @@ UnitTestResult check_lint(const LintCase& test){ return true; } +// A checkpoint "03.06" of `steps`, the plan's "save" `save` and its +// "autosave_step" `autosave_step`. +struct AutosaveStepCase{ + std::string name; + struct Input{ + std::vector steps; + Pokemon::StoryRowSave save = Pokemon::StoryRowSave::NONE; + std::optional autosave_step = std::nullopt; + }; + Input input; + struct Expectation{ + // The error, empty for none. + std::string error; + }; + Expectation expectation; +}; + +const AutosaveStepCase AUTOSAVE_STEP_CASES[] = { + { + // console B, 2026-11-16: 03.06 autosaved in wild_zones_tutorial and + // went on to the gate; 03.07 reloaded that save and threw outside + // Wild Zone 1. + .name = "an autosave before steps that move the player fails", + .input = { + .steps = {"wild_zones_tutorial", "to_zone_1_gate", "enter_zone_1"}, + .autosave_step = "wild_zones_tutorial", + }, + .expectation = {.error = + "03.06: the game autosaves in wild_zones_tutorial, before to_zone_1_gate: the next checkpoint reloads " + "that save, so end 03.06 at wild_zones_tutorial and start the next one with to_zone_1_gate" + }, + }, + { + .name = "an autosave in the last step passes", + .input = { + .steps = {"toward_zone_1_gate", "wild_zones_tutorial"}, + .save = Pokemon::StoryRowSave::AUTOSAVE, + .autosave_step = "wild_zones_tutorial", + }, + .expectation = {.error = ""}, + }, + { + .name = "a plan autosave without its step fails", + .input = {.steps = {"wild_zones_tutorial"}, .save = Pokemon::StoryRowSave::AUTOSAVE}, + .expectation = {.error = "03.06: \"save\": \"autosave\" needs \"autosave_step\", the step a run log showed the badge in"}, + }, + { + .name = "an autosave step that is not a step fails", + .input = {.steps = {"wild_zones_tutorial"}, .autosave_step = "enter_zone_1"}, + .expectation = {.error = "03.06: autosave_step enter_zone_1 is not one of its steps"}, + }, +}; + +UnitTestResult check_autosave_step(const AutosaveStepCase& test){ + StoryCheckpoint checkpoint; + checkpoint.id = "03.06"; + checkpoint.title = "Test"; + for (const std::string& name : test.input.steps){ + checkpoint.steps.push_back(StoryStep{.kind = Pokemon::StoryStepKind::GAME, .name = name, .why = "", .action = "walk", .args = {}}); + } + const std::optional error = autosave_step_error(checkpoint, test.input.save, test.input.autosave_step); + const std::string got = error.value_or(""); + if (got != test.expectation.error){ + return std::format("expected \"{}\", got \"{}\"", test.expectation.error, got); + } + return true; +} + + // A look with `events` and the readings named in `readings`, `at` after // the scripts' common start. @@ -1138,6 +1207,9 @@ struct ChainCase{ struct Input{ std::set> reload_always; std::vector> looks; + // The actions of 01.01's steps; a repeated one's step is named + // "_again". + std::vector first_actions = {"wait_for_platform"}; std::string second_action = "text_to_choice"; size_t attempts = 1; }; @@ -1193,6 +1265,21 @@ const ChainCase CHAIN_CASES[] = { .input = {.reload_always = {"01.02"}, .looks = {PLATFORM_SAVING, PLATFORM}}, .expectation = {.verdict = "failed at 01.02 chain: older_save", .reloads = 1}, }, + { + // console B, 2026-11-16: 03.06 autosaved in wild_zones_tutorial and + // walked on to Wild Zone 1's gate; 03.07 reloaded that save, outside + // the gate, and threw Poke Balls there. + .name = "an autosave before the last step does not save the row: no save to reload the next from", + .input = { + .reload_always = {"01.02"}, + .looks = {PLATFORM_SAVING, PLATFORM, PLATFORM, PLATFORM, PLATFORM}, + .first_actions = {"wait_for_platform", "wait_for_platform"}, + }, + .expectation = { + .verdict = "failed at 01.02 chain: no_start_save", .reloads = 0, + .line = "[Save] 01.01: the game autosaved in wait_for_platform, before wait_for_platform_again: not saved, a reload would skip wait_for_platform_again", + }, + }, { // console B, 2026-11-16: 03.04 autosaved in pokedex_app and failed // in the step after it; the next run's 03.04 loaded that save, @@ -1218,7 +1305,12 @@ UnitTestResult check_chain(const ChainCase& test, CancellableScope& scope){ const Pokemon::StoryGame game = game_with_reload(story, sightings); Pokemon::FakeStoryBackend backend({.looks = test.input.looks}, scope); Pokemon::RunState state; - const std::vector rows{one_step_row("01.01", "wait_for_platform"), one_step_row("01.02", test.input.second_action)}; + StoryCheckpoint first = one_step_row("01.01", test.input.first_actions[0]); + for (size_t index = 1; index < test.input.first_actions.size(); index++){ + const std::string& action = test.input.first_actions[index]; + first.steps.push_back(StoryStep{.kind = Pokemon::StoryStepKind::GAME, .name = std::format("{}_again", action), .why = "", .action = action, .args = {}}); + } + const std::vector rows{first, one_step_row("01.02", test.input.second_action)}; const Pokemon::SegmentReport report = run_plza_segments( game, story, rows, test.input.attempts, backend, state, sightings ); @@ -1283,6 +1375,19 @@ class RunTest : public UnitTest{ RunCase m_case; }; +class AutosaveStepTest : public UnitTest{ +public: + explicit AutosaveStepTest(AutosaveStepCase test_case) + : UnitTest(std::format("PokemonLZA::AutoStoryGame autosave step - {}", test_case.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return check_autosave_step(m_case); + } +private: + AutosaveStepCase m_case; +}; + class LoadTest : public UnitTest{ public: explicit LoadTest(LoadCase test_case) @@ -1319,6 +1424,9 @@ void add_tests_AutoStoryGame(UnitTestDatabase& database){ for (const LintCase& test : LINT_CASES){ database.add(test); } + for (const AutosaveStepCase& test : AUTOSAVE_STEP_CASES){ + database.add(test); + } for (const RunCase& test : RUN_CASES){ database.add(test); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp index a4a2106df8..4535199fdb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp @@ -4,9 +4,12 @@ * */ +#include +#include #include #include #include +#include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Json/JsonValue.h" #include "Pokemon/AutoStory/Data/Pokemon_AuthoredCheckpointJson.h" #include "PokemonLZA_AutoStoryGame.h" @@ -24,21 +27,34 @@ using Pokemon::StoryRowExecution; namespace{ // A checkpoint file's checkpoint and its shared execution fields. `source` -// names the file in parse errors. +// names the file in parse errors. Throws ParseException too when the +// checkpoint does not end on the autosave its "autosave_step" names +// (autosave_step_error()). StoryFileRow read_checkpoint_file(std::string_view text, std::string_view source){ StoryRowExecution read; - const Pokemon::ExecutionReader read_execution = [&read](const JsonObject& execution, std::string_view where){ - read = Pokemon::read_story_row_execution(execution, where, /*game_fields=*/{}); + std::optional autosave_step; + const Pokemon::ExecutionReader read_execution = [&read, &autosave_step](const JsonObject& execution, std::string_view where){ + read = Pokemon::read_story_row_execution(execution, where, /*game_fields=*/{"autosave_step"}); + if (const JsonValue* step = execution.get_value("autosave_step")){ + const std::string* name = step->to_string(); + if (name == nullptr){ + throw ParseException(std::format("{}: autosave_step is a step's id", where)); + } + autosave_step = *name; + } }; StoryCheckpoint checkpoint = Pokemon::read_authored_checkpoint( parse_json(std::string(text)), "plza", source, read_execution, plza_story_specs() ); + if (const std::optional error = autosave_step_error(checkpoint, read.save, autosave_step)){ + throw ParseException(std::format("{}: {}", source, *error)); + } return {.checkpoint = std::move(checkpoint), .execution = read}; } // How the shared loader reads a PLZA checkpoint file: against -// plza_story_specs(), its execution with only the shared "save" and -// "reload_when_chained". 01.00 (story_row_starts_without_save()) has no +// plza_story_specs(), its execution with the shared "save" and +// "reload_when_chained" and PLZA's "autosave_step". 01.00 (story_row_starts_without_save()) has no // save to reload. const Pokemon::StoryFileReader& plza_story_file_reader(){ static const Pokemon::StoryFileReader reader{ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json index 43033888a4..f5187a4cb7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json @@ -33,6 +33,7 @@ } }, "execution": { - "save": "autosave" + "save": "autosave", + "autosave_step": "opening" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json index f953f4c022..1a5be4dca5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json @@ -47,6 +47,7 @@ } }, "execution": { - "save": "autosave" + "save": "autosave", + "autosave_step": "wake_up" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json index 959508c7ae..27fb9ab354 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json @@ -31,6 +31,7 @@ } }, "execution": { - "save": "autosave" + "save": "autosave", + "autosave_step": "leave_hotel_z" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.03.plan.json index 79618cb7b6..8f6096293f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.03.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.03.plan.json @@ -66,6 +66,7 @@ } }, "execution": { - "save": "autosave" + "save": "autosave", + "autosave_step": "south_boulevard" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json index f6465a01dd..b12061ad91 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json @@ -37,6 +37,7 @@ }, "execution": { "reload_when_chained": "always", - "save": "autosave" + "save": "autosave", + "autosave_step": "pokedex_app" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json index b70f662047..ea33501939 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json @@ -37,6 +37,7 @@ } }, "execution": { - "save": "autosave" + "save": "autosave", + "autosave_step": "heal_party" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json index 8f10ebd082..76c836517d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json @@ -49,6 +49,7 @@ } }, "execution": { - "save": "autosave" + "save": "autosave", + "autosave_step": "wild_zones_tutorial" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json index f1ad0f34a8..0adaff220f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json @@ -50,6 +50,7 @@ } }, "execution": { - "save": "autosave" + "save": "autosave", + "autosave_step": "after_catches" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json index 6e24281532..6fce99c9e8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json @@ -21,6 +21,7 @@ } }, "execution": { - "save": "autosave" + "save": "autosave", + "autosave_step": "catch_more_species" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json index 0ac58d0bf9..8a2b86e9e0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json @@ -56,6 +56,7 @@ } }, "execution": { - "save": "autosave" + "save": "autosave", + "autosave_step": "arrive_3f" } }