Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3d9bf94
Pokemon navigation: story steps, one table vocabulary for FRLG and BDSP
dayfine Nov 1, 2026
fd599b0
Merge nav/story-steps (3d9bf943d: shared story steps, with nav/shared…
dayfine Nov 1, 2026
bac9b9f
FRLG AutoStory: the story table on the shared story steps
dayfine Nov 1, 2026
474c2a0
Pokemon navigation: one retry policy for every story segment
dayfine Nov 1, 2026
ad62d91
Merge nav/story-steps (474c2a013: one retry policy) into frlg/story-s…
dayfine Nov 1, 2026
ebe8087
FRLG AutoStory: the shared retry options instead of its own attempts
dayfine Nov 1, 2026
f140830
Pokemon navigation: story executors hear of each attempt (begin_attempt)
dayfine Nov 1, 2026
86604db
Merge nav/story-steps (f1408301a: begin_attempt) into frlg/story-steps
dayfine Nov 1, 2026
a8611fa
Merge frlg/autostory-mvp (1a9002430: #119 merged) into frlg/story-steps
dayfine Nov 1, 2026
d48c063
FRLG AutoStory: run the story table end to end against a fake game
dayfine Nov 1, 2026
1a9acf3
Merge frlg/autostory-mvp (ad5d40885: the Mart cursor stays on the ite…
dayfine Nov 1, 2026
b60d993
FRLG AutoStory: simulate the Viridian Mart with its cursor staying on…
dayfine Nov 1, 2026
03298de
Pokemon navigation: a shared checks level for story steps (Thorough o…
dayfine Nov 1, 2026
c9d9d67
Merge nav/story-steps (03298de07: checks level) into frlg/story-steps
dayfine Nov 1, 2026
7b07480
FRLG AutoStory: hand the shared checks option to the story executor
dayfine Nov 1, 2026
fd32e9b
Merge frlg/autostory-mvp (44742ac63: Checks option, Mart and bag read…
dayfine Nov 1, 2026
daf7b8f
Pokemon navigation: story steps take the game's language, and never n…
dayfine Nov 1, 2026
1c2d007
Merge nav/story-steps (daf7b8faf: game language) into frlg/story-steps
dayfine Nov 1, 2026
530a5be
FRLG AutoStory: the game's language from the shared options; simulate…
dayfine Nov 1, 2026
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 @@ -66,6 +66,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){
Pokemon::add_tests_MapData(ret);
Pokemon::add_tests_StoryEvents(ret);
Pokemon::add_tests_StorySegments(ret);
Pokemon::add_tests_StorySteps(ret);
NintendoSwitch::add_tests_CheckOnlineDetector(ret);
NintendoSwitch::add_tests_FailedToConnectDetector(ret);
NintendoSwitch::add_tests_UpdatePopupDetector(ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void add_tests_LegWalker(UnitTestDatabase& database);
void add_tests_MapData(UnitTestDatabase& database);
void add_tests_StoryEvents(UnitTestDatabase& database);
void add_tests_StorySegments(UnitTestDatabase& database);
void add_tests_StorySteps(UnitTestDatabase& database);

// (name, JSON text) of each map in Pokemon/Navigation/TestMaps/, built into
// the program by pa_embed_text_files() (cmake/EmbedTextFiles.cmake).
Expand Down
69 changes: 65 additions & 4 deletions SerialPrograms/Source/Pokemon/Navigation/Pokemon_StorySegments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,67 @@ Outcome reload(RunState& state, SegmentHooks& hooks){
return outcome_ok();
}

// The policy's in-place recovery, after each event's own: the game's
// recover hook, if any, then the event again. Counts into `used`.
void add_policy_recoveries(Checkpoint& checkpoint, const SegmentPolicy& policy, SegmentHooks& hooks, size_t& used){
if (policy.recoveries_per_event == 0){
return;
}
for (Event& event : checkpoint.events){
Recovery recovery;
recovery.kind = RecoveryKind::REANCHOR;
recovery.attempts = policy.recoveries_per_event;
recovery.why = "the segment's policy: recover in place before reloading";
recovery.prepare = [&hooks, &used, name = event.name](RunState& state){
used++;
return hooks.recover ? hooks.recover(state, name) : outcome_ok();
};
event.recoveries.push_back(std::move(recovery));
}
}

std::string resets_text(size_t attempts){
if (attempts == 1){
return "one-shot";
}
return std::format("{} reset{}", attempts - 1, attempts == 2 ? "" : "s");
}

// One row to success, reloading and rebuilding after each failed attempt.
// Returns the last attempt's report, or the reload's failure.
// Returns the last attempt's report, or the reload's failure; `run` says
// how many attempts and recoveries it took.
CheckpointReport run_row(
RunState& state, const Segment& segment, CheckpointSpec& spec,
const SegmentPolicy& policy, SegmentHooks& hooks, SegmentReport& report
const SegmentPolicy& policy, SegmentHooks& hooks, SegmentReport& report, CheckpointRun& run
){
for (size_t attempt = 1; ; attempt++){
run.attempts = attempt;
Checkpoint checkpoint = spec.build();
if (spec.saves && !checkpoint.save){
checkpoint.save = [&hooks](RunState& state){
return hooks.save ? hooks.save(state) : outcome_failed("no_save_hook");
};
}
add_policy_recoveries(checkpoint, policy, hooks, run.recoveries);
CheckpointReport result = run_checkpoint(state, checkpoint, hooks.log);
if (result.completed || attempt >= policy.attempts_per_checkpoint){
if (result.completed){
run.passed = true;
hooks.log(std::format(
"[Checkpoint] {}: passed on attempt {} ({}){}",
spec.id, attempt, resets_text(attempt),
run.recoveries == 0 ? "" : std::format(", {} in place", run.recoveries)
));
return result;
}
if (policy.stop_at_first_failure){
hooks.log(std::format(
"[Segment] {}: {} failed; stopping at the first failure, the game stays where it failed",
segment.id, spec.id
));
report.stopped_at_first_failure = true;
return result;
}
if (attempt >= policy.attempts_per_checkpoint){
return result;
}
hooks.log(std::format(
Expand Down Expand Up @@ -128,6 +174,19 @@ SegmentReport stop_segment(SegmentReport& report, SegmentHooks& hooks, const std
}


bool CheckpointRun::one_shot() const{
return passed && attempts == 1 && recoveries == 0;
}

size_t SegmentReport::one_shot_passes() const{
size_t count = 0;
for (const CheckpointRun& run : runs){
count += run.one_shot() ? 1 : 0;
}
return count;
}


SegmentReport run_segment(
RunState& state, Segment& segment, const SegmentRange& range,
const SegmentPolicy& policy, SegmentHooks& hooks
Expand All @@ -141,14 +200,16 @@ SegmentReport run_segment(
for (size_t c = selected.first; c <= selected.last; c++){
CheckpointSpec& spec = segment.checkpoints[c];
report.checkpoints_run++;
CheckpointReport result = run_row(state, segment, spec, policy, hooks, report);
report.runs.push_back(CheckpointRun{.id = spec.id});
CheckpointReport result = run_row(state, segment, spec, policy, hooks, report, report.runs.back());
if (!result.completed){
report.failed_checkpoint = spec.id;
report.failed_event = result.failed_name;
return stop_segment(report, hooks, segment.id, std::move(result.failure));
}
}
report.completed = true;
hooks.log(std::format("[Segment] {}: {} of {} checkpoints one-shot", segment.id, report.one_shot_passes(), report.checkpoints_run));
hooks.log(std::format("[Segment] {}: done, {} checkpoints", segment.id, report.checkpoints_run));
return report;
}
Expand Down
37 changes: 36 additions & 1 deletion SerialPrograms/Source/Pokemon/Navigation/Pokemon_StorySegments.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,28 @@ struct Segment{
// What the game lends the runner: how to save, how to reload the last save
// (the run state is emptied first; the reload's Outcome says where the
// player stands), and where to log.
// `recover`, if set, is the game's way of recovering in place from a failed
// event (re-anchor on a landmark, close a stray dialogue) before the event
// is tried again; see SegmentPolicy::recoveries_per_event.
struct SegmentHooks{
Act save;
Act reload;
EventLogger log;
MoveOnlyFunction<Outcome(RunState& state, const std::string& event)> recover;
};

// How hard a segment tries, for every game: the one place retries are set.
struct SegmentPolicy{
// Runs of one checkpoint, reloading between them, before the segment stops.
// Runs of one checkpoint, reloading its save between them, before the
// segment stops.
size_t attempts_per_checkpoint = 3;
// Lab: stop at the first failed attempt without reloading, leaving the
// game where it failed for a look.
bool stop_at_first_failure = false;
// Times each event may recover in place (SegmentHooks::recover, then
// the event again) once its own recoveries are used up, before its
// checkpoint fails and is reloaded. 0 keeps a failure a reload.
size_t recoveries_per_event = 0;
};

// The checkpoints to run, by id, both inclusive. An unset end is the
Expand All @@ -65,8 +78,22 @@ struct SegmentRange{
};


// How one checkpoint went: one attempt with no in-place recovery is a
// one-shot pass.
struct CheckpointRun{
std::string id;
bool passed = false;
size_t attempts = 0;
// In-place recoveries (SegmentPolicy::recoveries_per_event) used, in all attempts.
size_t recoveries = 0;

bool one_shot() const;
};

struct SegmentReport{
bool completed = false;
// The run stopped at its first failure (SegmentPolicy::stop_at_first_failure).
bool stopped_at_first_failure = false;
// Both empty when nothing failed; the event is empty when a start
// check, an end check, a save or a reload failed.
std::string failed_checkpoint;
Expand All @@ -75,13 +102,21 @@ struct SegmentReport{
size_t checkpoints_run = 0;
// Reloads after failed attempts.
size_t reloads = 0;
// Each checkpoint run, in order, the failed one last.
std::vector<CheckpointRun> runs;

size_t one_shot_passes() const;
};

// Runs the checkpoints in `range`, in order. Logs through `hooks.log`,
// around the checkpoint lines:
// [Segment] 00: start, 3 checkpoints
// [Segment] 00: 00.02 failed, reloading for attempt 2/3
// [Checkpoint] 00.02: passed on attempt 2 (1 reset)
// [Checkpoint] 00.03: passed on attempt 1 (one-shot)
// [Segment] 00: 2 of 3 checkpoints one-shot
// [Segment] 00: done, 3 checkpoints
// [Segment] 00: 00.02 failed; stopping at the first failure, the game stays where it failed
// [Segment] 00: failed at 00.02 talk_mom: expect_failed: dialogue opened
SegmentReport run_segment(
RunState& state, Segment& segment, const SegmentRange& range,
Expand Down
Loading
Loading