From 51cb26677a5a5b1ae58362329cb42e31045fffcb Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 09:58:23 -0800 Subject: [PATCH 1/3] FRLG AutoStory: checkpoints 00.01-00.10 as authored JSON, on #312's action/args steps The FRLG stack stopped building after #312: the C++ rows set step.target, legs, direction, fight_wild and may_lose directly, StoryChecks became StoryCheckLevel, Pokemon_StorySteps.h moved to Pokemon_StoryStepExecutor.h and the JSON codecs to Data/. - Each checkpoint is StoryData/frlg-.plan.json (pokesim-authored- checkpoint/1), read with read_authored_checkpoint() against FRLG's actions: the built-in ones plus ROUTE/LEGS "run". The parser fills in the fallbacks (fight_wild, may_lose, yes), so the files give only what differs. FRLG's execution object carries the START menu, the supplies, the lead after Brock and the notes that were C++ comments. - The executor, the step-table, sim and route tests read typed args (story_arg()); the sim's fake game dispatches by kind in run(). - Check levels: DEFAULT and above check the screen as THOROUGH did; FAST and SPEEDRUN trust counts as FAST did. - AutoStory: StoryRunOptions with the FRLG languages, the check level and language into StoryEnv, record_story_counts(). The old C++ rows stay in PokemonFRLG_AutoStoryTableParity_Tests.cpp for this commit only: each file loads to the same steps, args, poses, supplies and START menu. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- SerialPrograms/CMakeLists.txt | 2 + .../PokemonFRLG_OverworldRecovery.cpp | 10 +- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 1 + .../AutoStory/PokemonFRLG_AutoStory.cpp | 27 +- .../PokemonFRLG_AutoStoryActions.cpp | 4 +- .../AutoStory/PokemonFRLG_AutoStoryActions.h | 21 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.cpp | 26 +- .../AutoStory/PokemonFRLG_AutoStoryBattle.h | 6 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 52 ++- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 6 +- .../AutoStory/PokemonFRLG_AutoStoryExport.cpp | 2 +- .../PokemonFRLG_AutoStoryExport_Tests.cpp | 2 +- .../PokemonFRLG_AutoStorySimulation_Tests.cpp | 79 ++-- .../PokemonFRLG_AutoStoryStepInterrupts.h | 2 +- .../PokemonFRLG_AutoStoryStepTable.cpp | 20 +- .../PokemonFRLG_AutoStoryStepTable.h | 13 +- .../PokemonFRLG_AutoStoryStepTable_Tests.cpp | 4 +- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 369 +++++------------- .../AutoStory/PokemonFRLG_AutoStoryTable.h | 32 +- ...PokemonFRLG_AutoStoryTableParity_Tests.cpp | 344 ++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 13 +- .../AutoStory/StoryData/frlg-00.01.plan.json | 29 ++ .../AutoStory/StoryData/frlg-00.02.plan.json | 22 ++ .../AutoStory/StoryData/frlg-00.03.plan.json | 41 ++ .../AutoStory/StoryData/frlg-00.04.plan.json | 76 ++++ .../AutoStory/StoryData/frlg-00.05.plan.json | 41 ++ .../AutoStory/StoryData/frlg-00.06.plan.json | 33 ++ .../AutoStory/StoryData/frlg-00.07.plan.json | 95 +++++ .../AutoStory/StoryData/frlg-00.08.plan.json | 82 ++++ .../AutoStory/StoryData/frlg-00.09.plan.json | 79 ++++ .../AutoStory/StoryData/frlg-00.10.plan.json | 48 +++ SerialPrograms/cmake/SourceFiles.cmake | 1 + 32 files changed, 1212 insertions(+), 370 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 73729ebde9..5a90664df8 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -231,6 +231,8 @@ pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Overworld/Ma VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h PokemonAutomation::NintendoSwitch::PokemonFRLG overworld_map_json) pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_battle_json) +pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData + VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_checkpoint_json) # Create binary target diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index 7e37bafded..ce552195c7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -71,20 +71,20 @@ class RouteLogLines{ for (const RouteStep& step : steps){ legs.push_back({.leg = route_log_leg(step), .after = route_tiles(step.end)}); } - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_plan_line(m_label, route_tiles(from), legs)); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_plan_line(m_label, route_tiles(from), legs)); } void leg(size_t index, const std::vector& steps) const{ const RouteStep& step = steps[index]; - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_leg_line(index + 1, steps.size(), {.leg = route_log_leg(step), .after = route_tiles(step.end)})); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_leg_line(index + 1, steps.size(), {.leg = route_log_leg(step), .after = route_tiles(step.end)})); } void end(const RouteStep& step, const std::optional& at, EndBasis basis, const std::string& why) const{ - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_leg_end_line(m_label, route_log_leg(step), route_tiles(at), basis, why)); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_leg_end_line(m_label, route_log_leg(step), route_tiles(at), basis, why)); } void trainer_stopped(const RouteStep& step, const MapPosition& at) const{ - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_replan_line(m_label, route_log_leg(step), "stopped by a trainer who saw the player", route_tiles(at))); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_replan_line(m_label, route_log_leg(step), "stopped by a trainer who saw the player", route_tiles(at))); } void found(const MapPosition& at, size_t holds) const{ - m_calls.log(ROUTE_LOG_TAG + Pokemon::route_found_line(m_label, route_tiles(at), holds)); + m_calls.log(std::string(ROUTE_LOG_TAG) + Pokemon::route_found_line(m_label, route_tiles(at), holds)); } // Step `number` (from 1) of a plan whose first `holds` steps are holds // to walls, walked to its end. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index cea4ff7bc9..4a5a0b5310 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -319,6 +319,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); + add_tests_AutoStoryTableParity(database); add_tests_AutoStoryExport(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 6dab6ec05e..431de98ad7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -11,7 +11,9 @@ #include "CommonFramework/Notifications/ProgramNotifications.h" #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" +#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/Options/Pokemon_GameLanguages.h" #include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -46,7 +48,14 @@ namespace{ // The start and end dropdowns' entries: the table's checkpoints, 00.01 to // 00.10. The options hold a reference to it. const StringSelectDatabase& checkpoint_database(){ - static const StringSelectDatabase database = Pokemon::story_checkpoint_database(story_checkpoints()); + static const std::vector labels = []{ + std::vector result; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + result.push_back(Pokemon::story_checkpoint_label(checkpoint)); + } + return result; + }(); + static const StringSelectDatabase database = Pokemon::story_checkpoint_database(labels); return database; } @@ -58,7 +67,7 @@ const char* const KEEP_START_FRAME_TEXT = } // namespace AutoStory::AutoStory() - : RUN(checkpoint_database()) + : RUN(checkpoint_database(), Pokemon::FireRedLeafGreenLanguages_Database()) , NEW_GAME_FROM_TITLE( "New game from the title screen:
The game is on its title screen with no save data. " "Needed to start at 00.01. Otherwise the program loads the save, which must be the one the start checkpoint begins from.", @@ -101,7 +110,7 @@ namespace{ // the screen as its frame if `keep_start_frame` (a save made by hand). StoryEnv story_env( SingleSwitchProgramEnvironment& env, ProControllerContext& context, - const StoryCheckpoint& checkpoint, StoryChecks checks, bool keep_start_frame + const StoryCheckpoint& checkpoint, Pokemon::StoryCheckLevel checks, bool keep_start_frame ){ StoryEnv story{env.console, context, checkpoint.supplies, checkpoint.supplies, false, checks}; story.start_frames = program_start_frames(); @@ -173,11 +182,10 @@ void verify_story_checkpoint( ){ const std::vector& checkpoints = story_checkpoints(); const StoryCheckpoint& checkpoint = checkpoints[run.start_index()]; - StoryEnv story = story_env(env, context, checkpoint, run.checks(), false); + StoryEnv story = story_env(env, context, checkpoint, run.check_level(), false); load_verify_save(env, context, story, checkpoint); + story.language = run.language(); StoryExecutor executor(story); - executor.set_checks(run.checks()); - executor.set_language(run.language()); Pokemon::Segment segment = make_story_segment(checkpoints, executor); Pokemon::SegmentHooks hooks = story_hooks(env, story); @@ -211,7 +219,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex throw UserSetupError(env.console, "Checkpoint 00.01 starts a new game: start on the title screen with no save."); } - StoryEnv story = story_env(env, context, checkpoints[first], RUN.checks(), KEEP_START_FRAME); + StoryEnv story = story_env(env, context, checkpoints[first], RUN.check_level(), KEEP_START_FRAME); if (!(first == 0 && NEW_GAME_FROM_TITLE)){ env.console.log("Loading the save for " + checkpoints[first].id + "."); soft_reset(env.console, context); @@ -221,9 +229,8 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex read_bag_supplies(story, checkpoints[first].menu); } + story.language = RUN.language(); StoryExecutor executor(story); - executor.set_checks(RUN.checks()); - executor.set_language(RUN.language()); Pokemon::Segment segment = make_story_segment(checkpoints, executor); Pokemon::SegmentHooks hooks = story_hooks(env, story); @@ -231,7 +238,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex const Pokemon::SegmentReport report = run_segment( state, segment, Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), hooks ); - Pokemon::record_story_stats(env.current_stats(), report); + Pokemon::record_story_counts(env.current_stats(), report.story_counts()); env.update_stats(); if (!report.completed){ throw OperationFailedException( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index e484701c7d..d38e145428 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -796,7 +796,7 @@ static void check_mart_row(ConsoleHandle& console, ProControllerContext& context void buy_items( ConsoleHandle& console, ProControllerContext& context, - const std::vector& orders, StoryChecks checks, Language language + const std::vector& orders, Pokemon::StoryCheckLevel checks, Language language ){ // "May I help you?" with BUY on top, then the list, cursor on its top. press(context, BUTTON_A, 2000ms); @@ -813,7 +813,7 @@ void buy_items( } cursor = order.row; mart_shot(console, context, std::format("row{}-list", order.row + 1)); - if (checks == StoryChecks::THOROUGH){ + if (checks_screen(checks)){ check_mart_row(console, context, order, language); } // "How many?" drops presses while its text prints. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 27eeb690b3..31d2a99fbf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -23,7 +23,8 @@ #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" #include "Pokemon/Navigation/Pokemon_Grid.h" namespace PokemonAutomation{ @@ -31,13 +32,15 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// How much the story checks the screen before and after it acts: the -// shared level (Pokemon_StorySteps.h, set by StoryRunOptions). For FRLG, -// THOROUGH reads a Mart row's item before buying it, the bag's Items -// pocket after shopping (the counts the story then keeps), and an item's -// name in the bag before using it. FAST trusts the counts it keeps and the -// timings. -using StoryChecks = Pokemon::StoryChecks; +// Whether the shared check level (Types/Pokemon_StoryCheckLevel.h, set by +// StoryRunOptions) has the story check the screen before and after it +// acts: DEFAULT and above (TESTING, THOROUGH). Then FRLG reads a Mart +// row's item before buying it, the bag's Items pocket after shopping (the +// counts the story then keeps), and an item's name in the bag before +// using it. FAST and SPEEDRUN trust the counts it keeps and the timings. +inline bool checks_screen(Pokemon::StoryCheckLevel level){ + return level <= Pokemon::StoryCheckLevel::DEFAULT; +} // The START menu as the story grows it. Before the starter: BAG, the // player, SAVE, OPTION, EXIT; the starter adds POKEMON on top, the Pokedex @@ -214,7 +217,7 @@ int mart_cursor_moves(int cursor, int row); // bought by position only. void buy_items( ConsoleHandle& console, ProControllerContext& context, - const std::vector& orders, StoryChecks checks, Language language + const std::vector& orders, Pokemon::StoryCheckLevel checks, Language language ); // From the title screen of a game with no save, to the bedroom: the diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 555ecccfbe..8e02ced513 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -164,9 +164,9 @@ void tap(ProControllerContext& context, DpadPosition position){ // no names for) is taken by its position; only another item's name stops it. bool bag_row_is( ConsoleHandle& console, ProControllerContext& context, - int row, const std::string& item, StoryChecks checks, Language language + int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language ){ - if (checks == StoryChecks::FAST){ + if (!checks_screen(checks)){ return true; } context.wait_for_all_requests(); @@ -190,7 +190,7 @@ bool bag_row_is( // backs out to the battle menu. Not run on the console yet. bool use_item( ConsoleHandle& console, ProControllerContext& context, - int row, const std::string& item, StoryChecks checks, Language language + int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language ){ console.log(std::format("Battle: using the {} in row {} of the Items pocket.", item, row + 1)); tap(context, DPAD_LEFT); @@ -321,7 +321,7 @@ class BattleLoop{ public: BattleLoop( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, BattleKind kind, StoryChecks checks, Language language + Supplies& supplies, BattleKind kind, Pokemon::StoryCheckLevel checks, Language language ) : m_console(console) , m_context(context) @@ -659,7 +659,7 @@ class BattleLoop{ BattleEndWatch m_end; MoveRefusalWatch m_refusal; const BattleKind m_kind; - const StoryChecks m_checks; + const Pokemon::StoryCheckLevel m_checks; const Language m_language; const WallClock m_start; WallClock m_last_battle; @@ -694,7 +694,7 @@ void open_items_pocket(ConsoleHandle& console, ProControllerContext& context){ // Not run on the console yet. bool use_item_on_overworld( ConsoleHandle& console, ProControllerContext& context, - int row, const std::string& item, StoryChecks checks, Language language + int row, const std::string& item, Pokemon::StoryCheckLevel checks, Language language ){ console.log(std::format("Story: using a {} from the bag (Items pocket, row {}).", item, row + 1)); open_items_pocket(console, context); @@ -727,7 +727,7 @@ void fail_on_blackout(ConsoleHandle& console, BattleEnd end){ // appeared!". class StoryWildBattle : public OverworldInterrupt{ public: - StoryWildBattle(Supplies& supplies, bool fight, bool late, StoryChecks checks, Language language) + StoryWildBattle(Supplies& supplies, bool fight, bool late, Pokemon::StoryCheckLevel checks, Language language) : m_supplies(supplies) , m_checks(checks) , m_language(language) @@ -758,7 +758,7 @@ class StoryWildBattle : public OverworldInterrupt{ private: Supplies& m_supplies; - const StoryChecks m_checks; + const Pokemon::StoryCheckLevel m_checks; const Language m_language; const bool m_fight; const bool m_late; @@ -767,7 +767,7 @@ class StoryWildBattle : public OverworldInterrupt{ // A message: read to its end, then a trainer's battle if one starts. class StoryMessage : public OverworldInterrupt{ public: - StoryMessage(Supplies& supplies, StoryChecks checks, Language language) + StoryMessage(Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language) : m_supplies(supplies) , m_checks(checks) , m_language(language) @@ -793,7 +793,7 @@ class StoryMessage : public OverworldInterrupt{ private: Supplies& m_supplies; - const StoryChecks m_checks; + const Pokemon::StoryCheckLevel m_checks; const Language m_language; }; @@ -932,7 +932,7 @@ std::vector read_items_pocket(ConsoleHandle& console, ProControllerConte void recover_after_battle( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, StoryChecks checks, Language language + Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language ){ if (supplies.status == StatusCondition::POISON && supplies.antidotes > 0){ if (use_item_on_overworld(console, context, item_row(supplies, "antidote"), "antidote", checks, language)){ @@ -959,12 +959,12 @@ void recover_after_battle( BattleEnd fight_battle( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, BattleKind kind, StoryChecks checks, Language language + Supplies& supplies, BattleKind kind, Pokemon::StoryCheckLevel checks, Language language ){ return BattleLoop(console, context, supplies, kind, checks, language).run(); } -OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language){ +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, Pokemon::StoryCheckLevel checks, Language language){ // Battles first: their screens are checked before the message box's. OverworldInterruptSet ret; ret.wild.emplace_back(std::make_unique(supplies, fight_wild, false, checks, language)); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index b0cca42e3c..7f65bf3d0b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -179,7 +179,7 @@ bool battle_shows(const ImageViewRGB32& screen); // different one isn't used. BattleEnd fight_battle( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, BattleKind kind, StoryChecks checks, Language language + Supplies& supplies, BattleKind kind, Pokemon::StoryCheckLevel checks, Language language ); @@ -188,7 +188,7 @@ BattleEnd fight_battle( // The bag's inputs are not checked on the console yet. void recover_after_battle( ConsoleHandle& console, ProControllerContext& context, - Supplies& supplies, StoryChecks checks, Language language + Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language ); @@ -196,7 +196,7 @@ void recover_after_battle( // fought if `fight_wild`. A message is advanced until the overworld is // back; a battle that starts after it (a trainer who saw the player) is // fought. A battle lost (a blackout) throws OperationFailedException. -OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, StoryChecks checks, Language language); +OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, Pokemon::StoryCheckLevel checks, Language language); // Registers AutoStory item usage unit tests. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 5a2baefcf1..7756577c90 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -51,6 +51,20 @@ Outcome guarded(Body&& body){ } } +// The step's arg `key`, which its action declares. +template +const Type& arg(const StoryStep& step, std::string_view key){ + return Pokemon::story_arg(step.args, key); +} + +// A checkpoint's start as the engine's Pose: nothing for a new game. +std::optional start_pose(const StoryCheckpoint& checkpoint){ + if (!checkpoint.start){ + return std::nullopt; + } + return Pokemon::pose_of(*checkpoint.start); +} + const MapData* find_story_map(const std::string& name){ for (const MapData& map : story_maps()){ if (map.name == name){ @@ -78,13 +92,13 @@ std::optional face_a_wall(StoryEnv& env, const MapPosition& position) // The shared route log's arrival line (Pokemon_RouteLog.h), as BDSP's walker // writes it: where the route was walked to. void log_arrival(StoryEnv& env, const std::string& label, const std::string& map, const TilePos& tile){ - env.console.log(Pokemon::ROUTE_LOG_TAG + Pokemon::route_arrived_line(label, {{map, tile}})); + env.console.log(std::string(Pokemon::ROUTE_LOG_TAG) + Pokemon::route_arrived_line(label, {{map, tile}})); } // The walker's check that each leg to a wall ended at it (a diagnostic): // with Thorough checks only, as Fast trusts the walk. WallCheck wall_check(const StoryEnv& env){ - return env.checks == StoryChecks::THOROUGH ? WallCheck::TAP : WallCheck::SKIP; + return checks_screen(env.checks) ? WallCheck::TAP : WallCheck::SKIP; } Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ @@ -100,9 +114,10 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ if (!facing){ return Pokemon::outcome_failed("unknown_facing", to_string(start)); } - const std::optional target = step.target ? story_pose(*step.target) : std::nullopt; + const Pokemon::Pose target_pose = Pokemon::pose_of(arg(step, "target")); + const std::optional target = story_pose(target_pose); if (!target){ - return Pokemon::outcome_failed("bad_target", step.target ? Pokemon::to_string(*step.target) : "none"); + return Pokemon::outcome_failed("bad_target", Pokemon::to_string(target_pose)); } const RouteGoal goal{{target->map, target->tile}, target->facing}; const std::optional> route = plan_overworld_route( @@ -111,7 +126,7 @@ Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step){ if (!route){ return Pokemon::outcome_failed("no_route", to_string(start) + " to " + to_string(goal.position)); } - const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, arg(step, "fight_wild"), env.checks, env.language); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; @@ -131,11 +146,11 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ if (!facing){ facing = face_a_wall(env, start); } - const std::optional> route = fixed_route(story_maps(), start, step.legs); + const std::optional> route = fixed_route(story_maps(), start, arg>(step, "legs")); if (!facing || !route || route->empty()){ return Pokemon::outcome_failed("bad_legs", to_string(start)); } - const OverworldInterruptSet interrupts = story_interrupts(env.supplies, step.fight_wild, env.checks, env.language); + const OverworldInterruptSet interrupts = story_interrupts(env.supplies, arg(step, "fight_wild"), env.checks, env.language); // Planning lets the walker recover a stopped open leg: it plans back to // the leg's end, then walks the rest as given. const RoutePlanning planning{.maps = &story_maps(), .costs = default_route_costs(), .start = start, .label = step.name, .wall_check = wall_check(env)}; @@ -145,19 +160,20 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ } Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ - step_once(env.context, step.direction, facing_of(state.pose)); + const Direction direction = arg(step, "direction"); + step_once(env.context, direction, facing_of(state.pose)); const std::vector tiles = Pokemon::tiles_of(state.pose); if (tiles.size() != 1){ return Pokemon::outcome_ok(); } - return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, tiles[0].next(step.direction), step.direction})); + return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, tiles[0].next(direction), direction})); } // Before a BattleRisk::HIGH battle the story may lose: the sim's win // chance, the HP as the last bar read left it. Why not to fight, if so. std::optional refuse_battle(StoryEnv& env, const StoryStep& step, std::string_view trainer){ const Supplies& supplies = env.supplies; - if (step.may_lose || supplies.risk != BattleRisk::HIGH){ + if (arg(step, "may_lose") || supplies.risk != BattleRisk::HIGH){ return std::nullopt; } const std::optional estimate = story_win_chance(supplies.lead, supplies.potions, supplies.hp_fill, trainer); @@ -194,7 +210,7 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ env.supplies.foes.clear(); env.supplies.trainer.clear(); env.supplies.foe_out.reset(); - if (end == BattleEnd::LOST && !step.may_lose){ + if (end == BattleEnd::LOST && !arg(step, "may_lose")){ return Pokemon::outcome_failed("blackout"); } mash_until_overworld(env.console, env.context, SCENE_TIMEOUT); @@ -249,16 +265,16 @@ const MartItem* viridian_mart_item(const std::string& name){ } Outcome shop(StoryEnv& env, const StoryStep& step){ - const std::optional> orders = viridian_mart_orders(step.items); + const std::optional> orders = viridian_mart_orders(arg>(step, "items")); if (!orders){ return Pokemon::outcome_failed("unknown_item", step.name); } // 2000 of the 3000 a new game starts with, plus the rival's prize. buy_items(env.console, env.context, *orders, env.checks, env.language); - for (const Pokemon::StoryItem& item : step.items){ + for (const Pokemon::StoryItem& item : arg>(step, "items")){ env.supplies.*viridian_mart_item(item.item)->count += (int)item.quantity; } - if (env.checks == StoryChecks::FAST){ + if (!checks_screen(env.checks)){ return Pokemon::outcome_ok(); } // The counts from the bag, not from the orders: a wrong row once bought @@ -298,7 +314,7 @@ const std::vector& story_maps(){ } MoveSpeed move_speed(const StoryStep& step){ - return step.variant == RUN_VARIANT ? MoveSpeed::RUN : MoveSpeed::WALK; + return step.action == RUN_VARIANT ? MoveSpeed::RUN : MoveSpeed::WALK; } Pokemon::Pose to_pose(const StoryPose& pose){ @@ -435,7 +451,7 @@ ConsoleAction console_action_of(StoryActionId id){ }; case StoryActionId::ANSWER: return [](StoryEnv& env, RunState&, const StoryStep& step){ - answer_yes_no(env.console, env.context, step.yes, BUTTON_B, YES_NO_TIMEOUT); + answer_yes_no(env.console, env.context, arg(step, "yes"), BUTTON_B, YES_NO_TIMEOUT); return Pokemon::outcome_ok(); }; case StoryActionId::MASH: @@ -493,7 +509,7 @@ Pokemon::StoryAction StoryExecutor::console_action(StoryActionId id){ }, .needs_console = true}; } if (id == StoryActionId::GAME){ - return {.act = [this](RunState& state, const StoryStep& step){ return game(state, step); }, .needs_console = true}; + return {.act = [](RunState&, const StoryStep& step){ return Pokemon::unsupported_step(step); }, .needs_console = true}; } const ConsoleAction action = console_action_of(id); return {.act = [this, action](RunState& state, const StoryStep& step){ return action(m_env, state, step); }, .needs_console = true}; @@ -582,7 +598,7 @@ Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& // program last saved there. With none kept, it passes. Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); add_start_check( - checkpoint, data.start, + checkpoint, start_pose(data), [&env, id = data.id]{ return read_console_start(env, id); }, [&env](const std::string& line){ env.console.log(line, COLOR_ORANGE); } ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index f8f006c849..d9f357e718 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -5,7 +5,7 @@ * The FRLG story as data for the shared story engine * (Pokemon/AutoStory/Pokemon_StoryEvents.h, Pokemon_StorySegments.h). * A checkpoint is a list of the shared StorySteps - * (Pokemon/AutoStory/Pokemon_StorySteps.h), each one kind of event (a + * (Pokemon/AutoStory/Pokemon_StoryStepExecutor.h), each one kind of event (a * route, a talk, text read to its end, a YES/NO, a battle, the nurse, the * Mart); StoryExecutor does each kind on the console, and * make_story_segment() turns the table into engine checkpoints. Routes @@ -29,7 +29,7 @@ #include "Pokemon/AutoStory/Pokemon_StoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" @@ -143,7 +143,7 @@ struct StoryEnv{ Supplies saved_supplies; // Whether the game has a save to reload. bool has_save = false; - StoryChecks checks = StoryChecks::THOROUGH; + Pokemon::StoryCheckLevel checks = Pokemon::StoryCheckLevel::DEFAULT; // The game's language, for reading item names. In one the readers have // no names for, the checks fall back to positions and counts. Language language = Language::English; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp index a0b85c21ea..3d7dd7f18a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport.cpp @@ -6,7 +6,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" -#include "Pokemon/AutoStory/Pokemon_StoryStepJson.h" +#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" #include "PokemonFRLG_AutoStoryExport.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp index bc4e0f3f12..7f3757d020 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.cpp @@ -3,7 +3,7 @@ */ #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" -#include "Pokemon/AutoStory/Pokemon_StoryStepJson.h" +#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" #include "PokemonFRLG_AutoStoryExport.h" #include "PokemonFRLG_AutoStoryTable.h" #include "PokemonFRLG_AutoStoryExport_Tests.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index 6148a1211b..9199c2478e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -22,7 +22,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -45,6 +45,14 @@ std::string joined(const std::vector& lines){ return text; } +// A checkpoint's start as the engine's Pose: nothing for a new game. +std::optional start_pose(const StoryCheckpoint& checkpoint){ + if (!checkpoint.start){ + return std::nullopt; + } + return Pokemon::pose_of(*checkpoint.start); +} + const MapData* map_named(const std::string& name){ for (const MapData& map : story_maps()){ if (map.name == name){ @@ -133,48 +141,66 @@ class FakeGame : public Pokemon::StoryStepExecutor{ failure->second.times--; return Pokemon::outcome_failed(failure->second.failure, key); } - return Pokemon::StoryStepExecutor::run(state, step); + return act(state, step); } -protected: - virtual Outcome route(RunState& state, const StoryStep& step) override{ - return walk_to(state.pose, step); +private: + // The step by its kind, as the console does it (StoryExecutor), with + // nothing done on a screen. + Outcome act(RunState& state, const StoryStep& step){ + switch (step.kind){ + case StoryStepKind::ROUTE: + return walk_to(state.pose, step); + case StoryStepKind::LEGS: + return legs(state, step); + case StoryStepKind::STEP: + return take_step(state, step); + case StoryStepKind::READY: + return ready(state, step); + case StoryStepKind::SHOP: + return shop(step); + case StoryStepKind::NEW_GAME: + case StoryStepKind::OPTIONS: + case StoryStepKind::TALK: + case StoryStepKind::ANSWER: + case StoryStepKind::MASH: + case StoryStepKind::BATTLE: + case StoryStepKind::HEAL: + return Pokemon::outcome_ok(); + default: + return Pokemon::unsupported_step(step); + } } - virtual Outcome legs(RunState& state, const StoryStep& step) override{ + Outcome legs(RunState& state, const StoryStep& step){ const Standing at = standing(state.pose); if (!at.error.empty()){ return Pokemon::outcome_failed("no_pose", at.error); } - const std::optional> route = fixed_route(story_maps(), at.position, step.legs); + const std::optional> route = fixed_route(story_maps(), at.position, Pokemon::story_arg>(step.args, "legs")); if (!route || route->empty()){ return Pokemon::outcome_failed("bad_legs", to_string(at.position)); } return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); } - virtual Outcome step(RunState& state, const StoryStep& step) override{ + Outcome take_step(RunState& state, const StoryStep& step){ const std::optional at = story_pose(state.pose); if (!at){ return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); } - return Pokemon::outcome_ok(to_pose(StoryPose{at->map, at->tile.next(step.direction), step.direction})); + const Direction direction = Pokemon::story_arg(step.args, "direction"); + return Pokemon::outcome_ok(to_pose(StoryPose{at->map, at->tile.next(direction), direction})); } // The nurse's way must plan too, but the run goes on from where it stands. - virtual Outcome ready(RunState& state, const StoryStep& step) override{ + Outcome ready(RunState& state, const StoryStep& step){ const Outcome to_nurse = walk_to(state.pose, step); return to_nurse.succeeded() ? Pokemon::outcome_ok() : to_nurse; } - virtual Outcome new_game(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome options(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome talk(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome answer(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome mash(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome battle(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } - virtual Outcome heal(RunState&, const StoryStep&) override{ return Pokemon::outcome_ok(); } // The Viridian Mart's list as the game shows it. After a purchase the // cursor stays on the row bought (console B, 2026-11-01), so each // order moves it from there, as buy_items() does since ad5d40885. - virtual Outcome shop(RunState&, const StoryStep& step) override{ + Outcome shop(const StoryStep& step){ + const std::vector& items = Pokemon::story_arg>(step.args, "items"); static const std::vector LIST{"poke_ball", "potion", "antidote", "parlyz_heal", "cancel"}; - const std::optional> orders = viridian_mart_orders(step.items); + const std::optional> orders = viridian_mart_orders(items); if (!orders){ return Pokemon::outcome_failed("unknown_item", step.name); } @@ -186,21 +212,20 @@ class FakeGame : public Pokemon::StoryStepExecutor{ if (cursor < 0 || cursor >= (int)LIST.size() || LIST[cursor] == "cancel"){ return Pokemon::outcome_failed("mart_cancel", std::format("order {} ends on row {}", c + 1, cursor + 1)); } - if (LIST[cursor] != step.items[c].item){ - return Pokemon::outcome_failed("wrong_item", std::format("{} instead of {}", LIST[cursor], step.items[c].item)); + if (LIST[cursor] != items[c].item){ + return Pokemon::outcome_failed("wrong_item", std::format("{} instead of {}", LIST[cursor], items[c].item)); } bag[LIST[cursor]] += order.quantity; } return Pokemon::outcome_ok(); } -private: Outcome walk_to(const Pokemon::Pose& pose, const StoryStep& step){ const Standing at = standing(pose); if (!at.error.empty()){ return Pokemon::outcome_failed("no_pose", at.error); } - const std::optional target = story_pose(*step.target); + const std::optional target = story_pose(Pokemon::pose_of(Pokemon::story_arg(step.args, "target"))); const RouteGoal goal{{target->map, target->tile}, target->facing}; const std::optional> route = plan_overworld_route( story_maps(), at.position, goal, default_route_costs(), at.facing @@ -232,9 +257,7 @@ struct Simulation{ std::vector> saves; Pokemon::SegmentPolicy policy; - // A language no reader supports, so a step that needed text would show. Pokemon::SegmentReport run(const Pokemon::SegmentRange& range){ - game.set_language(Language::Japanese); Pokemon::Segment segment; segment.id = "00"; for (const StoryCheckpoint& data : story_checkpoints()){ @@ -242,7 +265,7 @@ struct Simulation{ .id = data.id, .title = data.title, .saves = true, .build = [this, &data]{ Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, game); - add_start_pose_check(checkpoint, data.start, [this]{ return game.save_stands; }, [this](const std::string& line){ lines.push_back(line); }); + add_start_pose_check(checkpoint, start_pose(data), [this]{ return game.save_stands; }, [this](const std::string& line){ lines.push_back(line); }); return checkpoint; }, }); @@ -333,13 +356,13 @@ UnitTestResult test_whole_story(){ // Each checkpoint starts where the save before it stands. for (size_t c = 1; c < story_checkpoints().size(); c++){ const StoryCheckpoint& data = story_checkpoints()[c]; - const std::optional start = story_pose(*data.start); + const std::optional start = story_pose(*start_pose(data)); const std::optional saved = story_pose(sim.saves[c - 1].second); const bool same = start && saved && start->map == saved->map && start->tile == saved->tile && (!start->facing || start->facing == saved->facing); if (!same){ return std::format("{} starts at {}, but {} saved at {}.", data.id, - Pokemon::to_string(*data.start), sim.saves[c - 1].first, Pokemon::to_string(sim.saves[c - 1].second)); + Pokemon::to_string(*start_pose(data)), sim.saves[c - 1].first, Pokemon::to_string(sim.saves[c - 1].second)); } } if (report.one_shot_passes() != report.checkpoints_run){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h index d1d3e5d32a..a396b790c7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepInterrupts.h @@ -32,7 +32,7 @@ #include "Pokemon/AutoStory/Pokemon_ScreenEvents.h" #include "Pokemon/AutoStory/Pokemon_StoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryInterrupts.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryScreenEvents.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp index 2869e1c299..7d9da2e079 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -52,10 +52,28 @@ const std::vector& story_action_rows(){ return ROWS; } +std::span story_action_specs(){ + static const std::vector SPECS = []{ + const std::span builtin = Pokemon::builtin_story_actions(); + std::vector specs(builtin.begin(), builtin.end()); + for (StoryStepKind kind : {StoryStepKind::ROUTE, StoryStepKind::LEGS}){ + Pokemon::StoryActionSpec run = *Pokemon::find_story_action(builtin, kind, ""); + run.name = "run"; + specs.push_back(std::move(run)); + } + return specs; + }(); + return SPECS; +} + Pokemon::StoryActionTable make_story_action_table(const StoryActionBinding& bind){ Pokemon::StoryActionTable table; for (const StoryActionRow& row : story_action_rows()){ - table.add(row.kind, row.variant, bind(row.id)); + Pokemon::StoryAction action = bind(row.id); + if (const Pokemon::StoryActionSpec* spec = Pokemon::find_story_action(story_action_specs(), row.kind, row.variant)){ + action.args = spec->args; + } + table.add(row.kind, row.variant, std::move(action)); } return table; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h index 002e749cb3..3743d498a2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h @@ -14,11 +14,13 @@ #define PokemonAutomation_PokemonFRLG_AutoStoryStepTable_H #include +#include #include #include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" #include "Pokemon/AutoStory/Pokemon_StoryActions.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -55,9 +57,16 @@ struct StoryActionRow{ // Every row. TRAIN and SAVE have none: FRLG's story doesn't use them. const std::vector& story_action_rows(); +// The actions FRLG's steps name, with the args each takes: the built-in +// ones (Pokemon_BuiltinStoryActions.h), then a ROUTE and a LEGS named +// "run" (RUN_VARIANT), which take the same args and run with B held. +// A story file is read against these. +std::span story_action_specs(); + // How one binding (the console, a test) does each action. using StoryActionBinding = std::function; -// The rows as a table, each with `bind`'s action for its id. +// The rows as a table, each with `bind`'s action for its id and its +// spec's args. Pokemon::StoryActionTable make_story_action_table(const StoryActionBinding& bind); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp index ef2de6078e..e1903cfcf4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable_Tests.cpp @@ -98,7 +98,7 @@ std::string parity_error(FakeGame& game, const StoryStep& step){ std::vector trace; const Pokemon::Outcome outcome = game.run(step, trace); const std::optional expected = old_dispatch(step); - const std::string label = std::format("{} '{}' ({})", Pokemon::story_step_kind_name(step.kind), step.variant, step.name); + const std::string label = std::format("{} '{}' ({})", Pokemon::story_step_kind_name(step.kind), step.action, step.name); if (!expected){ if (!trace.empty() || outcome.failure != "unsupported_step"){ return label + ": expected unsupported, ran " + (trace.empty() ? outcome.failure : trace[0]); @@ -126,7 +126,7 @@ std::vector every_kind_and_variant(){ StoryStep step; step.kind = kind; step.name = "synthetic"; - step.variant = variant; + step.action = variant; steps.push_back(std::move(step)); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 5a88824d81..88573b08af 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -4,6 +4,14 @@ * */ +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Pokemon/AutoStory/Data/Pokemon_AuthoredCheckpointJson.h" +#include "PokemonFRLG_AutoStoryParty.h" +#include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" namespace PokemonAutomation{ @@ -13,280 +21,115 @@ namespace PokemonFRLG{ namespace{ -constexpr Direction NORTH = Direction::NORTH; -constexpr Direction SOUTH = Direction::SOUTH; -constexpr Direction EAST = Direction::EAST; -constexpr Direction WEST = Direction::WEST; - -const char* const BEDROOM = "PalletTown_PlayersHouse_2F"; -const char* const PALLET = "PalletTown"; -const char* const LAB = "PalletTown_ProfessorOaksLab"; -const char* const VIRIDIAN = "ViridianCity"; -const char* const VIRIDIAN_MART = "ViridianCity_Mart"; -const char* const VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; -const char* const FOREST = "ViridianForest"; -const char* const FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; -const char* const PEWTER = "PewterCity"; -const char* const PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; -const char* const GYM = "PewterCity_Gym"; - -Pokemon::Pose at(const char* map, int x, int y, std::optional facing = std::nullopt){ - return to_pose(StoryPose{map, {x, y}, facing}); -} - -StoryCheckpoint row( - std::string id, std::string title, std::optional start, - Supplies supplies, StartMenu menu, std::vector steps -){ - StoryCheckpoint checkpoint; - checkpoint.id = std::move(id); - checkpoint.title = std::move(title); - checkpoint.start = std::move(start); - checkpoint.steps = std::move(steps); - checkpoint.supplies = supplies; - checkpoint.menu = menu; - return checkpoint; -} - -// At the rows after Brock: no items counted, the starter with the moves -// the story gave it by Lv13. A run that loads a save reads the moves off -// the lead's summary instead (read_lead_moves()), so a save whose moves -// differ from these (console B, 2026-11-02: Water Gun where Tackle was) -// is fought with the moves it has. -Supplies after_brock(){ +// The wire names of the START menus. +StartMenu read_start_menu(std::string_view name, std::string_view source){ + if (name == "before_pokemon"){ + return StartMenu::BEFORE_POKEMON; + } + if (name == "before_pokedex"){ + return StartMenu::BEFORE_POKEDEX; + } + if (name == "full"){ + return StartMenu::FULL; + } + throw ParseException(std::format("{}: unknown START menu {}", source, name)); +} + +// `object`'s fields, each of which must be one of `keys`. +void only_fields(const JsonObject& object, std::initializer_list keys, std::string_view source){ + for (const auto& [key, unused] : object){ + bool known = false; + for (std::string_view allowed : keys){ + known |= key == allowed; + } + if (!known){ + throw ParseException(std::format("{}: unsupported execution field {}", source, key)); + } + } +} + +int read_count(const JsonObject& object, const std::string& key, std::string_view source){ + const JsonValue* value = object.get_value(key); + if (value == nullptr){ + return 0; + } + const int64_t count = value->to_integer_throw(std::string(source)); + if (count < 0 || count > 999){ + throw ParseException(std::format("{}: {} out of range", source, key)); + } + return (int)count; +} + +Supplies read_supplies(const JsonObject& execution, std::string_view source){ Supplies supplies; - supplies.lead = story_lead_after_brock(); + if (const JsonObject* items = execution.get_object("supplies")){ + only_fields(*items, {"potions", "antidotes", "parlyz_heals"}, source); + supplies.potions = read_count(*items, "potions", source); + supplies.antidotes = read_count(*items, "antidotes", source); + supplies.parlyz_heals = read_count(*items, "parlyz_heals", source); + } + if (const std::string* lead = execution.get_string("lead")){ + if (*lead != "after_brock"){ + throw ParseException(std::format("{}: unknown lead {}", source, *lead)); + } + supplies.lead = story_lead_after_brock(); + }else if (execution.get_value("lead") != nullptr){ + throw ParseException(std::format("{}: lead must be a string", source)); + } return supplies; } -// What a walk does about wild Pokemon: runs, or fights them for EXP. -enum class WildBattles{ - RUN, - FIGHT, -}; - -StoryStep make(StoryStepKind kind, std::string name, std::string why){ - StoryStep step; - step.kind = kind; - step.name = std::move(name); - step.why = std::move(why); - return step; -} - -StoryStep route(std::string name, Pokemon::Pose target, std::string why, WildBattles wild = WildBattles::RUN){ - StoryStep step = make(StoryStepKind::ROUTE, std::move(name), std::move(why)); - step.target = std::move(target); - step.fight_wild = wild == WildBattles::FIGHT; - return step; -} - -StoryStep step_into(std::string name, Direction direction, std::string why){ - StoryStep step = make(StoryStepKind::STEP, std::move(name), std::move(why)); - step.direction = direction; - return step; -} - -StoryStep answer(std::string name, bool yes, std::string why){ - StoryStep step = make(StoryStepKind::ANSWER, std::move(name), std::move(why)); - step.yes = yes; - return step; -} - -StoryStep scene(std::string name, std::optional pose_after, std::string why){ - StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep battle(std::string name, Pokemon::Pose pose_after, bool may_lose, std::string why){ - StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why)); - step.pose_after = std::move(pose_after); - step.may_lose = may_lose; - return step; -} - -StoryStep legs(std::string name, std::vector legs, std::string why, WildBattles wild = WildBattles::RUN){ - StoryStep step = make(StoryStepKind::LEGS, std::move(name), std::move(why)); - step.legs = std::move(legs); - step.fight_wild = wild == WildBattles::FIGHT; - return step; -} - -// `step`, a ROUTE or LEGS, run with B held: from the Running Shoes on. No -// checkpoint after 00.10 is in the table yet. -[[maybe_unused]] StoryStep running(StoryStep step){ - step.variant = RUN_VARIANT; - return step; -} - -StoryStep new_game_intro(Pokemon::Pose pose_after, std::string why){ - StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep talk(std::string name, std::string why){ - return make(StoryStepKind::TALK, std::move(name), std::move(why)); -} - -StoryStep ready(std::string name, Pokemon::Pose nurse, std::string why){ - StoryStep step = make(StoryStepKind::READY, std::move(name), std::move(why)); - step.target = std::move(nurse); - return step; +// The keys of the notes: "checkpoint" or a step's id, each a list of lines. +std::set read_note_keys(const JsonObject& execution, std::string_view source){ + std::set keys; + const JsonValue* notes = execution.get_value("notes"); + if (notes == nullptr){ + return keys; + } + for (const auto& [key, lines] : notes->to_object_throw(std::string(source))){ + for (const JsonValue& line : lines.to_array_throw(std::string(source))){ + line.to_string_throw(std::string(source)); + } + keys.insert(key); + } + return keys; } -StoryStep heal(std::string name){ - return make(StoryStepKind::HEAL, std::move(name), "full HP"); -} - -StoryStep shop(std::string name, std::vector items, std::string why){ - StoryStep step = make(StoryStepKind::SHOP, std::move(name), std::move(why)); - step.items = std::move(items); - return step; -} - - -StoryCheckpoint new_game(){ - return row("00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { - // new_game.c: the bedroom at (6, 6), facing the TV. - new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, default names, rival GREEN"), - make(StoryStepKind::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), - }); -} - -StoryCheckpoint leave_house(){ - return row("00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { - route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), - }); -} - -StoryCheckpoint oaks_trigger(){ - return row("00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { - route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), - step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), - // PlayerEnter walks the player up 8 tiles from the lab's door. - scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), - }); -} - -StoryCheckpoint starter(){ - return row("00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { - route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), - talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), - answer("choose_squirtle", true, "take Squirtle"), - answer("no_nickname", false, "\"give a nickname?\" NO"), - scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)"), - route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8"), - step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), - // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. - battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), - }); -} - -StoryCheckpoint parcel(){ - return row("00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { - route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), - step_into("mart_door", NORTH, "the clerk's scene starts on entering"), - // ApproachCounter: up 4 from the mat, then faces the clerk. - scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), - }); -} - -StoryCheckpoint pokedex(){ - return row("00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { - route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), - talk("give_parcel", "Oak takes the parcel"), - scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), - }); -} - -StoryCheckpoint shopping(){ - return row("00.07", "Viridian shopping, then into Viridian Forest", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { - route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), - // 2000 of the 3000 a new game starts with, plus the rival's prize. - shop("potions_and_antidotes", {{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}, "5 Potions, 3 Antidotes, 1 Parlyz Heal"), - route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), - heal("heal_viridian"), - route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), - step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around"), - // TutorialTriggerLeft turns the player right, to the old man. - scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV"), - // After his demo the old man stands east of the player, beside (20, 8), where - // the map doesn't have him: "east 2" from there didn't move, and the walk north - // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. - route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), - // The gate's north warp lands on the forest's exit mat (29, 62), facing - // north. The save there keeps a forest failure from going back to Pallet. - route("forest_entrance", at(FOREST, 29, 62, NORTH), "Route 2 and the south gate, running from wild battles"), - }); -} - -StoryCheckpoint forest(){ - // The supplies bought in 00.07. - return row("00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { - // Wild battles are fought for EXP. Straight up the east side from the - // entrance, each leg ending on a wall (the Boy at (45, 58) stops the - // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets - // his battle and is held on to its wall after it. The by-hand run's - // detour west to (13, 46) and back is dropped. - legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", WildBattles::FIGHT), - route("forest_north", at(FOREST, 39, 25), "north part", WildBattles::FIGHT), - // To the gate by legs that end on walls, which the walker holds again - // after a battle instead of estimating where it stopped: planned - // routes with open legs lost the player in the north of the forest - // (console B, 2026-11-01). The two 1-tile legs are single steps. - legs("forest_exit", { - {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, - {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, - }, "walls all the way to the gate's column", WildBattles::FIGHT), - route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", WildBattles::FIGHT), - // Out of the forest, wild battles are run from; trainers are still fought. - route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), - heal("heal_pewter"), - }); -} +} // namespace -StoryCheckpoint brock(){ - // The by-hand save: 2 Potions and 1 Antidote left after the forest. - return row("00.09", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { - // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight - // 4) and sees (4..7, 8): walking north up column 6 from the door, - // the step onto (6, 8) starts his battle. He walks up to the player, - // who stays put and keeps facing north (FRLG doesn't turn the player - // to a trainer). That step is taken on its own, so no leg is cut. - route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), - step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), - battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), - // On to Brock unless red HP or a status is left that no item cures. - ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse only if they can't"), - route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), - talk("challenge_brock", "Brock's speech"), - battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), - }); -} -StoryCheckpoint running_shoes(){ - return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), after_brock(), StartMenu::FULL, { - // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at - // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The - // Gym guide's triggers at (42..43, 21..23) need the scene at 0. - route("before_aide_trigger", at(PEWTER, 45, 21, EAST), "out of the Gym, east along row 21, short of the top trigger"), - step_into("aide_trigger", EAST, "onto (46, 21), below the aide"), - // RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; - // the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH - // is set (console B, 2026-11-02: about 20 B presses to the overworld). - scene("shoes_from_aide", at(PEWTER, 46, 21, NORTH), "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north"), - }); +StoryCheckpoint read_story_checkpoint_file(const JsonValue& value, std::string_view source){ + StoryCheckpoint checkpoint; + std::set note_keys; + const Pokemon::ExecutionReader read_execution = [&](const JsonObject& execution, std::string_view where){ + only_fields(execution, {"menu", "supplies", "lead", "notes"}, where); + checkpoint.menu = read_start_menu(execution.get_string_throw("menu", std::string(where)), where); + checkpoint.supplies = read_supplies(execution, where); + note_keys = read_note_keys(execution, where); + }; + static_cast(checkpoint) = Pokemon::read_authored_checkpoint( + value, "frlg", source, read_execution, story_action_specs() + ); + for (const std::string& key : note_keys){ + bool found = key == "checkpoint"; + for (const StoryStep& step : checkpoint.steps){ + found |= step.name == key; + } + if (!found){ + throw ParseException(std::format("{}: notes for unknown step {}", source, key)); + } + } + return checkpoint; } -} // namespace - - const std::vector& story_checkpoints(){ - static const std::vector checkpoints{ - new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), - running_shoes(), - }; + static const std::vector checkpoints = []{ + std::vector result; + for (const auto& [name, text] : autostory_checkpoint_json()){ + result.push_back(read_story_checkpoint_file(parse_json(text), name)); + } + return result; + }(); return checkpoints; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index ab7731466e..d89e1dcf30 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -7,12 +7,31 @@ * every route and leg runs. Taken from a by-hand run on * console B (2026-11-01) and the pokefirered map scripts. * + * Each checkpoint is an authored JSON file in StoryData/ + * (frlg-.plan.json, format pokesim-authored-checkpoint/1): the shared + * checkpoint, its steps each an action with args, read against FRLG's + * actions (story_action_specs()), and FRLG's execution object: + * + * "menu" before_pokemon, before_pokedex or full: the START menu + * at its end (StoryCheckpoint::menu); + * "supplies" optional: {"potions", "antidotes", "parlyz_heals"} at + * its start, for a run that loads its save; + * "lead" optional: "after_brock", the starter as the story left + * it by Brock (story_lead_after_brock()); + * "notes" optional: {"checkpoint" or a step's id: [lines]}, the + * reasons behind a step that a reader of the file needs. + * The program doesn't read them. + * */ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryTable_H #define PokemonAutomation_PokemonFRLG_AutoStoryTable_H +#include +#include +#include #include +#include "Common/Cpp/Json/JsonValue.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -21,12 +40,23 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Checkpoints 00.01 to 00.10, in order. +// (name, JSON text) of each file in StoryData/, sorted by name. +// Generated at build time (SerialPrograms/cmake/EmbedTextFiles.cmake). +const std::vector>& autostory_checkpoint_json(); + +// The checkpoint of an authored FRLG file. Throws ParseException when +// the file is malformed, names an action FRLG doesn't have, gives an +// action args it doesn't take, or has notes for a step it doesn't have. +StoryCheckpoint read_story_checkpoint_file(const JsonValue& value, std::string_view source); + +// Checkpoints 00.01 to 00.10, in order: every file in StoryData/. const std::vector& story_checkpoints(); // Registers AutoStory table validation unit tests. void add_tests_AutoStory(UnitTestDatabase& database); +// The story files against the C++ rows they replace. +void add_tests_AutoStoryTableParity(UnitTestDatabase& database); // The table run end to end against a fake game (PokemonFRLG_AutoStorySimulation_Tests.cpp). void add_tests_AutoStorySimulation(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp new file mode 100644 index 0000000000..9b592aeed1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp @@ -0,0 +1,344 @@ +/* AutoStory Table Parity Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The C++ rows the story table had before StoryData/, built with the + * shared step API, against the checkpoints read from the files: each + * loads to the same steps, args (with the fallbacks the reader fills in), + * poses, supplies and START menu. Removed with the C++ rows. + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" +#include "PokemonFRLG_AutoStoryParty.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +constexpr Direction NORTH = Direction::NORTH; +constexpr Direction SOUTH = Direction::SOUTH; +constexpr Direction EAST = Direction::EAST; +constexpr Direction WEST = Direction::WEST; + +constexpr std::string_view BEDROOM = "PalletTown_PlayersHouse_2F"; +constexpr std::string_view PALLET = "PalletTown"; +constexpr std::string_view LAB = "PalletTown_ProfessorOaksLab"; +constexpr std::string_view VIRIDIAN = "ViridianCity"; +constexpr std::string_view VIRIDIAN_MART = "ViridianCity_Mart"; +constexpr std::string_view VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; +constexpr std::string_view FOREST = "ViridianForest"; +constexpr std::string_view FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; +constexpr std::string_view PEWTER = "PewterCity"; +constexpr std::string_view PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; +constexpr std::string_view GYM = "PewterCity_Gym"; + +Pokemon::GridPose at(std::string_view map, int x, int y, std::optional facing = std::nullopt){ + return Pokemon::GridPose{std::string(map), {{x, y}}, facing}; +} + +StoryCheckpoint row( + std::string id, std::string title, std::optional start, + Supplies supplies, StartMenu menu, std::vector steps +){ + StoryCheckpoint checkpoint; + checkpoint.id = std::move(id); + checkpoint.title = std::move(title); + checkpoint.start = std::move(start); + checkpoint.steps = std::move(steps); + checkpoint.supplies = supplies; + checkpoint.menu = menu; + return checkpoint; +} + +Supplies after_brock(){ + Supplies supplies; + supplies.lead = story_lead_after_brock(); + return supplies; +} + +// What a walk does about wild Pokemon: runs, or fights them for EXP. +enum class WildBattles{ + RUN, + FIGHT, +}; + +StoryStep make(StoryStepKind kind, std::string name, std::string why, Pokemon::StoryActionArgs args = {}){ + StoryStep step; + step.kind = kind; + step.name = std::move(name); + step.why = std::move(why); + step.args = std::move(args); + return step; +} + +StoryStep route(std::string name, Pokemon::GridPose target, std::string why, WildBattles wild = WildBattles::RUN){ + return make(StoryStepKind::ROUTE, std::move(name), std::move(why), { + {"target", std::move(target)}, {"fight_wild", wild == WildBattles::FIGHT}, + }); +} + +StoryStep step_into(std::string name, Direction direction, std::string why){ + return make(StoryStepKind::STEP, std::move(name), std::move(why), {{"direction", direction}}); +} + +StoryStep answer(std::string name, bool yes, std::string why){ + return make(StoryStepKind::ANSWER, std::move(name), std::move(why), {{"yes", yes}}); +} + +StoryStep scene(std::string name, std::optional pose_after, std::string why){ + StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep battle(std::string name, Pokemon::GridPose pose_after, bool may_lose, std::string why){ + StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why), {{"may_lose", may_lose}}); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep legs(std::string name, std::vector legs, std::string why, WildBattles wild = WildBattles::RUN){ + return make(StoryStepKind::LEGS, std::move(name), std::move(why), { + {"legs", std::move(legs)}, {"fight_wild", wild == WildBattles::FIGHT}, + }); +} + +StoryStep new_game_intro(Pokemon::GridPose pose_after, std::string why){ + StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); + step.pose_after = std::move(pose_after); + return step; +} + +StoryStep talk(std::string name, std::string why){ + return make(StoryStepKind::TALK, std::move(name), std::move(why)); +} + +StoryStep ready(std::string name, Pokemon::GridPose nurse, std::string why){ + return make(StoryStepKind::READY, std::move(name), std::move(why), {{"target", std::move(nurse)}}); +} + +StoryStep heal(std::string name){ + return make(StoryStepKind::HEAL, std::move(name), "full HP"); +} + +StoryStep shop(std::string name, std::vector items, std::string why){ + return make(StoryStepKind::SHOP, std::move(name), std::move(why), {{"items", std::move(items)}}); +} + + +StoryCheckpoint new_game(){ + return row("00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { + // new_game.c: the bedroom at (6, 6), facing the TV. + new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, default names, rival GREEN"), + make(StoryStepKind::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), + }); +} + +StoryCheckpoint leave_house(){ + return row("00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { + route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), + }); +} + +StoryCheckpoint oaks_trigger(){ + return row("00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { + route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), + step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), + // PlayerEnter walks the player up 8 tiles from the lab's door. + scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), + }); +} + +StoryCheckpoint starter(){ + return row("00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { + route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), + talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), + answer("choose_squirtle", true, "take Squirtle"), + answer("no_nickname", false, "\"give a nickname?\" NO"), + scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)"), + route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8"), + step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), + // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. + battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), + }); +} + +StoryCheckpoint parcel(){ + return row("00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { + route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), + step_into("mart_door", NORTH, "the clerk's scene starts on entering"), + // ApproachCounter: up 4 from the mat, then faces the clerk. + scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), + }); +} + +StoryCheckpoint pokedex(){ + return row("00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { + route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), + talk("give_parcel", "Oak takes the parcel"), + scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), + }); +} + +StoryCheckpoint shopping(){ + return row("00.07", "Viridian shopping, then into Viridian Forest", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { + route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), + // 2000 of the 3000 a new game starts with, plus the rival's prize. + shop("potions_and_antidotes", {{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}, "5 Potions, 3 Antidotes, 1 Parlyz Heal"), + route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), + heal("heal_viridian"), + route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), + step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around"), + // TutorialTriggerLeft turns the player right, to the old man. + scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV"), + // After his demo the old man stands east of the player, beside (20, 8), where + // the map doesn't have him: "east 2" from there didn't move, and the walk north + // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. + route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), + // The gate's north warp lands on the forest's exit mat (29, 62), facing + // north. The save there keeps a forest failure from going back to Pallet. + route("forest_entrance", at(FOREST, 29, 62, NORTH), "Route 2 and the south gate, running from wild battles"), + }); +} + +StoryCheckpoint forest(){ + // The supplies bought in 00.07. + return row("00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { + // Wild battles are fought for EXP. Straight up the east side from the + // entrance, each leg ending on a wall (the Boy at (45, 58) stops the + // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets + // his battle and is held on to its wall after it. The by-hand run's + // detour west to (13, 46) and back is dropped. + legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", WildBattles::FIGHT), + route("forest_north", at(FOREST, 39, 25), "north part", WildBattles::FIGHT), + // To the gate by legs that end on walls, which the walker holds again + // after a battle instead of estimating where it stopped: planned + // routes with open legs lost the player in the north of the forest + // (console B, 2026-11-01). The two 1-tile legs are single steps. + legs("forest_exit", { + {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, + {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, + }, "walls all the way to the gate's column", WildBattles::FIGHT), + route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", WildBattles::FIGHT), + // Out of the forest, wild battles are run from; trainers are still fought. + route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), + heal("heal_pewter"), + }); +} + +StoryCheckpoint brock(){ + // The by-hand save: 2 Potions and 1 Antidote left after the forest. + return row("00.09", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { + // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight + // 4) and sees (4..7, 8): walking north up column 6 from the door, + // the step onto (6, 8) starts his battle. He walks up to the player, + // who stays put and keeps facing north (FRLG doesn't turn the player + // to a trainer). That step is taken on its own, so no leg is cut. + route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), + step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), + battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), + // On to Brock unless red HP or a status is left that no item cures. + ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse only if they can't"), + route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), + talk("challenge_brock", "Brock's speech"), + battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), + }); +} + +StoryCheckpoint running_shoes(){ + return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), after_brock(), StartMenu::FULL, { + // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at + // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The + // Gym guide's triggers at (42..43, 21..23) need the scene at 0. + route("before_aide_trigger", at(PEWTER, 45, 21, EAST), "out of the Gym, east along row 21, short of the top trigger"), + step_into("aide_trigger", EAST, "onto (46, 21), below the aide"), + // RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; + // the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH + // is set (console B, 2026-11-02: about 20 B presses to the overworld). + scene("shoes_from_aide", at(PEWTER, 46, 21, NORTH), "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north"), + }); +} + + +std::vector cpp_rows(){ + return { + new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), + running_shoes(), + }; +} + +// Why `loaded` differs from `row`, or empty. Steps compare as their +// shared JSON, which writes every field. +std::string checkpoint_difference(const StoryCheckpoint& row, const StoryCheckpoint& loaded){ + const std::string row_json = Pokemon::story_checkpoint_json(row).dump(); + const std::string loaded_json = Pokemon::story_checkpoint_json(loaded).dump(); + if (row_json != loaded_json){ + return std::format("{}: the file loads to\n{}\nbut the C++ row is\n{}", row.id, loaded_json, row_json); + } + if (row.menu != loaded.menu){ + return row.id + ": a different START menu."; + } + const Supplies& a = row.supplies; + const Supplies& b = loaded.supplies; + if (a.potions != b.potions || a.antidotes != b.antidotes || a.parlyz_heals != b.parlyz_heals){ + return row.id + ": different supplies."; + } + if (a.lead.species != b.lead.species || a.lead.level != b.lead.level || a.lead.moves.size() != b.lead.moves.size()){ + return row.id + ": a different lead."; + } + for (size_t c = 0; c < a.lead.moves.size(); c++){ + if (a.lead.moves[c].move != b.lead.moves[c].move || a.lead.moves[c].pp != b.lead.moves[c].pp){ + return row.id + ": a different lead move " + std::to_string(c + 1) + "."; + } + } + return ""; +} + +class Test_AutoStoryTableParity : public UnitTest{ +public: + Test_AutoStoryTableParity() + : UnitTest("PokemonFRLG::AutoStory - the story files load to the C++ rows") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + const std::vector rows = cpp_rows(); + const std::vector& loaded = story_checkpoints(); + if (rows.size() != loaded.size()){ + return std::format("{} C++ rows, {} files.", rows.size(), loaded.size()); + } + for (size_t c = 0; c < rows.size(); c++){ + const std::string difference = checkpoint_difference(rows[c], loaded[c]); + if (!difference.empty()){ + return difference; + } + } + return true; + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } +}; + +} // namespace + + +void add_tests_AutoStoryTableParity(UnitTestDatabase& database){ + database.add(); +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index ee7c0f43c7..9aa3be8596 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -84,7 +84,8 @@ std::string describe(const StoryPose& pose){ } // A table pose as a StoryPose; FRLG's table has one-tile poses only. -StoryPose one_tile(const Pokemon::Pose& pose){ +StoryPose one_tile(const Pokemon::GridPose& grid_pose){ + const Pokemon::Pose pose = Pokemon::pose_of(grid_pose); const std::optional ret = story_pose(pose); if (!ret){ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Not a one-tile pose: " + Pokemon::to_string(pose)); @@ -138,7 +139,7 @@ UnitTestResult check_held_legs(const std::string& name, const std::vector> route = fixed_route(story_maps(), MapPosition{pose.map, pose.tile}, step.legs); + const std::optional> route = fixed_route(story_maps(), MapPosition{pose.map, pose.tile}, Pokemon::story_arg>(step.args, "legs")); if (!route || route->empty()){ return step.name + ": the legs can't be walked from " + describe(pose) + "."; } @@ -163,10 +164,7 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step){ return step.name + ": the facing is unknown at " + describe(pose) + " and no wall is beside it."; } } - if (!step.target){ - return step.name + ": no target."; - } - const StoryPose target = one_tile(*step.target); + const StoryPose target = one_tile(Pokemon::story_arg(step.args, "target")); const RouteGoal goal{{target.map, target.tile}, target.facing}; const std::optional> route = plan_overworld_route(story_maps(), start, goal, default_route_costs(), facing); if (!route){ @@ -214,7 +212,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po return checkpoint.id + " " + result.message; } }else if (step.kind == StoryStepKind::STEP){ - pose = StoryPose{pose.map, pose.tile.next(step.direction), step.direction}; + const Direction direction = Pokemon::story_arg(step.args, "direction"); + pose = StoryPose{pose.map, pose.tile.next(direction), direction}; } if (step.pose_after){ pose = one_tile(*step.pose_after); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json new file mode 100644 index 0000000000..31eea5b1d0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json @@ -0,0 +1,29 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.01", + "title": "new game to the bedroom", + "events": [ + { + "id": "intro", + "kind": "new_game", + "declared_after": {"map": "PalletTown_PlayersHouse_2F", "tiles": [[6, 6]], "facing": "north"}, + "why": "Oak's speech, BOY, default names, rival GREEN" + }, + { + "id": "options", + "kind": "options", + "why": "fast text; no switch prompt between a trainer's Pokemon" + } + ] + }, + "execution": { + "menu": "before_pokemon", + "notes": { + "intro": [ + "new_game.c: the bedroom at (6, 6), facing the TV." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json new file mode 100644 index 0000000000..2f09e7db16 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.02.plan.json @@ -0,0 +1,22 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.02", + "title": "bedroom to Pallet Town", + "start": {"map": "PalletTown_PlayersHouse_2F", "tiles": [[6, 6]], "facing": "north"}, + "events": [ + { + "id": "front_door", + "kind": "route", + "args": { + "target": {"map": "PalletTown", "tiles": [[6, 8]]} + }, + "why": "down the stairs and out of the house" + } + ] + }, + "execution": { + "menu": "before_pokemon" + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json new file mode 100644 index 0000000000..b44478b878 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.03.plan.json @@ -0,0 +1,41 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.03", + "title": "Oak stops the player and walks them to the lab", + "start": {"map": "PalletTown", "tiles": [[6, 8]], "facing": "south"}, + "events": [ + { + "id": "below_oaks_trigger", + "kind": "route", + "args": { + "target": {"map": "PalletTown", "tiles": [[12, 2]], "facing": "north"} + }, + "why": "below the north exit, short of Oak's trigger at (12, 1)" + }, + { + "id": "oaks_trigger", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "the trigger: \"Don't go out!\"" + }, + { + "id": "to_the_lab", + "kind": "scene", + "declared_after": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "north"}, + "why": "Oak walks the player into the lab; the scene ends at the table" + } + ] + }, + "execution": { + "menu": "before_pokemon", + "notes": { + "to_the_lab": [ + "PlayerEnter walks the player up 8 tiles from the lab's door." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json new file mode 100644 index 0000000000..af5c28173a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json @@ -0,0 +1,76 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.04", + "title": "Squirtle, then the rival's battle", + "start": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "north"}, + "events": [ + { + "id": "below_squirtle", + "kind": "route", + "args": { + "target": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[9, 5]], "facing": "north"} + }, + "why": "under Squirtle's ball (9, 4)" + }, + { + "id": "squirtle_ball", + "kind": "talk", + "why": "\"So, you want the WATER POKEMON SQUIRTLE?\"" + }, + { + "id": "choose_squirtle", + "kind": "answer", + "why": "take Squirtle" + }, + { + "id": "no_nickname", + "kind": "answer", + "args": { + "yes": false + }, + "why": "\"give a nickname?\" NO" + }, + { + "id": "rival_takes_bulbasaur", + "kind": "scene", + "declared_after": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[9, 5]], "facing": "north"}, + "why": "the rival picks his ball; the player still faces the table (console B, 2026-11-01)" + }, + { + "id": "above_rival_trigger", + "kind": "route", + "args": { + "target": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[7, 7]], "facing": "south"} + }, + "why": "short of the rival's trigger row 8" + }, + { + "id": "rival_trigger", + "kind": "step", + "args": { + "direction": "south" + }, + "why": "\"Wait, let's check out our POKEMON!\"" + }, + { + "id": "rival_battle", + "kind": "battle", + "args": { + "may_lose": true + }, + "declared_after": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[7, 8]], "facing": "south"}, + "why": "the tutorial battle; losing goes on too" + } + ] + }, + "execution": { + "menu": "before_pokedex", + "notes": { + "rival_battle": [ + "The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json new file mode 100644 index 0000000000..d3923d0565 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.05.plan.json @@ -0,0 +1,41 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.05", + "title": "Route 1 to Viridian Mart: Oak's Parcel", + "start": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[7, 8]], "facing": "south"}, + "events": [ + { + "id": "below_mart_door", + "kind": "route", + "args": { + "target": {"map": "ViridianCity", "tiles": [[36, 20]], "facing": "north"} + }, + "why": "Route 1, running from wild battles" + }, + { + "id": "mart_door", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "the clerk's scene starts on entering" + }, + { + "id": "parcel_from_clerk", + "kind": "scene", + "declared_after": {"map": "ViridianCity_Mart", "tiles": [[4, 3]], "facing": "west"}, + "why": "the clerk gives OAK'S PARCEL" + } + ] + }, + "execution": { + "menu": "before_pokedex", + "notes": { + "parcel_from_clerk": [ + "ApproachCounter: up 4 from the mat, then faces the clerk." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json new file mode 100644 index 0000000000..431917879d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.06.plan.json @@ -0,0 +1,33 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.06", + "title": "Oak's Parcel to the Pokedex", + "start": {"map": "ViridianCity_Mart", "tiles": [[4, 3]], "facing": "west"}, + "events": [ + { + "id": "below_oak", + "kind": "route", + "args": { + "target": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "north"} + }, + "why": "back down Route 1 to Oak" + }, + { + "id": "give_parcel", + "kind": "talk", + "why": "Oak takes the parcel" + }, + { + "id": "pokedex_scene", + "kind": "scene", + "declared_after": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "south"}, + "why": "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)" + } + ] + }, + "execution": { + "menu": "full" + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json new file mode 100644 index 0000000000..4abe1885aa --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.07.plan.json @@ -0,0 +1,95 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.07", + "title": "Viridian shopping, then into Viridian Forest", + "start": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[6, 4]], "facing": "south"}, + "events": [ + { + "id": "mart_clerk", + "kind": "route", + "args": { + "target": {"map": "ViridianCity_Mart", "tiles": [[4, 3]], "facing": "west"} + }, + "why": "Route 1 again" + }, + { + "id": "potions_and_antidotes", + "kind": "shop", + "args": { + "items": [{"item": "potion", "quantity": 5}, {"item": "antidote", "quantity": 3}, {"item": "parlyz_heal", "quantity": 1}] + }, + "why": "5 Potions, 3 Antidotes, 1 Parlyz Heal" + }, + { + "id": "viridian_nurse", + "kind": "route", + "args": { + "target": {"map": "ViridianCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "heal before the forest" + }, + { + "id": "heal_viridian", + "kind": "heal", + "why": "full HP" + }, + { + "id": "below_old_man_trigger", + "kind": "route", + "args": { + "target": {"map": "ViridianCity", "tiles": [[20, 9]], "facing": "north"} + }, + "why": "short of the tutorial trigger (20, 8)" + }, + { + "id": "old_man_trigger", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "the old man's catching tutorial can't be walked around" + }, + { + "id": "old_man_tutorial", + "kind": "scene", + "declared_after": {"map": "ViridianCity", "tiles": [[20, 8]], "facing": "east"}, + "why": "about 60 lines and his demo battle; TEACHY TV" + }, + { + "id": "past_old_man", + "kind": "route", + "args": { + "target": {"map": "ViridianCity", "tiles": [[20, 5]], "facing": "north"} + }, + "why": "north along column 20, clear of the old man" + }, + { + "id": "forest_entrance", + "kind": "route", + "args": { + "target": {"map": "ViridianForest", "tiles": [[29, 62]], "facing": "north"} + }, + "why": "Route 2 and the south gate, running from wild battles" + } + ] + }, + "execution": { + "menu": "full", + "notes": { + "potions_and_antidotes": [ + "2000 of the 3000 a new game starts with, plus the rival's prize." + ], + "old_man_tutorial": [ + "TutorialTriggerLeft turns the player right, to the old man." + ], + "past_old_man": [ + "After his demo the old man stands east of the player, beside (20, 8), where the map doesn't have him: \"east 2\" from there didn't move, and the walk north ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first." + ], + "forest_entrance": [ + "The gate's north warp lands on the forest's exit mat (29, 62), facing north. The save there keeps a forest failure from going back to Pallet." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json new file mode 100644 index 0000000000..c02e6e877f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.08.plan.json @@ -0,0 +1,82 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.08", + "title": "Viridian Forest to Pewter Center", + "start": {"map": "ViridianForest", "tiles": [[29, 62]], "facing": "north"}, + "events": [ + { + "id": "forest_east", + "kind": "legs", + "args": { + "legs": [{"direction": "east", "tiles": 1}, {"direction": "north", "tiles": 4}, {"direction": "east", "tiles": 14}, {"direction": "north", "tiles": 15}], + "fight_wild": true + }, + "why": "up the east side to (44, 43)" + }, + { + "id": "forest_north", + "kind": "route", + "args": { + "target": {"map": "ViridianForest", "tiles": [[39, 25]]}, + "fight_wild": true + }, + "why": "north part" + }, + { + "id": "forest_exit", + "kind": "legs", + "args": { + "legs": [{"direction": "north", "tiles": 10}, {"direction": "west", "tiles": 12}, {"direction": "south", "tiles": 10}, {"direction": "west", "tiles": 6}, {"direction": "north", "tiles": 20}, {"direction": "south", "tiles": 1}, {"direction": "west", "tiles": 10}, {"direction": "south", "tiles": 27}, {"direction": "west", "tiles": 8}, {"direction": "north", "tiles": 20}, {"direction": "east", "tiles": 1}], + "fight_wild": true + }, + "why": "walls all the way to the gate's column" + }, + { + "id": "forest_gate", + "kind": "route", + "args": { + "target": {"map": "Route2_ViridianForest_NorthEntrance", "tiles": [[7, 10]], "facing": "north"}, + "fight_wild": true + }, + "why": "north onto the exit, arriving on the gate's mat" + }, + { + "id": "pewter_nurse", + "kind": "route", + "args": { + "target": {"map": "PewterCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "Route 2 north to Pewter's Center" + }, + { + "id": "heal_pewter", + "kind": "heal", + "why": "full HP" + } + ] + }, + "execution": { + "menu": "full", + "supplies": { + "potions": 5, + "antidotes": 3, + "parlyz_heals": 1 + }, + "notes": { + "checkpoint": [ + "The supplies bought in 00.07." + ], + "forest_east": [ + "Wild battles are fought for EXP. Straight up the east side from the entrance, each leg ending on a wall (the Boy at (45, 58) stops the east one). Rick (47, 45) sees (42..46, 45), so the last leg meets his battle and is held on to its wall after it. The by-hand run's detour west to (13, 46) and back is dropped." + ], + "forest_exit": [ + "To the gate by legs that end on walls, which the walker holds again after a battle instead of estimating where it stopped: planned routes with open legs lost the player in the north of the forest (console B, 2026-11-01). The two 1-tile legs are single steps." + ], + "pewter_nurse": [ + "Out of the forest, wild battles are run from; trainers are still fought." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json new file mode 100644 index 0000000000..28b36cc3e4 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.09.plan.json @@ -0,0 +1,79 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.09", + "title": "Pewter Gym: Camper Liam, then Brock", + "start": {"map": "PewterCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"}, + "events": [ + { + "id": "below_liam_line", + "kind": "route", + "args": { + "target": {"map": "PewterCity_Gym", "tiles": [[6, 9]], "facing": "north"} + }, + "why": "in by the door, up column 6 to below Liam's row" + }, + { + "id": "liam_line", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "onto (6, 8), in Liam's line" + }, + { + "id": "camper_liam", + "kind": "battle", + "declared_after": {"map": "PewterCity_Gym", "tiles": [[6, 8]], "facing": "north"}, + "why": "Geodude and Sandshrew; EXP before Brock" + }, + { + "id": "ready_for_brock", + "kind": "ready", + "args": { + "target": {"map": "PewterCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "items for a status or low HP; the nurse only if they can't" + }, + { + "id": "before_brock", + "kind": "route", + "args": { + "target": {"map": "PewterCity_Gym", "tiles": [[6, 6]], "facing": "north"} + }, + "why": "below Brock (6, 5); Liam, beaten, stands at (5, 8)" + }, + { + "id": "challenge_brock", + "kind": "talk", + "why": "Brock's speech" + }, + { + "id": "brock", + "kind": "battle", + "declared_after": {"map": "PewterCity_Gym", "tiles": [[6, 6]], "facing": "north"}, + "why": "Geodude and Onix, with Bubble; Boulder Badge and TM39" + } + ] + }, + "execution": { + "menu": "full", + "supplies": { + "potions": 2, + "antidotes": 1, + "parlyz_heals": 0 + }, + "notes": { + "checkpoint": [ + "The by-hand save: 2 Potions and 1 Antidote left after the forest." + ], + "below_liam_line": [ + "Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight 4) and sees (4..7, 8): walking north up column 6 from the door, the step onto (6, 8) starts his battle. He walks up to the player, who stays put and keeps facing north (FRLG doesn't turn the player to a trainer). That step is taken on its own, so no leg is cut." + ], + "ready_for_brock": [ + "On to Brock unless red HP or a status is left that no item cures." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json new file mode 100644 index 0000000000..b8cf6a8ccd --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json @@ -0,0 +1,48 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.10", + "title": "Pewter: the Running Shoes from Oak's aide", + "start": {"map": "PewterCity_Gym", "tiles": [[6, 6]], "facing": "north"}, + "events": [ + { + "id": "before_aide_trigger", + "kind": "route", + "args": { + "target": {"map": "PewterCity", "tiles": [[45, 21]], "facing": "east"} + }, + "why": "out of the Gym, east along row 21, short of the top trigger" + }, + { + "id": "aide_trigger", + "kind": "step", + "args": { + "direction": "east" + }, + "why": "onto (46, 21), below the aide" + }, + { + "id": "shoes_from_aide", + "kind": "scene", + "declared_after": {"map": "PewterCity", "tiles": [[46, 21]], "facing": "north"}, + "why": "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "At the rows after Brock: no items counted, the starter with the moves the story gave it by Lv13. A run that loads a save reads the moves off the lead's summary instead (read_lead_moves()), so a save whose moves differ from these (console B, 2026-11-02: Water Gun where Tackle was) is fought with the moves it has." + ], + "before_aide_trigger": [ + "Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The Gym guide's triggers at (42..43, 21..23) need the scene at 0." + ], + "shoes_from_aide": [ + "RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH is set (console B, 2026-11-02: about 20 B presses to the overworld)." + ] + } + } +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 9de1bf1a1f..cb22d12626 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1947,6 +1947,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp From 3f0b338f11daad2b62feae9ecccc12791313815a Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 09:59:00 -0800 Subject: [PATCH 2/3] FRLG AutoStory: delete the C++ story rows, parity proven The previous commit's parity test passed: every StoryData file loads to its old C++ row. The rows and the test go; StoryData/ is the table. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 1 - .../AutoStory/PokemonFRLG_AutoStoryTable.h | 2 - ...PokemonFRLG_AutoStoryTableParity_Tests.cpp | 344 ------------------ SerialPrograms/cmake/SourceFiles.cmake | 1 - 4 files changed, 348 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 4a5a0b5310..cea4ff7bc9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -319,7 +319,6 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); - add_tests_AutoStoryTableParity(database); add_tests_AutoStoryExport(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index d89e1dcf30..99d5ed45d4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -55,8 +55,6 @@ const std::vector& story_checkpoints(); // Registers AutoStory table validation unit tests. void add_tests_AutoStory(UnitTestDatabase& database); -// The story files against the C++ rows they replace. -void add_tests_AutoStoryTableParity(UnitTestDatabase& database); // The table run end to end against a fake game (PokemonFRLG_AutoStorySimulation_Tests.cpp). void add_tests_AutoStorySimulation(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp deleted file mode 100644 index 9b592aeed1..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/* AutoStory Table Parity Tests - * - * From: https://github.com/PokemonAutomation/ - * - * The C++ rows the story table had before StoryData/, built with the - * shared step API, against the checkpoints read from the files: each - * loads to the same steps, args (with the fallbacks the reader fills in), - * poses, supplies and START menu. Removed with the C++ rows. - * - */ - -#include -#include -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" -#include "PokemonFRLG_AutoStoryParty.h" -#include "PokemonFRLG_AutoStoryTable.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -namespace{ - -constexpr Direction NORTH = Direction::NORTH; -constexpr Direction SOUTH = Direction::SOUTH; -constexpr Direction EAST = Direction::EAST; -constexpr Direction WEST = Direction::WEST; - -constexpr std::string_view BEDROOM = "PalletTown_PlayersHouse_2F"; -constexpr std::string_view PALLET = "PalletTown"; -constexpr std::string_view LAB = "PalletTown_ProfessorOaksLab"; -constexpr std::string_view VIRIDIAN = "ViridianCity"; -constexpr std::string_view VIRIDIAN_MART = "ViridianCity_Mart"; -constexpr std::string_view VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; -constexpr std::string_view FOREST = "ViridianForest"; -constexpr std::string_view FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; -constexpr std::string_view PEWTER = "PewterCity"; -constexpr std::string_view PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; -constexpr std::string_view GYM = "PewterCity_Gym"; - -Pokemon::GridPose at(std::string_view map, int x, int y, std::optional facing = std::nullopt){ - return Pokemon::GridPose{std::string(map), {{x, y}}, facing}; -} - -StoryCheckpoint row( - std::string id, std::string title, std::optional start, - Supplies supplies, StartMenu menu, std::vector steps -){ - StoryCheckpoint checkpoint; - checkpoint.id = std::move(id); - checkpoint.title = std::move(title); - checkpoint.start = std::move(start); - checkpoint.steps = std::move(steps); - checkpoint.supplies = supplies; - checkpoint.menu = menu; - return checkpoint; -} - -Supplies after_brock(){ - Supplies supplies; - supplies.lead = story_lead_after_brock(); - return supplies; -} - -// What a walk does about wild Pokemon: runs, or fights them for EXP. -enum class WildBattles{ - RUN, - FIGHT, -}; - -StoryStep make(StoryStepKind kind, std::string name, std::string why, Pokemon::StoryActionArgs args = {}){ - StoryStep step; - step.kind = kind; - step.name = std::move(name); - step.why = std::move(why); - step.args = std::move(args); - return step; -} - -StoryStep route(std::string name, Pokemon::GridPose target, std::string why, WildBattles wild = WildBattles::RUN){ - return make(StoryStepKind::ROUTE, std::move(name), std::move(why), { - {"target", std::move(target)}, {"fight_wild", wild == WildBattles::FIGHT}, - }); -} - -StoryStep step_into(std::string name, Direction direction, std::string why){ - return make(StoryStepKind::STEP, std::move(name), std::move(why), {{"direction", direction}}); -} - -StoryStep answer(std::string name, bool yes, std::string why){ - return make(StoryStepKind::ANSWER, std::move(name), std::move(why), {{"yes", yes}}); -} - -StoryStep scene(std::string name, std::optional pose_after, std::string why){ - StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep battle(std::string name, Pokemon::GridPose pose_after, bool may_lose, std::string why){ - StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why), {{"may_lose", may_lose}}); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep legs(std::string name, std::vector legs, std::string why, WildBattles wild = WildBattles::RUN){ - return make(StoryStepKind::LEGS, std::move(name), std::move(why), { - {"legs", std::move(legs)}, {"fight_wild", wild == WildBattles::FIGHT}, - }); -} - -StoryStep new_game_intro(Pokemon::GridPose pose_after, std::string why){ - StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep talk(std::string name, std::string why){ - return make(StoryStepKind::TALK, std::move(name), std::move(why)); -} - -StoryStep ready(std::string name, Pokemon::GridPose nurse, std::string why){ - return make(StoryStepKind::READY, std::move(name), std::move(why), {{"target", std::move(nurse)}}); -} - -StoryStep heal(std::string name){ - return make(StoryStepKind::HEAL, std::move(name), "full HP"); -} - -StoryStep shop(std::string name, std::vector items, std::string why){ - return make(StoryStepKind::SHOP, std::move(name), std::move(why), {{"items", std::move(items)}}); -} - - -StoryCheckpoint new_game(){ - return row("00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { - // new_game.c: the bedroom at (6, 6), facing the TV. - new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, default names, rival GREEN"), - make(StoryStepKind::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"), - }); -} - -StoryCheckpoint leave_house(){ - return row("00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { - route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), - }); -} - -StoryCheckpoint oaks_trigger(){ - return row("00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { - route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), - step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), - // PlayerEnter walks the player up 8 tiles from the lab's door. - scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), - }); -} - -StoryCheckpoint starter(){ - return row("00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { - route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), - talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), - answer("choose_squirtle", true, "take Squirtle"), - answer("no_nickname", false, "\"give a nickname?\" NO"), - scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)"), - route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8"), - step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), - // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. - battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), - }); -} - -StoryCheckpoint parcel(){ - return row("00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { - route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), - step_into("mart_door", NORTH, "the clerk's scene starts on entering"), - // ApproachCounter: up 4 from the mat, then faces the clerk. - scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), - }); -} - -StoryCheckpoint pokedex(){ - return row("00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { - route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), - talk("give_parcel", "Oak takes the parcel"), - scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), - }); -} - -StoryCheckpoint shopping(){ - return row("00.07", "Viridian shopping, then into Viridian Forest", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { - route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), - // 2000 of the 3000 a new game starts with, plus the rival's prize. - shop("potions_and_antidotes", {{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}, "5 Potions, 3 Antidotes, 1 Parlyz Heal"), - route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), - heal("heal_viridian"), - route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), - step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around"), - // TutorialTriggerLeft turns the player right, to the old man. - scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV"), - // After his demo the old man stands east of the player, beside (20, 8), where - // the map doesn't have him: "east 2" from there didn't move, and the walk north - // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. - route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), - // The gate's north warp lands on the forest's exit mat (29, 62), facing - // north. The save there keeps a forest failure from going back to Pallet. - route("forest_entrance", at(FOREST, 29, 62, NORTH), "Route 2 and the south gate, running from wild battles"), - }); -} - -StoryCheckpoint forest(){ - // The supplies bought in 00.07. - return row("00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { - // Wild battles are fought for EXP. Straight up the east side from the - // entrance, each leg ending on a wall (the Boy at (45, 58) stops the - // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets - // his battle and is held on to its wall after it. The by-hand run's - // detour west to (13, 46) and back is dropped. - legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", WildBattles::FIGHT), - route("forest_north", at(FOREST, 39, 25), "north part", WildBattles::FIGHT), - // To the gate by legs that end on walls, which the walker holds again - // after a battle instead of estimating where it stopped: planned - // routes with open legs lost the player in the north of the forest - // (console B, 2026-11-01). The two 1-tile legs are single steps. - legs("forest_exit", { - {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, - {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, - }, "walls all the way to the gate's column", WildBattles::FIGHT), - route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", WildBattles::FIGHT), - // Out of the forest, wild battles are run from; trainers are still fought. - route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), - heal("heal_pewter"), - }); -} - -StoryCheckpoint brock(){ - // The by-hand save: 2 Potions and 1 Antidote left after the forest. - return row("00.09", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { - // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight - // 4) and sees (4..7, 8): walking north up column 6 from the door, - // the step onto (6, 8) starts his battle. He walks up to the player, - // who stays put and keeps facing north (FRLG doesn't turn the player - // to a trainer). That step is taken on its own, so no leg is cut. - route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), - step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), - battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), - // On to Brock unless red HP or a status is left that no item cures. - ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse only if they can't"), - route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), - talk("challenge_brock", "Brock's speech"), - battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), - }); -} - -StoryCheckpoint running_shoes(){ - return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), after_brock(), StartMenu::FULL, { - // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at - // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The - // Gym guide's triggers at (42..43, 21..23) need the scene at 0. - route("before_aide_trigger", at(PEWTER, 45, 21, EAST), "out of the Gym, east along row 21, short of the top trigger"), - step_into("aide_trigger", EAST, "onto (46, 21), below the aide"), - // RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; - // the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH - // is set (console B, 2026-11-02: about 20 B presses to the overworld). - scene("shoes_from_aide", at(PEWTER, 46, 21, NORTH), "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north"), - }); -} - - -std::vector cpp_rows(){ - return { - new_game(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), - running_shoes(), - }; -} - -// Why `loaded` differs from `row`, or empty. Steps compare as their -// shared JSON, which writes every field. -std::string checkpoint_difference(const StoryCheckpoint& row, const StoryCheckpoint& loaded){ - const std::string row_json = Pokemon::story_checkpoint_json(row).dump(); - const std::string loaded_json = Pokemon::story_checkpoint_json(loaded).dump(); - if (row_json != loaded_json){ - return std::format("{}: the file loads to\n{}\nbut the C++ row is\n{}", row.id, loaded_json, row_json); - } - if (row.menu != loaded.menu){ - return row.id + ": a different START menu."; - } - const Supplies& a = row.supplies; - const Supplies& b = loaded.supplies; - if (a.potions != b.potions || a.antidotes != b.antidotes || a.parlyz_heals != b.parlyz_heals){ - return row.id + ": different supplies."; - } - if (a.lead.species != b.lead.species || a.lead.level != b.lead.level || a.lead.moves.size() != b.lead.moves.size()){ - return row.id + ": a different lead."; - } - for (size_t c = 0; c < a.lead.moves.size(); c++){ - if (a.lead.moves[c].move != b.lead.moves[c].move || a.lead.moves[c].pp != b.lead.moves[c].pp){ - return row.id + ": a different lead move " + std::to_string(c + 1) + "."; - } - } - return ""; -} - -class Test_AutoStoryTableParity : public UnitTest{ -public: - Test_AutoStoryTableParity() - : UnitTest("PokemonFRLG::AutoStory - the story files load to the C++ rows") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - try{ - const std::vector rows = cpp_rows(); - const std::vector& loaded = story_checkpoints(); - if (rows.size() != loaded.size()){ - return std::format("{} C++ rows, {} files.", rows.size(), loaded.size()); - } - for (size_t c = 0; c < rows.size(); c++){ - const std::string difference = checkpoint_difference(rows[c], loaded[c]); - if (!difference.empty()){ - return difference; - } - } - return true; - }catch (Exception& e){ - return std::string(e.name()) + ": " + e.message(); - } - } -}; - -} // namespace - - -void add_tests_AutoStoryTableParity(UnitTestDatabase& database){ - database.add(); -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index cb22d12626..9de1bf1a1f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1947,7 +1947,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp From 9d54f1bd4d91f279edaad19b6d8cc48bbe4df1b5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 10:03:35 -0800 Subject: [PATCH 3/3] FRLG AutoStory: delete stage 2's C++ story rows, parity proven The merge's parity test passed: every StoryData file, 00.01b and the 00.04/00.04b split included, loads to its C++ row. The rows and the test go. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 1 - .../AutoStory/PokemonFRLG_AutoStoryTable.h | 2 - ...PokemonFRLG_AutoStoryTableParity_Tests.cpp | 379 ------------------ SerialPrograms/cmake/SourceFiles.cmake | 1 - 4 files changed, 383 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 5c65e8ee28..bc405956b3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -911,7 +911,6 @@ void add_tests(UnitTestDatabase& database){ add_tests_OverworldRecovery(database); add_tests_PlayerFacingReader(database); add_tests_AutoStory(database); - add_tests_AutoStoryTableParity(database); add_tests_AutoStoryExport(database); add_tests_AutoStorySimulation(database); add_tests_AutoStoryItems(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 50bfe92342..0201a8e65f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -61,8 +61,6 @@ const std::vector& story_checkpoints(); // Registers AutoStory table validation unit tests. void add_tests_AutoStory(UnitTestDatabase& database); -// The story files against the C++ rows they replace. -void add_tests_AutoStoryTableParity(UnitTestDatabase& database); // The table run end to end against a fake game (PokemonFRLG_AutoStorySimulation_Tests.cpp). void add_tests_AutoStorySimulation(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp deleted file mode 100644 index d4853c8a49..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp +++ /dev/null @@ -1,379 +0,0 @@ -/* AutoStory Table Parity Tests - * - * From: https://github.com/PokemonAutomation/ - * - * The C++ rows the story table had before StoryData/, built with the - * shared step API, against the checkpoints read from the files: each - * loads to the same steps, args (with the fallbacks the reader fills in), - * poses, supplies and START menu. Removed with the C++ rows. - * - */ - -#include -#include -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" -#include "PokemonFRLG_AutoStoryParty.h" -#include "PokemonFRLG_AutoStoryTable.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -namespace{ - -constexpr Direction NORTH = Direction::NORTH; -constexpr Direction SOUTH = Direction::SOUTH; -constexpr Direction EAST = Direction::EAST; -constexpr Direction WEST = Direction::WEST; - -constexpr std::string_view BEDROOM = "PalletTown_PlayersHouse_2F"; -constexpr std::string_view PALLET = "PalletTown"; -constexpr std::string_view LAB = "PalletTown_ProfessorOaksLab"; -constexpr std::string_view VIRIDIAN = "ViridianCity"; -constexpr std::string_view VIRIDIAN_MART = "ViridianCity_Mart"; -constexpr std::string_view VIRIDIAN_CENTER = "ViridianCity_PokemonCenter_1F"; -constexpr std::string_view FOREST = "ViridianForest"; -constexpr std::string_view FOREST_GATE = "Route2_ViridianForest_NorthEntrance"; -constexpr std::string_view PEWTER = "PewterCity"; -constexpr std::string_view PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; -constexpr std::string_view GYM = "PewterCity_Gym"; - -Pokemon::GridPose at(std::string_view map, int x, int y, std::optional facing = std::nullopt){ - return Pokemon::GridPose{std::string(map), {{x, y}}, facing}; -} - -StoryCheckpoint row( - std::string id, std::string title, std::optional start, - Supplies supplies, StartMenu menu, std::vector steps -){ - StoryCheckpoint checkpoint; - checkpoint.id = std::move(id); - checkpoint.title = std::move(title); - checkpoint.start = std::move(start); - checkpoint.steps = std::move(steps); - checkpoint.supplies = supplies; - checkpoint.menu = menu; - return checkpoint; -} - -Supplies after_brock(){ - Supplies supplies; - supplies.lead = story_lead_after_brock(); - return supplies; -} - -// What a walk does about wild Pokemon: runs, or fights them for EXP. -enum class WildBattles{ - RUN, - FIGHT, -}; - -StoryStep make(StoryStepKind kind, std::string name, std::string why, Pokemon::StoryActionArgs args = {}){ - StoryStep step; - step.kind = kind; - step.name = std::move(name); - step.why = std::move(why); - step.args = std::move(args); - return step; -} - -StoryStep route(std::string name, Pokemon::GridPose target, std::string why, WildBattles wild = WildBattles::RUN){ - return make(StoryStepKind::ROUTE, std::move(name), std::move(why), { - {"target", std::move(target)}, {"fight_wild", wild == WildBattles::FIGHT}, - }); -} - -StoryStep step_into(std::string name, Direction direction, std::string why){ - return make(StoryStepKind::STEP, std::move(name), std::move(why), {{"direction", direction}}); -} - -StoryStep answer(std::string name, bool yes, std::string why){ - return make(StoryStepKind::ANSWER, std::move(name), std::move(why), {{"yes", yes}}); -} - -StoryStep scene(std::string name, std::optional pose_after, std::string why){ - StoryStep step = make(StoryStepKind::MASH, std::move(name), std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep battle(std::string name, Pokemon::GridPose pose_after, bool may_lose, std::string why){ - StoryStep step = make(StoryStepKind::BATTLE, std::move(name), std::move(why), {{"may_lose", may_lose}}); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep legs(std::string name, std::vector legs, std::string why, WildBattles wild = WildBattles::RUN){ - return make(StoryStepKind::LEGS, std::move(name), std::move(why), { - {"legs", std::move(legs)}, {"fight_wild", wild == WildBattles::FIGHT}, - }); -} - -StoryStep new_game_intro(Pokemon::GridPose pose_after, std::string why){ - StoryStep step = make(StoryStepKind::NEW_GAME, "intro", std::move(why)); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep talk(std::string name, std::string why){ - return make(StoryStepKind::TALK, std::move(name), std::move(why)); -} - -StoryStep ready(std::string name, Pokemon::GridPose nurse, std::string why){ - return make(StoryStepKind::READY, std::move(name), std::move(why), {{"target", std::move(nurse)}}); -} - -StoryStep heal(std::string name){ - return make(StoryStepKind::HEAL, std::move(name), "full HP"); -} - -StoryStep shop(std::string name, std::vector items, std::string why){ - return make(StoryStepKind::SHOP, std::move(name), std::move(why), {{"items", std::move(items)}}); -} - -StoryStep game_step(std::string action, Pokemon::GridPose pose_after, std::string why){ - StoryStep step = make(StoryStepKind::GAME, action, std::move(why)); - step.action = std::move(action); - step.pose_after = std::move(pose_after); - return step; -} - -StoryStep options_step(){ - return make(StoryStepKind::OPTIONS, "options", "fast text; no switch prompt between a trainer's Pokemon"); -} - - -StoryCheckpoint new_game(){ - StoryCheckpoint checkpoint = row("00.01", "new game to the bedroom", std::nullopt, {}, StartMenu::BEFORE_POKEMON, { - // new_game.c: the bedroom at (6, 6), facing the TV. - new_game_intro(at(BEDROOM, 6, 6, NORTH), "Oak's speech, BOY, the player's name (default if none is set), rival GREEN"), - options_step(), - }); - checkpoint.handoff = StoryHandoff::SID_HELPER; - return checkpoint; -} - -// SID Helper confirms the name, finishes the intro and reads the Trainer -// Card from the START menu, without moving the player or saving. -StoryCheckpoint after_sid_helper(){ - StoryCheckpoint checkpoint = row("00.01b", "after SID Helper: close the Trainer Card, save in the bedroom", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { - game_step(CLOSE_TRAINER_CARD, at(BEDROOM, 6, 6, NORTH), "the Trainer Card SID Helper left open, or HOME"), - options_step(), - }); - checkpoint.live_start = true; - return checkpoint; -} - -StoryCheckpoint leave_house(){ - return row("00.02", "bedroom to Pallet Town", at(BEDROOM, 6, 6, NORTH), {}, StartMenu::BEFORE_POKEMON, { - route("front_door", at(PALLET, 6, 8), "down the stairs and out of the house"), - }); -} - -StoryCheckpoint oaks_trigger(){ - return row("00.03", "Oak stops the player and walks them to the lab", at(PALLET, 6, 8, SOUTH), {}, StartMenu::BEFORE_POKEMON, { - route("below_oaks_trigger", at(PALLET, 12, 2, NORTH), "below the north exit, short of Oak's trigger at (12, 1)"), - step_into("oaks_trigger", NORTH, "the trigger: \"Don't go out!\""), - // PlayerEnter walks the player up 8 tiles from the lab's door. - scene("to_the_lab", at(LAB, 6, 4, NORTH), "Oak walks the player into the lab; the scene ends at the table"), - }); -} - -// Starter RNG starts from a save south of the table, facing the ball. -StoryCheckpoint to_starter_ball(){ - StoryCheckpoint checkpoint = row("00.04", "to Squirtle's ball, south of the table", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEMON, { - route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), - }); - checkpoint.handoff = StoryHandoff::STARTER_RNG; - return checkpoint; -} - -StoryCheckpoint starter(){ - return row("00.04b", "Squirtle, then the rival's battle", at(LAB, 9, 5, NORTH), {}, StartMenu::BEFORE_POKEDEX, { - talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), - answer("choose_squirtle", true, "take Squirtle"), - answer("no_nickname", false, "\"give a nickname?\" NO"), - scene("rival_takes_bulbasaur", at(LAB, 9, 5, NORTH), "the rival picks his ball; the player still faces the table (console B, 2026-11-01)"), - route("above_rival_trigger", at(LAB, 7, 7, SOUTH), "short of the rival's trigger row 8"), - step_into("rival_trigger", SOUTH, "\"Wait, let's check out our POKEMON!\""), - // The rival leaves; PlayerWatchRivalExitAfterBattleRight ends facing down. - battle("rival_battle", at(LAB, 7, 8, SOUTH), true, "the tutorial battle; losing goes on too"), - }); -} - -StoryCheckpoint parcel(){ - return row("00.05", "Route 1 to Viridian Mart: Oak's Parcel", at(LAB, 7, 8, SOUTH), {}, StartMenu::BEFORE_POKEDEX, { - route("below_mart_door", at(VIRIDIAN, 36, 20, NORTH), "Route 1, running from wild battles"), - step_into("mart_door", NORTH, "the clerk's scene starts on entering"), - // ApproachCounter: up 4 from the mat, then faces the clerk. - scene("parcel_from_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "the clerk gives OAK'S PARCEL"), - }); -} - -StoryCheckpoint pokedex(){ - return row("00.06", "Oak's Parcel to the Pokedex", at(VIRIDIAN_MART, 4, 3, WEST), {}, StartMenu::FULL, { - route("below_oak", at(LAB, 6, 4, NORTH), "back down Route 1 to Oak"), - talk("give_parcel", "Oak takes the parcel"), - scene("pokedex_scene", at(LAB, 6, 4, SOUTH), "the rival comes in, Pokedexes from the desk; the player ends facing south (console B, 2026-11-01)"), - }); -} - -StoryCheckpoint shopping(){ - return row("00.07", "Viridian shopping, then into Viridian Forest", at(LAB, 6, 4, SOUTH), {}, StartMenu::FULL, { - route("mart_clerk", at(VIRIDIAN_MART, 4, 3, WEST), "Route 1 again"), - // 2000 of the 3000 a new game starts with, plus the rival's prize. - shop("potions_and_antidotes", {{"potion", 5}, {"antidote", 3}, {"parlyz_heal", 1}}, "5 Potions, 3 Antidotes, 1 Parlyz Heal"), - route("viridian_nurse", at(VIRIDIAN_CENTER, 7, 4, NORTH), "heal before the forest"), - heal("heal_viridian"), - route("below_old_man_trigger", at(VIRIDIAN, 20, 9, NORTH), "short of the tutorial trigger (20, 8)"), - step_into("old_man_trigger", NORTH, "the old man's catching tutorial can't be walked around"), - // TutorialTriggerLeft turns the player right, to the old man. - scene("old_man_tutorial", at(VIRIDIAN, 20, 8, EAST), "about 60 lines and his demo battle; TEACHY TV"), - // After his demo the old man stands east of the player, beside (20, 8), where - // the map doesn't have him: "east 2" from there didn't move, and the walk north - // ended under Route 2's ledge in column 8 (console B, 2026-11-01). Go north first. - route("past_old_man", at(VIRIDIAN, 20, 5, NORTH), "north along column 20, clear of the old man"), - // The gate's north warp lands on the forest's exit mat (29, 62), facing - // north. The save there keeps a forest failure from going back to Pallet. - route("forest_entrance", at(FOREST, 29, 62, NORTH), "Route 2 and the south gate, running from wild battles"), - }); -} - -StoryCheckpoint forest(){ - // The supplies bought in 00.07. - return row("00.08", "Viridian Forest to Pewter Center", at(FOREST, 29, 62, NORTH), {5, 3, 1}, StartMenu::FULL, { - // Wild battles are fought for EXP. Straight up the east side from the - // entrance, each leg ending on a wall (the Boy at (45, 58) stops the - // east one). Rick (47, 45) sees (42..46, 45), so the last leg meets - // his battle and is held on to its wall after it. The by-hand run's - // detour west to (13, 46) and back is dropped. - legs("forest_east", {{EAST, 1}, {NORTH, 4}, {EAST, 14}, {NORTH, 15}}, "up the east side to (44, 43)", WildBattles::FIGHT), - route("forest_north", at(FOREST, 39, 25), "north part", WildBattles::FIGHT), - // To the gate by legs that end on walls, which the walker holds again - // after a battle instead of estimating where it stopped: planned - // routes with open legs lost the player in the north of the forest - // (console B, 2026-11-01). The two 1-tile legs are single steps. - legs("forest_exit", { - {NORTH, 10}, {WEST, 12}, {SOUTH, 10}, {WEST, 6}, {NORTH, 20}, - {SOUTH, 1}, {WEST, 10}, {SOUTH, 27}, {WEST, 8}, {NORTH, 20}, {EAST, 1}, - }, "walls all the way to the gate's column", WildBattles::FIGHT), - route("forest_gate", at(FOREST_GATE, 7, 10, NORTH), "north onto the exit, arriving on the gate's mat", WildBattles::FIGHT), - // Out of the forest, wild battles are run from; trainers are still fought. - route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "Route 2 north to Pewter's Center"), - heal("heal_pewter"), - }); -} - -StoryCheckpoint brock(){ - // The by-hand save: 2 Potions and 1 Antidote left after the forest. - return row("00.09", "Pewter Gym: Camper Liam, then Brock", at(PEWTER_CENTER, 7, 4, NORTH), {2, 1}, StartMenu::FULL, { - // Camper Liam (3, 8) always faces east (MOVEMENT_TYPE_FACE_RIGHT, sight - // 4) and sees (4..7, 8): walking north up column 6 from the door, - // the step onto (6, 8) starts his battle. He walks up to the player, - // who stays put and keeps facing north (FRLG doesn't turn the player - // to a trainer). That step is taken on its own, so no leg is cut. - route("below_liam_line", at(GYM, 6, 9, NORTH), "in by the door, up column 6 to below Liam's row"), - step_into("liam_line", NORTH, "onto (6, 8), in Liam's line"), - battle("camper_liam", at(GYM, 6, 8, NORTH), false, "Geodude and Sandshrew; EXP before Brock"), - // On to Brock unless red HP or a status is left that no item cures. - ready("ready_for_brock", at(PEWTER_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse only if they can't"), - route("before_brock", at(GYM, 6, 6, NORTH), "below Brock (6, 5); Liam, beaten, stands at (5, 8)"), - talk("challenge_brock", "Brock's speech"), - battle("brock", at(GYM, 6, 6, NORTH), false, "Geodude and Onix, with Bubble; Boulder Badge and TM39"), - }); -} - -StoryCheckpoint running_shoes(){ - return row("00.10", "Pewter: the Running Shoes from Oak's aide", at(GYM, 6, 6, NORTH), after_brock(), StartMenu::FULL, { - // Brock's win sets VAR_MAP_SCENE_PEWTER_CITY to 1 and shows the aide at - // (46, 20); his triggers are (46, 21..23) (PewterCity map.json). The - // Gym guide's triggers at (42..43, 21..23) need the scene at 0. - route("before_aide_trigger", at(PEWTER, 45, 21, EAST), "out of the Gym, east along row 21, short of the top trigger"), - step_into("aide_trigger", EAST, "onto (46, 21), below the aide"), - // RunningShoesAideTriggerTop: the aide talks from (46, 20), no YES/NO; - // the player only turns up. He walks off and is removed; FLAG_SYS_B_DASH - // is set (console B, 2026-11-02: about 20 B presses to the overworld). - scene("shoes_from_aide", at(PEWTER, 46, 21, NORTH), "\"Oh, PLAYER!\" ... the Running Shoes; ends facing north"), - }); -} - - -std::vector cpp_rows(){ - return { - new_game(), after_sid_helper(), leave_house(), oaks_trigger(), to_starter_ball(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), - running_shoes(), - }; -} - -// Why `loaded` differs from `row`, or empty. Steps compare as their -// shared JSON, which writes every field. -std::string checkpoint_difference(const StoryCheckpoint& row, const StoryCheckpoint& loaded){ - const std::string row_json = Pokemon::story_checkpoint_json(row).dump(); - const std::string loaded_json = Pokemon::story_checkpoint_json(loaded).dump(); - if (row_json != loaded_json){ - return std::format("{}: the file loads to\n{}\nbut the C++ row is\n{}", row.id, loaded_json, row_json); - } - if (row.handoff != loaded.handoff || row.live_start != loaded.live_start){ - return row.id + ": a different handoff or live start."; - } - if (row.menu != loaded.menu){ - return row.id + ": a different START menu."; - } - const Supplies& a = row.supplies; - const Supplies& b = loaded.supplies; - if (a.potions != b.potions || a.antidotes != b.antidotes || a.parlyz_heals != b.parlyz_heals){ - return row.id + ": different supplies."; - } - if (a.lead.species != b.lead.species || a.lead.level != b.lead.level || a.lead.moves.size() != b.lead.moves.size()){ - return row.id + ": a different lead."; - } - for (size_t c = 0; c < a.lead.moves.size(); c++){ - if (a.lead.moves[c].move != b.lead.moves[c].move || a.lead.moves[c].pp != b.lead.moves[c].pp){ - return row.id + ": a different lead move " + std::to_string(c + 1) + "."; - } - } - return ""; -} - -class Test_AutoStoryTableParity : public UnitTest{ -public: - Test_AutoStoryTableParity() - : UnitTest("PokemonFRLG::AutoStory - the story files load to the C++ rows") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - try{ - const std::vector rows = cpp_rows(); - const std::vector& loaded = story_checkpoints(); - if (rows.size() != loaded.size()){ - return std::format("{} C++ rows, {} files.", rows.size(), loaded.size()); - } - for (size_t c = 0; c < rows.size(); c++){ - const std::string difference = checkpoint_difference(rows[c], loaded[c]); - if (!difference.empty()){ - return difference; - } - } - return true; - }catch (Exception& e){ - return std::string(e.name()) + ": " + e.message(); - } - } -}; - -} // namespace - - -void add_tests_AutoStoryTableParity(UnitTestDatabase& database){ - database.add(); -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 3b11728b46..37529b52c5 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1953,7 +1953,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryExport_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableParity_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryWinChance.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp