diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index c1ccc08e35..ec0b25eee3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -123,6 +123,9 @@ constexpr std::string_view REWINDS_TO_BACKUP_LABEL = "Rewinds to the Backup Save:
A checkpoint that fails after the game autosaved in it cannot reload its start. " "The run then closes the game, opens the backup save's card at the title (Up + B + X), and when the card matches a checkpoint's start " "(\"start_signature\" in its plan), loads it and plays on from that checkpoint, up to this many times. An unknown backup is never loaded."; +constexpr std::string_view SKIP_FORCED_RELOADS_LABEL = + "Developer: skip forced reloads:
A chained run does not reload the start save of a checkpoint whose plan says it always reloads " + "(reload_when_chained \"always\"): it goes on from the live screen, to test whether that reload is needed. Each skipped reload is logged."; // Loads the latest save for `row` with `game`: a run that starts after // the new game starts from it (01.01: the platform autosave), not from @@ -233,6 +236,7 @@ AutoStory::AutoStory() LockMode::LOCK_WHILE_RUNNING, true ) + , SKIP_FORCED_RELOADS(std::string(SKIP_FORCED_RELOADS_LABEL), LockMode::LOCK_WHILE_RUNNING, /*default_value=*/false) , GO_HOME_WHEN_DONE(false) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, @@ -248,6 +252,7 @@ AutoStory::AutoStory() PA_ADD_OPTION(ATTEMPTS_PER_CHECKPOINT); PA_ADD_OPTION(REWINDS_TO_BACKUP); PA_ADD_OPTION(LOAD_SAVE_FIRST); + PA_ADD_OPTION(SKIP_FORCED_RELOADS); PA_ADD_OPTION(BATTLE_AI); PA_ADD_OPTION(GO_HOME_WHEN_DONE); PA_ADD_OPTION(NOTIFICATIONS); @@ -275,7 +280,10 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex RunState state; RewindPlan plan{ - .rows = rows, .first = first, .last = last, .attempts_per_checkpoint = ATTEMPTS_PER_CHECKPOINT, + .rows = rows, .first = first, .last = last, .segments = { + .attempts_per_checkpoint = ATTEMPTS_PER_CHECKPOINT, + .forced_reloads = SKIP_FORCED_RELOADS ? SegmentRunOptions::ForcedReloads::SKIP : SegmentRunOptions::ForcedReloads::KEEP, + }, .starts = builtin_checkpoint_starts(), .max_rewinds = REWINDS_TO_BACKUP, }; if (!story_row_starts_without_save(rows[first])){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index 004efc98f1..a976d57d01 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -52,6 +52,7 @@ class AutoStory : public SingleSwitchProgramInstance{ SimpleIntegerOption ATTEMPTS_PER_CHECKPOINT; SimpleIntegerOption REWINDS_TO_BACKUP; BooleanCheckBoxOption LOAD_SAVE_FIRST; + BooleanCheckBoxOption SKIP_FORCED_RELOADS; BattleAIOption BATTLE_AI; GoHomeWhenDoneOption GO_HOME_WHEN_DONE; EventNotificationsOption NOTIFICATIONS; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups.cpp index 35d49f4317..64169fd18d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups.cpp @@ -131,7 +131,7 @@ SegmentReport run_plza_with_rewinds( size_t from = plan.first; for (size_t rewinds = 0;; rewinds++){ const std::vector run_rows = Pokemon::story_run_rows(rows, from, plan.last); - add_part(run_plza_segments(game, story, run_rows, plan.attempts_per_checkpoint, backend, state, sightings), total); + add_part(run_plza_segments(game, story, run_rows, plan.segments, backend, state, sightings), total); if (total.completed){ return total; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups.h index 872be20ab3..91c2bc7479 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups.h @@ -26,6 +26,7 @@ #include "Pokemon/AutoStory/Types/Pokemon_StorySegmentTypes.h" #include "PokemonLZA_AutoStoryAutosaves.h" #include "PokemonLZA_AutoStoryBackend.h" +#include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryStarts.h" namespace PokemonAutomation{ @@ -55,14 +56,14 @@ struct BackupSave{ }; // A run that may rewind: the rows `first` to `last` of `rows` (all the -// story's checkpoints), `attempts_per_checkpoint` each, and up to +// story's checkpoints), each run as `segments` says, and up to // `max_rewinds` rewinds to the backup saves `starts` name (a backup // card's StartSignature::registered). struct RewindPlan{ std::span rows; size_t first = 0; size_t last = 0; - size_t attempts_per_checkpoint = 1; + SegmentRunOptions segments = {}; std::span starts = {}; size_t max_rewinds = 0; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups_Tests.cpp index 88496ac0d0..6b5879a6c2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackups_Tests.cpp @@ -309,7 +309,7 @@ UnitTestResult check_rewind(const RewindCase& test, CancellableScope& scope){ const std::vector rows = story_rows(); const std::vector starts{{.checkpoint = "03.06", .signature = {.registered = 1}}}; const RewindPlan plan{ - .rows = rows, .first = RUN_FROM, .last = RUN_TO, .attempts_per_checkpoint = 1, + .rows = rows, .first = RUN_FROM, .last = RUN_TO, .segments = {.attempts_per_checkpoint = 1}, .starts = starts, .max_rewinds = test.input.max_rewinds, }; const Pokemon::SegmentReport report = run_plza_with_rewinds(game, story, plan, backup, backend, sightings, state); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 2180b1cde8..22d3ed8a4f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -882,7 +882,8 @@ enum class Chain{ // autosave showed; a failure when only a reload would do and there is no // save to load. Logs the decision. std::variant decide_chain( - PlzaBackend& backend, const Pokemon::StoryRows& story, const Pokemon::StoryCheckpoint& row, bool seen + PlzaBackend& backend, const Pokemon::StoryRows& story, SegmentRunOptions::ForcedReloads forced_reloads, + const Pokemon::StoryCheckpoint& row, bool seen ){ const auto no_save = [&](std::string_view why){ backend.log(std::format("[Checkpoint] {}: no save at its start: {}", row.id, why)); @@ -891,6 +892,10 @@ std::variant decide_chain( )); }; if (story.reload_always.contains(row.id)){ + if (forced_reloads == SegmentRunOptions::ForcedReloads::SKIP){ + backend.log(std::format("[Checkpoint] {}: reload skipped (developer option)", row.id)); + return Chain::ON; + } if (!seen){ return no_save("it always reloads, and the autosave before it was not seen"); } @@ -921,7 +926,7 @@ std::variant decide_chain( Pokemon::SegmentReport run_plza_segments( const Pokemon::StoryGame& game, const Pokemon::StoryRows& story, - std::span rows, size_t attempts_per_checkpoint, + std::span rows, const SegmentRunOptions& options, PlzaBackend& backend, Pokemon::RunState& state, AutosaveSightings& sightings ){ const Pokemon::StoryGame retry_game = reloading_only_to_start(game, sightings); @@ -939,7 +944,7 @@ Pokemon::SegmentReport run_plza_segments( return total; }; start_saved = sightings.last_end_seen(); - const std::variant chain = decide_chain(backend, story, row, start_saved); + const std::variant chain = decide_chain(backend, story, options.forced_reloads, row, start_saved); if (const Outcome* failure = std::get_if(&chain)){ return fail(*failure); } @@ -951,12 +956,12 @@ Pokemon::SegmentReport run_plza_segments( state = Pokemon::RunState{}; } } - if (!start_saved && attempts_per_checkpoint > 1){ + if (!start_saved && options.attempts_per_checkpoint > 1){ backend.log(std::format("[Checkpoint] {}: no autosave seen at its start, so no reload if it fails", row.id)); } sightings.restart(); const Pokemon::SegmentReport part = engine.run_segment( - "PLZA", std::span(&row, 1), start_saved ? attempts_per_checkpoint : 1, state + "PLZA", std::span(&row, 1), start_saved ? options.attempts_per_checkpoint : 1, state ); add_segment(part, total); if (!part.completed){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index c6d5c20dcb..98e3cd28dc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -140,12 +140,28 @@ Pokemon::Outcome load_checkpoint_start( const Pokemon::StoryGame& game, PlzaBackend& backend, const Pokemon::StoryCheckpoint& row ); +// How run_plza_segments() runs its rows. +struct SegmentRunOptions{ + // Whether a chained run keeps the reloads `story` forces with + // reload_when_chained "always". SKIP is a developer option: it tests + // whether a row needs its reload by running it from the live screen. + enum class ForcedReloads{ + KEEP, + SKIP, + }; + + size_t attempts_per_checkpoint = 1; + ForcedReloads forced_reloads = ForcedReloads::KEEP; +}; + // `rows` in order from the save the game is on, each with the story -// engine's run_segment() on `backend`, `attempts_per_checkpoint` each when a reload +// engine's run_segment() on `backend`, `options.attempts_per_checkpoint` each when a reload // returns to its start (the first row, or one after a row whose autosave // `sightings` saw), else once. Between two rows, the event "chain": // - a row `story` marks reload_when_chained "always" loads its start // (load_checkpoint_start()) when the row before's autosave was seen; +// with `options.forced_reloads` SKIP it runs on from the live screen instead, +// unchecked, and logs "[Checkpoint] : reload skipped (developer option)"; // - any other row runs on from the live screen when its start check // passes or cannot tell (logged as "start unchecked"); when it fails, // the row's start is loaded if the row before's autosave was seen. @@ -156,7 +172,7 @@ Pokemon::Outcome load_checkpoint_start( // 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, + std::span rows, const SegmentRunOptions& options, PlzaBackend& backend, Pokemon::RunState& state, AutosaveSightings& sightings ); 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 9da9eb2930..3b5ef3cd95 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -1259,6 +1259,7 @@ struct ChainCase{ std::vector first_actions = {"wait_for_platform"}; std::string second_action = "text_to_choice"; size_t attempts = 1; + SegmentRunOptions::ForcedReloads forced_reloads = SegmentRunOptions::ForcedReloads::KEEP; }; Input input; struct Expectation{ @@ -1307,6 +1308,24 @@ const ChainCase CHAIN_CASES[] = { .input = {.reload_always = {"01.02"}, .looks = {PLATFORM}}, .expectation = {.verdict = "failed at 01.02 chain: no_start_save", .reloads = 0}, }, + { + .name = "reload always, forced reloads skipped: on from the live screen", + .input = { + .reload_always = {"01.02"}, + .looks = {PLATFORM_SAVING, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}, + .forced_reloads = SegmentRunOptions::ForcedReloads::SKIP, + }, + .expectation = {.verdict = "done", .reloads = 0, .line = "[Checkpoint] 01.02: reload skipped (developer option)"}, + }, + { + .name = "reload always, forced reloads skipped, no autosave seen: on from the live screen", + .input = { + .reload_always = {"01.02"}, + .looks = {PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}, + .forced_reloads = SegmentRunOptions::ForcedReloads::SKIP, + }, + .expectation = {.verdict = "done", .reloads = 0, .line = "[Checkpoint] 01.02: reload skipped (developer option)"}, + }, { .name = "a reload onto an older save stops", .input = {.reload_always = {"01.02"}, .looks = {PLATFORM_SAVING, PLATFORM}}, @@ -1359,7 +1378,8 @@ UnitTestResult check_chain(const ChainCase& test, CancellableScope& scope){ } 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 + game, story, rows, {.attempts_per_checkpoint = test.input.attempts, .forced_reloads = test.input.forced_reloads}, + backend, state, sightings ); const std::string verdict = report.completed ? "done"