Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"<b>Rewinds to the Backup Save:</b><br>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 =
"<b>Developer: skip forced reloads:</b><br>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
Expand Down Expand Up @@ -204,7 +207,7 @@
} // namespace


AutoStory::AutoStory()

Check warning on line 210 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::AutoStory::AutoStory(): function_lines=50 (advisory above 25, limit 50)
: RANGE("Checkpoints", checkpoint_database())
, GAME_LANGUAGE(
"<b>Game Language:</b><br>01.00 picks it on the new game's language list.",
Expand Down Expand Up @@ -233,6 +236,7 @@
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,
Expand All @@ -248,12 +252,13 @@
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);
}

void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){

Check warning on line 261 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::AutoStory::program( SingleSwitchProgramEnvironment & env , ProControllerContext & context): function_lines=48 (advisory above 25, limit 50)
if (CAPTURE_INTRO_SCREENS){
require_player(env.console, context, BUTTON_L);
capture_intro_screens(env.console, context, PLAYER_LOOK);
Expand All @@ -275,7 +280,10 @@
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])){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class AutoStory : public SingleSwitchProgramInstance{
SimpleIntegerOption<uint8_t> ATTEMPTS_PER_CHECKPOINT;
SimpleIntegerOption<uint8_t> REWINDS_TO_BACKUP;
BooleanCheckBoxOption LOAD_SAVE_FIRST;
BooleanCheckBoxOption SKIP_FORCED_RELOADS;
BattleAIOption BATTLE_AI;
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
EventNotificationsOption NOTIFICATIONS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ SegmentReport run_plza_with_rewinds(
size_t from = plan.first;
for (size_t rewinds = 0;; rewinds++){
const std::vector<StoryCheckpoint> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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<const Pokemon::StoryCheckpoint> rows;
size_t first = 0;
size_t last = 0;
size_t attempts_per_checkpoint = 1;
SegmentRunOptions segments = {};
std::span<const CheckpointStart> starts = {};
size_t max_rewinds = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ UnitTestResult check_rewind(const RewindCase& test, CancellableScope& scope){
const std::vector<StoryCheckpoint> rows = story_rows();
const std::vector<CheckpointStart> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PokemonLZA AutoStory - Story game

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=978 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -881,8 +881,9 @@
// Chain::ON or RELOAD into `row`, `seen` whether the row before's
// autosave showed; a failure when only a reload would do and there is no
// save to load. Logs the decision.
std::variant<Chain, Outcome> decide_chain(

Check warning on line 884 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::decide_chain( PlzaBackend & backend , const Pokemon :: StoryRows & story , SegmentRunOptions :: ForcedReloads forced_reloads , const Pokemon :: StoryCheckpoint & row , bool seen): function_lines=40 (advisory above 25, limit 50)
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));
Expand All @@ -891,6 +892,10 @@
));
};
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");
}
Expand Down Expand Up @@ -921,7 +926,7 @@

Pokemon::SegmentReport run_plza_segments(
const Pokemon::StoryGame<ZonePose>& game, const Pokemon::StoryRows& story,
std::span<const Pokemon::StoryCheckpoint> rows, size_t attempts_per_checkpoint,
std::span<const Pokemon::StoryCheckpoint> rows, const SegmentRunOptions& options,
PlzaBackend& backend, Pokemon::RunState& state, AutosaveSightings& sightings
){
const Pokemon::StoryGame<ZonePose> retry_game = reloading_only_to_start(game, sightings);
Expand All @@ -939,7 +944,7 @@
return total;
};
start_saved = sightings.last_end_seen();
const std::variant<Chain, Outcome> chain = decide_chain(backend, story, row, start_saved);
const std::variant<Chain, Outcome> chain = decide_chain(backend, story, options.forced_reloads, row, start_saved);
if (const Outcome* failure = std::get_if<Outcome>(&chain)){
return fail(*failure);
}
Expand All @@ -951,12 +956,12 @@
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<const Pokemon::StoryCheckpoint>(&row, 1), start_saved ? attempts_per_checkpoint : 1, state
"PLZA", std::span<const Pokemon::StoryCheckpoint>(&row, 1), start_saved ? options.attempts_per_checkpoint : 1, state
);
add_segment(part, total);
if (!part.completed){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PokemonLZA AutoStory - Story game

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=8 (advisory above 6, limit 8)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -140,12 +140,28 @@
const Pokemon::StoryGame<Pokemon::ZonePose>& 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] <id>: 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.
Expand All @@ -156,7 +172,7 @@
// logs "[Save] <id>: the game autosaved in <step> before the run failed".
Pokemon::SegmentReport run_plza_segments(
const Pokemon::StoryGame<Pokemon::ZonePose>& game, const Pokemon::StoryRows& story,
std::span<const Pokemon::StoryCheckpoint> rows, size_t attempts_per_checkpoint,
std::span<const Pokemon::StoryCheckpoint> rows, const SegmentRunOptions& options,
PlzaBackend& backend, Pokemon::RunState& state, AutosaveSightings& sightings
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PokemonLZA AutoStory - Story game Tests

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (bypass)

<file>: file_lines=1587 over limit 1000, bypassed by the tag at line 11: "one table per story game behavior, sharing the scripted looks above them"
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -1259,6 +1259,7 @@
std::vector<std::string> 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{
Expand Down Expand Up @@ -1307,6 +1308,24 @@
.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}},
Expand Down Expand Up @@ -1345,7 +1364,7 @@
},
};

UnitTestResult check_chain(const ChainCase& test, CancellableScope& scope){

Check warning on line 1367 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonLZA::check_chain( const ChainCase & test , CancellableScope & scope): function_lines=37 (advisory above 25, limit 50)
Pokemon::StoryRows story;
story.reload_always = test.input.reload_always;
AutosaveSightings sightings;
Expand All @@ -1359,7 +1378,8 @@
}
const std::vector<StoryCheckpoint> 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"
Expand Down
Loading