diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 5c800bb009..c362957808 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -243,6 +243,8 @@ pa_pokesim_map_directory(BDSP_MAP_DIRECTORY bdsp "${POKESIM_CONSUMER}" "${POKESI file(RELATIVE_PATH BDSP_MAP_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}" "${BDSP_MAP_DIRECTORY}") pa_embed_text_files(SerialProgramsLib "${BDSP_MAP_RESOURCES}" PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h PokemonAutomation::NintendoSwitch::PokemonBDSP bdsp_map_json) +pa_embed_text_files(SerialProgramsLib Source/PokemonBDSP/Programs/AutoStory/StoryData + PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.h PokemonAutomation::NintendoSwitch::PokemonBDSP bdsp_checkpoint_json) # Create binary target diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp index e2aa07801f..7f1b00688e 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp @@ -7,6 +7,8 @@ #include "CommonFramework/StaticGlobals.h" #include "CommonFramework/GlobalAutoPaths.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h" + #include "PokemonBDSP_Panels.h" #include "PokemonBDSP_Settings.h" @@ -57,6 +59,25 @@ PanelListFactory::PanelListFactory() ) {} +namespace{ + +// The programs shown only in beta builds or developer mode. +void add_beta_and_developer_panels(std::vector& ret){ + if (IS_BETA_VERSION || STATIC_GLOBALS.DEVELOPER_MODE){ + ret.emplace_back("---- Untested/Beta/WIP ----"); + ret.emplace_back(make_SingleSwitchProgram()); + ret.emplace_back(make_SingleSwitchProgram()); + } + if (STATIC_GLOBALS.DEVELOPER_MODE){ + ret.emplace_back("---- Developer Tools ----"); + ret.emplace_back(make_SingleSwitchProgram()); + ret.emplace_back(make_SingleSwitchProgram()); + ret.emplace_back(make_SingleSwitchProgram()); + } +} + +} // namespace + std::vector PanelListFactory::make_panels() const{ std::vector ret; @@ -91,6 +112,9 @@ std::vector PanelListFactory::make_panels() const{ ret.emplace_back(make_SingleSwitchProgram()); ret.emplace_back(make_SingleSwitchProgram()); + ret.emplace_back("---- Auto Story ----"); + ret.emplace_back(make_SingleSwitchProgram()); + ret.emplace_back("---- Glitches (v1.1.3) ----"); ret.emplace_back(make_SingleSwitchProgram()); ret.emplace_back(make_SingleSwitchProgram()); @@ -98,17 +122,7 @@ std::vector PanelListFactory::make_panels() const{ ret.emplace_back("---- Glitches (v1.1.2) ----"); ret.emplace_back(make_SingleSwitchProgram()); - if (IS_BETA_VERSION || STATIC_GLOBALS.DEVELOPER_MODE){ - ret.emplace_back("---- Untested/Beta/WIP ----"); - ret.emplace_back(make_SingleSwitchProgram()); - ret.emplace_back(make_SingleSwitchProgram()); - } - if (STATIC_GLOBALS.DEVELOPER_MODE){ - ret.emplace_back("---- Developer Tools ----"); - ret.emplace_back(make_SingleSwitchProgram()); - ret.emplace_back(make_SingleSwitchProgram()); - ret.emplace_back(make_SingleSwitchProgram()); - } + add_beta_and_developer_panels(ret); return ret; } diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp index 22208e80f8..afac33d987 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp @@ -14,6 +14,9 @@ #include "Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h" #include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h" #include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h" +#include "Programs/AutoStory/PokemonBDSP_AutoStory_StorySimulation_Tests.h" +#include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.h" +#include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.h" #include "Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.h" #include "PokemonBDSP_Tests.h" @@ -32,6 +35,9 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStory_RoutePlanner(database); add_tests_AutoStory_StoryMaps(database); add_tests_AutoStory_Segment00(database); + add_tests_AutoStory_StorySimulation(database); + add_tests_AutoStory_StoryTable(database); + add_tests_AutoStory_StoryData(database); add_tests_AutoStory_Walk(database); add_tests_AutoStory_PlannedRoute(database); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.cpp index 535147f833..884ebfbc35 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.cpp @@ -7,6 +7,7 @@ */ #include +#include #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/PrettyPrint.h" #include "CommonFramework/Exceptions/OperationFailedException.h" @@ -273,7 +274,7 @@ std::string read_location_from_save_screen(VideoStream& stream, ProControllerCon return location; } -bool save_game( +void save_game( SingleSwitchProgramEnvironment& env, ProControllerContext& context, const std::string& expected_location @@ -283,7 +284,7 @@ bool save_game( for (size_t attempt = 0; attempt < MAX_RETRIES; attempt++){ const SaveAttempt result = save_once(env, context, expected_location, attempt); if (result.outcome == SaveOutcome::SAVED){ - return true; + return; } // No blind fallback for the wrong place: it would save there. if (result.outcome == SaveOutcome::WRONG_PLACE){ @@ -291,15 +292,13 @@ bool save_game( } } - // Blind fallback: reuse the non-feedback save_game(context) from GameNavigation - // rather than duplicating the button sequence manually. - env.console.log("All save retries failed. Using blind fallback.", COLOR_ORANGE); - pbf_mash_button(context, BUTTON_B, 1000ms); - save_game(context); // PokemonBDSP_GameNavigation.h - non-feedback overload - pbf_mash_button(context, BUTTON_B, 2000ms); - context.wait_for_all_requests(); - - return false; + // No blind save: presses the screen never confirmed could land anywhere, + // even on the HOME menu (console B, 2026-11-11). Stop instead. + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("Couldn't confirm the save screen in {} attempts; not saving.", MAX_RETRIES), + env.console + ); } void wait_for_dialogue(VideoStream& stream, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h index afeb466640..b7f3235901 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h @@ -24,13 +24,14 @@ namespace NintendoSwitch{ namespace PokemonBDSP{ -// Save the game from the overworld with retries. Returns true if the save was -// verified via overworld detection, false if the blind fallback was used. +// Save the game from the overworld with retries. A save the screen never +// confirmed fails with a screenshot: there is no blind save (console B, +// 2026-11-11: one pressed X/R/ZL on the HOME menu). // With `expected_location`, the map named on the save screen's card must be // it (compared as a location banner is), or the save is backed out of and // the function fails with a screenshot: r124a saved in Sandgem Town after a // walk that was sure it stood on Route 202. -bool save_game( +void save_game( SingleSwitchProgramEnvironment& env, ProControllerContext& context, const std::string& expected_location = "" diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.cpp new file mode 100644 index 0000000000..40fa26813b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.cpp @@ -0,0 +1,39 @@ +/* BDSP AutoStory - Events + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonBDSP_AutoStory_Events.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +const StoryEvents& story_events(){ + static const StoryEvents events = []{ + StoryEvents ret; + add_lake_events(ret); + add_sandgem_events(ret); + add_jubilife_events(ret); + add_oreburgh_events(ret); + add_route204_events(ret); + return ret; + }(); + return events; +} + +StoryEvent console_event(std::function action){ + return [action = std::move(action)](StoryExecutor& executor, Pokemon::RunState&, const Pokemon::StoryStep&){ + action(executor.stream(), executor.context()); + return Pokemon::outcome_ok(); + }; +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h new file mode 100644 index 0000000000..a39c9738d9 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h @@ -0,0 +1,65 @@ +// code-health: allow header_symbols -- story event dispatch table and per-area event population functions +/* BDSP AutoStory - Events + * + * From: https://github.com/PokemonAutomation/ + * + * The story's steps that only BDSP has, by name: a step of the table whose + * variant names one of these runs it (StoryExecutor::run()). Some are the + * scripted scenes (the Azure Flute, the lake's briefcase, the starter, + * Dawn's catching tutorial and the catch); the rest do what the shared + * steps cannot, as they ran on the console: the Poke Mart lady's Potions + * and the stairs into Jubilife (00.04c, 00.04d), a clown who wanders + * (00.05b), the Gym's tries from the Pokemon Center (01.04) and Rock Smash + * (01.09). Each fails by throwing, with a screenshot; the executor turns + * that into a failed step. + * + * They are in files by area: _Events_Lake (00.00 to 00.04), _Sandgem + * (00.04c, 00.04d), _Jubilife (00.05b), _Oreburgh (01.04) and _Route204 + * (01.09). + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Events_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Events_H + +#include +#include +#include +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Runs a step on the console. Returns where it left the player when it +// knows; throws OperationFailedException when it fails. +using StoryEvent = std::function; +// Map of story event names to their execution functions. +using StoryEvents = std::map; + +// Every event of the story, by name. +const StoryEvents& story_events(); + +// An event that only acts and says nothing of where it leaves us. +StoryEvent console_event(std::function action); + +// Populates lake-area story event handlers. +void add_lake_events(StoryEvents& events); +// Populates Sandgem-area story event handlers. +void add_sandgem_events(StoryEvents& events); +// Populates Jubilife-area story event handlers. +void add_jubilife_events(StoryEvents& events); +// Populates Oreburgh-area story event handlers. +void add_oreburgh_events(StoryEvents& events); +// Populates Route 204-area story event handlers. +void add_route204_events(StoryEvents& events); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp new file mode 100644 index 0000000000..86413db20a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp @@ -0,0 +1,97 @@ +/* BDSP AutoStory - Events: Jubilife City (00.05b) + * + * From: https://github.com/PokemonAutomation/ + * + * The Jubilife beat of 00.05b the story table cannot plan: the talk to a + * wandering clown. + * + */ + +#include +#include +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkDpad.h" +#include "PokemonBDSP_AutoStory_Talks.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" +#include "PokemonBDSP_AutoStory_WildBattle.h" +#include "PokemonBDSP_AutoStory_Events.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; + + +namespace{ + +// 00.05b: a talk to someone who wanders a tile either side of home along a +// row (the clowns by the Mart and the Poketch Company, WANDER_AROUND with +// x range 1). Waiting under home alone missed him for a minute (r66: he +// stood a tile east), so walk the row below his range, a whole D-pad tile +// at a time, asking north from each tile. His question's answer is Yes, so +// A answers and takes the coupon; then back under his home tile. +bool ask_north(VideoStream& stream, ProControllerContext& context){ + route_turn(stream, context, Direction::NORTH); + for (size_t ask = 0; ask < 2; ask++){ + pbf_press_button(context, BUTTON_A, 80ms, 0ms); + context.wait_for_all_requests(); + ShortDialogWatcher dialog(COLOR_YELLOW); + if (wait_until(stream, context, 1500ms, {{dialog}}) == 0){ + return true; + } + } + return false; +} +// One tile along the row, east (+1) or west (-1). +void step_along(VideoStream& stream, ProControllerContext& context, int east, const std::string& label){ + route_turn(stream, context, east > 0 ? Direction::EAST : Direction::WEST); + walk_tiles_dpad(stream, context, run_from_wild_battle, {east > 0 ? 1.0 : -1.0, 0}, 1, label); +} +Pokemon::Outcome talk_to_wanderer(StoryExecutor& executor, Pokemon::RunState&, const Pokemon::StoryStep& step){ + VideoStream& stream = executor.stream(); + ProControllerContext& context = executor.context(); + const std::string label = "Along the row below " + step.name; + // Home, east, west, west, east: each move one tile on the D-pad. + const int moves[] = {0, 1, -1, -1, 1}; + int at = 0; + for (size_t round = 0; round < 6; round++){ + for (int move : moves){ + if (move != 0){ + step_along(stream, context, move, label); + at += move; + } + if (!ask_north(stream, context)){ + continue; + } + stream.log(std::format("[Talk] {}: answered in round {}, {} tiles east of home.", step.name, round + 1, at)); + finish_dialogue(stream, context, BUTTON_A, step.name); + for (; at != 0; at += at > 0 ? -1 : 1){ + step_along(stream, context, at > 0 ? -1 : 1, "Back below " + step.name + "'s home"); + } + route_turn(stream, context, Direction::NORTH); + return Pokemon::outcome_ok(); + } + } + fail_step(stream, step.name + ": no answer from any tile below his range."); +} + +} // namespace + + +void add_jubilife_events(StoryEvents& events){ + events.emplace("talk_to_wanderer", talk_to_wanderer); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Lake.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Lake.cpp new file mode 100644 index 0000000000..0c7841c7fe --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Lake.cpp @@ -0,0 +1,147 @@ +/* BDSP AutoStory - Events: the lake and the Pokedex (00.02 to 00.04) + * + * From: https://github.com/PokemonAutomation/ + * + * Adapted from PokemonAutomation/Arduino-Source#1717 by Developer-Butters. + * + * The scenes of the story's start that need scripted input: the briefcase + * at Lake Verity, the starter, Mom's and Barry's mother's lines, and Dawn's + * catching tutorial. The button sequences are + * Butters' (#1717); they ran on + * the console in his recordings, but not yet from the planned walks around + * them. + * + */ + +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "CommonTools/VisualDetectors/ImageMatchDetector.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP_AutoStory_Actions.h" +#include "PokemonBDSP_AutoStory_WildBattle.h" +#include "PokemonBDSP_AutoStory_Events.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; + + +namespace{ + +// 00.02: the lake's scene, from Barry's first line by the entrance to the +// starters' briefcase: B until the briefcase shows, then until it is open. +void starter_briefcase(VideoStream& stream, ProControllerContext& context){ + wait_for_dialogue(stream, context, "Barry before the starter selection"); + pbf_mash_button(context, BUTTON_A, 1000ms); + pbf_wait(context, 500ms); + std::shared_ptr briefcase = std::make_shared( + RESOURCE_PATH() + "PokemonBDSP/StarterBriefcase.png" + ); + ImageMatchWatcher detector(briefcase, {0.5, 0.1, 0.5, 0.7}, 100, true); + const int ret = run_until( + stream, context, + [](ProControllerContext& context){ + pbf_mash_button(context, BUTTON_B, 120000ms); + }, + {{detector}} + ); + if (ret != 0){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, + "Failed to detect the starters' briefcase.", stream); + } + stream.log("Detected briefcase! Mashing B for it to open."); + pbf_mash_button(context, BUTTON_B, 2000ms); +} + +// 00.02: the starter from the program's option, in the briefcase: Turtwig +// is first, Chimchar a press right, Piplup two; ZL picks, then Up and ZL +// answer "this one?" with Yes. +Pokemon::Outcome choose_starter(StoryExecutor& executor, Pokemon::RunState&, const Pokemon::StoryStep&){ + VideoStream& stream = executor.stream(); + ProControllerContext& context = executor.context(); + size_t rights = 0; + switch (executor.env().starter){ + case StarterChoice::TURTWIG: + rights = 0; + break; + case StarterChoice::CHIMCHAR: + rights = 1; + break; + case StarterChoice::PIPLUP: + rights = 2; + break; + } + for (size_t i = 0; i < rights; i++){ + pbf_press_dpad(context, DPAD_RIGHT, 160ms, 840ms); + } + pbf_press_button(context, BUTTON_ZL, 160ms, 240ms); + context.wait_for_all_requests(); + ShortDialogWatcher watcher(COLOR_CYAN); + int ret = wait_until(stream, context, 5000ms, {{watcher}}); + if (ret != 0){ + ShortDialogWatcher watcher_red(COLOR_RED); + ret = wait_until(stream, context, 5000ms, {{watcher_red}}); + } + stream.log(ret == 0 ? "[Starter] Confirmation dialogue detected." : "[Starter] Dialogue detection failed, proceeding anyway.", ret == 0 ? COLOR_BLACK : COLOR_ORANGE); + pbf_wait(context, 400ms); + pbf_press_dpad(context, DPAD_UP, 80ms, 400ms); + pbf_press_button(context, BUTTON_ZL, 80ms, 5000ms); + context.wait_for_all_requests(); + return Pokemon::outcome_ok(); +} + +// 00.01: BDSP puts an Azure Flute on the bedroom floor at (7, 4) when the console +// has Legends: Arceus save data, and nothing there otherwise. Facing that tile: +// A, and if text follows ("You found an Azure Flute!", then the pocket line), B +// through it. Without the ball the A does nothing and we go on. +void azure_flute_if_there(VideoStream& stream, ProControllerContext& context){ + // The route ends facing the way its last leg went (east, r15): a short tap + // north only turns us to face the tile. + pbf_press_dpad(context, DPAD_UP, 40ms, 400ms); + pbf_press_button(context, BUTTON_A, 80ms, 0ms); + context.wait_for_all_requests(); + for (int presses = 0; presses < 6; presses++){ + ShortDialogWatcher dialog(COLOR_YELLOW); + if (wait_until(stream, context, 2000ms, {{dialog}}) != 0){ + return; + } + pbf_press_button(context, BUTTON_B, 80ms, 1000ms); + context.wait_for_all_requests(); + } +} + + + +// 00.04: Dawn's catching tutorial on Route 202: her lines and her demo +// battle, B for 70 s. +void catch_tutorial(VideoStream& stream, ProControllerContext& context){ + wait_for_dialogue(stream, context, "Dawn's catching tutorial"); + pbf_mash_button(context, BUTTON_B, 70000ms); + context.wait_for_all_requests(); + pbf_wait(context, 2000ms); +} + +} // namespace + + +void add_lake_events(StoryEvents& events){ + events.emplace("azure_flute_if_there", console_event(azure_flute_if_there)); + events.emplace("starter_briefcase", console_event(starter_briefcase)); + events.emplace("choose_starter", choose_starter); + + + events.emplace("catch_tutorial", console_event(catch_tutorial)); + events.emplace("catch_pokemon", console_event(catch_1_pokemon)); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Oreburgh.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Oreburgh.cpp new file mode 100644 index 0000000000..6ce669a041 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Oreburgh.cpp @@ -0,0 +1,146 @@ +/* BDSP AutoStory - Events: Oreburgh Gym (01.04) + * + * From: https://github.com/PokemonAutomation/ + * + * 01.04's walk into the Oreburgh Gym and up it to Roark, again from the + * Pokemon Center after each loss, as it ran on the console (2026-10-29 to + * 10-31). A loss keeps the experience, which a reload of the row's save + * would not. + * + */ + +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" +#include "PokemonBDSP_AutoStory_Talks.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" +#include "PokemonBDSP_AutoStory_WildBattle.h" +#include "PokemonBDSP_AutoStory_Events.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; + + +namespace{ + +// 01.04 starts below Oreburgh's Center door (47, 21): 01.03's heal and +// the walk out after a loss both leave us there. The Gym's door is on the +// same street, so the D-pad taps west are the columns between the two +// doors on the map (21). A hand count of 20, from before the maps, ended +// a tile east of the Gym's door (lab-B, 2026-11-08 14:51). +size_t gym_taps_west_of_center(){ + const Pokemon::TilePos center = map_point("OreburghCity", "pokemon_center_door"); + const Pokemon::TilePos gym = map_point("OreburghCity", "gym_door"); + return static_cast(center.x - gym.x); +} + +void oreburgh_street_to_gym(VideoStream& stream, ProControllerContext& context){ + // From the Center's doorstep, straight west along its row to below the + // gym's door, then north through it, all on the D-pad (whole tiles; see + // gym_taps_west_of_center()). 01.04 always starts on the doorstep: its + // own save, or the walk out of the Center after a loss. A brightness + // check for "already in the gym" (gym 75 against street 104 by day, r74) + // read the street at night (88, game clock 00:25) as the gym and talked + // to the nurse as Roark (lab-B, 2026-11-08 14:25). + context.wait_for_all_requests(); + dpad_tiles(stream, context, DPAD_LEFT, gym_taps_west_of_center(), "west to the gym's door"); + if (dpad_through_door_north(stream, context, "Oreburgh Gym door")){ + return; + } + // The gym's wall stopped us: try the column west, then the one east. + dpad_tiles(stream, context, DPAD_LEFT, 1, "a column west of the gym's door"); + if (dpad_through_door_north(stream, context, "Oreburgh Gym door")){ + return; + } + dpad_tiles(stream, context, DPAD_RIGHT, 2, "a column east of the gym's door"); + if (dpad_through_door_north(stream, context, "Oreburgh Gym door")){ + return; + } + fail_step(stream, "Oreburgh: no column near the gym's door went in."); +} + +// Inside the Oreburgh Gym: straight up the middle, fighting the trainers +// who stop us, to Roark on the top tier. Returns whether Roark was beaten; +// false after a whiteout, which leaves us in the Pokemon Center. +// Walking straight up meets both gym trainers (one at the entrance, one on +// the second tier); their experience helps an under-levelled team, and +// after a whiteout they stay beaten. Butters' route goes round them. +bool oreburgh_gym_battles(VideoStream& stream, ProControllerContext& context){ + // The entry camera pans for about 7.5 s (Butters' reference video). + context.wait_for(8000ms); + if (dialogue_opens(stream, context, 3000ms)){ + if (talk_or_fight(stream, context, "Gym trainer at the entrance") && in_pokemon_center(stream)){ + return false; + } + } + size_t stuck = 0; + for (size_t leg = 0; leg < 10; leg++){ + const WalkResult up = walk_until_no_wild(stream, context, {0, 1}, 8000ms, "north up the gym"); + if (up.stop == WalkStop::DIALOG){ + if (talk_or_fight(stream, context, "Gym trainer") && in_pokemon_center(stream)){ + return false; + } + continue; + } + if (up.stop != WalkStop::BLOCKED){ + continue; + } + // Roark stands at the top facing us; a wall or a stair edge says + // nothing to A. Only Roark starts a battle from our A here. The walk + // left us facing north: a turn tap that way would be a step. + pbf_press_button(context, BUTTON_A, 80ms, 200ms); + if (dialogue_opens(stream, context, 3000ms)){ + // His lines pause for more than 4 s before the battle (r210d: "only + // talked"), so the battle is expected. + // His badge speech is over when talk_or_fight() returns: the + // battle ends with its speeches (confirm_battle_overworld()). + if (talk_or_fight(stream, context, "Roark", TalkExpect::BATTLE)){ + return !in_pokemon_center(stream); + } + continue; + } + if (up.walked <= 800ms && ++stuck >= 3){ + fail_step(stream, "Oreburgh Gym: stuck on the way up, and nobody answers A."); + } + } + fail_step(stream, "Oreburgh Gym: did not reach Roark."); +} + +// 01.04: west along the row into the gym and up it to Roark, again from the Center after a loss. +void gym_until_roark_beaten(VideoStream& stream, ProControllerContext& context){ + // Losing costs some money and keeps the experience, so each try comes + // back stronger: Roark won twice by hand against Piplup Lv 10 and 14 and + // lost the third time. + bool won = false; + for (size_t attempt = 0; attempt < 5 && !won; attempt++){ + oreburgh_street_to_gym(stream, context); + won = oreburgh_gym_battles(stream, context); + if (!won){ + stream.log("[01.04] Lost in the gym (try " + std::to_string(attempt + 1) + "); back from the Center.", COLOR_ORANGE); + walk_out_of_center(stream, context, "Oreburgh"); + } + } + if (!won){ + fail_step(stream, "Oreburgh Gym: lost to Roark five times."); + } +} + +} // namespace + + +void add_oreburgh_events(StoryEvents& events){ + events.emplace("gym_until_roark_beaten", console_event(gym_until_roark_beaten)); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Route204.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Route204.cpp new file mode 100644 index 0000000000..f72eb04b39 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Route204.cpp @@ -0,0 +1,85 @@ +/* BDSP AutoStory - Events: the Ravaged Path (01.09) + * + * From: https://github.com/PokemonAutomation/ + * + * The Ravaged Path's Rock Smash, as it ran on the console (2026-10-31). + * + */ + +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" +#include "PokemonBDSP_AutoStory_Talks.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" +#include "PokemonBDSP_AutoStory_WildBattle.h" +#include "PokemonBDSP_AutoStory_Events.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; + + +namespace{ + +// "This rock seems breakable with a hidden move. Would you like to use Rock +// Smash?" is open, from an A at a smashable rock. Its Yes/No box comes only +// once the text is advanced again (by hand, 2026-10-31: the text complete +// 1.2 s after the first A, the box 1.2 s after a second), and r237a's timed +// A, A, B put its B on that box: No. So press A until the box's cursor +// shows, then once more for Yes, and wait out the move. False if no box +// shows: whatever is open is not this prompt. +bool answer_rock_smash_prompt(VideoStream& stream, ProControllerContext& context, const std::string& label){ + static const ImageFloatBox YES_NO_ARROW_BOX{0.700, 0.620, 0.070, 0.120}; + SelectionArrowFinder yes_no(stream.overlay(), YES_NO_ARROW_BOX, COLOR_GREEN); + for (size_t press = 0; press < 5; press++){ + context.wait_for(1200ms); + context.wait_for_all_requests(); + const VideoSnapshot screen = stream.video().snapshot(); + if (screen && yes_no.detect(*screen.frame)){ + stream.log("[Route] " + label + ": Rock Smash offered; Yes."); + pbf_press_button(context, BUTTON_A, 80ms, 0ms); + context.wait_for(5000ms); + if (dialogue_opens(stream, context, 500ms)){ + finish_dialogue(stream, context, BUTTON_B, label + ": after Rock Smash"); + } + return true; + } + pbf_press_button(context, BUTTON_A, 80ms, 0ms); + } + stream.log("[Route] " + label + ": no Yes/No box for Rock Smash.", COLOR_RED); + return false; +} + +// 01.09: Rock Smash on the rock east of us, from the tile the route ends on +// facing it. Only the prompt's Yes/No box tells the rock from someone in +// the way (r237a: the walker took one for a person and said No). +void smash_the_rock(VideoStream& stream, ProControllerContext& context){ + route_turn(stream, context, Direction::EAST); + if (!talk_with_nudges(stream, context, run_from_wild_battle, Direction::EAST, "the rock east of us", 2000ms)){ + fail_step(stream, "Ravaged Path: nothing answered facing the rock east of us."); + } + if (!answer_rock_smash_prompt(stream, context, "the rock east of us")){ + fail_step(stream, "Ravaged Path: no Rock Smash offer facing the rock east of us."); + } +} + +} // namespace + + +void add_route204_events(StoryEvents& events){ + events.emplace("smash_the_rock", console_event(smash_the_rock)); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Sandgem.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Sandgem.cpp new file mode 100644 index 0000000000..3ed31c906c --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Sandgem.cpp @@ -0,0 +1,259 @@ +/* BDSP AutoStory - Events: Sandgem and Route 202 (00.04) + * + * From: https://github.com/PokemonAutomation/ + * + * 00.04's Potions from the Poke Mart lady on Route 201's east end, the + * way back to Route 202's save spot, and the stairs into Jubilife. + * + */ + +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryTrainers.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkDpad.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" +#include "PokemonBDSP_AutoStory_Bag.h" +#include "PokemonBDSP_AutoStory_Center.h" +#include "PokemonBDSP_AutoStory_Talks.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" +#include "PokemonBDSP_AutoStory_WildBattle.h" +#include "PokemonBDSP_AutoStory_Events.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; +using Pokemon::TilePos; + + +namespace{ + +// A walk_until() callback that keeps every location banner it sees. +std::function banner_keeper(std::vector& banners){ + return [&banners](const ImageViewRGB32& screen){ + const std::string read = read_location_banner(screen); + if (!read.empty() && (banners.empty() || banners.back() != read)){ + banners.push_back(read); + } + return false; + }; +} + +bool any_banner_names(const std::vector& banners, const std::string& map){ + return std::any_of(banners.begin(), banners.end(), + [&](const std::string& read){ return location_banner_matches(read, map); }); +} + +// Whether all of `tiles` are on `map`. +bool all_on_map(const StoryWorld& maps, const std::vector& tiles, const std::string& map){ + return !tiles.empty() && std::all_of(tiles.begin(), tiles.end(), [&](const TilePos& pos){ + const std::optional tile = maps.to_local(pos); + return tile && tile->map == map; + }); +} + +// North from below the gap between the signs until a wall stops us, +// nudging a tile west, twice at most, when blocked at once (below a +// sign or the Mart). Returns whether Route 202's banner showed: only +// one of the gap's columns leads out of town before a wall. +bool walk_north_through_gap(VideoStream& stream, ProControllerContext& context){ + using Pokemon::Direction; + std::vector banners; + for (size_t nudges = 0;; nudges++){ + const WalkResult north = walk_until(stream, context, run_from_wild_battle, {0, 1}, 8000ms, "North through the gap", banner_keeper(banners)); + if (north.stop == WalkStop::TRANSITION || north.stop == WalkStop::DIALOG || north.wild_battles > 0){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, + "North through the gap: " + std::string(walk_stop_name(north.stop)) + " instead of a wall.", stream); + } + // Blocked at once: the wall reads after about 800ms still. + if (north.walked > ROUTE_START_DELAY + 800ms + 2 * ROUTE_MS_PER_TILE_UP_DOWN){ + break; + } + if (nudges == 2){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, + "North through the gap: still blocked after two tiles west.", stream); + } + route_status(stream, "North through the gap: blocked at once, below a sign or the Mart; a tile west."); + route_turn(stream, context, Direction::WEST); + walk_for(stream, context, run_from_wild_battle, {-1, 0}, route_open_hold(Direction::WEST, 1), "A tile west"); + route_turn(stream, context, Direction::NORTH); + } + context.wait_for_all_requests(); + if (VideoSnapshot screen = stream.video().snapshot()){ + banner_keeper(banners)(*screen.frame); + } + return any_banner_names(banners, MAP_ROUTE_202); +} + +// From the trees at the east end of the doors' row, west into the gap +// between the Center's sign and the Mart's (below_sign_gap()) and +// north through it until a wall stops us. Six tiles west from column +// 29 ends on 23, and on 20 to 26 if two tiles off: north from all of +// those passes no door, and only the gap lets us through. A walk +// north that goes nowhere stood below a sign or the Mart: a tile +// west, twice at most, never reaches the Center's door at 17. The +// planner would rather go round the south of town on walls, where +// townspeople wander. Returns where the walk north may have ended: +// the gap's columns end on Sandgem's top row, bar one that runs on to +// Route 202, and its banner tells the two apart. +std::vector north_through_sign_gap(VideoStream& stream, ProControllerContext& context, const StoryWorld& maps){ + using Pokemon::Direction; + route_status(stream, "To the gap between the Center's and the Mart's signs: west 6."); + route_turn(stream, context, Direction::WEST); + walk_for(stream, context, run_from_wild_battle, {-1, 0}, route_open_hold(Direction::WEST, 6), "To the gap between the signs"); + const bool on_route = walk_north_through_gap(stream, context); + std::vector ends; + for (const TilePos& pos : map_region("SandgemTown", "below_sign_gap")){ + const TilePos end = slide_to_wall(maps, maps.to_world(MAP_SANDGEM_TOWN, pos), Direction::NORTH).stop; + if (all_on_map(maps, {end}, MAP_ROUTE_202) == on_route){ + ends.push_back(end); + } + } + route_status(stream, std::string("North through the gap: Route 202's banner ") + + (on_route ? "showed; on Route 202." : "did not show; on Sandgem Town's top row.")); + return ends; +} + +// Back up to Route 202's save spot under the ledge: it is where a +// retry may start (story_save_spots()), its walls pin it, and the +// trainers are north of it. First east to the trees that end the +// doors' row, so the way north starts from one known tile, then north +// through the gap between the signs: r123a, planned round the south +// of town on a map that had it wrong, walked into a house. +void walk_to_route_202_save_spot( + VideoStream& stream, ProControllerContext& context, const StoryWorld& maps, + std::vector at, RouteTrainers& trainers +){ + const TilePos row_end = maps.to_world(MAP_SANDGEM_TOWN, map_point("SandgemTown", "front_row_east_end")); + const TilePos save_spot = maps.to_world(MAP_ROUTE_202, map_point("Route202", "save_spot")); + if (!all_on_map(maps, at, MAP_ROUTE_202)){ + at = walk_route(stream, context, run_from_wild_battle, maps, std::move(at), trainers, RouteWalkPlan{[&](const TilePos& pos){ return pos == row_end; }, "To the trees east of the Poke Mart", {}, route_plan_costs()}); + at = north_through_sign_gap(stream, context, maps); + } + walk_route(stream, context, run_from_wild_battle, maps, std::move(at), trainers, RouteWalkPlan{[&](const TilePos& pos){ return pos == save_spot; }, "Back to Route 202", {}, route_plan_costs()}); +} + +// North into Jubilife until Dawn's scene starts (00.04d's +// jubilife_stairs). Jubilife's south edge is a wall with stairs in it, +// west of where the route may leave us (r78 stood at its east end). +// Entering starts a scene: Dawn walks over while we stand still. So +// walk north; if the wall stops us and no dialogue follows, the stairs +// are further west. The scene itself is the next step. +void up_jubilife_stairs(VideoStream& stream, ProControllerContext& context){ + for (size_t attempt = 0; attempt < 6; attempt++){ + const WalkResult walk = walk_until(stream, context, run_from_wild_battle, {0, 1}, 4000ms, "to Dawn in Jubilife"); + if (walk.stop == WalkStop::TRANSITION){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, + "Jubilife: left the area instead of meeting Dawn.", stream); + } + ShortDialogWatcher dialog(COLOR_CYAN); + if (walk.stop == WalkStop::DIALOG || wait_until(stream, context, 6s, {{dialog}}) == 0){ + return; + } + stream.log("[00.04] Jubilife: the wall stopped us; looking for the stairs one tile west."); + route_turn(stream, context, Pokemon::Direction::WEST); + pbf_move_left_joystick(context, {-1, 0}, route_open_hold(Pokemon::Direction::WEST, 1), 200ms); + context.wait_for_all_requests(); + } + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, + "Jubilife: no stairs found and no Dawn after six tiles west.", stream); +} + +// Reads a sign facing `facing`: its box must open and close, and its text, +// when there is a reader for it, have `key`. A walk that stopped short of +// it is put right by walking on until the sign stops us, once. +void read_sign_on_the_way(VideoStream& stream, ProControllerContext& context, Direction facing, const std::string& sign, const std::string& key){ + for (size_t attempt = 0; attempt < 2; attempt++){ + const DialogueRead read = read_sign(stream, context, facing, sign); + if (read.opened && read.closed && (read.text.empty() || sign_text_matches(read.text, key))){ + return; + } + walk_until_stopped(stream, context, facing, 2, "On to the sign"); + } + fail_step(stream, "Sandgem: " + sign + " did not read facing " + Pokemon::direction_name(facing) + "."); +} + +// From the doors' row in front of Sandgem's Pokemon Center to the Poke Mart +// lady and back to Route 202's save spot. Every leg but three one-tile +// steps walks until something stops it, as measured on the console +// (2026-10-30, CFR "walk"): west to the Lab's sign; south a tile, west to +// the grass's edge; north to the trees, on her row; east until she stops +// us (she gives new games 10 Potions); south a tile, east to Route 201's +// sign; south a tile, east to the trees east of the Mart, north a row; then +// the planned walk to the save spot. She stands on the top row of her +// grass, a tile or two in from its west edge: missed, back west to the +// edge and again, twice. +void mart_lady(VideoStream& stream, ProControllerContext& context){ + walk_until_stopped(stream, context, Direction::WEST, 20, "West to the Lab's sign"); + read_sign_on_the_way(stream, context, Direction::WEST, "the Lab's sign", "lab"); + hold_for(stream, context, Direction::SOUTH, 200ms, "South onto the path"); + walk_until_stopped(stream, context, Direction::WEST, 28, "West along the path"); + walk_until_stopped(stream, context, Direction::NORTH, 3, "North to the trees"); + bool talked = false; + for (size_t attempt = 0; attempt < 3 && !talked; attempt++){ + if (attempt > 0){ + walk_until_stopped(stream, context, Direction::WEST, 6, "West to the grass's edge"); + } + const DialogueRead read = talk_walking(stream, context, Direction::EAST, 4, "Poke Mart lady"); + talked = read.opened && read.closed; + } + if (!talked){ + fail_step(stream, "Route 201: the Poke Mart lady did not talk."); + } + hold_for(stream, context, Direction::SOUTH, 200ms, "South onto the signs' row"); + walk_until_stopped(stream, context, Direction::EAST, 16, "East to the Route 201 sign"); + read_sign_on_the_way(stream, context, Direction::EAST, "Route 201's sign", "201"); + hold_for(stream, context, Direction::SOUTH, 200ms, "South onto the path"); + walk_until_stopped(stream, context, Direction::EAST, 40, "East along the path"); + walk_until_stopped(stream, context, Direction::NORTH, 2, "North to the front row"); + const StoryWorld& maps = story_maps(); + RouteTrainers trainers{story_trainer_sights(), [&](const std::string& name){ fight_route_trainer(stream, context, name); }}; + walk_to_route_202_save_spot(stream, context, maps, {maps.to_world(MAP_SANDGEM_TOWN, map_point("SandgemTown", "front_row_east_end"))}, trainers); +} + +// 00.04c's potions step, from the save out of Sandgem's Center: the Poke +// Mart lady's 10, on to Route 202's save spot, where 00.04d's save goes. +// The Bag must have Potions after. +void sandgem_potions(VideoStream& stream, ProControllerContext& context){ + // Onto the doors' row first: out of the door we stand a tile to + // three below it (r261 walked west into the trees from three). + route_turn(stream, context, Direction::EAST); + walk_tiles_dpad(stream, context, run_from_wild_battle, {1, 0}, 1, "east under the Center's wall"); + const WalkResult up = walk_until(stream, context, run_from_wild_battle, {0, 1}, 3000ms, "north to the Center's front"); + if (up.stop != WalkStop::BLOCKED){ + fail_step(stream, std::string("Sandgem: north to the Center's front ended ") + walk_stop_name(up.stop) + "."); + } + mart_lady(stream, context); + if (!bag_has_item(stream, context, "potion", 1)){ + fail_step(stream, "00.04: no Potions in the Bag after the shop."); + } +} + +} // namespace + + +void add_sandgem_events(StoryEvents& events){ + events.emplace("sandgem_potions", console_event(sandgem_potions)); + events.emplace("jubilife_stairs", console_event(up_jubilife_stairs)); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp new file mode 100644 index 0000000000..90d8afaf94 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp @@ -0,0 +1,328 @@ +/* BDSP AutoStory - Talks + * + * From: https://github.com/PokemonAutomation/ + * + * Talking to people and fighting the trainers among them, and the looks + * at the screen the story's events decide by. + * + */ + +#include +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/PrettyPrint.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "CommonTools/OCR/OCR_RawTesseractOCR.h" +#include "CommonTools/OCR/OCR_Routines.h" +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.h" +#include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h" +#include "PokemonBDSP_AutoStory_Bag.h" +#include "PokemonBDSP_AutoStory_Battle.h" +#include "PokemonBDSP_AutoStory_WildBattle.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" +#include "PokemonBDSP_AutoStory_Talks.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; + + +[[noreturn]] void fail_step(VideoStream& stream, const std::string& message){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, message, stream); +} + +// True if a dialogue opens within `timeout`: someone who stopped us as the +// walk ended reads as BLOCKED, and their box comes up a moment later. +bool dialogue_opens(VideoStream& stream, ProControllerContext& context, Milliseconds timeout){ + context.wait_for_all_requests(); + ShortDialogWatcher dialog(COLOR_CYAN); + return wait_until(stream, context, timeout, {{dialog}}) == 0; +} + +bool talk_or_fight(VideoStream& stream, ProControllerContext& context, const std::string& label, TalkExpect expect, BattleFormat format){ + ShortDialogDetector dialog; + OverworldDetector overworld; + BattleMenuDetector battle_menu(BattleType::TRAINER); + // Roark's battle menu read as STANDARD, not TRAINER, and nothing fought + // it (r210d): either counts here, as only a trainer's battle can start. + BattleMenuDetector battle_menu_standard(BattleType::STANDARD); + BlackScreenDetector black; + auto quiet_since = std::chrono::steady_clock::now(); + for (size_t check = 0; check < 120; check++){ + context.wait_for_all_requests(); + const auto frame = stream.video().snapshot(); + if (!frame){ + fail_step(stream, label + ": No video frame."); + } + if (battle_menu.detect(*frame.frame) || battle_menu_standard.detect(*frame.frame) || black.detect(*frame.frame)){ + route_status(stream, "Fighting " + label + "."); + fight_story_battle(stream, context, label, format); + // Lines after the battle (Roark's badge, r211d) keep the menu + // from opening: finish them before the Potion. + if (dialogue_opens(stream, context, 3000ms)){ + finish_dialogue(stream, context, BUTTON_B, label + " after the battle"); + } + if (!in_pokemon_center(stream)){ + use_potion_first_pokemon(stream, context, 0.5); + } + return true; + } + const bool talking = dialog.detect(*frame.frame); + if (!talking && overworld.detect(*frame.frame)){ + if (expect != TalkExpect::BATTLE && std::chrono::steady_clock::now() - quiet_since >= 4s){ + route_status(stream, label + " only talked."); + return false; + } + pbf_wait(context, 300ms); + continue; + } + quiet_since = std::chrono::steady_clock::now(); + if (talking){ + pbf_press_button(context, BUTTON_B, 80ms, 1100ms); + }else{ + pbf_wait(context, 300ms); + } + } + fail_step(stream, label + ": neither a battle nor the overworld after the dialogue."); +} + +// A rough check that we stand in a Pokemon Center: its floor fills the lower +// half of the screen with warm yellow, where the gym is grey and routes are +// green. After a battle it tells a loss (a whiteout ends at the counter) +// from a win. +bool center_floor_on_screen(const ImageViewRGB32& screen, size_t* percent){ + const ImageRGB32 small = screen.scale_to(192, 108); + size_t warm = 0, total = 0; + for (size_t y = 54; y < 108; y++){ + for (size_t x = 0; x < 192; x++){ + const uint32_t pixel = small.pixel(x, y); + const int r = (pixel >> 16) & 0xff, g = (pixel >> 8) & 0xff, b = pixel & 0xff; + total++; + if (r > 200 && g > 150 && b < 150 && r - b > 70){ + warm++; + } + } + } + if (percent){ + *percent = warm * 100 / total; + } + return warm * 10 > total * 3; +} + +bool pokemon_center_on_screen(const ImageViewRGB32& screen, size_t* percent){ + return center_floor_on_screen(screen, percent) && indoors(screen); +} + +bool in_pokemon_center(VideoStream& stream){ + const VideoSnapshot frame = stream.video().snapshot(); + if (!frame){ + return false; + } + size_t percent = 0; + const bool inside = pokemon_center_on_screen(*frame.frame, &percent); + stream.log("[Center check] warm floor " + std::to_string(percent) + " %, " + + (indoors(*frame.frame) ? "a room" : "outside") + ": " + + (inside ? "in a Pokemon Center." : "not in a Pokemon Center.")); + return inside; +} + +// The Oreburgh Mine's hall and corridors are dim: mean brightness 45 to 64 +// on the console, against 99 to 116 for the city and its yard (2026-10-31). +bool in_dim_cave(VideoStream& stream, uint64_t below){ + const VideoSnapshot frame = stream.video().snapshot(); + if (!frame){ + return false; + } + const ImageRGB32 small = frame.frame->scale_to(192, 108); + uint64_t sum = 0; + for (size_t y = 0; y < 108; y++){ + for (size_t x = 0; x < 192; x++){ + const uint32_t pixel = small.pixel(x, y); + sum += ((pixel >> 16) & 0xff) + ((pixel >> 8) & 0xff) + (pixel & 0xff); + } + } + const uint64_t mean = sum / (3 * 192 * 108); + stream.log("[Cave check] mean brightness " + std::to_string(mean) + "."); + return mean < below; +} + +// Mean of the three channels over a small copy of the frame, 0 to 255. +uint64_t mean_brightness(const ImageViewRGB32& screen){ + const ImageRGB32 small = screen.scale_to(192, 108); + uint64_t sum = 0; + for (size_t y = 0; y < 108; y++){ + for (size_t x = 0; x < 192; x++){ + const uint32_t pixel = small.pixel(x, y); + sum += ((pixel >> 16) & 0xff) + ((pixel >> 8) & 0xff) + (pixel & 0xff); + } + } + return sum / (3 * 192 * 108); +} + +// Fights a trainer whose dialogue has opened, with whatever starter we +// have. Someone who only talks leaves no battle to fight. +void fight_route_trainer(VideoStream& stream, ProControllerContext& context, const std::string& name){ + pbf_mash_button(context, BUTTON_B, 5000ms); + context.wait_for_all_requests(); + BattleMenuWatcher battle_menu(BattleType::TRAINER, COLOR_YELLOW); + BattleDialogWatcher battle_dialog(COLOR_YELLOW); + if (wait_until(stream, context, 8s, {{battle_menu}, {battle_dialog}}) < 0){ + stream.log("[Route] " + name + ": no battle followed the talk."); + pbf_mash_button(context, BUTTON_B, 2000ms); + context.wait_for_all_requests(); + return; + } + fight_trainer(stream, context, name); + context.wait_for_all_requests(); + // The next trainer may be a few tiles on: check HP now. With no + // Potion in the Bag this only looks. + use_potion_first_pokemon(stream, context, 0.5); +} + +bool sign_text_matches(const std::string& text, const std::string& key){ + std::string lower; + for (char ch : text){ + lower += (char)std::tolower((unsigned char)ch); + } + return lower.find(key) != std::string::npos; +} + +namespace{ + +// Where a sign's box shows: the bottom of the screen, as a dialogue's. The +// Lab's is grey, Route 201's green; opening either changes the area far +// more than the overworld behind it moves standing still. +const ImageFloatBox SIGN_BOX(0.19, 0.80, 0.64, 0.18); +// Its text, inside the margins. +const ImageFloatBox SIGN_TEXT(0.22, 0.82, 0.58, 0.15); +constexpr double SIGN_BOX_OPENED = 20.0; + +bool dialogue_showing(VideoStream& stream, ProControllerContext& context){ + context.wait_for_all_requests(); + VideoSnapshot screen = stream.video().snapshot(); + return screen && ShortDialogDetector().detect(*screen.frame); +} + +// After a talk opened: reads the first box, then presses `next` once +// per line, 1.5 s apart, and only while a box shows: a press after it +// has closed would start the talk over. +void finish_talk(VideoStream& stream, ProControllerContext& context, DialogueRead& read, Button next, const std::string& label){ + // The first box's text, inside its white margins. + // For the log only; a talk is checked by its box opening and closing. + VideoSnapshot screen = stream.video().snapshot(); + if (screen && story_reads_text()){ + read.text = OCR::ocr_read(story_language(), extract_box_reference(*screen.frame, SIGN_TEXT), OCR::PageSegMode::SINGLE_BLOCK); + } + stream.log("[Talk] " + label + ": the dialogue reads \"" + read.text + "\"."); + size_t quiet = 0; + // Barry's scene, to the Town Map, took more than 20 (r150a). + for (size_t presses = 0; presses < 80 && quiet < 2; presses++){ + ShortDialogWatcher dialog(COLOR_YELLOW); + if (wait_until(stream, context, 1500ms, {{dialog}}) == 0){ + quiet = 0; + pbf_press_button(context, next, 80ms, 0ms); + }else{ + quiet++; + } + } + read.closed = !dialogue_showing(stream, context); + stream.log("[Talk] " + label + (read.closed ? ": closed." : ": still open.")); +} + +} // namespace + +DialogueRead talk_facing(VideoStream& stream, ProControllerContext& context, Direction direction, Button next, const std::string& label){ + route_turn(stream, context, direction); + return talk_ahead(stream, context, next, label); +} + +DialogueRead talk_ahead(VideoStream& stream, ProControllerContext& context, Button next, const std::string& label){ + DialogueRead read; + pbf_press_button(context, BUTTON_A, 80ms, 0ms); + context.wait_for_all_requests(); + ShortDialogWatcher opened(COLOR_CYAN); + if (wait_until(stream, context, 2000ms, {{opened}}) != 0){ + stream.log("[Talk] " + label + ": no dialogue opened."); + return read; + } + read.opened = true; + finish_talk(stream, context, read, next, label); + return read; +} + +DialogueRead talk_walking(VideoStream& stream, ProControllerContext& context, Direction direction, size_t tiles, const std::string& label){ + DialogueRead read; + const auto [x, y] = dpad_of(direction); + const bool across = direction == Direction::EAST || direction == Direction::WEST; + const Milliseconds limit = (int64_t)tiles * (across ? ROUTE_MS_PER_TILE_ACROSS : ROUTE_MS_PER_TILE_UP_DOWN) + 800ms; + const WalkResult walked = walk_to_talk(stream, context, run_from_wild_battle, {x, y}, limit, label); + if (walked.stop != WalkStop::DIALOG){ + stream.log("[Talk] " + label + ": nobody answered."); + return read; + } + read.opened = true; + finish_talk(stream, context, read, BUTTON_A, label); + return read; +} + +DialogueRead read_sign(VideoStream& stream, ProControllerContext& context, Direction facing, const std::string& label){ + DialogueRead read; + route_turn(stream, context, facing); + // Let the camera settle after the turn: its drift read as a box + // opening (r132a). + pbf_wait(context, 800ms); + context.wait_for_all_requests(); + VideoSnapshot before = stream.video().snapshot(); + // The text types out over about a second; B before it has finished + // only finishes it (r131a). + pbf_press_button(context, BUTTON_A, 80ms, 1500ms); + context.wait_for_all_requests(); + VideoSnapshot shown = stream.video().snapshot(); + if (!before || !shown){ + return read; + } + const double opened = walk_screen_change(extract_box_reference(*before.frame, SIGN_BOX), extract_box_reference(*shown.frame, SIGN_BOX)); + read.opened = opened > SIGN_BOX_OPENED; + if (!read.opened){ + stream.log("[Sign] " + label + ": no box opened (change " + std::to_string(opened) + ")."); + return read; + } + // Tesseract read the Lab's white-on-grey text as "e R O e IO" (r131a). + // Only to say which sign, when there is a reader for the game's + // language; the box opening and closing is the check. + if (story_reads_text()){ + read.text = OCR::ocr_read(story_language(), extract_box_reference(*shown.frame, SIGN_TEXT), OCR::PageSegMode::SINGLE_BLOCK); + } + stream.log("[Sign] " + label + ": reads \"" + read.text + "\" (change " + std::to_string(opened) + ")."); + for (size_t presses = 0; presses < 3 && !read.closed; presses++){ + pbf_press_button(context, BUTTON_B, 80ms, 1000ms); + context.wait_for_all_requests(); + VideoSnapshot after = stream.video().snapshot(); + read.closed = after && walk_screen_change(extract_box_reference(*before.frame, SIGN_BOX), extract_box_reference(*after.frame, SIGN_BOX)) < SIGN_BOX_OPENED; + } + stream.log("[Sign] " + label + (read.closed ? ": closed." : ": still open.")); + return read; +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h new file mode 100644 index 0000000000..ceceef7d0e --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h @@ -0,0 +1,105 @@ +/* BDSP AutoStory - Talks + * + * From: https://github.com/PokemonAutomation/ + * + * Talking to people and fighting the trainers among them, and the looks + * at the screen the story's events decide by. Measured on the console + * (segment 01, 2026-10-29 to 10-31; the Jubilife talks, 2026-10-30). + * + */ + +// code-health: allow header_symbols -- dialogue and screen-detection primitives for story interactions that callers need together +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Talks_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Talks_H + +#include +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Tools/VideoStream.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonBDSP_AutoStory_Battle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Fails the step with a screenshot of the screen now. +[[noreturn]] void fail_step(VideoStream& stream, const std::string& message); + +// True if a dialogue opens within `timeout`: someone who stopped us as the +// walk ended reads as BLOCKED, and their box comes up a moment later. +bool dialogue_opens(VideoStream& stream, ProControllerContext& context, Milliseconds timeout); + +// For a dialogue that has opened: B through it. A trainer's ends in a +// battle, which is fought with the best move (Potions when HP runs low), +// followed by a Potion if HP is under half. Anyone else's ends back in the +// overworld. Returns whether there was a battle. Between a trainer's last +// line and the battle the overworld shows with no dialogue for a moment, +// so "only talked" needs 4 s of it, and never comes when `expect` is +// BATTLE. `format` DOUBLES for tag and twin battles. A lost battle ends in +// the last Pokemon Center; see in_pokemon_center(). +enum class TalkExpect{ + TALK_OR_BATTLE, + BATTLE, +}; +// Handles dialogue interaction or battle sequence with an NPC or trainer. +bool talk_or_fight( + VideoStream& stream, ProControllerContext& context, const std::string& label, + TalkExpect expect = TalkExpect::TALK_OR_BATTLE, BattleFormat format = BattleFormat::SINGLES +); + +// Fights a trainer whose dialogue has opened, with whatever starter we +// have, then a Potion if HP is under half. Someone who only talks leaves +// no battle to fight. How the story's planned walks fight (RouteTrainerFight). +void fight_route_trainer(VideoStream& stream, ProControllerContext& context, const std::string& name); + +// A rough check that we stand in a Pokemon Center: its floor fills the lower +// half of the screen with warm yellow, where the gym is grey and routes are +// green. After a battle it tells a loss (a whiteout ends at the counter) +// from a win. `percent`, if given, gets the warm share of the lower half. +bool center_floor_on_screen(const ImageViewRGB32& screen, size_t* percent = nullptr); +// In a Pokemon Center: its floor on screen, and a room (indoors()). Floor +// colour alone read Jubilife's yellow plaza as a Center (63 %, r79) and +// Sandgem's and Oreburgh's streets at 30 to 35 %; of 635 lab frames, the +// two together pick out exactly the Center interiors. +bool pokemon_center_on_screen(const ImageViewRGB32& screen, size_t* percent = nullptr); +// Checks whether the console stream currently shows the interior of a Pokemon Center. +bool in_pokemon_center(VideoStream& stream); +// The Oreburgh Mine's hall and corridors are dim: mean brightness 45 to 64 +// on the console, against 99 to 116 for the city and its yard (2026-10-31). +bool in_dim_cave(VideoStream& stream, uint64_t below = 85); +// Mean of the three channels over a small copy of the frame, 0 to 255. +uint64_t mean_brightness(const ImageViewRGB32& screen); + +// What a talk showed: whether a dialogue opened, whether it had closed +// after, and what OCR read in its first box. +struct DialogueRead{ + bool opened = false; + bool closed = false; + std::string text; +}; +// Whether a sign's OCR text has `key` (lower case), ignoring case. +bool sign_text_matches(const std::string& text, const std::string& key); +// Faces `direction` and presses A. If a dialogue opens, reads its first +// box, then presses `next` once per line, 1.5 s apart, while it shows. +DialogueRead talk_facing(VideoStream& stream, ProControllerContext& context, Pokemon::Direction direction, Button next, const std::string& label); +// Presses A the way we face, without the turn talk_facing() taps first: a +// turn tap the way we already face is a step. +DialogueRead talk_ahead(VideoStream& stream, ProControllerContext& context, Button next, const std::string& label); +// Walks `direction`, pressing A after each short stretch, for at most +// `tiles` tiles' time until someone answers; then one A per line, 1.5 s +// apart, while the box shows. +DialogueRead talk_walking(VideoStream& stream, ProControllerContext& context, Pokemon::Direction direction, size_t tiles, const std::string& label); +// Faces `facing` and presses A: whether a box opened at the bottom of +// the screen (a sign's may be green, not a dialogue's), what OCR reads +// in it, and whether B closed it. +DialogueRead read_sign(VideoStream& stream, ProControllerContext& context, Pokemon::Direction facing, const std::string& label); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp index eb982fef43..fed0c55f4c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp @@ -30,13 +30,14 @@ RobustPlanCosts waypoint_plan_costs(){ } RobustPlanCosts town_plan_costs(){ + // Open legs go on the D-pad now, a whole tile a tap, so they land exactly + // at any length ("south 5" went 6 in r134a on stick holds). A wall at a + // leg's end is still worth a little: r64 went 38 tiles round the town + // to end each leg on one, for 12 straight. RobustPlanCosts costs; - // A tile's hold moves exactly a tile; a longer open leg may end a tile - // either way ("south 5" went 6 in r134a), so the plan ends on a wall. - costs.exact_open_tiles = 1; - costs.open_error_per = 8; - costs.leg_not_at_wall = 6; - costs.per_open_tile = 2; + costs.exact_open_tiles = costs.max_open_tiles; + costs.per_open_tile = 1; + costs.leg_not_at_wall = 4; return costs; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index d6f7a67b80..a3cb3e6495 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -70,6 +70,11 @@ void StoryWorld::add(std::string name, const Pokemon::MapData& map, const TilePo placed.warps.push_back({warp.x, warp.y}); } check_overlap(placed); + Pokemon::MapData connected = map; + connected.name = placed.name; + connected.world = Pokemon::MapWorld{"story", offset}; + m_connected.push_back(std::move(connected)); + Pokemon::connect_by_world(m_connected); m_maps.push_back(std::move(placed)); rebuild(); } @@ -271,6 +276,10 @@ std::optional StoryWorld::to_local(const TilePos& world) const{ +Pokemon::ConnectedMaps connected_maps(const StoryWorld& world){ + return Pokemon::ConnectedMaps(world.m_connected); +} + bool covered(const StoryWorld& world, const TilePos& pos){ return world.tile(pos).has_value(); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index cf46b6f0c5..b7c57f01db 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -11,6 +11,10 @@ * plan may not end there, but walking into one is not a wall, since it may * be an exit. * + * The same maps are also kept as connected maps (Pokemon::ConnectedMaps), + * joined where they meet on the world grid, for planning on a map and a + * tile instead of the grid. + * */ #ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryWorld_H @@ -19,6 +23,7 @@ #include #include #include +#include "Pokemon/Navigation/Pokemon_ConnectedMaps.h" #include "Pokemon/Navigation/Pokemon_Grid.h" #include "Pokemon/Navigation/Pokemon_MapData.h" @@ -71,6 +76,7 @@ class StoryWorld{ // The map that holds a world tile, or nothing between maps. std::optional to_local(const Pokemon::TilePos& world) const; + friend Pokemon::ConnectedMaps connected_maps(const StoryWorld& world); friend std::vector wandering_hazards(const StoryWorld& world); friend bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); friend bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); @@ -102,6 +108,7 @@ class StoryWorld{ Cell* cell(const Pokemon::TilePos& pos); std::vector m_maps; + std::vector m_connected; Pokemon::TilePos m_origin; // offset of world tile (0,0) Pokemon::Grid m_cells; std::vector m_blocked; // world tiles, kept across add() @@ -109,6 +116,13 @@ class StoryWorld{ }; +// The world's maps as added, under their names in it, joined where they +// meet. Tiles blocked or taken off the maps are not in them. The view +// lasts until the world's next add(). +Pokemon::ConnectedMaps connected_maps(const StoryWorld& world); +// A temporary world would be gone before the view is used. +Pokemon::ConnectedMaps connected_maps(StoryWorld&& world) = delete; + // The rules of walking on a story world, from its tiles. // All tiles where someone wanders on the maps, in world coordinates. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp new file mode 100644 index 0000000000..9e10c1ac1f --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp @@ -0,0 +1,280 @@ +/* BDSP AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + * Adapted from PokemonAutomation/Arduino-Source#1717 by Developer-Butters. + * + */ + +#include +#include +#include +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/VideoPipeline/VideoOverlay.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "Pokemon/AutoStory/Pokemon_StoryPreflight.h" +#include "Pokemon/AutoStory/Pokemon_StoryRun.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.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/Options/Pokemon_StoryRunOptions.h" +#include "PokemonBDSP/Programs/PokemonBDSP_GameEntry.h" +#include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" +#include "PokemonBDSP_AutoStory_StoryTable.h" +#include "PokemonBDSP_AutoStory.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; + + +BDSPAutoStory_Descriptor::BDSPAutoStory_Descriptor() + : SingleSwitchProgramDescriptor( + "PokemonBDSP:AutoStory", + "Pokemon BDSP", "Auto Story", + "Programs/PokemonBDSP/AutoStory.html", + "Automatically completes BDSP story segments.", + PanelQualityStanding::OFFICIAL_BETA, + ProgramControllerClass::StandardController_NoRestrictions, + FeedbackType::REQUIRED, + AllowCommandsWhenRunning::DISABLE_COMMANDS, + {"Tesseract"} + ) +{} + +std::unique_ptr BDSPAutoStory_Descriptor::make_stats() const{ + return std::make_unique(); +} + + +namespace{ + +// The start and end dropdowns' entries: segments 00 and 01 joined, 00.00 +// to 01.11. The options hold a reference to it. +const StringSelectDatabase& checkpoint_database(){ + static const StringSelectDatabase database = []{ + std::vector labels; + for (const StoryCheckpoint& row : story_checkpoints()){ + labels.push_back(story_checkpoint_label(row)); + } + return Pokemon::story_checkpoint_database(labels); + }(); + return database; +} + +std::set rows_that_stop(const std::vector& rows){ + std::set ids; + for (const StoryCheckpoint& row : rows){ + if (row.on_failure == StoryFailure::STOP){ + ids.insert(row.id); + } + } + return ids; +} + +// What BDSP lends the shared shell: the console's preflight; a load is a +// reset from HOME, which loads the save the row made at its start; the +// engine's lines go to the console's log. +Pokemon::StoryGameHooks story_game(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + Pokemon::StoryGameHooks game; + game.preflight = [&env, &context]{ + return Pokemon::StoryPreflight::read(env.console, context); + }; + game.load_save = [&env, &context](Pokemon::RunState&){ + if (!reset_game_from_home(env, env.console, context, true, 1000ms)){ + return Pokemon::outcome_failed("reload_failed", "Failed to reset the game from HOME."); + } + return Pokemon::outcome_ok(); + }; + game.log = [&env](const std::string& line){ + env.log(line, COLOR_BLUE); + }; + game.status = [&env](const std::string& line){ + env.console.overlay().add_log(line); + }; + return game; +} + +// Verify mode: the checkpoint run as `policy` says, from the save the +// start loaded. Rows save at their start, never at their end, so each +// reload between runs loads that same save. Throws unless enough runs pass. +std::string verify_story_checkpoint( + const std::string& id, const Pokemon::VerifyPolicy& policy, + Pokemon::Segment& segment, Pokemon::StoryGameHooks& game, Pokemon::RunState& state +){ + Pokemon::SegmentHooks hooks = Pokemon::story_segment_hooks(game); + Pokemon::VerifyReport report; + try{ + report = Pokemon::verify_checkpoint(id, policy, segment, hooks, state); + }catch (OperationFailedException&){ + Pokemon::log_story_failure(game); + throw; + } + return Pokemon::finish_story_verify(id, policy, report, game); +} + +} // namespace + + +BDSPAutoStory::BDSPAutoStory() + : RUN(checkpoint_database(), Pokemon::Gen8ToGen9Languages_Database()) + , NEW_GAME_INTRO( + "Start a new game first:
" + "For a game with no save: restart it and play the intro (language, appearance, names) " + "until the player is in control in the bedroom. Only when starting at 00.00.", + LockMode::LOCK_WHILE_RUNNING, false + ) + , PLAYER_NAME(false, "Player name:
For a new game. Letters and digits.", LockMode::LOCK_WHILE_RUNNING, "Kosmos", "Kosmos") + , STARTER( + "Starter Pokemon:", + { + {StarterChoice::TURTWIG, "turtwig", "Turtwig"}, + {StarterChoice::CHIMCHAR, "chimchar", "Chimchar"}, + {StarterChoice::PIPLUP, "piplup", "Piplup"}, + }, + LockMode::LOCK_WHILE_RUNNING, + StarterChoice::CHIMCHAR + ) + , NOTIFICATIONS({ + &NOTIFICATION_PROGRAM_FINISH, + &NOTIFICATION_ERROR_RECOVERABLE, + &NOTIFICATION_ERROR_FATAL, + }) +{ + PA_ADD_OPTION(RUN); + PA_ADD_OPTION(NEW_GAME_INTRO); + PA_ADD_OPTION(PLAYER_NAME); + PA_ADD_OPTION(STARTER); + PA_ADD_OPTION(NOTIFICATIONS); +} + +namespace{ + +// The checkpoints whose start save is skipped: the first one, unless the +// run starts a new game. After a load its save is already there (saving +// again cost ~10 s), and nothing saves before the start is confirmed. +std::set saved_before_the_run(const std::vector& checkpoints, size_t first, Pokemon::StoryStart start){ + if (Pokemon::story_first_save_allowed(start)){ + return {}; + } + return {checkpoints[first].id}; +} + +// "" when the save screen's card names `place`, the map the start row +// saved in, else why not. Opens the save screen and backs out unsaved. +std::string check_start_place(SingleSwitchProgramEnvironment& env, ProControllerContext& context, const std::string& place){ + if (place.empty()){ + return ""; + } + const std::string read = read_location_from_save_screen(env.console, context); + if (location_banner_matches(read, place)){ + return ""; + } + return std::format("The save is in \"{}\", not {}.", read, place); +} + +// Gets the game to where `row` starts through the shared start gate: +// preflight, then (for a save) the load and the save card's place. Throws a +// setup error when the preflight failed, nothing pressed, and an +// OperationFailedException when the load or place check failed, unsaved. +void start_story( + SingleSwitchProgramEnvironment& env, ProControllerContext& context, const StoryCheckpoint& row, + Pokemon::StoryStart start, Pokemon::StoryGameHooks& game, Pokemon::RunState& state +){ + // The loaded save must be where the start row saved; a retry's reload + // in a later row is checked by that row's own start save. + game.check_save_place = [&env, &context, place = row.saves_in]{ + return check_start_place(env, context, place); + }; + const Pokemon::Outcome loaded = Pokemon::prepare_story_start(row.id, start, game, state); + game.check_save_place = nullptr; + if (loaded.failure == Pokemon::StoryPreflight::FAILURE){ + throw UserSetupError(env.console, std::format("AutoStory did not start, nothing was pressed: {}", loaded.detail)); + } + if (!loaded.succeeded()){ + Pokemon::log_story_failure(game); + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format("AutoStory could not load the save for {}: {}", row.id, Pokemon::to_string(loaded)) + ); + } +} + +// The run from `range`'s first checkpoint to its last, its counts in the +// stats. Returns the finish line; throws if it stopped short. +std::string run_story( + const Pokemon::SegmentRange& range, const Pokemon::SegmentPolicy& policy, + Pokemon::Segment& segment, Pokemon::StoryGameHooks& game, Pokemon::RunState& state, + SingleSwitchProgramEnvironment& env +){ + Pokemon::SegmentHooks hooks = Pokemon::story_segment_hooks(game); + Pokemon::SegmentReport report; + try{ + report = run_segment(range, policy, segment, hooks, state); + }catch (OperationFailedException&){ + Pokemon::log_story_failure(game); + throw; + } + Pokemon::AutoStoryStats& stats = env.current_stats(); + std::string done; + try{ + done = Pokemon::finish_story_run(report, range.to.value_or(""), stats, game); + }catch (OperationFailedException&){ + env.update_stats(); + throw; + } + env.update_stats(); + return done; +} + +} // namespace + +void BDSPAutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + const std::vector& checkpoints = story_checkpoints(); + const size_t first = RUN.start_index(); + const size_t last = RUN.end_index(); + if (first > last || last >= checkpoints.size()){ + throw UserSetupError(env.console, "The start checkpoint must not come after the end checkpoint."); + } + // The reads that use text (Location.h) take the game's language from here. + set_story_language(RUN.language()); + + StoryEnv story{env, context, STARTER, PLAYER_NAME}; + StoryExecutor executor(story); + executor.set_stop_rows(rows_that_stop(checkpoints)); + // A start with a save always loads it first, so the run never walks + // from wherever the game was left (console B, 2026-11-11: a run from + // 00.04b walked from 00.04d's position). + const bool new_game = first == 0 && NEW_GAME_INTRO; + const Pokemon::StoryStart start = new_game ? Pokemon::StoryStart::NEW_GAME : Pokemon::StoryStart::FROM_SAVE; + if (new_game && RUN.VERIFY.policy()){ + throw UserSetupError(env.console, "Verify mode reloads the start's save between runs: turn off \"Start a new game first\"."); + } + std::set saved = saved_before_the_run(checkpoints, first, start); + Pokemon::Segment segment = make_story_segment(checkpoints, executor, saved); + Pokemon::StoryGameHooks game = story_game(env, context); + Pokemon::RunState state; + start_story(env, context, checkpoints[first], start, game, state); + if (const std::optional verify = RUN.VERIFY.policy()){ + const std::string summary = verify_story_checkpoint(checkpoints[first].id, *verify, segment, game, state); + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH, summary); + return; + } + const std::string done = run_story( + Pokemon::SegmentRange{checkpoints[first].id, checkpoints[last].id}, RUN.policy(), segment, game, state, env + ); + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH, done); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h new file mode 100644 index 0000000000..154eccade4 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h @@ -0,0 +1,61 @@ +/* BDSP AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + * Adapted from PokemonAutomation/Arduino-Source#1717 by Developer-Butters. + * + * Plays Brilliant Diamond / Shining Pearl from a new game to Floaroma Town: + * the story table (PokemonBDSP_AutoStory_StoryTable.h) run by the shared + * story engine, from the start checkpoint to the end one. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_H +#define PokemonAutomation_PokemonBDSP_AutoStory_H + +#include "Common/Cpp/Options/BooleanCheckBoxOption.h" +#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "Common/Cpp/Options/StringOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "Pokemon/Options/Pokemon_StoryRunOptions.h" +#include "PokemonBDSP_AutoStory_StoryExecutor.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Descriptor for the BDSP AutoStory single-switch program. +class BDSPAutoStory_Descriptor : public SingleSwitchProgramDescriptor{ +public: + BDSPAutoStory_Descriptor(); + + virtual std::unique_ptr make_stats() const override; +}; + + +// Single-switch program instance executing BDSP story automation. +class BDSPAutoStory : public SingleSwitchProgramInstance{ +public: + using Descriptor = BDSPAutoStory_Descriptor; + BDSPAutoStory(); + + virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; + +private: + // The start and end checkpoints, attempts, checks and language. + Pokemon::StoryRunOptions RUN; + BooleanCheckBoxOption NEW_GAME_INTRO; + StringOption PLAYER_NAME; + EnumDropdownOption STARTER; + + EventNotificationsOption NOTIFICATIONS; +}; + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlanGolden.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlanGolden.h new file mode 100644 index 0000000000..e63fe2d69b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlanGolden.h @@ -0,0 +1,281 @@ +/* BDSP AutoStory Plan Golden + * + * From: https://github.com/PokemonAutomation/ + * + * The legs the planner plans for every ROUTE of the story simulation + * (PokemonBDSP_AutoStory_StorySimulation_Tests.cpp, "plans match the + * golden"): per route a header " costs= from + * to ", then one line per leg with the tiles it may end on. + * One string per line: MSVC caps a single literal at 16 KB. + * Regenerate from the test's failure log; see test_golden_plans(). + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_PlanGolden_H +#define PokemonAutomation_PokemonBDSP_AutoStory_PlanGolden_H + +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +// The stored plan lines, in the order the simulation plans them. +inline constexpr std::string_view BDSP_PLAN_GOLDEN[] = { + "00.01 below_the_flute costs=default from PlayerHouse2F (4, 6) to PlayerHouse2F (7, 5)", + "00.01 north 1 (to wall) -> PlayerHouse2F (4, 5)", + "00.01 east 3 (open) -> PlayerHouse2F (7, 5)", + "00.01 onto_the_flute_tile costs=default from PlayerHouse2F (7, 5) to PlayerHouse2F (8, 4)", + "00.01 north 1 (to wall) -> PlayerHouse2F (7, 4)", + "00.01 east 1 (to wall) -> PlayerHouse2F (8, 4)", + "00.01 above_the_door costs=default from PlayerHouse1F (10, 3) (10, 4) to PlayerHouse1F (6, 9)", + "00.01 south 7 (to wall) -> PlayerHouse1F (10, 10)", + "00.01 north 1 (open) -> PlayerHouse1F (10, 9)", + "00.01 west 4 (open) -> PlayerHouse1F (6, 9)", + "00.01 short_of_barrys_door costs=default from TwinleafTown (20, 22) to TwinleafTown (10, 12)", + "00.01 west 7 (open) -> Twinleaf Town (13, 22)", + "00.01 north 10 (to wall) -> Twinleaf Town (13, 12)", + "00.01 west 3 (open) -> Twinleaf Town (10, 12)", + "00.01 back_onto_barrys_doorstep costs=default from TwinleafTown (9, 13) to TwinleafTown (9, 12)", + "00.01 north 1 (open) -> Twinleaf Town (9, 12)", + "00.01 below_barrys_stairs costs=default from RivalHouse1F (6, 9) to RivalHouse1F (2, 3)", + "00.01 west 4 (to wall) -> RivalHouse1F (2, 9)", + "00.01 north 6 (to wall) -> RivalHouse1F (2, 3)", + "00.01 above_barrys_stairs costs=default from RivalHouse2F (3, 5) to RivalHouse2F (3, 4)", + "00.01 north 1 (to wall) -> RivalHouse2F (3, 4)", + "00.01 above_barrys_door costs=default from RivalHouse1F (2, 3) to RivalHouse1F (6, 9)", + "00.01 south 6 (open) -> RivalHouse1F (2, 9)", + "00.01 east 4 (open) -> RivalHouse1F (6, 9)", + "00.01 below_barrys_warning costs=default from TwinleafTown (9, 12) to Route201 (15, 19)", + "00.01 east 6 (open) -> Twinleaf Town (15, 12)", + "00.01 north 24 (to wall) -> Route 201 (15, 13)", + "00.01 south 6 (open) -> Route 201 (15, 19)", + "00.01 away_from_barry costs=default from Route201 (15, 18) to Route201 (12, 17)", + "00.01 north 1 (open) -> Route 201 (15, 17)", + "00.01 west 3 (open) -> Route 201 (12, 17)", + "00.01 below_the_lake_entrance costs=default from Route201 (12, 17) to VerityLakefront (17, 14)", + "00.01 north 1 (open) -> Route 201 (12, 16)", + "00.01 west 26 (to wall) -> Verity Lakefront (18, 23)", + "00.01 north 9 (to wall) -> Verity Lakefront (18, 14)", + "00.01 west 1 (open) -> Verity Lakefront (17, 14)", + "00.02 to_the_lake_entrance costs=default from VerityLakefront (17, 14) to VerityLakefront (17, 13)", + "00.02 north 1 (open) -> Verity Lakefront (17, 13)", + "00.03 short_of_rowan costs=default from VerityLakefront (17, 14) (17, 15) to Route201 (4, 14)", + "00.03 south 7 (to wall) -> Verity Lakefront (17, 21)", + "00.03 east 19 (open) -> Route 201 (4, 14)", + "00.03 by_the_counter costs=default from PlayerHouse1F (5, 8) (6, 8) to PlayerHouse1F (4, 8)", + "00.03 west 2 (to wall) -> PlayerHouse1F (4, 8)", + "00.03 above_the_door_again costs=default from PlayerHouse1F (4, 8) to PlayerHouse1F (6, 9)", + "00.03 east 2 (open) -> PlayerHouse1F (6, 8)", + "00.03 south 1 (open) -> PlayerHouse1F (6, 9)", + "00.03 short_of_dawn costs=default from TwinleafTown (20, 22) to Route201 (63, 5)", + "00.03 west 3 (open) -> Twinleaf Town (17, 22)", + "00.03 north 34 (to wall) -> Route 201 (17, 13)", + "00.03 east 40 (to wall) -> Route 201 (57, 13)", + "00.03 west 7 (open) -> Route 201 (50, 13)", + "00.03 north 10 (to wall) -> Route 201 (50, 3)", + "00.03 east 13 (to wall) -> Route 201 (63, 3)", + "00.03 south 2 (open) -> Route 201 (63, 5)", + "00.04 onto_the_path costs=town from SandgemTown (26, 11) (27, 11) (28, 11) (26, 12) (27, 12) (28, 12) to SandgemTown (29, 12)", + "00.04 east 3 (to wall) -> Sandgem Town (29, 11) Sandgem Town (29, 12)", + "00.04 north 1 (to wall) -> Sandgem Town (29, 11)", + "00.04 south 1 (open) -> Sandgem Town (29, 12)", + "00.04 home costs=default from Route201 (57, 5) (58, 5) (59, 5) (60, 5) (61, 5) (62, 5) (63, 5) to TwinleafTown (20, 22) (20, 23) (20, 24) (20, 25) (20, 26)", + "00.04 west 21 (to wall) -> Route 201 (42, 5)", + "00.04 south 4 (open) -> Route 201 (42, 9)", + "00.04 west 28 (to wall) -> Route 201 (14, 9)", + "00.04 south 42 (to wall) -> Twinleaf Town (14, 26)", + "00.04 east 6 (open) -> Twinleaf Town (20, 26)", + "00.04 beside_mom costs=default from PlayerHouse1F (6, 9) to PlayerHouse1F (6, 7)", + "00.04 north 2 (open) -> PlayerHouse1F (6, 7)", + "00.04 around_mom costs=default from PlayerHouse1F (6, 7) to PlayerHouse1F (5, 9)", + "00.04 south 2 (open) -> PlayerHouse1F (6, 9)", + "00.04 west 1 (to wall) -> PlayerHouse1F (5, 9)", + "00.04 short_of_the_catch_tutorial costs=default from TwinleafTown (19, 22) to Route202 (22, 27)", + "00.04 west 2 (open) -> Twinleaf Town (17, 22)", + "00.04 north 34 (to wall) -> Route 201 (17, 13)", + "00.04 east 40 (to wall) -> Route 201 (57, 13)", + "00.04 west 7 (open) -> Route 201 (50, 13)", + "00.04 north 7 (open) -> Route 201 (50, 6)", + "00.04 east 43 (to wall) -> Sandgem Town (29, 13)", + "00.04 west 5 (open) -> Sandgem Town (24, 13)", + "00.04 north 21 (to wall) -> Route 202 (25, 24)", + "00.04 west 3 (to wall) -> Route 202 (22, 24)", + "00.04 south 3 (open) -> Route 202 (22, 27)", + "00.04b to_catch_grass costs=default from Route202 (15, 25) (16, 25) (17, 25) (18, 25) (19, 25) (20, 25) (21, 25) (15, 26) (16, 26) (17, 26) (18, 26) (19, 26) (20, 26) (21, 26) (15, 27) (16, 27) (17, 27) (18, 27) (19, 27) (20, 27) (21, 27) (21, 28) (21, 29) to Route202 (18, 25) (19, 25) (20, 25) (18, 26) (19, 26) (20, 26) (18, 27) (19, 27) (20, 27)", + "00.04b east 15 (to wall) -> Route 202 (23, 25) Route 202 (30, 26) Route 202 (30, 27) Route 202 (30, 28) Route 202 (30, 29)", + "00.04b north 5 (to wall) -> Route 202 (23, 24) Route 202 (30, 24)", + "00.04b west 8 (to wall) -> Route 202 (22, 24)", + "00.04b south 1 (open) -> Route 202 (22, 25)", + "00.04b west 2 (open) -> Route 202 (20, 25)", + "00.04b into_sandgem costs=robust from Route202 (18, 25) (19, 25) (20, 25) (18, 26) (19, 26) (20, 26) (18, 27) (19, 27) (20, 27) to SandgemTown (29, 5)", + "00.04b south 2 (to wall) -> Route 202 (18, 27) Route 202 (19, 27) Route 202 (20, 27)", + "00.04b east 12 (to wall) -> Route 202 (30, 27)", + "00.04b south 10 (to wall) -> Sandgem Town (29, 5)", + "00.04b below_center_door costs=town from SandgemTown (29, 5) to SandgemTown (17, 11)", + "00.04b west 5 (open) -> Sandgem Town (24, 5)", + "00.04b south 6 (open) -> Sandgem Town (24, 11)", + "00.04b west 7 (open) -> Sandgem Town (17, 11)", + "00.04d north_to_jubilife costs=default from Route202 (30, 24) to Route202 (11, 0) (12, 0) (13, 0) (14, 0) (15, 0) (16, 0) (17, 0) (18, 0) (11, 1) (12, 1) (13, 1) (14, 1) (15, 1) (16, 1) (17, 1) (18, 1) (11, 2) (12, 2) (13, 2) (14, 2) (15, 2) (16, 2) (17, 2) (18, 2) (11, 3) (12, 3) (13, 3) (14, 3) (15, 3) (16, 3) (17, 3) (18, 3)", + "00.04d south 2 (open) -> Route 202 (30, 26)", + "00.04d west 27 (to wall) -> Route 202 (3, 26)", + "00.04d north 12 (to wall) -> Route 202 (3, 14)", + "00.04d east 14 (to wall) -> Route 202 (17, 14)", + "00.04d south 8 (to wall) -> Route 202 (17, 22)", + "00.04d east 13 (to wall) -> Route 202 (30, 22)", + "00.04d north 18 (to wall) -> Route 202 (30, 4)", + "00.04d south 1 (open) -> Route 202 (30, 5)", + "00.04d west 12 (open) -> Route 202 (18, 5)", + "00.04d north 2 (open) -> Route 202 (18, 3)", + "00.05 to_the_center costs=town from JubilifeCity (48, 62) to JubilifeCity (52, 41)", + "00.05 west 1 (open) -> Jubilife City (47, 62)", + "00.05 north 21 (open) -> Jubilife City (47, 41)", + "00.05 east 5 (open) -> Jubilife City (52, 41)", + "00.05 to_the_school costs=town from JubilifeCity (52, 41) to JubilifeCity (40, 41)", + "00.05 west 12 (open) -> Jubilife City (40, 41)", + "00.05b below_the_presidents_trigger costs=town from JubilifeCity (40, 41) to JubilifeCity (46, 41)", + "00.05b east 6 (open) -> Jubilife City (46, 41)", + "00.05b past_the_president costs=default from JubilifeCity (46, 40) to JubilifeCity (48, 40)", + "00.05b east 2 (open) -> Jubilife City (48, 40)", + "00.05b below_the_mart_clown costs=town from JubilifeCity (48, 40) to JubilifeCity (55, 34)", + "00.05b north 6 (open) -> Jubilife City (48, 34)", + "00.05b east 7 (open) -> Jubilife City (55, 34)", + "00.05b below_the_tv_clown costs=town from JubilifeCity (55, 34) to JubilifeCity (36, 17)", + "00.05b west 23 (to wall) -> Jubilife City (32, 34)", + "00.05b north 10 (open) -> Jubilife City (32, 24)", + "00.05b east 4 (open) -> Jubilife City (36, 24)", + "00.05b north 7 (open) -> Jubilife City (36, 17)", + "00.05b below_the_company_clown costs=town from JubilifeCity (36, 17) to JubilifeCity (15, 19)", + "00.05b south 4 (open) -> Jubilife City (36, 21)", + "00.05b west 21 (open) -> Jubilife City (15, 21)", + "00.05b north 2 (open) -> Jubilife City (15, 19)", + "00.05c below_the_president costs=town from JubilifeCity (15, 19) to JubilifeCity (46, 36)", + "00.05c south 5 (open) -> Jubilife City (15, 24)", + "00.05c east 29 (open) -> Jubilife City (44, 24)", + "00.05c south 12 (open) -> Jubilife City (44, 36)", + "00.05c east 2 (open) -> Jubilife City (46, 36)", + "00.05c to_the_route_203_street costs=town from JubilifeCity (46, 36) to JubilifeCity (58, 22)", + "00.05c east 1 (open) -> Jubilife City (47, 36)", + "00.05c north 14 (open) -> Jubilife City (47, 22)", + "00.05c east 11 (open) -> Jubilife City (58, 22)", + "01.01 west_of_barrys_trigger costs=town from JubilifeCity (58, 22) to Route203 (4, 18)", + "01.01 east 9 (open) -> Route 203 (4, 18)", + "01.02 south_to_the_cliff costs=default from Route203 (5, 17) (5, 18) (5, 19) (5, 20) to Route203 (5, 20)", + "01.02 south 3 (to wall) -> Route 203 (5, 20)", + "01.02 by_the_gate costs=default from Route203 (5, 20) to Route203 (55, 9)", + "01.02 north 2 (open) -> Route 203 (5, 18)", + "01.02 east 50 (to wall) -> Route 203 (55, 18)", + "01.02 north 9 (open) -> Route 203 (55, 9)", + "01.02 west_of_the_hikers_trigger costs=default from OreburghGate (4, 22) (5, 22) to OreburghGate (6, 22)", + "01.02 south 1 (to wall) -> OreburghGate (4, 23) OreburghGate (5, 23)", + "01.02 east 2 (to wall) -> OreburghGate (6, 23)", + "01.02 north 1 (open) -> OreburghGate (6, 22)", + "01.02 past_curtis costs=default from OreburghGate (7, 22) to OreburghGate (20, 22)", + "01.02 east 13 (open) -> OreburghGate (20, 22)", + "01.02 by_the_east_mouth costs=default from OreburghGate (20, 22) to OreburghGate (27, 22)", + "01.02 east 7 (open) -> OreburghGate (27, 22)", + "01.02 west_of_the_welcome costs=default from OreburghCity (2, 13) (3, 13) to OreburghCity (9, 13)", + "01.02 north 3 (to wall) -> Oreburgh City (2, 10) Oreburgh City (3, 10)", + "01.02 east 4 (to wall) -> Oreburgh City (6, 10)", + "01.02 south 3 (open) -> Oreburgh City (6, 13)", + "01.02 east 3 (open) -> Oreburgh City (9, 13)", + "01.03 below_the_centers_door costs=town from OreburghCity (43, 21) (44, 21) (45, 21) (43, 22) (44, 22) (45, 22) to OreburghCity (47, 21)", + "01.03 east 5 (to wall) -> Oreburgh City (48, 21) Oreburgh City (48, 22)", + "01.03 north 1 (to wall) -> Oreburgh City (48, 21)", + "01.03 west 1 (open) -> Oreburgh City (47, 21)", + "01.03 above_the_mine costs=town from OreburghCity (47, 21) to OreburghCity (46, 58)", + "01.03 west 3 (open) -> Oreburgh City (44, 21)", + "01.03 south 20 (to wall) -> Oreburgh City (44, 41)", + "01.03 east 2 (open) -> Oreburgh City (46, 41)", + "01.03 south 17 (open) -> Oreburgh City (46, 58)", + "01.03 below_roark costs=default from OreburghMine (15, 9) to OreburghMine (18, 29)", + "01.03 east 2 (to wall) -> OreburghMine (17, 9)", + "01.03 south 2 (to wall) -> OreburghMine (17, 11)", + "01.03 west 2 (to wall) -> OreburghMine (15, 11)", + "01.03 south 6 (to wall) -> OreburghMine (15, 17)", + "01.03 east 14 (to wall) -> OreburghMine (29, 17)", + "01.03 south 10 (to wall) -> OreburghMine (29, 27)", + "01.03 west 3 (to wall) -> OreburghMine (26, 27)", + "01.03 south 2 (to wall) -> OreburghMine (26, 29)", + "01.03 west 8 (open) -> OreburghMine (18, 29)", + "01.03 below_the_coal_rooms_warp costs=default from OreburghMine (18, 29) to OreburghMine (15, 2)", + "01.03 east 9 (to wall) -> OreburghMine (27, 29)", + "01.03 north 5 (to wall) -> OreburghMine (27, 24)", + "01.03 east 2 (to wall) -> OreburghMine (29, 24)", + "01.03 north 8 (to wall) -> OreburghMine (29, 16)", + "01.03 west 16 (to wall) -> OreburghMine (13, 16)", + "01.03 east 2 (open) -> OreburghMine (15, 16)", + "01.03 north 5 (to wall) -> OreburghMine (15, 11)", + "01.03 east 2 (to wall) -> OreburghMine (17, 11)", + "01.03 north 2 (to wall) -> OreburghMine (17, 9)", + "01.03 west 4 (to wall) -> OreburghMine (13, 9)", + "01.03 north 7 (to wall) -> OreburghMine (13, 2)", + "01.03 east 2 (open) -> OreburghMine (15, 2)", + "01.03 below_the_centers_door_again costs=town from OreburghCity (45, 57) to OreburghCity (47, 21)", + "01.03 west 2 (to wall) -> Oreburgh City (43, 57)", + "01.03 north 16 (to wall) -> Oreburgh City (43, 41)", + "01.03 east 1 (open) -> Oreburgh City (44, 41)", + "01.03 north 21 (to wall) -> Oreburgh City (44, 20)", + "01.03 south 1 (open) -> Oreburgh City (44, 21)", + "01.03 east 3 (open) -> Oreburgh City (47, 21)", + "01.05 east_of_barrys_trigger costs=town from OreburghCity (26, 21) (26, 22) to OreburghCity (7, 13)", + "01.05 west 17 (to wall) -> Oreburgh City (9, 21) Oreburgh City (9, 22)", + "01.05 north 5 (to wall) -> Oreburgh City (9, 17)", + "01.05 east 2 (open) -> Oreburgh City (11, 17)", + "01.05 north 4 (open) -> Oreburgh City (11, 13)", + "01.05 west 4 (open) -> Oreburgh City (7, 13)", + "01.05 by_the_gate costs=default from OreburghCity (5, 13) to OreburghCity (2, 13)", + "01.05 west 3 (open) -> Oreburgh City (2, 13)", + "01.05 through_the_gate costs=default from OreburghGate (27, 22) (26, 22) to OreburghGate (4, 22)", + "01.05 south 1 (open) -> OreburghGate (26, 23) OreburghGate (27, 23)", + "01.05 west 19 (to wall) -> OreburghGate (8, 23)", + "01.05 north 1 (to wall) -> OreburghGate (8, 22)", + "01.05 west 4 (open) -> OreburghGate (4, 22)", + "01.06 below_rowans_trigger costs=town from Route203 (55, 9) to JubilifeCity (47, 8)", + "01.06 south 10 (to wall) -> Route 203 (55, 19)", + "01.06 west 17 (to wall) -> Route 203 (38, 19)", + "01.06 north 1 (open) -> Route 203 (38, 18)", + "01.06 west 57 (open) -> Jubilife City (44, 22)", + "01.06 north 14 (to wall) -> Jubilife City (44, 8)", + "01.06 east 3 (to wall) -> Jubilife City (47, 8)", + "01.08 west_to_the_wall costs=default from JubilifeCity (46, 5) (47, 5) to JubilifeCity (44, 5)", + "01.08 west 3 (to wall) -> Jubilife City (44, 5)", + "01.08 below_the_ravaged_path costs=town from JubilifeCity (44, 5) to Route204South (11, 2)", + "01.08 east 2 (open) -> Jubilife City (46, 5)", + "01.08 north 19 (to wall) -> Route 204 (14, 18)", + "01.08 west 2 (open) -> Route 204 (12, 18)", + "01.08 north 16 (to wall) -> Route 204 (12, 2)", + "01.08 west 1 (to wall) -> Route 204 (11, 2)", + "01.09 west_of_the_rock costs=default from RavagedPath (19, 50) to RavagedPath (21, 43)", + "01.09 north 7 (open) -> RavagedPath (19, 43)", + "01.09 east 2 (open) -> RavagedPath (21, 43)", + "01.09 above_the_way_out costs=default from RavagedPath (21, 43) to RavagedPath (28, 44)", + "01.09 east 8 (to wall) -> RavagedPath (29, 43)", + "01.09 south 1 (to wall) -> RavagedPath (29, 44)", + "01.09 west 1 (open) -> RavagedPath (28, 44)", + "01.10 line_1 costs=line from Route204North (20, 26) to Route204North (20, 27)", + "01.10 south 1 (open) -> Route 204 (20, 27)", + "01.10 line_2 costs=line from Route204North (20, 27) to Route204North (11, 27)", + "01.10 west 9 (open) -> Route 204 (11, 27)", + "01.10 line_3 costs=line from Route204North (11, 27) to Route204North (11, 22)", + "01.10 north 5 (open) -> Route 204 (11, 22)", + "01.10 line_4 costs=line from Route204North (11, 22) to Route204North (19, 22)", + "01.10 east 8 (open) -> Route 204 (19, 22)", + "01.10 line_5 costs=line from Route204North (19, 22) to Route204North (19, 12)", + "01.10 north 10 (open) -> Route 204 (19, 12)", + "01.10 line_6 costs=line from Route204North (19, 12) to Route204North (11, 12)", + "01.10 west 8 (open) -> Route 204 (11, 12)", + "01.10 line_7 costs=line from Route204North (11, 12) to Route204North (11, 5)", + "01.10 north 7 (open) -> Route 204 (11, 5)", + "01.10 into_floaroma costs=line from Route204North (11, 5) to FloaromaTown (11, 29)", + "01.10 north 8 (open) -> Floaroma Town (11, 29)", + "01.11 west_along_the_field costs=default from FloaromaTown (11, 29) to FloaromaTown (3, 29)", + "01.11 west 8 (open) -> Floaroma Town (3, 29)", + "01.11 below_the_old_man costs=default from FloaromaTown (4, 26) to FloaromaTown (3, 26)", + "01.11 west 1 (open) -> Floaroma Town (3, 26)", +}; + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp index a03a4692b7..61d1d2ba92 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp @@ -16,13 +16,22 @@ #include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Data/PokemonBDSP_AutoStory_Maps.h" +#include "Data/PokemonBDSP_AutoStory_PlanCosts.h" #include "Data/PokemonBDSP_AutoStory_RoutePlanner.h" #include "Data/PokemonBDSP_AutoStory_StoryMaps.h" #include "Data/PokemonBDSP_AutoStory_StoryTrainers.h" #include "Data/PokemonBDSP_AutoStory_TrainerSight.h" #include "Data/PokemonBDSP_AutoStory_WalkRules.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "Pokemon/AutoStory/Types/Pokemon_GridPose.h" +#include "PokemonBDSP_AutoStory_StoryExecutor.h" +#include "PokemonBDSP_AutoStory_StoryPlaces.h" +#include "PokemonBDSP_AutoStory_StoryTable.h" +#include "Utils/PokemonBDSP_AutoStory_StoryLanguage.h" #include "Utils/PokemonBDSP_AutoStory_PlannedRoute.h" #include "Utils/PokemonBDSP_AutoStory_RouteIO.h" +#include "Utils/PokemonBDSP_AutoStory_RouteTiming.h" #include "PokemonBDSP_AutoStory_PlannedRoute_Tests.h" #include "Utils/PokemonBDSP_AutoStory_WalkResult.h" @@ -35,6 +44,10 @@ namespace{ using namespace std::chrono_literals; using Pokemon::Direction; +using Pokemon::GridPose; +using Pokemon::Pose; +using Pokemon::StoryStep; +using Pokemon::StoryStepKind; using Pokemon::TilePos; @@ -357,6 +370,355 @@ UnitTestResult test_open_leg_known_trainer(Logger&){ } +// The console as a small simulator: the player stands on one tile of +// `world`, walls and `obstacles` stop them, and every walk and tap moves +// them. Fails the case after `max_calls` calls (a walker that loops). +class SimulatedRouteIO : public RouteIO{ +public: + SimulatedRouteIO(const StoryWorld& world, TilePos at, std::vector obstacles, std::vector& notes) + : m_world(world) + , m_at(at) + , m_obstacles(std::move(obstacles)) + , m_notes(notes) + {} + + const TilePos& at() const{ + return m_at; + } + size_t tiles_walked() const{ + return m_walked; + } + + virtual WalkResult walk_to_wall(const RouteWallWalk& walk) override{ + count_call(); + const Milliseconds per_tile = route_ms_per_tile(walk.direction, MoveSpeed::WALK); + if (m_overshoot && walk.limit > ROUTE_START_DELAY){ + // A hold timed for n tiles (ROUTE_START_DELAY, then half a + // tile under n) goes on past them until a wall stops it. + const size_t tiles = (size_t)((walk.limit - ROUTE_START_DELAY + per_tile / 2) / per_tile); + const size_t want = tiles + (tiles * 35 + 99) / 100; + const size_t moved = move(walk.direction, want); + return {.stop = moved < want ? WalkStop::BLOCKED : WalkStop::LIMIT, .walked = walk.limit, + .wild_battles = 0, .moved_chunks = moved}; + } + const size_t moved = move(walk.direction, SIZE_MAX); + return {.stop = WalkStop::BLOCKED, .walked = ROUTE_START_DELAY + 800ms + per_tile * moved + per_tile / 2, + .wild_battles = 0, .moved_chunks = moved}; + } + // Fault class "a timed hold overshoots": a stick hold timed for n + // tiles goes 0..ceil(0.35 n) tiles further, unseen, until a wall stops + // it (lab-B 2026-11-11, Jubilife: runs timed for 10 tiles went about 13, + // three of three). D-pad taps are tile-exact (5 to 20 taps, every one + // moved) and walks to a wall end at the wall, so neither has a fault. + void overshoot_timed_holds(bool overshoot){ + m_overshoot = overshoot; + } + virtual WalkResult walk_taps(Direction direction, size_t tiles, const std::string&) override{ + count_call(); + const size_t moved = move(direction, tiles); + return {.stop = moved < tiles ? WalkStop::BLOCKED : WalkStop::LIMIT, .walked = 250ms * tiles, + .wild_battles = 0, .moved_chunks = moved}; + } + virtual void press(const RouteInput& input) override{ + // arrive() pauses for up to 3 s for a location banner the sim never + // shows: those pauses are not a walker that loops. + if (input.kind != RouteInputKind::PAUSE){ + count_call(); + } + // A tap under 100 ms only turns (route_turn_tap()). + if (input.kind == RouteInputKind::DPAD && input.hold >= 100ms){ + move(input.direction, input.count); + } + // A stick hold is timed: route_open_hold() is half a tile under n. + if (input.kind == RouteInputKind::STICK){ + const Milliseconds per_tile = route_ms_per_tile(input.direction, MoveSpeed::WALK); + const size_t tiles = (size_t)((input.hold + per_tile / 2) / per_tile); + const size_t over = m_overshoot ? (tiles * 35 + 99) / 100 : 0; + for (size_t press = 0; press < input.count; press++){ + move(input.direction, tiles + over); + } + } + } + virtual bool dialog_within(Milliseconds, Color) override{ + count_call(); + return false; + } + virtual bool holding_against_wall(Direction, const std::string&) override{ + count_call(); + return true; + } + virtual void look(const std::function&) override{} + virtual void note(const std::string& text, RouteNote kind) override{ + m_notes.push_back(text); + if (kind == RouteNote::FAILURE){ + throw RouteFailed{text}; + } + } + +private: + void count_call(){ + if (++m_calls > MAX_CALLS){ + throw RouteFailed{"the walker made more than " + std::to_string(MAX_CALLS) + " calls."}; + } + } + size_t move(Direction direction, size_t tiles){ + size_t moved = 0; + while (moved < tiles){ + const std::optional next = step(m_world, m_at, direction); + if (!next || std::find(m_obstacles.begin(), m_obstacles.end(), *next) != m_obstacles.end()){ + break; + } + m_at = *next; + moved++; + } + m_walked += moved; + return moved; + } + + static constexpr size_t MAX_CALLS = 300; + const StoryWorld& m_world; + TilePos m_at; + std::vector m_obstacles; + std::vector& m_notes; + size_t m_calls = 0; + size_t m_walked = 0; + bool m_overshoot = false; +}; + +StoryWorld jubilife_world(){ + StoryWorld world; + world.add("Jubilife City", story_map("JubilifeCity"), {0, 0}); + return world; +} + +// lab-B 2026-11-11 11:17 (00.05 to_the_center): a walk east stopped about +// 13 tiles short of the wall, which left 15 possible tiles, (49..53, +// 41..43). Something the map lacks stood east of us; with several possible +// tiles nothing was marked, so every replan chose "east 7 (to wall)" again, +// walked 0 tiles five times and gave up on "too many plans". A walk that +// never moved from several possible tiles must route around the tiles just +// past them. +UnitTestResult test_blocked_from_several_tiles(Logger&){ + const StoryWorld world = jubilife_world(); + std::vector from; + for (int y = 41; y <= 43; y++){ + for (int x = 49; x <= 53; x++){ + from.push_back({x, y}); + } + } + const TilePos goal{52, 41}; + std::vector notes; + SimulatedRouteIO io(world, {53, 41}, {{54, 41}}, notes); + RouteTrainers trainers{.sights = {}, .fight = [](const std::string&){}}; + try{ + walk_route(io, world, from, trainers, { + .goal = [goal](const TilePos& pos){ return pos == goal; }, + .label = "T", + .avoid = {}, + .costs = town_plan_costs(), + .speed = MoveSpeed::WALK, + }); + }catch (const RouteFailed& e){ + return "failed: " + e.message; + } + if (io.at() != goal){ + return "ended at " + Pokemon::to_string(io.at()) + ", not at (52, 41)."; + } + return true; +} + +size_t tiles_of(const std::vector& legs){ + size_t tiles = 0; + for (const PlannedLeg& leg : legs){ + tiles += leg.leg.tiles; + } + return tiles; +} + +// The fewest tiles from `from` to `goal` on Jubilife, open legs exact. +size_t jubilife_shortest(const StoryWorld& world, TilePos from, TilePos goal){ + const auto plan = plan_robust_route(world, from, goal, waypoint_plan_costs()); + return plan ? tiles_of(*plan) : 0; +} + +// lab-B 2026-11-11 13:38 (00.05 to_the_center from (48, 62)): "north 20 +// (open)" walked as a held run (3175 ms) overshot, the west leg after it +// stopped 9 tiles in, the walker put walls at (54, 41..43) and "arrived" +// at (52, 41) nowhere near the Center. Timed holds overshoot by up to +// ceil(0.35 n) tiles (three runs of 10 went about 13); taps are exact. +// With every timed hold overshooting the walk still ends on the tile. +UnitTestResult test_jubilife_center_held_overshoot(Logger&){ + const StoryWorld world = jubilife_world(); + const TilePos from{48, 62}; + const TilePos goal{52, 41}; + std::vector notes; + SimulatedRouteIO io(world, from, {}, notes); + io.overshoot_timed_holds(true); + RouteTrainers trainers{.sights = {}, .fight = [](const std::string&){}}; + try{ + walk_route(io, world, {from}, trainers, { + .goal = [goal](const TilePos& pos){ return pos == goal; }, + .label = "T", + .avoid = {}, + .costs = town_plan_costs(), + .speed = MoveSpeed::WALK, + }); + }catch (const RouteFailed& e){ + return "failed: " + e.message; + } + if (io.at() != goal){ + return "ended at " + Pokemon::to_string(io.at()) + ", not at (52, 41)."; + } + return true; +} + +// The same walk on the console: the kids at (52, 46) and (54, 46) stop a +// walk north up their columns. The walker replans from where it stopped +// and reaches the Center without a long way round. +UnitTestResult test_jubilife_center_kids(Logger&){ + const StoryWorld world = jubilife_world(); + const TilePos from{48, 62}; + const TilePos goal{52, 41}; + std::vector notes; + SimulatedRouteIO io(world, from, {{52, 46}, {54, 46}}, notes); + RouteTrainers trainers{.sights = {}, .fight = [](const std::string&){}}; + try{ + walk_route(io, world, {from}, trainers, { + .goal = [goal](const TilePos& pos){ return pos == goal; }, + .label = "T", + .avoid = {}, + .costs = town_plan_costs(), + .speed = MoveSpeed::WALK, + }); + }catch (const RouteFailed& e){ + return "failed: " + e.message; + } + if (io.at() != goal){ + return "ended at " + Pokemon::to_string(io.at()) + ", not at (52, 41)."; + } + const size_t least = jubilife_shortest(world, from, goal); + if (io.tiles_walked() * 10 > least * 13 + 40){ + return std::format("walked {} tiles where {} would do.", io.tiles_walked(), least); + } + return true; +} + +// One ROUTE step of the story table, from where the steps before it end. +struct StoryRoute{ + std::string name; + Pose from; + Pose goal; + std::string costs; +}; + +// Every ROUTE step whose start the table knows: a row's start, a ROUTE's +// target or a step's pose_after. Steps after any other step start +// unknown and are left out. +void add_story_route(const std::string& row, const StoryStep& step, std::optional& at, std::vector& routes){ + if (step.kind == StoryStepKind::ROUTE){ + const Pose goal = Pokemon::pose_of(Pokemon::story_arg(step.args, "target")); + if (at){ + routes.push_back({std::format("{} {}", row, step.name), *at, goal, step.action}); + } + at = goal; + }else{ + at.reset(); + } + if (step.pose_after){ + at = Pokemon::pose_of(*step.pose_after); + } +} +std::vector story_routes(){ + std::vector routes; + for (const StoryCheckpoint& row : story_checkpoints()){ + std::optional at; + if (row.start){ + at = Pokemon::pose_of(*row.start); + } + for (const StoryStep& step : row.steps){ + add_story_route(row.id, step, at, routes); + } + } + return routes; +} + +// Walks `route` from each of its start tiles on the simulated console, +// every timed hold overshooting if `overshoot`. Returns the tiles walked +// from each start, or why it failed. +std::string sweep_story_route(const StoryRoute& route, bool overshoot, std::vector& walked){ + const StoryWorld* world = story_plan_world(route.from.map, route.goal.map); + const std::optional costs = story_route_costs(route.costs); + if (world == nullptr || !costs){ + return route.name + ": no world or costs."; + } + std::vector targets; + for (const TilePos& pos : Pokemon::tiles_of(route.goal)){ + targets.push_back(story_to_world(*world, route.goal.map, pos)); + } + std::vector start; + for (const TilePos& pos : Pokemon::tiles_of(route.from)){ + start.push_back(story_to_world(*world, route.from.map, pos)); + } + for (const TilePos& from : start){ + std::vector notes; + SimulatedRouteIO io(*world, from, {}, notes); + io.overshoot_timed_holds(overshoot); + RouteTrainers trainers{.sights = story_trainers(*world), .fight = [](const std::string&){}}; + try{ + walk_route(io, *world, start, trainers, { + .goal = [&](const TilePos& pos){ return std::find(targets.begin(), targets.end(), pos) != targets.end(); }, + .label = route.name, + .avoid = {}, + .costs = *costs, + .speed = MoveSpeed::WALK, + }); + }catch (const RouteFailed& e){ + std::string last; + for (size_t i = notes.size() > 4 ? notes.size() - 4 : 0; i < notes.size(); i++){ + last += "\n " + notes[i]; + } + return std::format("{} from {}{}: {}{}", route.name, Pokemon::to_string(from), overshoot ? ", holds overshooting" : "", e.message, last); + } + if (std::find(targets.begin(), targets.end(), io.at()) == targets.end()){ + return std::format("{} from {}{}: ended at {}.", route.name, Pokemon::to_string(from), overshoot ? ", holds overshooting" : "", Pokemon::to_string(io.at())); + } + walked.push_back(io.tiles_walked()); + } + return ""; +} + +// Fault sweep: every story route, walked with every timed hold +// overshooting, still ends on its target. The log line per route gives the +// most tiles walked from any of its start tiles, without the fault and with +// it. +UnitTestResult test_story_routes_holds_overshoot(Logger& logger){ + std::string failures; + const std::vector routes = story_routes(); + for (const StoryRoute& route : routes){ + std::string line = route.name + ":"; + for (bool overshoot : {false, true}){ + std::vector walked; + const std::string error = sweep_story_route(route, overshoot, walked); + if (!error.empty()){ + failures += "\n " + error; + line += " FAIL"; + continue; + } + size_t most = 0; + for (size_t tiles : walked){ + most = std::max(most, tiles); + } + line += " " + std::to_string(most); + } + logger.log("[timed holds overshoot: no, yes] " + line); + } + if (!failures.empty()){ + return std::format("{} routes swept:{}", routes.size(), failures); + } + return true; +} + + struct PlannedRouteInput{ std::string name; std::function body; @@ -404,6 +766,22 @@ const PlannedRouteCase PLANNED_ROUTE_CASES[] = { .input = {"a known trainer stops an open leg", test_open_leg_known_trainer}, .expectation = {}, }, + { + .input = {"blocked from several possible tiles routes around", test_blocked_from_several_tiles}, + .expectation = {}, + }, + { + .input = {"Jubilife to the Center with timed holds overshooting", test_jubilife_center_held_overshoot}, + .expectation = {}, + }, + { + .input = {"Jubilife to the Center past the kids", test_jubilife_center_kids}, + .expectation = {}, + }, + { + .input = {"fault sweep: every story route with timed holds overshooting", test_story_routes_holds_overshoot}, + .expectation = {}, + }, }; void add_tests_AutoStory_PlannedRoute(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp new file mode 100644 index 0000000000..1fd3adce8e --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -0,0 +1,171 @@ +/* BDSP Authored Checkpoint Data + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Pokemon/AutoStory/Data/Pokemon_AuthoredCheckpointJson.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Actions/PokemonBDSP_AutoStory_Events.h" +#include "PokemonBDSP_AutoStory_StoryData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +Pokemon::StoryArgSpec required(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(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)}; +} + +std::vector make_bdsp_actions(){ + std::vector actions( + Pokemon::builtin_story_actions().begin(), Pokemon::builtin_story_actions().end() + ); + const Pokemon::StoryArgSpec fight_wild = optional( + "fight_wild", Pokemon::StoryArgType::BOOLEAN, false, "fight wild battles on the way instead of running" + ); + const Pokemon::StoryArgSpec route_target = required( + "target", Pokemon::StoryArgType::GRID_POSE, "where to go; with several tiles, any of them" + ); + const Pokemon::StoryArgSpec legs_arg = required( + "legs", Pokemon::StoryArgType::LEGS, "the straight legs to walk" + ); + const Pokemon::StoryArgSpec direction_arg = required( + "direction", Pokemon::StoryArgType::DIRECTION, "the way to step or face" + ); + const Pokemon::StoryArgSpec may_lose = optional( + "may_lose", Pokemon::StoryArgType::BOOLEAN, false, "losing goes on (a rival's first battle)" + ); + const Pokemon::StoryArgSpec items = required( + "items", Pokemon::StoryArgType::ITEMS, "the items and how many of each" + ); + + for (std::string_view cost : {"town", "overworld", "indoors", "caves", "robust", "line"}){ + actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild}}); + } + for (std::string_view act : {"to_wall", "to_dialogue", "to_map", "one_short_ok"}){ + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = std::string(act), .args = {legs_arg, fight_wild}}); + } + actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_arg}}); + actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {}}); + actions.push_back({.kind = Pokemon::StoryStepKind::MASH, .name = "a", .args = {}}); + actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "starter", .args = {may_lose}}); + actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "doubles", .args = {may_lose}}); + actions.push_back({.kind = Pokemon::StoryStepKind::SHOP, .name = "sandgem_potions", .args = {items}}); + + for (const auto& [name, unused] : story_events()){ + actions.push_back({.kind = Pokemon::StoryStepKind::GAME, .name = name, .args = {}}); + } + + return actions; +} + +StoryFailure read_failure(std::string_view value){ + if (value == "reload_and_retry"){ + return StoryFailure::RELOAD_AND_RETRY; + } + if (value == "stop"){ + return StoryFailure::STOP; + } + throw ParseException("Unsupported BDSP failure policy: " + std::string(value)); +} + +// 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)); +} + +} // namespace + +std::span bdsp_story_actions(){ + static const std::vector actions = make_bdsp_actions(); + return actions; +} + +StoryCheckpoint read_authored_checkpoint(const JsonValue& value, std::string_view source){ + StoryFailure on_failure = StoryFailure::RELOAD_AND_RETRY; + std::string saves_in; + auto read_execution = [&](const JsonObject& execution, std::string_view src){ + Pokemon::validate_json_fields(execution, {"on_failure", "saves_in"}, src); + on_failure = read_failure(execution.get_string_throw("on_failure")); + saves_in = execution.get_string_throw("saves_in"); + if ((on_failure == StoryFailure::RELOAD_AND_RETRY) == saves_in.empty()){ + throw ParseException("BDSP save-card location is required exactly when the checkpoint saves/retries."); + } + }; + StoryCheckpoint result; + static_cast(result) = Pokemon::read_authored_checkpoint( + without_metadata(value, source), "bdsp", source, read_execution, bdsp_story_actions() + ); + result.on_failure = on_failure; + result.saves_in = std::move(saves_in); + return result; +} + +JsonValue authored_checkpoint_document(std::string_view file){ + for (const auto& [name, text] : bdsp_checkpoint_json()){ + if (name == file){ + return parse_json(text); + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Authored checkpoint is not embedded: " + std::string(file)); +} + +StoryCheckpoint load_authored_checkpoint(std::string_view file){ + return read_authored_checkpoint(authored_checkpoint_document(file), file); +} + +std::vector load_authored_story(){ + std::vector result; + for (const auto& [name, text] : bdsp_checkpoint_json()){ + if (name.ends_with(".plan")){ + result.push_back(read_authored_checkpoint(parse_json(text), name)); + } + } + std::sort(result.begin(), result.end(), [](const StoryCheckpoint& a, const StoryCheckpoint& b){ + return a.id < b.id; + }); + for (size_t c = 1; c < result.size(); c++){ + if (result[c].id == result[c - 1].id){ + throw ParseException("Two authored checkpoints are " + result[c].id + "."); + } + } + return result; +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.h new file mode 100644 index 0000000000..052cd044d8 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.h @@ -0,0 +1,47 @@ +/* BDSP Authored Checkpoint Data + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryData_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryData_H + +#include +#include +#include +#include +#include +#include "Common/Cpp/Json/JsonValue.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" +#include "PokemonBDSP_AutoStory_StoryExecutor.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// The action specifications that BDSP steps parse against. +std::span bdsp_story_actions(); + +// The embedded authored JSON files, keyed by filename without .json. +const std::vector>& bdsp_checkpoint_json(); + +// Strict authored envelope and BDSP save/failure configuration; no controller IO. +// Unknown fields/values or inconsistent save policy throw ParseException. +StoryCheckpoint read_authored_checkpoint(const JsonValue& value, std::string_view source); + +// Load an embedded authored checkpoint; a missing file throws InternalProgramError. +StoryCheckpoint load_authored_checkpoint(std::string_view file); + +// Load all embedded authored checkpoints in id order. +std::vector load_authored_story(); + +// The embedded authored checkpoint file, parsed but not read. +JsonValue authored_checkpoint_document(std::string_view file); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.cpp new file mode 100644 index 0000000000..254532191a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.cpp @@ -0,0 +1,199 @@ +/* BDSP Authored Checkpoint Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" +#include "PokemonBDSP_AutoStory_StoryData.h" +#include "PokemonBDSP_AutoStory_StoryTable.h" +#include "PokemonBDSP_AutoStory_StoryData_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +struct StoryDataInput{ + std::string name; + void (*mutate)(JsonObject&) = nullptr; +}; + +struct StoryDataExpectation{ + bool rejected = false; +}; + +struct StoryDataCase{ + StoryDataInput input; + StoryDataExpectation expectation; +}; + +void extra(JsonObject& root){ + root["unknown"] = true; +} + +void wrong_game(JsonObject& root){ + root["game"] = "frlg"; +} + +void wrong_policy(JsonObject& root){ + root.get_object_throw("execution")["on_failure"] = "guess"; +} + +void missing_card(JsonObject& root){ + root.get_object_throw("execution")["saves_in"] = ""; +} + +void stop_with_save(JsonObject& root){ + root.get_object_throw("execution")["on_failure"] = "stop"; +} + +void bad_metadata_field(JsonObject& root){ + JsonObject meta; + meta["unknown"] = "testing"; + root["metadata"] = std::move(meta); +} + +void bad_metadata_phase(JsonObject& root){ + JsonObject meta; + meta["phase"] = "invalid"; + root["metadata"] = std::move(meta); +} + +UnitTestResult check_all_checkpoints_load(){ + const auto& table = story_checkpoints(); + if (table.size() != 22){ + return std::format("Expected 22 authored checkpoints, got {}", table.size()); + } + + const std::vector expected_ids{ + "00.00", "00.01", "00.02", "00.03", "00.04", "00.04b", "00.04c", "00.04d", + "00.05", "00.05b", "00.05c", + "01.01", "01.02", "01.03", "01.04", "01.05", "01.06", "01.07", "01.08", "01.09", "01.10", "01.11" + }; + + for (size_t i = 0; i < expected_ids.size(); i++){ + if (table[i].id != expected_ids[i]){ + return std::format("Checkpoint index {} mismatch: expected {}, got {}", i, expected_ids[i], table[i].id); + } + if (table[i].id == "00.00"){ + if (table[i].on_failure != StoryFailure::STOP || !table[i].saves_in.empty()){ + return "00.00 must have on_failure=stop and empty saves_in"; + } + }else{ + if (table[i].on_failure != StoryFailure::RELOAD_AND_RETRY || table[i].saves_in.empty()){ + return std::format("{} must have on_failure=reload_and_retry and non-empty saves_in", table[i].id); + } + } + if (table[i].steps.empty()){ + return std::format("{} has no steps", table[i].id); + } + } + + const StoryCheckpoint mine = load_authored_checkpoint("bdsp-mine-01.03.plan"); + if (mine.id != "01.03" || mine.on_failure != StoryFailure::RELOAD_AND_RETRY || mine.saves_in != "Oreburgh City"){ + return "Failed to load bdsp-mine-01.03.plan correctly"; + } + + return true; +} + +UnitTestResult run_envelope_case(const StoryDataCase& test_case){ + JsonValue val = authored_checkpoint_document("bdsp-00.01.plan"); + if (test_case.input.mutate != nullptr){ + test_case.input.mutate(val.to_object_throw()); + } + try{ + StoryCheckpoint cp = read_authored_checkpoint(val, test_case.input.name); + if (test_case.expectation.rejected){ + return "Expected rejection but read_authored_checkpoint succeeded."; + } + if (cp.id != "00.01"){ + return "Loaded checkpoint id mismatch."; + } + return true; + }catch (const Exception&){ + if (test_case.expectation.rejected){ + return true; + } + return "Unexpected rejection."; + } +} + +class Test_StoryData : public UnitTest{ +public: + explicit Test_StoryData(StoryDataCase test_case) + : UnitTest("PokemonBDSP::StoryData - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + if (m_case.input.name == "All 22 authored checkpoints load"){ + return check_all_checkpoints_load(); + } + return run_envelope_case(m_case); + } + +private: + StoryDataCase m_case; +}; + +const StoryDataCase STORY_DATA_CASES[] = { + { + .input = {.name = "All 22 authored checkpoints load"}, + .expectation = {.rejected = false}, + }, + { + .input = {.name = "Envelope: valid 00.01 plan"}, + .expectation = {.rejected = false}, + }, + { + .input = {.name = "Envelope: extra envelope field", .mutate = extra}, + .expectation = {.rejected = true}, + }, + { + .input = {.name = "Envelope: wrong game", .mutate = wrong_game}, + .expectation = {.rejected = true}, + }, + { + .input = {.name = "Envelope: unknown failure policy", .mutate = wrong_policy}, + .expectation = {.rejected = true}, + }, + { + .input = {.name = "Envelope: missing save-card location for reload_and_retry", .mutate = missing_card}, + .expectation = {.rejected = true}, + }, + { + .input = {.name = "Envelope: stop policy with start save", .mutate = stop_with_save}, + .expectation = {.rejected = true}, + }, + { + .input = {.name = "Envelope: unknown metadata field", .mutate = bad_metadata_field}, + .expectation = {.rejected = true}, + }, + { + .input = {.name = "Envelope: unknown metadata phase", .mutate = bad_metadata_phase}, + .expectation = {.rejected = true}, + }, +}; + +} // namespace + +void add_tests_AutoStory_StoryData(UnitTestDatabase& database){ + for (const auto& item : STORY_DATA_CASES){ + database.add(item); + } +} + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.h new file mode 100644 index 0000000000..a5f20325cd --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.h @@ -0,0 +1,22 @@ +/* BDSP Authored Checkpoint Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryData_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryData_Tests_H + +#include "Common/Cpp/TestRunners/UnitTest.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +// Registers unit tests for BDSP authored story data loading and envelope validation. +void add_tests_AutoStory_StoryData(UnitTestDatabase& database); + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.cpp new file mode 100644 index 0000000000..5d45ed3912 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.cpp @@ -0,0 +1,701 @@ +/* BDSP AutoStory - Story executor + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/PrettyPrint.h" +#include "CommonFramework/Exceptions/FatalProgramException.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/Globals.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RobustRoute.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TrainerSight.h" +#include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" +#include "Actions/PokemonBDSP_AutoStory_Actions.h" +#include "Actions/PokemonBDSP_AutoStory_Center.h" +#include "Actions/PokemonBDSP_AutoStory_Events.h" +#include "Actions/PokemonBDSP_AutoStory_NewGame.h" +#include "Actions/PokemonBDSP_AutoStory_Settings.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkDpad.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h" +#include "PokemonBDSP_AutoStory_StoryPlaces.h" +#include "PokemonBDSP_AutoStory_StoryTable.h" +#include "Actions/PokemonBDSP_AutoStory_Talks.h" +#include "PokemonBDSP_AutoStory_Walks.h" +#include "Actions/PokemonBDSP_AutoStory_WildBattle.h" +#include "PokemonBDSP_AutoStory_StoryExecutor.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; +using Pokemon::GridPose; +using Pokemon::Outcome; +using Pokemon::Pose; +using Pokemon::RunState; +using Pokemon::StoryStep; +using Pokemon::TilePos; +using Pokemon::story_arg; + + +std::optional story_route_costs(const std::string& action){ + if (action.empty() || action == "route"){ + return route_plan_costs(); + } + if (action == "town"){ + return town_plan_costs(); + } + if (action == "robust"){ + return RobustPlanCosts(); + } + if (action == "line"){ + return waypoint_plan_costs(); + } + return std::nullopt; +} + + +namespace{ + +// "to_catch_grass" as "to catch grass", for the logs. +std::string label_of(const StoryStep& step){ + std::string label = step.name; + std::replace(label.begin(), label.end(), '_', ' '); + return label; +} + +// The screen at a failed step, kept: the retry resets the game. +void save_failure_screenshot(VideoStream& stream, size_t attempt){ + VideoSnapshot screen = stream.video().snapshot(); + if (!screen){ + return; + } + const std::string folder = SCREENSHOTS_PATH() + "AutoStory/failures/"; + Filesystem::create_directories(Filesystem::Path(folder)); + const std::string path = std::format("{}{}-attempt{}.png", folder, now_to_filestring(), attempt); + screen.frame->save(path); + stream.log("Failure screenshot: " + path); +} + +// A trainer who saw us on a route: Route 204's Twins battle as a pair +// (01.10), everyone else alone. +void fight_story_trainer(VideoStream& stream, ProControllerContext& context, const std::string& trainer){ + if (trainer.find("Twins") != std::string::npos){ + talk_or_fight(stream, context, trainer, TalkExpect::BATTLE, BattleFormat::DOUBLES); + return; + } + fight_route_trainer(stream, context, trainer); +} + +} // namespace + + +StoryExecutor::StoryExecutor(StoryEnv& env) + : m_env(env) +{} + +void StoryExecutor::begin_attempt(const Pokemon::StoryCheckpoint& data){ + m_checkpoint = data.id; + // A row starts from its save: after the shoes' row, the save has them. + m_can_run = data.id > std::string(RUNNING_SHOES_ROW); + m_trainers.clear(); +} + +Outcome StoryExecutor::run(const StoryStep& step, RunState& state){ + stream().log(std::format("[{}] {} {}: {}", m_checkpoint, Pokemon::story_step_kind_name(step.kind), step.name, step.why), COLOR_BLUE); + try{ + Outcome outcome = run_guarded(state, step); + if (outcome.succeeded() && m_checkpoint == RUNNING_SHOES_ROW && step.name == RUNNING_SHOES_STEP){ + m_can_run = true; + } + return outcome; + }catch (OperationFailedException& e){ + if (m_stop_rows.contains(m_checkpoint)){ + throw; + } + // Attempts are the segment's policy; this only counts them for the + // log line the lab's run watcher reads. + const size_t attempt = m_failures[m_checkpoint]++; + stream().log(std::format("checkpoint_reattempt_loop: attempt {} failed: {}: {}", attempt, m_checkpoint, e.message()), COLOR_RED); + save_failure_screenshot(stream(), attempt); + return Pokemon::outcome_failed("operation_failed", e.message()); + } +} + +Outcome StoryExecutor::run_guarded(RunState& state, const StoryStep& step){ + const StoryEvents& events = story_events(); + if (auto event = events.find(step.action); event != events.end()){ + return event->second(*this, state, step); + } + switch (step.kind){ + case Pokemon::StoryStepKind::NEW_GAME: + return new_game(state, step); + case Pokemon::StoryStepKind::OPTIONS: + return options(state, step); + case Pokemon::StoryStepKind::ROUTE: + return route(state, step); + case Pokemon::StoryStepKind::LEGS: + return legs(state, step); + case Pokemon::StoryStepKind::STEP: + return this->step(state, step); + case Pokemon::StoryStepKind::TALK: + return talk(state, step); + case Pokemon::StoryStepKind::ANSWER: + return answer(state, step); + case Pokemon::StoryStepKind::MASH: + return mash(state, step); + case Pokemon::StoryStepKind::BATTLE: + return battle(state, step); + case Pokemon::StoryStepKind::TRAIN: + return train(state, step); + case Pokemon::StoryStepKind::HEAL: + return heal(state, step); + case Pokemon::StoryStepKind::SAVE: + return save(state, step); + case Pokemon::StoryStepKind::GAME: + return game(state, step); + default: + return Pokemon::unsupported_step(step); + } +} + +Pose StoryExecutor::walk_to(const Pose& from, const Pose& goal, const StoryStep& step){ + const StoryWorld* maps = story_plan_world(from.map, goal.map); + if (maps == nullptr){ + fail_step(stream(), std::format("{}: no maps join {} and {}.", step.name, from.map, goal.map)); + } + const std::optional costs = story_route_costs(step.action); + if (!costs){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown route costs: " + step.action); + } + std::vector start; + for (const TilePos& pos : Pokemon::tiles_of(from)){ + start.push_back(story_to_world(*maps, from.map, pos)); + } + std::vector targets; + for (const TilePos& pos : Pokemon::tiles_of(goal)){ + targets.push_back(story_to_world(*maps, goal.map, pos)); + } + // The ones fought stay off m_trainers until the next attempt. + std::vector& sights = m_trainers.try_emplace(maps, story_trainers(*maps)).first->second; + RouteTrainers trainers{ + sights, + [this](const std::string& trainer){ fight_story_trainer(stream(), context(), trainer); } + }; + const RouteWalkPlan plan{ + [&](const TilePos& pos){ return std::find(targets.begin(), targets.end(), pos) != targets.end(); }, + label_of(step), {}, *costs, m_can_run ? MoveSpeed::RUN : MoveSpeed::WALK + }; + const std::vector at = walk_route(stream(), context(), run_from_wild_battle, *maps, start, trainers, plan); + sights = std::move(trainers.sights); + std::vector local; + for (const TilePos& pos : at){ + const std::optional tile = story_to_local(*maps, goal.map, pos); + if (!tile){ + fail_step(stream(), std::format("{}: the walk ended off {}.", step.name, goal.map)); + } + local.push_back(*tile); + } + return Pokemon::tile_pose(goal.map, local, Pokemon::facing_of(goal)); +} + +Outcome StoryExecutor::new_game(RunState&, const StoryStep&){ + play_new_game_intro(m_env.env, context(), m_env.player_name); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::options(RunState&, const StoryStep&){ + verify_tutorial_settings(stream(), context()); + context().wait_for_all_requests(); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::route(RunState& state, const StoryStep& step){ + if (Pokemon::tiles_of(state.pose).empty()){ + return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); + } + const GridPose& target = story_arg(step.args, "target"); + return Pokemon::outcome_ok(walk_to(state.pose, Pokemon::pose_of(target), step)); +} + +namespace{ + +// A LEGS step "to_dialogue": taps its one leg until a dialogue starts on the +// way, wherever it starts (Dawn's at Sandgem's edge, r35/r36: an exact tile +// and banner raced her scene). The scene's lines are the next step's. +Outcome leg_to_dialogue(VideoStream& stream, ProControllerContext& context, const StoryStep& step, const std::string& checkpoint){ + const auto& legs_list = story_arg>(step.args, "legs"); + const Pokemon::StoryLeg& leg = legs_list.front(); + route_turn(stream, context, leg.direction); + const auto [x, y] = dpad_of(leg.direction); + const WalkResult walk = walk_tiles_dpad(stream, context, run_from_wild_battle, {x, y}, (size_t)leg.tiles, step.name); + stream.log(std::format("[{}] {}: taps {} to a dialogue: {} tiles, {}.", checkpoint, step.name, direction_name(leg.direction), walk.moved_chunks, walk_stop_name(walk.stop))); + if (walk.stop == WalkStop::DIALOG){ + return Pokemon::outcome_ok(); + } + // A scene can lock us before its first line: Dawn walks over first (r37). + ShortDialogWatcher dialog(COLOR_CYAN); + if (walk.stop == WalkStop::BLOCKED && wait_until(stream, context, 10000ms, {{dialog}}) == 0){ + return Pokemon::outcome_ok(); + } + return Pokemon::outcome_failed("no_dialogue", step.name); +} + +// A LEGS step "to_map": runs its one leg until the location banner of +// pose_after's map shows, wherever it shows. A straight run along an open +// row needs no tile count (r41, r42: Sandgem's row 11 took us into the lab). +Outcome leg_to_map(VideoStream& stream, ProControllerContext& context, const StoryStep& step, const std::string& checkpoint){ + const auto& legs_list = story_arg>(step.args, "legs"); + const Pokemon::StoryLeg& leg = legs_list.front(); + const std::string map = step.pose_after ? Pokemon::grid_pose_of(*step.pose_after).map : ""; + route_turn(stream, context, leg.direction); + const auto [x, y] = dpad_of(leg.direction); + const WalkResult walk = walk_until_dpad(stream, context, run_from_wild_battle, {x, y}, + Milliseconds(250) * leg.tiles + 2000ms, step.name, { + .arrived = [&](const ImageViewRGB32& screen){ return location_banner_matches(read_location_banner(screen), map); }, + .pace = DpadPace::RUN, + }); + stream.log(std::format("[{}] {}: ran {} to {}'s banner: {}.", checkpoint, step.name, direction_name(leg.direction), map, walk_stop_name(walk.stop))); + return walk.stop == WalkStop::ARRIVED ? Pokemon::outcome_ok() : Pokemon::outcome_failed("no_banner", map); +} + +} // namespace + +Outcome StoryExecutor::legs(RunState& state, const StoryStep& step){ + const auto& legs_list = story_arg>(step.args, "legs"); + if (step.action == "to_wall"){ + for (const Pokemon::StoryLeg& leg : legs_list){ + walk_until_stopped(stream(), context(), leg.direction, (size_t)leg.tiles, label_of(step)); + } + return Pokemon::outcome_ok(); + } + if (step.action == "to_dialogue"){ + return leg_to_dialogue(stream(), context(), step, m_checkpoint); + } + if (step.action == "to_map"){ + return leg_to_map(stream(), context(), step, m_checkpoint); + } + const bool one_short_ok = step.action == "one_short_ok"; + if (!one_short_ok && !step.action.empty() && step.action != "legs"){ + return Pokemon::outcome_failed("unknown_action", step.action); + } + std::vector at = Pokemon::tiles_of(state.pose); + for (const Pokemon::StoryLeg& leg : legs_list){ + // Facing another way, a tap only turns (r256): turn first. + route_turn(stream(), context(), leg.direction); + const auto [x, y] = dpad_of(leg.direction); + const size_t tiles = (size_t)leg.tiles; + const WalkResult walk = walk_tiles_dpad(stream(), context(), run_from_wild_battle, {x, y}, tiles, step.name); + stream().log(std::format("[{}] {}: taps {} moved {} of {} tiles.", m_checkpoint, step.name, direction_name(leg.direction), walk.moved_chunks, tiles)); + if (walk.moved_chunks + (one_short_ok ? 1 : 0) < tiles){ + return Pokemon::outcome_failed("short_leg", std::format("{} {} moved {}", direction_name(leg.direction), tiles, walk.moved_chunks)); + } + // Where we may be: the end, or a tile short of it. + std::vector next; + for (const TilePos& start : at){ + TilePos end = start; + for (size_t i = 0; i < tiles; i++){ + if (one_short_ok && i + 1 == tiles){ + next.push_back(end); + } + end = end.next(leg.direction); + } + next.push_back(end); + } + at = std::move(next); + } + return Pokemon::outcome_ok(Pokemon::tile_pose(state.pose.map, at, legs_list.back().direction)); +} + +namespace{ + +// One rule for scenes and map changes: v2's long B mashes, with an end +// check. Press through the text, and keep pressing B while the screen is +// quiet: a scene can pause while someone walks off (Dawn and Barry after +// Rowan leaves, r23), fade dimly, not to black, to another map (r25), or +// wait on a box the detector misses (r26). B never starts a talk on the +// overworld. Done once the overworld has shown, with no text and a still +// screen, for 5 s of presses: after r31's fade home a scripted walk-in ran +// 5 s with no text before Mom spoke. +// +// A step or scene that ends on another map (`fade`) must fade on the way, +// and only the quiet after the fade counts: r30's scene went quiet for 5 s +// before the fade home, and r28 "went out" a tile beside the door and +// walked a whole route in the house. No fade is a map mismatch. +constexpr double FADE_DARKNESS = 40; // brightness 0 to 255; r24's dim fade home goes darker +void settle(VideoStream& stream, ProControllerContext& context, Button button, const std::string& label, bool fade){ + const WallClock none = WallClock::max(); + const WallClock deadline = current_time() + 120s; + ShortDialogDetector dialog; + OverworldDetector overworld; + WallClock quiet_since = none; + WallClock calm_since = none; // overworld, no text, still or not + double darkest = 255; + VideoSnapshot previous; + while (current_time() < deadline){ + context.wait_for_all_requests(); + const auto frame = stream.video().snapshot(); + const WallClock now = current_time(); + if (frame){ + darkest = std::min(darkest, image_average(*frame.frame).sum() / 3); + } + const bool talking = frame && dialog.detect(frame); + const bool still = frame && previous && walk_screen_change(*previous.frame, *frame.frame) < WALK_TAP_BLOCKED_CHANGE; + previous = frame; + // Cloud shadows drift over Floaroma, so its screen is never still: r83 + // got Mew and then waited out the 120 s on a calm overworld. 15 s of + // overworld with no text is three times r31's silent walk-in. + const bool calm = !talking && overworld.detect(frame) && (!fade || darkest < FADE_DARKNESS); + calm_since = calm ? (calm_since == none ? now : calm_since) : none; + if (calm && now - calm_since >= 15000ms){ + stream.log(std::format("[Story] {}: settled on 15 s of overworld without text (the screen kept moving); darkest frame {:.0f}.", label, darkest)); + return; + } + if (!talking && still && overworld.detect(frame) && (!fade || darkest < FADE_DARKNESS)){ + quiet_since = quiet_since == none ? now : quiet_since; + if (now - quiet_since >= 5000ms){ + stream.log(std::format("[Story] {}: settled; darkest frame {:.0f}.", label, darkest)); + return; + } + }else{ + quiet_since = none; + } + pbf_press_button(context, talking ? button : BUTTON_B, 80ms, 1200ms); + } + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, + fade && darkest >= FADE_DARKNESS + ? label + ": no fade within 120 s, so we are not where the step goes (map mismatch)." + : label + ": not back on a quiet overworld within 120 s.", + stream); +} + +} // namespace + +namespace{ + +// Holds the D-pad toward a door (with B after the shoes) until the screen goes +// dark or a line shows, up to 12 s. Returns whether it went dark. A line +// stops it: holding on under Mom's "Oh, Kosmos!" wasted 12 s (r45). The walker's black-screen watch +// missed the lab's fade into Sandgem (r44, "dialog"), and settle's samples +// 1.3 s apart can fall either side of it, so watch at settle's own darkness. +DpadPosition dpad_toward(Direction direction){ + return + direction == Direction::NORTH ? DPAD_UP : + direction == Direction::SOUTH ? DPAD_DOWN : + direction == Direction::WEST ? DPAD_LEFT : DPAD_RIGHT; +} + +bool run_into_door(VideoStream& stream, ProControllerContext& context, Direction direction, bool run){ + const DpadPosition dpad = dpad_toward(direction); + BlackScreenWatcher dark(COLOR_RED, {0.1, 0.1, 0.8, 0.8}, 3 * FADE_DARKNESS, 60); + ShortDialogWatcher dialog(COLOR_YELLOW); + const int ret = run_until(stream, context, [&](ProControllerContext& context){ + if (run){ + ssf_press_button(context, BUTTON_B, 0ms, 12000ms, 0ms); + } + pbf_press_dpad(context, dpad, 12000ms, 0ms); + }, {{dark}, {dialog}}); + return ret == 0; +} + +// What the screen showed after a tap toward a door or a cave mouth. +enum class TapLook{ + NOTHING, + DARK, + BANNER, +}; + +// Looks for `map`'s location banner (and, if `dark_too`, the fade) for up +// to `wait`. +TapLook look_after_tap(VideoStream& stream, ProControllerContext& context, const std::string& map, Milliseconds wait, bool dark_too){ + const WallClock deadline = current_time() + wait; + while (true){ + context.wait_for_all_requests(); + const VideoSnapshot screen = stream.video().snapshot(); + if (screen && location_banner_matches(read_location_banner(*screen.frame), map)){ + return TapLook::BANNER; + } + if (dark_too && screen && image_average(*screen.frame).sum() / 3 < FADE_DARKNESS){ + return TapLook::DARK; + } + if (current_time() >= deadline){ + return TapLook::NOTHING; + } + context.wait_for(100ms); + } +} + +// A STEP "to_banner": D-pad taps one at a time toward a door or cave mouth, +// each followed by a look, until the fade (then no more taps) and +// pose_after's map's location banner. A held walk can carry on past a +// fade that goes unseen: out of the Gym it walked on south (r219g), and +// through the Oreburgh Gate's west mouth on west into a pocket by Route +// 203's pond (r75). Taps during the fade are eaten. No banner fails the +// step right there. +Outcome tap_to_banner(VideoStream& stream, ProControllerContext& context, const StoryStep& step, const std::string& checkpoint){ + const std::string map = step.pose_after ? story_banner_name(Pokemon::grid_pose_of(*step.pose_after).map) : ""; + const Direction direction = story_arg(step.args, "direction"); + for (size_t tap = 1; tap <= 30; tap++){ + pbf_press_dpad(context, dpad_toward(direction), 160ms, 0ms); + TapLook look = look_after_tap(stream, context, map, 1500ms, true); + const bool faded = look == TapLook::DARK; + if (faded){ + look = look_after_tap(stream, context, map, 8000ms, false); + } + if (look == TapLook::BANNER){ + stream.log(std::format("[{}] {}: {}'s banner after {} taps {}.", checkpoint, step.name, map, tap, direction_name(direction))); + context.wait_for(1000ms); + return Pokemon::outcome_ok(); + } + if (faded){ + break; + } + } + return Pokemon::outcome_failed("no_banner", map); +} + +} // namespace + +Outcome StoryExecutor::step(RunState& state, const StoryStep& step){ + const Direction direction = story_arg(step.args, "direction"); + route_turn(stream(), context(), direction); + if (step.action == "to_banner"){ + return tap_to_banner(stream(), context(), step, m_checkpoint); + } + // A step through a door: walk (or run) on until the screen goes dark, + // from next to the door or from anywhere in its line (r43: tapping 8 tiles + // down the lab took 7 s), then settle for any scene on arrival (Mom's, + // 00.01; Dawn's tour, 00.04). Without the fade, settle must see it itself + // (r33 was outside, "no fade"). + if (step.pose_after && Pokemon::grid_pose_of(*step.pose_after).map != state.pose.map){ + const bool faded = run_into_door(stream(), context(), direction, m_can_run); + stream().log(std::format("[{}] {}: {} through the door: {}.", m_checkpoint, step.name, direction_name(direction), faded ? "faded" : "no fade yet")); + settle(stream(), context(), BUTTON_B, label_of(step), !faded); + return Pokemon::outcome_ok(); + } + const auto [x, y] = dpad_of(direction); + const WalkResult walk = walk_tiles_dpad(stream(), context(), run_from_wild_battle, {x, y}, 1, step.name); + stream().log(std::format("[{}] {}: a step {}, {}.", m_checkpoint, step.name, direction_name(direction), walk_stop_name(walk.stop))); + std::vector at; + for (const TilePos& pos : Pokemon::tiles_of(state.pose)){ + at.push_back(pos.next(direction)); + } + return Pokemon::outcome_ok(Pokemon::tile_pose(state.pose.map, at, direction)); +} + +Outcome StoryExecutor::talk(RunState& state, const StoryStep& step){ + // Face whom we talk to: a route ends facing its last leg, not its goal + // (r40 reached Mom facing north). They block the tile, so the tap only turns. + if (const std::optional facing = Pokemon::facing_of(state.pose)){ + route_turn(stream(), context(), *facing); + } + pbf_press_button(context(), BUTTON_A, 80ms, 200ms); + context().wait_for_all_requests(); + // Roark's first line in the mine comes after the camera zooms in on + // us, which can take some seconds (r98; the old event waited 8 s). + ShortDialogWatcher dialog(COLOR_YELLOW); + if (wait_until(stream(), context(), 8000ms, {{dialog}}) != 0){ + fail_step(stream(), label_of(step) + ": nobody answered."); + } + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::answer(RunState&, const StoryStep& step){ + wait_for_dialogue(stream(), context(), label_of(step)); + const bool yes = story_arg(step.args, "yes"); + pbf_press_button(context(), yes ? BUTTON_A : BUTTON_B, 80ms, 1000ms); + context().wait_for_all_requests(); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::mash(RunState& state, const StoryStep& step){ + // The step before may have played the scene already (a door step settles + // its arrival scene), so its first line is not required. + ShortDialogWatcher dialog(COLOR_CYAN); + if (wait_until(stream(), context(), 15000ms, {{dialog}}) != 0){ + stream().log(label_of(step) + ": no line within 15 s; the step before played it.", COLOR_ORANGE); + } + settle(stream(), context(), step.action == "a" ? BUTTON_A : BUTTON_B, label_of(step), + step.pose_after && Pokemon::grid_pose_of(*step.pose_after).map != state.pose.map); + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::battle(RunState&, const StoryStep& step){ + // "starter": the Starly battle at the lake (00.02). It opens on its own, + // with no talk, and the starter has no Poke Balls to throw; the scene + // goes on whoever wins. + if (step.action == "starter"){ + fight_starly(stream(), context()); + return Pokemon::outcome_ok(); + } + // A loss sends us to a Pokemon Center, so ending on its floor means a + // loss - unless the floor check already passed where the battle began: + // Jubilife's yellow plaza reads as Center floor (63 %, r79 won Rowan's + // tag battle there and was called lost). + const bool may_lose = story_arg(step.args, "may_lose"); + const bool center_before = !may_lose && in_pokemon_center(stream()); + if (!talk_or_fight(stream(), context(), label_of(step), TalkExpect::BATTLE, step.action == "doubles" ? BattleFormat::DOUBLES : BattleFormat::SINGLES)){ + fail_step(stream(), label_of(step) + ": talked but did not battle."); + } + if (center_before){ + stream().log(label_of(step) + ": the floor read as a Center's before the battle too; no loss check here.", COLOR_ORANGE); + }else if (!may_lose && in_pokemon_center(stream())){ + fail_step(stream(), label_of(step) + ": lost the battle."); + } + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::train(RunState&, const StoryStep& step){ + const int64_t battles = story_arg(step.args, "battles"); + for (int64_t battle = 0; battle < battles; battle++){ + const std::string label = std::format("Training battle {}/{}", battle + 1, battles); + route_status(stream(), label); + battle_1_pokemon(stream(), context()); + fail_if_blacked_out(stream(), context(), label); + } + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::heal(RunState&, const StoryStep& step){ + // From the planned tile below the door, run in like any door. The lit- + // doorway lineup is for when the run in finds no door: people on the + // way can leave the route unsure of the column (r59, Jubilife). Below + // Sandgem's door the lineup read 0.7 tile off and stepped us off it (r48). + route_turn(stream(), context(), Direction::NORTH); + const bool in = run_into_door(stream(), context(), Direction::NORTH, m_can_run); + stream().log(std::format("[{}] {}: north into the Center: {}.", m_checkpoint, step.name, in ? "faded" : "no door; lining up by sight")); + if (in){ + pbf_wait(context(), 1500ms); + }else{ + enter_lit_door(stream(), context(), label_of(step)); + } + talk_to_nurse(stream(), context(), label_of(step)); + // Her last line ("We hope to see you again!") can still be up, and a + // line stops the run out at once (r62): B until none shows. + ShortDialogDetector line; + for (size_t presses = 0; presses < 10; presses++){ + context().wait_for_all_requests(); + const VideoSnapshot screen = stream().video().snapshot(); + if (!screen || !line.detect(*screen.frame)){ + break; + } + pbf_press_button(context(), BUTTON_B, 80ms, 700ms); + } + // Out the same way: south until the fade. The walk out's indoor check + // read "not a room" a step from the counter and stopped inside (r50, r59). + route_turn(stream(), context(), Direction::SOUTH); + const bool out = run_into_door(stream(), context(), Direction::SOUTH, m_can_run); + stream().log(std::format("[{}] {}: south out of the Center: {}.", m_checkpoint, step.name, out ? "faded" : "no fade yet")); + settle(stream(), context(), BUTTON_B, label_of(step), !out); + // r143a's heal said it had walked out while still inside. + context().wait_for_all_requests(); + VideoSnapshot screen = stream().video().snapshot(); + if (screen && indoors(*screen.frame)){ + fail_step(stream(), label_of(step) + ": still inside the Pokemon Center."); + } + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::save(RunState&, const StoryStep& step){ + if (step.action.empty()){ + save_game(m_env.env, context()); + return Pokemon::outcome_ok(); + } + // A row's start save, its action the map the card must name. With a + // map, save_game() throws only when the card names another one, having + // backed out unsaved. That stops the program: a reset would load an + // older save and run this row from wherever that is. + try{ + save_game(m_env.env, context(), step.action); + }catch (OperationFailedException& e){ + throw FatalProgramException( + ErrorReportMode::NO_ERROR_REPORT, + std::format("[{}] Not at the checkpoint's start, so not saving: {}", m_checkpoint, e.message()), + stream() + ); + } + return Pokemon::outcome_ok(); +} + +Outcome StoryExecutor::game(RunState&, const StoryStep& step){ + return Pokemon::outcome_failed("unknown_event", step.action); +} + + +Pokemon::Segment make_story_segment( + const std::vector& rows, Pokemon::StoryStepExecutor& executor, + std::set& saved +){ + static const StoryStep SAVE_AT_START = []{ + StoryStep step; + step.kind = Pokemon::StoryStepKind::SAVE; + step.name = "save"; + step.why = "the save a failed step resets to"; + return step; + }(); + Pokemon::Segment segment; + segment.id = "BDSP"; + for (const StoryCheckpoint& row : rows){ + segment.checkpoints.push_back(Pokemon::CheckpointSpec{ + .id = row.id, .title = row.title, .saves = false, + .build = [&row, &executor, &saved]{ + Pokemon::Checkpoint steps = Pokemon::build_story_checkpoint(row, executor); + if (row.on_failure != StoryFailure::RELOAD_AND_RETRY){ + return steps; + } + StoryStep save_at_start = SAVE_AT_START; + save_at_start.action = row.saves_in; + Pokemon::Event save = Pokemon::story_event(save_at_start, executor); + save.skip_if.push_back(Pokemon::condition("saved at the start", [&saved, id = row.id](RunState&){ + return saved.contains(id); + })); + // A save that fails is a failed first attempt: the retry + // resets and does not save again. + save.act = [&executor, &saved, id = row.id, save_at_start](RunState& state){ + saved.insert(id); + return executor.run(save_at_start, state); + }; + Pokemon::Checkpoint checkpoint; + checkpoint.id = row.id; + checkpoint.events.push_back(std::move(save)); + for (Pokemon::Event& event : steps.events){ + checkpoint.events.push_back(std::move(event)); + } + return checkpoint; + }, + }); + } + return segment; +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h new file mode 100644 index 0000000000..bc8e9b535e --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h @@ -0,0 +1,190 @@ +/* BDSP AutoStory - Story executor + * + * From: https://github.com/PokemonAutomation/ + * + * BDSP's way of doing the shared story steps + * (Pokemon/AutoStory/Pokemon_StorySteps.h) on the console. A route is + * planned on the joined maps that hold its start and its target + * (story_plan_world()), from the tiles the run's pose holds, and walked by + * the walker, which fights the trainers who see us and runs from wild + * battles. A step whose variant names one of the story's events + * (story_events(), PokemonBDSP_AutoStory_Events.h) runs that event, + * whatever its kind: the scripted scenes and the console-measured walks + * of segment 01. + * + * Every step runs inside a guard that turns a failed console step into a + * failed Outcome, with a screenshot and the "checkpoint_reattempt_loop: + * attempt N failed" line the lab's run watcher reads; the segment then + * reloads the row's save and runs it again. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryExecutor_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryExecutor_H + +#include +#include +#include +#include +#include +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RobustRoute.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_GridPose.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryStep.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TrainerSight.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Starter Pokemon options for BDSP story automation. +enum class StarterChoice{ + TURTWIG, + CHIMCHAR, + PIPLUP, +}; + +// What a row does when one of its steps fails. +enum class StoryFailure{ + // Save before the first step; on a failure reset to that save and run + // the row again from its first step. + RELOAD_AND_RETRY, + // No save and no retry: the failure ends the program (00.00, before + // the game has anything worth saving). + STOP, +}; + +// A row of the story table: the shared checkpoint, and what a failure does. +struct StoryCheckpoint : public Pokemon::StoryCheckpoint{ + StoryFailure on_failure = StoryFailure::RELOAD_AND_RETRY; + // The map the save screen's card names where the row starts ("Route + // 203"). The save at its start is refused anywhere else and the program + // stops: r76/r77 started 01.06 a walk away from its start and saved over + // the good save there. Empty for a row that does not save first. + std::string saves_in; +}; + +// What the story's steps act on. +struct StoryEnv{ + SingleSwitchProgramEnvironment& env; + ProControllerContext& context; + StarterChoice starter = StarterChoice::CHIMCHAR; + std::string player_name; +}; + + +// The plan costs a ROUTE step's variant names: "" the route costs, +// "town" town_plan_costs(), "robust" the planner's defaults, "line" +// waypoint_plan_costs() (a stretch of a line a human walked). Nothing for +// another name. +std::optional story_route_costs(const std::string& variant); + + +// Does BDSP's kinds of story step on the console. +class StoryExecutor : public Pokemon::StoryStepExecutor{ +public: + explicit StoryExecutor(StoryEnv& env); + + StoryEnv& env(){ + return m_env; + } + VideoStream& stream(){ + return m_env.env.console; + } + ProControllerContext& context(){ + return m_env.context; + } + // The rows whose failure ends the program (StoryFailure::STOP): a + // failed step there throws on instead of failing the step. + void set_stop_rows(std::set rows){ + m_stop_rows = std::move(rows); + } + // A new attempt of a row: every trainer can see us again. + virtual void begin_attempt(const Pokemon::StoryCheckpoint& data) override; + virtual Pokemon::Outcome run(const Pokemon::StoryStep& step, Pokemon::RunState& state) override; + +protected: + // The row running now. + const std::string& checkpoint() const{ + return m_checkpoint; + } + // Walks from the tiles of `from` on its map to any of `goal`'s tiles, + // fighting the trainers who see us this attempt. Returns where it left + // us, as a pose on `goal`'s map. + Pokemon::Pose walk_to(const Pokemon::Pose& from, const Pokemon::Pose& goal, const Pokemon::StoryStep& step); + + // The intro of a new game, from the title screen to the bedroom. + Pokemon::Outcome new_game(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // verify_tutorial_settings(): fast text, Autosave off. + Pokemon::Outcome options(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // Variant: the plan's costs ("" route, "town", "robust", "line"). + Pokemon::Outcome route(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // Each leg in D-pad taps, turning first. Variant "one_short_ok": a leg + // may end a tile short (a door lined up by sight after). Variant + // "to_wall": each leg walks until something stops it, for at most its + // tiles' time, as measured on the console; the pose is then unknown + // unless the step gives one. + Pokemon::Outcome legs(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // One D-pad step `direction`, turning first: onto a scene's trigger or + // into a door. Variant "to_banner": one tap into a cave mouth, then + // wait for pose_after's map's location banner. + Pokemon::Outcome step(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // A at what we face; a dialogue must open. + Pokemon::Outcome talk(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // A for YES, B for NO, once the question's box shows. + Pokemon::Outcome answer(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // A dialogue opens (or has), then B through it to the overworld; + // variant "a": A through it, for lines that give an item. + Pokemon::Outcome mash(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // A trainer's text opens (or has) and ends in a battle, fought with the + // best move; one lost fails the step unless `may_lose`. Variant + // "doubles" for a tag battle. + Pokemon::Outcome battle(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // `battles` wild battles in the grass we stand in, with the best move. + Pokemon::Outcome train(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // In front of a Pokemon Center, its lit doorway on screen: in, the + // nurse, and out (heal_at_pokemon_center()). + Pokemon::Outcome heal(Pokemon::RunState& state, const Pokemon::StoryStep& step); + Pokemon::Outcome save(Pokemon::RunState& state, const Pokemon::StoryStep& step); + // The event its variant names (story_events()). + Pokemon::Outcome game(Pokemon::RunState& state, const Pokemon::StoryStep& step); + +private: + Pokemon::Outcome run_guarded(Pokemon::RunState& state, const Pokemon::StoryStep& step); + + StoryEnv& m_env; + std::string m_checkpoint; + // Whether the player has the Running Shoes: the pace routes are timed at. + bool m_can_run = false; + // The trainers who can still see us on each story_plan_world() world, + // in its tiles, from its first walk this attempt; all of them again at + // each attempt. + std::map> m_trainers; + std::map m_failures; + std::map m_run_counts; + std::set m_stop_rows; +}; + + +// `rows` (kept alive by the caller) as one segment. A row that reloads on +// failure saves first, unless `saved` says it has in this run: a retry +// starts from that save. `executor` and `saved` must outlive the segment. +Pokemon::Segment make_story_segment( + const std::vector& rows, Pokemon::StoryStepExecutor& executor, + std::set& saved +); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.cpp new file mode 100644 index 0000000000..4531c88fb4 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.cpp @@ -0,0 +1,313 @@ +/* BDSP AutoStory - Story places + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Data/PokemonBDSP_AutoStory_Maps.h" +#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" +#include "Data/PokemonBDSP_AutoStory_StoryTrainers.h" +#include "Data/PokemonBDSP_AutoStory_TrainerSight.h" +#include "PokemonBDSP_AutoStory_StoryPlaces.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using Pokemon::Direction; +using Pokemon::TilePos; + + +namespace{ + +// The JSON maps' names and the location banners'. Both halves of Route +// 204 show "Route 204"; no world holds both. +const std::map& banner_names(){ + static const std::map names{ + {"TwinleafTown", "Twinleaf Town"}, + {"Route201", MAP_ROUTE_201}, + {"VerityLakefront", "Verity Lakefront"}, + {"SandgemTown", MAP_SANDGEM_TOWN}, + {"Route202", MAP_ROUTE_202}, + {"JubilifeCity", MAP_JUBILIFE_CITY}, + {"Route203", MAP_ROUTE_203}, + {"OreburghCity", MAP_OREBURGH_CITY}, + {"Route204South", "Route 204"}, + {"Route204North", "Route 204"}, + {"FloaromaTown", MAP_FLOAROMA_TOWN}, + }; + return names; +} + +const std::string& banner_name(const std::string& map){ + const auto& names = banner_names(); + if (auto iter = names.find(map); iter != names.end()){ + return iter->second; + } + return map; +} + +// `maps` (JSON names) in one world, each with its tile (0,0) at the corner +// of its decomp rectangle (devtools/maps/bdsp_maps.py), so maps that meet +// in the game meet here. +StoryWorld joined(const std::vector>& maps){ + StoryWorld world; + for (const auto& [map, corner] : maps){ + world.add(banner_name(std::string(map)), story_map(std::string(map)), corner); + } + return world; +} + +// TODO(#114 multi-map view): MapData has no joined view of maps yet. +// Twinleaf to Route 202 in one world, at the decomp's world tiles (its +// cells are 32 tiles square; Route 201's map starts 7 rows into its cell +// and Route 202's a column west of its own). +const StoryWorld& south_world(){ + static const StoryWorld world = joined({ + {"TwinleafTown", {96, 864}}, + {"Route201", {96, 839}}, + {"VerityLakefront", {64, 832}}, + {"SandgemTown", {160, 832}}, + {"Route202", {159, 800}}, + }); + return world; +} + +// Jubilife without its east column: Route 203's map starts on that column +// (world x 191, its column 0), and two maps may not both hold open ground. +// Jubilife's tiles keep their coordinates. +Pokemon::MapData jubilife_west_of_route_203(){ + const Pokemon::MapData& city = story_map("JubilifeCity"); + Pokemon::MapData cut; + cut.name = city.name; + cut.source = city.source; + cut.tiles = Pokemon::Grid{city.tiles.width - 1, city.tiles.height, {}}; + for (int y = 0; y < cut.tiles.height; y++){ + for (int x = 0; x < cut.tiles.width; x++){ + cut.tiles.cells.push_back(city.tiles.at({x, y})); + } + } + for (const Pokemon::MapObject& object : city.objects){ + if (cut.tiles.contains({object.x, object.y})){ + cut.objects.push_back(object); + } + } + return cut; +} + +// 01.06: Route 203 west into Jubilife (decomp rectangles (191, 740) and +// (128, 736)): Route 203's rows 17..20 are Jubilife's street, rows 21..24. +const StoryWorld& route_203_world(){ + static const StoryWorld world = []{ + StoryWorld world = joined({{"Route203", {191, 740}}}); + world.add(MAP_JUBILIFE_CITY, jubilife_west_of_route_203(), {128, 736}); + return world; + }(); + return world; +} + +// 01.08: Jubilife north onto Route 204's south half (160, 704), whose street +// (12..15, 31) carries on Jubilife's (44..47, 0). +const StoryWorld& route_204_south_world(){ + static const StoryWorld world = joined({{"JubilifeCity", {128, 736}}, {"Route204South", {160, 704}}}); + return world; +} + +// 01.10: Route 204's north half (160, 672) up into Floaroma (160, 640). +const StoryWorld& route_204_north_world(){ + static const StoryWorld world = joined({{"Route204North", {160, 672}}, {"FloaromaTown", {160, 640}}}); + return world; +} + +// The Ravaged Path with the rock 01.09 smashes, (22, 43), open: no route +// before the smash can use it, since it only leads east, where the rocks +// shut everything else off. +Pokemon::MapData ravaged_path_smashed(){ + Pokemon::MapData map = story_map("RavagedPath"); + Pokemon::cell_at(map_point("RavagedPath", "rocks.13"), map.tiles) = Pokemon::TileKind::OPEN; + return map; +} + +// The interiors (houses, the lab, the Gym, the Gate, the mine's two floors, +// the Ravaged Path), each its own world, named by its JSON map. +const std::map& room_worlds(){ + static const std::map rooms = []{ + std::map ret; + for (std::string_view room : {"PlayerHouse2F", "PlayerHouse1F", "RivalHouse1F", "RivalHouse2F", "RowansLab", "OreburghGym", "OreburghGate", "OreburghMineB1F", "OreburghMine"}){ + ret[std::string(room)].add(std::string(room), story_map(std::string(room)), {0, 0}); + } + ret["RavagedPath"].add("RavagedPath", ravaged_path_smashed(), {0, 0}); + return ret; + }(); + return rooms; +} + +// A world and the JSON maps it holds. +struct PlanWorld{ + const StoryWorld* world; + std::set maps; +}; + +// In order: the first that holds both ends of a walk plans it. Jubilife +// alone comes before the worlds that join it to a route, so 00.05's walks +// plan on the city alone. +const std::vector& plan_worlds(){ + static const std::vector worlds = []{ + std::vector ret{ + {&south_world(), {"TwinleafTown", "Route201", "VerityLakefront", "SandgemTown", "Route202"}}, + {&jubilife_maps(), {"JubilifeCity"}}, + {&oreburgh_city_maps(), {"OreburghCity"}}, + {&route_203_world(), {"Route203", "JubilifeCity"}}, + {&route_204_south_world(), {"JubilifeCity", "Route204South"}}, + {&route_204_north_world(), {"Route204North", "FloaromaTown"}}, + }; + for (const auto& [name, world] : room_worlds()){ + ret.push_back({&world, {name}}); + } + return ret; + }(); + return worlds; +} + +// Route 203's trainers, from the Diamond decomp's events (zone event +// narc_0329): where each stands on the JSON map, the way they look and +// how far. The one by the Gate wanders in BDSP and is off the map. +std::vector route_203_trainer_sights(){ + const auto at = [](std::string_view name){ + for (const Pokemon::MapObject& object : story_map("Route203").objects){ + if (object.name == name){ + return TilePos{object.x, object.y}; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::string("Route 203 has no ") + std::string(name) + "."); + }; + return { + {.name = "Youngster (west)", .pos = at("youngster_1"), .facing = Direction::WEST, .range = 2}, + {.name = "Lass (above row 18)", .pos = at("lass_2"), .facing = Direction::WEST, .range = 5}, + {.name = "Youngster (above row 18)", .pos = at("youngster_3"), .facing = Direction::SOUTH, .range = 4}, + {.name = "Lass (by the Gate)", .pos = at("lass_4"), .facing = Direction::SOUTH, .range = 5}, + }; +} + +std::vector oreburgh_gate_trainer_sights(){ + const auto at = [](std::string_view name){ + for (const Pokemon::MapObject& object : story_map("OreburghGate").objects){ + if (object.name == name){ + return TilePos{object.x, object.y}; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::string("Oreburgh Gate has no ") + std::string(name) + "."); + }; + return { + {.name = "Camper Curtis", .pos = at("camper_1"), .facing = Direction::NORTH, .range = 4}, + {.name = "Picnicker Diana", .pos = at("picnicker_0"), .facing = Direction::SOUTH, .range = 2}, + }; +} + +// The trainers of the JSON map `map`, in its own tiles. +std::vector map_trainers(const std::string& map){ + if (map == "Route202"){ + return route202_trainer_sights(); + } + if (map == "Route203"){ + return route_203_trainer_sights(); + } + if (map == "Route204South"){ + return route204_south_trainer_sights(); + } + if (map == "Route204North"){ + return route204_north_trainer_sights(); + } + return {}; +} + +} // namespace + + +const std::string& story_banner_name(const std::string& map){ + return banner_name(map); +} + +std::string story_arrival_banner(const std::string& from, const std::string& to){ + // The named places, by the place each map is part of: the mine's two floors are one. + static const std::map caves{ + {"OreburghGate", "OreburghGate"}, + {"OreburghMine", "OreburghMine"}, + {"OreburghMineB1F", "OreburghMine"}, + {"RavagedPath", "RavagedPath"}, + }; + const auto place = [](const std::string& map) -> std::string{ + if (banner_names().contains(map)){ + return banner_name(map); + } + const auto cave = caves.find(map); + return cave == caves.end() ? "" : cave->second; + }; + const std::string there = place(to); + return there.empty() || there == place(from) ? "" : story_banner_name(to); +} + +const StoryWorld* story_plan_world(const std::string& from, const std::string& to){ + for (const PlanWorld& world : plan_worlds()){ + if (world.maps.contains(from) && world.maps.contains(to)){ + return world.world; + } + } + return nullptr; +} + +TilePos story_to_world(const StoryWorld& world, const std::string& map, const TilePos& local){ + return world.to_world(banner_name(map), local); +} + +std::optional story_to_local(const StoryWorld& world, const std::string& map, const TilePos& pos){ + const std::optional tile = world.to_local(pos); + if (!tile || tile->map != banner_name(map)){ + return std::nullopt; + } + return tile->pos; +} + +std::optional story_to_local(const StoryWorld& world, const TilePos& pos){ + const std::optional tile = world.to_local(pos); + if (!tile){ + return std::nullopt; + } + for (const PlanWorld& plan : plan_worlds()){ + if (plan.world != &world){ + continue; + } + for (const std::string& map : plan.maps){ + if (banner_name(map) == tile->map){ + return MapTile{map, tile->pos}; + } + } + } + return std::nullopt; +} + +std::vector story_trainers(const StoryWorld& world){ + std::vector sights; + for (const PlanWorld& plan : plan_worlds()){ + if (plan.world != &world){ + continue; + } + for (const std::string& map : plan.maps){ + for (TrainerSight sight : map_trainers(map)){ + sight.pos = story_to_world(world, map, sight.pos); + sights.push_back(std::move(sight)); + } + } + } + return sights; +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h new file mode 100644 index 0000000000..0e84a18163 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h @@ -0,0 +1,60 @@ +/* BDSP AutoStory - Story places + * + * From: https://github.com/PokemonAutomation/ + * + * Where the story's steps walk: poses are tiles of the JSON maps + * ("Route202"), named by map_point() and map_region(). A walk from one map + * to another is planned on a story world that holds both: the outdoors + * from Twinleaf to Route 202, Jubilife, Oreburgh, Route 203 into Jubilife, + * Jubilife up Route 204's south half, Route 204's north half into + * Floaroma, and each interior on its own. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryPlaces_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryPlaces_H + +#include +#include +#include +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TrainerSight.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// The story world a walk from `from` to `to` is planned on, or nothing if +// no world holds both. Its maps are named as the game's location banners +// name them ("Route 202"), which the walker reads. +const StoryWorld* story_plan_world(const std::string& from, const std::string& to); + +// The location banner of the JSON map `map` ("Route 204" for both of its +// halves), or `map` itself for one no banner list names. +const std::string& story_banner_name(const std::string& map); +// The banner (story_banner_name()) a warp from the JSON map `from` onto +// `to` shows, or "" if none: arriving in another town, route or cave shows +// its name (out of the Gym, Oreburgh City's), arriving in a house, a lab, +// a school or another floor of the same cave shows none. +std::string story_arrival_banner(const std::string& from, const std::string& to); + +// The tile `local` of the map `map` in `world`. +Pokemon::TilePos story_to_world(const StoryWorld& world, const std::string& map, const Pokemon::TilePos& local); + +// The world tile `pos` as a tile of `map`, or nothing if it is not on `map`. +std::optional story_to_local(const StoryWorld& world, const std::string& map, const Pokemon::TilePos& pos); +// The world tile `pos` as a tile of whichever JSON map of `world` holds +// it, or nothing if none does. +std::optional story_to_local(const StoryWorld& world, const Pokemon::TilePos& pos); + +// The trainers a walk on `world` may meet (Routes 202 to 204's), in its tiles. +std::vector story_trainers(const StoryWorld& world); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp new file mode 100644 index 0000000000..79bab21f0a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp @@ -0,0 +1,687 @@ +/* BDSP AutoStory Story Simulation Tests + * + * From: https://github.com/PokemonAutomation/ + * + * A run of the whole story table, new game to Floaroma, without the + * console: story_checkpoints() built into one segment as the program builds + * it (make_story_segment()), run by the shared runner with the program's + * retry policy, against a fake game. The fake plans each ROUTE on the story + * world that holds its start and target, walks each LEGS tile by tile, and + * passes every other step unless told to fail it. Events pass as a whole. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_StorySegments.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_GridPose.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "Data/PokemonBDSP_AutoStory_RobustRoute.h" +#include "PokemonBDSP_AutoStory_PlanGolden.h" +#include "Data/PokemonBDSP_AutoStory_WalkRules.h" +#include "Utils/PokemonBDSP_AutoStory_Location.h" +#include "Data/PokemonBDSP_AutoStory_PlanCosts.h" +#include "PokemonBDSP_AutoStory_StoryPlaces.h" +#include "PokemonBDSP_AutoStory_StoryTable.h" +#include "PokemonBDSP_AutoStory_StorySimulation_Tests.h" +#include "Utils/PokemonBDSP_AutoStory_StoryLanguage.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +using Pokemon::Direction; +using Pokemon::GridPose; +using Pokemon::Outcome; +using Pokemon::Pose; +using Pokemon::RunState; +using Pokemon::StoryLeg; +using Pokemon::StoryStep; +using Pokemon::StoryStepKind; +using Pokemon::TilePos; +using Pokemon::story_arg; + +std::string describe(const std::string& map, const std::vector& tiles){ + std::string text = " " + map; + for (const TilePos& pos : tiles){ + text += " " + Pokemon::to_string(pos); + } + return text; +} + +std::string joined(const std::vector& lines){ + std::string text; + for (const std::string& line : lines){ + text += "\n " + line; + } + return text; +} + +bool contains(const std::vector& tiles, const TilePos& pos){ + return std::find(tiles.begin(), tiles.end(), pos) != tiles.end(); +} + +// Where a step ends, or why it does not plan. +struct Walked{ + std::optional at; + std::string error; + std::string plan; + std::vector golden = {}; +}; + +// The tiles a plan walks. +int tiles_walked(const std::vector& plan){ + int tiles = 0; + for (const PlannedLeg& leg : plan){ + tiles += leg.leg.tiles; + } + return tiles; +} + +// A route may walk a little further than the shortest way, for a wall at a +// leg's end, but not round the town: r64 went 38 tiles to the School's door +// for 12 straight (the "town" costs still feared stick-era open legs). +std::string detour_error(const StoryWorld& world, const std::vector& start, + const std::function& at_goal, const std::vector& plan +){ + const auto shortest = plan_robust_route(world, start, at_goal, waypoint_plan_costs()); + const int walked = tiles_walked(plan); + const int least = shortest ? tiles_walked(*shortest) : walked; + if (walked <= least + least / 2 + 4){ + return ""; + } + return std::format("the plan walks {} tiles where {} would do.", walked, least); +} + + +// A ROUTE step from `from`, planned as StoryExecutor::walk_to() walks it. +Walked plan_route(const Pose& from, const StoryStep& step){ + const GridPose& target = story_arg(step.args, "target"); + const Pose goal = Pokemon::pose_of(target); + const StoryWorld* world = story_plan_world(from.map, goal.map); + const std::optional costs = story_route_costs(step.action); + if (world == nullptr || !costs){ + return {std::nullopt, std::format("{}: no world joins {} and {}, or no costs \"{}\".", step.name, from.map, goal.map, step.action), ""}; + } + std::vector start; + for (const TilePos& pos : Pokemon::tiles_of(from)){ + start.push_back(story_to_world(*world, from.map, pos)); + } + std::vector targets; + for (const TilePos& pos : Pokemon::tiles_of(goal)){ + targets.push_back(story_to_world(*world, goal.map, pos)); + } + const std::function at_goal = [&](const TilePos& pos){ return contains(targets, pos); }; + const auto plan = plan_robust_route(*world, start, at_goal, *costs); + if (!plan){ + return {std::nullopt, step.name + ": no plan from" + describe(from.map, Pokemon::tiles_of(from)) + ".", ""}; + } + Walked walked{std::nullopt, "", std::format("{}: {} legs", step.name, plan->size())}; + std::vector local; + for (const PlannedLeg& leg : *plan){ + walked.plan += " " + to_string(leg.leg); + } + walked.golden.push_back(std::format("{} costs={} from{} to{}", step.name, step.action.empty() ? "default" : step.action, + describe(from.map, Pokemon::tiles_of(from)), describe(goal.map, Pokemon::tiles_of(goal)))); + for (const PlannedLeg& leg : *plan){ + std::string line = std::format(" {} ->", to_string(leg.leg)); + for (const TilePos& pos : leg.after){ + line += std::format(" {}", describe(*world, pos)); + } + walked.golden.push_back(line); + } + const std::string detour = detour_error(*world, start, at_goal, *plan); + if (!detour.empty()){ + return {std::nullopt, step.name + ": " + detour, walked.plan}; + } + for (const TilePos& pos : plan->empty() ? start : plan->back().after){ + const std::optional tile = story_to_local(*world, goal.map, pos); + if (!tile || !contains(Pokemon::tiles_of(goal), *tile)){ + return {std::nullopt, step.name + ": the plan may end off the target, at " + describe(*world, pos) + ".", walked.plan}; + } + local.push_back(*tile); + } + walked.at = Pokemon::tile_pose(goal.map, local, Pokemon::facing_of(goal)); + return walked; +} + +// `leg` of `step` from `pos`: adds where it ends to `next` (and a tile +// short where the step allows it). Returns why it is blocked, or "". +std::string walk_leg_from( + const StoryWorld& world, TilePos pos, const Pokemon::StoryLeg& leg, const StoryStep& step, + std::vector& next +){ + for (int i = 0; i < leg.tiles; i++){ + const std::optional stepped = PokemonBDSP::step(world, pos, leg.direction); + if (!stepped){ + return step.name + ": " + direction_name(leg.direction) + " is blocked at " + describe(world, pos) + "."; + } + if (step.action == "one_short_ok" && i + 1 == leg.tiles){ + next.push_back(pos); + } + pos = *stepped; + } + next.push_back(pos); + return ""; +} + +// A LEGS step from `from`, walked tile by tile on its map, a tile short too +// where the step allows it. Walks to walls end where nothing is known. +Walked walk_legs(const Pose& from, const StoryStep& step){ + if (step.action == "to_wall"){ + return {std::nullopt, "", ""}; + } + const StoryWorld* world = story_plan_world(from.map, from.map); + if (world == nullptr){ + return {std::nullopt, step.name + ": no world holds " + from.map + ".", ""}; + } + const auto& legs = story_arg>(step.args, "legs"); + std::vector at; + for (const TilePos& pos : Pokemon::tiles_of(from)){ + at.push_back(story_to_world(*world, from.map, pos)); + } + for (const Pokemon::StoryLeg& leg : legs){ + std::vector next; + for (const TilePos& pos : at){ + const std::string blocked = walk_leg_from(*world, pos, leg, step, next); + if (!blocked.empty()){ + return {std::nullopt, blocked, ""}; + } + } + at = std::move(next); + } + // Legs may cross onto a neighbouring map of the same world (Route 201's + // east end into Sandgem): the pose lands on the map the tiles are on. + std::string map; + std::vector local; + for (const TilePos& pos : at){ + const std::optional tile = story_to_local(*world, pos); + if (!tile){ + return {std::nullopt, step.name + ": the legs end off every map, at " + Pokemon::to_string(pos) + ".", ""}; + } + if (!map.empty() && tile->map != map){ + return {std::nullopt, step.name + ": the legs end across " + map + " and " + tile->map + ".", ""}; + } + map = tile->map; + local.push_back(tile->pos); + } + return {Pokemon::tile_pose(map, local, legs.back().direction), "", ""}; +} + +// A STEP onto the next tile of the same map. +Walked step_on(const Pose& from, const StoryStep& step){ + const Direction direction = story_arg(step.args, "direction"); + std::vector at; + for (const TilePos& pos : Pokemon::tiles_of(from)){ + at.push_back(pos.next(direction)); + } + return {Pokemon::tile_pose(from.map, at, direction), "", ""}; +} + + +// The game: steps pass, routes, legs and steps move the pose on the maps, +// and the steps in `failures` ("/") fail, so many times. +class FakeGame : public Pokemon::StoryStepExecutor{ +public: + struct Failure{ + std::string failure; + size_t times = 0; + }; + + std::vector& trace; + std::map failures; + std::vector plans; + // Every ROUTE's legs, one header line per route, for the golden test. + std::vector golden; + + explicit FakeGame(std::vector& trace) + : trace(trace) + {} + + virtual void begin_attempt(const Pokemon::StoryCheckpoint& data) override{ + m_row = data.id; + trace.push_back("begin " + data.id); + } + virtual Outcome run(const StoryStep& step, RunState& state) override{ + const std::string key = m_row + "/" + step.name; + trace.push_back(key); + auto failure = failures.find(key); + if (failure != failures.end() && failure->second.times > 0){ + failure->second.times--; + return Pokemon::outcome_failed(failure->second.failure, key); + } + switch (step.kind){ + case StoryStepKind::ROUTE: + return route(state, step); + case StoryStepKind::LEGS: + return legs(state, step); + case StoryStepKind::STEP: + return this->step(state, step); + case StoryStepKind::SAVE: + return save(state, step); + default: + return Pokemon::outcome_ok(); + } + } +protected: + Outcome route(RunState& state, const StoryStep& step){ + return moved(plan_route(state.pose, step), "no_plan"); + } + Outcome legs(RunState& state, const StoryStep& step){ + return moved(walk_legs(state.pose, step), "blocked"); + } + Outcome step(RunState& state, const StoryStep& step){ + return moved(step_on(state.pose, step), "blocked"); + } + Outcome save(RunState&, const StoryStep& step){ + trace.push_back("save in " + m_row); + if (!step.action.empty()){ + trace.push_back("card for " + m_row + ": " + step.action); + } + return Pokemon::outcome_ok(); + } +public: + void set_language(PokemonAutomation::Language){} + +private: + Outcome moved(const Walked& walked, std::string_view failure){ + if (!walked.error.empty()){ + return Pokemon::outcome_failed(std::string(failure), walked.error); + } + if (!walked.plan.empty()){ + plans.push_back(walked.plan); + } + for (const std::string& line : walked.golden){ + golden.push_back(std::format("{} {}", m_row, line)); + } + return walked.at ? Pokemon::outcome_ok(*walked.at) : Pokemon::outcome_ok(Pose{}); + } + + std::string m_row; +}; + + +// One simulated run, as the program runs it, in `language`. Japanese has +// no text reader, so a step that needed text would show. (The console's +// global language is left alone: tests run in parallel.) +struct Simulation{ + std::vector trace; + std::vector lines; + FakeGame game{trace}; + std::set saved; + Pokemon::SegmentPolicy policy; + + Pokemon::SegmentReport run(const Pokemon::SegmentRange& range, Language language = Language::Japanese){ + game.set_language(language); + Pokemon::Segment segment = make_story_segment(story_checkpoints(), game, saved); + Pokemon::SegmentHooks hooks; + hooks.reload = [this](RunState&){ + trace.push_back("reload"); + return Pokemon::outcome_ok(); + }; + hooks.log = [this](const std::string& line){ lines.push_back(line); }; + RunState state; + return Pokemon::run_segment(range, policy, segment, hooks, state); + } + std::vector begun() const{ + std::vector ids; + for (const std::string& item : trace){ + if (item.starts_with("begin ")){ + ids.push_back(item.substr(6)); + } + } + return ids; + } + size_t count(const std::string& item) const{ + return (size_t)std::count(trace.begin(), trace.end(), item); + } + bool logged(const std::string& line) const{ + return std::find(lines.begin(), lines.end(), line) != lines.end(); + } +}; + +std::vector all_ids(){ + std::vector ids; + for (const StoryCheckpoint& row : story_checkpoints()){ + ids.push_back(row.id); + } + return ids; +} + + +UnitTestResult test_whole_table(Logger& logger){ + for (Language language : {Language::English, Language::Japanese}){ + Simulation sim; + const Pokemon::SegmentReport report = sim.run({}, language); + for (const std::string& plan : sim.game.plans){ + logger.log(plan); + } + if (!report.completed){ + return std::string(language_data(language).name) + ": expected the whole story through:" + joined(sim.lines); + } + if (sim.begun() != all_ids()){ + return "Unexpected checkpoint order:" + joined(sim.begun()); + } + // Every row saves first but 00.00, which a failure ends; 01.10 and + // 01.11 save again at their ends. + for (const std::string& id : all_ids()){ + const size_t saves = sim.count("save in " + id); + const size_t expected = id == "00.00" ? 0 : id == "01.10" || id == "01.11" ? 2 : 1; + if (saves != expected){ + return std::format("{} saved {} times, expected {}:{}", id, saves, expected, joined(sim.trace)); + } + } + // Each start save checks the card for its row's map. + for (const StoryCheckpoint& row : story_checkpoints()){ + if (!row.saves_in.empty() && sim.count("card for " + row.id + ": " + row.saves_in) != 1){ + return std::format("{}'s start save did not check the card for {}:{}", row.id, row.saves_in, joined(sim.trace)); + } + } + if (report.one_shot_passes() != report.checkpoints_run){ + return "Expected every checkpoint one-shot:" + joined(sim.lines); + } + } + return true; +} + +// The legs planned for every ROUTE of the whole story, against the stored +// copy in PokemonBDSP_AutoStory_PlanGolden.h. A change that should not +// alter any plan must leave this byte-identical. To regenerate after an +// intended plan change: run this suite, and replace the lines of +// BDSP_PLAN_GOLDEN with the lines the failure logs after "GOLDEN|". +UnitTestResult test_golden_plans(Logger& logger){ + Simulation sim; + const Pokemon::SegmentReport report = sim.run({}, Language::English); + if (!report.completed){ + return "expected the whole story through:" + joined(sim.lines); + } + const std::vector& actual = sim.game.golden; + const size_t stored = sizeof(BDSP_PLAN_GOLDEN) / sizeof(BDSP_PLAN_GOLDEN[0]); + size_t first_diff = 0; + while (first_diff < actual.size() && first_diff < stored && actual[first_diff] == BDSP_PLAN_GOLDEN[first_diff]){ + first_diff++; + } + if (first_diff == actual.size() && first_diff == stored){ + return true; + } + for (const std::string& line : actual){ + logger.log(std::format("GOLDEN|{}", line)); + } + return std::format("plans differ from the golden at line {} ({} lines now, {} stored): now \"{}\", stored \"{}\".", + first_diff + 1, actual.size(), stored, + first_diff < actual.size() ? std::string_view(actual[first_diff]) : std::string_view(), + first_diff < stored ? BDSP_PLAN_GOLDEN[first_diff] : std::string_view()); +} + +UnitTestResult test_start_and_end(Logger&){ + Simulation sim; + Pokemon::SegmentReport report = sim.run({.from = "00.04b", .to = "00.04d"}); + if (!report.completed || sim.begun() != std::vector{"00.04b", "00.04c", "00.04d"}){ + return "Expected 00.04b to 00.04d only:" + joined(sim.begun()); + } + Simulation tail; + report = tail.run({.from = "01.10", .to = std::nullopt}); + if (!report.completed || tail.begun() != std::vector{"01.10", "01.11"}){ + return "Expected 01.10 to the end:" + joined(tail.begun()); + } + Simulation one; + report = one.run({.from = "00.02", .to = "00.02"}); + if (!report.completed || one.begun() != std::vector{"00.02"}){ + return "Expected 00.02 alone:" + joined(one.begun()); + } + return true; +} + +// r72: a blackout in 00.04b's training. The checkpoint resets to the save +// it made at its start, does not save again, and walks from that save's +// pose to the grass again. +UnitTestResult test_training_blackout(Logger&){ + Simulation sim; + sim.game.failures["00.04b/train"] = {.failure = "blackout", .times = 1}; + const Pokemon::SegmentReport report = sim.run({.from = "00.04b", .to = "00.04d"}); + const std::vector expected{"00.04b", "00.04b", "00.04c", "00.04d"}; + if (!report.completed || report.reloads != 1 || sim.begun() != expected){ + return "Expected 00.04b reloaded once, then on:" + joined(sim.trace); + } + if (sim.count("save in 00.04b") != 1 || sim.count("00.04b/to_catch_grass") != 2){ + return "Expected the retry to start from 00.04b's one save and walk to the grass again:" + joined(sim.trace); + } + if (!sim.logged("[Checkpoint] 00.04b: passed on attempt 2 (1 reset)")){ + return "Expected the retried pass logged:" + joined(sim.lines); + } + return true; +} + +// A step that fails every time: three attempts from the checkpoint's +// save, then the segment stops on it and runs nothing after. +UnitTestResult test_gives_up_after_attempts(Logger&){ + const std::string step = "01.04/gym_until_roark_beaten"; + Simulation sim; + sim.game.failures[step] = {.failure = "operation_failed", .times = 10}; + const Pokemon::SegmentReport report = sim.run({.from = "01.01", .to = std::nullopt}); + if (report.completed || report.reloads != 2 || report.failed_checkpoint != "01.04" || report.failed_event != "gym_until_roark_beaten" + || report.runs.empty() || report.runs.back().attempts != 3 || sim.count(step) != 3 + || sim.count("save in 01.04") != 1 || sim.count("begin 01.05") != 0 + ){ + return "Expected 01.04 tried 3 times from its save, then a stop:" + joined(sim.trace) + joined(sim.lines); + } + Simulation lab; + lab.policy.attempts_per_checkpoint = 1; + lab.game.failures[step] = {.failure = "operation_failed", .times = 10}; + const Pokemon::SegmentReport stopped = lab.run({.from = "01.01", .to = std::nullopt}); + if (stopped.completed || stopped.reloads != 0 || lab.count("reload") != 0){ + return "Expected a stop at the first failure without a reload:" + joined(lab.trace); + } + return true; +} + +// Each row that has a start pose starts where the row before it leaves +// the player, by the same planning and walking the fake run does. +UnitTestResult test_poses_chain(Logger&){ + std::optional at; + std::string last; + for (const StoryCheckpoint& row : story_checkpoints()){ + if (row.start){ + const Pose start_pose = Pokemon::pose_of(*row.start); + const std::vector start = Pokemon::tiles_of(start_pose); + if (at && (at->map != Pokemon::grid_pose_of(*row.start).map || + !std::ranges::all_of(Pokemon::tiles_of(*at), [&](const TilePos& pos){ return contains(start, pos); })) + ){ + return std::format("{} starts at{}, but {} may end at{}.", row.id, describe(Pokemon::grid_pose_of(*row.start).map, start), + last, describe(at->map, Pokemon::tiles_of(*at))); + } + at = start_pose; + }else{ + at.reset(); + } + for (const StoryStep& step : row.steps){ + if (step.kind == StoryStepKind::ROUTE || step.kind == StoryStepKind::LEGS || step.kind == StoryStepKind::STEP){ + if (!at && step.action != "to_wall" && step.action != "jubilife_stairs"){ + return row.id + " " + step.name + ": walks from an unknown pose."; + } + const Walked walked = !at ? Walked{} : step.kind == StoryStepKind::ROUTE ? plan_route(*at, step) + : step.kind == StoryStepKind::LEGS ? walk_legs(*at, step) : step_on(*at, step); + if (!walked.error.empty()){ + return row.id + " " + walked.error; + } + at = walked.at; + }else if (step.kind == StoryStepKind::GAME || step.kind == StoryStepKind::SHOP || step.kind == StoryStepKind::MASH){ + // A scene or an event: where it ends is the table's to say. + at.reset(); + } + if (step.pose_after){ + at = Pokemon::pose_of(*step.pose_after); + } + } + last = row.id; + } + return true; +} + +// Walks are planned on the maps: a LEGS step ("east 6, north 18") is +// left only where no route can do its job, each with its reason. +UnitTestResult test_no_hand_written_legs(Logger&){ + const std::map exceptions = { + {"00.01/off_barrys_mat", "steps off a door's mat, where no route starts"}, + {"00.03/into_sandgem", "walks until Dawn's scene starts, wherever it starts"}, + {"00.04/to_route_201", "runs until Route 201's banner, wherever it shows"}, + {"00.04/to_moms_call", "walks until Mom calls, wherever she calls"}, + {"00.05/up_to_barry", "starts inside the School's door, from no known tile"}, + {"01.03/down_the_hall", "steps off the hall's warp tile, where no route starts"}, + {"01.03/down_to_the_boulder", "steps off the coal room's warp tile, where no route starts"}, + {"01.03/up_the_hall", "steps off the hall's warp tile, where no route starts"}, + {"01.03/up_to_the_mines_sign", "steps off the mine's exit, where no route starts"}, + {"01.11/up_to_the_old_woman", "walks until the old woman stops us"}, + }; + std::set seen; + for (const StoryCheckpoint& row : story_checkpoints()){ + for (const StoryStep& step : row.steps){ + if (step.kind != StoryStepKind::LEGS){ + continue; + } + const std::string key = std::format("{}/{}", row.id, step.name); + if (!exceptions.contains(key)){ + return std::format("{}: hand-written legs; plan a route to where they end.", key); + } + seen.insert(key); + } + } + for (const auto& item : exceptions){ + if (!seen.contains(item.first)){ + return std::format("{}: listed as an exception, but no such LEGS step.", item.first); + } + } + return true; +} + +// Legs that run off the end of their map land on the next one of the same +// world: east along Route 201's top row ends in Sandgem, not off the map. +UnitTestResult test_legs_cross_maps(Logger&){ + const Pose from = Pokemon::tile_pose("Route201", {{42, 5}}, Direction::EAST); + StoryStep step{.kind = StoryStepKind::LEGS, .name = "east into Sandgem"}; + step.args["legs"] = std::vector{{Direction::EAST, 22}}; + const Walked walked = walk_legs(from, step); + if (!walked.error.empty()){ + return walked.error; + } + if (!walked.at || walked.at->map != "SandgemTown"){ + return "The legs end on " + (walked.at ? walked.at->map : std::string("no pose")) + ", not SandgemTown."; + } + return true; +} + +// With no reader for the game's language, the reads that used text give +// way: a banner or save card that showed matches any map. +UnitTestResult test_no_text_reader(Logger&){ + for (Language language : {Language::Japanese, Language::Korean, Language::French}){ + if (story_reads_text(language)){ + return std::string("Expected no text reader for ") + language_data(language).name + "."; + } + } + if (!location_banner_matches(UNREAD_LOCATION, "Route 202") || location_banner_matches("", "Route 202")){ + return "Expected a shown, unread banner to match and no banner not to."; + } + if (!story_reads_text(Language::English) || location_banner_matches("sandgemtown", "Route 202")){ + return "Expected English banners read and compared."; + } + return true; +} + + +struct AutoStoryStorySimulationInput{ + std::string name; + std::function body; +}; + +struct AutoStoryStorySimulationExpectation{ +}; + +struct AutoStoryStorySimulationCase{ + AutoStoryStorySimulationInput input; + AutoStoryStorySimulationExpectation expectation; +}; + +class Test_StorySimulation : public UnitTest{ +public: + explicit Test_StorySimulation(AutoStoryStorySimulationCase test_case) + : UnitTest("PokemonBDSP::AutoStory - Simulation: " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + AutoStoryStorySimulationCase m_case; +}; + +} // namespace + + +const AutoStoryStorySimulationCase AUTO_STORY_STORY_SIMULATION_CASES[] = { + { + .input = {"00.00 to Floaroma, in order, each row saved first, English and Japanese", test_whole_table}, + .expectation = {}, + }, + { + .input = {"start and end checkpoints", test_start_and_end}, + .expectation = {}, + }, + { + .input = {"a blackout in 00.04b's training resets to its save", test_training_blackout}, + .expectation = {}, + }, + { + .input = {"a step that keeps failing stops after 3 attempts", test_gives_up_after_attempts}, + .expectation = {}, + }, + { + .input = {"each start pose is where the row before ends; routes plan on the maps", test_poses_chain}, + .expectation = {}, + }, + { + .input = {"legs that run off their map land on the next", test_legs_cross_maps}, + .expectation = {}, + }, + { + .input = {"no text reader for the game's language", test_no_text_reader}, + .expectation = {}, + }, + { + .input = {"no hand-written legs but the listed ones", test_no_hand_written_legs}, + .expectation = {}, + }, + { + .input = {"plans match the golden", test_golden_plans}, + .expectation = {}, + }, +}; + +void add_tests_AutoStory_StorySimulation(UnitTestDatabase& database){ + for (const auto& item : AUTO_STORY_STORY_SIMULATION_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StorySimulation_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StorySimulation_Tests.h new file mode 100644 index 0000000000..0363e1e75d --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StorySimulation_Tests.h @@ -0,0 +1,27 @@ +/* BDSP AutoStory Story Simulation Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StorySimulation_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StorySimulation_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Segments 00 and 01 run end to end without a console: the story table, +// the shared segment runner and its retry policy, against a fake game +// that plans every route and walk on the built-in maps. +void add_tests_AutoStory_StorySimulation(UnitTestDatabase& database); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.cpp new file mode 100644 index 0000000000..3977dedaa1 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.cpp @@ -0,0 +1,26 @@ +/* BDSP AutoStory - Story table + * + * From: https://github.com/PokemonAutomation/ + * + * The story from a new game to Floaroma, 00.00 to 01.11, as rows of the + * shared story steps: plain data loaded from the embedded authored plans. + * + */ + +#include "PokemonBDSP_AutoStory_StoryData.h" +#include "PokemonBDSP_AutoStory_StoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +const std::vector& story_checkpoints(){ + static const std::vector checkpoints = load_authored_story(); + return checkpoints; +} + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.h new file mode 100644 index 0000000000..72504da1b8 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.h @@ -0,0 +1,41 @@ +/* BDSP AutoStory - Story table + * + * From: https://github.com/PokemonAutomation/ + * + * The story from a new game to Floaroma, 00.00 to 01.11, as rows of the + * shared story steps (Pokemon/AutoStory/Pokemon_StorySteps.h): plain + * data, as FRLG's table is, so the tests plan its routes and run it + * against a fake game. Each row but 00.00 saves at its start, which is + * where the row before it ends, and only if the save screen's card names + * the row's map (saves_in). + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryTable_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryTable_H + +#include +#include +#include "PokemonBDSP_AutoStory_StoryExecutor.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Checkpoints 00.00 to 01.11, in order: segment 00 (the intro to the +// Poketch) and segment 01 (Jubilife to Floaroma). +const std::vector& story_checkpoints(); + +// Mom gives the Running Shoes in this row's step: from then on, B held +// with the D-pad runs (r24, r27). +inline constexpr std::string_view RUNNING_SHOES_ROW = "00.03"; +// Story step name in which Mom gives the Running Shoes. +inline constexpr std::string_view RUNNING_SHOES_STEP = "rowan_and_dawn"; + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp new file mode 100644 index 0000000000..09f4e95ba9 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp @@ -0,0 +1,298 @@ +/* BDSP AutoStory - Story table Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_GridPose.h" +#include "Data/PokemonBDSP_AutoStory_Maps.h" +#include "Data/PokemonBDSP_AutoStory_PlanCosts.h" +#include "Data/PokemonBDSP_AutoStory_RobustRoute.h" +#include "Data/PokemonBDSP_AutoStory_RoutePlanner.h" +#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" +#include "Actions/PokemonBDSP_AutoStory_Events.h" +#include "Data/PokemonBDSP_AutoStory_WalkRules.h" +#include "PokemonBDSP_AutoStory_StoryTable.h" +#include "PokemonBDSP_AutoStory_StoryTable_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +using Pokemon::Direction; +using Pokemon::StoryStepKind; +using Pokemon::TilePos; +using Pokemon::story_arg; + +// The actions each kind does itself, besides the story's events. +const std::map>& built_in_actions(){ + static const std::map> actions{ + {StoryStepKind::ROUTE, {"", "route", "town", "robust", "line"}}, + {StoryStepKind::LEGS, {"", "legs", "one_short_ok", "to_wall", "to_dialogue", "to_map", "counted_wall"}}, + {StoryStepKind::STEP, {"", "face", "to_banner", "tap"}}, + {StoryStepKind::MASH, {"", "a"}}, + {StoryStepKind::BATTLE, {"", "fight", "doubles", "starter"}}, + {StoryStepKind::TALK, {"", "talk_to_wanderer"}}, + {StoryStepKind::SHOP, {"", "sandgem_potions"}}, + }; + return actions; +} + +// The table: unique ids in order, each row lints, and every step's variant +// is one its kind does or one of the story's events. +UnitTestResult test_story_table_lints(Logger&){ + const StoryEvents& events = story_events(); + std::set ids; + std::string previous; + for (const StoryCheckpoint& row : story_checkpoints()){ + if (!ids.insert(row.id).second || row.id <= previous){ + return row.id + ": repeated or out of order."; + } + previous = row.id; + if ((row.on_failure == StoryFailure::RELOAD_AND_RETRY) == row.saves_in.empty()){ + return row.id + ": a row names the map its start save is made in (saves_in) exactly when it saves first."; + } + const std::vector problems = Pokemon::lint_story_checkpoint(row); + if (!problems.empty()){ + return row.id + ": " + problems[0]; + } + for (const Pokemon::StoryStep& step : row.steps){ + const auto built_in = built_in_actions().find(step.kind); + const bool known = events.contains(step.action) || + (step.kind != StoryStepKind::GAME && step.action.empty()) || + (built_in != built_in_actions().end() && built_in->second.contains(step.action)); + if (!known){ + return std::format("{} {}: no event or {} way named \"{}\".", + row.id, step.name, Pokemon::story_step_kind_name(step.kind), step.action); + } + } + } + if (!ids.contains("00.00") || !ids.contains("01.11") || story_checkpoints().front().on_failure != StoryFailure::STOP){ + return "Expected 00.00 (which stops on a failure) to 01.11."; + } + return true; +} + +// Where a row's last step says it leaves the player: the end of its scene, +// or where its route (or heal) goes. None for a step that does not say. +std::optional end_pose(const StoryCheckpoint& row){ + if (row.steps.empty()){ + return std::nullopt; + } + const Pokemon::StoryStep& last = row.steps.back(); + if (last.pose_after){ + return Pokemon::pose_of(*last.pose_after); + } + if (last.kind == StoryStepKind::ROUTE){ + return Pokemon::pose_of(story_arg(last.args, "target")); + } + return std::nullopt; +} + +// Each row starts where the row before it ends: every tile its start allows +// is one the last row's end allows, on the same map. Checked where the last +// step says where it ends. +UnitTestResult test_story_table_rows_join(Logger&){ + const std::vector& rows = story_checkpoints(); + for (size_t i = 1; i < rows.size(); i++){ + const std::optional end = end_pose(rows[i - 1]); + const std::optional start = rows[i].start ? std::make_optional(Pokemon::pose_of(*rows[i].start)) : std::nullopt; + if (!end || !start){ + continue; + } + const std::vector ends = Pokemon::tiles_of(*end); + bool joins = start->map == end->map; + for (const TilePos& pos : Pokemon::tiles_of(*start)){ + joins = joins && std::find(ends.begin(), ends.end(), pos) != ends.end(); + } + if (!joins){ + return std::format("{} starts at {}, but {} ends at {}.", + rows[i].id, Pokemon::to_string(*start), rows[i - 1].id, Pokemon::to_string(*end)); + } + } + return true; +} + +struct LadyLeg{ + Direction direction; + size_t tiles; // 0: walk until the wall + TilePos end; // world tile + std::string name; +}; + +// 00.04c's Potions: the Mart lady's walk (mart_lady()) is walks until +// stopped, so on the map each leg ends at its wall: from a tile to three +// below the Center's door, a tap east and north to the Center's front, +// west to the Lab's sign, a row south and west to her grass's edge, north +// to the trees on her row (she stands east of there), back a row south and +// east to Route 201's sign, a row south and east to the trees east of the +// Mart, and north to the front row's end. +std::string follow_mart_lady(const StoryWorld& maps, const std::vector& legs, TilePos at, Logger& logger){ + for (const LadyLeg& leg : legs){ + if (leg.tiles == 0){ + at = slide_to_wall(maps, at, leg.direction).stop; + }else{ + const std::optional next = PokemonBDSP::step(maps, at, leg.direction); + if (!next){ + return leg.name + ": blocked at " + describe(maps, at) + "."; + } + at = *next; + } + // The tap east lands on whichever row we stood on. + if (&leg != &legs.front() && !(at == leg.end)){ + return leg.name + ": ends at " + describe(maps, at) + ", not " + describe(maps, leg.end) + "."; + } + logger.log(leg.name + ": " + describe(maps, at)); + } + return ""; +} + +UnitTestResult test_mart_lady_walk(Logger& logger){ + const StoryWorld& maps = story_maps(); + const auto sandgem = [&](const TilePos& pos){ return maps.to_world(MAP_SANDGEM_TOWN, pos); }; + const auto route201 = [&](const TilePos& pos){ return maps.to_world(MAP_ROUTE_201, pos); }; + const std::vector legs{ + {Direction::EAST, 1, sandgem({18, 0}), "a tap east under the Center's wall"}, + {Direction::NORTH, 0, sandgem({18, 11}), "north to the Center's front"}, + {Direction::WEST, 0, sandgem({6, 11}), "west to the Lab's sign"}, + {Direction::SOUTH, 1, sandgem({6, 12}), "a row south onto the path"}, + {Direction::WEST, 0, route201({42, 5}), "west to her grass's edge"}, + {Direction::NORTH, 0, route201({42, 3}), "north to the trees, on her row"}, + {Direction::SOUTH, 1, route201({42, 4}), "a row south onto the signs' row"}, + {Direction::EAST, 0, route201(map_point("Route201", "border_sign").next(Direction::WEST)), "east to Route 201's sign"}, + {Direction::SOUTH, 1, route201({54, 5}), "a row south onto the path"}, + {Direction::EAST, 0, sandgem({29, 12}), "east to the trees east of the Mart"}, + {Direction::NORTH, 0, sandgem(map_point("SandgemTown", "front_row_east_end")), "north to the front row's end"}, + }; + // Out of the Center's door we stand a tile to three below it (r261). + for (int below = 1; below <= 3; below++){ + const std::string error = follow_mart_lady(maps, legs, sandgem({17, 10 + below}), logger); + if (!error.empty()){ + return std::format("From {} below the door: {}", below, error); + } + } + return true; +} + +// 01.10 on Route 204's north half: the line a human walked (2026-10-31), +// corner to corner, from the Ravaged Path's exit into Floaroma. Each +// stretch must plan as the one straight tap leg the human took, on the map +// as it is: a detour here means the map or the line changed. +UnitTestResult test_route204_north_line(Logger& logger){ + const StoryWorld& route = route204_north_maps(); + const std::vector waypoints = map_region("Route204North", "floaroma_waypoints"); + struct Expected{ Direction direction; size_t tiles; }; + const std::vector expected{ + {Direction::SOUTH, 1}, {Direction::WEST, 9}, {Direction::NORTH, 5}, {Direction::EAST, 8}, + {Direction::NORTH, 10}, {Direction::WEST, 8}, {Direction::NORTH, 7}, + }; + if (waypoints.size() != expected.size()){ + return std::format("Route 204 North: {} waypoints, expected {}.", waypoints.size(), expected.size()); + } + std::vector at{map_point("Route204North", "cave_exit")}; + for (size_t i = 0; i < waypoints.size(); i++){ + const TilePos goal = waypoints[i]; + const std::string name = std::format("Route 204 North stretch {} to {}", i + 1, describe(route, goal)); + const auto plan = plan_robust_route(route, at, [&](const TilePos& pos){ return pos == goal; }, waypoint_plan_costs()); + if (!plan){ + return name + ": no plan."; + } + if (plan->size() != 1){ + return std::format("{}: {} legs, expected the one straight leg.", name, plan->size()); + } + const TileLeg& leg = (*plan)[0].leg; + logger.log(name + ": " + to_string(leg)); + if (leg.ends_at_wall || leg.direction != expected[i].direction || leg.tiles != expected[i].tiles){ + return std::format("{}: planned {}, expected an open leg of {} tiles.", name, to_string(leg), expected[i].tiles); + } + if ((*plan)[0].after.size() != 1 || !((*plan)[0].after[0] == goal)){ + return name + ": the leg does not end exactly on the waypoint."; + } + at = {goal}; + } + if (!in_floaroma_path(at[0])){ + return "Route 204 North: the last waypoint is not in the path into Floaroma."; + } + return true; +} + + +struct AutoStoryStoryTableInput{ + std::string name; + std::function body; +}; + +struct AutoStoryStoryTableExpectation{ +}; + +struct AutoStoryStoryTableCase{ + AutoStoryStoryTableInput input; + AutoStoryStoryTableExpectation expectation; +}; + +class Test_AutoStoryStoryTable : public UnitTest{ +public: + explicit Test_AutoStoryStoryTable(AutoStoryStoryTableCase test_case) + : UnitTest("PokemonBDSP::AutoStory - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + AutoStoryStoryTableCase m_case; +}; + +} // namespace + + +const AutoStoryStoryTableCase AUTO_STORY_STORY_TABLE_CASES[] = { + { + .input = {"Story table: rows lint, variants known", test_story_table_lints}, + .expectation = {}, + }, + { + .input = {"Story table: each row starts where the last one ends", test_story_table_rows_join}, + .expectation = {}, + }, + { + .input = {"00.04: the walk to the Poke Mart lady and back", test_mart_lady_walk}, + .expectation = {}, + }, + { + .input = {"Route 204 North: the line into Floaroma", test_route204_north_line}, + .expectation = {}, + }, +}; + +void add_tests_AutoStory_StoryTable(UnitTestDatabase& database){ + for (const auto& item : AUTO_STORY_STORY_TABLE_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.h new file mode 100644 index 0000000000..cff4508962 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.h @@ -0,0 +1,25 @@ +/* BDSP AutoStory - StoryTable Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryTable_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryTable_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Tests that need no console: the story table: rows lint, every step's variant is known, and the walks its events plan. +void add_tests_AutoStory_StoryTable(UnitTestDatabase& database); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index 99cb510515..37e501f309 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -3,18 +3,23 @@ * From: https://github.com/PokemonAutomation/ * * StoryWorld on small synthetic maps: what each tile does to a step, maps - * joined at offsets, and tiles blocked or taken off the maps. + * joined at offsets, and tiles blocked or taken off the maps. Also the + * story's own worlds: their connected maps step across every map edge + * where the world grid does. * */ #include #include #include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" #include "Data/PokemonBDSP_AutoStory_StoryWorld.h" #include "Data/PokemonBDSP_AutoStory_WalkRules.h" +#include "PokemonBDSP_AutoStory_StoryPlaces.h" #include "PokemonBDSP_AutoStory_StoryWorld_Tests.h" namespace PokemonAutomation{ @@ -219,10 +224,127 @@ const StoryWorldCase STORY_WORLD_CASES[] = { }, }; +namespace{ + +// Whether stepping `direction` from `from` lands on the same map and tile +// on the world grid as on the connected maps (or nowhere on both). +bool steps_agree(const StoryWorld& world, const Pokemon::MapPlace& from, Direction direction){ + const Pokemon::ConnectedMaps connected = connected_maps(world); + const std::string& name = connected.map(from.map).name; + const std::optional grid = world.to_local(world.to_world(name, from.tile).next(direction)); + const std::optional place = connected.neighbour(from, direction); + if (grid && place){ + return grid->map == connected.map(place->map).name && grid->pos == place->tile; + } + return !grid && !place; +} + +// The first step off a map's edge, from any of its tiles, that lands +// somewhere else on the connected maps than on the world grid, or nothing. +std::optional edge_mismatch(const StoryWorld& world){ + const Pokemon::ConnectedMaps connected = connected_maps(world); + for (size_t index = 0; index < connected.size(); index++){ + const Pokemon::Grid& tiles = connected.map(index).tiles; + for (int cell = 0; cell < tiles.width * tiles.height; cell++){ + const TilePos from{cell % tiles.width, cell / tiles.width}; + for (Direction direction : Pokemon::ALL_DIRECTIONS){ + if (tiles.contains(from.next(direction)) || steps_agree(world, {index, from}, direction)){ + continue; + } + return std::format("{} {} {}: the grid and the connected maps disagree.", + connected.map(index).name, Pokemon::to_string(from), Pokemon::direction_name(direction)); + } + } + } + return std::nullopt; +} + +struct ConnectedWorldInput{ + std::string_view name; + // The story's plan world between two places (story_plan_world()), or, + // if `world` is set, that world. + std::string_view plan_from = {}; + std::string_view plan_to = {}; + const StoryWorld& (*world)() = nullptr; +}; +struct ConnectedWorldExpectation{ + // Connections over all the maps: two for each pair that meets. + size_t connections = 0; +}; +struct ConnectedWorldCase{ + ConnectedWorldInput input; + ConnectedWorldExpectation expectation; +}; + +class Test_ConnectedStoryWorld : public UnitTest{ +public: + explicit Test_ConnectedStoryWorld(ConnectedWorldCase test_case) + : UnitTest(std::format("PokemonBDSP::AutoStory - Story world as connected maps: {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const ConnectedWorldInput& input = m_case.input; + const StoryWorld* found = input.world != nullptr + ? &input.world() + : story_plan_world(std::string(input.plan_from), std::string(input.plan_to)); + if (found == nullptr){ + return std::format("No story plan world from {} to {}.", input.plan_from, input.plan_to); + } + const StoryWorld& world = *found; + if (std::optional error = edge_mismatch(world)){ + return *error; + } + const Pokemon::ConnectedMaps connected = connected_maps(world); + size_t connections = 0; + for (size_t index = 0; index < connected.size(); index++){ + connections += connected.map(index).connections.size(); + } + if (connections != m_case.expectation.connections){ + return std::format("{} connections, expected {}.", connections, m_case.expectation.connections); + } + return true; + } + +private: + ConnectedWorldCase m_case; +}; + +const ConnectedWorldCase CONNECTED_WORLD_CASES[] = { + { + .input = {.name = "Route 201, Sandgem and Route 202", .world = story_maps}, + .expectation = {.connections = 4}, + }, + { + .input = {.name = "Twinleaf to Route 202", .plan_from = "TwinleafTown", .plan_to = "Route202"}, + .expectation = {.connections = 8}, + }, + { + .input = {.name = "Route 203 into Jubilife", .plan_from = "Route203", .plan_to = "JubilifeCity"}, + .expectation = {.connections = 2}, + }, + { + .input = {.name = "Jubilife up Route 204's south half", .plan_from = "JubilifeCity", .plan_to = "Route204South"}, + .expectation = {.connections = 2}, + }, + { + .input = {.name = "Route 204's north half into Floaroma", .plan_from = "Route204North", .plan_to = "FloaromaTown"}, + .expectation = {.connections = 2}, + }, + { + .input = {.name = "Jubilife alone", .world = jubilife_maps}, + .expectation = {.connections = 0}, + }, +}; + +} // namespace + void add_tests_AutoStory_StoryWorld(UnitTestDatabase& database){ for (const auto& item : STORY_WORLD_CASES){ database.add(item); } + for (const ConnectedWorldCase& item : CONNECTED_WORLD_CASES){ + database.add(item); + } } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.cpp index 38f63b69d4..58d2dabb0b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -17,6 +18,8 @@ #include "Utils/PokemonBDSP_AutoStory_Location.h" #include "Utils/PokemonBDSP_AutoStory_RouteWalk.h" #include "Utils/PokemonBDSP_AutoStory_Walk.h" +#include "Actions/PokemonBDSP_AutoStory_Talks.h" +#include "Utils/PokemonBDSP_AutoStory_Walk.h" #include "PokemonBDSP_AutoStory_Walk_Tests.h" #include "Utils/PokemonBDSP_AutoStory_WalkResult.h" #include "Utils/PokemonBDSP_AutoStory_WalkScreen.h" @@ -262,6 +265,122 @@ UnitTestResult test_location_banner_showing(Logger& logger){ } + +// walk_view_shift(): a step scrolls the whole view; scenery that moves on +// its own does not. Synthetic 384x216 screens of 8-pixel blocks in mixed +// colours, as grass and flowers are, with one change each. +uint32_t scenery_at(int x, int y){ + const uint32_t block = (uint32_t)((x >> 3) * 73856093u) ^ (uint32_t)((y >> 3) * 19349663u); + const uint32_t hashed = block * 2654435761u; + return 0xff000000 | (hashed & 0x00ffffff); +} +ImageRGB32 scenery(int shift_x, int shift_y){ + ImageRGB32 screen(384, 216); + for (int y = 0; y < 216; y++){ + for (int x = 0; x < 384; x++){ + screen.pixel(x, y) = scenery_at(x + shift_x + 1000, y + shift_y + 1000); + } + } + return screen; +} +// Each colour channel of the pixels in [x0, x1) x [y0, y1) times `scale`, +// or set to `fill` if given. +void paint(ImageRGB32& screen, int x0, int y0, int x1, int y1, double scale, uint32_t fill = 0){ + for (int y = y0; y < y1; y++){ + for (int x = x0; x < x1; x++){ + uint32_t p = screen.pixel(x, y); + if (fill != 0){ + screen.pixel(x, y) = fill; + continue; + } + uint32_t out = 0xff000000; + for (int shift = 0; shift < 24; shift += 8){ + out |= (uint32_t)(((p >> shift) & 0xff) * scale) << shift; + } + screen.pixel(x, y) = out; + } + } +} + +UnitTestResult test_view_shift(Logger&){ + const ImageRGB32 before = scenery(0, 0); + struct Case{ + std::string name; + ImageRGB32 after; + bool scrolled; + }; + std::vector cases; + cases.push_back({"the same view", scenery(0, 0), false}); + cases.push_back({"a step east: the view scrolls 16 pixels west", scenery(16, 0), true}); + cases.push_back({"a step south", scenery(0, 12), true}); + { + // r83, r84: a cloud's shadow over the top of the view. + ImageRGB32 shadow = scenery(0, 0); + paint(shadow, 0, 0, 384, 90, 0.6); + cases.push_back({"a cloud shadow over the top third", std::move(shadow), false}); + } + { + // Jubilife's TV screens, the mine's conveyors. + ImageRGB32 tv = scenery(0, 0); + paint(tv, 20, 20, 110, 80, 0, 0xffffffff); + cases.push_back({"a TV lights up in a corner", std::move(tv), false}); + } + { + // A turn changes only the player's sprite. + ImageRGB32 turned = scenery(0, 0); + paint(turned, 175, 75, 210, 150, 0, 0xffff4040); + cases.push_back({"the player turns", std::move(turned), false}); + } + for (const Case& item : cases){ + const ViewShift shift = walk_view_shift(before, item.after); + if (shift.scrolled() != item.scrolled){ + return std::format("{}: {} (shift {}, {}; difference {:.1f} unshifted, {:.1f} shifted).", + item.name, item.scrolled ? "did not read as a scroll" : "read as a scroll", + shift.dx, shift.dy, shift.unshifted, shift.shifted); + } + } + const ViewShift east = walk_view_shift(before, scenery(16, 0)); + if (east.dx != -8 || east.dy != 0){ + return std::format("A 16-pixel scroll west read as ({}, {}) on the half-size copy, expected (-8, 0).", east.dx, east.dy); + } + return true; +} + +// pokemon_center_on_screen(): the Center's warm floor in a room. r79 read +// Jubilife's yellow plaza as a Center and called a won battle lost. +UnitTestResult test_pokemon_center_on_screen(Logger&){ + constexpr uint32_t FLOOR = 0xfff0c860; // the Center's warm yellow + constexpr uint32_t WALL = 0xffe08030; // its orange back wall + constexpr uint32_t GRASS = 0xff60b040; + struct Case{ + std::string name; + uint32_t top; + uint32_t bottom; + double dark_bottom; // how much of the screen's height, from the bottom, is black + bool center; + }; + const std::vector cases{ + {"a Center: wall over floor, black below it", WALL, FLOOR, 0.15, true}, + {"Jubilife's plaza: yellow paving, no black edge", FLOOR, FLOOR, 0, false}, + {"a street: grass over yellow paving", GRASS, FLOOR, 0, false}, + {"a grey gym in a room", 0xff808080, 0xff909090, 0.15, false}, + }; + for (const Case& item : cases){ + ImageRGB32 screen(1920, 1080); + const size_t dark_from = (size_t)(1080 * (1 - item.dark_bottom)); + for (size_t y = 0; y < 1080; y++){ + for (size_t x = 0; x < 1920; x++){ + screen.pixel(x, y) = y >= dark_from ? 0xff000000 : y < 540 ? item.top : item.bottom; + } + } + if (pokemon_center_on_screen(screen) != item.center){ + return item.name + (item.center ? ": not read as a Center." : ": read as a Center."); + } + } + return true; +} + + struct AutoStoryWalkInput{ std::string name; std::function body; @@ -364,6 +483,14 @@ const AutoStoryWalkCase AUTO_STORY_WALK_CASES[] = { .input = {"location banner showing", test_location_banner_showing}, .expectation = {}, }, + { + .input = {"a Pokemon Center is its floor in a room, not a yellow plaza", test_pokemon_center_on_screen}, + .expectation = {}, + }, + { + .input = {"a step scrolls the view; moving scenery does not", test_view_shift}, + .expectation = {}, + }, { .input = {"a wild battle on an open leg's taps, placed by its screen events", test_leg_battle_place}, .expectation = {}, @@ -377,7 +504,6 @@ void add_tests_AutoStory_Walk(UnitTestDatabase& database){ } - } // namespace PokemonBDSP } // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp new file mode 100644 index 0000000000..2c4578fadd --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp @@ -0,0 +1,252 @@ +/* BDSP AutoStory - Walks + * + * From: https://github.com/PokemonAutomation/ + * + * Walks measured on the console that the planner does not make: straight + * holds and D-pad taps, walks until something stops us, and the ways in + * and out of doors. + * + */ + +#include +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "Actions/PokemonBDSP_AutoStory_Talks.h" +#include "Actions/PokemonBDSP_AutoStory_WildBattle.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h" +#include "PokemonBDSP_AutoStory_Walks.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; + + +std::pair dpad_of(Direction direction){ + switch (direction){ + case Direction::NORTH: + return {0, 1}; + case Direction::EAST: + return {1, 0}; + case Direction::SOUTH: + return {0, -1}; + case Direction::WEST: + return {-1, 0}; + } + return {0, 0}; +} + +void walk_until_stopped(VideoStream& stream, ProControllerContext& context, Direction direction, size_t tiles, const std::string& label){ + const bool across = direction == Direction::EAST || direction == Direction::WEST; + const auto [x, y] = dpad_of(direction); + // Twice every tile's time, and time for the wall to read as still: it + // stops at the wall anyway. One tile's time each fell short once the + // turn stopped stepping us ahead (r57: west to Jubilife's sign ended + // on the time, a column short). + const Milliseconds limit = ROUTE_START_DELAY + 800ms + + (int64_t)tiles * 2 * (across ? ROUTE_MS_PER_TILE_ACROSS : ROUTE_MS_PER_TILE_UP_DOWN); + // Turn first: the first press of a new way only turns us, the screen + // holds still meanwhile, and that read as a wall two tiles into the + // walk west to the Lab's sign (r132a). + route_turn(stream, context, direction); + const WalkResult walked = walk_until(stream, context, run_from_wild_battle, {x, y}, limit, label); + stream.log("[Walk] " + label + ": stopped on " + walk_stop_name(walked.stop) + "."); + if (walked.stop == WalkStop::TRANSITION || walked.stop == WalkStop::DIALOG){ + fail_step(stream, label + ": " + walk_stop_name(walked.stop) + " instead of a stop."); + } + // The leg was measured to end against a wall, so holding toward it + // for every tile's time leaves us there whatever the screen shows: + // people walking or a TV screen nearby kept it changing and the stop + // went unseen (r162a, r167a, r171a). Seeing the stop only ends the + // hold early; a wrong place is caught by the next gate (a sign, a + // door, someone who answers). + if (walked.stop == WalkStop::LIMIT){ + stream.log("[Walk] " + label + ": held for " + std::to_string(tiles) + + " tiles' time without seeing the stop; taking the wall as reached."); + } +} + +void hold_for(VideoStream& stream, ProControllerContext& context, Direction direction, Milliseconds hold, const std::string& label){ + const auto [x, y] = dpad_of(direction); + const WalkResult walk = walk_for(stream, context, run_from_wild_battle, {x, y}, hold, label); + if (walk.stop == WalkStop::DIALOG || walk.stop == WalkStop::TRANSITION){ + fail_step(stream, label + ": " + walk_stop_name(walk.stop) + "."); + } +} + +void tap_tiles(VideoStream& stream, ProControllerContext& context, Direction direction, size_t tiles, const std::string& label){ + const auto [x, y] = dpad_of(direction); + stream.log("[Walk] " + label + ": " + std::to_string(tiles) + " taps."); + for (size_t i = 0; i < tiles; i++){ + pbf_move_left_joystick(context, {x, y}, 160ms, 400ms); + } + pbf_wait(context, 800ms); + context.wait_for_all_requests(); +} + +void nudge(VideoStream& stream, ProControllerContext& context, Direction direction, const std::string& label){ + route_turn(stream, context, direction); + walk_for(stream, context, run_from_wild_battle, {direction == Direction::EAST ? 1.0 : -1.0, 0.0}, 80ms, label); +} + +bool door_north_by_scene(VideoStream& stream, ProControllerContext& context, const std::string& label){ + context.wait_for_all_requests(); + VideoSnapshot before = stream.video().snapshot(); + const WalkResult up = walk_until(stream, context, run_from_wild_battle, {0, 1}, 1200ms, label); + context.wait_for(1500ms); + if (up.stop == WalkStop::TRANSITION){ + return true; + } + // The School's fade is not always black enough to read as one: r146b + // went in (changes 156, 261) and read "limit". A whole new scene is + // through, as leave_door_south() counts it. + VideoSnapshot after = stream.video().snapshot(); + const bool through = before && after && walk_screen_change(*before.frame, *after.frame) > WALK_SCENE_CHANGE; + if (through){ + stream.log("[Route] " + label + ": a new scene; through the door."); + } + return through; +} + +// One tile south, for a player facing another way. +void step_south(VideoStream& stream, ProControllerContext& context){ + route_turn(stream, context, Direction::SOUTH); + pbf_move_left_joystick(context, {0, -1}, route_open_hold(Direction::SOUTH, 1), 200ms); + context.wait_for_all_requests(); +} + +// Holds the stick toward `dir` for `tiles` tiles, turning first. +void hold_tiles(VideoStream& stream, ProControllerContext& context, Direction dir, size_t tiles){ + route_turn(stream, context, dir); + const double x = dir == Direction::EAST ? 1 : dir == Direction::WEST ? -1 : 0; + const double y = dir == Direction::NORTH ? 1 : dir == Direction::SOUTH ? -1 : 0; + pbf_move_left_joystick(context, {x, y}, route_open_hold(dir, tiles), 200ms); + context.wait_for_all_requests(); +} + +WalkResult walk_dir( + VideoStream& stream, ProControllerContext& context, Direction dir, Milliseconds limit, const std::string& label, + const std::function& arrived +){ + const double x = dir == Direction::EAST ? 1 : dir == Direction::WEST ? -1 : 0; + const double y = dir == Direction::NORTH ? 1 : dir == Direction::SOUTH ? -1 : 0; + return walk_until(stream, context, run_from_wild_battle, {x, y}, limit, label, arrived); +} + +// `taps` D-pad taps toward `dpad`, settling between them. On the D-pad the +// player moves a whole tile per tap (measured above), so counted legs do +// not drift the way stick holds do. +void dpad_tiles(VideoStream& stream, ProControllerContext& context, DpadPosition dpad, size_t taps, const std::string& label){ + stream.log("[Walk] " + label + ": " + std::to_string(taps) + " D-pad taps."); + // No turn tap: a 160 ms tap is a whole step from any facing, so N taps + // are N tiles (r80: the old 160 ms "turn" tap walked one tile too many, + // two tiles west in the Ravaged Path, not one). Turning only matters to + // talk to someone, and they block like a wall, so a tap toward them turns. + size_t moved = 0; + // Count only taps that moved the view: one after the turn was lost and + // the leg ended a tile short (r215d). A tile's scroll changes the view by + // about 100; standing still, under 15. A tap that does not move is someone + // in the way: people walk about these streets (r220g: blocked on tap 9 + // for 12 s while a passer-by stood in our row). Wait for them to move on, + // up to 30 s, before giving up. + const auto deadline = current_time() + std::chrono::milliseconds(taps * 1000 + 30000); + while (moved < taps && current_time() < deadline){ + context.wait_for_all_requests(); + const VideoSnapshot before = stream.video().snapshot(); + pbf_press_dpad(context, dpad, 160ms, 700ms); + context.wait_for_all_requests(); + const VideoSnapshot after = stream.video().snapshot(); + const double change = before && after ? walk_screen_change(*before.frame, *after.frame) : 100; + if (!before || !after || tap_moved(*before.frame, *after.frame, 30)){ + moved++; + continue; + } + stream.log("[Walk] " + label + ": tap " + std::to_string(moved + 1) + " did not move (view change " + std::to_string(change) + "); someone in the way? Waiting."); + if (dialogue_opens(stream, context, 300ms)){ + talk_or_fight(stream, context, label + ": someone in the way"); + } + context.wait_for(1500ms); + } + if (moved < taps){ + fail_step(stream, label + ": only " + std::to_string(moved) + " of " + std::to_string(taps) + " D-pad taps moved us."); + } +} + +// Through a door straight north of us: tap up to face it, hold up into it, +// and wait for its dark fade (by hand: brightness 7, about 1 s after). +bool dpad_through_door_north(VideoStream& stream, ProControllerContext& context, const std::string& label){ + pbf_press_dpad(context, DPAD_UP, 160ms, 300ms); + pbf_press_dpad(context, DPAD_UP, 300ms, 0ms); + context.wait_for_all_requests(); + const auto start = current_time(); + while (current_time() - start < 5000ms){ + context.wait_for(100ms); + const VideoSnapshot frame = stream.video().snapshot(); + if (frame && mean_brightness(*frame.frame) < 25){ + stream.log("[Route] " + label + ": the screen went dark; through the door."); + context.wait_for(2000ms); + return true; + } + } + stream.log("[Route] " + label + ": no dark screen after the D-pad step north."); + return false; +} + +// For a player inside a Pokemon Center after a whiteout, at the counter: +// out through the door. The door is straight south of the nurse in most +// Centers; in Oreburgh's it was two tiles east of where we stood (by hand). +void walk_out_of_center(VideoStream& stream, ProControllerContext& context, const std::string& label){ + finish_dialogue(stream, context, BUTTON_B, label + ": the nurse"); + const int shifts[] = {0, 2, -4}; + for (int shift : shifts){ + if (shift != 0){ + hold_tiles(stream, context, shift > 0 ? Direction::EAST : Direction::WEST, (size_t)std::abs(shift)); + } + // A tile at a time, looking after each, so we stop on the doorstep: + // walk_until() looks only between 400 ms holds, and r205d held on + // through the fade and stepped a tile further south. + bool out = false; + for (size_t tile = 0; tile < 10 && !out; tile++){ + // D-pad taps: whole tiles (the first only turns us from the nurse). + pbf_press_dpad(context, DPAD_DOWN, 160ms, 0ms); + context.wait_for(1500ms); + if (dialogue_opens(stream, context, 100ms)){ + finish_dialogue(stream, context, BUTTON_B, label + ": someone in the Center"); + } + const VideoSnapshot frame = stream.video().snapshot(); + size_t percent = 100; + if (frame){ + center_floor_on_screen(*frame.frame, &percent); + } + out = percent < 30; + } + if (out){ + // "No floor" also reads true on the door's black fade, and the game + // takes no input until it ends: the first D-pad taps after it were + // lost and the gym's door ended a tile away (r215d, r216d; a shot + // per press by hand showed the black frame). Wait for daylight. + const auto start = current_time(); + while (current_time() - start < 6000ms){ + context.wait_for(100ms); + const VideoSnapshot frame = stream.video().snapshot(); + if (frame && mean_brightness(*frame.frame) > 40){ + break; + } + } + context.wait_for(1000ms); + return; + } + } + fail_step(stream, label + ": could not find the Pokemon Center's door."); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h new file mode 100644 index 0000000000..a24689d60e --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h @@ -0,0 +1,82 @@ +/* BDSP AutoStory - Walks + * + * From: https://github.com/PokemonAutomation/ + * + * Walks measured on the console that the planner does not make: straight + * holds and D-pad taps, walks until something stops us, and the ways in + * and out of doors. Each fails the step with a screenshot when the walk + * ends where it should not (a dialogue or a door on a walk to a wall). + * + */ + +// code-health: allow header_symbols -- movement primitives measured on console that are used across story executor and event scripts +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Walks_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Walks_H + +#include +#include +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Tools/VideoStream.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// The stick's (x, y) for `direction`: y is up the screen. +std::pair dpad_of(Pokemon::Direction direction); + +// Walks `direction` until something stops us, for at most `tiles` tiles' +// time, turning first. Holding on for the whole time counts as stopped: +// the leg was measured to end against a wall. Fails on a transition or a +// dialogue. +void walk_until_stopped(VideoStream& stream, ProControllerContext& context, Pokemon::Direction direction, size_t tiles, const std::string& label); +// Holds the stick `direction` for `hold` from standing still (200 ms is a +// row, turning included; 160 ms a tile across, facing that way already). +// Fails on a transition or a dialogue. +void hold_for(VideoStream& stream, ProControllerContext& context, Pokemon::Direction direction, Milliseconds hold, const std::string& label); +// `tiles` one-tile taps `direction` in a row, facing that way already, +// without waiting for the screen to settle in between: six of these moved +// exactly six tiles on the console, where six single holds moved seven +// (2026-10-30). +void tap_tiles(VideoStream& stream, ProControllerContext& context, Pokemon::Direction direction, size_t tiles, const std::string& label); +// Half a tile `direction` (EAST or WEST), facing it first. +void nudge(VideoStream& stream, ProControllerContext& context, Pokemon::Direction direction, const std::string& label); +// Walks north; true if a door took us through, by its fade or by a whole +// new scene (the Trainers' School's fade is not always black, r146b). +bool door_north_by_scene(VideoStream& stream, ProControllerContext& context, const std::string& label); + +// One tile south, for a player facing another way. +void step_south(VideoStream& stream, ProControllerContext& context); +// Holds the stick toward `dir` for `tiles` tiles, turning first. +void hold_tiles(VideoStream& stream, ProControllerContext& context, Pokemon::Direction dir, size_t tiles); +// walk_until() toward `dir`. +WalkResult walk_dir( + VideoStream& stream, ProControllerContext& context, Pokemon::Direction dir, Milliseconds limit, const std::string& label, + const std::function& arrived = nullptr +); + +// `taps` D-pad taps toward `dpad`, settling between them. On the D-pad the +// player moves a whole tile per tap, so counted legs do not drift the way +// stick holds do. The first tap toward a new way only turns the player, so +// turn first. +void dpad_tiles(VideoStream& stream, ProControllerContext& context, DpadPosition dpad, size_t taps, const std::string& label); +// Through a door straight north of us: tap up to face it, hold up into it, +// and wait for its dark fade (by hand: brightness 7, about 1 s after). +bool dpad_through_door_north(VideoStream& stream, ProControllerContext& context, const std::string& label); +// For a player inside a Pokemon Center after a whiteout, at the counter: +// out through the door. The door is straight south of the nurse in most +// Centers; in Oreburgh's it was two tiles east of where we stood (by hand). +void walk_out_of_center(VideoStream& stream, ProControllerContext& context, const std::string& label); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.00.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.00.plan.json new file mode 100644 index 0000000000..6b40e409c8 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.00.plan.json @@ -0,0 +1,40 @@ +{ + "checkpoint": { + "events": [ + { + "declared_after": { + "facing": "north", + "map": "PlayerHouse2F", + "tiles": [ + [ + 4, + 6 + ] + ] + }, + "id": "intro", + "kind": "new_game", + "skip_if": [ + "save_loaded" + ], + "why": "language, appearance, the player's name, Barry's default name" + }, + { + "id": "settings", + "kind": "options", + "why": "fast text, Send to Boxes automatic, no nickname prompt, Autosave off" + } + ], + "id": "00.00", + "title": "New game: the intro and the settings" + }, + "execution": { + "on_failure": "stop", + "saves_in": "" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.01.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.01.plan.json new file mode 100644 index 0000000000..bca1f4918c --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.01.plan.json @@ -0,0 +1,483 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "PlayerHouse2F", + "tiles": [ + [ + 7, + 5 + ] + ] + } + }, + "id": "below_the_flute", + "kind": "route", + "why": "below the Azure Flute's tile" + }, + { + "action": "azure_flute_if_there", + "declared_after": { + "facing": "north", + "map": "PlayerHouse2F", + "tiles": [ + [ + 7, + 5 + ] + ] + }, + "id": "azure_flute_if_there", + "kind": "game_action", + "why": "take the Azure Flute if this save has one" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "PlayerHouse2F", + "tiles": [ + [ + 8, + 4 + ] + ] + } + }, + "id": "onto_the_flute_tile", + "kind": "route", + "why": "onto the top of the stairs' mat (8, 4), past the flute's tile" + }, + { + "args": { + "direction": "east" + }, + "declared_after": { + "map": "PlayerHouse1F", + "tiles": [ + [ + 10, + 3 + ], + [ + 10, + 4 + ] + ] + }, + "id": "down_the_stairs", + "kind": "step", + "why": "onto the stairs" + }, + { + "declared_after": { + "map": "PlayerHouse1F", + "tiles": [ + [ + 10, + 3 + ], + [ + 10, + 4 + ] + ] + }, + "id": "mom_calls", + "kind": "scene", + "why": "Mom calls the player over as they come down; we stay put" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "south", + "map": "PlayerHouse1F", + "tiles": [ + [ + 6, + 9 + ] + ] + } + }, + "id": "above_the_door", + "kind": "route", + "why": "past Mom at (7, 8) to above the door" + }, + { + "args": { + "direction": "south" + }, + "id": "mom_warning", + "kind": "step", + "why": "the door's tile (6, 10): Mom's warning (coord event, VAR_PLAYER_HOUSE_STATE 1)" + }, + { + "declared_after": { + "facing": "south", + "map": "PlayerHouse1F", + "tiles": [ + [ + 6, + 10 + ] + ] + }, + "id": "mom_warns_us", + "kind": "scene", + "why": "\"don't go into the tall grass\"" + }, + { + "args": { + "direction": "south" + }, + "declared_after": { + "facing": "south", + "map": "TwinleafTown", + "tiles": [ + [ + 20, + 22 + ] + ] + }, + "id": "out_of_the_house", + "kind": "step", + "why": "out of the door" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "TwinleafTown", + "tiles": [ + [ + 10, + 12 + ] + ] + } + }, + "id": "short_of_barrys_door", + "kind": "route", + "why": "a tile east of Barry's doorstep" + }, + { + "args": { + "direction": "west" + }, + "id": "barrys_door", + "kind": "step", + "why": "the trigger on his doorstep (9, 12)" + }, + { + "action": "a", + "declared_after": { + "facing": "north", + "map": "TwinleafTown", + "tiles": [ + [ + 9, + 13 + ] + ] + }, + "id": "barry_bursts_out", + "kind": "scene", + "why": "Barry runs out, bumps into us and runs back in" + }, + { + "action": "a", + "declared_after": { + "facing": "north", + "map": "TwinleafTown", + "tiles": [ + [ + 9, + 13 + ] + ] + }, + "id": "barry_goes_home", + "kind": "scene", + "why": "his second lines (Butters waited for two)" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "TwinleafTown", + "tiles": [ + [ + 9, + 12 + ] + ] + } + }, + "id": "back_onto_barrys_doorstep", + "kind": "route", + "why": "back to his doorstep (9, 12); its trigger is spent" + }, + { + "args": { + "direction": "north" + }, + "declared_after": { + "facing": "north", + "map": "RivalHouse1F", + "tiles": [ + [ + 6, + 10 + ] + ] + }, + "id": "into_barrys_house", + "kind": "step", + "why": "his door" + }, + { + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "north", + "tiles": 1 + } + ] + }, + "id": "off_barrys_mat", + "kind": "legs", + "why": "off the door's mat, which no route starts on" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "RivalHouse1F", + "tiles": [ + [ + 2, + 3 + ] + ] + } + }, + "id": "below_barrys_stairs", + "kind": "route", + "why": "past his mother at (4, 6) to the top of the stairs' mat" + }, + { + "args": { + "direction": "east" + }, + "declared_after": { + "map": "RivalHouse2F", + "tiles": [ + [ + 3, + 4 + ] + ] + }, + "id": "up_barrys_stairs", + "kind": "step", + "why": "onto the stairs" + }, + { + "action": "a", + "declared_after": { + "facing": "north", + "map": "RivalHouse2F", + "tiles": [ + [ + 3, + 5 + ] + ] + }, + "id": "barry_runs_to_the_lake", + "kind": "scene", + "why": "Barry's lines; he runs off to the lake" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "RivalHouse2F", + "tiles": [ + [ + 3, + 4 + ] + ] + } + }, + "id": "above_barrys_stairs", + "kind": "route", + "why": "back to the top of the stairs' mat" + }, + { + "args": { + "direction": "west" + }, + "declared_after": { + "map": "RivalHouse1F", + "tiles": [ + [ + 2, + 3 + ] + ] + }, + "id": "down_barrys_stairs", + "kind": "step", + "why": "onto the stairs" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "south", + "map": "RivalHouse1F", + "tiles": [ + [ + 6, + 9 + ] + ] + } + }, + "id": "above_barrys_door", + "kind": "route", + "why": "back to his door" + }, + { + "args": { + "direction": "south" + }, + "declared_after": { + "facing": "south", + "map": "TwinleafTown", + "tiles": [ + [ + 9, + 12 + ] + ] + }, + "id": "out_of_barrys_house", + "kind": "step", + "why": "out of his door" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "Route201", + "tiles": [ + [ + 15, + 19 + ] + ] + } + }, + "id": "below_barrys_warning", + "kind": "route", + "why": "below the trigger, up Twinleaf's exit to Route 201 (15, 19)" + }, + { + "args": { + "direction": "north" + }, + "id": "barrys_warning", + "kind": "step", + "why": "the trigger (14..19, 18)" + }, + { + "declared_after": { + "map": "Route201", + "tiles": [ + [ + 15, + 18 + ] + ] + }, + "id": "barry_warns_us", + "kind": "scene", + "why": "Barry's tall-grass warning; he then stands north of us at (15, 17)" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "Route201", + "tiles": [ + [ + 12, + 17 + ] + ] + } + }, + "id": "away_from_barry", + "kind": "route", + "why": "to (12, 17): row 18 west of the path is trees, the dirt goes on along row 17" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "VerityLakefront", + "tiles": [ + [ + 17, + 14 + ] + ] + } + }, + "id": "below_the_lake_entrance", + "kind": "route", + "why": "west along Route 201's lower level to the Lakefront" + } + ], + "id": "00.01", + "start": { + "facing": "north", + "map": "PlayerHouse2F", + "tiles": [ + [ + 4, + 6 + ] + ] + }, + "title": "Bedroom to the Verity Lakefront" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Twinleaf Town" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.02.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.02.plan.json new file mode 100644 index 0000000000..40663f923f --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.02.plan.json @@ -0,0 +1,92 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "VerityLakefront", + "tiles": [ + [ + 17, + 13 + ] + ] + } + }, + "id": "to_the_lake_entrance", + "kind": "route", + "why": "a tile short of the trigger" + }, + { + "args": { + "direction": "north" + }, + "id": "lake_entrance", + "kind": "step", + "why": "the trigger (16..17, 12): Barry hears Rowan and the two walk in" + }, + { + "action": "starter_briefcase", + "id": "starter_briefcase", + "kind": "game_action", + "why": "the lake's scene, to the open briefcase" + }, + { + "action": "choose_starter", + "id": "choose_starter", + "kind": "game_action", + "why": "the starter from the program's option" + }, + { + "action": "starter", + "args": { + "may_lose": true + }, + "id": "starly", + "kind": "battle", + "why": "the Starly battle, with the starter alone" + }, + { + "declared_after": { + "map": "VerityLakefront", + "tiles": [ + [ + 17, + 14 + ], + [ + 17, + 15 + ] + ] + }, + "id": "after_starly", + "kind": "scene", + "why": "Rowan's lines and the walk out of the lake" + } + ], + "id": "00.02", + "start": { + "facing": "north", + "map": "VerityLakefront", + "tiles": [ + [ + 17, + 14 + ] + ] + }, + "title": "Lake Verity: the starter and the Starly battle" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Verity Lakefront" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.03.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.03.plan.json new file mode 100644 index 0000000000..4309d2658c --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.03.plan.json @@ -0,0 +1,177 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "Route201", + "tiles": [ + [ + 4, + 14 + ] + ] + } + }, + "id": "short_of_rowan", + "kind": "route", + "why": "back east onto Route 201's lower level" + }, + { + "args": { + "direction": "east" + }, + "id": "rowans_stop", + "kind": "step", + "why": "the trigger (5, 14..16)" + }, + { + "declared_after": { + "facing": "east", + "map": "PlayerHouse1F", + "tiles": [ + [ + 5, + 8 + ], + [ + 6, + 8 + ] + ] + }, + "id": "rowan_and_dawn", + "kind": "scene", + "why": "Rowan and Dawn come back; Barry, then home for the Running Shoes" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "PlayerHouse1F", + "tiles": [ + [ + 4, + 8 + ] + ] + } + }, + "id": "by_the_counter", + "kind": "route", + "why": "west against the table's corner (3, 8)" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "south", + "map": "PlayerHouse1F", + "tiles": [ + [ + 6, + 9 + ] + ] + } + }, + "id": "above_the_door_again", + "kind": "route", + "why": "to above the door" + }, + { + "args": { + "direction": "south" + }, + "declared_after": { + "facing": "south", + "map": "TwinleafTown", + "tiles": [ + [ + 20, + 22 + ] + ] + }, + "id": "out_of_the_house_again", + "kind": "step", + "why": "onto the door's tile (6, 10), and out" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "Route201", + "tiles": [ + [ + 63, + 5 + ] + ] + } + }, + "id": "short_of_dawn", + "kind": "route", + "why": "Twinleaf, then east along Route 201 to its east edge" + }, + { + "action": "to_dialogue", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "east", + "tiles": 8 + } + ] + }, + "id": "into_sandgem", + "kind": "legs", + "why": "east into Sandgem until Dawn's scene starts" + }, + { + "declared_after": { + "facing": "north", + "map": "RowansLab", + "tiles": [ + [ + 7, + 6 + ] + ] + }, + "id": "rowan_gives_pokedex", + "kind": "scene", + "why": "Dawn walks us to the lab: Rowan, no nickname, the Pokedex" + } + ], + "id": "00.03", + "start": { + "map": "VerityLakefront", + "tiles": [ + [ + 17, + 14 + ], + [ + 17, + 15 + ] + ] + }, + "title": "Back to Sandgem: Rowan, Dawn and the Pokedex" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Verity Lakefront" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04.plan.json new file mode 100644 index 0000000000..13f5fdb661 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04.plan.json @@ -0,0 +1,406 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "direction": "south" + }, + "declared_after": { + "facing": "north", + "map": "SandgemTown", + "tiles": [ + [ + 26, + 11 + ], + [ + 27, + 11 + ], + [ + 28, + 11 + ], + [ + 26, + 12 + ], + [ + 27, + 12 + ], + [ + 28, + 12 + ] + ] + }, + "id": "out_of_the_lab", + "kind": "step", + "why": "out of the lab; Dawn's tour of Sandgem" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "SandgemTown", + "tiles": [ + [ + 29, + 12 + ] + ] + } + }, + "id": "onto_the_path", + "kind": "route", + "why": "to the east end of the path below the doors' row" + }, + { + "action": "to_map", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "west", + "tiles": 40 + } + ] + }, + "declared_after": { + "facing": "west", + "map": "Route201", + "tiles": [ + [ + 57, + 5 + ], + [ + 58, + 5 + ], + [ + 59, + 5 + ], + [ + 60, + 5 + ], + [ + 61, + 5 + ], + [ + 62, + 5 + ], + [ + 63, + 5 + ] + ] + }, + "id": "to_route_201", + "kind": "legs", + "why": "run west along the path until Route 201's banner" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "TwinleafTown", + "tiles": [ + [ + 20, + 22 + ], + [ + 20, + 23 + ], + [ + 20, + 24 + ], + [ + 20, + 25 + ], + [ + 20, + 26 + ] + ] + } + }, + "id": "home", + "kind": "route", + "why": "west along Route 201 to Twinleaf, running from wild battles" + }, + { + "args": { + "direction": "north" + }, + "declared_after": { + "facing": "north", + "map": "PlayerHouse1F", + "tiles": [ + [ + 6, + 9 + ] + ] + }, + "id": "into_the_house", + "kind": "step", + "why": "the house's door" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "PlayerHouse1F", + "tiles": [ + [ + 6, + 7 + ] + ] + } + }, + "id": "beside_mom", + "kind": "route", + "why": "west of Mom at (7, 7)" + }, + { + "id": "mom", + "kind": "talk", + "why": "Mom" + }, + { + "declared_after": { + "facing": "east", + "map": "PlayerHouse1F", + "tiles": [ + [ + 6, + 7 + ] + ] + }, + "id": "mom_heals_us", + "kind": "scene", + "why": "Mom heals us; Barry's mom gives us his parcel" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "south", + "map": "PlayerHouse1F", + "tiles": [ + [ + 5, + 9 + ] + ] + } + }, + "id": "around_mom", + "kind": "route", + "why": "around Mom at (6, 8), to beside the door's column" + }, + { + "action": "to_dialogue", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "east", + "tiles": 1 + } + ] + }, + "id": "to_moms_call", + "kind": "legs", + "why": "east above the door until Mom calls" + }, + { + "declared_after": { + "facing": "east", + "map": "TwinleafTown", + "tiles": [ + [ + 19, + 22 + ] + ] + }, + "id": "moms_hat", + "kind": "scene", + "why": "Mom's hat; she walks out with us" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "Route202", + "tiles": [ + [ + 22, + 27 + ] + ] + } + }, + "id": "short_of_the_catch_tutorial", + "kind": "route", + "why": "through Sandgem onto Route 202, east of its trigger column" + }, + { + "args": { + "direction": "west" + }, + "id": "catch_tutorial_trigger", + "kind": "step", + "why": "the trigger (21, 25..29), VAR_ROUTE_202_STATE 0" + }, + { + "action": "catch_tutorial", + "id": "catch_tutorial", + "kind": "game_action", + "why": "Dawn's catching tutorial" + }, + { + "action": "catch_pokemon", + "declared_after": { + "map": "Route202", + "tiles": [ + [ + 15, + 25 + ], + [ + 16, + 25 + ], + [ + 17, + 25 + ], + [ + 18, + 25 + ], + [ + 19, + 25 + ], + [ + 20, + 25 + ], + [ + 21, + 25 + ], + [ + 15, + 26 + ], + [ + 16, + 26 + ], + [ + 17, + 26 + ], + [ + 18, + 26 + ], + [ + 19, + 26 + ], + [ + 20, + 26 + ], + [ + 21, + 26 + ], + [ + 15, + 27 + ], + [ + 16, + 27 + ], + [ + 17, + 27 + ], + [ + 18, + 27 + ], + [ + 19, + 27 + ], + [ + 20, + 27 + ], + [ + 21, + 27 + ], + [ + 21, + 28 + ], + [ + 21, + 29 + ] + ] + }, + "id": "catch_pokemon", + "kind": "game_action", + "why": "a Pokemon of our own from the grass" + } + ], + "id": "00.04", + "start": { + "facing": "north", + "map": "RowansLab", + "tiles": [ + [ + 7, + 6 + ] + ] + }, + "title": "Home to Mom, then Dawn's catching tutorial on Route 202" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Sandgem Town" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04b.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04b.plan.json new file mode 100644 index 0000000000..58d57b54c9 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04b.plan.json @@ -0,0 +1,271 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "fight_wild": false, + "target": { + "map": "Route202", + "tiles": [ + [ + 18, + 25 + ], + [ + 19, + 25 + ], + [ + 20, + 25 + ], + [ + 18, + 26 + ], + [ + 19, + 26 + ], + [ + 20, + 26 + ], + [ + 18, + 27 + ], + [ + 19, + 27 + ], + [ + 20, + 27 + ] + ] + } + }, + "id": "to_catch_grass", + "kind": "route", + "why": "into the training column's grass" + }, + { + "args": { + "battles": 3 + }, + "declared_after": { + "map": "Route202", + "tiles": [ + [ + 18, + 25 + ], + [ + 19, + 25 + ], + [ + 20, + 25 + ], + [ + 18, + 26 + ], + [ + 19, + 26 + ], + [ + 20, + 26 + ], + [ + 18, + 27 + ], + [ + 19, + 27 + ], + [ + 20, + 27 + ] + ] + }, + "id": "train", + "kind": "train", + "why": "three wild battles with the best move" + }, + { + "action": "robust", + "args": { + "fight_wild": false, + "target": { + "map": "SandgemTown", + "tiles": [ + [ + 29, + 5 + ] + ] + } + }, + "id": "into_sandgem", + "kind": "route", + "why": "south down the road to above the Mart" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "SandgemTown", + "tiles": [ + [ + 17, + 11 + ] + ] + } + }, + "id": "below_center_door", + "kind": "route", + "why": "below the Center's door" + }, + { + "declared_after": { + "map": "SandgemTown", + "tiles": [ + [ + 16, + 11 + ], + [ + 17, + 11 + ], + [ + 18, + 11 + ] + ] + }, + "id": "heal_sandgem", + "kind": "heal", + "why": "Sandgem Town Pokemon Center" + } + ], + "id": "00.04b", + "start": { + "map": "Route202", + "tiles": [ + [ + 15, + 25 + ], + [ + 16, + 25 + ], + [ + 17, + 25 + ], + [ + 18, + 25 + ], + [ + 19, + 25 + ], + [ + 20, + 25 + ], + [ + 21, + 25 + ], + [ + 15, + 26 + ], + [ + 16, + 26 + ], + [ + 17, + 26 + ], + [ + 18, + 26 + ], + [ + 19, + 26 + ], + [ + 20, + 26 + ], + [ + 21, + 26 + ], + [ + 15, + 27 + ], + [ + 16, + 27 + ], + [ + 17, + 27 + ], + [ + 18, + 27 + ], + [ + 19, + 27 + ], + [ + 20, + 27 + ], + [ + 21, + 27 + ], + [ + 21, + 28 + ], + [ + 21, + 29 + ] + ] + }, + "title": "After the catch: train and heal in Sandgem" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Route 202" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04c.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04c.plan.json new file mode 100644 index 0000000000..24634070ff --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04c.plan.json @@ -0,0 +1,57 @@ +{ + "checkpoint": { + "events": [ + { + "action": "sandgem_potions", + "args": { + "items": [ + { + "item": "potion", + "quantity": 10 + } + ] + }, + "declared_after": { + "map": "Route202", + "tiles": [ + [ + 30, + 24 + ] + ] + }, + "id": "potions", + "kind": "shop", + "why": "Potions before Route 202's trainers: the Poke Mart lady's 10 (she stands still, as in the decomp)" + } + ], + "id": "00.04c", + "start": { + "map": "SandgemTown", + "tiles": [ + [ + 16, + 11 + ], + [ + 17, + 11 + ], + [ + 18, + 11 + ] + ] + }, + "title": "Potions, back to Route 202's save spot" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Sandgem Town" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json new file mode 100644 index 0000000000..666569b83e --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json @@ -0,0 +1,196 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "fight_wild": false, + "target": { + "map": "Route202", + "tiles": [ + [ + 11, + 0 + ], + [ + 12, + 0 + ], + [ + 13, + 0 + ], + [ + 14, + 0 + ], + [ + 15, + 0 + ], + [ + 16, + 0 + ], + [ + 17, + 0 + ], + [ + 18, + 0 + ], + [ + 11, + 1 + ], + [ + 12, + 1 + ], + [ + 13, + 1 + ], + [ + 14, + 1 + ], + [ + 15, + 1 + ], + [ + 16, + 1 + ], + [ + 17, + 1 + ], + [ + 18, + 1 + ], + [ + 11, + 2 + ], + [ + 12, + 2 + ], + [ + 13, + 2 + ], + [ + 14, + 2 + ], + [ + 15, + 2 + ], + [ + 16, + 2 + ], + [ + 17, + 2 + ], + [ + 18, + 2 + ], + [ + 11, + 3 + ], + [ + 12, + 3 + ], + [ + 13, + 3 + ], + [ + 14, + 3 + ], + [ + 15, + 3 + ], + [ + 16, + 3 + ], + [ + 17, + 3 + ], + [ + 18, + 3 + ] + ] + } + }, + "id": "north_to_jubilife", + "kind": "route", + "why": "north past Route 202's trainers, fighting who sees us" + }, + { + "action": "jubilife_stairs", + "declared_after": { + "map": "JubilifeCity", + "tiles": [ + [ + 48, + 62 + ] + ] + }, + "id": "jubilife_stairs", + "kind": "game_action", + "why": "Jubilife's south edge is a wall with stairs in it, west of where the route may leave us (r78)" + }, + { + "declared_after": { + "map": "JubilifeCity", + "tiles": [ + [ + 48, + 62 + ] + ] + }, + "id": "dawn_scene", + "kind": "scene", + "why": "Dawn walks over while we stand still" + } + ], + "id": "00.04d", + "start": { + "map": "Route202", + "tiles": [ + [ + 30, + 24 + ] + ] + }, + "title": "Route 202's trainers, Dawn in Jubilife" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Route 202" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json new file mode 100644 index 0000000000..fe94d37361 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json @@ -0,0 +1,134 @@ +{ + "checkpoint": { + "events": [ + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 52, + 41 + ] + ] + } + }, + "id": "to_the_center", + "kind": "route", + "why": "below the Center's door (52, 40)" + }, + { + "id": "heal_jubilife", + "kind": "heal", + "why": "in, the nurse, out onto the doorstep (r143a: check we are out)" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 40, + 41 + ] + ] + } + }, + "id": "to_the_school", + "kind": "route", + "why": "below the School's door (40, 40)" + }, + { + "args": { + "direction": "north" + }, + "declared_after": { + "map": "TrainersSchool", + "tiles": [] + }, + "id": "into_the_school", + "kind": "step", + "why": "the School's door" + }, + { + "action": "to_wall", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "north", + "tiles": 10 + } + ] + }, + "declared_after": { + "facing": "west", + "map": "TrainersSchool", + "tiles": [] + }, + "id": "up_to_barry", + "kind": "legs", + "why": "the door's column to the back wall, beside Barry" + }, + { + "id": "barry", + "kind": "talk", + "why": "Barry, west of us at the blackboard" + }, + { + "action": "a", + "declared_after": { + "map": "TrainersSchool", + "tiles": [] + }, + "id": "barry_town_map", + "kind": "scene", + "why": "his lines to \"You obtained a Town Map!\", closed with A" + }, + { + "args": { + "direction": "south" + }, + "declared_after": { + "facing": "south", + "map": "JubilifeCity", + "tiles": [ + [ + 40, + 41 + ] + ] + }, + "id": "out_of_the_school", + "kind": "step", + "why": "straight down the door's column and out" + } + ], + "id": "00.05", + "start": { + "map": "JubilifeCity", + "tiles": [ + [ + 48, + 62 + ] + ] + }, + "title": "Jubilife: the Center, the Trainers' School and the Town Map" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Jubilife City" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json new file mode 100644 index 0000000000..8021fabee4 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json @@ -0,0 +1,197 @@ +{ + "checkpoint": { + "events": [ + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 46, + 41 + ] + ] + } + }, + "id": "below_the_presidents_trigger", + "kind": "route", + "why": "east along the School's row" + }, + { + "args": { + "direction": "north" + }, + "id": "presidents_trigger", + "kind": "step", + "why": "the trigger (44..48, 40)" + }, + { + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 46, + 40 + ] + ] + }, + "id": "president_walks_up", + "kind": "scene", + "why": "he walks down to (46, 39) and sends us for the coupons" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "JubilifeCity", + "tiles": [ + [ + 48, + 40 + ] + ] + } + }, + "id": "past_the_president", + "kind": "route", + "why": "east of his column" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 55, + 34 + ] + ] + } + }, + "id": "below_the_mart_clown", + "kind": "route", + "why": "up the road east of the Center" + }, + { + "action": "talk_to_wanderer", + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 55, + 34 + ] + ] + }, + "id": "mart_clown", + "kind": "talk", + "why": "the clown by the Mart: 'Do Pokemon grow by defeating others?' Yes; Coupon 1" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 36, + 17 + ] + ] + } + }, + "id": "below_the_tv_clown", + "kind": "route", + "why": "west and north to the TV station" + }, + { + "id": "tv_clown", + "kind": "talk", + "why": "the clown below the TV station's door" + }, + { + "action": "a", + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 36, + 17 + ] + ] + }, + "id": "tv_clowns_coupon", + "kind": "scene", + "why": "\"Can a Pokemon hold an item?\" Yes; Coupon 3" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 15, + 19 + ] + ] + } + }, + "id": "below_the_company_clown", + "kind": "route", + "why": "west along the long road, north beside the sign" + }, + { + "action": "talk_to_wanderer", + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 15, + 19 + ] + ] + }, + "id": "company_clown", + "kind": "talk", + "why": "the clown by the Poketch Company: 'Do moves have types?' Yes; Coupon 2" + } + ], + "id": "00.05b", + "start": { + "facing": "south", + "map": "JubilifeCity", + "tiles": [ + [ + 40, + 41 + ] + ] + }, + "title": "Jubilife: the president and the clowns' coupons" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Jubilife City" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json new file mode 100644 index 0000000000..b22437315b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json @@ -0,0 +1,85 @@ +{ + "checkpoint": { + "events": [ + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 46, + 36 + ] + ] + } + }, + "id": "below_the_president", + "kind": "route", + "why": "east along the long road, down the main road" + }, + { + "id": "president", + "kind": "talk", + "why": "the Poketch Company's president at (46, 35)" + }, + { + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 46, + 36 + ] + ] + }, + "id": "the_poketch", + "kind": "scene", + "why": "the coupons for the Poketch; he walks off north" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "JubilifeCity", + "tiles": [ + [ + 58, + 22 + ] + ] + } + }, + "id": "to_the_route_203_street", + "kind": "route", + "why": "up the main road and east along the street" + } + ], + "id": "00.05c", + "start": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 15, + 19 + ] + ] + }, + "title": "Jubilife: the Poketch, up to the street east to Route 203" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Jubilife City" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json new file mode 100644 index 0000000000..e44f7cbc0b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json @@ -0,0 +1,84 @@ +{ + "checkpoint": { + "events": [ + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "Route203", + "tiles": [ + [ + 4, + 18 + ] + ] + } + }, + "id": "west_of_barrys_trigger", + "kind": "route", + "why": "east along the street onto Route 203" + }, + { + "args": { + "direction": "east" + }, + "id": "barrys_trigger", + "kind": "step", + "why": "the trigger (5, 17..20): Barry walks over" + }, + { + "args": { + "may_lose": true + }, + "declared_after": { + "facing": "east", + "map": "Route203", + "tiles": [ + [ + 5, + 17 + ], + [ + 5, + 18 + ], + [ + 5, + 19 + ], + [ + 5, + 20 + ] + ] + }, + "id": "barry", + "kind": "battle", + "why": "Barry's battle; a loss goes on, as it did on the console" + } + ], + "id": "01.01", + "start": { + "facing": "east", + "map": "JubilifeCity", + "tiles": [ + [ + 58, + 22 + ] + ] + }, + "title": "Jubilife to Barry" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Jubilife City" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.02.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.02.plan.json new file mode 100644 index 0000000000..b5eee72e0f --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.02.plan.json @@ -0,0 +1,268 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "fight_wild": false, + "target": { + "facing": "south", + "map": "Route203", + "tiles": [ + [ + 5, + 20 + ] + ] + } + }, + "declared_after": { + "facing": "south", + "map": "Route203", + "tiles": [ + [ + 5, + 20 + ] + ] + }, + "id": "south_to_the_cliff", + "kind": "route", + "why": "down the trigger's column to the cliff" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "Route203", + "tiles": [ + [ + 55, + 9 + ] + ] + } + }, + "id": "by_the_gate", + "kind": "route", + "why": "east along Route 203 to the Gate's warp tile (55, 9)" + }, + { + "action": "to_banner", + "args": { + "direction": "east" + }, + "declared_after": { + "facing": "east", + "map": "OreburghGate", + "tiles": [ + [ + 4, + 22 + ], + [ + 5, + 22 + ] + ] + }, + "id": "into_oreburgh_gate", + "kind": "step", + "why": "the Gate's west mouth (56, 9)" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "OreburghGate", + "tiles": [ + [ + 6, + 22 + ] + ] + } + }, + "id": "west_of_the_hikers_trigger", + "kind": "route", + "why": "east along row 22" + }, + { + "args": { + "direction": "east" + }, + "id": "hikers_trigger", + "kind": "step", + "why": "the trigger (7, 22): the Hiker walks down to us" + }, + { + "declared_after": { + "facing": "east", + "map": "OreburghGate", + "tiles": [ + [ + 7, + 22 + ] + ] + }, + "id": "the_hiker", + "kind": "scene", + "why": "HM Rock Smash, then the Hidden Moves card" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "OreburghGate", + "tiles": [ + [ + 20, + 22 + ] + ] + } + }, + "id": "past_curtis", + "kind": "route", + "why": "east along row 22 past Camper Curtis's column (17), fighting him" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "OreburghGate", + "tiles": [ + [ + 27, + 22 + ] + ] + } + }, + "id": "by_the_east_mouth", + "kind": "route", + "why": "east past Picnicker Diana's column (24), fighting her" + }, + { + "action": "to_banner", + "args": { + "direction": "east" + }, + "declared_after": { + "facing": "east", + "map": "OreburghCity", + "tiles": [ + [ + 2, + 13 + ], + [ + 3, + 13 + ] + ] + }, + "id": "into_oreburgh", + "kind": "step", + "why": "the Gate's east mouth (28, 22)" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "OreburghCity", + "tiles": [ + [ + 9, + 13 + ] + ] + } + }, + "id": "west_of_the_welcome", + "kind": "route", + "why": "east along row 13" + }, + { + "args": { + "direction": "east" + }, + "id": "welcome_trigger", + "kind": "step", + "why": "the trigger (10, 12..15): the man walks over" + }, + { + "declared_after": { + "map": "OreburghCity", + "tiles": [ + [ + 43, + 21 + ], + [ + 44, + 21 + ], + [ + 45, + 21 + ], + [ + 43, + 22 + ], + [ + 44, + 22 + ], + [ + 45, + 22 + ] + ] + }, + "id": "oreburgh_welcome", + "kind": "scene", + "why": "the man's lines, the walk to the Center, and Barry's" + } + ], + "id": "01.02", + "start": { + "facing": "east", + "map": "Route203", + "tiles": [ + [ + 5, + 17 + ], + [ + 5, + 18 + ], + [ + 5, + 19 + ], + [ + 5, + 20 + ] + ] + }, + "title": "Route 203 to Oreburgh" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Route 203" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.04.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.04.plan.json new file mode 100644 index 0000000000..45345a431b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.04.plan.json @@ -0,0 +1,47 @@ +{ + "checkpoint": { + "events": [ + { + "action": "gym_until_roark_beaten", + "declared_after": { + "facing": "north", + "map": "OreburghGym", + "tiles": [ + [ + 5, + 4 + ] + ] + }, + "id": "gym_until_roark_beaten", + "kind": "game_action", + "why": "west into the gym, up it to Roark; again from the Center after a loss" + } + ], + "id": "01.04", + "start": { + "facing": "south", + "map": "OreburghCity", + "tiles": [ + [ + 47, + 21 + ], + [ + 46, + 21 + ] + ] + }, + "title": "Oreburgh Gym" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Oreburgh City" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "testing" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.05.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.05.plan.json new file mode 100644 index 0000000000..99db77974b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.05.plan.json @@ -0,0 +1,170 @@ +{ + "checkpoint": { + "events": [ + { + "action": "to_banner", + "args": { + "direction": "south" + }, + "declared_after": { + "facing": "south", + "map": "OreburghCity", + "tiles": [ + [ + 26, + 21 + ], + [ + 26, + 22 + ] + ] + }, + "id": "out_of_the_gym", + "kind": "step", + "why": "down the middle column (5, 4..23) and out of the door (5, 24)" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "OreburghCity", + "tiles": [ + [ + 7, + 13 + ] + ] + } + }, + "id": "east_of_barrys_trigger", + "kind": "route", + "why": "west along the street, north up the stairs west of the houses, west along the Gate's row" + }, + { + "args": { + "direction": "west" + }, + "id": "barrys_trigger", + "kind": "step", + "why": "the trigger (6, 12..15)" + }, + { + "declared_after": { + "facing": "east", + "map": "OreburghCity", + "tiles": [ + [ + 5, + 13 + ] + ] + }, + "id": "barry_bumps_into_us", + "kind": "scene", + "why": "Barry runs into us, talks of Eterna, and leaves (assumed: the push)" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "OreburghCity", + "tiles": [ + [ + 2, + 13 + ] + ] + } + }, + "id": "by_the_gate", + "kind": "route", + "why": "west to the Gate's warp tile (2, 13)" + }, + { + "action": "to_banner", + "args": { + "direction": "west" + }, + "declared_after": { + "facing": "west", + "map": "OreburghGate", + "tiles": [ + [ + 27, + 22 + ], + [ + 26, + 22 + ] + ] + }, + "id": "into_oreburgh_gate", + "kind": "step", + "why": "the Gate's mouth (1, 13)" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "OreburghGate", + "tiles": [ + [ + 4, + 22 + ] + ] + } + }, + "id": "through_the_gate", + "kind": "route", + "why": "west along row 22 to the warp tile by the west mouth (3, 22)" + }, + { + "action": "to_banner", + "args": { + "direction": "west" + }, + "declared_after": { + "facing": "west", + "map": "Route203", + "tiles": [ + [ + 55, + 9 + ] + ] + }, + "id": "out_of_oreburgh_gate", + "kind": "step", + "why": "the west mouth (3, 22)" + } + ], + "id": "01.05", + "start": { + "facing": "north", + "map": "OreburghGym", + "tiles": [ + [ + 5, + 4 + ] + ] + }, + "title": "Oreburgh to Route 203" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Oreburgh City" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "testing" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.06.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.06.plan.json new file mode 100644 index 0000000000..7bbe63308f --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.06.plan.json @@ -0,0 +1,46 @@ +{ + "checkpoint": { + "events": [ + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 47, + 8 + ] + ] + } + }, + "id": "below_rowans_trigger", + "kind": "route", + "why": "down Route 203 (its ledges only south), west along it into Jubilife's street, north up the road" + } + ], + "id": "01.06", + "start": { + "facing": "west", + "map": "Route203", + "tiles": [ + [ + 55, + 9 + ] + ] + }, + "title": "Route 203 to Jubilife" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Route 203" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "testing" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.07.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.07.plan.json new file mode 100644 index 0000000000..87a11f994a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.07.plan.json @@ -0,0 +1,62 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "direction": "north" + }, + "id": "rowans_trigger", + "kind": "step", + "why": "the trigger (45..47, 7): the game walks us up to Rowan" + }, + { + "action": "doubles", + "args": { + "may_lose": false + }, + "id": "galactic_grunts", + "kind": "battle", + "why": "the lines, then the tag battle with Dawn" + }, + { + "declared_after": { + "map": "JubilifeCity", + "tiles": [ + [ + 46, + 5 + ], + [ + 47, + 5 + ] + ] + }, + "id": "rowan_and_dawn_leave", + "kind": "scene", + "why": "Rowan's and Dawn's lines, then Bebe walks over with hers (r80 saved over her lines)" + } + ], + "id": "01.07", + "start": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 47, + 8 + ] + ] + }, + "title": "Jubilife: Rowan, Dawn and the Galactic grunts" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Jubilife City" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "testing" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json new file mode 100644 index 0000000000..387cad3518 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json @@ -0,0 +1,96 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 44, + 5 + ] + ] + } + }, + "declared_after": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 44, + 5 + ] + ] + }, + "id": "west_to_the_wall", + "kind": "route", + "why": "west along row 5 to the wall" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "Route204South", + "tiles": [ + [ + 11, + 2 + ] + ] + } + }, + "id": "below_the_ravaged_path", + "kind": "route", + "why": "north out of Jubilife, up Route 204's street and grass to below the door (11, 1)" + }, + { + "action": "to_banner", + "args": { + "direction": "north" + }, + "declared_after": { + "facing": "north", + "map": "RavagedPath", + "tiles": [ + [ + 19, + 50 + ] + ] + }, + "id": "into_the_ravaged_path", + "kind": "step", + "why": "the door (11, 1)" + } + ], + "id": "01.08", + "start": { + "map": "JubilifeCity", + "tiles": [ + [ + 46, + 5 + ], + [ + 47, + 5 + ] + ] + }, + "title": "Jubilife to the Ravaged Path" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Jubilife City" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "testing" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.09.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.09.plan.json new file mode 100644 index 0000000000..579b52d3da --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.09.plan.json @@ -0,0 +1,98 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "fight_wild": false, + "target": { + "facing": "east", + "map": "RavagedPath", + "tiles": [ + [ + 21, + 43 + ] + ] + } + }, + "id": "west_of_the_rock", + "kind": "route", + "why": "up the stairs and along the corridor" + }, + { + "action": "smash_the_rock", + "declared_after": { + "facing": "east", + "map": "RavagedPath", + "tiles": [ + [ + 21, + 43 + ] + ] + }, + "id": "smash_the_rock", + "kind": "game_action", + "why": "Rock Smash on the rock east of us" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "south", + "map": "RavagedPath", + "tiles": [ + [ + 28, + 44 + ] + ] + } + }, + "id": "above_the_way_out", + "kind": "route", + "why": "east through the rock's tile" + }, + { + "action": "to_banner", + "args": { + "direction": "south" + }, + "declared_after": { + "facing": "south", + "map": "Route204North", + "tiles": [ + [ + 20, + 26 + ] + ] + }, + "id": "out_of_the_ravaged_path", + "kind": "step", + "why": "the way out (28, 45)" + } + ], + "id": "01.09", + "start": { + "facing": "north", + "map": "RavagedPath", + "tiles": [ + [ + 19, + 50 + ] + ] + }, + "title": "Ravaged Path" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Ravaged Path" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "testing" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.10.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.10.plan.json new file mode 100644 index 0000000000..fc47208040 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.10.plan.json @@ -0,0 +1,177 @@ +{ + "checkpoint": { + "events": [ + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "map": "Route204North", + "tiles": [ + [ + 20, + 27 + ] + ] + } + }, + "id": "line_1", + "kind": "route", + "why": "a corner of the human's line" + }, + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "map": "Route204North", + "tiles": [ + [ + 11, + 27 + ] + ] + } + }, + "id": "line_2", + "kind": "route", + "why": "a corner of the human's line" + }, + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "map": "Route204North", + "tiles": [ + [ + 11, + 22 + ] + ] + } + }, + "id": "line_3", + "kind": "route", + "why": "a corner of the human's line" + }, + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "map": "Route204North", + "tiles": [ + [ + 19, + 22 + ] + ] + } + }, + "id": "line_4", + "kind": "route", + "why": "a corner of the human's line" + }, + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "map": "Route204North", + "tiles": [ + [ + 19, + 12 + ] + ] + } + }, + "id": "line_5", + "kind": "route", + "why": "a corner of the human's line" + }, + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "map": "Route204North", + "tiles": [ + [ + 11, + 12 + ] + ] + } + }, + "id": "line_6", + "kind": "route", + "why": "a corner of the human's line" + }, + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "map": "Route204North", + "tiles": [ + [ + 11, + 5 + ] + ] + } + }, + "id": "line_7", + "kind": "route", + "why": "a corner of the human's line" + }, + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "FloaromaTown", + "tiles": [ + [ + 11, + 29 + ] + ] + } + }, + "id": "into_floaroma", + "kind": "route", + "why": "north up column 11 into Floaroma" + }, + { + "id": "save_here", + "kind": "save", + "why": "the next checkpoint starts here" + } + ], + "id": "01.10", + "start": { + "facing": "south", + "map": "Route204North", + "tiles": [ + [ + 20, + 26 + ] + ] + }, + "title": "Route 204 to Floaroma" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Route 204" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "testing" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.11.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.11.plan.json new file mode 100644 index 0000000000..dafdf2a436 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.11.plan.json @@ -0,0 +1,143 @@ +{ + "checkpoint": { + "events": [ + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "FloaromaTown", + "tiles": [ + [ + 3, + 29 + ] + ] + } + }, + "id": "west_along_the_field", + "kind": "route", + "why": "west along row 29" + }, + { + "action": "to_wall", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "north", + "tiles": 5 + } + ] + }, + "declared_after": { + "facing": "north", + "map": "FloaromaTown", + "tiles": [ + [ + 4, + 26 + ] + ] + }, + "id": "up_to_the_old_woman", + "kind": "legs", + "why": "north until she stops us" + }, + { + "id": "old_woman", + "kind": "talk", + "why": "she gives Mew when a Let's Go save is on the console" + }, + { + "declared_after": { + "facing": "north", + "map": "FloaromaTown", + "tiles": [ + [ + 4, + 26 + ] + ] + }, + "id": "old_woman_talks", + "kind": "scene", + "why": "her lines" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "FloaromaTown", + "tiles": [ + [ + 3, + 26 + ] + ] + } + }, + "declared_after": { + "facing": "north", + "map": "FloaromaTown", + "tiles": [ + [ + 3, + 26 + ] + ] + }, + "id": "below_the_old_man", + "kind": "route", + "why": "a tile west" + }, + { + "id": "old_man", + "kind": "talk", + "why": "he gives Jirachi with a Sword/Shield save" + }, + { + "declared_after": { + "facing": "north", + "map": "FloaromaTown", + "tiles": [ + [ + 3, + 26 + ] + ] + }, + "id": "old_man_talks", + "kind": "scene", + "why": "his lines" + }, + { + "id": "save_here", + "kind": "save", + "why": "the next checkpoint starts here" + } + ], + "id": "01.11", + "start": { + "facing": "north", + "map": "FloaromaTown", + "tiles": [ + [ + 11, + 29 + ] + ] + }, + "title": "Floaroma's old couple" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Floaroma Town" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "testing" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-mine-01.03.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-mine-01.03.plan.json new file mode 100644 index 0000000000..5d873530a3 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-mine-01.03.plan.json @@ -0,0 +1,366 @@ +{ + "checkpoint": { + "events": [ + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "OreburghCity", + "tiles": [ + [ + 47, + 21 + ] + ] + } + }, + "declared_after": { + "facing": "north", + "map": "OreburghCity", + "tiles": [ + [ + 47, + 21 + ] + ] + }, + "id": "below_the_centers_door", + "kind": "route", + "why": "below the Center's door" + }, + { + "id": "barry", + "kind": "talk", + "why": "Barry in the Center's door" + }, + { + "declared_after": { + "facing": "north", + "map": "OreburghCity", + "tiles": [ + [ + 47, + 21 + ] + ] + }, + "id": "barrys_lines", + "kind": "scene", + "why": "Roark has gone to the mine" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "south", + "map": "OreburghCity", + "tiles": [ + [ + 46, + 58 + ] + ] + } + }, + "id": "above_the_mine", + "kind": "route", + "why": "down the door's column to above the mine's warp tiles" + }, + { + "args": { + "direction": "south" + }, + "declared_after": { + "facing": "south", + "map": "OreburghMineB1F", + "tiles": [ + [ + 12, + 1 + ] + ] + }, + "id": "into_the_mine", + "kind": "step", + "why": "the warp tile (46, 59)" + }, + { + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "south", + "tiles": 19 + } + ] + }, + "id": "down_the_hall", + "kind": "legs", + "why": "down column 12 of the entrance hall" + }, + { + "args": { + "direction": "south" + }, + "declared_after": { + "facing": "south", + "map": "OreburghMine", + "tiles": [ + [ + 15, + 2 + ], + [ + 15, + 1 + ] + ] + }, + "id": "into_the_coal_room", + "kind": "step", + "why": "the hall's warp tiles (11..13, 21)" + }, + { + "action": "to_wall", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "south", + "tiles": 9 + } + ] + }, + "declared_after": { + "facing": "south", + "map": "OreburghMine", + "tiles": [ + [ + 15, + 9 + ] + ] + }, + "id": "down_to_the_boulder", + "kind": "legs", + "why": "down the corridor to the boulder (15, 10)" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "OreburghMine", + "tiles": [ + [ + 18, + 29 + ] + ] + } + }, + "id": "below_roark", + "kind": "route", + "why": "down the corridor and the room's east side, west along the bottom row" + }, + { + "id": "roark", + "kind": "talk", + "why": "Roark, north of us between his rocks" + }, + { + "declared_after": { + "facing": "north", + "map": "OreburghMine", + "tiles": [ + [ + 18, + 29 + ] + ] + }, + "id": "roark_smashes_the_rock", + "kind": "scene", + "why": "his lines, Rock Smash on the rock east of him, and he walks off" + }, + { + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "OreburghMine", + "tiles": [ + [ + 15, + 2 + ] + ] + } + }, + "id": "below_the_coal_rooms_warp", + "kind": "route", + "why": "back up the corridor" + }, + { + "args": { + "direction": "north" + }, + "declared_after": { + "facing": "north", + "map": "OreburghMineB1F", + "tiles": [ + [ + 11, + 21 + ] + ] + }, + "id": "up_to_the_hall", + "kind": "step", + "why": "the warp tile (15, 1)" + }, + { + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "north", + "tiles": 19 + } + ] + }, + "id": "up_the_hall", + "kind": "legs", + "why": "up column 11 of the entrance hall" + }, + { + "args": { + "direction": "north" + }, + "declared_after": { + "facing": "north", + "map": "OreburghCity", + "tiles": [ + [ + 45, + 59 + ], + [ + 45, + 58 + ] + ] + }, + "id": "out_of_the_mine", + "kind": "step", + "why": "the hall's warp tiles (11..13, 1)" + }, + { + "action": "to_wall", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "north", + "tiles": 3 + } + ] + }, + "declared_after": { + "facing": "north", + "map": "OreburghCity", + "tiles": [ + [ + 45, + 57 + ] + ] + }, + "id": "up_to_the_mines_sign", + "kind": "legs", + "why": "north against the mine's sign (45, 56)" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "OreburghCity", + "tiles": [ + [ + 47, + 21 + ] + ] + } + }, + "id": "below_the_centers_door_again", + "kind": "route", + "why": "up to below the Center's door" + }, + { + "declared_after": { + "facing": "south", + "map": "OreburghCity", + "tiles": [ + [ + 47, + 21 + ], + [ + 46, + 21 + ] + ] + }, + "id": "heal_oreburgh", + "kind": "heal", + "why": "the nurse; out onto the doorstep, where 01.04 starts" + } + ], + "id": "01.03", + "start": { + "map": "OreburghCity", + "tiles": [ + [ + 43, + 21 + ], + [ + 44, + 21 + ], + [ + 45, + 21 + ], + [ + 43, + 22 + ], + [ + 44, + 22 + ], + [ + 45, + 22 + ] + ] + }, + "title": "Oreburgh Mine to Roark" + }, + "execution": { + "on_failure": "reload_and_retry", + "saves_in": "Oreburgh City" + }, + "format": "pokesim-authored-checkpoint/1", + "game": "bdsp", + "metadata": { + "phase": "reproduction" + } +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp index 02cfac9207..e2b54c7a79 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp @@ -268,6 +268,7 @@ class RouteWalker{ void talk_to_blocker(const std::string& leg_label); LegNext replan_from(const LegWalk& walk, std::vector stopped, const std::string& why); void mark_blocker(const LegWalk& walk, const std::vector& stopped); + void mark_tiles_past(const LegWalk& walk, const std::vector& stopped); RouteIO& m_io; const StoryWorld& m_maps; @@ -475,7 +476,7 @@ size_t RouteWalker::unstick_wall_leg(LegWalk& walk, size_t walked_tiles, size_t if (walk.result.stop == WalkStop::BLOCKED && walked_tiles + 2 < nearest){ m_io.note("[Route] " + walk.label + ": stopped after about " + std::to_string(walked_tiles) + " tiles, short of the wall; two D-pad taps, then on to the wall.", RouteNote::WARNING); - m_io.press({.kind = RouteInputKind::DPAD, .direction = walk.planned.leg.direction, .hold = 160ms, .release = 640ms, + m_io.press({.kind = RouteInputKind::DPAD, .direction = walk.planned.leg.direction, .hold = BDSP_MOVE_MECHANICS.walk.tap.hold, .release = BDSP_MOVE_MECHANICS.walk.tap.release, .count = 2, .end = RouteInputEnd::DONE}); walk.result = m_io.walk_to_wall({.direction = walk.planned.leg.direction, .limit = limit, .label = walk.label, .options = run_watching(walk)}); walked_tiles += tiles_moved(walk.result, per_tile); @@ -516,6 +517,9 @@ LegNext RouteWalker::stopped_short_of_wall(LegWalk& walk, size_t walked_tiles){ fail(m_io, walk.label + ": stopped early, and no tile fits."); } mark_blocker(walk, stopped); + if (never_moved(walk.result, walked_tiles)){ + mark_tiles_past(walk, stopped); + } return replan_from(walk, std::move(stopped), "stopped early after about " + std::to_string(walked_tiles) + " tiles"); } @@ -654,6 +658,9 @@ LegNext RouteWalker::blocked_open_leg(LegWalk& walk, size_t moved){ } stopped = sorted_unique(std::move(stopped)); mark_blocker(walk, stopped); + if (moved == 0){ + mark_tiles_past(walk, stopped); + } return replan_from(walk, std::move(stopped), "blocked after " + std::to_string(moved) + " of " + std::to_string(walk.planned.leg.tiles) + " tiles"); } @@ -839,6 +846,31 @@ void RouteWalker::mark_blocker(const LegWalk& walk, const std::vector& describe(m_maps, blocker) + "; marked it.", RouteNote::WARNING); } +// A walk that never moved from several possible tiles: whatever stopped it +// stands just past one of them, so mark the tiles just past them all +// (but the goal and the tiles we may stand on), or the next plan takes the +// same leg into it again. On lab-B (2026-11-11, 00.05) "east 7 (to wall)" +// from 15 possible tiles below Jubilife's Center walked 0 tiles in five +// plans in a row, and the route gave up on "too many plans". +void RouteWalker::mark_tiles_past(const LegWalk& walk, const std::vector& stopped){ + if (stopped.size() < 2){ + return; + } + std::vector marked; + for (const TilePos& pos : stopped){ + const std::optional next = step(m_grid, pos, walk.planned.leg.direction); + if (!next || m_plan.goal(*next) || std::find(stopped.begin(), stopped.end(), *next) != stopped.end()){ + continue; + } + m_grid.block(*next); + marked.push_back(*next); + } + if (!marked.empty()){ + m_io.note("[Route] " + walk.label + ": nothing moved from " + std::to_string(stopped.size()) + + " possible tiles; marked the tiles past them: " + describe(m_maps, sorted_unique(std::move(marked))) + ".", RouteNote::WARNING); + } +} + LegNext RouteWalker::replan_from(const LegWalk& walk, std::vector stopped, const std::string& why){ m_io.note(std::format("{}{}", ROUTE_LOG_TAG, route_replan_line(m_plan.label, route_log_leg(walk.planned.leg), why, route_tiles(m_maps, stopped))), RouteNote::WARNING); m_facing = walk.planned.leg.direction; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteInput.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteInput.h index 1148e00e5d..bd7df720e0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteInput.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteInput.h @@ -14,6 +14,7 @@ #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "Pokemon/Navigation/Pokemon_Grid.h" +#include "Pokemon/Navigation/Pokemon_MoveMechanics.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -25,7 +26,7 @@ namespace PokemonBDSP{ // stick tap stepped about 0.6 tile, off the tile grid, and a 160 ms D-pad // tap steps a whole tile (r49: a stick "turn" put us a tile west of // Sandgem's Center door; r248a). -constexpr Milliseconds ROUTE_TURN_TAP = Milliseconds(50); +constexpr Milliseconds ROUTE_TURN_TAP = Pokemon::BDSP_MOVE_MECHANICS.turn_tap; // What a RouteInput presses. enum class RouteInputKind{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h index 0648fe7547..3ccbc4125d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h @@ -14,6 +14,7 @@ #include "Common/Cpp/Time.h" #include "Controllers/Joystick.h" #include "Pokemon/Navigation/Pokemon_Grid.h" +#include "Pokemon/Navigation/Pokemon_MoveMechanics.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -22,11 +23,11 @@ namespace PokemonBDSP{ // Walking time per tile, measured on the console from the post-catch save: // a row is deeper than a column is wide under the tilted camera. -constexpr Milliseconds ROUTE_MS_PER_TILE_ACROSS = Milliseconds(160); // east or west +constexpr Milliseconds ROUTE_MS_PER_TILE_ACROSS = Pokemon::BDSP_MOVE_MECHANICS.walk.tile.across; // Walking time per vertical tile (north or south). -constexpr Milliseconds ROUTE_MS_PER_TILE_UP_DOWN = Milliseconds(240); // north or south +constexpr Milliseconds ROUTE_MS_PER_TILE_UP_DOWN = Pokemon::BDSP_MOVE_MECHANICS.walk.tile.up_down; // From pressing the stick to the first step, when standing still. -constexpr Milliseconds ROUTE_START_DELAY = Milliseconds(250); +constexpr Milliseconds ROUTE_START_DELAY = Pokemon::BDSP_MOVE_MECHANICS.start_delay; // How fast the player moves on a leg to a wall (B held with the D-pad). // B only runs once Mom has given the Running Shoes (00.03); before that // it walks. The bike comes later, with its own measured times. @@ -40,9 +41,9 @@ enum class MoveSpeed{ // tile) where walking took 240. Across is scaled the same until measured. // Rounded down: a count from too fast a pace runs over, which a wall leg // forgives, where one from too slow a pace stops short of the wall. -constexpr Milliseconds ROUTE_RUN_MS_PER_TILE_ACROSS = Milliseconds(100); +constexpr Milliseconds ROUTE_RUN_MS_PER_TILE_ACROSS = Pokemon::BDSP_MOVE_MECHANICS.run.tile.across; // Running time per vertical tile (north or south). -constexpr Milliseconds ROUTE_RUN_MS_PER_TILE_UP_DOWN = Milliseconds(150); +constexpr Milliseconds ROUTE_RUN_MS_PER_TILE_UP_DOWN = Pokemon::BDSP_MOVE_MECHANICS.run.tile.up_down; // Time per tile in `direction` at `speed`. Milliseconds route_ms_per_tile(Pokemon::Direction direction, MoveSpeed speed = MoveSpeed::WALK); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.cpp index d42cfd12e7..5461f08337 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.cpp @@ -16,6 +16,7 @@ #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/Navigation/Pokemon_MoveMechanics.h" #include "Pokemon/Navigation/Pokemon_RouteLog.h" #include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" #include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h" @@ -34,19 +35,9 @@ using namespace std::chrono_literals; using namespace Pokemon; -namespace{ - -bool across(Direction direction){ - return direction == Direction::EAST || direction == Direction::WEST; -} - -} // namespace - Milliseconds route_ms_per_tile(Direction direction, MoveSpeed speed){ - if (speed == MoveSpeed::RUN){ - return across(direction) ? ROUTE_RUN_MS_PER_TILE_ACROSS : ROUTE_RUN_MS_PER_TILE_UP_DOWN; - } - return across(direction) ? ROUTE_MS_PER_TILE_ACROSS : ROUTE_MS_PER_TILE_UP_DOWN; + const MoveMechanics& game = BDSP_MOVE_MECHANICS; + return (speed == MoveSpeed::RUN ? game.run : game.walk).tile.along(direction); } JoystickPosition route_stick(Direction direction){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.cpp index ee57909017..677d4a32eb 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.cpp @@ -19,9 +19,11 @@ #include "CommonTools/VisualDetectors/BlackScreenDetector.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" +#include "Pokemon/Navigation/Pokemon_MoveMechanics.h" #include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" #include "PokemonBDSP/Inference/PokemonBDSP_TransitionWatchers.h" #include "PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.h" +#include "PokemonBDSP_AutoStory_Indoors.h" #include "PokemonBDSP_AutoStory_Location.h" #include "PokemonBDSP_AutoStory_LocationBannerWatcher.h" #include "PokemonBDSP_AutoStory_Walk.h" @@ -112,6 +114,70 @@ WarpFade WarpFadeWatch::push(const Pokemon::TransitionSample& sample){ } +namespace detail{ +bool ViewShift::scrolled() const{ + constexpr double LEAST_DIFFERENCE = 3; // standing still in the video: 0 to 1.5 + return (dx != 0 || dy != 0) && unshifted >= LEAST_DIFFERENCE && unshifted >= 2 * shifted; +} + +ViewShift walk_view_shift(const ImageViewRGB32& before, const ImageViewRGB32& after){ + constexpr int W = 192; + constexpr int H = 108; + // A step scrolls 2 to 10 pixels of the copy in 300 ms. + constexpr int REACH = 12; + const ImageRGB32 a = before.scale_to(W, H); + const ImageRGB32 b = after.scale_to(W, H); + // The player's box, which moves with the camera, not with the scenery. + auto in_player_box = [](int x, int y){ + return x >= W * 42 / 100 && x < W * 58 / 100 && y >= H * 30 / 100 && y < H * 75 / 100; + }; + auto difference = [&](int dx, int dy){ + uint64_t sum = 0; + size_t count = 0; + for (int y = REACH; y < H - REACH; y++){ + for (int x = REACH; x < W - REACH; x++){ + if (in_player_box(x, y)){ + continue; + } + const uint32_t p = a.pixel(x - dx, y - dy); + const uint32_t q = b.pixel(x, y); + for (int shift = 0; shift < 24; shift += 8){ + const int c = (int)((p >> shift) & 0xff) - (int)((q >> shift) & 0xff); + sum += c < 0 ? -c : c; + } + count += 3; + } + } + return (double)sum / (double)count; + }; + ViewShift best; + best.unshifted = difference(0, 0); + best.shifted = best.unshifted; + for (int dy = -REACH; dy <= REACH; dy++){ + for (int dx = -REACH; dx <= REACH; dx++){ + if (dx == 0 && dy == 0){ + continue; + } + const double d = difference(dx, dy); + if (d < best.shifted){ + best.shifted = d; + best.dx = dx; + best.dy = dy; + } + } + } + return best; +} + +bool tap_moved(const ImageViewRGB32& before, const ImageViewRGB32& after, double line){ + if (indoors(after)){ + return walk_screen_change(before, after) >= line; + } + return walk_view_shift(before, after).scrolled(); +} +} // namespace detail + + namespace{ // The battle's text box, held for 250ms. @@ -323,8 +389,9 @@ class WalkUntil{ {} WalkResult run(){ - // A tile a tap: 160 ms held, the rest released, so each chunk is one tile. - const Milliseconds CHUNK = m_spec.input == WalkInput::TAPS ? 800ms : 400ms; + // A tile a tap: the step tap held, the rest released, so each chunk is one tile. + const Pokemon::StepTap& tap = Pokemon::BDSP_MOVE_MECHANICS.walk.tap; + const Milliseconds CHUNK = m_spec.input == WalkInput::TAPS ? tap.hold + tap.release : 400ms; m_context.wait_for_all_requests(); m_result.started = current_time(); m_result.events.record({}, m_result.started); @@ -373,9 +440,11 @@ class WalkUntil{ void press(ProControllerContext& context, Milliseconds chunk) const{ switch (m_spec.input){ - case WalkInput::TAPS: - pbf_press_dpad(context, m_dpad, 160ms, chunk - 160ms); + case WalkInput::TAPS:{ + const Pokemon::StepTap& tap = Pokemon::BDSP_MOVE_MECHANICS.walk.tap; + pbf_press_dpad(context, m_dpad, tap.hold, chunk - tap.hold); return; + } case WalkInput::DPAD_RUN: ssf_press_button(context, BUTTON_B, 0ms, chunk, 0ms); ssf_press_dpad(context, m_dpad, chunk, chunk, 0ms); @@ -438,7 +507,11 @@ class WalkUntil{ m_before = std::move(after); return {ChunkNext::NEXT_CHUNK, WalkStop::LIMIT}; } - const bool still = still_chunk(change); + // Taps count what scrolled the view, not scenery that moved (r84: + // cloud shadows read as steps). + const bool still = m_spec.input == WalkInput::TAPS + ? !tap_moved(*m_before.frame, *after.frame, still_line(change)) + : change < still_line(change); if (!still){ // A quiet tap and then a moving one: the first moved too. What // blocks a tap still blocks the next; the view barely changed @@ -460,12 +533,11 @@ class WalkUntil{ // NPC measured 17.2 after steps of 63 to 65 (r250a, Floaroma's old // woman), over the fixed line of 16, so for taps "still" is also // anything under 40% of the walk's own steps. - bool still_chunk(double change){ + double still_line(double change){ m_largest = std::max(m_largest, change); - const double line = m_spec.input == WalkInput::TAPS + return m_spec.input == WalkInput::TAPS ? std::max(WALK_TAP_BLOCKED_CHANGE, 0.4 * m_largest) : WALK_BLOCKED_CHANGE; - return change < line; } // What hold()'s watcher `ret` saw (see after_watchers()). @@ -528,7 +600,7 @@ class WalkUntil{ ){ VideoSnapshot after = snapshot_or_fail(m_stream, m_spec.label); const double change = walk_screen_change(*m_before_still.frame, *after.frame); - if (!still_chunk(change)){ + if (tap_moved(*m_before_still.frame, *after.frame, still_line(change))){ m_result.moved_chunks++; } } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h index acb7daf3b4..a5b0fe8c4f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h @@ -36,6 +36,47 @@ constexpr double WALK_TAP_BLOCKED_CHANGE = 16.0; // More than walking changes in 400ms: a new scene, such as a battle opening. constexpr double WALK_SCENE_CHANGE = 120.0; +namespace detail{ + +// How the view scrolled between two frames, on 192x108 copies: the shift +// (dx, dy) of `before` that best lines up with `after`, leaving out the +// middle where the player stands, and the mean difference per colour +// channel (0 to 255) with and without it. Outside, the camera follows the +// player, so a step scrolls everything one way; a TV, a conveyor, a +// passer-by or a cloud shadow changes part of the view with no common +// scroll. In r83's and r84's Floaroma video, frames 300 ms apart while +// standing (screen changes up to 57, cloud shadows, text boxes) never read +// as scrolled; walking read a shift 2 to 6 times better than none. +struct ViewShift{ + int dx = 0; + int dy = 0; + double unshifted = 0; + double shifted = 0; + + // A shift lines up at least twice as well as none, and none leaves a + // real difference. + bool scrolled() const; +}; + +// Calculates the view scroll shift between before and after images. +ViewShift walk_view_shift(const ImageViewRGB32& before, const ImageViewRGB32& after); + +// Whether the player moved between `before` and `after`, frames around a +// D-pad tap. Outside: only if the view scrolled. Inside, the camera can +// stay put while the player crosses a room (the house's 1F), so there a +// screen change of at least `line` counts, as it did before. +bool tap_moved(const ImageViewRGB32& before, const ImageViewRGB32& after, double line); + +} // namespace detail + +// View scroll shift calculation. +using detail::ViewShift; +// Calculates the view scroll shift between before and after images. +using detail::walk_view_shift; +// Whether the player moved between before and after frames. +using detail::tap_moved; + + // Whether two frames show different scenes: a change walking cannot make // (WALK_SCENE_CHANGE). UNKNOWN without both frames. Pokemon::SceneChange walk_scenes_differ(const Pokemon::TransitionSample& before, const Pokemon::TransitionSample& after); diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index a3579f8b44..eae67abbf3 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -346,6 +346,8 @@ file(GLOB CORE_LIBRARY_SOURCES Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController_from_Keyboard.h Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProControllerState.cpp Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProControllerState.h + Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp + Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h Source/NintendoSwitch/NintendoSwitch_Settings.cpp Source/NintendoSwitch/NintendoSwitch_Settings.h Source/NintendoSwitch/Options/NintendoSwitch_CodeEntrySettingsOption.cpp @@ -738,8 +740,6 @@ file(GLOB LIBRARY_SOURCES Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.5.h Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.cpp Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.h - Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6_QQuickView.cpp - Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6_QQuickView.h Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6_QQuickWidget.cpp Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6_QQuickWidget.h Source/CommonFramework/VideoPipeline/Backends/MediaServicesQt6.cpp @@ -962,7 +962,6 @@ file(GLOB LIBRARY_SOURCES Source/Controllers/NullControllerWidget.h Source/Controllers/PABotBase2/SerialPABotBase2_SelectorWidget.cpp Source/Controllers/PABotBase2/SerialPABotBase2_SelectorWidget.h - Source/Controllers/PABotBase2/SerialPABotBase_StatusThread.h Source/Controllers/SerialPort/SerialPortPollerQt.cpp Source/Controllers/SerialPort/SerialPortPollerQt.h Source/Integrations/DiscordIntegrationSettings.cpp @@ -1141,7 +1140,6 @@ file(GLOB LIBRARY_SOURCES Source/Kernels/BinaryMatrix/Kernels_BinaryMatrix.h Source/Kernels/BinaryMatrix/Kernels_BinaryMatrix_Arch_64x16_x64_AVX2.h Source/Kernels/BinaryMatrix/Kernels_BinaryMatrix_Arch_64x32_x64_AVX512.h - Source/Kernels/BinaryMatrix/Kernels_BinaryMatrix_Arch_64x4_Default.h Source/Kernels/BinaryMatrix/Kernels_BinaryMatrix_Arch_64x64_x64_AVX512.h Source/Kernels/BinaryMatrix/Kernels_BinaryMatrix_Arch_64x8_arm64_NEON.h Source/Kernels/BinaryMatrix/Kernels_BinaryMatrix_Arch_64x8_x64_SSE42.h @@ -1163,7 +1161,6 @@ file(GLOB LIBRARY_SOURCES Source/Kernels/BinaryMatrix/Kernels_BinaryMatrixTile_64x8_x64_SSE42.h Source/Kernels/BinaryMatrix/Kernels_BinaryMatrixTile_64xH_Default.h Source/Kernels/BinaryMatrix/Kernels_BinaryMatrixTile_Debugging.h - Source/Kernels/BinaryMatrix/Kernels_PackedBinaryMatrix.h Source/Kernels/BinaryMatrix/Kernels_PackedBinaryMatrixCore.h Source/Kernels/BinaryMatrix/Kernels_PackedBinaryMatrixCore.tpp Source/Kernels/BinaryMatrix/Kernels_SparseBinaryMatrixCore.h @@ -1367,8 +1364,6 @@ file(GLOB LIBRARY_SOURCES Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.cpp Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.h - Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp - Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.cpp Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.cpp @@ -1709,90 +1704,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Resources/Pokemon_PokemonNames.h Source/Pokemon/Resources/Pokemon_PokemonSlugs.cpp Source/Pokemon/Resources/Pokemon_PokemonSlugs.h - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleBallReader.cpp - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleBallReader.h - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.cpp - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.h - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_EndBattleDetector.cpp - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_EndBattleDetector.h - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_ExperienceGainDetector.cpp - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_ExperienceGainDetector.h - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_StartBattleDetector.cpp - Source/PokemonBDSP/Inference/Battles/PokemonBDSP_StartBattleDetector.h - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxDetector.cpp - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxDetector.h - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxGenderDetector.cpp - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxGenderDetector.h - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxNatureDetector.cpp - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxNatureDetector.h - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxShinyDetector.cpp - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxShinyDetector.h - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_IvJudgeReader.cpp - Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_IvJudgeReader.h - Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp - Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h - Source/PokemonBDSP/Inference/PokemonBDSP_MapDetector.cpp - Source/PokemonBDSP/Inference/PokemonBDSP_MapDetector.h - Source/PokemonBDSP/Inference/PokemonBDSP_MarkFinder.cpp - Source/PokemonBDSP/Inference/PokemonBDSP_MarkFinder.h - Source/PokemonBDSP/Inference/PokemonBDSP_TransitionWatchers.cpp - Source/PokemonBDSP/Inference/PokemonBDSP_TransitionWatchers.h - Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp - Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h Source/PokemonBDSP/Inference/PokemonBDSP_NameListDetector.cpp Source/PokemonBDSP/Inference/PokemonBDSP_NameListDetector.h - Source/PokemonBDSP/Inference/PokemonBDSP_PokeballSpriteMatcher.cpp - Source/PokemonBDSP/Inference/PokemonBDSP_PokeballSpriteMatcher.h - Source/PokemonBDSP/Inference/PokemonBDSP_ReceivePokemonDetector.cpp - Source/PokemonBDSP/Inference/PokemonBDSP_ReceivePokemonDetector.h - Source/PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.cpp - Source/PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.h - Source/PokemonBDSP/Inference/PokemonBDSP_VSSeekerReaction.cpp - Source/PokemonBDSP/Inference/PokemonBDSP_VSSeekerReaction.h - Source/PokemonBDSP/Inference/Rng/PokemonBDSP_BlinkExtraction.cpp - Source/PokemonBDSP/Inference/Rng/PokemonBDSP_BlinkExtraction.h - Source/PokemonBDSP/Inference/Rng/PokemonBDSP_BlinkScenes.cpp - Source/PokemonBDSP/Inference/Rng/PokemonBDSP_BlinkScenes.h - Source/PokemonBDSP/Inference/Rng/PokemonBDSP_EyeBlinkDetector.cpp - Source/PokemonBDSP/Inference/Rng/PokemonBDSP_EyeBlinkDetector.h - Source/PokemonBDSP/Inference/Rng/PokemonBDSP_SummaryReader.cpp - Source/PokemonBDSP/Inference/Rng/PokemonBDSP_SummaryReader.h - Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinyEncounterDetector.cpp - Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinyEncounterDetector.h - Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinySparkleSet.cpp - Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinySparkleSet.h - Source/PokemonBDSP/Inference/Sounds/PokemonBDSP_ShinySoundDetector.cpp - Source/PokemonBDSP/Inference/Sounds/PokemonBDSP_ShinySoundDetector.h - Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterEnums.cpp - Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterEnums.h - Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.cpp - Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.h - Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOverride.cpp - Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOverride.h - Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterWidget.cpp - Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterWidget.h - Source/PokemonBDSP/Options/PokemonBDSP_BerrySelectOption.cpp - Source/PokemonBDSP/Options/PokemonBDSP_BerrySelectOption.h - Source/PokemonBDSP/Options/PokemonBDSP_BerryTable.cpp - Source/PokemonBDSP/Options/PokemonBDSP_BerryTable.h - Source/PokemonBDSP/Options/PokemonBDSP_EggStepOption.cpp - Source/PokemonBDSP/Options/PokemonBDSP_EggStepOption.h - Source/PokemonBDSP/Options/PokemonBDSP_EncounterBotCommon.h - Source/PokemonBDSP/Options/PokemonBDSP_LearnMove.h - Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.cpp - Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.h - Source/PokemonBDSP/Options/PokemonBDSP_ShortcutDirection.cpp - Source/PokemonBDSP/Options/PokemonBDSP_ShortcutDirection.h - Source/PokemonBDSP/Panels_PokemonBDSP.cpp - Source/PokemonBDSP/Panels_PokemonBDSP.h - Source/PokemonBDSP/PokemonBDSP_Panels.cpp - Source/PokemonBDSP/PokemonBDSP_Panels.h - Source/PokemonBDSP/PokemonBDSP_Settings.cpp - Source/PokemonBDSP/PokemonBDSP_Settings.h - Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.cpp - Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h - Source/PokemonBDSP/PokemonBDSP_Tests.cpp - Source/PokemonBDSP/PokemonBDSP_Tests.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp @@ -1808,6 +1721,13 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BattleMoves.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Center.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Center.h + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Lake.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Oreburgh.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Route204.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Sandgem.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroProbe.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroSteps.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_LitDoorway.h @@ -1815,12 +1735,10 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_NewGame.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.h + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.h - Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_BattleMenuReader.cpp - Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_BattleMenuReader.h - Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_MenuCursorDetector.cpp - Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_MenuCursorDetector.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp @@ -1843,20 +1761,45 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h + Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_BattleMenuReader.cpp + Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_BattleMenuReader.h + Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_MenuCursorDetector.cpp + Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_MenuCursorDetector.h + Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.cpp + Source/PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlanGolden.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StorySimulation_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_CountedWallLeg.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.h @@ -1885,6 +1828,84 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkProbe.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleBallReader.cpp + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleBallReader.h + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.cpp + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.h + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_EndBattleDetector.cpp + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_EndBattleDetector.h + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_ExperienceGainDetector.cpp + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_ExperienceGainDetector.h + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_StartBattleDetector.cpp + Source/PokemonBDSP/Inference/Battles/PokemonBDSP_StartBattleDetector.h + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxDetector.cpp + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxDetector.h + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxGenderDetector.cpp + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxGenderDetector.h + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxNatureDetector.cpp + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxNatureDetector.h + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxShinyDetector.cpp + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_BoxShinyDetector.h + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_IvJudgeReader.cpp + Source/PokemonBDSP/Inference/BoxSystem/PokemonBDSP_IvJudgeReader.h + Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp + Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h + Source/PokemonBDSP/Inference/PokemonBDSP_MapDetector.cpp + Source/PokemonBDSP/Inference/PokemonBDSP_MapDetector.h + Source/PokemonBDSP/Inference/PokemonBDSP_MarkFinder.cpp + Source/PokemonBDSP/Inference/PokemonBDSP_MarkFinder.h + Source/PokemonBDSP/Inference/PokemonBDSP_TransitionWatchers.cpp + Source/PokemonBDSP/Inference/PokemonBDSP_TransitionWatchers.h + Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp + Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h + Source/PokemonBDSP/Inference/PokemonBDSP_PokeballSpriteMatcher.cpp + Source/PokemonBDSP/Inference/PokemonBDSP_PokeballSpriteMatcher.h + Source/PokemonBDSP/Inference/PokemonBDSP_ReceivePokemonDetector.cpp + Source/PokemonBDSP/Inference/PokemonBDSP_ReceivePokemonDetector.h + Source/PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.cpp + Source/PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.h + Source/PokemonBDSP/Inference/PokemonBDSP_VSSeekerReaction.cpp + Source/PokemonBDSP/Inference/PokemonBDSP_VSSeekerReaction.h + Source/PokemonBDSP/Inference/Rng/PokemonBDSP_BlinkExtraction.cpp + Source/PokemonBDSP/Inference/Rng/PokemonBDSP_BlinkExtraction.h + Source/PokemonBDSP/Inference/Rng/PokemonBDSP_BlinkScenes.cpp + Source/PokemonBDSP/Inference/Rng/PokemonBDSP_BlinkScenes.h + Source/PokemonBDSP/Inference/Rng/PokemonBDSP_EyeBlinkDetector.cpp + Source/PokemonBDSP/Inference/Rng/PokemonBDSP_EyeBlinkDetector.h + Source/PokemonBDSP/Inference/Rng/PokemonBDSP_SummaryReader.cpp + Source/PokemonBDSP/Inference/Rng/PokemonBDSP_SummaryReader.h + Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinyEncounterDetector.cpp + Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinyEncounterDetector.h + Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinySparkleSet.cpp + Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinySparkleSet.h + Source/PokemonBDSP/Inference/Sounds/PokemonBDSP_ShinySoundDetector.cpp + Source/PokemonBDSP/Inference/Sounds/PokemonBDSP_ShinySoundDetector.h + Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterEnums.cpp + Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterEnums.h + Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.cpp + Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.h + Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOverride.cpp + Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOverride.h + Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterWidget.cpp + Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterWidget.h + Source/PokemonBDSP/Options/PokemonBDSP_BerrySelectOption.cpp + Source/PokemonBDSP/Options/PokemonBDSP_BerrySelectOption.h + Source/PokemonBDSP/Options/PokemonBDSP_BerryTable.cpp + Source/PokemonBDSP/Options/PokemonBDSP_BerryTable.h + Source/PokemonBDSP/Options/PokemonBDSP_EggStepOption.cpp + Source/PokemonBDSP/Options/PokemonBDSP_EggStepOption.h + Source/PokemonBDSP/Options/PokemonBDSP_EncounterBotCommon.h + Source/PokemonBDSP/Options/PokemonBDSP_LearnMove.h + Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.cpp + Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.h + Source/PokemonBDSP/Options/PokemonBDSP_ShortcutDirection.cpp + Source/PokemonBDSP/Options/PokemonBDSP_ShortcutDirection.h + Source/PokemonBDSP/PokemonBDSP_Panels.cpp + Source/PokemonBDSP/PokemonBDSP_Panels.h + Source/PokemonBDSP/PokemonBDSP_Settings.cpp + Source/PokemonBDSP/PokemonBDSP_Settings.h + Source/PokemonBDSP/PokemonBDSP_Tests.cpp + Source/PokemonBDSP/PokemonBDSP_Tests.h Source/PokemonBDSP/Programs/Eggs/PokemonBDSP_EggAutonomous.cpp Source/PokemonBDSP/Programs/Eggs/PokemonBDSP_EggAutonomous.h Source/PokemonBDSP/Programs/Eggs/PokemonBDSP_EggAutonomousState.cpp @@ -2302,8 +2323,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLA/Options/PokemonLA_TravelLocation.h Source/VideoGames/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.cpp Source/VideoGames/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.h - Source/VideoGames/PokemonLA/Panels_PokemonLA.cpp - Source/VideoGames/PokemonLA/Panels_PokemonLA.h Source/VideoGames/PokemonLA/PokemonLA_Locations.cpp Source/VideoGames/PokemonLA/PokemonLA_Locations.h Source/VideoGames/PokemonLA/PokemonLA_Panels.cpp @@ -2532,8 +2551,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h Source/VideoGames/PokemonLZA/Programs/PokemonLZA_HyperspaceNavigation.cpp Source/VideoGames/PokemonLZA/Programs/PokemonLZA_HyperspaceNavigation.h - Source/VideoGames/PokemonLZA/Programs/PokemonLZA_MegaShardFarmer.cpp - Source/VideoGames/PokemonLZA/Programs/PokemonLZA_MegaShardFarmer.h Source/VideoGames/PokemonLZA/Programs/PokemonLZA_MenuNavigation.cpp Source/VideoGames/PokemonLZA/Programs/PokemonLZA_MenuNavigation.h Source/VideoGames/PokemonLZA/Programs/PokemonLZA_PostKillCatcher.cpp