From e2e48e90aa0ebf9ae758953d36a1984fac2dc078 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 00:15:28 -0800 Subject: [PATCH 1/5] AutoStory: run options, language and checkpoint range dropdowns --- .../AutoStory/Pokemon_AutoStorySelect.h | 17 ++ .../Pokemon_AutoStorySelect_Tests.cpp | 66 +++++++ .../AutoStory/Pokemon_AutoStory_Tests.h | 4 + .../Pokemon_StoryStepExecutor_Tests.cpp | 116 ++++++++++++ .../Pokemon/Options/Pokemon_GameLanguages.cpp | 43 +++++ .../Pokemon/Options/Pokemon_GameLanguages.h | 45 +++++ .../Options/Pokemon_StoryRangeOptions.cpp | 51 +++++ .../Options/Pokemon_StoryRangeOptions.h | 53 ++++++ .../Pokemon_StoryRangeOptions_Tests.cpp | 142 ++++++++++++++ .../Options/Pokemon_StoryRangeOptions_Tests.h | 23 +++ .../Options/Pokemon_StoryRunOptions.cpp | 179 ++++++++++++++++++ .../Pokemon/Options/Pokemon_StoryRunOptions.h | 113 +++++++++++ .../Options/Pokemon_StoryRunOptions_Tests.cpp | 99 ++++++++++ .../Options/Pokemon_StoryRunOptions_Tests.h | 23 +++ SerialPrograms/cmake/SourceFiles.cmake | 10 + 15 files changed, 984 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.cpp create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h index 294dd5d21d..e711f8b1ab 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h @@ -8,6 +8,7 @@ #define PokemonAutomation_Pokemon_AutoStorySelect_H #include +#include #include #include #include "CommonTools/Options/StringSelectOption.h" @@ -40,6 +41,22 @@ StringSelectDatabase make_story_select_database( } +// The start/end dropdown database of a story's checkpoints, given by their +// labels in order ("00.09 Pewter Gym: Camper Liam, then Brock"), slugged +// by their index, as make_story_select_database() slugs SV's. A game whose +// story is in sections (BDSP's segments 00 and 01) passes them joined: a +// section's entry i is then story_index(true, i, first of the section). +// The program keeps it in a function-local static: the options hold a +// reference. +inline StringSelectDatabase story_checkpoint_database(std::span labels){ + StringSelectDatabase database; + for (size_t c = 0; c < labels.size(); c++){ + database.add_entry(StringSelectEntry(std::to_string(c), labels[c])); + } + return database; +} + + // The index in the whole story list of entry `index_in_section` of the // tutorial or the main story, whose first entry is `first_main_story_index`. // NOTE: a section ends where the user must step in (e.g. level up the diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp index efdd49bd8f..c9eae2f1ae 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include @@ -103,6 +104,68 @@ class Test_AutoStorySelectDatabase : public UnitTest{ const AutoStorySelectScenario m_scenario; }; +// (slug, label) entries as [0 "label", ...]. +std::string describe_entries(const std::vector>& entries){ + std::string text; + for (const auto& [slug, label] : entries){ + text += std::format("{}{} \"{}\"", text.empty() ? "" : ", ", slug, label); + } + return std::format("[{}]", text); +} + +// A game's checkpoint labels, in story order. +struct StoryCheckpointDatabaseInput{ + std::vector labels; +}; + +// The (slug, label) entries: one per label, in order, slugged by its index. +struct StoryCheckpointDatabaseExpectation{ + std::vector> entries; +}; + +// story_checkpoint_database() over a game's labels and the entries it must make. +struct StoryCheckpointDatabaseCase{ + std::string name; + StoryCheckpointDatabaseInput input; + StoryCheckpointDatabaseExpectation expectation; +}; + +class Test_StoryCheckpointDatabase : public UnitTest{ +public: + Test_StoryCheckpointDatabase(StoryCheckpointDatabaseCase test_case) + : UnitTest(std::format("Pokemon::AutoStorySelectDatabase - {}", test_case.name)) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const StringSelectDatabase database = story_checkpoint_database(m_case.input.labels); + std::vector> got; + for (const StringSelectEntry& entry : database.case_list()){ + got.emplace_back(entry.slug, entry.display_name); + } + if (got != m_case.expectation.entries){ + return std::format("Expected {}, got {}", describe_entries(m_case.expectation.entries), describe_entries(got)); + } + return true; + } + +private: + const StoryCheckpointDatabaseCase m_case; +}; + +const StoryCheckpointDatabaseCase STORY_CHECKPOINT_DATABASE_CASES[] = { + { + .name = "checkpoint labels slugged by index", + .input = {.labels = {"00.01 Pallet Town", "00.02 Oak's lab"}}, + .expectation = {.entries = {{"0", "00.01 Pallet Town"}, {"1", "00.02 Oak's lab"}}}, + }, + { + .name = "no checkpoints, no entries", + .input = {.labels = {}}, + .expectation = {.entries = {}}, + }, +}; + void add_index_tests(UnitTestDatabase& database){ const AutoStoryIndexScenario scenarios[] = { { @@ -158,6 +221,9 @@ void add_select_database_tests(UnitTestDatabase& database){ for (const AutoStorySelectScenario& scenario : select_scenarios){ database.add(scenario); } + for (const StoryCheckpointDatabaseCase& test_case : STORY_CHECKPOINT_DATABASE_CASES){ + database.add(test_case); + } } } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h index 555e0ed0e9..522e1cb049 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h @@ -21,6 +21,8 @@ #include "Engine/Pokemon_StoryEnginePolicy_Tests.h" #include "Engine/Pokemon_StoryEngineRuns_Tests.h" #include "Engine/Pokemon_StoryEngineSaveRetry_Tests.h" +#include "Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h" +#include "Pokemon/Options/Pokemon_StoryRunOptions_Tests.h" #include "Pokemon_SceneJudges_Tests.h" #include "Pokemon_StoryEvents_Tests.h" #include "Pokemon_StoryFailureClasses_Tests.h" @@ -53,6 +55,8 @@ inline void add_tests_AutoStory(UnitTestDatabase& database){ add_tests_StorySavePolicy(database); add_tests_SceneJudges(database); add_tests_StoryFiles(database); + add_tests_StoryRangeOptions(database); + add_tests_StoryRunOptions(database); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp index 8249895110..e8c7209afe 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp @@ -20,6 +20,9 @@ #include #include #include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/Options/Pokemon_GameLanguages.h" +#include "Pokemon/Options/Pokemon_StoryRunOptions.h" +#include "Pokemon_AutoStorySelect.h" #include "Pokemon_AutoStoryStats.h" #include "Pokemon_StoryEvents.h" #include "Pokemon_BuiltinStoryActions.h" @@ -606,6 +609,60 @@ UnitTestResult test_pause_points(){ } +// Two sections of a story, as BDSP has segments 00 and 01. +const std::vector& two_sections(){ + static const std::vector rows{ + StoryCheckpoint{.id = "00.01", .title = "Leave the house", .start = std::nullopt, .steps = {}}, + StoryCheckpoint{.id = "00.02", .title = "Walk to Sandgem Town", .start = std::nullopt, .steps = {}}, + StoryCheckpoint{.id = "01.01", .title = "Jubilife to Barry", .start = std::nullopt, .steps = {}}, + }; + return rows; +} + +const StringSelectDatabase& two_sections_database(){ + static const StringSelectDatabase database = []{ + std::vector labels; + for (const StoryCheckpoint& checkpoint : two_sections()){ + labels.push_back(story_checkpoint_label(checkpoint)); + } + return story_checkpoint_database(labels); + }(); + return database; +} + +// The dropdowns list the checkpoints as "id title", slugged by their index +// in the whole story, which is story_index() of a section's own index. +UnitTestResult test_checkpoint_dropdowns(){ + const StringSelectDatabase& database = two_sections_database(); + const std::vector expected{"00.01 Leave the house", "00.02 Walk to Sandgem Town", "01.01 Jubilife to Barry"}; + if (database.size() != expected.size()){ + return std::format("Expected 3 entries, got {}", database.size()); + } + for (size_t c = 0; c < expected.size(); c++){ + if (database[c].display_name != expected[c] || database[c].slug != std::to_string(c)){ + return std::format("Unexpected entry {}: {} {}", c, database[c].slug, database[c].display_name); + } + } + if (database[story_index(true, 0, 2)].display_name != "01.01 Jubilife to Barry"){ + return "Expected the second section's first entry at story_index(true, 0, 2)."; + } + if (story_checkpoint_label(StoryCheckpoint{.id = "00.09", .title = "Pewter Gym: Camper Liam, then Brock", .start = std::nullopt, .steps = {}}) + != "00.09 Pewter Gym: Camper Liam, then Brock" + ){ + return "Unexpected label."; + } + StoryRunOptions options(database, Gen8ToGen9Languages_Database()); + if (options.start_index() != 0 || options.end_index() != 2 || !options.check_validity().empty()){ + return "Expected the whole story by default."; + } + options.START_CHECKPOINT.set_by_index(2); + options.END_CHECKPOINT.set_by_index(1); + if (options.check_validity().empty()){ + return "Expected a start after the end to be refused."; + } + return true; +} + // A segment's report in the shared AutoStory stats. UnitTestResult test_story_stats(){ SegmentReport report; @@ -623,6 +680,53 @@ UnitTestResult test_story_stats(){ return true; } +// The program's option group: 3 attempts, no stop, Thorough, by default; +// Fast when chosen. +UnitTestResult test_run_options(){ + StoryRunOptions options(two_sections_database(), Gen8ToGen9Languages_Database()); + const SegmentPolicy policy = options.policy(); + if (policy.attempts_per_checkpoint != 3 || options.check_level() != StoryCheckLevel::DEFAULT){ + return "Expected 3 attempts, no stop at the first failure, and Thorough checks by default."; + } + options.CHECKS.set(StoryCheckLevel::FAST); + if (options.check_level() != StoryCheckLevel::FAST){ + return "Expected Fast checks once chosen."; + } + // Every game language can be chosen, read or not. + if (options.language() != Language::English){ + return "Expected English by default."; + } + options.LANGUAGE.set(Language::Japanese); + if (options.language() != Language::Japanese || !options.check_validity().empty()){ + return "Expected Japanese to be chosen and valid, reader or not."; + } + return true; +} + +// Verify mode: off by default; 3 runs and 2 passes when on, for one +// checkpoint only, never needing more passes than runs. +UnitTestResult test_verify_options(){ + StoryRunOptions options(two_sections_database(), Gen8ToGen9Languages_Database()); + if (options.VERIFY.policy()){ + return "Expected verify mode off by default."; + } + options.VERIFY.set_enabled(true); + if (options.check_validity().empty()){ + return "Expected verify mode refused over more than one checkpoint."; + } + options.END_CHECKPOINT.set_by_index(options.start_index()); + const std::optional policy = options.VERIFY.policy(); + if (!options.check_validity().empty() || !policy || policy->runs != 3 || policy->passes_needed != 2){ + return std::format("Expected 3 runs and 2 passes on one checkpoint: {}", options.check_validity()); + } + options.VERIFY.RUNS.set(2); + options.VERIFY.PASSES.set(3); + if (options.check_validity().empty()){ + return "Expected more passes than runs refused."; + } + return true; +} + UnitTestResult test_lint(){ StoryStep no_target = make(StoryStepKind::ROUTE, "walk"); StoryStep again = make(StoryStepKind::TALK, "walk"); @@ -710,6 +814,18 @@ const StoryStepTestCase STORY_STEP_CASES[] = { .name = "lint", .input = {.test = test_lint}, .expectation = {.description = "verifies lint validation rules on story checkpoints"}, }, + { + .name = "the run options' defaults", .input = {.test = test_run_options}, + .expectation = {.description = "validates initial default story run option values"}, + }, + { + .name = "the run options' verify mode", .input = {.test = test_verify_options}, + .expectation = {.description = "configures verification mode options and passes count"}, + }, + { + .name = "start and end checkpoint dropdowns", .input = {.test = test_checkpoint_dropdowns}, + .expectation = {.description = "populates start and end dropdown selections correctly"}, + }, { .name = "a segment's run in the AutoStory stats", .input = {.test = test_story_stats}, .expectation = {.description = "updates story run statistics following segment completion"}, diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.cpp new file mode 100644 index 0000000000..42f0dadf08 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.cpp @@ -0,0 +1,43 @@ +/* Game Languages + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Pokemon_GameLanguages.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +const EnumDropdownDatabase& Gen8ToGen9Languages_Database(){ + static const EnumDropdownDatabase database({ + {Language::English, "en", "English"}, + {Language::Japanese, "ja", "Japanese"}, + {Language::Spanish, "es", "Spanish"}, + {Language::French, "fr", "French"}, + {Language::German, "de", "German"}, + {Language::Italian, "it", "Italian"}, + {Language::Korean, "ko", "Korean"}, + {Language::ChineseSimplified, "zh-Hans", "Chinese (Simplified)"}, + {Language::ChineseTraditional, "zh-Hant", "Chinese (Traditional)"}, + }); + return database; +} + +const EnumDropdownDatabase& FireRedLeafGreenLanguages_Database(){ + static const EnumDropdownDatabase database({ + {Language::English, "en", "English"}, + {Language::Japanese, "ja", "Japanese"}, + {Language::Spanish, "es", "Spanish"}, + {Language::French, "fr", "French"}, + {Language::German, "de", "German"}, + {Language::Italian, "it", "Italian"}, + }); + return database; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h new file mode 100644 index 0000000000..003767c870 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h @@ -0,0 +1,45 @@ +/* Game Languages + * + * From: https://github.com/PokemonAutomation/ + * + * The languages each game can be played in, as dropdown databases for a + * program's language option. A program offers its game's set, so a user + * can't pick a language the game doesn't have. Every language a game ships + * in is listed, tested on console or not. Code that reads text takes this + * option and never assumes a language. With no reader for the chosen + * language, a name lookup throws InternalProgramError ("No data loaded for + * this language.") and a story step falls back to positions, digits and the + * screen. + * + */ + +#ifndef PokemonAutomation_Pokemon_GameLanguages_H +#define PokemonAutomation_Pokemon_GameLanguages_H + +#include "Common/Cpp/Options/EnumDropdownDatabase.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// The nine languages of the Switch games of generations 8 and 9: Sword and +// Shield, Brilliant Diamond and Shining Pearl, Legends: Arceus, Scarlet and +// Violet, Legends: Z-A. Japanese, English, French, Italian, German, +// Spanish, Korean, Chinese (Simplified and Traditional). The games have one +// Spanish (Spain), hence one "es". +const EnumDropdownDatabase& Gen8ToGen9Languages_Database(); + +// The six languages of FireRed and LeafGreen, the Game Boy Advance +// releases the Switch versions reissue: Japanese, English, French, Italian, +// German, Spanish. On Switch each language is a separate version with no +// in-game language option (Nintendo of America sells English, French and +// Spanish, the latter two in their European form), so the user picks the +// version they own. +const EnumDropdownDatabase& FireRedLeafGreenLanguages_Database(); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp new file mode 100644 index 0000000000..d294e5e386 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp @@ -0,0 +1,51 @@ +/* Story Range Options + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_StoryRangeOptions.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +StoryRangeOptions::StoryRangeOptions(std::string label, const StringSelectDatabase& checkpoints, LockMode end_lock) + : GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING) + , START_CHECKPOINT( + "Start checkpoint:
The program starts from this checkpoint's save.", + checkpoints, + LockMode::LOCK_WHILE_RUNNING, + 0 + ) + , END_CHECKPOINT( + "End checkpoint:
The program stops after this checkpoint.", + checkpoints, + end_lock, + checkpoints.size() == 0 ? 0 : checkpoints.size() - 1 + ) +{ + PA_ADD_OPTION(START_CHECKPOINT); + PA_ADD_OPTION(END_CHECKPOINT); +} + +size_t StoryRangeOptions::start_index() const{ + return START_CHECKPOINT.index(); +} + +size_t StoryRangeOptions::end_index() const{ + return END_CHECKPOINT.index(); +} + +std::string StoryRangeOptions::check_validity() const{ + if (start_index() > end_index()){ + return "The start checkpoint comes after the end checkpoint."; + } + return GroupOption::check_validity(); +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h new file mode 100644 index 0000000000..809f3324d2 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h @@ -0,0 +1,53 @@ +/* Story Range Options + * + * From: https://github.com/PokemonAutomation/ + * + * The start and end checkpoint dropdowns of an AutoStory program, over one + * list of the story's checkpoints, and the check that the start does not + * come after the end. StoryRunOptions (Pokemon_StoryRunOptions.h) is this + * group plus the run policy. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRangeOptions_H +#define PokemonAutomation_Pokemon_StoryRangeOptions_H + +#include +#include "Common/Cpp/Options/GroupOption.h" +#include "CommonTools/Options/StringSelectOption.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// A program shows the group, or adds START_CHECKPOINT and END_CHECKPOINT +// to its own options under its own keys (keeping the keys its saved +// settings already use) and calls check_validity() from its own. +class StoryRangeOptions : public GroupOption{ +public: + // `checkpoints`: the dropdown database (make_story_select_database() + // or story_checkpoint_database()), kept alive by the caller. The + // dropdowns start on its first and last entries. `end_lock`: + // UNLOCK_WHILE_RUNNING for a program that reads the end after each + // checkpoint, so the end can be moved during a run. + StoryRangeOptions( + std::string label, const StringSelectDatabase& checkpoints, + LockMode end_lock = LockMode::LOCK_WHILE_RUNNING + ); + + // The checkpoints chosen, by index in the database, both inclusive. + size_t start_index() const; + size_t end_index() const; + // "The start checkpoint comes after the end checkpoint." if it does. + virtual std::string check_validity() const override; + +public: + StringSelectOption START_CHECKPOINT; + StringSelectOption END_CHECKPOINT; +}; + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp new file mode 100644 index 0000000000..fce811e4c6 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp @@ -0,0 +1,142 @@ +/* Story Range Options Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" +#include "Pokemon_StoryRangeOptions.h" +#include "Pokemon_StoryRangeOptions_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + +namespace{ + +// A stand-in for a story checkpoint: only its name is read. +struct NamedCheckpoint{ + std::string label; + std::string name() const{ + return label; + } +}; + +// Two tutorial checkpoints, then three of the main story, as SV's list is +// laid out. +const std::vector>& story_list(){ + static const std::vector> list = []{ + std::vector> ret; + for (std::string_view label : {"tutorial 0", "tutorial 1", "main 0", "main 1", "main 2"}){ + ret.emplace_back(std::make_unique(NamedCheckpoint{.label = std::string(label)})); + } + return ret; + }(); + return list; +} + +// The main story's dropdowns: entries 2..4 of the list, slugged 2..4. +const StringSelectDatabase& main_story_database(){ + static const StringSelectDatabase database = make_story_select_database(story_list(), 2, story_list().size()); + return database; +} + +// A range chosen in the main story's dropdowns and what the group reads from it. +struct StoryRangeCase{ + // The start and end set by slug, as saved settings load them; empty + // leaves the default. + struct Input{ + std::string start_slug; + std::string end_slug; + }; + + // The indexes in the dropdown, and whether the range is valid. + struct Expectation{ + size_t start; + size_t end; + bool valid; + }; + + std::string name; + Input input; + Expectation expectation; +}; + +class Test_StoryRange : public UnitTest{ +public: + Test_StoryRange(StoryRangeCase test_case) + : UnitTest(std::format("Pokemon::StoryRangeOptions - {}", test_case.name)) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + StoryRangeOptions range("Checkpoints", main_story_database()); + if (!m_case.input.start_slug.empty()){ + range.START_CHECKPOINT.set_by_slug(m_case.input.start_slug); + } + if (!m_case.input.end_slug.empty()){ + range.END_CHECKPOINT.set_by_slug(m_case.input.end_slug); + } + const StoryRangeCase::Expectation& expected = m_case.expectation; + if (range.start_index() != expected.start || range.end_index() != expected.end){ + return std::format( + "Expected indexes {} to {}, got {} to {}", + expected.start, expected.end, range.start_index(), range.end_index() + ); + } + const std::string error = range.check_validity(); + if (error.empty() != expected.valid){ + return expected.valid ? std::format("Expected a valid range, got: {}", error) : "Expected the range refused."; + } + if (!expected.valid && error != "The start checkpoint comes after the end checkpoint."){ + return std::format("Unexpected message: {}", error); + } + return true; + } + +private: + const StoryRangeCase m_case; +}; + +const StoryRangeCase STORY_RANGE_CASES[] = { + { + .name = "the whole database by default", + .input = {.start_slug = "", .end_slug = ""}, + .expectation = {.start = 0, .end = 2, .valid = true}, + }, + { + .name = "slugs are whole-list indexes, indexes are the dropdown's", + .input = {.start_slug = "3", .end_slug = "4"}, + .expectation = {.start = 1, .end = 2, .valid = true}, + }, + { + .name = "one checkpoint", + .input = {.start_slug = "3", .end_slug = "3"}, + .expectation = {.start = 1, .end = 1, .valid = true}, + }, + { + .name = "a start after the end is refused", + .input = {.start_slug = "4", .end_slug = "2"}, + .expectation = {.start = 2, .end = 0, .valid = false}, + }, +}; + +} // namespace + + +void add_tests_StoryRangeOptions(UnitTestDatabase& database){ + for (const StoryRangeCase& test_case : STORY_RANGE_CASES){ + database.add(test_case); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h new file mode 100644 index 0000000000..1d3e48e19d --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h @@ -0,0 +1,23 @@ +/* Story Range Options Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRangeOptions_Tests_H +#define PokemonAutomation_Pokemon_StoryRangeOptions_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the shared start/end checkpoint range options. +void add_tests_StoryRangeOptions(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp new file mode 100644 index 0000000000..ff601182f6 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp @@ -0,0 +1,179 @@ +/* Story Run Options + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Pokemon_StoryRunOptions.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +const EnumDropdownDatabase& StoryCheckLevel_Database(){ + static const EnumDropdownDatabase database({ + {StoryCheckLevel::TESTING, "testing", "Testing: run each checkpoint 3 times to be sure it really passes"}, + {StoryCheckLevel::THOROUGH, "thorough", "Thorough: check everything for the user (Bag items, Pok\u00e9mon stats, preconditions)"}, + {StoryCheckLevel::DEFAULT, "default", "Default: check the most important things, assume the rest is fine"}, + {StoryCheckLevel::FAST, "fast", "Fast: minimal checks"}, + {StoryCheckLevel::SPEEDRUN, "speedrun", "Speedrun: almost no checks, as fast as possible"}, + }); + return database; +} + + +const EnumDropdownDatabase& StorySaveMode_Database(){ + static const EnumDropdownDatabase database({ + {StorySaveMode::NONE, "none", "None: never save (testing a checkpoint; the start save stays)"}, + {StorySaveMode::AFTER_VERIFICATION, "after_verification", "After verification: save once, at the end of a run that passed"}, + {StorySaveMode::PER_CHECKPOINT, "per_checkpoint", "Each checkpoint: save after each checkpoint that passed (a playthrough)"}, + }); + return database; +} + + +namespace{ + +constexpr std::string_view SAVE_MODE_LABEL = + "Save:
When the run saves the game. A failed run never saves. " + "None keeps the save the run started from. After verification saves once, at the end of a run that passed " + "(in Verify Mode, at the end of the last run, when every run passed). Each checkpoint saves after each " + "checkpoint that passed, for a playthrough of verified checkpoints."; + +constexpr std::string_view RELOAD_AT_START_LABEL = + "Reload the Save at the Start:
Close the game and load the save before the first checkpoint. " + "Off: start from wherever the game is (resumed from HOME if need be), for a game already at the start checkpoint. " + "Later checkpoints reload as usual. Off needs Save set to None."; + +} // namespace + + +std::string story_checkpoint_label(const StoryCheckpoint& checkpoint){ + return checkpoint.title.empty() ? checkpoint.id : std::format("{} {}", checkpoint.id, checkpoint.title); +} + + + +StoryVerifyOptions::StoryVerifyOptions() + : GroupOption( + "Verify Mode: run the start checkpoint (also the end) from its save several times. " + "Only with Save set to After verification does the last run save at its end, when every run passed", + LockMode::LOCK_WHILE_RUNNING, + EnableMode::DEFAULT_DISABLED + ) + , RUNS( + "Runs:
Runs of the checkpoint, each from its save.", + LockMode::LOCK_WHILE_RUNNING, + 3, 1, 20 + ) + , PASSES( + "Passes needed:
Runs that must pass for the checkpoint to be verified.", + LockMode::LOCK_WHILE_RUNNING, + 2, 1, 20 + ) +{ + PA_ADD_OPTION(RUNS); + PA_ADD_OPTION(PASSES); +} + +std::optional StoryVerifyOptions::policy() const{ + if (!enabled()){ + return std::nullopt; + } + return VerifyPolicy{.runs = RUNS, .passes_needed = PASSES}; +} + +std::string StoryVerifyOptions::check_validity() const{ + if (enabled() && PASSES > RUNS){ + return "Verify mode can't need more passes than it has runs."; + } + return GroupOption::check_validity(); +} + + +StoryRunOptions::StoryRunOptions(const StringSelectDatabase& checkpoints, const EnumDropdownDatabase& languages) + : StoryRangeOptions("Story Run", checkpoints) + , ATTEMPTS_PER_CHECKPOINT( + "Attempts per checkpoint:
A failed checkpoint reloads its save and runs again, up to this many times in all. " + "1 stops at the first failure, leaving the game where it failed.", + LockMode::LOCK_WHILE_RUNNING, + 3, 1, 20 + ) + , CHECKS( + "Checks:
How much each step reads the screen to confirm what it did, from Testing (the most) to Speedrun (almost none).", + StoryCheckLevel_Database(), + LockMode::LOCK_WHILE_RUNNING, + StoryCheckLevel::DEFAULT + ) + , LANGUAGE( + "Game language:
For the few reads that need text (item names in a shop or the Bag). " + "Story steps never match dialogue text; with no reader for this language they check positions, digits and the screen instead.", + languages, + LockMode::LOCK_WHILE_RUNNING, + Language::English + ) + , SAVE_MODE(std::string(SAVE_MODE_LABEL), StorySaveMode_Database(), LockMode::LOCK_WHILE_RUNNING, StorySaveMode::NONE) + , RELOAD_AT_START(std::string(RELOAD_AT_START_LABEL), LockMode::LOCK_WHILE_RUNNING, true) + , POSTCONDITIONS_ONLY( + "Check postconditions only:
Run nothing: read where the game stands and check the end checkpoint's " + "position, items and flags. What the game can't read yet is reported as not checked.", + LockMode::LOCK_WHILE_RUNNING, + false + ) +{ + PA_ADD_OPTION(ATTEMPTS_PER_CHECKPOINT); + PA_ADD_OPTION(CHECKS); + PA_ADD_OPTION(LANGUAGE); + PA_ADD_OPTION(VERIFY); + PA_ADD_OPTION(SAVE_MODE); + PA_ADD_OPTION(RELOAD_AT_START); + PA_ADD_OPTION(POSTCONDITIONS_ONLY); +} + +std::string StoryRunOptions::check_validity() const{ + std::string error = StoryRangeOptions::check_validity(); + if (!error.empty()){ + return error; + } + if (VERIFY.enabled() && start_index() != end_index()){ + return "Verify mode runs one checkpoint: set the end checkpoint to the start checkpoint."; + } + if (VERIFY.enabled() && POSTCONDITIONS_ONLY){ + return "Check postconditions only runs nothing: turn off Verify Mode."; + } + if (!RELOAD_AT_START && SAVE_MODE != StorySaveMode::NONE){ + return "Reload the Save at the Start is off: the run starts from wherever the game is, which nothing checked, " + "so it must not save. Set Save to None or turn the reload on."; + } + return error; +} + +SegmentPolicy StoryRunOptions::policy() const{ + SegmentPolicy policy; + policy.attempts_per_checkpoint = ATTEMPTS_PER_CHECKPOINT; + policy.save_mode = SAVE_MODE; + return policy; +} + +std::optional StoryRunOptions::verify_policy() const{ + std::optional policy = VERIFY.policy(); + if (policy){ + policy->save_mode = SAVE_MODE; + } + return policy; +} + +StoryCheckLevel StoryRunOptions::check_level() const{ + return CHECKS; +} + +Language StoryRunOptions::language() const{ + return LANGUAGE; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h new file mode 100644 index 0000000000..0029ea908c --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h @@ -0,0 +1,113 @@ +/* Story Run Options + * + * From: https://github.com/PokemonAutomation/ + * + * The options every AutoStory program shows for where to start and end, how + * hard to try and how much to check: the shared range group + * (Pokemon_StoryRangeOptions.h) plus the run policy, read into the shared + * SegmentPolicy (Pokemon/AutoStory/Pokemon_StorySegments.h), the checks + * level (Types/Pokemon_StoryCheckLevel.h), the language the game's steps + * read text in, when the run saves (Types/Pokemon_StorySaveMode.h), + * whether it reloads the save before its first checkpoint and whether it + * only checks postconditions. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRunOptions_H +#define PokemonAutomation_Pokemon_StoryRunOptions_H + +#include +#include +#include +#include +#include "Common/Cpp/Options/BooleanCheckBoxOption.h" +#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "Common/Cpp/Options/GroupOption.h" +#include "Common/Cpp/Options/SimpleIntegerOption.h" +#include "CommonFramework/Language.h" +#include "CommonTools/Options/StringSelectOption.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" +#include "Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h" +#include "Pokemon_StoryRangeOptions.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// A checkpoint's label in the start and end dropdowns, as SV labels its +// segments: "00.09 Pewter Gym: Camper Liam, then Brock". The labels of a +// story's checkpoints, in order, make its dropdowns +// (story_checkpoint_database()). +std::string story_checkpoint_label(const StoryCheckpoint& checkpoint); + + +// Verify mode, off by default (verify_checkpoint()): the start checkpoint +// RUNS times from its save; verified when at least PASSES pass. Only the +// last run may save, at its end, when SAVE_MODE is After verification +// and every run passed. For a battle that has lost twice or more, given +// its own checkpoint saved right before it. +class StoryVerifyOptions : public GroupOption{ +public: + StoryVerifyOptions(); + + // The runs and passes, unset when verify mode is off. + std::optional policy() const; + virtual std::string check_validity() const override; + +public: + SimpleIntegerOption RUNS; + SimpleIntegerOption PASSES; +}; + + +// The range group (START_CHECKPOINT, END_CHECKPOINT, start_index(), +// end_index()) with the run policy added to the same group, so the saved +// settings keep one flat object. +class StoryRunOptions : public StoryRangeOptions{ +public: + // `checkpoints`: story_checkpoint_database() of the game's story, kept + // alive by the caller; the dropdowns start on its first and last. + // `languages`: the ones the game has (Pokemon_GameLanguages.h). + StoryRunOptions(const StringSelectDatabase& checkpoints, const EnumDropdownDatabase& languages); + + // The range's check, then verify mode's: one checkpoint only; then a + // run without the reload at the start must not save. + virtual std::string check_validity() const override; + + // The policy these options set, with the save mode. + SegmentPolicy policy() const; + // Verify mode's runs and passes with the save mode; unset when off. + std::optional verify_policy() const; + // The checks level, for the game's steps to read. + StoryCheckLevel check_level() const; + // The game's language, for the steps that read text. + Language language() const; + +public: + SimpleIntegerOption ATTEMPTS_PER_CHECKPOINT; + EnumDropdownOption CHECKS; + // Any language the game has, whether or not a reader supports it: + // steps without one use language-free checks, so none is refused. + EnumDropdownOption LANGUAGE; + // On, it runs one checkpoint: the start, which must also be the end. + StoryVerifyOptions VERIFY; + // When the run saves; NONE (testing) by default. + EnumDropdownOption SAVE_MODE; + // On (the default), the run loads the save before its first + // checkpoint (StoryLaunchRequest::Running::RESTART). Off, it starts + // from where the game is, resumed from HOME if need be (Running::KEEP); + // later checkpoints reload as before. Off needs SAVE_MODE NONE: the + // run must not save from a position nothing checked. + BooleanCheckBoxOption RELOAD_AT_START; + // On, nothing runs: the game reads where it stands and checks the end + // checkpoint's postconditions (Pokemon_StoryPostconditionCheck.h). + BooleanCheckBoxOption POSTCONDITIONS_ONLY; +}; + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp new file mode 100644 index 0000000000..c9f62e050d --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp @@ -0,0 +1,99 @@ +/* Story Run Options Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" +#include "Pokemon_GameLanguages.h" +#include "Pokemon_StoryRunOptions.h" +#include "Pokemon_StoryRunOptions_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + +namespace{ + +// Two checkpoints' dropdowns. +const StringSelectDatabase& two_checkpoints(){ + static const StringSelectDatabase database = story_checkpoint_database(std::vector{"01.01", "01.02"}); + return database; +} + +// The reload at the start and the save mode a user set, and whether the +// options let the run start. +struct ReloadAtStartCase{ + struct Input{ + bool reload_at_start; + StorySaveMode save_mode; + }; + struct Expectation{ + // Empty: the options are valid; else the refusal's message. + std::string_view error; + }; + std::string_view name; + Input input; + Expectation expectation; +}; + +constexpr std::string_view NO_RELOAD_SAVES = + "Reload the Save at the Start is off: the run starts from wherever the game is, which nothing checked, " + "so it must not save. Set Save to None or turn the reload on."; + +const ReloadAtStartCase RELOAD_AT_START_CASES[] = { + {.name = "reload at the start by default", .input = {.reload_at_start = true, .save_mode = StorySaveMode::NONE}, + .expectation = {.error = ""}}, + {.name = "a reloaded run may save", .input = {.reload_at_start = true, .save_mode = StorySaveMode::PER_CHECKPOINT}, + .expectation = {.error = ""}}, + {.name = "no reload without saves", .input = {.reload_at_start = false, .save_mode = StorySaveMode::NONE}, + .expectation = {.error = ""}}, + {.name = "no reload refuses saves after verification", .input = {.reload_at_start = false, .save_mode = StorySaveMode::AFTER_VERIFICATION}, + .expectation = {.error = NO_RELOAD_SAVES}}, + {.name = "no reload refuses saves per checkpoint", .input = {.reload_at_start = false, .save_mode = StorySaveMode::PER_CHECKPOINT}, + .expectation = {.error = NO_RELOAD_SAVES}}, +}; + +class Test_ReloadAtStart : public UnitTest{ +public: + explicit Test_ReloadAtStart(ReloadAtStartCase test_case) + : UnitTest(std::format("Pokemon::StoryRunOptions - {}", test_case.name)) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + StoryRunOptions run(two_checkpoints(), Gen8ToGen9Languages_Database()); + if (!run.RELOAD_AT_START){ + return "Expected the reload at the start on by default."; + } + run.RELOAD_AT_START = m_case.input.reload_at_start; + run.SAVE_MODE.set(m_case.input.save_mode); + const std::string error = run.check_validity(); + if (error != m_case.expectation.error){ + return std::format("Expected \"{}\", got \"{}\".", m_case.expectation.error, error); + } + return true; + } + +private: + const ReloadAtStartCase m_case; +}; + +} // namespace + + +void add_tests_StoryRunOptions(UnitTestDatabase& database){ + for (const ReloadAtStartCase& test_case : RELOAD_AT_START_CASES){ + database.add(test_case); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.h new file mode 100644 index 0000000000..1ebc703cd0 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.h @@ -0,0 +1,23 @@ +/* Story Run Options Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRunOptions_Tests_H +#define PokemonAutomation_Pokemon_StoryRunOptions_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the shared run options' checks. +void add_tests_StoryRunOptions(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index ef854e0700..df9a705d19 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1606,6 +1606,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Options/Pokemon_BoxSortingTable.cpp Source/Pokemon/Options/Pokemon_BoxSortingTable.h Source/Pokemon/Options/Pokemon_EncounterBotOptions.h + Source/Pokemon/Options/Pokemon_GameLanguages.cpp + Source/Pokemon/Options/Pokemon_GameLanguages.h Source/Pokemon/Options/Pokemon_HomeSpriteSelectOption.cpp Source/Pokemon/Options/Pokemon_HomeSpriteSelectOption.h Source/Pokemon/Options/Pokemon_IvJudgeOption.cpp @@ -1626,6 +1628,14 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_CheckpointId.h Source/Pokemon/AutoStory/Pokemon_CheckpointId_Tests.cpp Source/Pokemon/AutoStory/Pokemon_CheckpointId_Tests.h + Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp + Source/Pokemon/Options/Pokemon_StoryRangeOptions.h + Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp + Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h + Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp + Source/Pokemon/Options/Pokemon_StoryRunOptions.h + Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp + Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.h Source/Pokemon/Pokemon_AdvRng.cpp Source/Pokemon/Pokemon_AdvRng.h Source/Pokemon/Pokemon_BdspRng.cpp From 8303d68f3bf5113fc75e8177d430576e240bfffd Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 01:04:49 -0800 Subject: [PATCH 2/5] AutoStory run options: no claim the check level does not keep; databases file-local The Testing check level said it runs each checkpoint 3 times, which is verify mode's job; the text now says what it checks. The two dropdown databases are declared in no header, so they move into the unnamed namespace. Also finishes the executor test table merge. --- .../Pokemon_StoryStepExecutor_Tests.cpp | 70 +------------------ .../Options/Pokemon_StoryRunOptions.cpp | 7 +- 2 files changed, 6 insertions(+), 71 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp index 7ac64d2c25..d88338efed 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp @@ -774,72 +774,6 @@ class Test_StoryStepExecutor : public UnitTest{ }; const StoryStepTestCase STORY_STEP_CASES[] = { -<<<<<<< HEAD - { - .name = "steps run in table order", .input = {.test = test_events_in_table_order}, - .expectation = {.description = "executes story steps sequentially as defined in table"}, - }, - { - .name = "skip_if asks the executor", .input = {.test = test_skip_if}, - .expectation = {.description = "delegates skip condition check to executor"}, - }, - { - .name = "each step starts where the last left the player", .input = {.test = test_pose_propagation}, - .expectation = {.description = "propagates player pose across sequential step executions"}, - }, - { - .name = "a failure names its step", .input = {.test = test_failure_names_the_step}, - .expectation = {.description = "records failing step identifier on error"}, - }, - { - .name = "unsupported kinds and lost battles", .input = {.test = test_unsupported_and_lost_battles}, - .expectation = {.description = "flags unsupported step types and handles battle defeat"}, - }, - { - .name = "tables as a segment, with a reload", .input = {.test = test_segment_of_tables}, - .expectation = {.description = "converts step tables into segment with checkpoint reload support"}, - }, - { - .name = "pause points pause before each step", .input = {.test = test_pause_points}, - .expectation = {.description = "calls the game's pause points before each step that runs"}, - }, - { - .name = "lint", .input = {.test = test_lint}, - .expectation = {.description = "verifies lint validation rules on story checkpoints"}, - }, - { - .name = "the run options' defaults", .input = {.test = test_run_options}, - .expectation = {.description = "validates initial default story run option values"}, - }, - { - .name = "the run options' verify mode", .input = {.test = test_verify_options}, - .expectation = {.description = "configures verification mode options and passes count"}, - }, - { - .name = "start and end checkpoint dropdowns", .input = {.test = test_checkpoint_dropdowns}, - .expectation = {.description = "populates start and end dropdown selections correctly"}, - }, - { - .name = "a segment's run in the AutoStory stats", .input = {.test = test_story_stats}, - .expectation = {.description = "updates story run statistics following segment completion"}, - }, - { - .name = "policy: attempts per checkpoint, then fail", .input = {.test = test_policy_attempts_then_fail}, - .expectation = {.description = "enforces max checkpoint attempt policy before terminal failure"}, - }, - { - .name = "policy: one attempt stops at the first failure", .input = {.test = test_policy_stop_at_first_failure}, - .expectation = {.description = "halts without a reload when a checkpoint has one attempt"}, - }, - { - .name = "once per save: a retry skips what changed nothing", .input = {.test = test_once_per_save_retry}, - .expectation = {.description = "skips steps that changed nothing during once per save retry"}, - }, - { - .name = "once per save: verify runs prepare once", .input = {.test = test_once_per_save_verify}, - .expectation = {.description = "executes once per save prepare step only once during verification"}, - }, -======= {.name = "steps run in table order", .test = test_events_in_table_order}, {.name = "skip_if asks the executor", .test = test_skip_if}, {.name = "each step starts where the last left the player", .test = test_pose_propagation}, @@ -848,12 +782,14 @@ const StoryStepTestCase STORY_STEP_CASES[] = { {.name = "tables as a segment, with a reload", .test = test_segment_of_tables}, {.name = "pause points pause before each step", .test = test_pause_points}, {.name = "lint", .test = test_lint}, + {.name = "the run options' defaults", .test = test_run_options}, + {.name = "the run options' verify mode", .test = test_verify_options}, + {.name = "start and end checkpoint dropdowns", .test = test_checkpoint_dropdowns}, {.name = "a segment's run in the AutoStory stats", .test = test_story_stats}, {.name = "policy: attempts per checkpoint, then fail", .test = test_policy_attempts_then_fail}, {.name = "policy: one attempt stops at the first failure", .test = test_policy_stop_at_first_failure}, {.name = "once per save: a retry skips what changed nothing", .test = test_once_per_save_retry}, {.name = "once per save: verify runs prepare once", .test = test_once_per_save_verify}, ->>>>>>> plza/upstream/s2-08 }; } // namespace diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp index ff601182f6..c356710e39 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp @@ -12,9 +12,11 @@ namespace PokemonAutomation{ namespace Pokemon{ +namespace{ + const EnumDropdownDatabase& StoryCheckLevel_Database(){ static const EnumDropdownDatabase database({ - {StoryCheckLevel::TESTING, "testing", "Testing: run each checkpoint 3 times to be sure it really passes"}, + {StoryCheckLevel::TESTING, "testing", "Testing: check everything, as Thorough does, while a checkpoint is new"}, {StoryCheckLevel::THOROUGH, "thorough", "Thorough: check everything for the user (Bag items, Pok\u00e9mon stats, preconditions)"}, {StoryCheckLevel::DEFAULT, "default", "Default: check the most important things, assume the rest is fine"}, {StoryCheckLevel::FAST, "fast", "Fast: minimal checks"}, @@ -33,9 +35,6 @@ const EnumDropdownDatabase& StorySaveMode_Database(){ return database; } - -namespace{ - constexpr std::string_view SAVE_MODE_LABEL = "Save:
When the run saves the game. A failed run never saves. " "None keeps the save the run started from. After verification saves once, at the end of a run that passed " From fdbe36650c1197c946dae71c1c90b90899437943 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 01:14:01 -0800 Subject: [PATCH 3/5] AutoStory: StoryCheckLevel is added here with the run options that choose it --- .../Types/Pokemon_StoryCheckLevel.cpp | 32 ++++++++++++++ .../AutoStory/Types/Pokemon_StoryCheckLevel.h | 43 +++++++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 3 files changed, 77 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.cpp create 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 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/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 165a929ec3..4a6cb2cd55 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1572,6 +1572,8 @@ 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 ca36d6f4b11c164d135e86162aec4e65d5b88eef Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 12:26:50 -0800 Subject: [PATCH 4/5] StoryRunOptions: drop SAVE_MODE, POSTCONDITIONS_ONLY and verify mode One input is left for saving: the row's execution.save, plus the attempts per checkpoint. --- .../Pokemon_StoryStepExecutor_Tests.cpp | 28 +----- .../Options/Pokemon_StoryRunOptions.cpp | 97 +------------------ .../Pokemon/Options/Pokemon_StoryRunOptions.h | 60 ++---------- .../Options/Pokemon_StoryRunOptions_Tests.cpp | 22 +---- 4 files changed, 15 insertions(+), 192 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp index fc9c40279d..e1c6b8e335 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp @@ -431,8 +431,7 @@ UnitTestResult test_story_stats(){ // Fast when chosen. UnitTestResult test_run_options(){ StoryRunOptions options(two_sections_database(), Gen8ToGen9Languages_Database()); - const SegmentPolicy policy = options.policy(); - if (policy.attempts_per_checkpoint != 3 || options.check_level() != StoryCheckLevel::DEFAULT){ + if (options.ATTEMPTS_PER_CHECKPOINT != 3 || options.check_level() != StoryCheckLevel::DEFAULT){ return "Expected 3 attempts, no stop at the first failure, and Thorough checks by default."; } options.CHECKS.set(StoryCheckLevel::FAST); @@ -450,30 +449,6 @@ UnitTestResult test_run_options(){ return true; } -// Verify mode: off by default; 3 runs and 2 passes when on, for one -// checkpoint only, never needing more passes than runs. -UnitTestResult test_verify_options(){ - StoryRunOptions options(two_sections_database(), Gen8ToGen9Languages_Database()); - if (options.VERIFY.policy()){ - return "Expected verify mode off by default."; - } - options.VERIFY.set_enabled(true); - if (options.check_validity().empty()){ - return "Expected verify mode refused over more than one checkpoint."; - } - options.END_CHECKPOINT.set_by_index(options.start_index()); - const std::optional policy = options.VERIFY.policy(); - if (!options.check_validity().empty() || !policy || policy->runs != 3 || policy->passes_needed != 2){ - return std::format("Expected 3 runs and 2 passes on one checkpoint: {}", options.check_validity()); - } - options.VERIFY.RUNS.set(2); - options.VERIFY.PASSES.set(3); - if (options.check_validity().empty()){ - return "Expected more passes than runs refused."; - } - return true; -} - UnitTestResult test_lint(){ StoryStep no_target = make(StoryStepKind::ROUTE, "walk"); StoryStep again = make(StoryStepKind::TALK, "walk"); @@ -529,7 +504,6 @@ const StoryStepTestCase STORY_STEP_CASES[] = { {.name = "pause points pause before each step", .test = test_pause_points}, {.name = "lint", .test = test_lint}, {.name = "the run options' defaults", .test = test_run_options}, - {.name = "the run options' verify mode", .test = test_verify_options}, {.name = "start and end checkpoint dropdowns", .test = test_checkpoint_dropdowns}, {.name = "a segment's run in the AutoStory stats", .test = test_story_stats}, }; diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp index c356710e39..b4897e6772 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp @@ -26,25 +26,10 @@ const EnumDropdownDatabase& StoryCheckLevel_Database(){ } -const EnumDropdownDatabase& StorySaveMode_Database(){ - static const EnumDropdownDatabase database({ - {StorySaveMode::NONE, "none", "None: never save (testing a checkpoint; the start save stays)"}, - {StorySaveMode::AFTER_VERIFICATION, "after_verification", "After verification: save once, at the end of a run that passed"}, - {StorySaveMode::PER_CHECKPOINT, "per_checkpoint", "Each checkpoint: save after each checkpoint that passed (a playthrough)"}, - }); - return database; -} - -constexpr std::string_view SAVE_MODE_LABEL = - "Save:
When the run saves the game. A failed run never saves. " - "None keeps the save the run started from. After verification saves once, at the end of a run that passed " - "(in Verify Mode, at the end of the last run, when every run passed). Each checkpoint saves after each " - "checkpoint that passed, for a playthrough of verified checkpoints."; - constexpr std::string_view RELOAD_AT_START_LABEL = "Reload the Save at the Start:
Close the game and load the save before the first checkpoint. " "Off: start from wherever the game is (resumed from HOME if need be), for a game already at the start checkpoint. " - "Later checkpoints reload as usual. Off needs Save set to None."; + "Later checkpoints reload as usual."; } // namespace @@ -55,43 +40,6 @@ std::string story_checkpoint_label(const StoryCheckpoint& checkpoint){ -StoryVerifyOptions::StoryVerifyOptions() - : GroupOption( - "Verify Mode: run the start checkpoint (also the end) from its save several times. " - "Only with Save set to After verification does the last run save at its end, when every run passed", - LockMode::LOCK_WHILE_RUNNING, - EnableMode::DEFAULT_DISABLED - ) - , RUNS( - "Runs:
Runs of the checkpoint, each from its save.", - LockMode::LOCK_WHILE_RUNNING, - 3, 1, 20 - ) - , PASSES( - "Passes needed:
Runs that must pass for the checkpoint to be verified.", - LockMode::LOCK_WHILE_RUNNING, - 2, 1, 20 - ) -{ - PA_ADD_OPTION(RUNS); - PA_ADD_OPTION(PASSES); -} - -std::optional StoryVerifyOptions::policy() const{ - if (!enabled()){ - return std::nullopt; - } - return VerifyPolicy{.runs = RUNS, .passes_needed = PASSES}; -} - -std::string StoryVerifyOptions::check_validity() const{ - if (enabled() && PASSES > RUNS){ - return "Verify mode can't need more passes than it has runs."; - } - return GroupOption::check_validity(); -} - - StoryRunOptions::StoryRunOptions(const StringSelectDatabase& checkpoints, const EnumDropdownDatabase& languages) : StoryRangeOptions("Story Run", checkpoints) , ATTEMPTS_PER_CHECKPOINT( @@ -113,55 +61,12 @@ StoryRunOptions::StoryRunOptions(const StringSelectDatabase& checkpoints, const LockMode::LOCK_WHILE_RUNNING, Language::English ) - , SAVE_MODE(std::string(SAVE_MODE_LABEL), StorySaveMode_Database(), LockMode::LOCK_WHILE_RUNNING, StorySaveMode::NONE) , RELOAD_AT_START(std::string(RELOAD_AT_START_LABEL), LockMode::LOCK_WHILE_RUNNING, true) - , POSTCONDITIONS_ONLY( - "Check postconditions only:
Run nothing: read where the game stands and check the end checkpoint's " - "position, items and flags. What the game can't read yet is reported as not checked.", - LockMode::LOCK_WHILE_RUNNING, - false - ) { PA_ADD_OPTION(ATTEMPTS_PER_CHECKPOINT); PA_ADD_OPTION(CHECKS); PA_ADD_OPTION(LANGUAGE); - PA_ADD_OPTION(VERIFY); - PA_ADD_OPTION(SAVE_MODE); PA_ADD_OPTION(RELOAD_AT_START); - PA_ADD_OPTION(POSTCONDITIONS_ONLY); -} - -std::string StoryRunOptions::check_validity() const{ - std::string error = StoryRangeOptions::check_validity(); - if (!error.empty()){ - return error; - } - if (VERIFY.enabled() && start_index() != end_index()){ - return "Verify mode runs one checkpoint: set the end checkpoint to the start checkpoint."; - } - if (VERIFY.enabled() && POSTCONDITIONS_ONLY){ - return "Check postconditions only runs nothing: turn off Verify Mode."; - } - if (!RELOAD_AT_START && SAVE_MODE != StorySaveMode::NONE){ - return "Reload the Save at the Start is off: the run starts from wherever the game is, which nothing checked, " - "so it must not save. Set Save to None or turn the reload on."; - } - return error; -} - -SegmentPolicy StoryRunOptions::policy() const{ - SegmentPolicy policy; - policy.attempts_per_checkpoint = ATTEMPTS_PER_CHECKPOINT; - policy.save_mode = SAVE_MODE; - return policy; -} - -std::optional StoryRunOptions::verify_policy() const{ - std::optional policy = VERIFY.policy(); - if (policy){ - policy->save_mode = SAVE_MODE; - } - return policy; } StoryCheckLevel StoryRunOptions::check_level() const{ diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h index 0029ea908c..d8d12c7f48 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h @@ -4,12 +4,10 @@ * * The options every AutoStory program shows for where to start and end, how * hard to try and how much to check: the shared range group - * (Pokemon_StoryRangeOptions.h) plus the run policy, read into the shared - * SegmentPolicy (Pokemon/AutoStory/Pokemon_StorySegments.h), the checks - * level (Types/Pokemon_StoryCheckLevel.h), the language the game's steps - * read text in, when the run saves (Types/Pokemon_StorySaveMode.h), - * whether it reloads the save before its first checkpoint and whether it - * only checks postconditions. + * (Pokemon_StoryRangeOptions.h) plus the attempts per checkpoint, the + * checks level (Types/Pokemon_StoryCheckLevel.h), the language the game's + * steps read text in, and whether it reloads the save before its first + * checkpoint. * */ @@ -17,19 +15,14 @@ #define PokemonAutomation_Pokemon_StoryRunOptions_H #include -#include -#include #include #include "Common/Cpp/Options/BooleanCheckBoxOption.h" #include "Common/Cpp/Options/EnumDropdownOption.h" -#include "Common/Cpp/Options/GroupOption.h" #include "Common/Cpp/Options/SimpleIntegerOption.h" #include "CommonFramework/Language.h" #include "CommonTools/Options/StringSelectOption.h" -#include "Pokemon/AutoStory/Pokemon_StorySegments.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" -#include "Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h" #include "Pokemon_StoryRangeOptions.h" namespace PokemonAutomation{ @@ -43,28 +36,10 @@ namespace Pokemon{ std::string story_checkpoint_label(const StoryCheckpoint& checkpoint); -// Verify mode, off by default (verify_checkpoint()): the start checkpoint -// RUNS times from its save; verified when at least PASSES pass. Only the -// last run may save, at its end, when SAVE_MODE is After verification -// and every run passed. For a battle that has lost twice or more, given -// its own checkpoint saved right before it. -class StoryVerifyOptions : public GroupOption{ -public: - StoryVerifyOptions(); - - // The runs and passes, unset when verify mode is off. - std::optional policy() const; - virtual std::string check_validity() const override; - -public: - SimpleIntegerOption RUNS; - SimpleIntegerOption PASSES; -}; - - // The range group (START_CHECKPOINT, END_CHECKPOINT, start_index(), -// end_index()) with the run policy added to the same group, so the saved -// settings keep one flat object. +// end_index()) with the run's options added to the same group, so the +// saved settings keep one flat object. Each checkpoint that passes saves +// as its row's execution says (the game's own autosave, or the menu). class StoryRunOptions : public StoryRangeOptions{ public: // `checkpoints`: story_checkpoint_database() of the game's story, kept @@ -72,14 +47,6 @@ class StoryRunOptions : public StoryRangeOptions{ // `languages`: the ones the game has (Pokemon_GameLanguages.h). StoryRunOptions(const StringSelectDatabase& checkpoints, const EnumDropdownDatabase& languages); - // The range's check, then verify mode's: one checkpoint only; then a - // run without the reload at the start must not save. - virtual std::string check_validity() const override; - - // The policy these options set, with the save mode. - SegmentPolicy policy() const; - // Verify mode's runs and passes with the save mode; unset when off. - std::optional verify_policy() const; // The checks level, for the game's steps to read. StoryCheckLevel check_level() const; // The game's language, for the steps that read text. @@ -91,19 +58,10 @@ class StoryRunOptions : public StoryRangeOptions{ // Any language the game has, whether or not a reader supports it: // steps without one use language-free checks, so none is refused. EnumDropdownOption LANGUAGE; - // On, it runs one checkpoint: the start, which must also be the end. - StoryVerifyOptions VERIFY; - // When the run saves; NONE (testing) by default. - EnumDropdownOption SAVE_MODE; // On (the default), the run loads the save before its first - // checkpoint (StoryLaunchRequest::Running::RESTART). Off, it starts - // from where the game is, resumed from HOME if need be (Running::KEEP); - // later checkpoints reload as before. Off needs SAVE_MODE NONE: the - // run must not save from a position nothing checked. + // checkpoint. Off, it starts from where the game is; later checkpoints + // reload as before. BooleanCheckBoxOption RELOAD_AT_START; - // On, nothing runs: the game reads where it stands and checks the end - // checkpoint's postconditions (Pokemon_StoryPostconditionCheck.h). - BooleanCheckBoxOption POSTCONDITIONS_ONLY; }; diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp index c9f62e050d..76265eb0f2 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp @@ -26,12 +26,11 @@ const StringSelectDatabase& two_checkpoints(){ return database; } -// The reload at the start and the save mode a user set, and whether the -// options let the run start. +// The reload at the start a user set, and whether the options let the run +// start. struct ReloadAtStartCase{ struct Input{ bool reload_at_start; - StorySaveMode save_mode; }; struct Expectation{ // Empty: the options are valid; else the refusal's message. @@ -42,21 +41,9 @@ struct ReloadAtStartCase{ Expectation expectation; }; -constexpr std::string_view NO_RELOAD_SAVES = - "Reload the Save at the Start is off: the run starts from wherever the game is, which nothing checked, " - "so it must not save. Set Save to None or turn the reload on."; - const ReloadAtStartCase RELOAD_AT_START_CASES[] = { - {.name = "reload at the start by default", .input = {.reload_at_start = true, .save_mode = StorySaveMode::NONE}, - .expectation = {.error = ""}}, - {.name = "a reloaded run may save", .input = {.reload_at_start = true, .save_mode = StorySaveMode::PER_CHECKPOINT}, - .expectation = {.error = ""}}, - {.name = "no reload without saves", .input = {.reload_at_start = false, .save_mode = StorySaveMode::NONE}, - .expectation = {.error = ""}}, - {.name = "no reload refuses saves after verification", .input = {.reload_at_start = false, .save_mode = StorySaveMode::AFTER_VERIFICATION}, - .expectation = {.error = NO_RELOAD_SAVES}}, - {.name = "no reload refuses saves per checkpoint", .input = {.reload_at_start = false, .save_mode = StorySaveMode::PER_CHECKPOINT}, - .expectation = {.error = NO_RELOAD_SAVES}}, + {.name = "reload at the start", .input = {.reload_at_start = true}, .expectation = {.error = ""}}, + {.name = "no reload at the start", .input = {.reload_at_start = false}, .expectation = {.error = ""}}, }; class Test_ReloadAtStart : public UnitTest{ @@ -72,7 +59,6 @@ class Test_ReloadAtStart : public UnitTest{ return "Expected the reload at the start on by default."; } run.RELOAD_AT_START = m_case.input.reload_at_start; - run.SAVE_MODE.set(m_case.input.save_mode); const std::string error = run.check_validity(); if (error != m_case.expectation.error){ return std::format("Expected \"{}\", got \"{}\".", m_case.expectation.error, error); From d8d1966fc9ff5b25b548e724602b45b6f4d72805 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 12:33:31 -0800 Subject: [PATCH 5/5] StoryRunOptions: drop RUN.LANGUAGE and GameLanguages PLZA keeps its own Game Language option. --- .../Pokemon_StoryStepExecutor_Tests.cpp | 13 +----- .../Pokemon/Options/Pokemon_GameLanguages.cpp | 43 ------------------ .../Pokemon/Options/Pokemon_GameLanguages.h | 45 ------------------- .../Options/Pokemon_StoryRunOptions.cpp | 15 ++----- .../Pokemon/Options/Pokemon_StoryRunOptions.h | 15 ++----- .../Options/Pokemon_StoryRunOptions_Tests.cpp | 3 +- SerialPrograms/cmake/SourceFiles.cmake | 2 - 7 files changed, 10 insertions(+), 126 deletions(-) delete mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.cpp delete mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp index e1c6b8e335..99ce9251d3 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp @@ -20,7 +20,6 @@ #include #include #include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon/Options/Pokemon_GameLanguages.h" #include "Pokemon/Options/Pokemon_StoryRunOptions.h" #include "Pokemon_AutoStorySelect.h" #include "Pokemon_AutoStoryStats.h" @@ -398,7 +397,7 @@ UnitTestResult test_checkpoint_dropdowns(){ ){ return "Unexpected label."; } - StoryRunOptions options(database, Gen8ToGen9Languages_Database()); + StoryRunOptions options(database); if (options.start_index() != 0 || options.end_index() != 2 || !options.check_validity().empty()){ return "Expected the whole story by default."; } @@ -430,7 +429,7 @@ UnitTestResult test_story_stats(){ // The program's option group: 3 attempts, no stop, Thorough, by default; // Fast when chosen. UnitTestResult test_run_options(){ - StoryRunOptions options(two_sections_database(), Gen8ToGen9Languages_Database()); + StoryRunOptions options(two_sections_database()); if (options.ATTEMPTS_PER_CHECKPOINT != 3 || options.check_level() != StoryCheckLevel::DEFAULT){ return "Expected 3 attempts, no stop at the first failure, and Thorough checks by default."; } @@ -438,14 +437,6 @@ UnitTestResult test_run_options(){ if (options.check_level() != StoryCheckLevel::FAST){ return "Expected Fast checks once chosen."; } - // Every game language can be chosen, read or not. - if (options.language() != Language::English){ - return "Expected English by default."; - } - options.LANGUAGE.set(Language::Japanese); - if (options.language() != Language::Japanese || !options.check_validity().empty()){ - return "Expected Japanese to be chosen and valid, reader or not."; - } return true; } diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.cpp deleted file mode 100644 index 42f0dadf08..0000000000 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* Game Languages - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "Pokemon_GameLanguages.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -const EnumDropdownDatabase& Gen8ToGen9Languages_Database(){ - static const EnumDropdownDatabase database({ - {Language::English, "en", "English"}, - {Language::Japanese, "ja", "Japanese"}, - {Language::Spanish, "es", "Spanish"}, - {Language::French, "fr", "French"}, - {Language::German, "de", "German"}, - {Language::Italian, "it", "Italian"}, - {Language::Korean, "ko", "Korean"}, - {Language::ChineseSimplified, "zh-Hans", "Chinese (Simplified)"}, - {Language::ChineseTraditional, "zh-Hant", "Chinese (Traditional)"}, - }); - return database; -} - -const EnumDropdownDatabase& FireRedLeafGreenLanguages_Database(){ - static const EnumDropdownDatabase database({ - {Language::English, "en", "English"}, - {Language::Japanese, "ja", "Japanese"}, - {Language::Spanish, "es", "Spanish"}, - {Language::French, "fr", "French"}, - {Language::German, "de", "German"}, - {Language::Italian, "it", "Italian"}, - }); - return database; -} - - - -} // namespace Pokemon -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h deleted file mode 100644 index 003767c870..0000000000 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Game Languages - * - * From: https://github.com/PokemonAutomation/ - * - * The languages each game can be played in, as dropdown databases for a - * program's language option. A program offers its game's set, so a user - * can't pick a language the game doesn't have. Every language a game ships - * in is listed, tested on console or not. Code that reads text takes this - * option and never assumes a language. With no reader for the chosen - * language, a name lookup throws InternalProgramError ("No data loaded for - * this language.") and a story step falls back to positions, digits and the - * screen. - * - */ - -#ifndef PokemonAutomation_Pokemon_GameLanguages_H -#define PokemonAutomation_Pokemon_GameLanguages_H - -#include "Common/Cpp/Options/EnumDropdownDatabase.h" -#include "CommonFramework/Language.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -// The nine languages of the Switch games of generations 8 and 9: Sword and -// Shield, Brilliant Diamond and Shining Pearl, Legends: Arceus, Scarlet and -// Violet, Legends: Z-A. Japanese, English, French, Italian, German, -// Spanish, Korean, Chinese (Simplified and Traditional). The games have one -// Spanish (Spain), hence one "es". -const EnumDropdownDatabase& Gen8ToGen9Languages_Database(); - -// The six languages of FireRed and LeafGreen, the Game Boy Advance -// releases the Switch versions reissue: Japanese, English, French, Italian, -// German, Spanish. On Switch each language is a separate version with no -// in-game language option (Nintendo of America sells English, French and -// Spanish, the latter two in their European form), so the user picks the -// version they own. -const EnumDropdownDatabase& FireRedLeafGreenLanguages_Database(); - - - -} // namespace Pokemon -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp index b4897e6772..41f69690ce 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp @@ -40,7 +40,7 @@ std::string story_checkpoint_label(const StoryCheckpoint& checkpoint){ -StoryRunOptions::StoryRunOptions(const StringSelectDatabase& checkpoints, const EnumDropdownDatabase& languages) +StoryRunOptions::StoryRunOptions(const StringSelectDatabase& checkpoints) : StoryRangeOptions("Story Run", checkpoints) , ATTEMPTS_PER_CHECKPOINT( "Attempts per checkpoint:
A failed checkpoint reloads its save and runs again, up to this many times in all. " @@ -54,18 +54,12 @@ StoryRunOptions::StoryRunOptions(const StringSelectDatabase& checkpoints, const LockMode::LOCK_WHILE_RUNNING, StoryCheckLevel::DEFAULT ) - , LANGUAGE( - "Game language:
For the few reads that need text (item names in a shop or the Bag). " - "Story steps never match dialogue text; with no reader for this language they check positions, digits and the screen instead.", - languages, - LockMode::LOCK_WHILE_RUNNING, - Language::English - ) + , RELOAD_AT_START(std::string(RELOAD_AT_START_LABEL), LockMode::LOCK_WHILE_RUNNING, true) { PA_ADD_OPTION(ATTEMPTS_PER_CHECKPOINT); PA_ADD_OPTION(CHECKS); - PA_ADD_OPTION(LANGUAGE); + PA_ADD_OPTION(RELOAD_AT_START); } @@ -73,9 +67,6 @@ StoryCheckLevel StoryRunOptions::check_level() const{ return CHECKS; } -Language StoryRunOptions::language() const{ - return LANGUAGE; -} diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h index d8d12c7f48..61800fa8a6 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h @@ -5,9 +5,8 @@ * The options every AutoStory program shows for where to start and end, how * hard to try and how much to check: the shared range group * (Pokemon_StoryRangeOptions.h) plus the attempts per checkpoint, the - * checks level (Types/Pokemon_StoryCheckLevel.h), the language the game's - * steps read text in, and whether it reloads the save before its first - * checkpoint. + * checks level (Types/Pokemon_StoryCheckLevel.h) and whether it reloads + * the save before its first checkpoint. * */ @@ -19,7 +18,7 @@ #include "Common/Cpp/Options/BooleanCheckBoxOption.h" #include "Common/Cpp/Options/EnumDropdownOption.h" #include "Common/Cpp/Options/SimpleIntegerOption.h" -#include "CommonFramework/Language.h" + #include "CommonTools/Options/StringSelectOption.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" @@ -44,20 +43,14 @@ class StoryRunOptions : public StoryRangeOptions{ public: // `checkpoints`: story_checkpoint_database() of the game's story, kept // alive by the caller; the dropdowns start on its first and last. - // `languages`: the ones the game has (Pokemon_GameLanguages.h). - StoryRunOptions(const StringSelectDatabase& checkpoints, const EnumDropdownDatabase& languages); + explicit StoryRunOptions(const StringSelectDatabase& checkpoints); // The checks level, for the game's steps to read. StoryCheckLevel check_level() const; - // The game's language, for the steps that read text. - Language language() const; public: SimpleIntegerOption ATTEMPTS_PER_CHECKPOINT; EnumDropdownOption CHECKS; - // Any language the game has, whether or not a reader supports it: - // steps without one use language-free checks, so none is refused. - EnumDropdownOption LANGUAGE; // On (the default), the run loads the save before its first // checkpoint. Off, it starts from where the game is; later checkpoints // reload as before. diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp index 76265eb0f2..353e83a8ac 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions_Tests.cpp @@ -11,7 +11,6 @@ #include #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" -#include "Pokemon_GameLanguages.h" #include "Pokemon_StoryRunOptions.h" #include "Pokemon_StoryRunOptions_Tests.h" @@ -54,7 +53,7 @@ class Test_ReloadAtStart : public UnitTest{ {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - StoryRunOptions run(two_checkpoints(), Gen8ToGen9Languages_Database()); + StoryRunOptions run(two_checkpoints()); if (!run.RELOAD_AT_START){ return "Expected the reload at the start on by default."; } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index ae8c222f78..4b39b9e356 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1598,8 +1598,6 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Options/Pokemon_BoxSortingTable.cpp Source/Pokemon/Options/Pokemon_BoxSortingTable.h Source/Pokemon/Options/Pokemon_EncounterBotOptions.h - Source/Pokemon/Options/Pokemon_GameLanguages.cpp - Source/Pokemon/Options/Pokemon_GameLanguages.h Source/Pokemon/Options/Pokemon_HomeSpriteSelectOption.cpp Source/Pokemon/Options/Pokemon_HomeSpriteSelectOption.h Source/Pokemon/Options/Pokemon_IvJudgeOption.cpp