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 8a64b28702..1785b5687e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -111,20 +111,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/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index cffd01a1e4..fc999c6c84 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -13,7 +13,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 "VideoGames/PokemonFRLG/Programs/PokemonFRLG_NamingScreenKeyboard.h" @@ -58,7 +60,14 @@ namespace{ // The start and end dropdowns' entries: the table's checkpoints, 00.01 to // 00.12b. 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; } @@ -86,7 +95,7 @@ const char* const RUN_GIFT_RNG_TEXT = "English only. The Magikarp costs 500 and needs a free party slot; AutoStory's options leave the text fast."; 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.", @@ -171,7 +180,7 @@ void check_player_name(ConsoleHandle& console, const std::string& name){ // 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(); @@ -248,11 +257,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); @@ -453,7 +461,7 @@ static void run_story_rows( const Pokemon::SegmentReport report = run_segment( state, segment, Pokemon::SegmentRange{rows.front().id, rows.back().id}, policy, hooks ); - Pokemon::record_story_stats(env.current_stats(), report); + Pokemon::record_story_counts(env.current_stats(), report.story_counts()); env.update_stats(); throw_if_failed(report); } @@ -661,13 +669,12 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex first = checkpoint_index(checkpoints, "00.01b"); plan = plan_story_run(checkpoints, first, last, handoffs); } - 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); story.player_name = player_name; const bool at_gift_rng = plan.stop == StoryHandoff::GIFT_RNG && plan.rows.empty(); prepare_start(env, context, checkpoints, first, story, at_gift_rng); + story.language = RUN.language(); StoryExecutor executor(story); - executor.set_checks(RUN.checks()); - executor.set_language(RUN.language()); const std::optional done_through = at_gift_rng ? run_from_gift_rng_save(env, context, story, executor, first) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp index aa0a8ac1b9..22fdb2b490 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp @@ -77,29 +77,28 @@ Outcome fossil(Logger& logger, Fossil fossil, StoryAbilities& abilities){ std::optional run_ability_game_step( Logger& logger, VideoStream* stream, const Pokemon::StoryStep& step, StoryAbilities& abilities ){ - const std::string_view variant = step.variant; - if (variant.starts_with(MART_VARIANT_PREFIX)){ - const std::optional plan = parse_mart_variant(variant); - return plan ? mart(logger, *plan, abilities) : Pokemon::outcome_failed("bad_variant", step.variant); + if (step.action == MART_ACTION){ + const std::optional plan = mart_plan_of(step.args); + return plan ? mart(logger, *plan, abilities) : Pokemon::outcome_failed("bad_args", step.action); } - if (variant.starts_with(TEACH_VARIANT_PREFIX)){ - const std::optional plan = parse_teach_variant(variant); - return plan ? teach(logger, *plan, abilities) : Pokemon::outcome_failed("bad_variant", step.variant); + if (step.action == TEACH_ACTION){ + const std::optional plan = teach_plan_of(step.args); + return plan ? teach(logger, *plan, abilities) : Pokemon::outcome_failed("bad_args", step.action); } - if (variant.starts_with(LEVEL_VARIANT_PREFIX)){ - const std::optional check = parse_level_variant(variant); - return check ? level(logger, *check, abilities) : Pokemon::outcome_failed("bad_variant", step.variant); + if (step.action == LEVEL_ACTION){ + const std::optional check = level_check_of(step.args); + return check ? level(logger, *check, abilities) : Pokemon::outcome_failed("bad_args", step.action); } - if (variant.starts_with(GRIND_VARIANT_PREFIX)){ - const std::optional plan = parse_grind_variant(variant); - if (!plan || !step.target){ - return Pokemon::outcome_failed("bad_variant", step.variant + (step.target ? "" : " (no nurse)")); + if (step.action == GRIND_ACTION){ + const std::optional plan = grind_plan_of(step.args); + if (!plan || !step.args.contains("nurse")){ + return Pokemon::outcome_failed("bad_args", step.action + (step.args.contains("nurse") ? "" : " (no nurse)")); } return grind(logger, stream, *plan, abilities); } - if (variant.starts_with(FOSSIL_VARIANT_PREFIX)){ - const std::optional choice = parse_fossil_variant(variant); - return choice ? fossil(logger, *choice, abilities) : Pokemon::outcome_failed("bad_variant", step.variant); + if (step.action == FOSSIL_ACTION){ + const std::optional choice = fossil_of(step.args); + return choice ? fossil(logger, *choice, abilities) : Pokemon::outcome_failed("bad_args", step.action); } return std::nullopt; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h index edb751e829..a6f787b9d1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h @@ -5,7 +5,7 @@ * The GAME steps beyond walking and talking that later checkpoints name * in the table: MART (a budgeted buy list), TEACH (a TM or HM), LEVEL (a * member's level checked), GRIND (wild battles to a level) and - * CHOICE(fossil). Each is a variant of a GAME step; this runs the one a + * CHOICE(fossil). Each is an action of a GAME step; this runs the one a * step names with the game steps it is given. * */ @@ -17,7 +17,7 @@ #include "Common/Cpp/Logging/AbstractLogger.h" #include "CommonFramework/Tools/VideoStream.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "PokemonFRLG_AutoStoryChoice.h" #include "PokemonFRLG_AutoStoryGrind.h" #include "PokemonFRLG_AutoStoryMart.h" @@ -39,7 +39,7 @@ struct StoryAbilities{ }; // A MART, TEACH, LEVEL, GRIND or fossil step with `abilities`: nothing for -// another variant. A GRIND that meets a shiny throws +// another action. A GRIND that meets a shiny throws // ProgramFinishedException, with a screenshot from `stream` if given, so // the segment stops without reloading. Any other end but success is a // failed Outcome; a MART that buys nothing because the money doesn't diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp index b4b8301a1a..9a6c46db20 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp @@ -115,11 +115,12 @@ class Test_AutoStoryAbilities : public UnitTest{ }; -Pokemon::StoryStep game_step(std::string variant){ +Pokemon::StoryStep game_step(std::string action, Pokemon::StoryActionArgs args){ Pokemon::StoryStep step; step.kind = Pokemon::StoryStepKind::GAME; step.name = "test"; - step.variant = std::move(variant); + step.action = std::move(action); + step.args = std::move(args); return step; } @@ -147,20 +148,21 @@ struct StepCase{ std::vector step_cases(){ const auto none = [](StubGame&){}; + const Pokemon::StoryStep mart = mart_step("mart", "", {.map = "PewterCity_Mart", .lines = {{"potion", 5}}, .budget = 2000}); const Pokemon::StoryStep grind = grind_step("grind", "", {.member = 0, .level = 20, .max_encounters = 5, .pace = Pokemon::Direction::EAST, .heal_every = 0}, {}); return { {"level reached", none, level_step("check", "", {.slot = 0, .level = 16}), ""}, {"level below", none, level_step("check", "", {.slot = 0, .level = 17}), "level_below"}, {"level unread", [](StubGame& game){ game.level.reset(); }, level_step("check", "", {.slot = 0, .level = 16}), "level_unread"}, - {"a Mart with too little money succeeds", [](StubGame& game){ game.mart.money = 100; }, game_step("mart PewterCity_Mart budget=2000 potion=5"), ""}, - {"a Mart purchase that fails", none, game_step("mart PewterCity_Mart budget=2000 potion=5"), "mart_failed"}, - {"a move it knows already succeeds", none, game_step("teach hm03 surf slot=1"), ""}, - {"a TM not in the TM Case is skipped", none, game_step("teach tm03 water-pulse slot=1 forget=water-gun"), ""}, + {"a Mart with too little money succeeds", [](StubGame& game){ game.mart.money = 100; }, mart, ""}, + {"a Mart purchase that fails", none, mart, "mart_failed"}, + {"a move it knows already succeeds", none, teach_step("teach", "", {.item = "hm03", .move = "surf", .member = 0}), ""}, + {"a TM not in the TM Case is skipped", none, teach_step("teach", "", {.item = "tm03", .move = "water-pulse", .member = 0, .forget_move = "water-gun"}), ""}, {"a level that can't be read stops a GRIND", [](StubGame& game){ game.level.reset(); }, grind, "grind_unread"}, - {"a GRIND without a nurse", none, game_step("grind slot=1 level=20"), "bad_variant"}, + {"a GRIND without a nurse", none, game_step(GRIND_ACTION, {{"slot", int64_t(1)}, {"level", int64_t(20)}}), "bad_args"}, {"no YES/NO at the fossil", none, fossil_step("fossil", "", Fossil::HELIX), "fossil_failed"}, - {"a bad variant", none, game_step("mart PewterCity_Mart"), "bad_variant"}, - {"another game step", none, game_step("capture rattata"), "none"}, + {"bad args", none, game_step(MART_ACTION, {{"map", std::string("PewterCity_Mart")}}), "bad_args"}, + {"another game step", none, capture_step("capture", "", {.species = "rattata"}), "none"}, }; } @@ -192,15 +194,21 @@ UnitTestResult test_grind_shiny_stops(){ } -UnitTestResult test_level_variant(){ - const std::string variant = level_variant({.slot = 1, .level = 23}); - const std::optional back = parse_level_variant(variant); - if (variant != "level slot=2 min=23" || !back || back->slot != 1 || back->level != 23){ - return "Unexpected level variant \"" + variant + "\"."; +UnitTestResult test_level_args(){ + const std::optional back = level_check_of(level_args({.slot = 1, .level = 23})); + if (!back || back->slot != 1 || back->level != 23){ + return "Expected slot 2, level 23 to read back."; } - for (std::string_view bad : {"level", "level slot=1", "level min=5", "level slot=0 min=5", "level slot=1 min=101"}){ - if (parse_level_variant(bad)){ - return "Expected \"" + std::string(bad) + "\" refused."; + const std::vector bad_args{ + {}, + {{"slot", int64_t(1)}}, + {{"min", int64_t(5)}}, + {{"slot", int64_t(0)}, {"min", int64_t(5)}}, + {{"slot", int64_t(1)}, {"min", int64_t(101)}}, + }; + for (const Pokemon::StoryActionArgs& bad : bad_args){ + if (level_check_of(bad)){ + return "Expected args with a missing or out-of-range value refused."; } } return true; @@ -219,7 +227,7 @@ const AutoStoryAbilitiesCase AUTO_STORY_ABILITIES_CASES[] = { .expectation = {}, }, { - .input = {"the LEVEL step's variant", test_level_variant}, + .input = {"the LEVEL step's args", test_level_args}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 17b9868a35..ed5a1aebb4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -843,7 +843,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); @@ -860,7 +860,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 e9d3be1707..735d883bb7 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 59a105c06f..5bf90401ea 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_AutoStoryCapture.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture.cpp index 6897734183..705e986fdf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture.cpp @@ -21,6 +21,7 @@ #include "VideoGames/PokemonFRLG/Programs/PokemonFRLG_BattleMenuNavigation.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryCapture.h" +#include "PokemonFRLG_AutoStoryGameArgs.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -35,45 +36,6 @@ namespace{ constexpr size_t PARTY_SIZE = 6; constexpr size_t MOVE_COUNT = 4; -std::vector words_of(std::string_view text){ - std::vector words; - while (!text.empty()){ - const size_t space = text.find(' '); - const std::string_view word = text.substr(0, space); - if (!word.empty()){ - words.push_back(word); - } - if (space == std::string_view::npos){ - break; - } - text.remove_prefix(space + 1); - } - return words; -} - -std::optional number_of(std::string_view text){ - if (text.empty() || text.size() > 4){ - return std::nullopt; - } - size_t value = 0; - for (char c : text){ - if (c < '0' || c > '9'){ - return std::nullopt; - } - value = value * 10 + size_t(c - '0'); - } - return value; -} - -std::optional direction_of(std::string_view text){ - for (Direction direction : Pokemon::ALL_DIRECTIONS){ - if (text == direction_name(direction)){ - return direction; - } - } - return std::nullopt; -} - Direction opposite(Direction direction){ switch (direction){ case Direction::NORTH: return Direction::SOUTH; @@ -109,57 +71,38 @@ const char* capture_end_name(CaptureEnd end){ } -std::string capture_variant(const CapturePlan& plan){ - std::string variant = std::format( - "{}{} catches={} encounters={} balls={} pace={}", - CAPTURE_VARIANT_PREFIX, plan.species, plan.catches, plan.max_encounters, plan.max_balls, direction_name(plan.pace) - ); +Pokemon::StoryActionArgs capture_args(const CapturePlan& plan){ + Pokemon::StoryActionArgs args{ + {"species", plan.species}, + {"catches", int64_t(plan.catches)}, + {"encounters", int64_t(plan.max_encounters)}, + {"balls", int64_t(plan.max_balls)}, + {"pace", plan.pace}, + {"turns", int64_t(plan.max_weaken_turns)}, + }; if (plan.weaken_move){ - variant += std::format(" move={} turns={}", *plan.weaken_move + 1, plan.max_weaken_turns); + args.emplace("move", int64_t(*plan.weaken_move + 1)); } - return variant; + return args; } -std::optional parse_capture_variant(std::string_view variant){ - if (!variant.starts_with(CAPTURE_VARIANT_PREFIX)){ - return std::nullopt; - } - const std::vector words = words_of(variant.substr(CAPTURE_VARIANT_PREFIX.size())); - if (words.empty() || words[0].find('=') != std::string_view::npos){ +std::optional capture_plan_of(const Pokemon::StoryActionArgs& args){ + const std::string* species = game_arg(args, "species"); + const std::optional catches = number_arg(args, "catches", 1, 999); + const std::optional encounters = number_arg(args, "encounters", 1, 9999); + const std::optional balls = number_arg(args, "balls", 1, 999); + const std::optional turns = number_arg(args, "turns", 0, 99); + const Direction* pace = game_arg(args, "pace"); + if (species == nullptr || species->empty() || !catches || !encounters || !balls || !turns || pace == nullptr){ return std::nullopt; } - CapturePlan plan; - plan.species = std::string(words[0]); - for (size_t c = 1; c < words.size(); c++){ - const size_t equals = words[c].find('='); - if (equals == std::string_view::npos){ - return std::nullopt; - } - const std::string_view key = words[c].substr(0, equals); - const std::string_view value = words[c].substr(equals + 1); - if (key == "pace"){ - const std::optional pace = direction_of(value); - if (!pace){ - return std::nullopt; - } - plan.pace = *pace; - continue; - } - const std::optional number = number_of(value); - if (!number){ - return std::nullopt; - } - if (key == "catches" && *number >= 1){ - plan.catches = *number; - }else if (key == "encounters" && *number >= 1){ - plan.max_encounters = *number; - }else if (key == "balls" && *number >= 1){ - plan.max_balls = *number; - }else if (key == "move" && *number >= 1 && *number <= MOVE_COUNT){ - plan.weaken_move = *number - 1; - }else if (key == "turns"){ - plan.max_weaken_turns = *number; - }else{ + CapturePlan plan{ + .species = *species, .catches = *catches, .max_encounters = *encounters, .max_balls = *balls, + .pace = *pace, .max_weaken_turns = *turns, + }; + if (args.contains("move")){ + plan.weaken_move = counted_arg(args, "move", MOVE_COUNT); + if (!plan.weaken_move){ return std::nullopt; } } @@ -171,7 +114,8 @@ Pokemon::StoryStep capture_step(std::string name, std::string why, const Capture step.kind = Pokemon::StoryStepKind::GAME; step.name = std::move(name); step.why = std::move(why); - step.variant = capture_variant(plan); + step.action = CAPTURE_ACTION; + step.args = capture_args(plan); return step; } @@ -180,7 +124,8 @@ Pokemon::StoryStep pc_step(std::string name, std::string why, const PcTransfer& step.kind = Pokemon::StoryStepKind::GAME; step.name = std::move(name); step.why = std::move(why); - step.variant = pc_variant(transfer); + step.action = PC_ACTION; + step.args = pc_args(transfer); return step; } @@ -395,10 +340,10 @@ std::optional run_storage_game_step( Logger& logger, VideoStream* stream, const Pokemon::StoryStep& step, CaptureActions& capture, PcStorageActions& pc ){ - if (step.variant.starts_with(CAPTURE_VARIANT_PREFIX)){ - const std::optional plan = parse_capture_variant(step.variant); + if (step.action == CAPTURE_ACTION){ + const std::optional plan = capture_plan_of(step.args); if (!plan){ - return Pokemon::outcome_failed("bad_variant", step.variant); + return Pokemon::outcome_failed("bad_args", step.action); } const CaptureResult result = run_capture(logger, capture, *plan, pc.read_party().size()); const std::string message = capture_message(*plan, result); @@ -415,10 +360,10 @@ std::optional run_storage_game_step( } return Pokemon::outcome_failed(std::string("capture_") + capture_end_name(result.end), message); } - if (step.variant.starts_with(PC_VARIANT_PREFIX)){ - const std::optional transfer = parse_pc_variant(step.variant); + if (step.action == PC_ACTION){ + const std::optional transfer = pc_transfer_of(step.args); if (!transfer){ - return Pokemon::outcome_failed("bad_variant", step.variant); + return Pokemon::outcome_failed("bad_args", step.action); } const PcResult result = run_pc_transfer(logger, pc, *transfer); switch (result.end){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture.h index 7617b44be7..df4d4a3892 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture.h @@ -35,7 +35,8 @@ #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" #include "Pokemon/Navigation/Pokemon_Grid.h" #include "PokemonFRLG_AutoStoryPcStorage.h" @@ -64,17 +65,16 @@ struct CapturePlan{ size_t max_weaken_turns = 2; }; -// The prefix of a GAME step's variant that names a capture step. -inline constexpr std::string_view CAPTURE_VARIANT_PREFIX = "capture "; - -// `plan` as a GAME step's variant, e.g. "capture rattata catches=1 -// encounters=20 balls=5 pace=east", with " move=1 turns=2" when it -// weakens (the move counted from 1). -std::string capture_variant(const CapturePlan& plan); -// A variant from capture_variant(), whose keys after the species may come -// in any order or be left out (their defaults); nothing if `variant` isn't -// one or has a key or value it doesn't know. -std::optional parse_capture_variant(std::string_view variant); +// The GAME action of a capture step: species WORD (required); catches +// INTEGER (1); encounters INTEGER (20); balls INTEGER (5); pace DIRECTION +// (east); move INTEGER (optional, from 1), the move that weakens; turns +// INTEGER (2). +inline const std::string CAPTURE_ACTION = "capture"; +// `plan` as its action's args. +Pokemon::StoryActionArgs capture_args(const CapturePlan& plan); +// The plan a CAPTURE_ACTION step's args give; nothing if one is out of +// range. +std::optional capture_plan_of(const Pokemon::StoryActionArgs& args); // The table's step that runs `plan`. Pokemon::StoryStep capture_step(std::string name, std::string why, const CapturePlan& plan); @@ -191,7 +191,7 @@ std::string capture_message(const CapturePlan& plan, const CaptureResult& result // A capture or PC GAME step (see capture_step(), pc_step()) with these -// actions, the party read from `pc`: nothing for another variant. A capture that ends on a shiny +// actions, the party read from `pc`: nothing for another action. A capture that ends on a shiny // throws ProgramFinishedException, so the segment stops without // reloading, with a screenshot from `stream` if given; any other end but // CAUGHT is a failed Outcome, as is a PC step that fails or is refused. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture_Tests.cpp index 29eef4bada..3f1d95f27e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCapture_Tests.cpp @@ -4,7 +4,7 @@ * * The capture step's decisions against a fake game: which encounters are * run from, when balls or encounters run out, where a catch goes, what a - * shiny stops; its table variant; and a capture and a PC step run by the + * shiny stops; its args; and a capture and a PC step run by the * shared segment runner, as the program runs them, to show which failures * reload the save and which stop the program. * @@ -20,8 +20,9 @@ #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/Exceptions/ProgramFinishedException.h" #include "Pokemon/AutoStory/Pokemon_StorySegments.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "PokemonFRLG_AutoStoryCapture.h" +#include "PokemonFRLG_AutoStoryStepTable.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -341,39 +342,48 @@ UnitTestResult test_capture_decisions(){ } -// The table's variant, both ways, and the variants it refuses. -UnitTestResult test_capture_variant(){ +// The step's args, both ways, and the args it refuses. +UnitTestResult test_capture_args(){ const std::vector plans = { RATTATA, {.species = "pidgey", .catches = 2, .max_encounters = 30, .max_balls = 8, .pace = Direction::NORTH, .weaken_move = 3, .max_weaken_turns = 1}, }; for (const CapturePlan& plan : plans){ - const std::string variant = capture_variant(plan); - const std::optional back = parse_capture_variant(variant); + const std::optional back = capture_plan_of(capture_args(plan)); if (!back || back->species != plan.species || back->catches != plan.catches || back->max_encounters != plan.max_encounters || back->max_balls != plan.max_balls || back->pace != plan.pace || back->weaken_move != plan.weaken_move - || (plan.weaken_move && back->max_weaken_turns != plan.max_weaken_turns) + || back->max_weaken_turns != plan.max_weaken_turns ){ - return "\"" + variant + "\" didn't read back as the plan it was made from."; + return "The " + plan.species + " plan didn't read back from its args."; } } - const std::optional short_form = parse_capture_variant("capture rattata"); - if (!short_form || short_form->species != "rattata" || short_form->max_balls != 5 || short_form->weaken_move){ - return "Expected \"capture rattata\" to read with the defaults."; + const Pokemon::StoryActionSpec* spec = Pokemon::find_story_action(story_action_specs(), Pokemon::StoryStepKind::GAME, CAPTURE_ACTION); + if (spec == nullptr){ + return "No capture action among FRLG's actions."; } - for (std::string_view bad : { - "capture", "capture ", "capture balls=3", "capture rattata balls=0", "capture rattata move=5", - "capture rattata pace=up", "capture rattata colour=red", "capture rattata balls", "pc deposit slot=2 box=1", - }){ - if (parse_capture_variant(bad)){ - return "Expected \"" + std::string(bad) + "\" refused."; + const Pokemon::StoryActionArgs short_form = Pokemon::with_fallbacks(*spec, {{"species", std::string("rattata")}}); + const std::optional defaults = capture_plan_of(short_form); + if (!defaults || defaults->species != "rattata" || defaults->max_balls != 5 || defaults->weaken_move){ + return "Expected a capture of only a species to read with the defaults."; + } + const std::vector> bad_args{ + {"species", std::string("")}, + {"balls", int64_t(0)}, + {"move", int64_t(5)}, + {"pace", std::string("up")}, + }; + for (const auto& [key, value] : bad_args){ + Pokemon::StoryActionArgs args = short_form; + args[key] = value; + if (capture_plan_of(args)){ + return "Expected a bad " + key + " refused."; } } const Pokemon::StoryStep step = capture_step("catch_rattata", "Cut user", RATTATA); - if (step.kind != Pokemon::StoryStepKind::GAME || !parse_capture_variant(step.variant)){ - return "Expected capture_step() to be a GAME step with a capture variant."; + if (step.kind != Pokemon::StoryStepKind::GAME || step.action != CAPTURE_ACTION || !capture_plan_of(step.args)){ + return "Expected capture_step() to be a GAME capture step with its plan's args."; } return true; } @@ -436,8 +446,10 @@ class StorageExecutor : public Pokemon::StoryStepExecutor{ FakeCaptureGame capture; IdlePc pc; -protected: - virtual Pokemon::Outcome game(Pokemon::RunState&, const StoryStep& step) override{ + virtual Pokemon::Outcome run(Pokemon::RunState&, const StoryStep& step) override{ + if (step.kind != Pokemon::StoryStepKind::GAME){ + return Pokemon::unsupported_step(step); + } const std::optional outcome = run_storage_game_step(logger, nullptr, step, capture, pc); return outcome ? *outcome : Pokemon::unsupported_step(step); } @@ -616,7 +628,7 @@ const AutoStoryCaptureCase AUTO_STORY_CAPTURE_CASES[] = { .expectation = {}, }, { - .input = {"the table's variant", test_capture_variant}, + .input = {"the step's args", test_capture_args}, .expectation = {}, }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice.cpp index 7bd64d3949..78137cc345 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice.cpp @@ -11,6 +11,7 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryChoice.h" +#include "PokemonFRLG_AutoStoryGameArgs.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -50,15 +51,12 @@ const char* choice_end_name(ChoiceEnd end){ } -std::string fossil_variant(Fossil fossil){ - return std::string(FOSSIL_VARIANT_PREFIX) + fossil_name(fossil); -} - -std::optional parse_fossil_variant(std::string_view variant){ - if (!variant.starts_with(FOSSIL_VARIANT_PREFIX)){ +std::optional fossil_of(const Pokemon::StoryActionArgs& args){ + const std::string* name = game_arg(args, "fossil"); + if (name == nullptr){ return std::nullopt; } - return fossil_from_name(variant.substr(FOSSIL_VARIANT_PREFIX.size())); + return fossil_from_name(*name); } Pokemon::StoryStep fossil_step(std::string name, std::string why, Fossil fossil){ @@ -66,7 +64,8 @@ Pokemon::StoryStep fossil_step(std::string name, std::string why, Fossil fossil) step.kind = Pokemon::StoryStepKind::GAME; step.name = std::move(name); step.why = std::move(why); - step.variant = fossil_variant(fossil); + step.action = FOSSIL_ACTION; + step.args = {{"fossil", std::string(fossil_name(fossil))}}; return step; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice.h index 59443c6675..4bfaff25a8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice.h @@ -33,7 +33,8 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.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_StoryActionSpec.h" #include "Pokemon/Navigation/Pokemon_Grid.h" namespace PokemonAutomation{ @@ -54,13 +55,11 @@ std::optional fossil_from_name(std::string_view name); // Where `fossil` lies on MtMoon_B2F (map.json object_events). Pokemon::TilePos fossil_tile(Fossil fossil); -// The prefix of a GAME step's variant that names the fossil CHOICE. -inline constexpr std::string_view FOSSIL_VARIANT_PREFIX = "fossil "; - -// "fossil helix" or "fossil dome". -std::string fossil_variant(Fossil fossil); -// Parses a fossil CHOICE variant string. -std::optional parse_fossil_variant(std::string_view variant); +// The GAME action of the fossil CHOICE: fossil WORD (required), "helix" +// or "dome". +inline const std::string FOSSIL_ACTION = "fossil"; +// The fossil a FOSSIL_ACTION step's args choose; nothing if it isn't one. +std::optional fossil_of(const Pokemon::StoryActionArgs& args); // The table's CHOICE(fossil) step, the player facing the fossil. Pokemon::StoryStep fossil_step(std::string name, std::string why, Fossil fossil); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice_Tests.cpp index 432ff26b00..9de1685ad4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryChoice_Tests.cpp @@ -178,15 +178,21 @@ UnitTestResult test_fossil_choice(){ } -UnitTestResult test_fossil_variant(){ - if (fossil_variant(Fossil::HELIX) != "fossil helix" || parse_fossil_variant("fossil dome") != Fossil::DOME){ - return "Expected \"fossil helix\" and \"fossil dome\"."; +UnitTestResult test_fossil_args(){ + const Pokemon::StoryStep step = fossil_step("helix", "", Fossil::HELIX); + if (step.action != FOSSIL_ACTION || fossil_of(step.args) != Fossil::HELIX + || fossil_of({{"fossil", std::string("dome")}}) != Fossil::DOME + ){ + return "Expected the HELIX step and \"dome\" to read back."; } - for (std::string_view bad : {"fossil", "fossil old_amber", "fossil helix dome", "grind level=18"}){ - if (parse_fossil_variant(bad)){ - return "Expected \"" + std::string(bad) + "\" refused."; + for (const std::string& bad : {"", "old_amber", "helix dome"}){ + if (fossil_of({{"fossil", bad}})){ + return "Expected \"" + bad + "\" refused."; } } + if (fossil_of({})){ + return "Expected a step with no fossil refused."; + } // MtMoon_B2F map.json: DOME at (13, 7), HELIX at (14, 7). if (!(fossil_tile(Fossil::DOME) == Pokemon::TilePos{13, 7}) || !(fossil_tile(Fossil::HELIX) == Pokemon::TilePos{14, 7})){ return "The fossils' tiles aren't MtMoon_B2F's."; @@ -203,7 +209,7 @@ const AutoStoryChoiceCase AUTO_STORY_CHOICE_CASES[] = { .expectation = {}, }, { - .input = {"the table's variant", test_fossil_variant}, + .input = {"the step's args", test_fossil_args}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 88db43ec14..f2bba586bb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -20,6 +20,7 @@ #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryCapture.h" #include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryGameArgs.h" #include "PokemonFRLG_AutoStorySummary.h" #include "PokemonFRLG_AutoStoryTable.h" #include "PokemonFRLG_AutoStoryTeachScreens.h" @@ -54,6 +55,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){ @@ -81,13 +96,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){ @@ -103,9 +118,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( @@ -114,7 +130,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)}; @@ -134,11 +150,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)}; @@ -148,19 +164,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); @@ -197,7 +214,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); @@ -252,16 +269,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 @@ -301,7 +318,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){ @@ -442,7 +459,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: @@ -517,11 +534,13 @@ bool walked(StoryEnv& env, RunState& state, const StoryStep& step){ return outcome.succeeded(); } -// A GRIND's trip from the patch to the nurse (`step`'s target) and back +// A GRIND's trip from the patch to the nurse (`step`'s nurse) and back // to `patch`, starting where pacing left the player (`spot`). bool grind_heal_trip(StoryEnv& env, RunState& state, const StoryStep& step, const Pokemon::Pose& patch, const GrindSpot& spot){ std::optional here = story_pose(patch); - if (!here){ + const Pokemon::GridPose* nurse = game_arg(step.args, "nurse"); + const std::optional back = story_pose(patch); + if (!here || !back || nurse == nullptr){ return false; } if (spot.displaced && spot.facing){ @@ -534,7 +553,7 @@ bool grind_heal_trip(StoryEnv& env, RunState& state, const StoryStep& step, cons StoryStep walk; walk.kind = StoryStepKind::ROUTE; walk.name = step.name + "_to_nurse"; - walk.target = step.target; + walk.args = {{"target", *nurse}, {"fight_wild", false}}; if (!walked(env, state, walk)){ return false; } @@ -542,12 +561,12 @@ bool grind_heal_trip(StoryEnv& env, RunState& state, const StoryStep& step, cons // PP too: a grind's battles spend more than its attacks have. healed_by_nurse(env.supplies); walk.name = step.name + "_back_to_patch"; - walk.target = patch; + walk.args["target"] = Pokemon::GridPose{back->map, {back->tile}, back->facing}; return walked(env, state, walk); } // A MART, TEACH, LEVEL, GRIND or fossil step on the console; nothing for -// another variant. +// another action. std::optional run_abilities(StoryEnv& env, RunState& state, const StoryStep& step){ const Pokemon::Pose patch = state.pose; ConsoleMartActions mart(env.console, env.context, env.language, env.supplies); @@ -567,11 +586,11 @@ std::optional run_abilities(StoryEnv& env, RunState& state, const Story } // namespace Outcome StoryExecutor::game(RunState& state, const StoryStep& step){ - if (step.variant == CLOSE_TRAINER_CARD){ + if (step.action == CLOSE_TRAINER_CARD){ close_trainer_card(m_env.console, m_env.context); return Pokemon::outcome_ok(); } - if (step.variant == LEAVE_GIFT_SUMMARY){ + if (step.action == LEAVE_GIFT_SUMMARY){ leave_gift_summary(m_env.console, m_env.context); return Pokemon::outcome_ok(); } @@ -730,7 +749,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 853b9a0d40..a331bb40e9 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" @@ -203,7 +203,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; @@ -264,17 +264,16 @@ class StoryExecutor : public Pokemon::StoryStepExecutor{ // The step's action from the table. virtual Pokemon::Outcome run(Pokemon::RunState& state, const StoryStep& step) override; -protected: - // CLOSE_TRAINER_CARD: back from SID Helper (close_trainer_card()). - // LEAVE_GIFT_SUMMARY: back from Gift RNG (leave_gift_summary()). - // A capture or a PC deposit or withdrawal (capture_step(), pc_step() - // in PokemonFRLG_AutoStoryCapture.h); a shiny met in a capture stops - // the program without reloading. A MART, TEACH, LEVEL, GRIND or - // fossil CHOICE (PokemonFRLG_AutoStoryAbilities.h); a GRIND heals by - // routing to its target, the nurse, and back. - virtual Pokemon::Outcome game(Pokemon::RunState& state, const StoryStep& step) override; - private: + // A GAME step by its action. CLOSE_TRAINER_CARD: back from SID Helper + // (close_trainer_card()). LEAVE_GIFT_SUMMARY: back from Gift RNG + // (leave_gift_summary()). A capture or a PC deposit or withdrawal + // (capture_step(), pc_step() in PokemonFRLG_AutoStoryCapture.h); a + // shiny met in a capture stops the program without reloading. A MART, + // TEACH, LEVEL, GRIND or fossil CHOICE + // (PokemonFRLG_AutoStoryAbilities.h); a GRIND heals by routing to its + // nurse and back. + Pokemon::Outcome game(Pokemon::RunState& state, const StoryStep& step); // How the console does `id`. Pokemon::StoryAction console_action(StoryActionId id); 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_AutoStoryGameArgs.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGameArgs.cpp new file mode 100644 index 0000000000..84edd1e3de --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGameArgs.cpp @@ -0,0 +1,46 @@ +/* AutoStory Game Args + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonFRLG_AutoStoryGameArgs.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +Pokemon::StoryArgSpec required_arg(std::string key, Pokemon::StoryArgType type, std::string why){ + return Pokemon::StoryArgSpec{.key = std::move(key), .type = type, .required = true, .fallback = std::nullopt, .why = std::move(why)}; +} + +Pokemon::StoryArgSpec optional_arg(std::string key, Pokemon::StoryArgType type, Pokemon::StoryArgValue fallback, std::string why){ + return Pokemon::StoryArgSpec{.key = std::move(key), .type = type, .required = false, .fallback = std::move(fallback), .why = std::move(why)}; +} + +Pokemon::StoryArgSpec absent_arg(std::string key, Pokemon::StoryArgType type, std::string why){ + return Pokemon::StoryArgSpec{.key = std::move(key), .type = type, .required = false, .fallback = std::nullopt, .why = std::move(why)}; +} + +std::optional number_arg(const Pokemon::StoryActionArgs& args, std::string_view key, size_t min, size_t max){ + const int64_t* value = game_arg(args, key); + if (value == nullptr || *value < (int64_t)min || *value > (int64_t)max){ + return std::nullopt; + } + return (size_t)*value; +} + +std::optional counted_arg(const Pokemon::StoryActionArgs& args, std::string_view key, size_t max){ + const std::optional value = number_arg(args, key, 1, max); + if (!value){ + return std::nullopt; + } + return *value - 1; +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGameArgs.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGameArgs.h new file mode 100644 index 0000000000..7448f3c813 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGameArgs.h @@ -0,0 +1,57 @@ +/* AutoStory Game Args + * + * From: https://github.com/PokemonAutomation/ + * + * Declaring and reading the args of FRLG's own GAME actions (a PC + * transfer, a capture, a Mart, a TEACH...): each declares its args as a + * Pokemon::StoryActionSpec, the story file gives them, the reader fills in + * the fallbacks, and the step reads them back into its plan. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryGameArgs_H +#define PokemonAutomation_PokemonFRLG_AutoStoryGameArgs_H + +#include +#include +#include +#include +#include "Pokemon/AutoStory/Pokemon_MapUtil.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionArg.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// An arg the action needs. +Pokemon::StoryArgSpec required_arg(std::string key, Pokemon::StoryArgType type, std::string why); +// An arg read as `fallback` when the step leaves it out. +Pokemon::StoryArgSpec optional_arg(std::string key, Pokemon::StoryArgType type, Pokemon::StoryArgValue fallback, std::string why); +// An arg the step may leave out, with no fallback: absent means "none". +Pokemon::StoryArgSpec absent_arg(std::string key, Pokemon::StoryArgType type, std::string why); + +// `args`' value of `key`, or null when it is missing or of another type. +template +const Type* game_arg(const Pokemon::StoryActionArgs& args, std::string_view key); + +template +const Type* game_arg(const Pokemon::StoryActionArgs& args, std::string_view key){ + return Pokemon::value_if_at_it(args, args.find(key)); +} + +// The INTEGER arg `key` when it is from `min` to `max`; nothing if it is +// missing, of another type or out of range. +std::optional number_arg(const Pokemon::StoryActionArgs& args, std::string_view key, size_t min, size_t max); + +// The INTEGER arg `key`, a slot or box counted from 1 to `max` as the game +// shows it, counted from 0; nothing if it is missing or out of range. +std::optional counted_arg(const Pokemon::StoryActionArgs& args, std::string_view key, size_t max); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.cpp index 268af6e929..39b316b68a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.cpp @@ -5,11 +5,12 @@ */ #include +#include #include #include "CommonFramework/Exceptions/OperationFailedException.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryGameArgs.h" #include "PokemonFRLG_AutoStoryGrind.h" -#include "PokemonFRLG_AutoStoryVariantWords.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -35,88 +36,59 @@ const char* grind_end_name(GrindEnd end){ } -std::string grind_variant(const GrindPlan& plan){ - std::string variant = std::format( - "{}slot={} level={} encounters={} pace={} heal_every={}", - GRIND_VARIANT_PREFIX, plan.member + 1, plan.level, plan.max_encounters, - direction_name(plan.pace), plan.heal_every - ); +Pokemon::StoryActionArgs grind_args(const GrindPlan& plan, Pokemon::GridPose nurse){ + Pokemon::StoryActionArgs args{ + {"slot", int64_t(plan.member + 1)}, + {"level", int64_t(plan.level)}, + {"encounters", int64_t(plan.max_encounters)}, + {"pace", plan.pace}, + {"heal_every", int64_t(plan.heal_every)}, + {"nurse", std::move(nurse)}, + }; if (!plan.trainer.empty()){ - variant += std::format(" beat={} chance={:.0f}", plan.trainer, 100 * plan.min_chance); - } - return variant; -} - -namespace{ - -bool set_grind_word(GrindPlan& plan, std::string_view word){ - const std::optional pair = variant_pair(word); - if (!pair){ - return false; - } - if (pair->key == "beat"){ - plan.trainer = std::string(pair->value); - return !plan.trainer.empty(); - } - if (pair->key == "pace"){ - for (Direction direction : Pokemon::ALL_DIRECTIONS){ - if (pair->value == direction_name(direction)){ - plan.pace = direction; - return true; - } - } - return false; - } - const std::optional number = variant_number(pair->value, 4); - if (!number){ - return false; + args.emplace("beat", plan.trainer); + args.emplace("chance", int64_t(std::lround(100 * plan.min_chance))); } - if (pair->key == "slot" && *number >= 1 && *number <= PARTY_SLOTS){ - plan.member = *number - 1; - }else if (pair->key == "level" && *number >= 2 && *number <= 100){ - plan.level = (unsigned)*number; - }else if (pair->key == "encounters" && *number >= 1){ - plan.max_encounters = *number; - }else if (pair->key == "heal_every"){ - plan.heal_every = *number; - }else if (pair->key == "chance" && *number >= 1 && *number <= 100){ - plan.min_chance = static_cast(*number) / 100; - }else{ - return false; - } - return true; + return args; } -} // namespace - -std::optional parse_grind_variant(std::string_view variant){ - if (!variant.starts_with(GRIND_VARIANT_PREFIX)){ +std::optional grind_plan_of(const Pokemon::StoryActionArgs& args){ + const std::optional member = counted_arg(args, "slot", PARTY_SLOTS); + const std::optional level = number_arg(args, "level", 2, 100); + const std::optional encounters = number_arg(args, "encounters", 1, 9999); + const std::optional heal_every = number_arg(args, "heal_every", 0, 9999); + const Direction* pace = game_arg(args, "pace"); + if (!member || !level || !encounters || !heal_every || pace == nullptr){ return std::nullopt; } - GrindPlan plan; - bool level_seen = false; - bool chance_seen = false; - for (std::string_view word : variant_words(variant.substr(GRIND_VARIANT_PREFIX.size()))){ - if (!set_grind_word(plan, word)){ + GrindPlan plan{ + .member = *member, .level = (unsigned)*level, .max_encounters = *encounters, + .pace = *pace, .heal_every = *heal_every, + }; + if (const std::string* trainer = game_arg(args, "beat")){ + if (trainer->empty()){ return std::nullopt; } - level_seen |= word.starts_with("level="); - chance_seen |= word.starts_with("chance="); + plan.trainer = *trainer; } - // A chance needs a trainer to be against. - if (!level_seen || (chance_seen && plan.trainer.empty())){ - return std::nullopt; + if (args.contains("chance")){ + const std::optional chance = number_arg(args, "chance", 1, 100); + // A chance needs a trainer to be against. + if (!chance || plan.trainer.empty()){ + return std::nullopt; + } + plan.min_chance = static_cast(*chance) / 100; } return plan; } -Pokemon::StoryStep grind_step(std::string name, std::string why, const GrindPlan& plan, Pokemon::Pose nurse){ +Pokemon::StoryStep grind_step(std::string name, std::string why, const GrindPlan& plan, Pokemon::GridPose nurse){ Pokemon::StoryStep step; step.kind = Pokemon::StoryStepKind::GAME; step.name = std::move(name); step.why = std::move(why); - step.variant = grind_variant(plan); - step.target = std::move(nurse); + step.action = GRIND_ACTION; + step.args = grind_args(plan, std::move(nurse)); return step; } @@ -316,7 +288,7 @@ std::optional healed_win_chance(PartyMember lead, int potions, std: ConsoleGrindActions::ConsoleGrindActions( ConsoleHandle& console, ProControllerContext& context, Language language, - Supplies& supplies, StoryChecks checks, HealTrip heal_trip + Supplies& supplies, Pokemon::StoryCheckLevel checks, HealTrip heal_trip ) : m_console(console) , m_context(context) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.h index c7c646952b..acf622b981 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.h @@ -38,7 +38,8 @@ #include "CommonFramework/Language.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_StoryActionSpec.h" #include "Pokemon/Navigation/Pokemon_Grid.h" #include "PokemonFRLG_AutoStoryBattle.h" #include "PokemonFRLG_AutoStoryBattleData.h" @@ -72,19 +73,20 @@ struct GrindPlan{ double min_chance = MIN_WIN_CHANCE; }; -// The prefix of a GAME step's variant that names a GRIND step. -inline constexpr std::string_view GRIND_VARIANT_PREFIX = "grind "; - -// `plan` as a variant: "grind slot=1 level=18 encounters=60 pace=east -// heal_every=8", the slot counted from 1, and with a trainer -// " beat=TRAINER_RIVAL_CERULEAN_BULBASAUR chance=70", the chance in -// percent. The step's target is the nurse. -std::string grind_variant(const GrindPlan& plan); -// Parses a grinding plan from a variant string. -std::optional parse_grind_variant(std::string_view variant); +// The GAME action of a GRIND step: slot INTEGER (required, from 1); +// level INTEGER (required, 2-100); encounters INTEGER (60); pace +// DIRECTION (east); heal_every INTEGER (0); beat WORD and chance INTEGER +// (optional), the trainer and the win chance in percent; nurse GRID_POSE +// (required), where the step heals. +inline const std::string GRIND_ACTION = "grind"; +// `plan` and `nurse` as its action's args. +Pokemon::StoryActionArgs grind_args(const GrindPlan& plan, Pokemon::GridPose nurse); +// The plan a GRIND_ACTION step's args give; nothing if one is out of +// range, or a chance has no trainer to be against. +std::optional grind_plan_of(const Pokemon::StoryActionArgs& args); // The table's GRIND step: `nurse` is where the player faces the nurse. -Pokemon::StoryStep grind_step(std::string name, std::string why, const GrindPlan& plan, Pokemon::Pose nurse); +Pokemon::StoryStep grind_step(std::string name, std::string why, const GrindPlan& plan, Pokemon::GridPose nurse); // The outcome of an individual grinding battle. @@ -182,7 +184,7 @@ class ConsoleGrindActions : public GrindActions{ ConsoleGrindActions( ConsoleHandle& console, ProControllerContext& context, Language language, - Supplies& supplies, StoryChecks checks, HealTrip heal_trip + Supplies& supplies, Pokemon::StoryCheckLevel checks, HealTrip heal_trip ); virtual bool find_encounter(Pokemon::Direction pace) override; @@ -199,7 +201,7 @@ class ConsoleGrindActions : public GrindActions{ ProControllerContext& m_context; Language m_language; Supplies& m_supplies; - StoryChecks m_checks; + Pokemon::StoryCheckLevel m_checks; ConsoleCaptureActions m_encounters; HealTrip m_heal_trip; GrindSpot m_spot; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind_Tests.cpp index 57daa3259e..f663040248 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind_Tests.cpp @@ -17,6 +17,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "PokemonFRLG_AutoStoryBattleSim.h" +#include "PokemonFRLG_AutoStoryGameArgs.h" #include "PokemonFRLG_AutoStoryGrind.h" namespace PokemonAutomation{ @@ -429,41 +430,55 @@ UnitTestResult test_console_party(){ } -UnitTestResult test_grind_variant(){ +// A GridPose for the nurse the args carry. +const Pokemon::GridPose NURSE{"Route4_PokemonCenter_1F", {{7, 4}}, Pokemon::Direction::NORTH}; + +UnitTestResult test_grind_args(){ GrindPlan plan = squirtle_to(18); plan.max_encounters = 60; plan.pace = Pokemon::Direction::NORTH; plan.heal_every = 8; - const std::string variant = grind_variant(plan); - if (variant != "grind slot=1 level=18 encounters=60 pace=north heal_every=8"){ - return "Unexpected variant \"" + variant + "\"."; - } - const std::optional back = parse_grind_variant(variant); + const Pokemon::StoryActionArgs args = grind_args(plan, NURSE); + const std::optional back = grind_plan_of(args); if (!back || back->level != 18 || back->max_encounters != 60 || back->pace != Pokemon::Direction::NORTH - || back->heal_every != 8 || back->member != 0 + || back->heal_every != 8 || back->member != 0 || !back->trainer.empty() || args.contains("chance") ){ - return "\"" + variant + "\" didn't read back as its plan."; + return "The level-18 plan didn't read back from its args."; } GrindPlan rival = beat_rival(30); rival.max_encounters = 100; rival.pace = Pokemon::Direction::WEST; - const std::string rival_variant = grind_variant(rival); - if (rival_variant != "grind slot=1 level=30 encounters=100 pace=west heal_every=0 beat=TRAINER_RIVAL_CERULEAN_BULBASAUR chance=70"){ - return "Unexpected variant \"" + rival_variant + "\"."; + Pokemon::StoryActionArgs rival_args = grind_args(rival, NURSE); + const int64_t* chance = game_arg(rival_args, "chance"); + const std::string* beat = game_arg(rival_args, "beat"); + if (chance == nullptr || *chance != 70 || beat == nullptr || *beat != RIVAL){ + return "Expected the rival's plan to carry beat and chance=70."; } - const std::optional rival_back = parse_grind_variant(rival_variant + " chance=75"); + rival_args["chance"] = int64_t(75); + const std::optional rival_back = grind_plan_of(rival_args); if (!rival_back || rival_back->trainer != RIVAL || rival_back->level != 30 || rival_back->min_chance != 0.75){ - return "\"" + rival_variant + " chance=75\" didn't read back as its plan."; + return "The rival's plan with chance=75 didn't read back."; } - for (std::string_view bad : { - "grind", "grind slot=1", "grind slot=1 level=101", "grind slot=7 level=18", "grind level=18 pace=up", - "grind level=18 encounters=0", "capture rattata", "grind level=30 beat=", "grind level=30 chance=70", - "grind level=30 beat=TRAINER_X chance=0", "grind level=30 beat=TRAINER_X chance=101", - }){ - if (parse_grind_variant(bad)){ - return "Expected \"" + std::string(bad) + "\" refused."; + const std::vector> bad_args{ + {"level", int64_t(101)}, + {"slot", int64_t(7)}, + {"encounters", int64_t(0)}, + {"beat", std::string("")}, + {"chance", int64_t(0)}, + {"chance", int64_t(101)}, + }; + for (const auto& [key, value] : bad_args){ + Pokemon::StoryActionArgs bad = rival_args; + bad[key] = value; + if (grind_plan_of(bad)){ + return "Expected a bad " + key + " refused."; } } + Pokemon::StoryActionArgs no_trainer = rival_args; + no_trainer.erase("beat"); + if (grind_plan_of(no_trainer)){ + return "Expected a chance with no trainer refused."; + } return true; } @@ -476,7 +491,7 @@ const AutoStoryGrindCase AUTO_STORY_GRIND_CASES[] = { .expectation = {}, }, { - .input = {"the table's variant", test_grind_variant}, + .input = {"the step's args", test_grind_args}, .expectation = {}, }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index d79671f5bc..aa98f049c0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -283,7 +283,7 @@ UnitTestResult test_late_battle_placed(Logger&){ script.encounters = {{.grass_step = 1, .seen_late = true}}; OverworldSim sim(maps, leg->start, leg->step.direction, script); Supplies supplies; - const OverworldInterruptSet story = story_interrupts(supplies, false, StoryChecks::FAST, Language::English); + const OverworldInterruptSet story = story_interrupts(supplies, false, Pokemon::StoryCheckLevel::FAST, Language::English); OverworldSimWalker walker(sim, {}, story); const StepOutcome outcome = walker.calls().walk(leg->step, leg->step.direction); const int walked = tiles_walked(maps, *leg, sim.state().position); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp index e09dfca5d3..87becb42fa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp @@ -12,8 +12,8 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryGameArgs.h" #include "PokemonFRLG_AutoStoryMart.h" -#include "PokemonFRLG_AutoStoryVariantWords.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -26,6 +26,8 @@ namespace{ // The quantity box's most (shop.c Task_BuyHowManyDialogueInit). constexpr size_t MAX_QUANTITY = 99; +// pokefirered: MAX_MONEY. +constexpr size_t MAX_MONEY = 999999; // Prices from pokefirered src/data/items.json. constexpr MartStockItem POKE_BALL{"poke-ball", 200}; @@ -79,25 +81,6 @@ std::optional stock_row(const std::vector& stock, std::st return std::nullopt; } -// Sets one "key=value" of a Mart variant into `plan`. False if it can't. -bool set_mart_word(MartPlan& plan, std::string_view word){ - const std::optional pair = variant_pair(word); - const std::optional number = pair ? variant_number(pair->value) : std::nullopt; - if (!number){ - return false; - } - if (pair->key == "budget"){ - plan.budget = *number; - }else if (pair->key == "floor"){ - plan.money_floor = *number; - }else if (*number >= 1 && *number <= MAX_QUANTITY && stock_row(mart_stock(plan.map), pair->key)){ - plan.lines.push_back({std::string(pair->key), *number}); - }else{ - return false; - } - return true; -} - } // namespace @@ -118,34 +101,39 @@ const char* mart_end_name(MartEnd end){ } -std::string mart_variant(const MartPlan& plan){ - std::string variant = std::format("{}{} budget={}", MART_VARIANT_PREFIX, plan.map, plan.budget); - if (plan.money_floor){ - variant += std::format(" floor={}", *plan.money_floor); - } +Pokemon::StoryActionArgs mart_args(const MartPlan& plan){ + std::vector items; for (const MartLine& line : plan.lines){ - variant += std::format(" {}={}", line.item, line.quantity); + items.push_back({line.item, line.quantity}); } - return variant; + Pokemon::StoryActionArgs args{ + {"map", plan.map}, {"budget", int64_t(plan.budget)}, {"items", std::move(items)}, + }; + if (plan.money_floor){ + args.emplace("floor", int64_t(*plan.money_floor)); + } + return args; } -std::optional parse_mart_variant(std::string_view variant){ - if (!variant.starts_with(MART_VARIANT_PREFIX)){ - return std::nullopt; - } - const std::vector words = variant_words(variant.substr(MART_VARIANT_PREFIX.size())); - if (words.empty() || mart_stock(words[0]).empty()){ +std::optional mart_plan_of(const Pokemon::StoryActionArgs& args){ + const std::string* map = game_arg(args, "map"); + const std::optional budget = number_arg(args, "budget", 0, MAX_MONEY); + const std::vector* items = game_arg>(args, "items"); + if (map == nullptr || mart_stock(*map).empty() || !budget || items == nullptr || items->empty()){ return std::nullopt; } - MartPlan plan; - plan.map = std::string(words[0]); - for (size_t c = 1; c < words.size(); c++){ - if (!set_mart_word(plan, words[c])){ + MartPlan plan{.map = *map, .budget = *budget}; + if (args.contains("floor")){ + plan.money_floor = number_arg(args, "floor", 0, MAX_MONEY); + if (!plan.money_floor){ return std::nullopt; } } - if (plan.lines.empty()){ - return std::nullopt; + for (const Pokemon::StoryItem& item : *items){ + if (item.quantity < 1 || item.quantity > MAX_QUANTITY || !stock_row(mart_stock(plan.map), item.item)){ + return std::nullopt; + } + plan.lines.push_back({item.item, item.quantity}); } return plan; } @@ -155,7 +143,8 @@ Pokemon::StoryStep mart_step(std::string name, std::string why, const MartPlan& step.kind = Pokemon::StoryStepKind::GAME; step.name = std::move(name); step.why = std::move(why); - step.variant = mart_variant(plan); + step.action = MART_ACTION; + step.args = mart_args(plan); return step; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h index 060ff0d9c4..f563fab219 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h @@ -46,7 +46,8 @@ #include "CommonFramework/Language.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_StoryActionSpec.h" #include "PokemonFRLG_AutoStoryBattle.h" namespace PokemonAutomation{ @@ -84,15 +85,15 @@ struct MartPlan{ std::optional money_floor = std::nullopt; }; -// The prefix of a GAME step's variant that names a Mart step. -inline constexpr std::string_view MART_VARIANT_PREFIX = "mart "; - -// `plan` as a variant: "mart PewterCity_Mart budget=2000 floor=2400 -// potion=5 repel=3", the lines in order. -std::string mart_variant(const MartPlan& plan); -// A variant from mart_variant(); nothing if it isn't one, has no line, or +// The GAME action of a Mart step: map WORD (required), the Mart's map; +// budget INTEGER (required); floor INTEGER (optional), the money floor; +// items ITEMS (required), the lines in order. +inline const std::string MART_ACTION = "mart"; +// `plan` as its action's args. +Pokemon::StoryActionArgs mart_args(const MartPlan& plan); +// The plan a MART_ACTION step's args give; nothing if it has no line or // names an item its Mart doesn't sell. -std::optional parse_mart_variant(std::string_view variant); +std::optional mart_plan_of(const Pokemon::StoryActionArgs& args); // The table's Mart step. Pokemon::StoryStep mart_step(std::string name, std::string why, const MartPlan& plan); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp index a8295b0702..7605472336 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp @@ -335,25 +335,27 @@ UnitTestResult test_quantity_presses(){ } -UnitTestResult test_mart_variant(){ +UnitTestResult test_mart_args(){ const MartPlan plan = pewter_plan(2000, {{"potion", 5}, {"repel", 3}}, 2400); - const std::string variant = mart_variant(plan); - if (variant != "mart PewterCity_Mart budget=2000 floor=2400 potion=5 repel=3"){ - return "Unexpected variant \"" + variant + "\"."; - } - const std::optional back = parse_mart_variant(variant); + const Pokemon::StoryActionArgs args = mart_args(plan); + const std::optional back = mart_plan_of(args); if (!back || back->map != plan.map || back->budget != 2000 || back->money_floor != plan.money_floor || back->lines.size() != 2 || back->lines[1].item != "repel" || back->lines[1].quantity != 3 ){ - return "\"" + variant + "\" didn't read back as its plan."; + return "The Pewter plan didn't read back from its args."; } - for (std::string_view bad : { - "mart", "mart PewterCity_Mart budget=2000", "mart Nowhere_Mart potion=1", - "mart ViridianCity_Mart repel=1", "mart PewterCity_Mart potion=0", "mart PewterCity_Mart potion=100", - "mart PewterCity_Mart potion", "teach hm03 surf slot=1", - }){ - if (parse_mart_variant(bad)){ - return "Expected \"" + std::string(bad) + "\" refused."; + const std::vector> bad_args{ + {"items", std::vector{}}, + {"map", std::string("Nowhere_Mart")}, + {"map", std::string("ViridianCity_Mart")}, + {"items", std::vector{{"potion", 0}}}, + {"items", std::vector{{"potion", 100}}}, + }; + for (const auto& [key, value] : bad_args){ + Pokemon::StoryActionArgs bad = args; + bad[key] = value; + if (mart_plan_of(bad)){ + return "Expected a bad " + key + " refused."; } } return true; @@ -406,7 +408,7 @@ const AutoStoryMartCase AUTO_STORY_MART_CASES[] = { .expectation = {}, }, { - .input = {"the table's variant", test_mart_variant}, + .input = {"the step's args", test_mart_args}, .expectation = {}, }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.cpp index 6d3f71dd1e..bb4a4b3eb2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.cpp @@ -5,9 +5,9 @@ */ #include +#include "PokemonFRLG_AutoStoryGameArgs.h" #include "PokemonFRLG_AutoStoryMember.h" #include "PokemonFRLG_AutoStorySummary.h" -#include "PokemonFRLG_AutoStoryVariantWords.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -30,37 +30,17 @@ MemberReader console_member_reader(ConsoleHandle& console, ProControllerContext& } -std::string level_variant(const LevelCheck& check){ - return std::format("{}slot={} min={}", LEVEL_VARIANT_PREFIX, check.slot + 1, check.level); +Pokemon::StoryActionArgs level_args(const LevelCheck& check){ + return {{"slot", int64_t(check.slot + 1)}, {"min", int64_t(check.level)}}; } -std::optional parse_level_variant(std::string_view variant){ - if (!variant.starts_with(LEVEL_VARIANT_PREFIX)){ +std::optional level_check_of(const Pokemon::StoryActionArgs& args){ + const std::optional slot = counted_arg(args, "slot", PARTY_SLOTS); + const std::optional level = number_arg(args, "min", 1, 100); + if (!slot || !level){ return std::nullopt; } - LevelCheck check; - bool slot_seen = false; - bool level_seen = false; - for (std::string_view word : variant_words(variant.substr(LEVEL_VARIANT_PREFIX.size()))){ - const std::optional pair = variant_pair(word); - const std::optional number = pair ? variant_number(pair->value, 3) : std::nullopt; - if (!number){ - return std::nullopt; - } - if (pair->key == "slot" && *number >= 1 && *number <= PARTY_SLOTS){ - check.slot = *number - 1; - slot_seen = true; - }else if (pair->key == "min" && *number >= 1 && *number <= 100){ - check.level = (unsigned)*number; - level_seen = true; - }else{ - return std::nullopt; - } - } - if (!slot_seen || !level_seen){ - return std::nullopt; - } - return check; + return LevelCheck{.slot = *slot, .level = (unsigned)*level}; } Pokemon::StoryStep level_step(std::string name, std::string why, const LevelCheck& check){ @@ -68,7 +48,8 @@ Pokemon::StoryStep level_step(std::string name, std::string why, const LevelChec step.kind = Pokemon::StoryStepKind::GAME; step.name = std::move(name); step.why = std::move(why); - step.variant = level_variant(check); + step.action = LEVEL_ACTION; + step.args = level_args(check); return step; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.h index 937c4962f7..0c681a9afd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.h @@ -28,7 +28,8 @@ #include "CommonFramework/Language.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_StoryActionSpec.h" #include "PokemonFRLG_AutoStoryDamage.h" namespace PokemonAutomation{ @@ -72,13 +73,13 @@ struct LevelCheck{ unsigned level = 1; }; -// The prefix of a GAME step's variant that names a LEVEL step. -inline constexpr std::string_view LEVEL_VARIANT_PREFIX = "level "; - -// `check` as a variant: "level slot=1 min=16", the slot counted from 1. -std::string level_variant(const LevelCheck& check); -// A variant from level_variant(); nothing if it isn't one. -std::optional parse_level_variant(std::string_view variant); +// The GAME action of a LEVEL step: slot INTEGER (required, from 1), min +// INTEGER (required, 1-100). +inline const std::string LEVEL_ACTION = "level"; +// `check` as its action's args. +Pokemon::StoryActionArgs level_args(const LevelCheck& check); +// The check a LEVEL_ACTION step's args give; nothing if one is out of range. +std::optional level_check_of(const Pokemon::StoryActionArgs& args); // The table's LEVEL step. Pokemon::StoryStep level_step(std::string name, std::string why, const LevelCheck& check); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.cpp index 380cdaed9a..9424d87f51 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.cpp @@ -9,6 +9,7 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryGameArgs.h" #include "PokemonFRLG_AutoStoryPcStorage.h" namespace PokemonAutomation{ @@ -30,86 +31,62 @@ constexpr size_t STORAGE_MENU_ROWS = 5; // A second look at a frame that reads as the overworld. constexpr Milliseconds OVERWORLD_CONFIRM = 800ms; -std::vector split_words(std::string_view text){ - std::vector words; - while (!text.empty()){ - const size_t space = text.find(' '); - const std::string_view word = text.substr(0, space); - if (!word.empty()){ - words.push_back(word); - } - if (space == std::string_view::npos){ - break; - } - text.remove_prefix(space + 1); - } - return words; -} - -// "key=N" with N from 1 to `max`, as N - 1. -std::optional counted_value(std::string_view word, std::string_view key, size_t max){ - if (!word.starts_with(key) || word.size() <= key.size() + 1 || word[key.size()] != '='){ - return std::nullopt; - } - size_t value = 0; - for (char c : word.substr(key.size() + 1)){ - if (c < '0' || c > '9' || value > max){ - return std::nullopt; - } - value = value * 10 + size_t(c - '0'); - } - if (value < 1 || value > max){ - return std::nullopt; +// "deposit slot=2 box=1" or "withdraw box=1 slot=7", for the log. +std::string pc_transfer_text(const PcTransfer& transfer){ + if (transfer.action == PcAction::DEPOSIT){ + return std::format( + "deposit slot={} box={}{}", transfer.party_slot + 1, transfer.box + 1, + transfer.if_missing == PcMissing::SKIP ? " if_present" : "" + ); } - return value - 1; + return std::format("withdraw box={} slot={}", transfer.box + 1, transfer.box_slot + 1); } } // namespace -std::string pc_variant(const PcTransfer& transfer){ +Pokemon::StoryActionArgs pc_args(const PcTransfer& transfer){ if (transfer.action == PcAction::DEPOSIT){ - return std::format( - "{}deposit slot={} box={}{}", PC_VARIANT_PREFIX, transfer.party_slot + 1, transfer.box + 1, - transfer.if_missing == PcMissing::SKIP ? " if_present" : "" - ); - } - return std::format("{}withdraw box={} slot={}", PC_VARIANT_PREFIX, transfer.box + 1, transfer.box_slot + 1); + return { + {"do", std::string("deposit")}, + {"slot", int64_t(transfer.party_slot + 1)}, + {"box", int64_t(transfer.box + 1)}, + {"if_present", transfer.if_missing == PcMissing::SKIP}, + }; + } + return { + {"do", std::string("withdraw")}, + {"slot", int64_t(transfer.box_slot + 1)}, + {"box", int64_t(transfer.box + 1)}, + {"if_present", false}, + }; } -std::optional parse_pc_variant(std::string_view variant){ - if (!variant.starts_with(PC_VARIANT_PREFIX)){ +std::optional pc_transfer_of(const Pokemon::StoryActionArgs& args){ + const std::string* action = game_arg(args, "do"); + const std::optional box = counted_arg(args, "box", BOX_COUNT); + if (action == nullptr || !box){ return std::nullopt; } - std::vector words = split_words(variant.substr(PC_VARIANT_PREFIX.size())); - PcTransfer transfer; - if (words.size() == 4 && words[0] == "deposit" && words[3] == "if_present"){ - transfer.if_missing = PcMissing::SKIP; - words.pop_back(); - } - if (words.size() != 3){ - return std::nullopt; + PcTransfer transfer{.box = *box}; + if (*action == "deposit"){ + const std::optional slot = counted_arg(args, "slot", PARTY_SIZE); + const bool* if_present = game_arg(args, "if_present"); + if (!slot){ + return std::nullopt; + } + transfer.party_slot = *slot; + if (if_present != nullptr && *if_present){ + transfer.if_missing = PcMissing::SKIP; + } + return transfer; } - std::optional slot; - std::optional box; - if (words[0] == "deposit"){ - transfer.action = PcAction::DEPOSIT; - slot = counted_value(words[1], "slot", PARTY_SIZE); - box = counted_value(words[2], "box", BOX_COUNT); - }else if (words[0] == "withdraw"){ - transfer.action = PcAction::WITHDRAW; - box = counted_value(words[1], "box", BOX_COUNT); - slot = counted_value(words[2], "slot", BOX_SLOTS); - } - if (!slot || !box){ + const std::optional slot = counted_arg(args, "slot", BOX_SLOTS); + if (*action != "withdraw" || !slot){ return std::nullopt; } - transfer.box = *box; - if (transfer.action == PcAction::DEPOSIT){ - transfer.party_slot = *slot; - }else{ - transfer.box_slot = *slot; - } + transfer.action = PcAction::WITHDRAW; + transfer.box_slot = *slot; return transfer; } @@ -317,7 +294,7 @@ PcDecision PcStorageDialog::on_box_chooser(const PcView& view){ PcResult run_pc_transfer(Logger& logger, PcStorageActions& actions, const PcTransfer& transfer){ - const std::string name = pc_variant(transfer); + const std::string name = pc_transfer_text(transfer); const std::vector party = actions.read_party(); if (transfer.action == PcAction::DEPOSIT && transfer.if_missing == PcMissing::SKIP && transfer.party_slot >= party.size()){ logger.log(std::format("PC: skipped \"{}\": the party has {} Pokemon.", name, party.size())); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.h index 453c78b1d8..6784fada60 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.h @@ -1,240 +1,242 @@ -/* AutoStory PC Storage - * - * From: https://github.com/PokemonAutomation/ - * - * A story step at a Pokemon Center's PC: deposit a party member in a box, - * or withdraw one from a box, as pokefirered's Pokemon Storage System runs - * it (data/scripts/pc.inc, src/pokemon_storage_system_*.c), confirmed by - * hand on console B (2026-11-02, Route 4's Pokemon Center): - * - * - A at the PC: " booted up the PC.", then "Which PC should be - * accessed?" with SOMEONE'S PC (BILL'S PC later) on top, always opened - * on it. A on it: "Accessed SOMEONE's PC." and "POKEMON Storage System - * opened.", then the storage menu: WITHDRAW, DEPOSIT, MOVE POKEMON, - * MOVE ITEMS, SEE YA!. It opens on WITHDRAW from the PC, but on the last - * option used when it comes back from a box, and UP/DOWN wrap. - * - DEPOSIT: the box screen with the party panel, the hand on the party's - * first slot. DOWN steps through the six slots, then CANCEL, and wraps. - * A on a Pokemon: STORE, SUMMARY, MARK, RELEASE, CANCEL, on STORE. - * STORE: "Deposit in which BOX?", on BOX 1 each time the PC is entered; - * RIGHT/LEFT change the box, A stores it there. - * - WITHDRAW: the box screen on the current box (the game remembers it), - * the hand on its top left Pokemon; RIGHT/DOWN move it by one of six - * columns and five rows. A on a Pokemon: WITHDRAW, SUMMARY, MARK, - * RELEASE, CANCEL, on WITHDRAW; WITHDRAW puts it in the party. - * - B on a box screen: "Continue BOX operations?" YES/NO on YES; B leaves - * for the storage menu, B again the PC list, B again the overworld. - * - * The step never moves the cursor on a Pokemon's menu, whose RELEASE is - * three rows below STORE: it confirms the top row and presses A there. - * The game refuses to deposit its last Pokemon and to withdraw into a full - * party; the step refuses first, and also refuses to leave the party with - * no Pokemon that can fight. - * - * The step's decisions take what shows from a PcStorageActions, so they - * run in tests against a fake PC. On the console, each screen is read - * (PokemonFRLG_PcScreenReader.h) before the press it gets: a press sent - * before a menu is drawn goes to the message behind it (console B, - * 2026-11-02: DOWN, A before the storage menu showed opened WITHDRAW). - * - */ - -#ifndef PokemonAutomation_PokemonFRLG_AutoStoryPcStorage_H -#define PokemonAutomation_PokemonFRLG_AutoStoryPcStorage_H - -#include -#include -#include -#include -#include -#include "Common/Cpp/Logging/AbstractLogger.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" -#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" -#include "VideoGames/PokemonFRLG/Inference/Box/PokemonFRLG_PcScreenReader.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// The storage operation to perform at the PC. -enum class PcAction{ - DEPOSIT, - WITHDRAW, -}; - -// What a DEPOSIT does when the party hasn't got its slot: refuse, or -// skip it as done (the Magikarp from Gift RNG, when Gift RNG didn't run). -enum class PcMissing{ - REFUSE, - SKIP, -}; - -// What a PC step does. Slots and boxes count from 0. -struct PcTransfer{ - PcAction action = PcAction::DEPOSIT; - // DEPOSIT: the party slot to store. - size_t party_slot = 0; - // DEPOSIT: the box to store it in. WITHDRAW: the box to take from, - // which must be the box the PC shows (the last one viewed). - size_t box = 0; - // WITHDRAW: the box slot, row by row, six to a row. - size_t box_slot = 0; - PcMissing if_missing = PcMissing::REFUSE; -}; - -// The prefix of a GAME step's variant that names a PC step. -inline constexpr std::string_view PC_VARIANT_PREFIX = "pc "; - -// `transfer` as a GAME step's variant: "pc deposit slot=2 box=1" or -// "pc withdraw box=1 slot=7", slots and boxes counted from 1 as the game -// shows them; a deposit with PcMissing::SKIP ends in " if_present". -std::string pc_variant(const PcTransfer& transfer); -// A variant from pc_variant(); nothing if `variant` isn't one, or names a -// slot or box the game hasn't got. -std::optional parse_pc_variant(std::string_view variant); - - -// A party member as far as a PC step needs to know. -struct PcPartyMember{ - // Its species' slug, or empty if not read. - std::string species = {}; - bool fainted = false; -}; - -// Why `transfer` can't be done with `party`, or empty if it can: a -// deposit of a slot the party hasn't got, of its last Pokemon, or of its -// last one that can fight; a withdrawal into a full party. -std::string pc_transfer_error(const PcTransfer& transfer, const std::vector& party); - - -// A controller action taken during a PC dialog sequence. -enum class PcPress{ - A, - B, - UP, - DOWN, - LEFT, - RIGHT, - // Nothing: look again. - WAIT, - // The transfer is made and the overworld is back. - DONE, - FAIL, -}; -// The human-readable name of a PC controller action. -const char* pc_press_name(PcPress press); - -// The next action decided by the PC dialog state machine. -struct PcDecision{ - PcPress press = PcPress::WAIT; - // FAIL: why. - std::string reason = {}; -}; - -// What the PC step presses on each screen it reads, from the overworld -// facing the PC to the overworld again with the transfer made. -class PcStorageDialog{ -public: - explicit PcStorageDialog(const PcTransfer& transfer); - - PcDecision next(const PcView& view); - - // Whether the transfer was made: the last press that makes it was sent. - bool transferred() const{ - return m_transferred; - } - -private: - PcDecision on_overworld(); - PcDecision on_storage_menu(const PcView& view); - PcDecision on_party_panel(const PcView& view); - PcDecision on_box_grid(const PcView& view); - PcDecision on_mon_menu(const PcView& view); - PcDecision on_box_chooser(const PcView& view); - - PcTransfer m_transfer; - bool m_booted = false; - // The overworld read since A at the PC, while the PC boots. - size_t m_booting_reads = 0; - bool m_transferred = false; - // BOX_CHOOSER opens on BOX 1 each time the PC is entered. - bool m_chooser_seen = false; - size_t m_others_in_a_row = 0; -}; - - -// The game steps a PC step takes, injected so its decisions run in tests. -class PcStorageActions{ -public: - virtual ~PcStorageActions() = default; - - // From the overworld: the party, read from the party menu, which is - // closed again. - virtual std::vector read_party() = 0; - // What shows now. - virtual PcView read_view() = 0; - // One press (A, B or the D-pad), and the wait for the screen to answer. - virtual void press(PcPress press) = 0; -}; - -// How a PC transfer sequence concluded. -enum class PcEnd{ - DONE, - // A DEPOSIT with PcMissing::SKIP whose slot the party hasn't got: the - // PC wasn't touched. - SKIPPED, - // pc_transfer_error() refused it before the PC was touched. - REFUSED, - FAILED, -}; -// The result of a PC transfer operation. -struct PcResult{ - PcEnd end = PcEnd::FAILED; - std::string detail = {}; -}; - -// Reads after this many presses without the overworld back: a failure. -constexpr size_t PC_MAX_PRESSES = 80; -// OTHER read this many times in a row: a failure. -constexpr size_t PC_MAX_OTHER_IN_A_ROW = 10; -// The overworld read this many times after A at the PC: it didn't boot. -constexpr size_t PC_BOOT_READS = 4; - -// From the overworld, facing the PC: the transfer, back to the overworld. -PcResult run_pc_transfer(Logger& logger, PcStorageActions& actions, const PcTransfer& transfer); - - -// From the overworld: the party's size, read from the party menu, which is -// closed again. -size_t read_party_size(ConsoleHandle& console, ProControllerContext& context); - -// The console's PC steps. Party members are read by count only: none is -// taken as fainted, since the story heals before it uses the PC. Screens -// are read with read_pc_screen(); the overworld only once a second frame, -// a moment later, shows it too, since a frame between two menus can look -// like it. -class ConsolePcStorageActions : public PcStorageActions{ -public: - ConsolePcStorageActions(ConsoleHandle& console, ProControllerContext& context); - - virtual std::vector read_party() override; - virtual PcView read_view() override; - virtual void press(PcPress press) override; - -private: - ConsoleHandle& m_console; - ProControllerContext& m_context; -}; - - -// Register auto-story PC storage unit tests. -void add_tests_AutoStoryPcStorage(UnitTestDatabase& database); - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif +/* AutoStory PC Storage + * + * From: https://github.com/PokemonAutomation/ + * + * A story step at a Pokemon Center's PC: deposit a party member in a box, + * or withdraw one from a box, as pokefirered's Pokemon Storage System runs + * it (data/scripts/pc.inc, src/pokemon_storage_system_*.c), confirmed by + * hand on console B (2026-11-02, Route 4's Pokemon Center): + * + * - A at the PC: " booted up the PC.", then "Which PC should be + * accessed?" with SOMEONE'S PC (BILL'S PC later) on top, always opened + * on it. A on it: "Accessed SOMEONE's PC." and "POKEMON Storage System + * opened.", then the storage menu: WITHDRAW, DEPOSIT, MOVE POKEMON, + * MOVE ITEMS, SEE YA!. It opens on WITHDRAW from the PC, but on the last + * option used when it comes back from a box, and UP/DOWN wrap. + * - DEPOSIT: the box screen with the party panel, the hand on the party's + * first slot. DOWN steps through the six slots, then CANCEL, and wraps. + * A on a Pokemon: STORE, SUMMARY, MARK, RELEASE, CANCEL, on STORE. + * STORE: "Deposit in which BOX?", on BOX 1 each time the PC is entered; + * RIGHT/LEFT change the box, A stores it there. + * - WITHDRAW: the box screen on the current box (the game remembers it), + * the hand on its top left Pokemon; RIGHT/DOWN move it by one of six + * columns and five rows. A on a Pokemon: WITHDRAW, SUMMARY, MARK, + * RELEASE, CANCEL, on WITHDRAW; WITHDRAW puts it in the party. + * - B on a box screen: "Continue BOX operations?" YES/NO on YES; B leaves + * for the storage menu, B again the PC list, B again the overworld. + * + * The step never moves the cursor on a Pokemon's menu, whose RELEASE is + * three rows below STORE: it confirms the top row and presses A there. + * The game refuses to deposit its last Pokemon and to withdraw into a full + * party; the step refuses first, and also refuses to leave the party with + * no Pokemon that can fight. + * + * The step's decisions take what shows from a PcStorageActions, so they + * run in tests against a fake PC. On the console, each screen is read + * (PokemonFRLG_PcScreenReader.h) before the press it gets: a press sent + * before a menu is drawn goes to the message behind it (console B, + * 2026-11-02: DOWN, A before the storage menu showed opened WITHDRAW). + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryPcStorage_H +#define PokemonAutomation_PokemonFRLG_AutoStoryPcStorage_H + +#include +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonFRLG/Inference/Box/PokemonFRLG_PcScreenReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The storage operation to perform at the PC. +enum class PcAction{ + DEPOSIT, + WITHDRAW, +}; + +// What a DEPOSIT does when the party hasn't got its slot: refuse, or +// skip it as done (the Magikarp from Gift RNG, when Gift RNG didn't run). +enum class PcMissing{ + REFUSE, + SKIP, +}; + +// What a PC step does. Slots and boxes count from 0. +struct PcTransfer{ + PcAction action = PcAction::DEPOSIT; + // DEPOSIT: the party slot to store. + size_t party_slot = 0; + // DEPOSIT: the box to store it in. WITHDRAW: the box to take from, + // which must be the box the PC shows (the last one viewed). + size_t box = 0; + // WITHDRAW: the box slot, row by row, six to a row. + size_t box_slot = 0; + PcMissing if_missing = PcMissing::REFUSE; +}; + +// The GAME action of a PC step, slots and boxes counted from 1 as the game +// shows them: do WORD (required), "deposit" or "withdraw"; slot INTEGER +// (required), the party slot (1-6) of a deposit or the box slot (1-30) +// of a withdrawal; box INTEGER (required, 1-14); if_present BOOLEAN +// (false): a deposit skipped when the party hasn't got the slot. +inline const std::string PC_ACTION = "pc"; +// `transfer` as its action's args. +Pokemon::StoryActionArgs pc_args(const PcTransfer& transfer); +// The transfer a PC_ACTION step's args give; nothing if they name a slot +// or box the game hasn't got. +std::optional pc_transfer_of(const Pokemon::StoryActionArgs& args); + + +// A party member as far as a PC step needs to know. +struct PcPartyMember{ + // Its species' slug, or empty if not read. + std::string species = {}; + bool fainted = false; +}; + +// Why `transfer` can't be done with `party`, or empty if it can: a +// deposit of a slot the party hasn't got, of its last Pokemon, or of its +// last one that can fight; a withdrawal into a full party. +std::string pc_transfer_error(const PcTransfer& transfer, const std::vector& party); + + +// A controller action taken during a PC dialog sequence. +enum class PcPress{ + A, + B, + UP, + DOWN, + LEFT, + RIGHT, + // Nothing: look again. + WAIT, + // The transfer is made and the overworld is back. + DONE, + FAIL, +}; +// The human-readable name of a PC controller action. +const char* pc_press_name(PcPress press); + +// The next action decided by the PC dialog state machine. +struct PcDecision{ + PcPress press = PcPress::WAIT; + // FAIL: why. + std::string reason = {}; +}; + +// What the PC step presses on each screen it reads, from the overworld +// facing the PC to the overworld again with the transfer made. +class PcStorageDialog{ +public: + explicit PcStorageDialog(const PcTransfer& transfer); + + PcDecision next(const PcView& view); + + // Whether the transfer was made: the last press that makes it was sent. + bool transferred() const{ + return m_transferred; + } + +private: + PcDecision on_overworld(); + PcDecision on_storage_menu(const PcView& view); + PcDecision on_party_panel(const PcView& view); + PcDecision on_box_grid(const PcView& view); + PcDecision on_mon_menu(const PcView& view); + PcDecision on_box_chooser(const PcView& view); + + PcTransfer m_transfer; + bool m_booted = false; + // The overworld read since A at the PC, while the PC boots. + size_t m_booting_reads = 0; + bool m_transferred = false; + // BOX_CHOOSER opens on BOX 1 each time the PC is entered. + bool m_chooser_seen = false; + size_t m_others_in_a_row = 0; +}; + + +// The game steps a PC step takes, injected so its decisions run in tests. +class PcStorageActions{ +public: + virtual ~PcStorageActions() = default; + + // From the overworld: the party, read from the party menu, which is + // closed again. + virtual std::vector read_party() = 0; + // What shows now. + virtual PcView read_view() = 0; + // One press (A, B or the D-pad), and the wait for the screen to answer. + virtual void press(PcPress press) = 0; +}; + +// How a PC transfer sequence concluded. +enum class PcEnd{ + DONE, + // A DEPOSIT with PcMissing::SKIP whose slot the party hasn't got: the + // PC wasn't touched. + SKIPPED, + // pc_transfer_error() refused it before the PC was touched. + REFUSED, + FAILED, +}; +// The result of a PC transfer operation. +struct PcResult{ + PcEnd end = PcEnd::FAILED; + std::string detail = {}; +}; + +// Reads after this many presses without the overworld back: a failure. +constexpr size_t PC_MAX_PRESSES = 80; +// OTHER read this many times in a row: a failure. +constexpr size_t PC_MAX_OTHER_IN_A_ROW = 10; +// The overworld read this many times after A at the PC: it didn't boot. +constexpr size_t PC_BOOT_READS = 4; + +// From the overworld, facing the PC: the transfer, back to the overworld. +PcResult run_pc_transfer(Logger& logger, PcStorageActions& actions, const PcTransfer& transfer); + + +// From the overworld: the party's size, read from the party menu, which is +// closed again. +size_t read_party_size(ConsoleHandle& console, ProControllerContext& context); + +// The console's PC steps. Party members are read by count only: none is +// taken as fainted, since the story heals before it uses the PC. Screens +// are read with read_pc_screen(); the overworld only once a second frame, +// a moment later, shows it too, since a frame between two menus can look +// like it. +class ConsolePcStorageActions : public PcStorageActions{ +public: + ConsolePcStorageActions(ConsoleHandle& console, ProControllerContext& context); + + virtual std::vector read_party() override; + virtual PcView read_view() override; + virtual void press(PcPress press) override; + +private: + ConsoleHandle& m_console; + ProControllerContext& m_context; +}; + + +// Register auto-story PC storage unit tests. +void add_tests_AutoStoryPcStorage(UnitTestDatabase& database); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage_Tests.cpp index c3af11e750..926a5a78d1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage_Tests.cpp @@ -516,32 +516,37 @@ UnitTestResult test_pc_dialog_screens(){ } -// The table's variant, both ways, and the variants it refuses. -UnitTestResult test_pc_variant(){ +// The step's args, both ways, and the args it refuses. +UnitTestResult test_pc_args(){ const std::vector transfers = { {.action = PcAction::DEPOSIT, .party_slot = 1, .box = 0}, {.action = PcAction::WITHDRAW, .box = 13, .box_slot = 29}, {.action = PcAction::DEPOSIT, .party_slot = 1, .box = 0, .if_missing = PcMissing::SKIP}, }; - for (const PcTransfer& transfer : transfers){ - const std::string variant = pc_variant(transfer); - const std::optional back = parse_pc_variant(variant); + for (size_t c = 0; c < transfers.size(); c++){ + const PcTransfer& transfer = transfers[c]; + const std::optional back = pc_transfer_of(pc_args(transfer)); if (!back || back->action != transfer.action || back->box != transfer.box || back->party_slot != transfer.party_slot || back->box_slot != transfer.box_slot || back->if_missing != transfer.if_missing ){ - return "\"" + variant + "\" didn't read back as the transfer it was made from."; + return std::format("Transfer {} didn't read back from its args.", c + 1); } } - if (pc_variant(transfers[0]) != "pc deposit slot=2 box=1"){ - return "Expected \"pc deposit slot=2 box=1\", got \"" + pc_variant(transfers[0]) + "\"."; - } - for (std::string_view bad : { - "pc", "pc deposit", "pc deposit slot=7 box=1", "pc deposit slot=0 box=1", "pc deposit slot=2 box=15", - "pc withdraw box=1 slot=31", "pc release slot=1 box=1", "pc deposit box=1 slot=2", "capture rattata", - }){ - if (parse_pc_variant(bad)){ - return "Expected \"" + std::string(bad) + "\" refused."; + const auto args = [](std::string action, int64_t slot, int64_t box){ + return Pokemon::StoryActionArgs{{"do", std::move(action)}, {"slot", slot}, {"box", box}}; + }; + const std::vector bad_args{ + {}, + args("deposit", 7, 1), + args("deposit", 0, 1), + args("deposit", 2, 15), + args("withdraw", 31, 1), + args("release", 1, 1), + }; + for (const Pokemon::StoryActionArgs& bad : bad_args){ + if (pc_transfer_of(bad)){ + return "Expected a missing or out-of-range arg refused."; } } return true; @@ -560,7 +565,7 @@ const AutoStoryPcStorageCase AUTO_STORY_PC_STORAGE_CASES[] = { .expectation = {}, }, { - .input = {"the table's variant", test_pc_variant}, + .input = {"the step's args", test_pc_args}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp index 4ecb06c609..1b810ac2cd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp @@ -160,7 +160,7 @@ StoryRunPlan rows_after_gift_rng( throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No checkpoint after the Magikarp salesman."); } const StoryCheckpoint& row = checkpoints[salesman_row + 1]; - if (row.steps.empty() || row.steps.front().variant != LEAVE_GIFT_SUMMARY){ + if (row.steps.empty() || row.steps.front().action != LEAVE_GIFT_SUMMARY){ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, row.id + " doesn't start by leaving the gift's summary."); } StoryRunPlan plan; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp index ce3ab7c091..a7839aff1d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp @@ -199,7 +199,7 @@ UnitTestResult test_rows_after_magikarp(){ const size_t salesman_row = row_index("00.12"); const StoryCheckpoint& salesman = checkpoints[salesman_row]; const StoryCheckpoint& after = checkpoints[salesman_row + 1]; - const std::optional start = after.start ? story_pose(*after.start) : std::nullopt; + const std::optional start = after.start ? story_pose(Pokemon::pose_of(*after.start)) : std::nullopt; if (salesman.handoff != StoryHandoff::GIFT_RNG || !after.live_start || !start || start->map != "Route4_PokemonCenter_1F" || !(start->tile == TilePos{2, 3}) || start->facing != Direction::WEST ){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp index ef4a62c4c8..99ac6fa2f4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp @@ -294,13 +294,13 @@ UnitTestResult test_starter_rows_joined(){ return "Expected 00.04 \"Squirtle, then the rival's battle\": " + expected_steps + "; got " + row.id + " \"" + row.title + "\": " + step_names(row); } - const std::optional start = story_pose(*row.start); + const std::optional start = story_pose(Pokemon::pose_of(*row.start)); if (!start || start->map != "PalletTown_ProfessorOaksLab" || !(start->tile == TilePos{6, 4}) || row.menu != StartMenu::BEFORE_POKEDEX){ return "Expected the joined 00.04 to start at the table (6, 4) and save with the starter's START menu."; } // Split, 00.04 saves under the ball facing it, before the starter. const StoryCheckpoint& to_ball = checkpoints[row_index("00.04")]; - const std::optional ball = story_pose(*checkpoints[row_index("00.04b")].start); + const std::optional ball = story_pose(Pokemon::pose_of(*checkpoints[row_index("00.04b")].start)); if (to_ball.handoff != StoryHandoff::STARTER_RNG || to_ball.menu != StartMenu::BEFORE_POKEMON || !ball || !(ball->tile == TilePos{9, 5}) || ball->facing != Direction::NORTH ){ 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 fd05a4ef78..9918e23313 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,49 +141,67 @@ 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: + case StoryStepKind::GAME: + 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(); } - virtual Outcome game(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); } @@ -187,21 +213,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 @@ -235,9 +260,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 : rows){ @@ -245,7 +268,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; }, }); @@ -336,13 +359,13 @@ UnitTestResult test_whole_story(){ // Each checkpoint starts where the save before it stands. for (size_t c = 1; c < sim.rows.size(); c++){ const StoryCheckpoint& data = sim.rows[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..1b81f7f627 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -5,6 +5,15 @@ */ #include "Common/Cpp/Exceptions.h" +#include "PokemonFRLG_AutoStoryCapture.h" +#include "PokemonFRLG_AutoStoryChoice.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryGameArgs.h" +#include "PokemonFRLG_AutoStoryGrind.h" +#include "PokemonFRLG_AutoStoryMart.h" +#include "PokemonFRLG_AutoStoryMember.h" +#include "PokemonFRLG_AutoStoryPcStorage.h" +#include "PokemonFRLG_AutoStoryTeach.h" #include "PokemonFRLG_AutoStoryStepTable.h" namespace PokemonAutomation{ @@ -52,10 +61,119 @@ const std::vector& story_action_rows(){ return ROWS; } +namespace{ + +using Pokemon::StoryArgType; +using Pokemon::Direction; + +// PC_ACTION's args (pc_args()). +Pokemon::StoryActionSpec pc_action_spec(){ + return {.kind = StoryStepKind::GAME, .name = PC_ACTION, .args = { + required_arg("do", StoryArgType::WORD, "\"deposit\" or \"withdraw\""), + required_arg("slot", StoryArgType::INTEGER, "the party slot to deposit, or the box slot to withdraw, from 1"), + required_arg("box", StoryArgType::INTEGER, "the box, from 1; a withdrawal's must be the one the PC shows"), + optional_arg("if_present", StoryArgType::BOOLEAN, false, "skip a deposit when the party hasn't got the slot"), + }}; +} + +Pokemon::StoryActionSpec capture_action_spec(){ + return {.kind = StoryStepKind::GAME, .name = CAPTURE_ACTION, .args = { + required_arg("species", StoryArgType::WORD, "the species' slug, e.g. \"rattata\""), + optional_arg("catches", StoryArgType::INTEGER, int64_t(1), "how many to catch"), + optional_arg("encounters", StoryArgType::INTEGER, int64_t(20), "wild battles before the step gives up"), + optional_arg("balls", StoryArgType::INTEGER, int64_t(5), "Poke Balls thrown before the step gives up"), + optional_arg("pace", StoryArgType::DIRECTION, Direction::EAST, "the way the player steps to look for a battle"), + absent_arg("move", StoryArgType::INTEGER, "the FIGHT list's move that weakens the target, from 1; none: only balls"), + optional_arg("turns", StoryArgType::INTEGER, int64_t(2), "the most turns spent weakening each target"), + }}; +} + +Pokemon::StoryActionSpec fossil_action_spec(){ + return {.kind = StoryStepKind::GAME, .name = FOSSIL_ACTION, .args = { + required_arg("fossil", Pokemon::StoryArgType::WORD, "\"helix\" or \"dome\""), + }}; +} + +Pokemon::StoryActionSpec level_action_spec(){ + return {.kind = StoryStepKind::GAME, .name = LEVEL_ACTION, .args = { + required_arg("slot", StoryArgType::INTEGER, "the party slot, from 1"), + required_arg("min", StoryArgType::INTEGER, "the level it must have"), + }}; +} + +Pokemon::StoryActionSpec mart_action_spec(){ + return {.kind = StoryStepKind::GAME, .name = MART_ACTION, .args = { + required_arg("map", StoryArgType::WORD, "the Mart's map, for its stock"), + required_arg("budget", StoryArgType::INTEGER, "the most the step spends"), + absent_arg("floor", StoryArgType::INTEGER, "the least money the player has here, when the money box can't be read"), + required_arg("items", StoryArgType::ITEMS, "what to buy, in priority order"), + }}; +} + +Pokemon::StoryActionSpec teach_action_spec(){ + return {.kind = StoryStepKind::GAME, .name = TEACH_ACTION, .args = { + required_arg("item", StoryArgType::WORD, "the TM or HM, e.g. \"hm03\""), + required_arg("move", StoryArgType::WORD, "the move it holds, e.g. \"surf\""), + required_arg("slot", StoryArgType::INTEGER, "the party slot, from 1"), + absent_arg("forget", StoryArgType::WORD, "the move to forget when it knows four"), + absent_arg("forget_slot", StoryArgType::INTEGER, "the move slot to forget, from 1, when no move is named"), + }}; +} + +Pokemon::StoryActionSpec grind_action_spec(){ + return {.kind = StoryStepKind::GAME, .name = GRIND_ACTION, .args = { + required_arg("slot", StoryArgType::INTEGER, "the party slot that grinds, from 1"), + required_arg("level", StoryArgType::INTEGER, "the level to reach; with a trainer, the cap"), + optional_arg("encounters", StoryArgType::INTEGER, int64_t(60), "wild battles before the step gives up"), + optional_arg("pace", StoryArgType::DIRECTION, Direction::EAST, "the way the player steps to look for a battle"), + optional_arg("heal_every", StoryArgType::INTEGER, int64_t(0), "battles between visits to the nurse; 0: only when hurt"), + absent_arg("beat", StoryArgType::WORD, "the next boss's trainer: grind until the sim's win chance is enough"), + absent_arg("chance", StoryArgType::INTEGER, "the win chance against it, in percent"), + required_arg("nurse", StoryArgType::GRID_POSE, "where the step heals"), + }}; +} + +} // namespace + +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)); + } + specs.push_back({.kind = StoryStepKind::GAME, .name = CLOSE_TRAINER_CARD, .args = {}}); + specs.push_back({.kind = StoryStepKind::GAME, .name = LEAVE_GIFT_SUMMARY, .args = {}}); + for (Pokemon::StoryActionSpec spec : { + pc_action_spec(), capture_action_spec(), fossil_action_spec(), level_action_spec(), + mart_action_spec(), teach_action_spec(), grind_action_spec(), + }){ + specs.push_back(std::move(spec)); + } + 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)); + } + // FRLG's own GAME actions: the GAME row's action, with each one's args. + for (const Pokemon::StoryActionSpec& spec : story_action_specs()){ + if (spec.kind != StoryStepKind::GAME || spec.name.empty()){ + continue; + } + Pokemon::StoryAction action = bind(StoryActionId::GAME); + action.args = spec.args; + table.add(StoryStepKind::GAME, spec.name, 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..64da00d347 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,20 @@ 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, +// then FRLG's GAME actions: closing the Trainer Card or the Gift RNG +// summary, a PC transfer, a capture, the fossil, a LEVEL check, a Mart, +// a TEACH and a GRIND, each with the args it declares. +// 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, and each of FRLG's GAME actions with the GAME row's action +// and its own 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 10061d6ce8..666fd4e56c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -4,9 +4,14 @@ * */ -#include "PokemonFRLG_AutoStoryCapture.h" -#include "PokemonFRLG_AutoStoryChoice.h" -#include "PokemonFRLG_AutoStoryPcStorage.h" +#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{ @@ -16,466 +21,159 @@ 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"; -const char* const ROUTE3 = "Route3"; -const char* const ROUTE4 = "Route4"; -const char* const ROUTE4_CENTER = "Route4_PokemonCenter_1F"; -const char* const MT_MOON_1F = "MtMoon_1F"; -const char* const MT_MOON_B2F = "MtMoon_B2F"; - -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)); +} + +// The wire names of the handoffs. +StoryHandoff read_handoff(std::string_view name, std::string_view source){ + if (name == "sid_helper"){ + return StoryHandoff::SID_HELPER; + } + if (name == "starter_rng"){ + return StoryHandoff::STARTER_RNG; + } + if (name == "gift_rng"){ + return StoryHandoff::GIFT_RNG; + } + throw ParseException(std::format("{}: unknown handoff {}", 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. -// Indoors, where the game doesn't let the player run, it walks. -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; -} - -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; -} - - -StoryStep game_step(std::string variant, Pokemon::Pose pose_after, std::string why){ - StoryStep step = make(StoryStepKind::GAME, variant, std::move(why)); - step.variant = std::move(variant); - 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"), - }); +// 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; +} + +// The file without its "metadata", which the shared reader doesn't take +// (yet): {"phase": testing, verification or reproduction}, how far the +// checkpoint is trusted to save (the engine's save policy reads it). +JsonValue without_metadata(const JsonValue& value, std::string_view source){ + JsonObject stripped; + for (const auto& [key, field] : value.to_object_throw(std::string(source))){ + if (key != "metadata"){ + stripped[key] = field.clone(); + continue; + } + const JsonObject& metadata = field.to_object_throw(std::string(source)); + for (const auto& [metadata_key, unused] : metadata){ + if (metadata_key != "phase"){ + throw ParseException(std::format("{}: unsupported metadata field {}", source, metadata_key)); + } + } + const std::string& phase = metadata.get_string_throw("phase", std::string(source)); + if (phase != "testing" && phase != "verification" && phase != "reproduction"){ + throw ParseException(std::format("{}: unknown phase {}", source, phase)); + } + } + return JsonValue(std::move(stripped)); } -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"), - // Where the by-hand walk stopped to start 00.11 (console B, 2026-11-02). - route("below_pewter_center", at(PEWTER, 17, 26, SOUTH), "west along row 21 and down to below the Pokemon Center's door (17, 25)"), - }); -} - -// Route 3's trainers (Route3 map.json): the way east meets three of them. -// Bug Catcher Colton (12, 6) faces east, sight 3: the only way north past -// the row 7 ledges is the gap at x 14..15, below his line. Youngster Ben -// (17, 4) faces south, sight 2, so the way east keeps to row 3 past him. -// Bug Catcher Greg (25, 4) faces south, sight 2, over the way east along -// row 5. Bug Catcher James (32, 6) faces east, sight 4, over the way down -// at x 35..36. The others are kept out of: Lass Janice (19, 9) sees west -// along row 9 to x 14, Lass Sally (30, 3) west along row 3 to x 25, and -// Youngster Calvin (29, 10) west along row 10. Each line is stepped into on -// its own, so no leg is cut; the trainer walks up to the player, who stays -// put facing the way they stepped. -StoryCheckpoint route3(){ - return row("00.11", "Pewter Center, then Route 3's trainers", at(PEWTER, 17, 26, SOUTH), after_brock(), StartMenu::FULL, { - running(route("pewter_nurse", at(PEWTER_CENTER, 7, 4, NORTH), "in by the door below the player")), - heal("heal_pewter"), - // Up from row 9 west of Janice's line, which ends at x 14. - running(route("west_of_janice_line", at(ROUTE3, 13, 8), "out of Pewter by row 21, east into Route 3, short of Janice's line")), - running(legs("below_colton_line", {{EAST, 1}, {NORTH, 1}}, "to (14, 7), in the ledges' gap")), - step_into("colton_line", NORTH, "onto (14, 6), in Colton's line"), - battle("bug_catcher_colton", at(ROUTE3, 14, 6, NORTH), false, "his Bug Pokemon; Colton stops at (13, 6)"), - running(legs("past_ben", {{NORTH, 3}, {EAST, 4}, {SOUTH, 2}, {EAST, 6}}, "up to row 3 above Ben, down at x 18 east of his line, to (24, 5)")), - step_into("greg_line", EAST, "onto (25, 5), below Greg"), - battle("bug_catcher_greg", at(ROUTE3, 25, 5, EAST), false, "his Bug Pokemon; Greg is already next to the player"), - running(legs("above_james_line", {{EAST, 11}}, "along row 5 to the wall at (36, 5)")), - step_into("james_line", SOUTH, "onto (36, 6), at the end of James's line"), - battle("bug_catcher_james", at(ROUTE3, 36, 6, SOUTH), false, "his Bug Pokemon; James stops at (35, 6)"), - // Saved here, the trainers behind, so a failure on the way to Route 4 - // doesn't fight them again. - running(legs("save_spot", {{SOUTH, 2}}, "down to (36, 8), beside the wall east of it")), - }); -} +} // namespace -// Route 3's north exit (x 68..75) joins Route 4 (offset 60) at x 8..15, up -// which column 12 leads to the Pokemon Center's door (12, 5). Lass Robin -// (40, 11) wanders up and down at x 40, looking north and south, sight 3. -// Rock above (y <= 8) and grass below (y >= 12) leave every way east -// across her column at y 9..11, so whether she sees the player depends on -// her facing. The walk watches for her after the leg along row 9, which -// crosses her sight on (40, 9) only; if she saw the player, her message -// goes to story_interrupts(), which fight her, and the route goes on from -// (40, 9) (run_route(); console B, 2026-11-02, she stopped the player -// there and spoke after the leg's short watch). -StoryCheckpoint magikarp_salesman(){ - StoryCheckpoint checkpoint = row("00.12", "Route 3 and 4 to the Magikarp salesman", at(ROUTE3, 36, 8, SOUTH), after_brock(), StartMenu::FULL, { - running(route("route4_nurse", at(ROUTE4_CENTER, 7, 4, NORTH), "east over Route 3, off the grass, north into Route 4 and its Pokemon Center")), - heal("heal_route4"), - // Gift RNG starts from a save facing the salesman (1, 3). - running(route("before_salesman", at(ROUTE4_CENTER, 2, 3, WEST), "beside the Magikarp salesman, facing him")), - }); - checkpoint.handoff = StoryHandoff::GIFT_RNG; - return checkpoint; -} -// Gift RNG buys the Magikarp (500 of the money 00.12 brings) without -// moving the player and leaves its summary open, or HOME. This saves the -// shiny where 00.12 ended. A run started here with Gift RNG's handoff on -// loads the save beside the salesman and runs Gift RNG first. -StoryCheckpoint after_gift_rng(){ - StoryCheckpoint checkpoint = row("00.12b", "after Gift RNG: save with the Magikarp", at(ROUTE4_CENTER, 2, 3, WEST), after_brock(), StartMenu::FULL, { - game_step(LEAVE_GIFT_SUMMARY, at(ROUTE4_CENTER, 2, 3, WEST), "the Magikarp's summary Gift RNG left open, or HOME"), - }); - checkpoint.live_start = true; +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", "handoff", "live_start", "notes"}, where); + checkpoint.menu = read_start_menu(execution.get_string_throw("menu", std::string(where)), where); + checkpoint.supplies = read_supplies(execution, where); + if (execution.get_value("handoff") != nullptr){ + checkpoint.handoff = read_handoff(execution.get_string_throw("handoff", std::string(where)), where); + } + if (execution.get_value("live_start") != nullptr){ + checkpoint.live_start = execution.get_boolean_throw("live_start", std::string(where)); + } + note_keys = read_note_keys(execution, where); + }; + static_cast(checkpoint) = Pokemon::read_authored_checkpoint( + without_metadata(value, source), "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; } -// The Magikarp goes to BOX 1 at the Center's PC (11, 1), so Mt. Moon is -// fought with the starter alone (console B, 2026-11-02: done by hand and -// saved at (11, 2), facing the PC, where this row ends). The wandering -// boy (4..6, 3..5) is walked around. The Magikarp comes from Gift RNG: -// with Gift RNG off the party is the starter alone, and the deposit is -// skipped. -StoryCheckpoint magikarp_to_box(){ - return row("00.12c", "Route 4 Center: the Magikarp into BOX 1", at(ROUTE4_CENTER, 2, 3, WEST), after_brock(), StartMenu::FULL, { - running(route("pc_front", at(ROUTE4_CENTER, 11, 2, NORTH), "below the PC (11, 1), facing it")), - pc_step("magikarp_to_box", "DEPOSIT the party's second slot into BOX 1, if it has one", PcTransfer{ - .action = PcAction::DEPOSIT, .party_slot = 1, .box = 0, .if_missing = PcMissing::SKIP, - }), - }); -} - -// Mt. Moon (pokefirered data/maps/MtMoon_1F, _B1F, _B2F). Every floor tile -// of the cave has wild encounters, which are run from, so its legs end on -// walls, ladders or someone standing still, which the walker holds again -// after a battle; the few open ones are short. The way through: up 1F's -// middle and west side, its north-west ladder, B1F's west ladder down to -// B2F's south-east, round B2F's south edge to its west, north past -// Miguel and the fossils, and the ladder up to B1F's east end, which -// leads out to Route 4 east of the mountain. -// - 1F's trainers are walked around: Youngster Josh (13, 17) sees east -// along row 17 to x 17, so the way west into the west room is down -// column 18 and up column 11; Lass Miriam walks round (32..33, 4..5), -// sight 2, so the way east keeps to row 9 and columns 38 and 40; Hiker -// Marcos wanders (5..9, 8..12) and sees one tile, so the way north is -// column 11 and row 3. -// - The Moon Stone ball (3, 2) on 1F (FLAG_HIDE_MT_MOON_1F_MOON_STONE) is -// a few tiles off the way to the ladder (5, 6). -// - The Grunt at (37, 21) on B2F looks around (sight 3) over the only way -// east round B2F. His room is crossed on legs to walls, at one tile of -// his sight each, (37, 22) and (40, 21); if he looks the player's way, -// he walks up beside the leg, story_interrupts() fights him, and the -// leg is held on to its wall. -// - The Grunt at (12, 20) faces south (sight 2) over (12, 21..22), across -// rows 21..22, the only way north to Miguel: stepped into from the -// west, he is next to the player and doesn't walk. -// - Super Nerd Miguel (13, 11) battles on the step onto (14, 11) -// (MtMoon_B2F_EventScript_MiguelTrigger, VAR_MAP_SCENE_MT_MOON_B2F 0), -// then "We'll each take one!" -// - The fossils: DOME (13, 7), HELIX (14, 7). After the HELIX, Miguel -// walks up to (13, 8) and takes the DOME, which opens the gap north. -// The save is on Route 4: the save card's places don't include Mt. Moon. -StoryCheckpoint mt_moon(){ - return row("00.13", "Mt. Moon: a Moon Stone, a Rocket, Miguel and the Helix Fossil", at(ROUTE4_CENTER, 11, 2, NORTH), after_brock(), StartMenu::FULL, { - running(route("route4_nurse", at(ROUTE4_CENTER, 7, 4, NORTH), "the nurse, below the counter")), - heal("heal_route4"), - running(route("mt_moon_entrance", at(MT_MOON_1F, 18, 37, NORTH), "out of the Center, west into Mt. Moon")), - running(legs("mt_moon_1f", { - {NORTH, 12}, {EAST, 8}, {NORTH, 12}, {EAST, 3}, {SOUTH, 1}, {EAST, 9}, - {NORTH, 1}, {EAST, 2}, {NORTH, 4}, {WEST, 24}, {EAST, 2}, {SOUTH, 12}, - {WEST, 7}, {NORTH, 18}, {WEST, 9}, {EAST, 1}, - }, "up the middle, east of Miriam, west along row 9, down column 18 past Josh, up column 11 past Marcos, to (3, 3)")), - running(route("below_moon_stone", at(MT_MOON_1F, 3, 3, NORTH), "facing the Moon Stone (3, 2)")), - talk("moon_stone_ball", "A on the item ball"), - // No reader for the text yet: the scene's end is the overworld. - scene("found_moon_stone", at(MT_MOON_1F, 3, 3, NORTH), "\" found a MOON STONE!\", then the pocket line; the ball is gone"), - running(route("b2f_ladder_foot", at(MT_MOON_B2F, 26, 21, EAST), "1F's ladder (5, 6), down B1F's west side to its ladder (22, 18), onto B2F")), - running(legs("b2f_south", { - {NORTH, 4}, {EAST, 8}, {WEST, 2}, {SOUTH, 5}, {EAST, 8}, {NORTH, 3}, {WEST, 1}, {NORTH, 5}, - {EAST, 7}, {SOUTH, 14}, {WEST, 9}, {SOUTH, 10}, {WEST, 29}, {EAST, 3}, {NORTH, 17}, - }, "through the Grunt's room at (37, 21), round the south edge, up column 11 to (11, 21)")), - step_into("grunt_line", EAST, "onto (12, 21), below the Grunt at (12, 20)"), - battle("rocket_grunt", at(MT_MOON_B2F, 12, 21, EAST), false, "Rattata and Zubat, Lv13"), - ready("ready_for_miguel", at(ROUTE4_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse, back through the cave, only if they can't"), - // Up column 13 to Miguel, who stops the leg on (13, 12), then east - // to the wall: the tile below his trigger. - running(legs("below_miguel_trigger", {{EAST, 1}, {NORTH, 9}, {EAST, 1}}, "to (14, 12), below Miguel's trigger (14, 11)")), - step_into("miguel_trigger", NORTH, "onto (14, 11), beside Miguel"), - battle("super_nerd_miguel", at(MT_MOON_B2F, 14, 11, NORTH), false, "Grimer, Voltorb and Koffing, Lv12; \"We'll each take one!\""), - running(legs("below_helix_fossil", {{NORTH, 3}}, "up column 14 to the HELIX FOSSIL (14, 7)")), - fossil_step("helix_fossil", "the HELIX FOSSIL; Miguel takes the DOME FOSSIL", Fossil::HELIX), - // The maps keep the fossils, which the game removes after the - // choice: the step onto the HELIX's tile is taken on its own. - step_into("helix_gap", NORTH, "onto (14, 7), where the HELIX FOSSIL lay"), - running(route("route4_east", at(ROUTE4, 32, 6, SOUTH), "west to B2F's ladder (5, 10), up to B1F, east to its exit onto Route 4")), - }); -} - -} // namespace - - const std::vector& story_checkpoints(){ - static const std::vector checkpoints{ - new_game(), after_sid_helper(), leave_house(), oaks_trigger(), to_starter_ball(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), - running_shoes(), route3(), magikarp_salesman(), after_gift_rng(), magikarp_to_box(), mt_moon(), - }; + 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 0ae3197e32..e9dcead69c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -8,12 +8,38 @@ * saved at its end. After 00.10 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()); + * "handoff" optional: sid_helper, starter_rng or gift_rng, the RNG program + * the user may run there (StoryCheckpoint::handoff); + * "live_start" optional, true: it starts from the game as another + * program left it (StoryCheckpoint::live_start); + * "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. + * + * Beside "execution", "metadata": {"phase": testing, verification or + * reproduction}: how far the checkpoint is trusted. + * */ #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" @@ -22,10 +48,20 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Checkpoints 00.01 to 00.13, in order, with 00.01b, the way back in after -// SID Helper, after 00.01, 00.04 split in two at Squirtle's ball for -// Starter RNG: 00.04 and 00.04b, 00.12b, the way back in after Gift RNG, -// after 00.12, and 00.12c, the Magikarp put in BOX 1, after it. +// (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.13, in order: every file in StoryData/. With +// 00.01b, the way back in after SID Helper, after 00.01, 00.04 split in +// two at Squirtle's ball for Starter RNG: 00.04 and 00.04b, 00.12b, the +// way back in after Gift RNG, after 00.12, and 00.12c, the Magikarp put +// in BOX 1, after it. const std::vector& story_checkpoints(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp index ef65bbc2ae..f6c7a961df 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp @@ -6,8 +6,8 @@ #include #include +#include "PokemonFRLG_AutoStoryGameArgs.h" #include "PokemonFRLG_AutoStoryTeach.h" -#include "PokemonFRLG_AutoStoryVariantWords.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -37,64 +37,46 @@ const char* teach_end_name(TeachEnd end){ } -std::string teach_variant(const TeachPlan& plan){ - std::string variant = std::format("{}{} {} slot={}", TEACH_VARIANT_PREFIX, plan.item, plan.move, plan.member + 1); - if (!plan.forget_move.empty()){ - variant += " forget=" + plan.forget_move; - }else if (plan.forget_slot){ - variant += std::format(" forget_slot={}", *plan.forget_slot + 1); - } - return variant; -} - namespace{ bool is_tm_or_hm(std::string_view item){ return item.size() == 4 && (item.starts_with("tm") || item.starts_with("hm")) - && variant_number(item.substr(2), 2).has_value(); -} - -bool set_teach_word(TeachPlan& plan, std::string_view word){ - const std::optional pair = variant_pair(word); - if (!pair){ - return false; - } - if (pair->key == "forget" && !pair->value.empty()){ - plan.forget_move = std::string(pair->value); - return true; - } - const std::optional number = variant_number(pair->value, 1); - if (pair->key == "slot" && number && *number >= 1 && *number <= PARTY_SLOTS){ - plan.member = *number - 1; - return true; - } - if (pair->key == "forget_slot" && number && *number >= 1 && *number <= MOVE_SLOTS){ - plan.forget_slot = *number - 1; - return true; - } - return false; + && item[2] >= '0' && item[2] <= '9' && item[3] >= '0' && item[3] <= '9'; } } // namespace -std::optional parse_teach_variant(std::string_view variant){ - if (!variant.starts_with(TEACH_VARIANT_PREFIX)){ - return std::nullopt; +Pokemon::StoryActionArgs teach_args(const TeachPlan& plan){ + Pokemon::StoryActionArgs args{ + {"item", plan.item}, {"move", plan.move}, {"slot", int64_t(plan.member + 1)}, + }; + if (!plan.forget_move.empty()){ + args.emplace("forget", plan.forget_move); + }else if (plan.forget_slot){ + args.emplace("forget_slot", int64_t(*plan.forget_slot + 1)); } - const std::vector words = variant_words(variant.substr(TEACH_VARIANT_PREFIX.size())); - if (words.size() < 3 || !is_tm_or_hm(words[0]) || variant_pair(words[1])){ + return args; +} + +std::optional teach_plan_of(const Pokemon::StoryActionArgs& args){ + const std::string* item = game_arg(args, "item"); + const std::string* move = game_arg(args, "move"); + const std::optional member = counted_arg(args, "slot", PARTY_SLOTS); + if (item == nullptr || !is_tm_or_hm(*item) || move == nullptr || move->empty() || !member){ return std::nullopt; } - TeachPlan plan{.item = std::string(words[0]), .move = std::string(words[1])}; - bool slot_seen = false; - for (size_t c = 2; c < words.size(); c++){ - if (!set_teach_word(plan, words[c])){ + TeachPlan plan{.item = *item, .move = *move, .member = *member}; + if (const std::string* forget = game_arg(args, "forget")){ + if (forget->empty()){ return std::nullopt; } - slot_seen |= words[c].starts_with("slot="); + plan.forget_move = *forget; } - if (!slot_seen){ - return std::nullopt; + if (args.contains("forget_slot")){ + plan.forget_slot = counted_arg(args, "forget_slot", MOVE_SLOTS); + if (!plan.forget_slot){ + return std::nullopt; + } } return plan; } @@ -104,7 +86,8 @@ Pokemon::StoryStep teach_step(std::string name, std::string why, const TeachPlan step.kind = Pokemon::StoryStepKind::GAME; step.name = std::move(name); step.why = std::move(why); - step.variant = teach_variant(plan); + step.action = TEACH_ACTION; + step.args = teach_args(plan); return step; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h index 4f83146223..1fbd319205 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h @@ -46,7 +46,8 @@ #include #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "Pokemon/AutoStory/Pokemon_StorySteps.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" #include "PokemonFRLG_AutoStoryMember.h" namespace PokemonAutomation{ @@ -71,14 +72,16 @@ struct TeachPlan{ // Whether `move` is an HM's, which the game won't let a Pokemon forget. bool is_hm_move(std::string_view move); -// The prefix of a GAME step's variant that names a TEACH step. -inline constexpr std::string_view TEACH_VARIANT_PREFIX = "teach "; - -// `plan` as a variant: "teach hm03 surf slot=1 forget=tail-whip" or -// "... forget_slot=2", slots counted from 1, no forget when it has room. -std::string teach_variant(const TeachPlan& plan); -// Parses a move teaching plan from a variant string. -std::optional parse_teach_variant(std::string_view variant); +// The GAME action of a TEACH step: item WORD (required), the TM or HM, +// e.g. "hm03"; move WORD (required), e.g. "surf"; slot INTEGER +// (required, from 1); forget WORD or forget_slot INTEGER (from 1) +// (optional): the move to forget when it knows four. +inline const std::string TEACH_ACTION = "teach"; +// `plan` as its action's args. +Pokemon::StoryActionArgs teach_args(const TeachPlan& plan); +// The plan a TEACH_ACTION step's args give; nothing if the item isn't a +// TM or HM or a slot is out of range. +std::optional teach_plan_of(const Pokemon::StoryActionArgs& args); // Constructs an auto-story step for teaching a TM or HM. Pokemon::StoryStep teach_step(std::string name, std::string why, const TeachPlan& plan); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach_Tests.cpp index def0427bf3..4e13fcedd9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach_Tests.cpp @@ -375,26 +375,30 @@ UnitTestResult test_tm_used_up(){ } -UnitTestResult test_teach_variant(){ +UnitTestResult test_teach_args(){ const TeachPlan plan{.item = "hm03", .move = "surf", .member = 0, .forget_move = "tail-whip"}; - const std::string variant = teach_variant(plan); - if (variant != "teach hm03 surf slot=1 forget=tail-whip"){ - return "Unexpected variant \"" + variant + "\"."; - } - const std::optional back = parse_teach_variant(variant); + const Pokemon::StoryActionArgs args = teach_args(plan); + const std::optional back = teach_plan_of(args); if (!back || back->item != "hm03" || back->move != "surf" || back->member != 0 || back->forget_move != "tail-whip"){ - return "\"" + variant + "\" didn't read back as its plan."; + return "The Surf plan didn't read back from its args."; } - const std::optional by_slot = parse_teach_variant("teach tm28 dig slot=2 forget_slot=4"); + const std::optional by_slot = teach_plan_of({ + {"item", std::string("tm28")}, {"move", std::string("dig")}, {"slot", int64_t(2)}, {"forget_slot", int64_t(4)}, + }); if (!by_slot || by_slot->member != 1 || by_slot->forget_slot != 3u){ - return "\"teach tm28 dig slot=2 forget_slot=4\" didn't read back."; + return "Dig into slot 2, forgetting move 4, didn't read back."; } - for (std::string_view bad : { - "teach", "teach hm03 surf", "teach potion surf slot=1", "teach hm03 surf slot=7", - "teach hm03 surf slot=1 forget_slot=5", "teach hm03 slot=1", "mart PewterCity_Mart potion=1", - }){ - if (parse_teach_variant(bad)){ - return "Expected \"" + std::string(bad) + "\" refused."; + const std::vector> bad_args{ + {"item", std::string("potion")}, + {"slot", int64_t(7)}, + {"forget_slot", int64_t(5)}, + {"move", std::string("")}, + }; + for (const auto& [key, value] : bad_args){ + Pokemon::StoryActionArgs bad = args; + bad[key] = value; + if (teach_plan_of(bad)){ + return "Expected a bad " + key + " refused."; } } return true; @@ -413,7 +417,7 @@ const AutoStoryTeachCase AUTO_STORY_TEACH_CASES[] = { .expectation = {}, }, { - .input = {"the table's variant", test_teach_variant}, + .input = {"the step's args", test_teach_args}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVariantWords.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVariantWords.cpp deleted file mode 100644 index 975658f892..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVariantWords.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* AutoStory Variant Words - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonFRLG_AutoStoryVariantWords.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -std::vector variant_words(std::string_view text){ - std::vector words; - while (!text.empty()){ - const size_t space = text.find(' '); - const std::string_view word = text.substr(0, space); - if (!word.empty()){ - words.push_back(word); - } - if (space == std::string_view::npos){ - break; - } - text.remove_prefix(space + 1); - } - return words; -} - -std::optional variant_pair(std::string_view word){ - const size_t equals = word.find('='); - if (equals == std::string_view::npos || equals == 0){ - return std::nullopt; - } - return VariantPair{word.substr(0, equals), word.substr(equals + 1)}; -} - -std::optional variant_number(std::string_view text, size_t max_digits){ - if (text.empty() || text.size() > max_digits){ - return std::nullopt; - } - size_t value = 0; - for (char c : text){ - if (c < '0' || c > '9'){ - return std::nullopt; - } - value = value * 10 + size_t(c - '0'); - } - return value; -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVariantWords.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVariantWords.h deleted file mode 100644 index 3618657a27..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVariantWords.h +++ /dev/null @@ -1,44 +0,0 @@ -/* AutoStory Variant Words - * - * From: https://github.com/PokemonAutomation/ - * - * Reading a GAME step's variant: words split on spaces, "key=value" - * pairs, and small numbers. The table writes variants such as - * "mart PewterCity_Mart budget=2000 potion=5"; the steps read them back. - * - */ - -#ifndef PokemonAutomation_PokemonFRLG_AutoStoryVariantWords_H -#define PokemonAutomation_PokemonFRLG_AutoStoryVariantWords_H - -#include -#include -#include -#include - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// `text`'s words, split on spaces, empty words dropped. -std::vector variant_words(std::string_view text); - -// A word "key=value" as its two halves; nothing without an '='. -struct VariantPair{ - std::string_view key; - std::string_view value; -}; -// Splits a variant word into a key-value pair separated by "=". -std::optional variant_pair(std::string_view word); - -// `text` as a number of up to `max_digits` decimal digits; nothing if it -// isn't one. -std::optional variant_number(std::string_view text, size_t max_digits = 6); - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif 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 0bcdec45e1..570d879d17 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -88,7 +88,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)); @@ -142,7 +143,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) + "."; } @@ -167,10 +168,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){ @@ -218,7 +216,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); @@ -412,11 +411,11 @@ std::vector legs_walked(const StoryPose& pose, const StoryStep& step) const MapPosition start{pose.map, pose.tile}; std::optional> route; if (step.kind == StoryStepKind::LEGS){ - route = fixed_route(story_maps(), start, step.legs); - }else if (step.target){ + route = fixed_route(story_maps(), start, Pokemon::story_arg>(step.args, "legs")); + }else if (step.args.contains("target")){ const MapData* map = find_map_named(pose.map); const std::optional facing = pose.facing ? pose.facing : map ? wall_beside(*map, pose.tile) : std::nullopt; - const StoryPose target = one_tile(*step.target); + const StoryPose target = one_tile(Pokemon::story_arg(step.args, "target")); route = plan_overworld_route(story_maps(), start, RouteGoal{{target.map, target.tile}, target.facing}, default_route_costs(), facing); } return route ? *route : std::vector{}; @@ -522,7 +521,8 @@ UnitTestResult advance(StoryPose& pose, const StoryStep& step){ return check_legs(pose, step); } 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); @@ -551,7 +551,7 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set(step.args, "direction")), beaten) : nullptr; if (trainer != nullptr && (c + 1 == checkpoint.steps.size() || checkpoint.steps[c + 1].kind != StoryStepKind::BATTLE)){ return where + "steps into a trainer's line with no battle after it."; } @@ -795,7 +795,7 @@ UnitTestResult test_magikarp_deposit_skippable(){ continue; } for (const StoryStep& step : checkpoint.steps){ - const std::optional transfer = parse_pc_variant(step.variant); + const std::optional transfer = step.action == PC_ACTION ? pc_transfer_of(step.args) : std::nullopt; if (transfer && transfer->party_slot == 1 && transfer->if_missing == PcMissing::SKIP){ return true; } 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..638b71fa29 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01.plan.json @@ -0,0 +1,30 @@ +{ + "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, the player's name (default if none is set), rival GREEN" + }, + { + "id": "options", + "kind": "options", + "why": "fast text; no switch prompt between a trainer's Pokemon" + } + ] + }, + "execution": { + "menu": "before_pokemon", + "handoff": "sid_helper", + "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.01b.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01b.plan.json new file mode 100644 index 0000000000..fba9b09f08 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.01b.plan.json @@ -0,0 +1,32 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.01b", + "title": "after SID Helper: close the Trainer Card, save in the bedroom", + "start": {"map": "PalletTown_PlayersHouse_2F", "tiles": [[6, 6]], "facing": "north"}, + "events": [ + { + "id": "close_trainer_card", + "kind": "game_action", + "action": "close_trainer_card", + "declared_after": {"map": "PalletTown_PlayersHouse_2F", "tiles": [[6, 6]], "facing": "north"}, + "why": "the Trainer Card SID Helper left open, or HOME" + }, + { + "id": "options", + "kind": "options", + "why": "fast text; no switch prompt between a trainer's Pokemon" + } + ] + }, + "execution": { + "menu": "before_pokemon", + "live_start": true, + "notes": { + "checkpoint": [ + "SID Helper confirms the name, finishes the intro and reads the Trainer Card from the START menu, without moving the player or saving." + ] + } + } +} 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..e56a583371 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04.plan.json @@ -0,0 +1,28 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.04", + "title": "to Squirtle's ball, south of the table", + "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)" + } + ] + }, + "execution": { + "menu": "before_pokemon", + "handoff": "starter_rng", + "notes": { + "checkpoint": [ + "Starter RNG starts from a save south of the table, facing the ball." + ] + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04b.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04b.plan.json new file mode 100644 index 0000000000..08af2bfd81 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.04b.plan.json @@ -0,0 +1,68 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.04b", + "title": "Squirtle, then the rival's battle", + "start": {"map": "PalletTown_ProfessorOaksLab", "tiles": [[9, 5]], "facing": "north"}, + "events": [ + { + "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..8687203adb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.10.plan.json @@ -0,0 +1,60 @@ +{ + "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" + }, + { + "id": "below_pewter_center", + "kind": "route", + "args": { + "target": {"map": "PewterCity", "tiles": [[17, 26]], "facing": "south"} + }, + "why": "west along row 21 and down to below the Pokemon Center's door (17, 25)" + } + ] + }, + "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)." + ], + "below_pewter_center": [ + "Where the by-hand walk stopped to start 00.11 (console B, 2026-11-02)." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.11.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.11.plan.json new file mode 100644 index 0000000000..ab4cbf00e3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.11.plan.json @@ -0,0 +1,128 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.11", + "title": "Pewter Center, then Route 3's trainers", + "start": {"map": "PewterCity", "tiles": [[17, 26]], "facing": "south"}, + "events": [ + { + "id": "pewter_nurse", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "PewterCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "in by the door below the player" + }, + { + "id": "heal_pewter", + "kind": "heal", + "why": "full HP" + }, + { + "id": "west_of_janice_line", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route3", "tiles": [[13, 8]]} + }, + "why": "out of Pewter by row 21, east into Route 3, short of Janice's line" + }, + { + "id": "below_colton_line", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "east", "tiles": 1}, {"direction": "north", "tiles": 1}] + }, + "why": "to (14, 7), in the ledges' gap" + }, + { + "id": "colton_line", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "onto (14, 6), in Colton's line" + }, + { + "id": "bug_catcher_colton", + "kind": "battle", + "declared_after": {"map": "Route3", "tiles": [[14, 6]], "facing": "north"}, + "why": "his Bug Pokemon; Colton stops at (13, 6)" + }, + { + "id": "past_ben", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 3}, {"direction": "east", "tiles": 4}, {"direction": "south", "tiles": 2}, {"direction": "east", "tiles": 6}] + }, + "why": "up to row 3 above Ben, down at x 18 east of his line, to (24, 5)" + }, + { + "id": "greg_line", + "kind": "step", + "args": { + "direction": "east" + }, + "why": "onto (25, 5), below Greg" + }, + { + "id": "bug_catcher_greg", + "kind": "battle", + "declared_after": {"map": "Route3", "tiles": [[25, 5]], "facing": "east"}, + "why": "his Bug Pokemon; Greg is already next to the player" + }, + { + "id": "above_james_line", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "east", "tiles": 11}] + }, + "why": "along row 5 to the wall at (36, 5)" + }, + { + "id": "james_line", + "kind": "step", + "args": { + "direction": "south" + }, + "why": "onto (36, 6), at the end of James's line" + }, + { + "id": "bug_catcher_james", + "kind": "battle", + "declared_after": {"map": "Route3", "tiles": [[36, 6]], "facing": "south"}, + "why": "his Bug Pokemon; James stops at (35, 6)" + }, + { + "id": "save_spot", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "south", "tiles": 2}] + }, + "why": "down to (36, 8), beside the wall east of it" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "Route 3's trainers (Route3 map.json): the way east meets three of them. Bug Catcher Colton (12, 6) faces east, sight 3: the only way north past the row 7 ledges is the gap at x 14..15, below his line. Youngster Ben (17, 4) faces south, sight 2, so the way east keeps to row 3 past him. Bug Catcher Greg (25, 4) faces south, sight 2, over the way east along row 5. Bug Catcher James (32, 6) faces east, sight 4, over the way down at x 35..36. The others are kept out of: Lass Janice (19, 9) sees west along row 9 to x 14, Lass Sally (30, 3) west along row 3 to x 25, and Youngster Calvin (29, 10) west along row 10. Each line is stepped into on its own, so no leg is cut; the trainer walks up to the player, who stays put facing the way they stepped." + ], + "west_of_janice_line": [ + "Up from row 9 west of Janice's line, which ends at x 14." + ], + "save_spot": [ + "Saved here, the trainers behind, so a failure on the way to Route 4 doesn't fight them again." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.12.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.12.plan.json new file mode 100644 index 0000000000..de54d42cfa --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.12.plan.json @@ -0,0 +1,48 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.12", + "title": "Route 3 and 4 to the Magikarp salesman", + "start": {"map": "Route3", "tiles": [[36, 8]], "facing": "south"}, + "events": [ + { + "id": "route4_nurse", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route4_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "east over Route 3, off the grass, north into Route 4 and its Pokemon Center" + }, + { + "id": "heal_route4", + "kind": "heal", + "why": "full HP" + }, + { + "id": "before_salesman", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route4_PokemonCenter_1F", "tiles": [[2, 3]], "facing": "west"} + }, + "why": "beside the Magikarp salesman, facing him" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "handoff": "gift_rng", + "notes": { + "checkpoint": [ + "Route 3's north exit (x 68..75) joins Route 4 (offset 60) at x 8..15, up which column 12 leads to the Pokemon Center's door (12, 5). Lass Robin (40, 11) wanders up and down at x 40, looking north and south, sight 3. Rock above (y <= 8) and grass below (y >= 12) leave every way east across her column at y 9..11, so whether she sees the player depends on her facing. The walk watches for her after the leg along row 9, which crosses her sight on (40, 9) only; if she saw the player, her message goes to story_interrupts(), which fight her, and the route goes on from (40, 9) (run_route(); console B, 2026-11-02, she stopped the player there and spoke after the leg's short watch)." + ], + "before_salesman": [ + "Gift RNG starts from a save facing the salesman (1, 3)." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.12b.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.12b.plan.json new file mode 100644 index 0000000000..f3150745d3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.12b.plan.json @@ -0,0 +1,29 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.12b", + "title": "after Gift RNG: save with the Magikarp", + "start": {"map": "Route4_PokemonCenter_1F", "tiles": [[2, 3]], "facing": "west"}, + "events": [ + { + "id": "leave_gift_summary", + "kind": "game_action", + "action": "leave_gift_summary", + "declared_after": {"map": "Route4_PokemonCenter_1F", "tiles": [[2, 3]], "facing": "west"}, + "why": "the Magikarp's summary Gift RNG left open, or HOME" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "live_start": true, + "notes": { + "checkpoint": [ + "Gift RNG buys the Magikarp (500 of the money 00.12 brings) without moving the player and leaves its summary open, or HOME. This saves the shiny where 00.12 ended. A run started here with Gift RNG's handoff on loads the save beside the salesman and runs Gift RNG first." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.12c.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.12c.plan.json new file mode 100644 index 0000000000..e6e3c76ae2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.12c.plan.json @@ -0,0 +1,42 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.12c", + "title": "Route 4 Center: the Magikarp into BOX 1", + "start": {"map": "Route4_PokemonCenter_1F", "tiles": [[2, 3]], "facing": "west"}, + "events": [ + { + "id": "pc_front", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route4_PokemonCenter_1F", "tiles": [[11, 2]], "facing": "north"} + }, + "why": "below the PC (11, 1), facing it" + }, + { + "id": "magikarp_to_box", + "kind": "game_action", + "action": "pc", + "args": { + "do": "deposit", + "slot": 2, + "box": 1, + "if_present": true + }, + "why": "DEPOSIT the party's second slot into BOX 1, if it has one" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "The Magikarp goes to BOX 1 at the Center's PC (11, 1), so Mt. Moon is fought with the starter alone (console B, 2026-11-02: done by hand and saved at (11, 2), facing the PC, where this row ends). The wandering boy (4..6, 3..5) is walked around. The Magikarp comes from Gift RNG: with Gift RNG off the party is the starter alone, and the deposit is skipped." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.13.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.13.plan.json new file mode 100644 index 0000000000..6736d01d43 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.13.plan.json @@ -0,0 +1,187 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.13", + "title": "Mt. Moon: a Moon Stone, a Rocket, Miguel and the Helix Fossil", + "start": {"map": "Route4_PokemonCenter_1F", "tiles": [[11, 2]], "facing": "north"}, + "events": [ + { + "id": "route4_nurse", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route4_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "the nurse, below the counter" + }, + { + "id": "heal_route4", + "kind": "heal", + "why": "full HP" + }, + { + "id": "mt_moon_entrance", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "MtMoon_1F", "tiles": [[18, 37]], "facing": "north"} + }, + "why": "out of the Center, west into Mt. Moon" + }, + { + "id": "mt_moon_1f", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 12}, {"direction": "east", "tiles": 8}, {"direction": "north", "tiles": 12}, {"direction": "east", "tiles": 3}, {"direction": "south", "tiles": 1}, {"direction": "east", "tiles": 9}, {"direction": "north", "tiles": 1}, {"direction": "east", "tiles": 2}, {"direction": "north", "tiles": 4}, {"direction": "west", "tiles": 24}, {"direction": "east", "tiles": 2}, {"direction": "south", "tiles": 12}, {"direction": "west", "tiles": 7}, {"direction": "north", "tiles": 18}, {"direction": "west", "tiles": 9}, {"direction": "east", "tiles": 1}] + }, + "why": "up the middle, east of Miriam, west along row 9, down column 18 past Josh, up column 11 past Marcos, to (3, 3)" + }, + { + "id": "below_moon_stone", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "MtMoon_1F", "tiles": [[3, 3]], "facing": "north"} + }, + "why": "facing the Moon Stone (3, 2)" + }, + { + "id": "moon_stone_ball", + "kind": "talk", + "why": "A on the item ball" + }, + { + "id": "found_moon_stone", + "kind": "scene", + "declared_after": {"map": "MtMoon_1F", "tiles": [[3, 3]], "facing": "north"}, + "why": "\" found a MOON STONE!\", then the pocket line; the ball is gone" + }, + { + "id": "b2f_ladder_foot", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "MtMoon_B2F", "tiles": [[26, 21]], "facing": "east"} + }, + "why": "1F's ladder (5, 6), down B1F's west side to its ladder (22, 18), onto B2F" + }, + { + "id": "b2f_south", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 4}, {"direction": "east", "tiles": 8}, {"direction": "west", "tiles": 2}, {"direction": "south", "tiles": 5}, {"direction": "east", "tiles": 8}, {"direction": "north", "tiles": 3}, {"direction": "west", "tiles": 1}, {"direction": "north", "tiles": 5}, {"direction": "east", "tiles": 7}, {"direction": "south", "tiles": 14}, {"direction": "west", "tiles": 9}, {"direction": "south", "tiles": 10}, {"direction": "west", "tiles": 29}, {"direction": "east", "tiles": 3}, {"direction": "north", "tiles": 17}] + }, + "why": "through the Grunt's room at (37, 21), round the south edge, up column 11 to (11, 21)" + }, + { + "id": "grunt_line", + "kind": "step", + "args": { + "direction": "east" + }, + "why": "onto (12, 21), below the Grunt at (12, 20)" + }, + { + "id": "rocket_grunt", + "kind": "battle", + "declared_after": {"map": "MtMoon_B2F", "tiles": [[12, 21]], "facing": "east"}, + "why": "Rattata and Zubat, Lv13" + }, + { + "id": "ready_for_miguel", + "kind": "ready", + "args": { + "target": {"map": "Route4_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "items for a status or low HP; the nurse, back through the cave, only if they can't" + }, + { + "id": "below_miguel_trigger", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "east", "tiles": 1}, {"direction": "north", "tiles": 9}, {"direction": "east", "tiles": 1}] + }, + "why": "to (14, 12), below Miguel's trigger (14, 11)" + }, + { + "id": "miguel_trigger", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "onto (14, 11), beside Miguel" + }, + { + "id": "super_nerd_miguel", + "kind": "battle", + "declared_after": {"map": "MtMoon_B2F", "tiles": [[14, 11]], "facing": "north"}, + "why": "Grimer, Voltorb and Koffing, Lv12; \"We'll each take one!\"" + }, + { + "id": "below_helix_fossil", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 3}] + }, + "why": "up column 14 to the HELIX FOSSIL (14, 7)" + }, + { + "id": "helix_fossil", + "kind": "game_action", + "action": "fossil", + "args": { + "fossil": "helix" + }, + "why": "the HELIX FOSSIL; Miguel takes the DOME FOSSIL" + }, + { + "id": "helix_gap", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "onto (14, 7), where the HELIX FOSSIL lay" + }, + { + "id": "route4_east", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route4", "tiles": [[32, 6]], "facing": "south"} + }, + "why": "west to B2F's ladder (5, 10), up to B1F, east to its exit onto Route 4" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "Mt. Moon (pokefirered data/maps/MtMoon_1F, _B1F, _B2F). Every floor tile of the cave has wild encounters, which are run from, so its legs end on walls, ladders or someone standing still, which the walker holds again after a battle; the few open ones are short. The way through: up 1F's middle and west side, its north-west ladder, B1F's west ladder down to B2F's south-east, round B2F's south edge to its west, north past Miguel and the fossils, and the ladder up to B1F's east end, which leads out to Route 4 east of the mountain.", + "1F's trainers are walked around: Youngster Josh (13, 17) sees east along row 17 to x 17, so the way west into the west room is down column 18 and up column 11; Lass Miriam walks round (32..33, 4..5), sight 2, so the way east keeps to row 9 and columns 38 and 40; Hiker Marcos wanders (5..9, 8..12) and sees one tile, so the way north is column 11 and row 3.", + "The Moon Stone ball (3, 2) on 1F (FLAG_HIDE_MT_MOON_1F_MOON_STONE) is a few tiles off the way to the ladder (5, 6).", + "The Grunt at (37, 21) on B2F looks around (sight 3) over the only way east round B2F. His room is crossed on legs to walls, at one tile of his sight each, (37, 22) and (40, 21); if he looks the player's way, he walks up beside the leg, story_interrupts() fights him, and the leg is held on to its wall.", + "The Grunt at (12, 20) faces south (sight 2) over (12, 21..22), across rows 21..22, the only way north to Miguel: stepped into from the west, he is next to the player and doesn't walk.", + "Super Nerd Miguel (13, 11) battles on the step onto (14, 11) (MtMoon_B2F_EventScript_MiguelTrigger, VAR_MAP_SCENE_MT_MOON_B2F 0), then \"We'll each take one!\"", + "The fossils: DOME (13, 7), HELIX (14, 7). After the HELIX, Miguel walks up to (13, 8) and takes the DOME, which opens the gap north.", + "The save is on Route 4: the save card's places don't include Mt. Moon." + ], + "found_moon_stone": [ + "No reader for the text yet: the scene's end is the overworld." + ], + "below_miguel_trigger": [ + "Up column 13 to Miguel, who stops the leg on (13, 12), then east to the wall: the tile below his trigger." + ], + "helix_gap": [ + "The maps keep the fossils, which the game removes after the choice: the step onto the HELIX's tile is taken on its own." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 3d1248b007..b0e515e80c 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1944,6 +1944,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGameArgs.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGameArgs.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind_Tests.cpp @@ -1989,8 +1991,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachScreens.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachScreens.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachScreens_Tests.cpp - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVariantWords.cpp - Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVariantWords.h 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