From 09e802eeb0d1b63db6f63b4da056950f05c0e48f Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 00:14:33 -0800 Subject: [PATCH 1/4] AutoStory: story steps, checkpoints, breakpoints and save modes as plain data --- .../AutoStory/Pokemon_StoryCheckpointTypes.h | 86 ++++++++++++++++ .../Pokemon/AutoStory/Pokemon_StoryEvent.h | 90 +++++++++++++++++ .../Types/Pokemon_StoryBreakpoints.cpp | 91 +++++++++++++++++ .../Types/Pokemon_StoryBreakpoints.h | 97 +++++++++++++++++++ .../Types/Pokemon_StoryCheckLevel.cpp | 32 ++++++ .../AutoStory/Types/Pokemon_StoryCheckLevel.h | 43 ++++++++ .../AutoStory/Types/Pokemon_StoryCheckpoint.h | 48 +++++++++ .../Types/Pokemon_StoryCheckpointMetadata.cpp | 37 +++++++ .../Types/Pokemon_StoryCheckpointMetadata.h | 69 +++++++++++++ .../Types/Pokemon_StoryPostconditions.h | 43 ++++++++ .../AutoStory/Types/Pokemon_StorySaveMode.cpp | 43 ++++++++ .../AutoStory/Types/Pokemon_StorySaveMode.h | 59 +++++++++++ .../AutoStory/Types/Pokemon_StoryStep.h | 60 ++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 13 +++ 14 files changed, 811 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryPostconditions.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryStep.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h new file mode 100644 index 0000000000..79e540b467 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h @@ -0,0 +1,86 @@ +/* Story Checkpoint Types + * + * From: https://github.com/PokemonAutomation/ + * + * Split out of Pokemon_StoryEvents.h, unchanged; it includes this header. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryCheckpointTypes_H +#define PokemonAutomation_Pokemon_StoryCheckpointTypes_H + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/MoveOnlyFunction.h" +#include "Pokemon_StoryLog.h" +#include "Pokemon_StoryEvent.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Pose confidence adjustment following an event interruption. +enum class InterruptPose{ + UNCHANGED, // Cleared where we stood (a talk-only trainer). + WITHIN_SET, // Moved an unknown part of a leg: still within the position we had, no longer exactly where. + LOST, // Anywhere. +}; +// Policy defining how an interrupted event should be resumed. +enum class ResumePolicy{ + RETRY_EVENT, // Run the event again, from its skip_if. + RECHECK_EXPECT, // The action may have finished: done if its expects hold, else retry. + STOP, // Stop the checkpoint. +}; + +// Something that can stop an action part-way. +struct Interrupt{ + std::string name; + Check detect; + Act handle; + InterruptPose pose = InterruptPose::UNCHANGED; + ResumePolicy resume = ResumePolicy::RETRY_EVENT; +}; +// Writes what an interrupt did (`effect`) into `pose`. +void apply_interrupt_pose(InterruptPose effect, Pose& pose); + + +// Story milestone containing pre/post conditions and a series of events. +struct Checkpoint{ + std::string id; + // Must hold before the first event (the save it starts from). + std::vector start; + std::vector interrupts; + std::vector events; + // Must hold after the last event. + std::vector end; + // Saves the game after the end check, if set. + Act save; + size_t max_interrupts_per_event = 5; +}; + + +// Result report from executing a checkpoint. +struct CheckpointReport{ + bool completed = false; + // 1-based number of the event that failed; 0 for the start or end check + // or the save, or when nothing failed. + size_t failed_event = 0; + std::string failed_name; + Outcome failure; + size_t events_run = 0; + size_t events_skipped = 0; +}; + +// Callback receiver for story event execution log messages. +using EventLogger = MoveOnlyFunction; + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h new file mode 100644 index 0000000000..ffda3cee12 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h @@ -0,0 +1,90 @@ +/* Story Event + * + * From: https://github.com/PokemonAutomation/ + * + * Split out of Pokemon_StoryEvents.h, unchanged; it includes this header. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryEvent_H +#define PokemonAutomation_Pokemon_StoryEvent_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/MoveOnlyFunction.h" +#include "Pokemon_StoryLog.h" +#include "Pokemon_StoryOutcome.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Predicate callable evaluating current run state. +using Check = MoveOnlyFunction; + +// A question the screen (or the run state) answers, named for the log. +struct Condition{ + std::string name; + Check check; +}; +// Constructs a named Condition from a predicate check. +Condition condition(std::string name, Check check); + +// Holds while the pose is on `map` (any map if empty) and at least as +// certain as `need`. +Condition pose_known(std::string map, PoseCertainty need); + + +// Strategy for recovering from a failed event. +enum class RecoveryKind{ + WAIT, // Something transient (a wanderer, a slow scene): wait, try again. + REANCHOR, // The pose is in doubt: confirm it on a landmark, try again. + STOP, // Nothing to do: stop the checkpoint. +}; +// Returns the readable name of a recovery strategy. +std::string recovery_name(RecoveryKind kind); + +// Answers a failure named `on` (any failure if empty): runs `prepare`, if +// any, and tries the event again, up to `attempts` times. +struct Recovery{ + std::string on; + RecoveryKind kind = RecoveryKind::STOP; + Act prepare; + size_t attempts = 1; + std::string why; +}; + + +// Single executable story action with preconditions, recovery steps, and postconditions. +struct Event{ + std::string name; + std::string why; + // Skipped when all of these hold (and there is at least one). + std::vector skip_if; + // Run when the event is skipped: what the event leaves in the run + // state that is already so (a door it opens, a flag it sets). + std::function when_skipped; + // Must hold before `act`; a failure is "require_failed". + std::vector require; + Act act; + // Must hold after `act`; a failure is "expect_failed". + std::vector expect; + // Written to the run's pose once the event succeeds. An action that + // learns its pose as it goes (the row that answered) returns it in + // its Outcome instead. + std::optional pose_learned; + // In order of escalation. + std::vector recoveries; +}; + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp new file mode 100644 index 0000000000..8298ae45ce --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp @@ -0,0 +1,91 @@ +/* Story Breakpoints + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Pokemon_StoryBreakpoints.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +std::string story_step_pause_label(std::string_view checkpoint_id, size_t step_index, std::string_view step_name){ + return std::format("{}/{} {}", checkpoint_id, step_index + 1, step_name); +} + +std::string story_leg_pause_label( + size_t index, size_t count, Direction direction, int tiles, const std::optional& destination +){ + std::string label = std::format("leg {}/{} {} {}", index + 1, count, direction_name(direction), tiles); + if (destination){ + label += std::format(" -> ({}, {})", destination->x, destination->y); + } + return label; +} + + +StoryPausePoints::StoryPausePoints(StoryBreakpoints mode, StoryPauseHook hook) + : m_mode(mode) + , m_hook(std::move(hook)) +{} + +void StoryPausePoints::set_log(std::function log){ + m_log = std::move(log); +} + +void StoryPausePoints::before_step(const std::string& label){ + m_step_label = label; + if (m_mode != StoryBreakpoints::OFF){ + pause(label); + } +} + +void StoryPausePoints::before_leg(const std::string& leg_label){ + if (m_mode == StoryBreakpoints::LEGS){ + pause(std::format("{} {}", m_step_label, leg_label)); + } +} + +void StoryPausePoints::pause(const std::string& label){ + if (!m_hook){ + return; + } + if (m_log){ + m_log(std::format("[Break] {}: paused", label)); + } + m_hook(label); + if (m_log){ + m_log(std::format("[Break] {}: continued", label)); + } +} + + +namespace{ + +StoryPauseWait& installed_wait(){ + static StoryPauseWait wait; + return wait; +} + +} // namespace + +void set_story_pause_wait(StoryPauseWait wait){ + installed_wait() = std::move(wait); +} + +StoryPauseHook make_story_pause_hook(CancellableScope& scope){ + if (!installed_wait()){ + return {}; + } + return [&scope](std::string_view label){ + installed_wait()(label, scope); + }; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h new file mode 100644 index 0000000000..920e6bf16a --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h @@ -0,0 +1,97 @@ +/* Story Breakpoints + * + * From: https://github.com/PokemonAutomation/ + * + * A debugger's breakpoints for a story run: the program pauses before each + * step, or before each leg of a walk too, so the user can look at the + * console and then continue. The engine and the walk action call + * StoryPausePoints at those points; what a pause does is the game's + * StoryGame::pause_point hook. A normal build installs no wait + * (set_story_pause_wait()), so a pause point costs a log line and never + * blocks; a lab build installs one that waits for the user. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryBreakpoints_H +#define PokemonAutomation_Pokemon_StoryBreakpoints_H + +#include +#include +#include +#include +#include "Common/Cpp/CancellableScope.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Where a run pauses. +enum class StoryBreakpoints{ + // Nowhere. + OFF, + // Before each step. + STEPS, + // Before each step and each leg of a walk. + LEGS, +}; + +// "12.03/5 pallet_shore": the checkpoint, the step's place in it (from 1) +// and its name. +std::string story_step_pause_label(std::string_view checkpoint_id, size_t step_index, std::string_view step_name); + +// "leg 2/5 east 4 -> (10, 10)": leg `index` (from 0) of `count`, and the +// tile it ends on when the walk started on one known tile. +std::string story_leg_pause_label( + size_t index, size_t count, Direction direction, int tiles, const std::optional& destination +); + + +// What a pause point does when it is reached, given its full label. It +// returns when the run goes on, or when `scope` is cancelled. +using StoryPauseHook = std::function; + +// The pause points of one run. The engine owns it and hands it to actions. +class StoryPausePoints{ +public: + StoryPausePoints() = default; + StoryPausePoints(StoryBreakpoints mode, StoryPauseHook hook); + + // Where the engine logs "[Break]" lines. + void set_log(std::function log); + + // A step is about to run. Remembers `label` for the legs of the step + // and pauses when the mode asks for steps. + void before_step(const std::string& label); + // A leg is about to be walked: pauses, as " ", + // only in LEGS mode. + void before_leg(const std::string& leg_label); + // The label of the step under way ("12.03/5 pallet_shore"); empty before the first. + const std::string& step_label() const{ return m_step_label; } + +private: + void pause(const std::string& label); + + StoryBreakpoints m_mode = StoryBreakpoints::OFF; + StoryPauseHook m_hook; + std::function m_log; + std::string m_step_label; +}; + + +// The wait a lab build installs, called with the label and the run's scope. +// It returns when the user continues or `scope` is cancelled. Set once, +// before any program runs. Not installed: pause points do not block. +using StoryPauseWait = std::function; +// Installs it; an empty wait removes it. +void set_story_pause_wait(StoryPauseWait wait); + +// The hook for StoryGame::pause_point: the installed wait on `scope`, or +// nothing when none is installed. `scope` must outlive the hook. +StoryPauseHook make_story_pause_hook(CancellableScope& scope); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp new file mode 100644 index 0000000000..aade2b3809 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp @@ -0,0 +1,32 @@ +/* Story Checks + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Pokemon_StoryCheckLevel.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +std::string story_check_level_name(StoryCheckLevel level){ + switch (level){ + case StoryCheckLevel::TESTING: + return "testing"; + case StoryCheckLevel::THOROUGH: + return "thorough"; + case StoryCheckLevel::DEFAULT: + return "default"; + case StoryCheckLevel::FAST: + return "fast"; + case StoryCheckLevel::SPEEDRUN: + return "speedrun"; + } + return "?"; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h new file mode 100644 index 0000000000..86de9f8c76 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h @@ -0,0 +1,43 @@ +/* Story Check Level + * + * From: https://github.com/PokemonAutomation/ + * + * How much a story step reads the screen to confirm what it did. The + * program's options choose it (StoryRunOptions); each game decides what + * its steps check at each level. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryCheckLevel_H +#define PokemonAutomation_Pokemon_StoryCheckLevel_H + +#include + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// How much a step reads the screen to confirm what it did. +enum class StoryCheckLevel{ + // Everything THOROUGH checks, each checkpoint run 3 times by default to + // make sure it really passes. + TESTING, + // Check everything for the user: Bag items, Pokemon stats, + // preconditions. + THOROUGH, + // Assume most things are fine; check the most important ones. + DEFAULT, + // Minimal checks. + FAST, + // Almost no checks, to be as fast as possible. + SPEEDRUN, +}; + +// Returns the readable string representation of a story check level. +std::string story_check_level_name(StoryCheckLevel level); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h new file mode 100644 index 0000000000..21de004f19 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h @@ -0,0 +1,48 @@ +/* Story Checkpoint + * + * From: https://github.com/PokemonAutomation/ + * + * A checkpoint of a tile game's story table as plain data: where its save + * leaves the player and its steps in order. build_story_checkpoint() + * (Pokemon_StoryStepExecutor.h) turns it into engine events. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryCheckpoint_H +#define PokemonAutomation_Pokemon_StoryCheckpoint_H + +#include +#include +#include +#include "Pokemon_DeclaredPose.h" +#include "Pokemon_StoryCheckpointMetadata.h" +#include "Pokemon_StoryPostconditions.h" +#include "Pokemon_StoryStep.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Milestone row in the story table grouping related steps and starting pose. +struct StoryCheckpoint{ + std::string id; + std::string title; + // Where its starting save leaves the player; none for a new game. + std::optional start; + std::vector steps; + // The steps' JSON ("events") as read, dumped compactly; what + // story_steps_hash() hashes. Empty for a checkpoint built in code. + std::string steps_json = {}; + // What must hold when it is done; checked on its own after a run. + // JSON: "metadata": {"postconditions": ...}. + StoryPostconditions postconditions = {}; + // Its phase and verification (JSON "metadata"), which decide when a + // run of it may save. + StoryCheckpointMetadata metadata = {}; +}; + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.cpp new file mode 100644 index 0000000000..fb6eac85fd --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.cpp @@ -0,0 +1,37 @@ +/* Story Checkpoint Metadata + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Pokemon_StoryCheckpointMetadata.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +std::string story_phase_name(StoryPhase phase){ + switch (phase){ + case StoryPhase::TESTING: + return "testing"; + case StoryPhase::VERIFICATION: + return "verification"; + case StoryPhase::REPRODUCTION: + return "reproduction"; + } + return "?"; +} + +std::optional read_story_phase(std::string_view name){ + for (StoryPhase phase : {StoryPhase::TESTING, StoryPhase::VERIFICATION, StoryPhase::REPRODUCTION}){ + if (story_phase_name(phase) == name){ + return phase; + } + } + return std::nullopt; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h new file mode 100644 index 0000000000..0a305e0591 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h @@ -0,0 +1,69 @@ +/* Story Checkpoint Metadata + * + * From: https://github.com/PokemonAutomation/ + * + * What a checkpoint's JSON says about the checkpoint rather than how to + * play it: its phase (autostory/SAVE_POLICY.md on the notes branch), the + * steps it was verified with, and where it came from. The engine picks + * the save mode from the phase, and only while the steps still hash to + * the verified ones (Engine/Pokemon_StoryEnginePolicy.h). + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryCheckpointMetadata_H +#define PokemonAutomation_Pokemon_StoryCheckpointMetadata_H + +#include +#include +#include + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Where a checkpoint stands. It moves forward only on passes; a change to +// its steps moves it back to TESTING. +enum class StoryPhase{ + // New or changed: one run, never saves. + TESTING, + // Passed its test: 2-3 runs from the same start save, then one save. + VERIFICATION, + // Verified: a playthrough saves at its end. + REPRODUCTION, +}; + +// The wire and log name of a phase: "testing", "verification", "reproduction". +std::string story_phase_name(StoryPhase phase); + +// The phase named `name`; none for another name. +std::optional read_story_phase(std::string_view name); + +// The runs that moved the checkpoint out of testing, as recorded. +struct StoryVerification{ + // story_steps_hash() of the steps those runs ran: "sha256:". + std::string steps_hash = {}; + // The build those runs used (a commit). + std::string build = {}; + std::string date = {}; + // Passes out of runs, e.g. "3/3". + std::string runs = {}; + + bool operator==(const StoryVerification& other) const = default; +}; + +// A checkpoint's "metadata" object, less its postconditions, which the +// checkpoint keeps beside its steps (StoryCheckpoint::postconditions). +struct StoryCheckpointMetadata{ + StoryPhase phase = StoryPhase::TESTING; + std::optional verified = std::nullopt; + // Where the steps came from: a walkthrough, a console recording. + std::string source = {}; + + bool operator==(const StoryCheckpointMetadata& other) const = default; +}; + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryPostconditions.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryPostconditions.h new file mode 100644 index 0000000000..5b3cd7df37 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryPostconditions.h @@ -0,0 +1,43 @@ +/* Story Postconditions + * + * From: https://github.com/PokemonAutomation/ + * + * What must hold once a checkpoint is done, as plain data from its plan: + * where the player stands, what the Bag holds, which story flags moved. + * check_postconditions() (Pokemon_StoryPostconditionCheck.h) checks them + * against what the game read, as a step of its own after the run. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryPostconditions_H +#define PokemonAutomation_Pokemon_StoryPostconditions_H + +#include +#include +#include +#include "Pokemon_GridPose.h" +#include "Pokemon_StoryActionArg.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// The end state a checkpoint's plan promises: position, Bag items and flags. +struct StoryPostconditions{ + // Where the checkpoint ends; unset, it is the last step's target + // (checkpoint_end_pose()). + std::optional position; + // Each item's count in the Bag, exactly, by the game's item id + // ("LIFT_KEY", "RARE_CANDY"). + std::vector items; + // Story flags that must be set: a trainer beaten, a door open. + std::vector flags; + + bool operator==(const StoryPostconditions& other) const = default; +}; + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp new file mode 100644 index 0000000000..7fbeebf500 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp @@ -0,0 +1,43 @@ +/* Story Save Mode + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Pokemon_StorySaveMode.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +std::string story_save_mode_name(StorySaveMode mode){ + switch (mode){ + case StorySaveMode::NONE: + return "none"; + case StorySaveMode::AFTER_VERIFICATION: + return "after_verification"; + case StorySaveMode::PER_CHECKPOINT: + return "per_checkpoint"; + } + return "?"; +} + +bool story_save_allowed(StorySaveMode mode, CheckpointVerdict verdict, SavePoint point){ + if (verdict != CheckpointVerdict::PASSED){ + return false; + } + switch (mode){ + case StorySaveMode::NONE: + return false; + case StorySaveMode::AFTER_VERIFICATION: + return point == SavePoint::RUN_END; + case StorySaveMode::PER_CHECKPOINT: + return true; + } + return false; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h new file mode 100644 index 0000000000..c06b0f52c5 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h @@ -0,0 +1,59 @@ +/* Story Save Mode + * + * From: https://github.com/PokemonAutomation/ + * + * When an AutoStory run may save the game. A run's own verdict can be + * wrong (a warp confirmed on the next floor while the player is still on + * the one before), and a save made then overwrites the only good one. So a segment + * under test never saves, a verified one saves once at its end, and only + * a playthrough of verified segments saves at each checkpoint. + * + */ + +#ifndef PokemonAutomation_Pokemon_StorySaveMode_H +#define PokemonAutomation_Pokemon_StorySaveMode_H + +#include + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// When a run saves. A failed run never saves, in any mode. +enum class StorySaveMode{ + // Testing: never save; the save the run started from stays. + NONE, + // Verification: save once, at the end of a run that passed. + AFTER_VERIFICATION, + // Reproduction (a playthrough of verified segments): save at the end + // of each checkpoint that passed. + PER_CHECKPOINT, +}; + +// Returns the wire and log name of a save mode: "none", "after_verification", "per_checkpoint". +std::string story_save_mode_name(StorySaveMode mode); + +// How a checkpoint ended: passed (and its postconditions, where checked, +// did not fail) or not. +enum class CheckpointVerdict{ + PASSED, + FAILED, +}; + +// Where a save would be made. +enum class SavePoint{ + // A checkpoint's end, with more checkpoints of the run after it. + CHECKPOINT_END, + // The last checkpoint's end: the run's end state. + RUN_END, +}; + +// Whether a run in `mode` saves at `point` after a checkpoint that ended +// as `verdict`. +bool story_save_allowed(StorySaveMode mode, CheckpointVerdict verdict, SavePoint point); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryStep.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryStep.h new file mode 100644 index 0000000000..4500111b71 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryStep.h @@ -0,0 +1,60 @@ +/* Story Step + * + * From: https://github.com/PokemonAutomation/ + * + * One step of a tile game's story (FRLG, BDSP) as plain data: its kind, + * the action that does it and the action's args. A game's executor does it + * (Pokemon_StoryStepExecutor.h); the shared JSON reads and writes it + * (Data/Pokemon_StoryStepJson.h). + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryStep_H +#define PokemonAutomation_Pokemon_StoryStep_H + +#include +#include +#include +#include "Pokemon_DeclaredPose.h" +#include "Pokemon_StoryActionArg.h" +#include "Pokemon_StoryStepKind.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Specification of an atomic story task with actions and postconditions. +struct StoryStep{ + StoryStepKind kind = StoryStepKind::TALK; + std::string name; + std::string why; + + // How the step does its kind: one of the built-in actions + // (Pokemon_BuiltinStoryActions.h) or the game's own; for a GAME step, the + // game's action. Empty is the kind's default action. + std::string action; + // The arguments the action reads, parsed against its spec when the + // game loads the step, with the spec's fallbacks filled in. + StoryActionArgs args; + + // Skipped when all of these hold (and there is at least one): names + // the game's executor answers (StoryStepExecutor::holds()), run flags + // unless the game reads them off the screen. + std::vector skip_if; + // Preparation for what follows, done once per save: a TEACH, a check, + // a read. Once it has succeeded and changed nothing + // (Outcome::changed_nothing), the attempts after a reload of the same + // save skip it, so a retry goes from the reload straight to the + // battle. One that changed the game (a TM taught) runs again, as the + // reload undid it. Only with build_story_checkpoint()'s PreparedSteps. + bool once_per_save = false; + // Where the step leaves the player, when its action does not say: the + // end of a scene that moves the player. + std::optional pose_after; +}; + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 9fe0bbaa32..0f0f3896a8 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1449,6 +1449,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_BuiltinStoryActions.cpp Source/Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h Source/Pokemon/AutoStory/Pokemon_MapUtil.h + Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h + Source/Pokemon/AutoStory/Pokemon_StoryEvent.h Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.cpp Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.h Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses_Tests.cpp @@ -1467,6 +1469,17 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg_Tests.h Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h + Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp + Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h + Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp + Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h + Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h + Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.cpp + Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h + Source/Pokemon/AutoStory/Types/Pokemon_StoryPostconditions.h + Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp + Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h + Source/Pokemon/AutoStory/Types/Pokemon_StoryStep.h Source/Pokemon/AutoStory/Types/Pokemon_StoryStepKind.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryStepKind.h Source/Pokemon/Inference/Pokemon_AbilityReader.cpp From 0550227dc6409afe31a27af93fe54aa1b76fdebc Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 00:50:08 -0800 Subject: [PATCH 2/4] AutoStory: event and checkpoint types define their functions; run types get tests condition(), pose_known(), recovery_name() and apply_interrupt_pose() get their own .cpp files beside the headers that declare them. The pause wait is passed to make_story_pause_hook() instead of living in a process-wide global, so a hook keeps the wait it was made with. New suite StoryRunTypes covers the save decision table, phase names and the pause points. Pokemon_DeclaredPose.h comes here with the step types that hold one. --- .../AutoStory/Pokemon_AutoStory_Tests.h | 2 + .../Pokemon_StoryCheckpointTypes.cpp | 32 +++ .../AutoStory/Pokemon_StoryCheckpointTypes.h | 10 +- .../Pokemon/AutoStory/Pokemon_StoryEvent.cpp | 41 +++ .../Pokemon/AutoStory/Pokemon_StoryEvent.h | 14 +- .../AutoStory/Types/Pokemon_DeclaredPose.h | 53 ++++ .../Types/Pokemon_StoryBreakpoints.cpp | 27 +- .../Types/Pokemon_StoryBreakpoints.h | 24 +- .../Types/Pokemon_StoryCheckpointMetadata.h | 2 +- .../Types/Pokemon_StoryRunTypes_Tests.cpp | 248 ++++++++++++++++++ .../Types/Pokemon_StoryRunTypes_Tests.h | 24 ++ SerialPrograms/cmake/SourceFiles.cmake | 5 + 12 files changed, 438 insertions(+), 44 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_DeclaredPose.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h index 3b2328fa87..075f80f255 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h @@ -15,6 +15,7 @@ #include "Pokemon_StoryFailureClasses_Tests.h" #include "Pokemon_StoryLog_Tests.h" #include "Types/Pokemon_StoryActionArg_Tests.h" +#include "Types/Pokemon_StoryRunTypes_Tests.h" namespace PokemonAutomation{ namespace Pokemon{ @@ -25,6 +26,7 @@ inline void add_tests_AutoStory(UnitTestDatabase& database){ add_tests_StoryActionArg(database); add_tests_StoryLog(database); add_tests_StoryFailureClasses(database); + add_tests_StoryRunTypes(database); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.cpp new file mode 100644 index 0000000000..92576991ec --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.cpp @@ -0,0 +1,32 @@ +/* Story Checkpoint Types + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Pokemon_StoryCheckpointTypes.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +void apply_interrupt_pose(InterruptPose effect, Pose& pose){ + switch (effect){ + case InterruptPose::UNCHANGED: + return; + case InterruptPose::WITHIN_SET: + if (pose.certainty != PoseCertainty::UNKNOWN){ + pose.certainty = PoseCertainty::SET; + } + return; + case InterruptPose::LOST: + pose.where.reset(); + pose.certainty = PoseCertainty::UNKNOWN; + return; + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h index 79e540b467..213b911eb5 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h @@ -2,7 +2,9 @@ * * From: https://github.com/PokemonAutomation/ * - * Split out of Pokemon_StoryEvents.h, unchanged; it includes this header. + * A checkpoint as the event runner sees it: its events, the interrupts + * that can stop one part-way, its start and end checks, and the report of + * a run of it. * */ @@ -49,7 +51,7 @@ struct Interrupt{ void apply_interrupt_pose(InterruptPose effect, Pose& pose); -// Story milestone containing pre/post conditions and a series of events. +// The stretch of story between two saves, as events. struct Checkpoint{ std::string id; // Must hold before the first event (the save it starts from). @@ -60,6 +62,8 @@ struct Checkpoint{ std::vector end; // Saves the game after the end check, if set. Act save; + // More interrupts than this in one event (wild battles, trainers) is + // a loop, not bad luck: the event fails as "too_many_interrupts". size_t max_interrupts_per_event = 5; }; @@ -76,7 +80,7 @@ struct CheckpointReport{ size_t events_skipped = 0; }; -// Callback receiver for story event execution log messages. +// Where the runner writes its log lines. using EventLogger = MoveOnlyFunction; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.cpp new file mode 100644 index 0000000000..cd5e892b8f --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.cpp @@ -0,0 +1,41 @@ +/* Story Event + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Pokemon_StoryEvent.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +Condition condition(std::string name, Check check){ + return Condition{std::move(name), std::move(check)}; +} + +Condition pose_known(std::string map, PoseCertainty need){ + std::string name = std::format("pose {}{}", certainty_name(need), map.empty() ? "" : std::format(" on {}", map)); + return condition(std::move(name), [map = std::move(map), need](RunState& state){ + return (map.empty() || state.pose.map == map) && certainty_covers(state.pose.certainty, need); + }); +} + +std::string recovery_name(RecoveryKind kind){ + switch (kind){ + case RecoveryKind::WAIT: + return "wait"; + case RecoveryKind::REANCHOR: + return "re-anchor"; + case RecoveryKind::STOP: + return "stop"; + } + return "?"; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h index ffda3cee12..c23bbb85fc 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h @@ -2,7 +2,9 @@ * * From: https://github.com/PokemonAutomation/ * - * Split out of Pokemon_StoryEvents.h, unchanged; it includes this header. + * One step of a checkpoint as the event runner sees it: what it checks + * before and after its action, when it is already done, and how a failure + * of it is answered. * */ @@ -25,7 +27,7 @@ namespace PokemonAutomation{ namespace Pokemon{ -// Predicate callable evaluating current run state. +// A question about the run state. using Check = MoveOnlyFunction; // A question the screen (or the run state) answers, named for the log. @@ -33,7 +35,7 @@ struct Condition{ std::string name; Check check; }; -// Constructs a named Condition from a predicate check. +// `check`, named `name` in the log. Condition condition(std::string name, Check check); // Holds while the pose is on `map` (any map if empty) and at least as @@ -41,13 +43,13 @@ Condition condition(std::string name, Check check); Condition pose_known(std::string map, PoseCertainty need); -// Strategy for recovering from a failed event. +// How a failed event is answered. enum class RecoveryKind{ WAIT, // Something transient (a wanderer, a slow scene): wait, try again. REANCHOR, // The pose is in doubt: confirm it on a landmark, try again. STOP, // Nothing to do: stop the checkpoint. }; -// Returns the readable name of a recovery strategy. +// "wait", "re-anchor", "stop": for log lines. std::string recovery_name(RecoveryKind kind); // Answers a failure named `on` (any failure if empty): runs `prepare`, if @@ -61,7 +63,7 @@ struct Recovery{ }; -// Single executable story action with preconditions, recovery steps, and postconditions. +// One step of a checkpoint: an action with the conditions around it. struct Event{ std::string name; std::string why; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_DeclaredPose.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_DeclaredPose.h new file mode 100644 index 0000000000..cfcab43d72 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_DeclaredPose.h @@ -0,0 +1,53 @@ +/* Declared Pose + * + * From: https://github.com/PokemonAutomation/ + * + * A pose a checkpoint declares in its data (its start, a step's + * declared_after), as plain data. A tile game (FRLG, BDSP) declares a + * map, tiles and a facing; a game with no tile grid (PLZA) declares a + * place, a spot in it and a heading. Each game reads only its own kind + * (StoryPoseTraits::Declared); the lint fails a checkpoint that declares + * the other. + * + */ + +#ifndef PokemonAutomation_Pokemon_DeclaredPose_H +#define PokemonAutomation_Pokemon_DeclaredPose_H + +#include +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// On one of `tiles` of `map` (any tile when none), facing `facing` if set. +struct TileDeclared{ + std::string map; + std::vector tiles; + std::optional facing; + + bool operator==(const TileDeclared& other) const = default; +}; + +// In `place` ("LumioseCity"), at `spot` in it if set, heading `heading` +// degrees if set. +struct ZoneDeclared{ + std::string place; + std::optional spot; + std::optional heading; + + bool operator==(const ZoneDeclared& other) const = default; +}; + +// Either kind; a game reads only its own (StoryPoseTraits::Declared). +using DeclaredPose = std::variant; + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp index 8298ae45ce..929cc8543e 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp @@ -36,20 +36,20 @@ void StoryPausePoints::set_log(std::function log){ m_log = std::move(log); } -void StoryPausePoints::before_step(const std::string& label){ +void StoryPausePoints::before_step(std::string_view label){ m_step_label = label; if (m_mode != StoryBreakpoints::OFF){ pause(label); } } -void StoryPausePoints::before_leg(const std::string& leg_label){ +void StoryPausePoints::before_leg(std::string_view leg_label){ if (m_mode == StoryBreakpoints::LEGS){ pause(std::format("{} {}", m_step_label, leg_label)); } } -void StoryPausePoints::pause(const std::string& label){ +void StoryPausePoints::pause(std::string_view label){ if (!m_hook){ return; } @@ -63,25 +63,12 @@ void StoryPausePoints::pause(const std::string& label){ } -namespace{ - -StoryPauseWait& installed_wait(){ - static StoryPauseWait wait; - return wait; -} - -} // namespace - -void set_story_pause_wait(StoryPauseWait wait){ - installed_wait() = std::move(wait); -} - -StoryPauseHook make_story_pause_hook(CancellableScope& scope){ - if (!installed_wait()){ +StoryPauseHook make_story_pause_hook(StoryPauseWait wait, CancellableScope& scope){ + if (!wait){ return {}; } - return [&scope](std::string_view label){ - installed_wait()(label, scope); + return [wait = std::move(wait), &scope](std::string_view label){ + wait(label, scope); }; } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h index 920e6bf16a..69133a8984 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h @@ -6,9 +6,8 @@ * step, or before each leg of a walk too, so the user can look at the * console and then continue. The engine and the walk action call * StoryPausePoints at those points; what a pause does is the game's - * StoryGame::pause_point hook. A normal build installs no wait - * (set_story_pause_wait()), so a pause point costs a log line and never - * blocks; a lab build installs one that waits for the user. + * StoryGame::pause_point hook. A program that passes no wait to + * make_story_pause_hook() gets no hook, so its pause points never block. * */ @@ -62,15 +61,15 @@ class StoryPausePoints{ // A step is about to run. Remembers `label` for the legs of the step // and pauses when the mode asks for steps. - void before_step(const std::string& label); + void before_step(std::string_view label); // A leg is about to be walked: pauses, as " ", // only in LEGS mode. - void before_leg(const std::string& leg_label); + void before_leg(std::string_view leg_label); // The label of the step under way ("12.03/5 pallet_shore"); empty before the first. const std::string& step_label() const{ return m_step_label; } private: - void pause(const std::string& label); + void pause(std::string_view label); StoryBreakpoints m_mode = StoryBreakpoints::OFF; StoryPauseHook m_hook; @@ -79,16 +78,13 @@ class StoryPausePoints{ }; -// The wait a lab build installs, called with the label and the run's scope. -// It returns when the user continues or `scope` is cancelled. Set once, -// before any program runs. Not installed: pause points do not block. +// A wait for the user, called with the label and the run's scope. It +// returns when the user continues or `scope` is cancelled. using StoryPauseWait = std::function; -// Installs it; an empty wait removes it. -void set_story_pause_wait(StoryPauseWait wait); -// The hook for StoryGame::pause_point: the installed wait on `scope`, or -// nothing when none is installed. `scope` must outlive the hook. -StoryPauseHook make_story_pause_hook(CancellableScope& scope); +// The hook for StoryGame::pause_point: `wait` on `scope`, or no hook when +// `wait` is empty. `scope` must outlive the hook. +StoryPauseHook make_story_pause_hook(StoryPauseWait wait, CancellableScope& scope); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h index 0a305e0591..b2e467859a 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h @@ -3,7 +3,7 @@ * From: https://github.com/PokemonAutomation/ * * What a checkpoint's JSON says about the checkpoint rather than how to - * play it: its phase (autostory/SAVE_POLICY.md on the notes branch), the + * play it: its phase (testing, verification or reproduction, below), the * steps it was verified with, and where it came from. The engine picks * the save mode from the phase, and only while the steps still hash to * the verified ones (Engine/Pokemon_StoryEnginePolicy.h). diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp new file mode 100644 index 0000000000..8473ed991d --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp @@ -0,0 +1,248 @@ +/* Story Run Types Tests + * + * From: https://github.com/PokemonAutomation/ + * + * When a run may save (Pokemon_StorySaveMode.h), the phase names a + * checkpoint's metadata uses (Pokemon_StoryCheckpointMetadata.h), and + * where a run pauses (Pokemon_StoryBreakpoints.h). + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_StoryBreakpoints.h" +#include "Pokemon_StoryCheckpointMetadata.h" +#include "Pokemon_StoryRunTypes_Tests.h" +#include "Pokemon_StorySaveMode.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + + +// One row of the save decision: mode x verdict x save point. +struct SaveDecisionCase{ + struct Input{ + StorySaveMode mode; + CheckpointVerdict verdict; + SavePoint point; + }; + + struct Expectation{ + bool saves; + }; + + Input input; + Expectation expectation; +}; + +std::string decision_name(const SaveDecisionCase::Input& input){ + return std::format( + "{}, {}, {}", story_save_mode_name(input.mode), + input.verdict == CheckpointVerdict::PASSED ? "passed" : "failed", + input.point == SavePoint::RUN_END ? "run end" : "checkpoint end" + ); +} + +class Test_SaveDecision : public UnitTest{ +public: + explicit Test_SaveDecision(SaveDecisionCase test_case) + : UnitTest(std::format("Pokemon::StoryRunTypes - save decision: {}", decision_name(test_case.input))) + , m_case(test_case) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const SaveDecisionCase::Input& in = m_case.input; + const bool saves = story_save_allowed(in.mode, in.verdict, in.point); + if (saves != m_case.expectation.saves){ + return std::format("expected {}, got {}", m_case.expectation.saves ? "a save" : "no save", saves ? "a save" : "no save"); + } + return true; + } + +private: + SaveDecisionCase m_case; +}; + +using M = StorySaveMode; +using V = CheckpointVerdict; +using S = SavePoint; + +// A failed checkpoint never saves; NONE never saves; AFTER_VERIFICATION +// saves only at the run's end; PER_CHECKPOINT at every checkpoint's end. +const SaveDecisionCase SAVE_DECISIONS[] = { + {.input = {M::NONE, V::FAILED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, + {.input = {M::NONE, V::FAILED, S::RUN_END}, .expectation = {.saves = false}}, + {.input = {M::NONE, V::PASSED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, + {.input = {M::NONE, V::PASSED, S::RUN_END}, .expectation = {.saves = false}}, + {.input = {M::AFTER_VERIFICATION, V::FAILED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, + {.input = {M::AFTER_VERIFICATION, V::FAILED, S::RUN_END}, .expectation = {.saves = false}}, + {.input = {M::AFTER_VERIFICATION, V::PASSED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, + {.input = {M::AFTER_VERIFICATION, V::PASSED, S::RUN_END}, .expectation = {.saves = true}}, + {.input = {M::PER_CHECKPOINT, V::FAILED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, + {.input = {M::PER_CHECKPOINT, V::FAILED, S::RUN_END}, .expectation = {.saves = false}}, + {.input = {M::PER_CHECKPOINT, V::PASSED, S::CHECKPOINT_END}, .expectation = {.saves = true}}, + {.input = {M::PER_CHECKPOINT, V::PASSED, S::RUN_END}, .expectation = {.saves = true}}, +}; + + +// A named check that returns its own failure. +struct NamedCheck{ + std::string_view name; + UnitTestResult (*check)(CancellableScope& scope); +}; + +class Test_NamedCheck : public UnitTest{ +public: + explicit Test_NamedCheck(NamedCheck check) + : UnitTest(std::format("Pokemon::StoryRunTypes - {}", check.name)) + , m_check(check) + {} + + virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ + return m_check.check(scope); + } + +private: + const NamedCheck m_check; +}; + + +UnitTestResult phase_names_round_trip(CancellableScope&){ + for (StoryPhase phase : {StoryPhase::TESTING, StoryPhase::VERIFICATION, StoryPhase::REPRODUCTION}){ + if (read_story_phase(story_phase_name(phase)) != phase){ + return std::format("\"{}\" does not read back", story_phase_name(phase)); + } + } + if (read_story_phase("Testing") || read_story_phase("")){ + return std::string("read a phase from a name that is none"); + } + return true; +} + +std::string joined(const std::vector& lines){ + std::string text; + for (const std::string& line : lines){ + text += "\n " + line; + } + return text; +} + +// The labels each pause point paused on, in `mode`: one step with two legs. +std::vector paused_on(StoryBreakpoints mode){ + std::vector paused; + StoryPausePoints points(mode, [&](std::string_view label){ + paused.emplace_back(label); + }); + points.before_step("12.03/1 first"); + points.before_leg("leg 1/2 east 3"); + points.before_leg("leg 2/2 north 1"); + points.before_step("12.03/2 second"); + return paused; +} + +UnitTestResult pause_points_by_mode(CancellableScope&){ + if (!paused_on(StoryBreakpoints::OFF).empty()){ + return std::format("OFF paused:{}", joined(paused_on(StoryBreakpoints::OFF))); + } + const std::vector steps = {"12.03/1 first", "12.03/2 second"}; + if (paused_on(StoryBreakpoints::STEPS) != steps){ + return std::format("STEPS paused:{}", joined(paused_on(StoryBreakpoints::STEPS))); + } + const std::vector legs = { + "12.03/1 first", "12.03/1 first leg 1/2 east 3", "12.03/1 first leg 2/2 north 1", "12.03/2 second", + }; + if (paused_on(StoryBreakpoints::LEGS) != legs){ + return std::format("LEGS paused:{}", joined(paused_on(StoryBreakpoints::LEGS))); + } + return true; +} + +UnitTestResult pause_points_log_and_keep_the_label(CancellableScope&){ + std::vector lines; + StoryPausePoints points(StoryBreakpoints::STEPS, [](std::string_view){}); + points.set_log([&](std::string_view line){ + lines.emplace_back(line); + }); + points.before_step("12.03/1 first"); + const std::vector expected = {"[Break] 12.03/1 first: paused", "[Break] 12.03/1 first: continued"}; + if (lines != expected){ + return std::format("unexpected log:{}", joined(lines)); + } + if (points.step_label() != "12.03/1 first"){ + return std::format("step label \"{}\"", points.step_label()); + } + StoryPausePoints no_hook(StoryBreakpoints::LEGS, {}); + no_hook.set_log([&](std::string_view line){ + lines.emplace_back(line); + }); + no_hook.before_step("12.03/2 second"); + if (lines.size() != expected.size() || no_hook.step_label() != "12.03/2 second"){ + return std::format("a pause point with no hook logged or lost its label:{}", joined(lines)); + } + return true; +} + +UnitTestResult pause_hook_from_a_wait(CancellableScope& scope){ + if (make_story_pause_hook({}, scope)){ + return std::string("expected no hook without a wait"); + } + std::vector waited; + const StoryPauseHook hook = make_story_pause_hook([&](std::string_view label, CancellableScope& with){ + waited.push_back(std::format("{} {}", label, &with == &scope)); + }, scope); + if (!hook){ + return std::string("expected a hook for a wait"); + } + hook("12.03/1 first"); + if (waited != std::vector{"12.03/1 first true"}){ + return std::format("expected the wait to get the label and the scope:{}", joined(waited)); + } + return true; +} + +UnitTestResult pause_labels(CancellableScope&){ + if (story_step_pause_label("12.03", 4, "pallet_shore") != "12.03/5 pallet_shore"){ + return story_step_pause_label("12.03", 4, "pallet_shore"); + } + const std::string with_end = story_leg_pause_label(1, 5, Direction::EAST, 4, TilePos{10, 10}); + if (with_end != "leg 2/5 east 4 -> (10, 10)"){ + return with_end; + } + const std::string without_end = story_leg_pause_label(0, 1, Direction::NORTH, 2, std::nullopt); + if (without_end != "leg 1/1 north 2"){ + return without_end; + } + return true; +} + +const NamedCheck CHECKS[] = { + {.name = "phase names round-trip", .check = phase_names_round_trip}, + {.name = "pause points by mode", .check = pause_points_by_mode}, + {.name = "pause points log and keep the label", .check = pause_points_log_and_keep_the_label}, + {.name = "pause hook from a wait", .check = pause_hook_from_a_wait}, + {.name = "pause labels", .check = pause_labels}, +}; + + +} // namespace + + +void add_tests_StoryRunTypes(UnitTestDatabase& database){ + for (const SaveDecisionCase& test_case : SAVE_DECISIONS){ + database.add(test_case); + } + for (const NamedCheck& check : CHECKS){ + database.add(check); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.h new file mode 100644 index 0000000000..69cf6cfcfc --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.h @@ -0,0 +1,24 @@ +/* Story Run Types Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRunTypes_Tests_H +#define PokemonAutomation_Pokemon_StoryRunTypes_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers the tests of the save decision, the phase names and the pause +// points. +void add_tests_StoryRunTypes(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index e5d9bcc904..5d2407dd36 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1449,7 +1449,9 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_BuiltinStoryActions.cpp Source/Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h Source/Pokemon/AutoStory/Pokemon_MapUtil.h + Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.cpp Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h + Source/Pokemon/AutoStory/Pokemon_StoryEvent.cpp Source/Pokemon/AutoStory/Pokemon_StoryEvent.h Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.cpp Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.h @@ -1463,6 +1465,7 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_StoryOutcome.h Source/Pokemon/AutoStory/Pokemon_StoryPose.cpp Source/Pokemon/AutoStory/Pokemon_StoryPose.h + Source/Pokemon/AutoStory/Types/Pokemon_DeclaredPose.h Source/Pokemon/AutoStory/Types/Pokemon_GridPose.h Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg.h @@ -1478,6 +1481,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h Source/Pokemon/AutoStory/Types/Pokemon_StoryPostconditions.h + Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp + Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.h Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h Source/Pokemon/AutoStory/Types/Pokemon_StoryStep.h From eb0f1b76ade76ffa3e5e7e8a9e6d863a568daf45 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 01:12:32 -0800 Subject: [PATCH 3/4] AutoStory: StoryCheckLevel moves to the run options PR, its first user --- .../Types/Pokemon_StoryCheckLevel.cpp | 32 -------------- .../AutoStory/Types/Pokemon_StoryCheckLevel.h | 43 ------------------- SerialPrograms/cmake/SourceFiles.cmake | 2 - 3 files changed, 77 deletions(-) delete mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp delete mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp deleted file mode 100644 index aade2b3809..0000000000 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* Story Checks - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Pokemon_StoryCheckLevel.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -std::string story_check_level_name(StoryCheckLevel level){ - switch (level){ - case StoryCheckLevel::TESTING: - return "testing"; - case StoryCheckLevel::THOROUGH: - return "thorough"; - case StoryCheckLevel::DEFAULT: - return "default"; - case StoryCheckLevel::FAST: - return "fast"; - case StoryCheckLevel::SPEEDRUN: - return "speedrun"; - } - return "?"; -} - - - -} // namespace Pokemon -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h deleted file mode 100644 index 86de9f8c76..0000000000 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Story Check Level - * - * From: https://github.com/PokemonAutomation/ - * - * How much a story step reads the screen to confirm what it did. The - * program's options choose it (StoryRunOptions); each game decides what - * its steps check at each level. - * - */ - -#ifndef PokemonAutomation_Pokemon_StoryCheckLevel_H -#define PokemonAutomation_Pokemon_StoryCheckLevel_H - -#include - -namespace PokemonAutomation{ -namespace Pokemon{ - - -// How much a step reads the screen to confirm what it did. -enum class StoryCheckLevel{ - // Everything THOROUGH checks, each checkpoint run 3 times by default to - // make sure it really passes. - TESTING, - // Check everything for the user: Bag items, Pokemon stats, - // preconditions. - THOROUGH, - // Assume most things are fine; check the most important ones. - DEFAULT, - // Minimal checks. - FAST, - // Almost no checks, to be as fast as possible. - SPEEDRUN, -}; - -// Returns the readable string representation of a story check level. -std::string story_check_level_name(StoryCheckLevel level); - - - -} // namespace Pokemon -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 5d2407dd36..75b4e47857 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1475,8 +1475,6 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h - Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp - Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h From 6203f68f19a79a4f809a1ae877d0e78edc9848a8 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 01:19:26 -0800 Subject: [PATCH 4/4] AutoStory: StorySaveMode moves to the segment runner PR, its first user --- .../Types/Pokemon_StoryRunTypes_Tests.cpp | 76 +------------------ .../AutoStory/Types/Pokemon_StorySaveMode.cpp | 43 ----------- .../AutoStory/Types/Pokemon_StorySaveMode.h | 59 -------------- SerialPrograms/cmake/SourceFiles.cmake | 2 - 4 files changed, 3 insertions(+), 177 deletions(-) delete mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp delete mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp index 8473ed991d..1e3a662720 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp @@ -2,9 +2,9 @@ * * From: https://github.com/PokemonAutomation/ * - * When a run may save (Pokemon_StorySaveMode.h), the phase names a - * checkpoint's metadata uses (Pokemon_StoryCheckpointMetadata.h), and - * where a run pauses (Pokemon_StoryBreakpoints.h). + * The phase names a checkpoint's metadata uses + * (Pokemon_StoryCheckpointMetadata.h) and where a run pauses + * (Pokemon_StoryBreakpoints.h). * */ @@ -16,7 +16,6 @@ #include "Pokemon_StoryBreakpoints.h" #include "Pokemon_StoryCheckpointMetadata.h" #include "Pokemon_StoryRunTypes_Tests.h" -#include "Pokemon_StorySaveMode.h" namespace PokemonAutomation{ namespace Pokemon{ @@ -25,72 +24,6 @@ namespace Pokemon{ namespace{ -// One row of the save decision: mode x verdict x save point. -struct SaveDecisionCase{ - struct Input{ - StorySaveMode mode; - CheckpointVerdict verdict; - SavePoint point; - }; - - struct Expectation{ - bool saves; - }; - - Input input; - Expectation expectation; -}; - -std::string decision_name(const SaveDecisionCase::Input& input){ - return std::format( - "{}, {}, {}", story_save_mode_name(input.mode), - input.verdict == CheckpointVerdict::PASSED ? "passed" : "failed", - input.point == SavePoint::RUN_END ? "run end" : "checkpoint end" - ); -} - -class Test_SaveDecision : public UnitTest{ -public: - explicit Test_SaveDecision(SaveDecisionCase test_case) - : UnitTest(std::format("Pokemon::StoryRunTypes - save decision: {}", decision_name(test_case.input))) - , m_case(test_case) - {} - - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const SaveDecisionCase::Input& in = m_case.input; - const bool saves = story_save_allowed(in.mode, in.verdict, in.point); - if (saves != m_case.expectation.saves){ - return std::format("expected {}, got {}", m_case.expectation.saves ? "a save" : "no save", saves ? "a save" : "no save"); - } - return true; - } - -private: - SaveDecisionCase m_case; -}; - -using M = StorySaveMode; -using V = CheckpointVerdict; -using S = SavePoint; - -// A failed checkpoint never saves; NONE never saves; AFTER_VERIFICATION -// saves only at the run's end; PER_CHECKPOINT at every checkpoint's end. -const SaveDecisionCase SAVE_DECISIONS[] = { - {.input = {M::NONE, V::FAILED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, - {.input = {M::NONE, V::FAILED, S::RUN_END}, .expectation = {.saves = false}}, - {.input = {M::NONE, V::PASSED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, - {.input = {M::NONE, V::PASSED, S::RUN_END}, .expectation = {.saves = false}}, - {.input = {M::AFTER_VERIFICATION, V::FAILED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, - {.input = {M::AFTER_VERIFICATION, V::FAILED, S::RUN_END}, .expectation = {.saves = false}}, - {.input = {M::AFTER_VERIFICATION, V::PASSED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, - {.input = {M::AFTER_VERIFICATION, V::PASSED, S::RUN_END}, .expectation = {.saves = true}}, - {.input = {M::PER_CHECKPOINT, V::FAILED, S::CHECKPOINT_END}, .expectation = {.saves = false}}, - {.input = {M::PER_CHECKPOINT, V::FAILED, S::RUN_END}, .expectation = {.saves = false}}, - {.input = {M::PER_CHECKPOINT, V::PASSED, S::CHECKPOINT_END}, .expectation = {.saves = true}}, - {.input = {M::PER_CHECKPOINT, V::PASSED, S::RUN_END}, .expectation = {.saves = true}}, -}; - - // A named check that returns its own failure. struct NamedCheck{ std::string_view name; @@ -234,9 +167,6 @@ const NamedCheck CHECKS[] = { void add_tests_StoryRunTypes(UnitTestDatabase& database){ - for (const SaveDecisionCase& test_case : SAVE_DECISIONS){ - database.add(test_case); - } for (const NamedCheck& check : CHECKS){ database.add(check); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp deleted file mode 100644 index 7fbeebf500..0000000000 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* Story Save Mode - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Pokemon_StorySaveMode.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -std::string story_save_mode_name(StorySaveMode mode){ - switch (mode){ - case StorySaveMode::NONE: - return "none"; - case StorySaveMode::AFTER_VERIFICATION: - return "after_verification"; - case StorySaveMode::PER_CHECKPOINT: - return "per_checkpoint"; - } - return "?"; -} - -bool story_save_allowed(StorySaveMode mode, CheckpointVerdict verdict, SavePoint point){ - if (verdict != CheckpointVerdict::PASSED){ - return false; - } - switch (mode){ - case StorySaveMode::NONE: - return false; - case StorySaveMode::AFTER_VERIFICATION: - return point == SavePoint::RUN_END; - case StorySaveMode::PER_CHECKPOINT: - return true; - } - return false; -} - - - -} // namespace Pokemon -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h deleted file mode 100644 index c06b0f52c5..0000000000 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Story Save Mode - * - * From: https://github.com/PokemonAutomation/ - * - * When an AutoStory run may save the game. A run's own verdict can be - * wrong (a warp confirmed on the next floor while the player is still on - * the one before), and a save made then overwrites the only good one. So a segment - * under test never saves, a verified one saves once at its end, and only - * a playthrough of verified segments saves at each checkpoint. - * - */ - -#ifndef PokemonAutomation_Pokemon_StorySaveMode_H -#define PokemonAutomation_Pokemon_StorySaveMode_H - -#include - -namespace PokemonAutomation{ -namespace Pokemon{ - - -// When a run saves. A failed run never saves, in any mode. -enum class StorySaveMode{ - // Testing: never save; the save the run started from stays. - NONE, - // Verification: save once, at the end of a run that passed. - AFTER_VERIFICATION, - // Reproduction (a playthrough of verified segments): save at the end - // of each checkpoint that passed. - PER_CHECKPOINT, -}; - -// Returns the wire and log name of a save mode: "none", "after_verification", "per_checkpoint". -std::string story_save_mode_name(StorySaveMode mode); - -// How a checkpoint ended: passed (and its postconditions, where checked, -// did not fail) or not. -enum class CheckpointVerdict{ - PASSED, - FAILED, -}; - -// Where a save would be made. -enum class SavePoint{ - // A checkpoint's end, with more checkpoints of the run after it. - CHECKPOINT_END, - // The last checkpoint's end: the run's end state. - RUN_END, -}; - -// Whether a run in `mode` saves at `point` after a checkpoint that ended -// as `verdict`. -bool story_save_allowed(StorySaveMode mode, CheckpointVerdict verdict, SavePoint point); - - - -} // namespace Pokemon -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 75b4e47857..d082af141a 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1481,8 +1481,6 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Types/Pokemon_StoryPostconditions.h Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryRunTypes_Tests.h - Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.cpp - Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h Source/Pokemon/AutoStory/Types/Pokemon_StoryStep.h Source/Pokemon/AutoStory/Types/Pokemon_StoryStepKind.cpp Source/Pokemon/AutoStory/Types/Pokemon_StoryStepKind.h