From 47e077953654f4b5bc510f5fc12a1df5f47d0557 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 22:51:55 -0800 Subject: [PATCH 01/24] AutoStory: breakpoints, pause before each step and each leg (hook, option, engine) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Engine/Pokemon_StoryActionRegistry.cpp | 3 +- .../Engine/Pokemon_StoryActionRegistry.h | 7 + .../Engine/Pokemon_StoryBuiltinActions.cpp | 10 +- .../AutoStory/Engine/Pokemon_StoryEngine.cpp | 27 +++- .../Engine/Pokemon_StoryEngineRuns_Tests.cpp | 142 ++++++++++++++++++ .../AutoStory/Engine/Pokemon_StoryGame.h | 12 ++ .../Types/Pokemon_StoryBreakpoints.cpp | 103 +++++++++++++ .../Types/Pokemon_StoryBreakpoints.h | 97 ++++++++++++ .../Options/Pokemon_StoryRunOptions.cpp | 22 +++ .../Pokemon/Options/Pokemon_StoryRunOptions.h | 6 + SerialPrograms/cmake/SourceFiles.cmake | 2 + 11 files changed, 426 insertions(+), 5 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.cpp index 9313165a6e..3f09cfaeb6 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.cpp @@ -82,6 +82,7 @@ StoryActionRegistry::StoryActionRegistry(const StoryGame& ga : m_game(game) , m_actions(builtin_story_handlers()) , m_game_problems(tile_arg_problems(game)) + , m_pause(game.breakpoints, game.pause_point) { // A game's action replaces the built-in of its kind and name in place, // so a kind's default stays the built-in one's position. @@ -172,7 +173,7 @@ Outcome StoryActionRegistry::dispatch(StoryBackend& backend, )); } const StoryActionArgs args = with_fallbacks(action->spec, step.args); - return action->handler(backend, StoryActionCall{.step = step, .args = args}, state); + return action->handler(backend, StoryActionCall{.step = step, .args = args, .pause = m_pause}, state); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.h b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.h index f8adbc6c6f..7c2e923acf 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.h @@ -58,6 +58,12 @@ class StoryActionRegistry{ // actions fails too. std::vector lint(const StoryCheckpoint& checkpoint) const; + // The pause points of this game's run (StoryGame::breakpoints and + // pause_point). Mutable state of the run, not of the game's actions. + StoryPausePoints& pause_points() const{ + return m_pause; + } + // Runs `step`'s action with its args' fallbacks filled in; a step with // no registered action fails as unsupported_step(), a console_only // action on another backend as CONSOLE_ONLY, before any input. @@ -73,6 +79,7 @@ class StoryActionRegistry{ std::vector m_specs; // What is wrong with the game's own actions, reported with every lint. std::vector m_game_problems; + mutable StoryPausePoints m_pause; }; // Instantiated once, in Pokemon_StoryActionRegistry.cpp. diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBuiltinActions.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBuiltinActions.cpp index 24e610dca6..7846f0aa04 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBuiltinActions.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBuiltinActions.cpp @@ -97,7 +97,15 @@ inline std::optional after_legs(const Pose& start, const std::vector Outcome walk_legs(StoryBackend& backend, const StoryActionCall& call, RunState& state){ const std::vector& legs = story_arg>(call.args, "legs"); - for (const StoryLeg& leg : legs){ + const std::vector start = tiles_of(state.pose); + std::optional tile = start.size() == 1 ? std::optional(start[0]) : std::nullopt; + for (size_t index = 0; index < legs.size(); index++){ + const StoryLeg& leg = legs[index]; + for (int c = 0; tile && c < leg.tiles; c++){ + tile = tile->next(leg.direction); + } + call.pause.before_leg(story_leg_pause_label(index, legs.size(), leg.direction, leg.tiles, tile)); + backend.scope().throw_if_cancelled(); for (int c = 0; c < leg.tiles; c++){ backend.tap(leg.direction); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp index e215a54d82..2b090b4a71 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp @@ -25,17 +25,20 @@ namespace{ template class RunnerExecutor : public StoryStepExecutor{ public: - RunnerExecutor(StoryStepRunner& runner, const StoryGame& game) + RunnerExecutor(StoryStepRunner& runner, const StoryGame& game, StoryPausePoints& pause) : m_runner(runner) , m_game(game) + , m_pause(pause) {} virtual void begin_attempt(const StoryCheckpoint& data) override{ + m_checkpoint = &data; if (m_game.begin_attempt){ m_game.begin_attempt(data); } } virtual Outcome run(const StoryStep& step, RunState& state) override{ + m_pause.before_step(pause_label(step)); return m_runner.act(step, state); } virtual bool holds(std::string_view condition, RunState& state) override{ @@ -43,8 +46,22 @@ class RunnerExecutor : public StoryStepExecutor{ } private: + // The step's place in its checkpoint (step names are unique, which the + // lint checks). + std::string pause_label(const StoryStep& step) const{ + size_t index = 0; + if (m_checkpoint != nullptr){ + while (index < m_checkpoint->steps.size() && m_checkpoint->steps[index].name != step.name){ + index++; + } + } + return story_step_pause_label(m_checkpoint == nullptr ? "" : m_checkpoint->id, index, step.name); + } + StoryStepRunner& m_runner; const StoryGame& m_game; + StoryPausePoints& m_pause; + const StoryCheckpoint* m_checkpoint = nullptr; }; // `game` with its SAVE step "save" saving `current` only while `mode` is @@ -166,7 +183,11 @@ StoryEngine::StoryEngine(const StoryGame& game, StoryBackend , m_backend(backend) , m_registry(m_game) , m_runner(m_registry, backend) -{} +{ + m_registry.pause_points().set_log([&backend](std::string_view line){ + backend.log(line); + }); +} template std::string StoryEngine::steps_hash(const StoryCheckpoint& checkpoint) const{ @@ -337,7 +358,7 @@ VerifyReport StoryEngine::verify_checkpoint(const StoryCheckpoint& che template CheckpointReport StoryEngine::run_steps(const StoryCheckpoint& checkpoint, RunState& state){ - RunnerExecutor executor(m_runner, m_game); + RunnerExecutor executor(m_runner, m_game, m_registry.pause_points()); Checkpoint events = build_story_checkpoint(checkpoint, executor, &m_prepared); if (m_game.interrupts){ events.interrupts = m_game.interrupts(m_backend); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp index d272a19648..4b69890477 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp @@ -675,6 +675,143 @@ std::string verify_saves_after_all_passed(CancellableScope& scope){ } +// A game whose "mark" action records "run " and whose pause hook +// records "pause