diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h index 0e51776983..a545337b5a 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h @@ -28,6 +28,7 @@ #include "Pokemon_StoryInterrupts_Tests.h" #include "Pokemon_StoryLog_Tests.h" #include "Pokemon_StoryRun_Tests.h" +#include "Pokemon_StoryRngHandoff_Tests.h" #include "Pokemon_StorySavePolicy_Tests.h" #include "Pokemon_StorySegments_Tests.h" #include "Pokemon_StoryStepExecutor_Tests.h" @@ -44,6 +45,7 @@ inline void add_tests_AutoStory(UnitTestDatabase& database){ add_tests_StoryRun(database); add_tests_AutoStoryStats(database); add_tests_StoryLog(database); + add_tests_StoryRngHandoff(database); add_tests_StoryRangeOptions(database); add_tests_StoryEvents(database); add_tests_StorySegments(database); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp new file mode 100644 index 0000000000..1890518dd4 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp @@ -0,0 +1,68 @@ +/* Story RNG Handoff + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Color.h" +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "Pokemon_StoryRngHandoff.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +RngHandoffMode rng_handoff_mode(const RngHandoffOptions& options){ + if (options.run){ + return RngHandoffMode::RUN; + } + return options.stop ? RngHandoffMode::STOP : RngHandoffMode::OFF; +} + +bool RngHandoffResult::succeeded() const{ + return failure.empty(); +} + +std::optional run_rng_handoff_or_user_turn( + Logger& logger, const std::string& program, const RngHandoffCall& call +){ + const RngHandoffResult result = call(); + if (!result.succeeded()){ + throw_and_log(logger, ErrorReportMode::SEND_ERROR_REPORT, result.failure); + } + if (!result.user_turn.empty()){ + logger.log(program + " stopped for the user: " + result.user_turn, COLOR_BLUE); + return result.user_turn; + } + logger.log(program + " succeeded: " + result.summary, COLOR_BLUE); + return std::nullopt; +} + +Outcome run_rng_handoff(Logger& logger, const std::string& program, const RngHandoffCall& call){ + const std::optional user_turn = run_rng_handoff_or_user_turn(logger, program, call); + if (user_turn){ + // A story action has no stop to give the user's turn to. + throw_and_log(logger, ErrorReportMode::SEND_ERROR_REPORT, *user_turn); + } + return outcome_ok(); +} + +std::string report_rng_handoff_stop( + Logger& logger, const std::string& message, const std::vector& lines, + const std::function& show +){ + std::string text = message; + logger.log(message, COLOR_BLUE); + show(message); + for (const std::string& line : lines){ + logger.log(line, COLOR_BLUE); + show(line); + text += "\n" + line; + } + return text; +} + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.h new file mode 100644 index 0000000000..ddc21f3286 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.h @@ -0,0 +1,96 @@ +/* Story RNG Handoff + * + * From: https://github.com/PokemonAutomation/ + * + * The part of an AutoStory run that hands the game to an RNG program (BDSP + * Starter RNG, FRLG Starter RNG and Gift RNG) and takes it back. A game + * supplies the program's call; the contract around it is shared: + * + * - A handoff row has a mode: OFF (the story plays it by hand), STOP (the run + * ends after the row's handoff save, for the user to run the RNG program) + * or RUN (the story calls the RNG program itself and continues). + * - The call ends in an RngHandoffResult: no failure means the game stands + * where the story goes on; a failure is the reason it does not. A game + * whose program can also end where the user takes over (FRLG: the target + * hit but not shiny, the attempts spent) gives that end a user_turn, which + * is a stop and not an error. What the story runs after a continuation + * (FRLG: the rows after a shiny) is the game's, built from the call. + * - A failed RUN stops the program. It never retries the row: the program's + * own reset loop is the retry, and a reload of the save would lose a + * shiny it caught. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRngHandoff_H +#define PokemonAutomation_Pokemon_StoryRngHandoff_H + +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Pokemon_StoryOutcome.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// What a handoff row does with its RNG program. +enum class RngHandoffMode{ + OFF, + STOP, + RUN, +}; + +// A handoff's two options. +struct RngHandoffOptions{ + bool stop = false; + bool run = false; +}; + +// The mode for a handoff's two options: RUN takes precedence over STOP. +RngHandoffMode rng_handoff_mode(const RngHandoffOptions& options); + + +// How an RNG program's call ended, as the story needs it. +struct RngHandoffResult{ + // Empty: the game stands where the story goes on. Otherwise why it does not. + std::string failure; + // What a success did, for the log: the resets used, the target hit. + std::string summary; + // Not empty (and no failure): the program ended where the user takes + // over, with this for them. The run stops without an error report. + std::string user_turn; + + bool succeeded() const; +}; + +// The call a handoff row runs in place of its steps. +using RngHandoffCall = std::function; + +// Runs `call` for the RNG program `program` ("Starter RNG"). A success is +// logged with its summary and returned as an ok Outcome. A failure throws +// OperationFailedException with an error report, so that no row retry +// reruns the program's reset loop. +Outcome run_rng_handoff(Logger& logger, const std::string& program, const RngHandoffCall& call); + +// As run_rng_handoff(), for a program whose call may end in the user's turn: +// returns that message, which is logged, and the run stops there. Returns +// nothing when the game stands where the story goes on. +std::optional run_rng_handoff_or_user_turn( + Logger& logger, const std::string& program, const RngHandoffCall& call +); + +// A run that stops for the user to run an RNG program, as the game's program +// reports it: `message` (what to do) and then `lines` (the RNG plan's +// attempts), each logged and passed to `show` (the overlay's log). Returns +// the whole text, one line each, for the program's finish notification. +std::string report_rng_handoff_stop( + Logger& logger, const std::string& message, const std::vector& lines, + const std::function& show +); + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp new file mode 100644 index 0000000000..a5733d5bce --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp @@ -0,0 +1,189 @@ +/* Story RNG Handoff Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "Pokemon_StoryRngHandoff.h" +#include "Pokemon_StoryRngHandoff_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + +namespace{ + +struct RngHandoffInput{ + std::string_view name; + UnitTestResult (*body)(Logger& logger); +}; + +struct RngHandoffExpectation{ + std::string_view description; +}; + +struct RngHandoffTestCase{ + RngHandoffInput input; + RngHandoffExpectation expectation; +}; + +class Test_RngHandoff : public UnitTest{ +public: + explicit Test_RngHandoff(RngHandoffTestCase scenario) + : UnitTest("Pokemon::StoryRngHandoff - " + std::string(scenario.input.name)) + , m_scenario(scenario) + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + return m_scenario.input.body(logger); + } + +private: + RngHandoffTestCase m_scenario; +}; + +// rng_handoff_mode()'s two options. +UnitTestResult test_mode(Logger&){ + struct Case{ + RngHandoffOptions options; + RngHandoffMode expected; + }; + const Case cases[] = { + {.options = {.stop = false, .run = false}, .expected = RngHandoffMode::OFF}, + {.options = {.stop = true, .run = false}, .expected = RngHandoffMode::STOP}, + {.options = {.stop = false, .run = true}, .expected = RngHandoffMode::RUN}, + {.options = {.stop = true, .run = true}, .expected = RngHandoffMode::RUN}, + }; + for (const Case& item : cases){ + if (rng_handoff_mode(item.options) != item.expected){ + return std::format("stop={}, run={}: wrong mode", item.options.stop, item.options.run); + } + } + return true; +} + +// A success is an ok Outcome and calls the program once. +UnitTestResult test_success(Logger& logger){ + int calls = 0; + const Outcome outcome = run_rng_handoff(logger, "Test RNG", [&]{ + calls++; + return RngHandoffResult{.summary = "2 resets"}; + }); + if (!outcome.succeeded()){ + return "Expected an ok outcome"; + } + if (calls != 1){ + return std::format("Expected 1 call, got {}", calls); + } + return true; +} + +// A failure throws, once: nothing reruns the program. +UnitTestResult test_failure(Logger& logger){ + int calls = 0; + try{ + run_rng_handoff(logger, "Test RNG", [&]{ + calls++; + return RngHandoffResult{.failure = "out of resets"}; + }); + }catch (OperationFailedException&){ + if (calls != 1){ + return std::format("Expected 1 call, got {}", calls); + } + return true; + } + return "Expected OperationFailedException"; +} + +// The user's turn is returned, not thrown, once; a success has none; a +// failure throws even with one. +UnitTestResult test_user_turn(Logger& logger){ + int calls = 0; + const std::optional turn = run_rng_handoff_or_user_turn(logger, "Test RNG", [&]{ + calls++; + return RngHandoffResult{.user_turn = "save by hand"}; + }); + if (!turn || *turn != "save by hand"){ + return "Expected the user's turn"; + } + if (calls != 1){ + return std::format("Expected 1 call, got {}", calls); + } + const std::optional none = run_rng_handoff_or_user_turn(logger, "Test RNG", []{ + return RngHandoffResult{.summary = "shiny"}; + }); + if (none){ + return "A success has no user's turn"; + } + try{ + run_rng_handoff_or_user_turn(logger, "Test RNG", []{ + return RngHandoffResult{.failure = "out of resets", .user_turn = "ignored"}; + }); + }catch (OperationFailedException&){ + return true; + } + return "A failure must throw even with a user's turn"; +} + +// A stop reports its message, then each line, to the log and to `show`; +// the notification text is one line each. +UnitTestResult test_stop_report(Logger& logger){ + std::vector shown; + const auto show = [&](const std::string& line){ + shown.push_back(line); + }; + const std::string text = report_rng_handoff_stop(logger, "Stopped for RNG.", {"Attempt 1", "Attempt 2"}, show); + if (text != "Stopped for RNG.\nAttempt 1\nAttempt 2"){ + return std::format("Wrong notification text: {}", text); + } + if (shown != std::vector{"Stopped for RNG.", "Attempt 1", "Attempt 2"}){ + return "The overlay must get the message and then each line"; + } + shown.clear(); + if (report_rng_handoff_stop(logger, "Stopped.", {}, show) != "Stopped." || shown.size() != 1){ + return "A stop without lines is its message alone"; + } + return true; +} + +const RngHandoffTestCase RNG_HANDOFF_CASES[] = { + { + .input = {.name = "RUN takes precedence over STOP", .body = test_mode}, + .expectation = {.description = "RUN wins when both options are on"}, + }, + { + .input = {.name = "a stop reports its message and lines", .body = test_stop_report}, + .expectation = {.description = "log, overlay and notification text agree"}, + }, + { + .input = {.name = "a success is ok", .body = test_success}, + .expectation = {.description = "an ok outcome after one call"}, + }, + { + .input = {.name = "a failure throws without a retry", .body = test_failure}, + .expectation = {.description = "OperationFailedException after one call"}, + }, + { + .input = {.name = "a user's turn is returned, not an error", .body = test_user_turn}, + .expectation = {.description = "the message comes back; a failure still throws"}, + }, +}; + +} // namespace + + +void add_tests_StoryRngHandoff(UnitTestDatabase& database){ + for (const RngHandoffTestCase& scenario : RNG_HANDOFF_CASES){ + database.add(scenario); + } +} + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.h new file mode 100644 index 0000000000..aca6f82c1b --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.h @@ -0,0 +1,23 @@ +/* Story RNG Handoff Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRngHandoff_Tests_H +#define PokemonAutomation_Pokemon_StoryRngHandoff_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the shared RNG handoff contract. +void add_tests_StoryRngHandoff(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp index e9bada9229..2881dff960 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp @@ -148,7 +148,6 @@ OverworldSim::OverworldSim(std::vector maps, MapPosition start, Directi } add_coded_field(); m_state.gates = m_script.gates; - m_state.card_key_held = m_script.card_key_held; read_gates(); m_player = PlayerState{start.point, elevation_at(map(), start.point), false}; m_state.facing = facing; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index 20c3b3efd1..ede21f0066 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -61,12 +61,18 @@ namespace PokemonFRLG{ // Simulates overworld movement, encounters and dialogs. +// code-health: allow public_methods -- the Card Key pickup is a story event the row sim reports to the one sim, beside its other inputs class OverworldSim{ public: OverworldSim(std::vector maps, MapPosition start, Direction facing, SimScript script = {}); const SimState& state() const{ return m_state; } + // Whether the player holds the Card Key (SimScript::card_key_held). + bool card_key_held() const{ return m_script.card_key_held; } + // The player picks up the Card Key: A on a card-key gate opens it from now on. + void give_card_key(){ m_script.card_key_held = true; } + // Whether the walker's screen check reads its last step tap as a // step: one that moved the player from `before`, but for // SimScript::unseen_step_taps, or a turn tap since `turn_taps_before` diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h index 7c1e063d98..e90ca6fb01 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h @@ -142,8 +142,6 @@ struct SimState{ // The maps as loaded, with each gate closed or open as the map says, to // plan through the gates (resolve_maps()); empty if no map has a gate. std::vector gate_maps; - // Whether the player holds the Card Key (SimScript::card_key_held). - bool card_key_held = false; Direction facing = Direction::SOUTH; SimScreen screen = SimScreen::OVERWORLD; // Whether black shows below the map: the player stands near the bottom diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index dc0d21bdcc..4dc1e53ac6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -13,6 +13,7 @@ #include "CommonFramework/Notifications/ProgramNotifications.h" #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "Pokemon/AutoStory/Pokemon_StoryPreflight.h" +#include "Pokemon/AutoStory/Pokemon_StoryRngHandoff.h" #include "Pokemon/AutoStory/Pokemon_StoryRun.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" @@ -93,11 +94,17 @@ const std::string RUN_GIFT_RNG_TEXT = "Pokemon Center, run Gift RNG's attempts for the Magikarp from that save, as the RNG plan lists them for its TID and " "SID (set by Run Starter RNG in AutoStory, or typed in). A shiny Magikarp is saved there (04.03) and the run goes " "on; otherwise the run stops with the save beside the salesman. Likewise for the Eevee: 09.03 saves facing its ball " - "in Celadon Mansion's roof room, and 09.04 saves the shiny.
" - "To try again from that save, start at 04.03 (09.04) with this on: it loads the save and runs the attempts first. " - "After Gift RNG run by hand, start at 04.03 (09.04) with this off.
" + "in Celadon Mansion's roof room, and 09.04 saves the shiny; and for the Lapras: 16.03b saves facing the employee " + "on Silph Co.'s 7F, and 16.04 saves the shiny.
" + "To try again from that save, start at 04.03 (09.04, 16.04) with this on: it loads the save and runs the attempts first. " + "After Gift RNG run by hand, start at 04.03 (09.04, 16.04) with this off.
" "English only. The Magikarp costs 500; each gift needs a free party slot; AutoStory's options leave the text fast."; +const std::string TAKE_MASTER_BALL_TEXT = + "Take the Master Ball:
On by default. After Giovanni on Silph Co.'s 11F, talk to the president for the " + "Master Ball (16.05). Off, or with the checks on SPEEDRUN, skips it."; + +// code-health: allow function_lines -- a flat list of the program's options, each one line of its own; splitting it hides which belong AutoStory::AutoStory() : RUN(checkpoint_database(), Pokemon::FireRedLeafGreenLanguages_Database()) , NEW_GAME_FROM_TITLE( @@ -142,6 +149,7 @@ AutoStory::AutoStory() ) , RUN_STARTER_RNG(RUN_STARTER_RNG_TEXT, LockMode::LOCK_WHILE_RUNNING, false) , RUN_GIFT_RNG(RUN_GIFT_RNG_TEXT, LockMode::LOCK_WHILE_RUNNING, false) + , TAKE_MASTER_BALL(TAKE_MASTER_BALL_TEXT, LockMode::LOCK_WHILE_RUNNING, true) , NOTIFICATION_SHINY("Shiny found", true, true, ImageAttachmentMode::JPG, {"Notifs", "Showcase"}) , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) , KEEP_START_FRAME(KEEP_START_FRAME_TEXT, LockMode::LOCK_WHILE_RUNNING, false) @@ -156,6 +164,7 @@ AutoStory::AutoStory() PA_ADD_OPTION(STOP_FOR_STARTER_RNG); PA_ADD_OPTION(RUN_STARTER_RNG); PA_ADD_OPTION(RUN_GIFT_RNG); + PA_ADD_OPTION(TAKE_MASTER_BALL); PA_ADD_OPTION(RNG_PLAN); PA_ADD_OPTION(NOTIFICATIONS); } @@ -368,14 +377,10 @@ static void stop_for_handoff( SingleSwitchProgramEnvironment& env, EventNotificationOption& notification, const std::string& message, const std::vector& lines = {} ){ - env.console.log(message, COLOR_BLUE); - env.console.overlay().add_log(message); - std::string full = message; - for (const std::string& line : lines){ - env.console.log(line, COLOR_BLUE); - env.console.overlay().add_log(line); - full += "\n" + line; - } + const std::string full = Pokemon::report_rng_handoff_stop( + env.console, message, lines, + [&](const std::string& line){ env.console.overlay().add_log(line); } + ); send_program_finished_notification(env, notification, full); } @@ -573,18 +578,26 @@ static StarterRngLoopResult run_rng_plan_in_program( return result; } -// True for a shiny, on the target or not, with `message` logged; otherwise -// the run has stopped with it. -static bool shiny_or_stop( +// Runs `call` as `program`'s handoff. True for a shiny, on the target or +// not, with its summary logged; otherwise the run has stopped with the +// user's turn (a shiny is the only way the story goes on, so the rows after +// it are the caller's). +static bool run_handoff_to_shiny( SingleSwitchProgramEnvironment& env, EventNotificationOption& finished, - const StarterRngLoopResult& result, const std::string& message + const std::string& program, const Pokemon::RngHandoffCall& call ){ - if (result.end != StarterRngLoopEnd::SHINY && result.end != StarterRngLoopEnd::SHINY_OFF_TARGET){ - stop_for_handoff(env, finished, message); + Pokemon::RngHandoffResult result; + const std::optional user_turn = Pokemon::run_rng_handoff_or_user_turn( + env.console, program, [&]{ + result = call(); + return result; + } + ); + if (user_turn){ + stop_for_handoff(env, finished, *user_turn); return false; } - env.console.log(message, COLOR_BLUE); - env.console.overlay().add_log(message); + env.console.overlay().add_log(result.summary); return true; } @@ -603,8 +616,10 @@ static bool run_starter_rng_in_program( .language = language, .sound = options.SOUND, .calibration = calibration.calibration(calibration.STARTER_INGAME), }, notifications); CalibrationSavingSteps steps(console_steps, calibration, calibration.STARTER_INGAME); - const StarterRngLoopResult result = run_rng_plan_in_program(env, steps, planned, options); - return shiny_or_stop(env, finished, result, starter_rng_loop_message(result)); + return run_handoff_to_shiny(env, finished, "Starter RNG", [&]{ + const StarterRngLoopResult result = run_rng_plan_in_program(env, steps, planned, options); + return rng_handoff_result(result, starter_rng_loop_message(result)); + }); } // Gift RNG's attempts in the program for the language and gift of @@ -671,12 +686,16 @@ static void send_story_finished( send_program_finished_notification(env, finished, message); } +Pokemon::RngHandoffMode AutoStory::starter_rng_mode() const{ + return Pokemon::rng_handoff_mode({.stop = STOP_FOR_STARTER_RNG, .run = RUN_STARTER_RNG}); +} + StoryHandoffs AutoStory::story_handoffs() const{ // Running Starter RNG here splits 01.05 at the ball as its stop does, // and sets the SID at 01.01 when it isn't known. return StoryHandoffs{ .sid_helper = RUN_STARTER_RNG ? static_cast(RNG_PLAN.SID).empty() : bool(STOP_FOR_SID_HELPER), - .starter_rng = STOP_FOR_STARTER_RNG || RUN_STARTER_RNG, + .starter_rng = starter_rng_mode() != Pokemon::RngHandoffMode::OFF, .gift_rng = RUN_GIFT_RNG, }; } @@ -711,6 +730,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex StoryEnv story = story_env(env, context, checkpoints[first], RUN.check_level(), KEEP_START_FRAME); story.player_gender = PLAYER_GENDER; story.player_name = player_name; + story.take_master_ball = TAKE_MASTER_BALL; const bool at_gift_rng = plan.stop == StoryHandoff::GIFT_RNG && plan.rows.empty(); prepare_start(env, checkpoints, first, story, at_gift_rng); story.language = RUN.language(); @@ -778,7 +798,7 @@ std::optional AutoStory::after_starter_ball( SingleSwitchProgramEnvironment& env, ProControllerContext& context, StoryEnv& story, const StarterRngPlanned& planned, size_t ball_row ){ - if (!RUN_STARTER_RNG){ + if (starter_rng_mode() != Pokemon::RngHandoffMode::RUN){ stop_for_starter_rng(env, NOTIFICATION_PROGRAM_FINISH, RNG_PLAN.sound_name(), rng_attempt_lines(planned.attempts)); return std::nullopt; } @@ -801,10 +821,13 @@ std::optional AutoStory::after_gift_row( const GiftRngNotifications notifications{ .shiny = NOTIFICATION_SHINY, .status_update = NOTIFICATION_STATUS_UPDATE, .error_recoverable = NOTIFICATION_ERROR_RECOVERABLE, }; - const StarterRngLoopResult result = run_gift_rng_in_program(env, context, planned, RNG_PLAN, settings, notifications); // The live-start row after the gift's, which saves it (04.03, 09.04). const std::string& saving_row = story_checkpoints().at(gift_row + 1).id; - if (!shiny_or_stop(env, NOTIFICATION_PROGRAM_FINISH, result, gift_rng_loop_message(result, settings.target, saving_row))){ + const bool shiny = run_handoff_to_shiny(env, NOTIFICATION_PROGRAM_FINISH, "Gift RNG", [&]{ + const StarterRngLoopResult result = run_gift_rng_in_program(env, context, planned, RNG_PLAN, settings, notifications); + return rng_handoff_result(result, gift_rng_loop_message(result, settings.target, saving_row)); + }); + if (!shiny){ return std::nullopt; } return after_shiny_gift(env, story, gift_row, RUN.end_index(), story_handoffs()); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h index da0bf2d6e5..88c3cc811d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -19,6 +19,7 @@ #include "Common/Cpp/Options/StringOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "Pokemon/AutoStory/Pokemon_StoryRngHandoff.h" #include "Pokemon/Options/Pokemon_StoryRunOptions.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -49,6 +50,8 @@ class AutoStory : public SingleSwitchProgramInstance{ ) override{} private: + // The mode of Stop for Starter RNG and Run Starter RNG in AutoStory. + Pokemon::RngHandoffMode starter_rng_mode() const; // The RNG programs' handoffs the run takes, from the options. StoryHandoffs story_handoffs() const; // Runs `plan`'s rows, then the RNG handoff they stop at and, for a @@ -97,6 +100,9 @@ class AutoStory : public SingleSwitchProgramInstance{ // Runs Gift RNG's attempts in the program after 04.02 (the Magikarp) // and 09.03 (the Eevee). BooleanCheckBoxOption RUN_GIFT_RNG; + // Takes the Master Ball from Silph Co.'s president (16.05), unless the + // run is a SPEEDRUN. + BooleanCheckBoxOption TAKE_MASTER_BALL; StarterRngPlanOptions RNG_PLAN; EventNotificationOption NOTIFICATION_SHINY; EventNotificationOption NOTIFICATION_STATUS_UPDATE; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 18bc4398cf..5b5b61f831 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -138,7 +138,7 @@ OverworldInterruptSet walk_interrupts(StoryEnv& env, const StoryStep& step){ // `maps`: where the route is planned; the story's but where a step knows // better (the trash cans' walks, past trainers who have walked up). -Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step, const std::vector& maps = story_maps()){ +Outcome walk_route(StoryEnv& env, RunState& state, const StoryStep& step, const std::vector& maps){ const std::vector tiles = Pokemon::tiles_of(state.pose); const bool known = state.pose.certainty == Pokemon::PoseCertainty::TILE || (state.pose.certainty == Pokemon::PoseCertainty::SET && tiles.size() > 1); @@ -299,7 +299,7 @@ Outcome get_ready(StoryEnv& env, RunState& state, const StoryStep& step){ if (!nurse_before_battle(supplies)){ return Pokemon::outcome_ok(); } - Outcome walked = walk_route(env, state, step); + Outcome walked = walk_route(env, state, step, story_maps(state.flags)); if (!walked.succeeded()){ return walked; } @@ -320,24 +320,6 @@ const RouteCosts& story_route_costs(){ return COSTS; } -const std::vector& story_maps(){ - static const std::vector maps = []{ - const std::vector all = overworld_maps(); - std::set flags = map_flag_set(all, "after_hall_of_fame"); - flags.merge(map_flag_set(all, "new_game")); - // The one ball the story picks up in its way: B2F's MOON STONE - // blocks column 2 of the arrow floor (09.02's moon_stone). - flags.insert("FLAG_HIDE_ROCKET_HIDEOUT_B2F_MOON_STONE"); - // Route 16's Snorlax (31, 13), gone once 11.01 has played the POKE - // FLUTE and run: the routes after it go over its tile. None before - // it does (10.01 goes north by the Cut tree), and 11.01 walks up to - // it from the east. - flags.insert("FLAG_HIDE_ROUTE_16_SNORLAX"); - return overworld_maps(flags); - }(); - return maps; -} - Pokemon::Pose to_pose(const StoryPose& pose){ return Pokemon::tile_pose(pose.map, {pose.tile}, pose.facing); } @@ -504,7 +486,7 @@ bool talk_until_message(ConsoleHandle& console, ProControllerContext& context, c bool walked(StoryEnv& env, RunState& state, const StoryStep& step){ - const Outcome outcome = walk_route(env, state, step); + const Outcome outcome = walk_route(env, state, step, story_maps(state.flags)); if (outcome.succeeded() && outcome.pose){ state.pose = *outcome.pose; } @@ -735,7 +717,7 @@ ConsoleAction console_action_of(StoryActionId id){ return Pokemon::outcome_ok(); }; case StoryActionId::ROUTE: - return [](StoryEnv& env, RunState& state, const StoryStep& step){ return walk_route(env, state, step); }; + return [](StoryEnv& env, RunState& state, const StoryStep& step){ return walk_route(env, state, step, story_maps(state.flags)); }; case StoryActionId::LEGS: return walk_legs; case StoryActionId::STEP: @@ -798,6 +780,17 @@ Outcome StoryExecutor::run(const StoryStep& step, RunState& state){ return m_executor.run(step, state); } +bool StoryExecutor::master_ball_skipped(bool take_master_ball, Pokemon::StoryCheckLevel checks){ + return !take_master_ball || checks == Pokemon::StoryCheckLevel::SPEEDRUN; +} + +bool StoryExecutor::holds(std::string_view condition, RunState& state){ + if (condition == "master_ball_skipped"){ + return master_ball_skipped(m_env.take_master_ball, m_env.checks); + } + return Pokemon::StoryStepExecutor::holds(condition, state); +} + Pokemon::StoryAction StoryExecutor::console_action(StoryActionId id){ if (id == StoryActionId::OPTIONS){ return {.act = [this](const StoryStep&, RunState&){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index d03e617838..b0a608c070 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -93,6 +93,9 @@ struct StoryEnv{ // The Items pocket's counts a count_items step kept // (PokemonFRLG_AutoStorySlopeRun.h), for the next to compare. std::map counted_items = {}; + // The program's "Take the Master Ball" option: 16.05's talk with Silph + // Co.'s president (skip_if master_ball_skipped). + bool take_master_ball = true; }; // After a save is loaded for a checkpoint that starts on `start_map`: the @@ -136,6 +139,11 @@ class StoryExecutor : public Pokemon::StoryStepExecutor{ // The step's action from the table. virtual Pokemon::Outcome run(const StoryStep& step, Pokemon::RunState& state) override; + // The step condition master_ball_skipped: the program's option is off, or + // the run is a SPEEDRUN, where the Master Ball's few seconds are not spent. + static bool master_ball_skipped(bool take_master_ball, Pokemon::StoryCheckLevel checks); + // master_ball_skipped(); any other condition as the run's flags say. + virtual bool holds(std::string_view condition, Pokemon::RunState& state) override; private: // How the console does `id`. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp new file mode 100644 index 0000000000..fba551d3f9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp @@ -0,0 +1,56 @@ +/* AutoStory Paced Route + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_AutoStoryPacedRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// The story's maps, with the Rockets who leave once Silph Co. is cleared +// gone if `silph_cleared`. +std::vector make_story_maps(bool silph_cleared){ + const std::vector all = overworld_maps(); + std::set flags = map_flag_set(all, "after_hall_of_fame"); + flags.merge(map_flag_set(all, "new_game")); + // The one ball the story picks up in its way: B2F's MOON STONE + // blocks column 2 of the arrow floor (09.02's moon_stone). + flags.insert("FLAG_HIDE_ROCKET_HIDEOUT_B2F_MOON_STONE"); + // Route 16's Snorlax (31, 13), gone once 11.01 has played the POKE + // FLUTE and run: the routes after it go over its tile. None before + // it does (10.01 goes north by the Cut tree), and 11.01 walks up to + // it from the east. + flags.insert("FLAG_HIDE_ROUTE_16_SNORLAX"); + if (silph_cleared){ + // Giovanni's Rockets leave Silph Co. and Saffron City when he has + // lost on 11F (SilphCo_11F_EventScript_Giovanni sets both). + flags.insert("FLAG_HIDE_SILPH_ROCKETS"); + flags.insert("FLAG_HIDE_SAFFRON_ROCKETS"); + } + return overworld_maps(flags); +} + +} // namespace + +const std::vector& story_maps(const std::set& run_flags){ + if (run_flags.contains(std::string(SILPH_CLEARED_FLAG))){ + static const std::vector cleared = make_story_maps(true); + return cleared; + } + static const std::vector maps = make_story_maps(false); + return maps; +} + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h index 6fac86baf3..3c8f3f7e40 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h @@ -11,6 +11,9 @@ #define PokemonAutomation_PokemonFRLG_AutoStoryPacedRoute_H #include +#include +#include +#include #include #include "Pokemon/Navigation/Pokemon_GatedTypes.h" #include "Pokemon/Navigation/Pokemon_Grid.h" @@ -33,7 +36,13 @@ Pokemon::Pose paced_pose(const Pokemon::Pose& patch, const StoryStep& step); // the objects the game hides after the Hall of Fame removed, as the lab's // frlg_route does, and those a new game hides until their scene (the // S.S. Anne's rival on the Captain's door). -const std::vector& story_maps(); +// With `run_flags` (a run's, default none): without the Rockets once +// SILPH_CLEARED_FLAG is among them. +const std::vector& story_maps(const std::set& run_flags = {}); +// The run flag Giovanni's step on 11F sets: the story's maps from then on +// have no Rockets in Silph Co. or Saffron City (15.01 to 16.xx before it +// have them). +inline constexpr std::string_view SILPH_CLEARED_FLAG = "silph_cleared"; // default_route_costs() without Surf, which the story hasn't got yet: // routes stay on land, even where water is the shorter way (Vermilion // City's harbor). diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden16.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden16.h index 3381f705f2..dbbd30fe44 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden16.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden16.h @@ -32,6 +32,78 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN_16[] = { "16.01 walk west 3 (warp) -> SilphCo_3F (28, 2)", "16.01 walk south 4 -> SilphCo_3F (28, 6)", "16.01 walk west 23 -> SilphCo_3F (5, 6)", + "16.02 to_corridor from SilphCo_5F (15, 7) facing west to SilphCo_5F (12, 21) facing south", + "16.02 walk south 1 (to wall) -> SilphCo_5F (15, 8)", + "16.02 walk west 5 -> SilphCo_5F (10, 8)", + "16.02 walk south 12 (warp) -> SilphCo_9F (22, 18)", + "16.02 walk west 4 (to wall) -> SilphCo_9F (18, 18)", + "16.02 walk east 4 (warp) -> SilphCo_5F (10, 20)", + "16.02 walk east 2 (to wall) -> SilphCo_5F (12, 20)", + "16.02 walk south 1 (to wall) -> SilphCo_5F (12, 21)", + "16.03 to_3f_trainer from SilphCo_5F (21, 21) facing east to SilphCo_3F (22, 9) facing south", + "16.03 walk west 11 -> SilphCo_5F (10, 21)", + "16.03 walk north 1 (warp) -> SilphCo_9F (22, 18)", + "16.03 walk west 4 (to wall) -> SilphCo_9F (18, 18)", + "16.03 walk east 4 (warp) -> SilphCo_5F (10, 20)", + "16.03 walk north 12 -> SilphCo_5F (10, 8)", + "16.03 walk east 5 -> SilphCo_5F (15, 8)", + "16.03 walk north 1 (warp) -> SilphCo_3F (4, 6)", + "16.03 walk east 18 -> SilphCo_3F (22, 6)", + "16.03 walk south 3 -> SilphCo_3F (22, 9)", + "16.03 to_3f_door from SilphCo_3F (22, 9) facing south to SilphCo_3F (18, 13) facing west", + "16.03 walk south 4 -> SilphCo_3F (22, 13)", + "16.03 open gate west -> SilphCo_3F (22, 13)", + "16.03 walk west 4 (to wall) -> SilphCo_3F (18, 13)", + "16.03 to_3f_pad_row from SilphCo_3F (18, 13) facing west to SilphCo_3F (18, 14) facing south", + "16.03 walk south 1 -> SilphCo_3F (18, 14)", + "16.03 to_rival_trigger from SilphCo_3F (18, 14) facing south to SilphCo_7F (3, 4) facing west", + "16.03 walk west 5 (warp) -> SilphCo_7F (5, 4)", + "16.03 walk west 2 -> SilphCo_7F (3, 4)", + "16.03b to_lapras_guy from SilphCo_7F (2, 4) facing south to SilphCo_7F (1, 7) facing west", + "16.03b walk west 1 -> SilphCo_7F (1, 4)", + "16.03b walk south 3 -> SilphCo_7F (1, 7)", + "16.03b face west -> SilphCo_7F (1, 7)", + "16.05 to_left_wall from SilphCo_7F (1, 7) facing west to SilphCo_11F (0, 18) facing south", + "16.05 walk east 4 (to wall) -> SilphCo_7F (5, 7)", + "16.05 walk south 1 (warp) -> SilphCo_11F (2, 5)", + "16.05 walk west 2 (to wall) -> SilphCo_11F (0, 5)", + "16.05 walk south 13 -> SilphCo_11F (0, 18)", + "16.05 to_rocket_column from SilphCo_11F (0, 18) facing south to SilphCo_11F (2, 18) facing east", + "16.05 walk east 2 -> SilphCo_11F (2, 18)", + "16.05 to_giovanni_door from SilphCo_11F (2, 18) facing east to SilphCo_11F (5, 16) facing north", + "16.05 walk east 3 -> SilphCo_11F (5, 18)", + "16.05 open gate north -> SilphCo_11F (5, 18)", + "16.05 walk north 2 -> SilphCo_11F (5, 16)", + "16.05 below_president from SilphCo_11F (5, 15) facing north to SilphCo_11F (9, 10) facing north", + "16.05 walk north 5 -> SilphCo_11F (5, 10)", + "16.05 walk east 4 -> SilphCo_11F (9, 10)", + "16.05 face north -> SilphCo_11F (9, 10)", + "16.06 below_center_door from SilphCo_11F (9, 10) facing north to SaffronCity (24, 39) facing north", + "16.06 walk west 4 (to wall) -> SilphCo_11F (5, 10)", + "16.06 walk south 9 (to wall) -> SilphCo_11F (5, 19)", + "16.06 walk west 3 -> SilphCo_11F (2, 19)", + "16.06 walk north 14 (warp) -> SilphCo_7F (5, 8)", + "16.06 walk north 1 (to wall) -> SilphCo_7F (5, 7)", + "16.06 walk west 4 -> SilphCo_7F (1, 7)", + "16.06 walk north 3 (to wall) -> SilphCo_7F (1, 4)", + "16.06 walk east 4 (warp) -> SilphCo_3F (13, 14)", + "16.06 walk east 6 (to wall) -> SilphCo_3F (19, 14)", + "16.06 walk north 2 -> SilphCo_3F (19, 12)", + "16.06 walk east 6 -> SilphCo_3F (25, 12)", + "16.06 walk north 8 (to wall) -> SilphCo_3F (25, 4)", + "16.06 walk east 3 -> SilphCo_3F (28, 4)", + "16.06 walk north 2 (to wall) -> SilphCo_3F (28, 2)", + "16.06 walk west 1 (warp) -> SilphCo_2F (28, 2)", + "16.06 walk east 3 (warp) -> SilphCo_1F (31, 2)", + "16.06 walk west 1 (to wall) -> SilphCo_1F (30, 2)", + "16.06 walk south 5 (to wall) -> SilphCo_1F (30, 7)", + "16.06 walk west 22 -> SilphCo_1F (8, 7)", + "16.06 walk south 14 (warp) -> SaffronCity (33, 31)", + "16.06 walk south 3 (to wall) -> SaffronCity (33, 34)", + "16.06 walk west 18 (to wall) -> SaffronCity (15, 34)", + "16.06 walk south 5 -> SaffronCity (15, 39)", + "16.06 walk east 9 -> SaffronCity (24, 39)", + "16.06 face north -> SaffronCity (24, 39)", }; } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp index c426201c9b..94b9a73eff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.cpp @@ -32,6 +32,8 @@ std::string_view gift_name(PokemonFRLG_RngTarget gift){ return "Magikarp"; case PokemonFRLG_RngTarget::eevee: return "Eevee"; + case PokemonFRLG_RngTarget::lapras: + return "Lapras"; default: return "gift"; } @@ -108,6 +110,15 @@ std::string gift_rng_loop_message(const StarterRngLoopResult& result, PokemonFRL } +Pokemon::RngHandoffResult rng_handoff_result(const StarterRngLoopResult& result, std::string message){ + if (result.end == StarterRngLoopEnd::SHINY || result.end == StarterRngLoopEnd::SHINY_OFF_TARGET){ + return Pokemon::RngHandoffResult{.summary = std::move(message)}; + } + return Pokemon::RngHandoffResult{.user_turn = std::move(message)}; +} + + + CalibrationSavingSteps::CalibrationSavingSteps( StarterRngLoopSteps& steps, RngStopCalibrationOptions& calibration, FloatingPointOption& ingame ) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h index 2a59ca7449..18a6ce6bd3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h @@ -18,6 +18,7 @@ #include #include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Pokemon_StoryRngHandoff.h" #include "VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_BlindNavigation.h" #include "VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngPlan.h" #include "VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRngLoop.h" @@ -41,6 +42,13 @@ std::string starter_rng_loop_message(const StarterRngLoopResult& result); // live-start row `row` (04.03, 09.04) saves after a shiny. std::string gift_rng_loop_message(const StarterRngLoopResult& result, PokemonFRLG_RngTarget gift, std::string_view row); +// The loop's end as the shared RNG handoff takes it (Pokemon_StoryRngHandoff.h). +// A shiny, on the target or not, is a success: the game is on its summary and the +// run goes on, with the rows rows_after_*_rng() give, which the caller runs. Every other +// end is the user's turn, with the message, not a failure: nothing here is an error. +// `message` is starter_rng_loop_message() or gift_rng_loop_message() for `result`. +Pokemon::RngHandoffResult rng_handoff_result(const StarterRngLoopResult& result, std::string message); + // `steps`, with the calibration of each reset also kept in the RNG plan's // calibration, with `ingame` as the stop's in-game advances offset, so the diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp index 59d80c9975..8670975d61 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop_Tests.cpp @@ -208,6 +208,41 @@ UnitTestResult test_gift_messages(){ return true; } +// The shared handoff takes a shiny as the story going on and every other end +// as the user's turn with the loop's message, never as a failure. +UnitTestResult test_handoff_results(){ + struct Case{ + StarterRngLoopEnd end; + bool shiny; + }; + const std::vector cases = { + {StarterRngLoopEnd::SHINY, true}, + {StarterRngLoopEnd::SHINY_OFF_TARGET, true}, + {StarterRngLoopEnd::TARGET, false}, + {StarterRngLoopEnd::OUT_OF_ATTEMPTS, false}, + {StarterRngLoopEnd::MISSED_EVERY_ATTEMPT_LEFT, false}, + {StarterRngLoopEnd::OUT_OF_TIME, false}, + }; + for (const Case& item : cases){ + const StarterRngLoopResult loop{.end = item.end, .attempts_run = 2, .remaining_sids = {300}, .sid = std::nullopt}; + const std::string starter_message = starter_rng_loop_message(loop); + const std::string gift_message = gift_rng_loop_message(loop, PokemonFRLG_RngTarget::eevee, "09.04"); + const Pokemon::RngHandoffResult starter = rng_handoff_result(loop, starter_message); + const Pokemon::RngHandoffResult gift = rng_handoff_result(loop, gift_message); + const std::string& starter_text = item.shiny ? starter.summary : starter.user_turn; + const std::string& gift_text = item.shiny ? gift.summary : gift.user_turn; + const std::string& starter_other = item.shiny ? starter.user_turn : starter.summary; + const std::string& gift_other = item.shiny ? gift.user_turn : gift.summary; + if (!starter.succeeded() || !gift.succeeded()){ + return std::format("End {}: a loop end is never a failure.", int(item.end)); + } + if (starter_text != starter_message || gift_text != gift_message || !starter_other.empty() || !gift_other.empty()){ + return std::format("End {}: expected the message as the {}.", int(item.end), item.shiny ? "summary" : "user's turn"); + } + } + return true; +} + // 04.02 saves facing the salesman for Gift RNG; after a shiny Magikarp, // 04.03 leaves its summary and saves there, then the run goes on. UnitTestResult test_rows_after_magikarp(){ @@ -375,6 +410,10 @@ const AutoStoryRngLoopTestCase AUTO_STORY_RNG_LOOP_CASES[] = { .input = {.name = "04.02 and 04.03: rows after a shiny Magikarp", .body = test_rows_after_magikarp}, .expectation = {.description = "plans continuation rows following shiny magikarp"}, }, + { + .input = {.name = "Loop ends as RNG handoff results", .body = test_handoff_results}, + .expectation = {.description = "a shiny continues; every other end is the user's turn"}, + }, { .input = {.name = "Gift RNG outcomes in the RNG plan", .body = test_gift_outcomes}, .expectation = {.description = "handles gift rng outcomes in plan"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index f5a138d6a9..56270cfacc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -491,7 +491,7 @@ std::string OverworldStepSim::walk(const StoryStep& step){ // which the walker's steps open. const std::vector& maps = story_maps(); const Pokemon::GateState& gates = m_sim.state().gates; - const std::optional> route = walked_route(m_at, step, maps, gates, Pokemon::GateRules{.card_key_held = m_sim.state().card_key_held}); + const std::optional> route = walked_route(m_at, step, maps, gates, Pokemon::GateRules{.card_key_held = m_sim.card_key_held()}); if (route && route->empty()){ // Already there. return ""; @@ -752,6 +752,11 @@ std::string row_step_on_sim(OverworldSim& sim, StoryPose& at, const StoryStep& s const Outcome outcome = executor.run(step, state); at = executor.at(); if (outcome.succeeded()){ + // The step that picks the Card Key up (flags_after) opens the doors the + // next ones walk to. + if (std::find(step.flags_after.begin(), step.flags_after.end(), "card_key_held") != step.flags_after.end()){ + sim.give_card_key(); + } return ""; } return id + "/" + step.name + ": " + outcome.detail + " On " + to_string(sim.state().position) + "."; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows16_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows16_Tests.h index c5a7d77654..5507d2528c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows16_Tests.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows16_Tests.h @@ -17,7 +17,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Row 16.01, Silph Co., on the overworld sim (PokemonFRLG_AutoStorySilph_Tests.cpp). +// Rows 16.01 to 16.03b, Silph Co., on the overworld sim (PokemonFRLG_AutoStorySilph_Tests.cpp). void add_tests_AutoStorySilph(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp index 436a867179..1be11dd057 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp @@ -145,7 +145,7 @@ class Test_RunPlan : public UnitTest{ const RunPlanScenario m_scenario; }; -const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01"; +const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 16.02 16.03 16.03b 16.05 16.06"; const RunPlanScenario RUN_PLAN_CASES[] = { { @@ -236,11 +236,11 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Gift RNG off: 04.03 is passed over", .first = "04.01"}, - .expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01"}, + .expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 16.02 16.03 16.03b 16.05 16.06"}, }, { .input = {.name = "Gift RNG off: 04.03 runs when started at", .first = "04.03"}, - .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01"}, + .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 16.02 16.03 16.03b 16.05 16.06"}, }, { .input = { .name = "Gift RNG: started at 04.03, from the save beside the salesman", @@ -279,7 +279,7 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Starter RNG alone: 04.03 runs when started at", .first = "04.03", .handoffs = {.starter_rng = true}}, - .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01"}, + .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 16.02 16.03 16.03b 16.05 16.06"}, }, { .input = { .name = "Starter RNG first, with both on", @@ -347,9 +347,9 @@ UnitTestResult test_after_sid_helper_row(){ return "Expected 01.01 to be SID Helper's handoff and 01.02 to start from the live game."; } for (const StoryCheckpoint& checkpoint : story_checkpoints()){ - const bool live = checkpoint.id == "01.02" || checkpoint.id == "04.03" || checkpoint.id == "09.04"; + const bool live = checkpoint.id == "01.02" || checkpoint.id == "04.03" || checkpoint.id == "09.04" || checkpoint.id == "16.04"; if (checkpoint.live_start != live){ - return checkpoint.id + ": only 01.02, 04.03 and 09.04 start from the live game."; + return checkpoint.id + ": only 01.02, 04.03, 09.04 and 16.04 start from the live game."; } } return true; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp index d5ccb81d4d..16aa09eab2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp @@ -1,124 +1,450 @@ -/* AutoStory Silph Tests - * - * From: https://github.com/PokemonAutomation/ - * - * Row 16.01 (StoryData/frlg-16.01.plan.json) on the overworld sim: from - * Saffron's nurse into Silph Co., up to 3F and through its pad to 5F. - * - */ - -#include -#include -#include -#include -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" -#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" -#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" -#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" -#include "PokemonFRLG_AutoStoryEvents.h" -#include "PokemonFRLG_AutoStoryRooms.h" -#include "PokemonFRLG_AutoStoryRowSim.h" -#include "PokemonFRLG_AutoStoryRows_Tests.h" -#include "PokemonFRLG_AutoStoryRows16_Tests.h" -#include "PokemonFRLG_AutoStoryTable.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -namespace{ - -struct AutoStorySilphInput{ - std::string name; - std::function body; -}; - -struct AutoStorySilphExpectation{ - std::string_view description; -}; - -struct AutoStorySilphCase{ - AutoStorySilphInput input; - AutoStorySilphExpectation expectation; -}; - -class Test_AutoStorySilph : public UnitTest{ -public: - explicit Test_AutoStorySilph(AutoStorySilphCase test_case) - : UnitTest(std::format("PokemonFRLG::AutoStory - Simulation: {}", test_case.input.name)) - , m_case(std::move(test_case)) - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - try{ - return m_case.input.body(); - }catch (Exception& e){ - return std::format("{}: {}", e.name(), e.message()); - } - } - -private: - AutoStorySilphCase m_case; -}; - -const StoryCheckpoint& checkpoint(std::string_view id){ - for (const StoryCheckpoint& row : story_checkpoints()){ - if (row.id == id){ - return row; - } - } - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No checkpoint {}.", id)); -} - -// 16.01 on the sim from Saffron's nurse: Silph Co.'s stairs to 3F, west -// along the hall and onto the pad to 5F, where the player stands on the pad -// that leads back. No trainer is met and no rule is broken. -UnitTestResult test_pad_to_5f(){ - const StoryCheckpoint& row = checkpoint("16.01"); - StoryPose at = *story_pose(Pokemon::pose_of(*row.start)); - OverworldSim sim(story_maps(), MapPosition{at.map, at.tile}, *at.facing); - std::vector floors; - for (const StoryStep& step : row.steps){ - if (const std::string failure = row_step_on_sim(sim, at, step, row.id); !failure.empty()){ - return std::format("16.01: ended on {}; {}", to_string(sim.state().position), failure); - } - floors.push_back(sim.state().position.map); - } - const MapPosition pad{"SilphCo_5F", {15, 7}}; - if (!(sim.state().position == pad)){ - return std::format("16.01: ended on {}, not on 5F's pad {}.", to_string(sim.state().position), to_string(pad)); - } - if (floors != std::vector{"SilphCo_3F", "SilphCo_5F"}){ - return "16.01: the steps ended on the wrong floors."; - } - if (!sim.state().trainers_beaten.empty() || !sim.state().violations.empty()){ - return "16.01: met a trainer or broke a rule on the way."; - } - return true; -} - -const AutoStorySilphCase AUTO_STORY_SILPH_CASES[] = { - { - .input = {.name = "16.01 Silph Co.'s stairs to 3F and its pad to 5F", .body = test_pad_to_5f}, - .expectation = {.description = "to 3F's pad (4, 6), onto 5F's (15, 7), nobody met"}, - }, -}; - -} // namespace - - -void add_tests_AutoStorySilph(UnitTestDatabase& database){ - for (const auto& item : AUTO_STORY_SILPH_CASES){ - database.add(item); - } -} - - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation +/* AutoStory Silph Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Rows 16.01 to 16.06 (StoryData/frlg-16.01.plan.json ...) on the overworld sim: from + * Saffron's nurse into Silph Co., up to 3F and through its pad to 5F. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGatedRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryRooms.h" +#include "PokemonFRLG_AutoStoryRowSim.h" +#include "PokemonFRLG_AutoStoryRows_Tests.h" +#include "PokemonFRLG_AutoStoryRows16_Tests.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +struct AutoStorySilphInput{ + std::string name; + std::function body; +}; + +struct AutoStorySilphExpectation{ + std::string_view description; +}; + +struct AutoStorySilphCase{ + AutoStorySilphInput input; + AutoStorySilphExpectation expectation; +}; + +class Test_AutoStorySilph : public UnitTest{ +public: + explicit Test_AutoStorySilph(AutoStorySilphCase test_case) + : UnitTest(std::format("PokemonFRLG::AutoStory - Simulation: {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_case.input.body(); + }catch (Exception& e){ + return std::format("{}: {}", e.name(), e.message()); + } + } + +private: + AutoStorySilphCase m_case; +}; + +const StoryCheckpoint& checkpoint(std::string_view id){ + for (const StoryCheckpoint& row : story_checkpoints()){ + if (row.id == id){ + return row; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No checkpoint {}.", id)); +} + +// 16.01 on the sim from Saffron's nurse: Silph Co.'s stairs to 3F, west +// along the hall and onto the pad to 5F, where the player stands on the pad +// that leads back. No trainer is met and no rule is broken. +UnitTestResult test_pad_to_5f(){ + const StoryCheckpoint& row = checkpoint("16.01"); + StoryPose at = *story_pose(Pokemon::pose_of(*row.start)); + OverworldSim sim(story_maps(), MapPosition{at.map, at.tile}, *at.facing); + std::vector floors; + for (const StoryStep& step : row.steps){ + if (const std::string failure = row_step_on_sim(sim, at, step, row.id); !failure.empty()){ + return std::format("16.01: ended on {}; {}", to_string(sim.state().position), failure); + } + floors.push_back(sim.state().position.map); + } + const MapPosition pad{"SilphCo_5F", {15, 7}}; + if (!(sim.state().position == pad)){ + return std::format("16.01: ended on {}, not on 5F's pad {}.", to_string(sim.state().position), to_string(pad)); + } + if (floors != std::vector{"SilphCo_3F", "SilphCo_5F"}){ + return "16.01: the steps ended on the wrong floors."; + } + if (!sim.state().trainers_beaten.empty() || !sim.state().violations.empty()){ + return "16.01: met a trainer or broke a rule on the way."; + } + return true; +} + +// The steps of row `id` walked on the sim over `maps`, from the row's start with +// the Card Key and doors its start_flags and start_gates say. +class RowWalk{ +public: + RowWalk(std::string_view id, const std::vector& maps) + : m_row(checkpoint(id)) + , m_at(*story_pose(Pokemon::pose_of(*m_row.start))) + , m_sim(maps, MapPosition{m_at.map, m_at.tile}, *m_at.facing, script_of(m_row)) + {} + + // Each step in turn; the failure of the first that fails, or empty. + std::string run(){ + for (const StoryStep& step : m_row.steps){ + // The sim has no trigger scenes: a scripted battle (the rival's, Giovanni's) + // is taken as won where it leaves the player. + if (step.kind == StoryStepKind::BATTLE){ + m_at = *story_pose(Pokemon::pose_of(*step.pose_after)); + m_floors.push_back(m_sim.state().position.map); + continue; + } + if (const std::string failure = row_step_on_sim(m_sim, m_at, step, m_row.id); !failure.empty()){ + return failure; + } + m_floors.push_back(m_sim.state().position.map); + } + return ""; + } + const StoryCheckpoint& row() const{ return m_row; } + const OverworldSim& sim() const{ return m_sim; } + const std::vector& floors() const{ return m_floors; } + + // What the row left out as a line, or empty: the sim's rule breaks and the + // trainers it fought, and the gates it has open against the ones the row's + // steps declare (gates_after). + std::string problems() const{ + std::string text; + if (!m_sim.state().violations.empty()){ + text += std::format(" broke a rule: {};", m_sim.state().violations.front()); + } + const Pokemon::GateState declared = Pokemon::checkpoint_gates(m_row, m_row.steps.size()); + if (!(declared == m_sim.state().gates)){ + text += std::format(" the sim has {} gates open, the row's gates_after {};", m_sim.state().gates.opened.size(), declared.opened.size()); + } + return text; + } + +private: + static SimScript script_of(const StoryCheckpoint& row){ + SimScript script; + script.card_key_held = std::find(row.start_flags.begin(), row.start_flags.end(), "card_key_held") != row.start_flags.end(); + script.gates = row.start_gates.value_or(Pokemon::GateState()); + return script; + } + + const StoryCheckpoint& m_row; + StoryPose m_at; + OverworldSim m_sim; + std::vector m_floors; +}; + +std::string opened_doors(const OverworldSim& sim){ + std::string text; + for (const std::string& key : sim.state().gates.opened){ + text += " " + key; + } + return text; +} + +// `maps` with the trainer at `at` on `map_name` beaten (his sight is gone, as in a +// save made after his fight). +std::vector with_beaten(std::vector maps, std::string_view map_name, int x, int y){ + for (MapData& map : maps){ + for (MapObject& object : map.objects){ + if (map.name == map_name && object.x == x && object.y == y){ + object.trainer.reset(); + } + } + } + return maps; +} + +// The maps a row after 16.02 starts on: the Rocket at 5F's (9, 21), beaten by +// 16.02 on its way, no longer sees the player (his fight is in the save). +std::vector maps_after_16_02(){ + return with_beaten(story_maps(), "SilphCo_5F", 9, 21); +} + +// Row `id` walked on the sim: the steps run, no rule broken, the gates the +// row declares open, and the Card Key held or not as `card_key` says. The +// trainers it fought and the tile it ends on are returned for the caller. +struct RowResult{ + std::string failure; + std::vector trainers; + std::vector floors; + MapPosition end; + bool card_key = false; +}; +RowResult walk_row(std::string_view id, const std::vector& maps){ + RowWalk walk(id, maps); + RowResult out; + out.failure = walk.run(); + if (out.failure.empty()){ + out.failure = walk.problems(); + } + out.trainers = walk.sim().state().trainers_beaten; + out.floors = walk.floors(); + out.end = walk.sim().state().position; + out.card_key = walk.sim().card_key_held(); + return out; +} + +std::string wrong_end(std::string_view id, const RowResult& result, const MapPosition& want){ + if (!result.failure.empty()){ + return std::format("{}: ended on {}; {}", id, to_string(result.end), result.failure); + } + if (!(result.end == want)){ + return std::format("{}: ended on {}, not {}.", id, to_string(result.end), to_string(want)); + } + return ""; +} + +// 16.02: 5F's pad to 9F and back by the loop to the corridor, east to the +// ball with the CARD KEY (21, 21); the scientist on the way fights. +UnitTestResult test_card_key_row(){ + const RowResult result = walk_row("16.02", story_maps()); + if (const std::string wrong = wrong_end("16.02", result, MapPosition{"SilphCo_5F", {21, 21}}); !wrong.empty()){ + return wrong; + } + if (!result.card_key){ + return "16.02: the Card Key was not picked up."; + } + if (result.trainers != std::vector{"scientist", "rocket_m"}){ + return "16.02: did not fight just the scientist and the Rocket on 5F."; + } + return true; +} + +// 16.03: up to 7F by 3F's Card Key door (opened with the key), the rival on +// his trigger, where his battle leaves the player; then 16.03b to the +// employee with the Lapras. +UnitTestResult test_rival_row(){ + const RowResult result = walk_row("16.03", maps_after_16_02()); + if (const std::string wrong = wrong_end("16.03", result, MapPosition{"SilphCo_7F", {2, 4}}); !wrong.empty()){ + return wrong; + } + const StoryPose after_rival = *story_pose(Pokemon::pose_of(*checkpoint("16.03b").start)); + if (after_rival.map != "SilphCo_7F" || !(after_rival.tile == MapPosition{"SilphCo_7F", {2, 4}}.point)){ + return "16.03b doesn't start where 16.03 ends."; + } + const RowResult to_employee = walk_row("16.03b", maps_after_16_02()); + if (const std::string wrong = wrong_end("16.03b", to_employee, MapPosition{"SilphCo_7F", {1, 7}}); !wrong.empty()){ + return wrong; + } + const std::vector floors_have = {"SilphCo_3F", "SilphCo_7F"}; + for (const std::string& floor : floors_have){ + if (std::find(result.floors.begin(), result.floors.end(), floor) == result.floors.end()){ + return "16.03: the steps never reached " + floor + "."; + } + } + return true; +} + +// 16.03b's checkpoint: Gift RNG's Lapras, on 7F beside the employee. +UnitTestResult test_lapras_handoff(){ + const StoryCheckpoint& gift = checkpoint("16.03b"); + if (gift.handoff != StoryHandoff::GIFT_RNG || gift.gift != PokemonFRLG_RngTarget::lapras){ + return "16.03b does not hand off to Gift RNG for the Lapras."; + } + if (checkpoint("16.03").handoff != StoryHandoff::NONE){ + return "16.03 hands off to Gift RNG; only 16.03b, beside the employee, does."; + } + const StoryCheckpoint& live = checkpoint("16.04"); + if (!live.live_start || live.handoff != StoryHandoff::NONE){ + return "16.04 is not the save Gift RNG leaves."; + } + return true; +} + +// 16.04 runs one step, the summary Gift RNG leaves open; 16.05 starts where it does. +UnitTestResult test_after_gift_row(){ + const RowResult result = walk_row("16.04", maps_after_16_02()); + const std::string wrong = wrong_end("16.04", result, MapPosition{"SilphCo_7F", {1, 7}}); + if (!wrong.empty()){ + return wrong; + } + return true; +} + +// 16.05: the pad to 11F, down its left wall out of the Rocket's column, the +// Rocket beside the player (his fight), the Card Key door and Giovanni's +// trigger, then to the president. +UnitTestResult test_giovanni_row(){ + const RowResult result = walk_row("16.05", maps_after_16_02()); + if (const std::string wrong = wrong_end("16.05", result, MapPosition{"SilphCo_11F", {9, 10}}); !wrong.empty()){ + return wrong; + } + if (result.trainers.size() != size_t(1)){ + return "16.05: the Rocket at (2, 19) did not fight alone."; + } + return true; +} + +// 16.06: the walk back down to Saffron's Center on the maps with no Rocket in +// Silph Co. or Saffron City. +UnitTestResult test_return_row(){ + const std::set flags{std::string(SILPH_CLEARED_FLAG)}; + const RowResult result = walk_row("16.06", with_beaten(story_maps(flags), "SilphCo_5F", 9, 21)); + if (const std::string wrong = wrong_end("16.06", result, MapPosition{"SaffronCity", {24, 39}}); !wrong.empty()){ + return wrong; + } + if (!result.trainers.empty()){ + return "16.06: walked into a trainer's line."; + } + return true; +} + +bool has_object_at(const std::vector& maps, std::string_view map_name, int x, int y){ + for (const MapData& map : maps){ + for (const MapObject& object : map.objects){ + if (map.name == map_name && object.x == x && object.y == y){ + return true; + } + } + } + return false; +} + +// The Rocket at Saffron (46, 13) blocks the Gym's door until the story sets +// silph_cleared (16.05's Giovanni); the maps of 15.01 and 16.01 keep him. +UnitTestResult test_saffron_rocket_removed(){ + if (!has_object_at(story_maps(), "SaffronCity", 46, 13)){ + return "No Rocket at Saffron (46, 13) before Silph Co. is cleared."; + } + if (!has_object_at(story_maps({"card_key_held"}), "SaffronCity", 46, 13)){ + return "Another flag hides the Rocket at Saffron (46, 13)."; + } + if (has_object_at(story_maps({std::string(SILPH_CLEARED_FLAG)}), "SaffronCity", 46, 13)){ + return "A Rocket still stands at Saffron (46, 13) after Silph Co."; + } + return true; +} + +// silph_cleared is set by the Giovanni step, nothing earlier. +UnitTestResult test_silph_cleared_flag(){ + for (const std::string_view id : {"16.01", "16.02", "16.03", "16.03b", "16.04"}){ + for (const StoryStep& step : checkpoint(id).steps){ + if (std::find(step.flags_after.begin(), step.flags_after.end(), SILPH_CLEARED_FLAG) != step.flags_after.end()){ + return std::format("{} sets silph_cleared.", id); + } + } + } + const StoryCheckpoint& row = checkpoint("16.05"); + const bool set = std::any_of(row.steps.begin(), row.steps.end(), [](const StoryStep& step){ + return step.name == "giovanni" && std::find(step.flags_after.begin(), step.flags_after.end(), SILPH_CLEARED_FLAG) != step.flags_after.end(); + }); + if (!set){ + return "16.05's Giovanni step does not set silph_cleared."; + } + const std::vector& start = checkpoint("16.06").start_flags; + if (std::find(start.begin(), start.end(), SILPH_CLEARED_FLAG) == start.end()){ + return "16.06 does not start with silph_cleared."; + } + return true; +} + +// The president's Master Ball is skipped by the option or a SPEEDRUN, taken otherwise. +UnitTestResult test_master_ball_option(){ + using Pokemon::StoryCheckLevel; + if (StoryExecutor::master_ball_skipped(true, StoryCheckLevel::DEFAULT)){ + return "The Master Ball is skipped with the option on."; + } + if (!StoryExecutor::master_ball_skipped(false, StoryCheckLevel::DEFAULT)){ + return "The Master Ball is taken with the option off."; + } + if (!StoryExecutor::master_ball_skipped(true, StoryCheckLevel::SPEEDRUN)){ + return "The Master Ball is taken in a SPEEDRUN."; + } + const StoryCheckpoint& row = checkpoint("16.05"); + const bool skippable = std::any_of(row.steps.begin(), row.steps.end(), [](const StoryStep& step){ + return step.name == "master_ball" && step.skip_if == std::vector{"master_ball_skipped"}; + }); + if (!skippable){ + return "16.05's master_ball step is not skip_if master_ball_skipped."; + } + return true; +} + +const AutoStorySilphCase AUTO_STORY_SILPH_CASES[] = { + { + .input = {.name = "16.01 Silph Co.'s stairs to 3F and its pad to 5F", .body = test_pad_to_5f}, + .expectation = {.description = "to 3F's pad (4, 6), onto 5F's (15, 7), nobody met"}, + }, + { + .input = {.name = "16.02 the pad loop on 5F to the Card Key", .body = test_card_key_row}, + .expectation = {.description = "ends at (21, 21) with the key, the scientist and a Rocket fought"}, + }, + { + .input = {.name = "16.03 3F's Card Key door, the pad to 7F and the rival; 16.03b to the employee", .body = test_rival_row}, + .expectation = {.description = "opens 3F's door_2, ends by the employee on 7F"}, + }, + { + .input = {.name = "16.03b/16.04 the Lapras by Gift RNG", .body = test_lapras_handoff}, + .expectation = {.description = "16.03b hands off to Gift RNG for a Lapras; 16.04 is the live save"}, + }, + { + .input = {.name = "16.04 the save after Gift RNG", .body = test_after_gift_row}, + .expectation = {.description = "one step, still beside the employee"}, + }, + { + .input = {.name = "16.05 11F's Card Key door and Giovanni", .body = test_giovanni_row}, + .expectation = {.description = "one Rocket fought, 11F's door opened, ends below the president"}, + }, + { + .input = {.name = "16.06 back to Saffron's Center with no Rockets", .body = test_return_row}, + .expectation = {.description = "no trainer met, ends below the Center's door"}, + }, + { + .input = {.name = "the Saffron Rocket is gone after Silph Co.", .body = test_saffron_rocket_removed}, + .expectation = {.description = "present for no flags, hidden by silph_cleared"}, + }, + { + .input = {.name = "silph_cleared is set by the Giovanni step", .body = test_silph_cleared_flag}, + .expectation = {.description = "16.05's giovanni sets it; 16.06 starts with it"}, + }, + { + .input = {.name = "the Master Ball option and SPEEDRUN", .body = test_master_ball_option}, + .expectation = {.description = "skipped when the option is off or in a SPEEDRUN"}, + }, +}; + +} // namespace + + +void add_tests_AutoStorySilph(UnitTestDatabase& database){ + for (const auto& item : AUTO_STORY_SILPH_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 9108463dc5..2bd72c07ed 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -62,6 +62,9 @@ PokemonFRLG_RngTarget read_gift(std::string_view name, std::string_view source){ if (name == "eevee"){ return PokemonFRLG_RngTarget::eevee; } + if (name == "lapras"){ + return PokemonFRLG_RngTarget::lapras; + } throw ParseException(std::format("{}: unknown gift {}", source, name)); } @@ -236,7 +239,7 @@ constexpr std::string_view STORY_ORDER[] = { "09.04", "10.01", "10.02", "10.03", "10.04", "10.05", "10.06", "11.01", "11.02", "11.03", "12.01", "12.02", "12.02b", "12.03", "13.01", "13.02", "13.03", "13.04", "14.01", "14.02", "14.02b", - "14.03", "14.04", "14.04b", "15.01", "16.01", + "14.03", "14.04", "14.04b", "15.01", "16.01", "16.02", "16.03", "16.03b", "16.04", "16.05", "16.06", }; // `checkpoints` in STORY_ORDER's order. Throws ParseException for a diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index ecd536bdb6..d2cc81f229 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -87,15 +87,6 @@ class Test_AutoStory : public UnitTest{ AutoStoryTestCase m_scenario; }; -const MapData* find_map_named(const std::string& name){ - for (const MapData& map : story_maps()){ - if (map.name == name){ - return ↦ - } - } - return nullptr; -} - // The gates the walk the test is following has opened and the switches it // has pressed, and whether it holds the Card Key: what the story's steps // carry through a checkpoint (start_gates, gates_after, flags_after). Each @@ -103,6 +94,8 @@ const MapData* find_map_named(const std::string& name){ struct WalkGates{ Pokemon::GateState gates; bool card_key_held = false; + // The run flags the walk has set (silph_cleared takes the Rockets off the maps). + std::set run_flags; }; WalkGates& walk_state(){ thread_local WalkGates walk; @@ -116,6 +109,7 @@ void begin_walk(const StoryCheckpoint& checkpoint){ walk_state().gates = *checkpoint.start_gates; } walk_state().card_key_held = std::ranges::find(checkpoint.start_flags, "card_key_held") != checkpoint.start_flags.end(); + walk_state().run_flags.insert(checkpoint.start_flags.begin(), checkpoint.start_flags.end()); } // A walk through the checkpoint that follows the one before: only what its @@ -127,6 +121,7 @@ void continue_walk(const StoryCheckpoint& checkpoint){ if (std::ranges::find(checkpoint.start_flags, "card_key_held") != checkpoint.start_flags.end()){ walk_state().card_key_held = true; } + walk_state().run_flags.insert(checkpoint.start_flags.begin(), checkpoint.start_flags.end()); } // What `step` does to the walk's gates once done, besides a route's own. @@ -137,18 +132,36 @@ void apply_step_effects(const StoryStep& step){ if (std::ranges::find(step.flags_after, "card_key_held") != step.flags_after.end()){ walk_state().card_key_held = true; } + walk_state().run_flags.insert(step.flags_after.begin(), step.flags_after.end()); +} + +// The story's maps as the walk's flags make them. +const std::vector& walk_story_maps(){ + return story_maps(walk_state().run_flags); +} + +const MapData* find_map_named(const std::string& name){ + for (const MapData& map : walk_story_maps()){ + if (map.name == name){ + return ↦ + } + } + return nullptr; } // The story's maps as the walk's gates make them. const std::vector& walk_maps(){ - thread_local std::optional>> resolved; - if (!has_gates(story_maps())){ - return story_maps(); + // The gates and the maps (the flags' ones) the cached maps were resolved for. + thread_local std::optional*>> resolved_for; + thread_local std::vector resolved; + if (!has_gates(walk_story_maps())){ + return walk_story_maps(); } - if (!resolved || !(resolved->first == walk_state().gates)){ - resolved.emplace(walk_state().gates, resolve_maps(story_maps(), walk_state().gates)); + if (!resolved_for || !(resolved_for->first == walk_state().gates) || resolved_for->second != &walk_story_maps()){ + resolved = resolve_maps(walk_story_maps(), walk_state().gates); + resolved_for.emplace(walk_state().gates, &walk_story_maps()); } - return resolved->second; + return resolved; } std::string describe(const std::vector& route){ @@ -271,7 +284,7 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step, std::vector(step.args, "target")); const RouteGoal goal{{target.map, target.tile}, target.facing}; const Pokemon::GateRules rules{.card_key_held = walk_state().card_key_held}; - const std::optional> route = plan_overworld_route_gated(story_maps(), start, goal, walk_state().gates, rules, default_route_costs(), facing); + const std::optional> route = plan_overworld_route_gated(walk_story_maps(), start, goal, walk_state().gates, rules, default_route_costs(), facing); if (!route){ return step.name + ": no route from " + to_string(start) + " to " + to_string(goal.position) + "."; } @@ -280,7 +293,7 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step, std::vector& golden){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 66 || checkpoints[0].start){ - return "Expected 66 checkpoints, the first from a new game."; + if (checkpoints.size() != 72 || checkpoints[0].start){ + return "Expected 72 checkpoints, the first from a new game."; } StoryPose pose; walk_state() = WalkGates{}; @@ -433,7 +446,7 @@ UnitTestResult check_legs_on( const std::string& map, const std::vector& expected ){ const std::optional> route = plan_overworld_route( - story_maps(), start, goal, default_route_costs(), start_facing + walk_story_maps(), start, goal, default_route_costs(), start_facing ); if (!route){ return "No route from " + to_string(start) + " to " + to_string(goal.position) + "."; @@ -492,7 +505,7 @@ UnitTestResult test_pewter_aide_walk(){ const MapPosition gym{"PewterCity_Gym", {6, 6}}; const MapPosition goal{"PewterCity", {45, 21}}; const std::optional> route = plan_overworld_route( - story_maps(), gym, RouteGoal{goal, Direction::EAST}, default_route_costs(), Direction::NORTH + walk_story_maps(), gym, RouteGoal{goal, Direction::EAST}, default_route_costs(), Direction::NORTH ); if (!route || route->empty()){ return "No route from " + to_string(gym) + " to " + to_string(goal) + "."; @@ -502,7 +515,7 @@ UnitTestResult test_pewter_aide_walk(){ if (step.action != RouteAction::WALK){ continue; } - for (const MapPosition& tile : leg_tiles(story_maps(), from, step)){ + for (const MapPosition& tile : leg_tiles(walk_story_maps(), from, step)){ if (tile.map == "PewterCity" && tile.point.x == 46 && tile.point.y >= 21 && tile.point.y <= 23){ return "The route crosses the aide's trigger " + to_string(tile) + ":" + describe(*route); } @@ -608,7 +621,7 @@ std::vector legs_walked(const StoryPose& pose, const StoryStep& step) const MapData* map = find_map_named(pose.map); const std::optional facing = pose.facing ? pose.facing : map ? wall_beside(*map, pose.tile) : std::nullopt; const StoryPose target = one_tile(Pokemon::story_arg(step.args, "target")); - route = plan_overworld_route_gated(story_maps(), start, RouteGoal{{target.map, target.tile}, target.facing}, walk_state().gates, Pokemon::GateRules{.card_key_held = walk_state().card_key_held}, story_route_costs(), facing); + route = plan_overworld_route_gated(walk_story_maps(), start, RouteGoal{{target.map, target.tile}, target.facing}, walk_state().gates, Pokemon::GateRules{.card_key_held = walk_state().card_key_held}, story_route_costs(), facing); } return route ? *route : std::vector{}; } @@ -731,6 +744,13 @@ UnitTestResult advance(StoryPose& pose, const StoryStep& step){ return true; } +// Silph Co.'s rows: their floors are full of trainers whose lines the walk +// can't keep out of (the way on crosses them); the walk's interrupts fight +// them as they see the player, each walked leg ending where one does. +bool incidental_fights(const std::string& id){ + return id == "16.02" || id == "16.03" || id == "16.05"; +} + // `checkpoint`'s routes and legs keep to tiles with no tile_problem(); a // step into a trainer's line is followed by the battle, which beats them. // `repelled`: a Repel the table used is on (it lasts past the @@ -751,7 +771,9 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set{}){ const StoryPose end = to_patch ? one_tile(Pokemon::story_arg(step.args, "target")) : StoryPose{}; const bool patch = to_patch && tile.map == end.map && tile.point == end.tile; - if (const std::string problem = tile_problem(tile, beaten); !problem.empty() && !((patch || repelled || grass_held(pose, step)) && problem.starts_with("in the grass"))){ + if (const std::string problem = tile_problem(tile, beaten); !problem.empty() && !((patch || repelled || grass_held(pose, step)) && problem.starts_with("in the grass")) + && !(incidental_fights(checkpoint.id) && problem.starts_with("in the line of the trainer")) + ){ return where + problem; } } @@ -759,10 +781,10 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set 0){ + if (!lewis && !incidental_fights(checkpoint.id) && std::count(stops.begin(), stops.end(), std::nullopt) > 0){ return where + "crosses a wandering trainer's sight where the walk can't tell where they'd stop the player."; } - if (const std::string problem = walks ? held_past_lookers(pose, step, beaten) : ""; !problem.empty()){ + if (const std::string problem = walks && !incidental_fights(checkpoint.id) ? held_past_lookers(pose, step, beaten) : ""; !problem.empty()){ return where + problem; } const MapData* map = find_map_named(pose.map); @@ -892,7 +914,9 @@ std::string approach_off_tile(const std::vector& legs){ // tile west and met a gravestone (console B, 2026-11-12 04:39). // PASSED_ON_CONSOLE: approaches before 10.05 that passed their console // runs as held legs (a follow-up to tap them). 13.03 and 13.04 plan their statue -// approaches (PRESS_SWITCH) and have not run on a console. +// approaches (PRESS_SWITCH) and have not run on a console, nor has 16.05's walk to the +// president: it ends at (9, 10) facing north, the only tile that faces him, with no wall to +// end a leg against (tap it once Silph Co. has run). UnitTestResult test_approaches_end_on_their_tile(){ const std::set PASSED_ON_CONSOLE{ "02.02/below_oak", "03.02/before_brock", "05.07/below_bill_clefairy", "05.07/pc_front", @@ -901,7 +925,7 @@ UnitTestResult test_approaches_end_on_their_tile(){ // Not run on a console: 14.01 (#410) predates this rule. Its quiz machine approaches are held // open routes; tap them (follow-up) and drop these. "14.01/below_quiz_1", "14.01/below_quiz_2", "14.01/below_quiz_3", "14.01/below_quiz_4", - "14.01/below_quiz_5", "14.01/below_quiz_6", + "14.01/below_quiz_5", "14.01/below_quiz_6", "16.05/below_president", }; std::string wrong; size_t count = 0; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.02.plan.json new file mode 100644 index 0000000000..dea90a15f0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.02.plan.json @@ -0,0 +1,83 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "16.02", + "title": "Silph Co. 5F: the pad pair to the bottom corridor, the CARD KEY", + "start": { + "map": "SilphCo_5F", + "tiles": [ + [ + 15, + 7 + ] + ], + "facing": "west" + }, + "events": [ + { + "id": "to_corridor", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_5F", + "tiles": [ + [ + 12, + 21 + ] + ], + "facing": "south" + } + }, + "why": "5F's pad (10, 20) to 9F's (22, 18) and back is the only way into the bottom corridor: east and down to its wall (12, 21)" + }, + { + "id": "to_card_key_ball", + "kind": "legs", + "action": "taps", + "args": { + "legs": [ + { + "direction": "east", + "tiles": 9 + } + ] + }, + "why": "a tap a tile east along row 21 to (21, 21), west of the CARD KEY's ball (22, 21)" + }, + { + "id": "card_key", + "kind": "talk", + "why": "pick up the CARD KEY (SilphCo_5F_EventScript_ItemCardKey): the doors open to it from now on", + "flags_after": [ + "card_key_held" + ] + } + ] + }, + "execution": { + "menu": "full", + "notes": { + "checkpoint": [ + "Starts on 5F's pad (15, 7), where 16.01 ends. The CARD KEY's ball (22, 21) is on the runtime map (SilphCo_5F items); pokeguy has it at 1:28:11. Ends beside it with the key: the doors open to a face-and-A from now on (card_key_held)." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": { + "map": "SilphCo_5F", + "tiles": [ + [ + 21, + 21 + ] + ], + "facing": "east" + } + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.03.plan.json new file mode 100644 index 0000000000..194459a624 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.03.plan.json @@ -0,0 +1,168 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "16.03", + "title": "Silph Co. 7F: the rival", + "start": { + "map": "SilphCo_5F", + "tiles": [ + [ + 21, + 21 + ] + ], + "facing": "east" + }, + "start_flags": [ + "card_key_held" + ], + "events": [ + { + "id": "to_3f_trainer", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_3F", + "tiles": [ + [ + 22, + 9 + ] + ], + "facing": "south" + } + }, + "why": "through 5F's pads and 3F's hall to (22, 9), where the Rocket (25, 9) sees the player and fights (incidental; the leg ends on the tile he sees)" + }, + { + "id": "to_3f_door", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_3F", + "tiles": [ + [ + 18, + 13 + ] + ], + "facing": "west" + } + }, + "why": "down 3F's east hall to the Card Key door (20..21, 12..13), a face-and-A at (22, 13) opens it, then through it to the wall", + "gates_after": { + "opened": [ + "SilphCo_3F/door_2" + ] + } + }, + { + "id": "to_3f_pad_row", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_3F", + "tiles": [ + [ + 18, + 14 + ] + ], + "facing": "south" + } + }, + "why": "down a row, to the pad's row" + }, + { + "id": "to_rival_trigger", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_7F", + "tiles": [ + [ + 3, + 4 + ] + ], + "facing": "west" + } + }, + "why": "3F's pad (13, 14) to 7F's (5, 4), west along row 4 to (3, 4), a tile east of the rival's trigger (2, 4)" + }, + { + "id": "rival_trigger", + "kind": "step", + "args": { + "direction": "west" + }, + "declared_after": { + "map": "SilphCo_7F", + "tiles": [ + [ + 2, + 4 + ] + ], + "facing": "south" + }, + "why": "onto the trigger (2, 4) (SilphCo_7F_EventScript_RivalTriggerTop): the rival (2, 6) steps up to the player, who turns to face down" + }, + { + "id": "rival", + "kind": "battle", + "args": { + "trainer": "TRAINER_RIVAL_SILPH_BULBASAUR", + "foes": [ + "pidgeot", + "gyarados", + "growlithe", + "alakazam", + "venusaur" + ] + }, + "declared_after": { + "map": "SilphCo_7F", + "tiles": [ + [ + 2, + 4 + ] + ], + "facing": "south" + }, + "why": "the rival (TRAINER_RIVAL_SILPH_BULBASAUR, for a Squirtle): Pidgeot Lv37, Gyarados Lv38, Growlithe Lv35, Alakazam Lv35, Venusaur Lv40; then he leaves (VAR_MAP_SCENE_SILPH_CO_7F 1)" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "Starts beside 16.02's CARD KEY (the doors open to it from now on). The rival's fight is the same wherever the player crosses the trigger columns (2, 4) or (2, 5).", + "A boss battle is its own checkpoint (user, 2026-11-12): the rival's fight is all this row does beyond the walk up to him. It ends where his battle leaves the player, and saves there; 16.03b walks to the employee." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": { + "map": "SilphCo_7F", + "tiles": [ + [ + 2, + 4 + ] + ], + "facing": "south" + } + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.03b.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.03b.plan.json new file mode 100644 index 0000000000..700582489f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.03b.plan.json @@ -0,0 +1,68 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "16.03b", + "title": "To the employee with the Lapras", + "start": { + "map": "SilphCo_7F", + "tiles": [ + [ + 2, + 4 + ] + ], + "facing": "south" + }, + "start_flags": [ + "card_key_held" + ], + "events": [ + { + "id": "to_lapras_guy", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_7F", + "tiles": [ + [ + 1, + 7 + ] + ], + "facing": "west" + } + }, + "why": "down column 1, past the rival's tile (2, 6), to (1, 7), beside the employee (0, 7) who gives the LAPRAS (SilphCo_7F_EventScript_LaprasGuy)" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "handoff": "gift_rng", + "gift": "lapras", + "notes": { + "checkpoint": [ + "Starts where 16.03 ends after the rival's battle and saves.", + "Gift RNG starts from a save facing the employee, who gives a LAPRAS Lv25 for a free party slot (pokeguy skips it, 1:32:51; a user-approved RNG gift)." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": { + "map": "SilphCo_7F", + "tiles": [ + [ + 1, + 7 + ] + ], + "facing": "west" + } + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.04.plan.json new file mode 100644 index 0000000000..f78d334d82 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.04.plan.json @@ -0,0 +1,69 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "16.04", + "title": "after Gift RNG: save with the Lapras", + "start": { + "map": "SilphCo_7F", + "tiles": [ + [ + 1, + 7 + ] + ], + "facing": "west" + }, + "start_gates": { + "opened": [ + "SilphCo_3F/door_2" + ] + }, + "start_flags": [ + "card_key_held" + ], + "events": [ + { + "id": "leave_gift_summary", + "kind": "game_action", + "action": "leave_gift_summary", + "declared_after": { + "map": "SilphCo_7F", + "tiles": [ + [ + 1, + 7 + ] + ], + "facing": "west" + }, + "why": "the Lapras's summary Gift RNG left open, or HOME" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "live_start": true, + "notes": { + "checkpoint": [ + "Gift RNG takes the Lapras from the employee without moving the player and leaves its summary open, or HOME. This saves the shiny where 16.03b ended. A run started here with Gift RNG's handoff on loads the save facing the employee and runs Gift RNG first." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": { + "map": "SilphCo_7F", + "tiles": [ + [ + 1, + 7 + ] + ], + "facing": "west" + } + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.05.plan.json new file mode 100644 index 0000000000..18b63286e2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.05.plan.json @@ -0,0 +1,181 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "16.05", + "title": "Silph Co. 11F: Giovanni and the MASTER BALL", + "start": { + "map": "SilphCo_7F", + "tiles": [ + [ + 1, + 7 + ] + ], + "facing": "west" + }, + "start_gates": { + "opened": [ + "SilphCo_3F/door_2" + ] + }, + "start_flags": [ + "card_key_held" + ], + "events": [ + { + "id": "to_left_wall", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_11F", + "tiles": [ + [ + 0, + 18 + ] + ], + "facing": "south" + } + }, + "why": "from 7F's left rooms onto the pad (5, 8) to 11F's (2, 5), down its left wall (column 0) out of the sight of the Rocket at (2, 19), who looks up column 2" + }, + { + "id": "to_rocket_column", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_11F", + "tiles": [ + [ + 2, + 18 + ] + ], + "facing": "east" + } + }, + "why": "east along row 18 to (2, 18): the Rocket (2, 19) sees the player there and fights beside him (incidental; the leg ends on the tile he sees)" + }, + { + "id": "to_giovanni_door", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_11F", + "tiles": [ + [ + 5, + 16 + ] + ], + "facing": "north" + } + }, + "why": "east along row 18, on to the Card Key door (5..6, 16..17): a face-and-A at (5, 18) opens it, then up to (5, 16), below the trigger (5, 15)", + "gates_after": { + "opened": [ + "SilphCo_11F/door" + ] + } + }, + { + "id": "giovanni_trigger", + "kind": "step", + "args": { + "direction": "north" + }, + "declared_after": { + "map": "SilphCo_11F", + "tiles": [ + [ + 5, + 15 + ] + ], + "facing": "north" + }, + "why": "onto the trigger (5, 15) (SilphCo_11F_EventScript_GiovanniTriggerLeft): Giovanni (6, 11) turns down, speaks and walks up to the player" + }, + { + "id": "giovanni", + "kind": "battle", + "args": { + "trainer": "TRAINER_BOSS_GIOVANNI_2", + "foes": [ + "nidorino", + "kangaskhan", + "rhyhorn", + "nidoqueen" + ] + }, + "declared_after": { + "map": "SilphCo_11F", + "tiles": [ + [ + 5, + 15 + ] + ], + "facing": "north" + }, + "flags_after": [ + "silph_cleared" + ], + "why": "Giovanni (TRAINER_BOSS_GIOVANNI_2): Nidorino Lv37, Kangaskhan Lv35, Rhyhorn Lv37, Nidoqueen Lv41; then he and the Rockets leave Silph Co. and Saffron City (FLAG_HIDE_SAFFRON_ROCKETS), the story's maps from here have none" + }, + { + "id": "below_president", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SilphCo_11F", + "tiles": [ + [ + 9, + 10 + ] + ], + "facing": "north" + } + }, + "why": "up the room to (9, 10), below the president (9, 9)" + }, + { + "id": "master_ball", + "kind": "talk", + "skip_if": [ + "master_ball_skipped" + ], + "why": "the president gives the MASTER BALL (SilphCo_11F_EventScript_President, FLAG_GOT_MASTER_BALL_FROM_SILPH); skipped by the program's option and in a SPEEDRUN (pokeguy skips it, 1:32:51)" + } + ] + }, + "execution": { + "menu": "full", + "notes": { + "checkpoint": [ + "Starts on 7F beside the employee, where 16.04 saves (16.03b without Gift RNG). Ends facing the president, with the MASTER BALL if taken; the save after it is the retry point before the walk back (16.06). Giovanni is a boss fight (pokeguy: C, TRAINER_BOSS_GIOVANNI_2)." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": { + "map": "SilphCo_11F", + "tiles": [ + [ + 9, + 10 + ] + ], + "facing": "north" + } + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.06.plan.json new file mode 100644 index 0000000000..319a4f29dc --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-16.06.plan.json @@ -0,0 +1,92 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "16.06", + "title": "Silph Co. to Saffron: back down to the Center", + "start": { + "map": "SilphCo_11F", + "tiles": [ + [ + 9, + 10 + ] + ], + "facing": "north" + }, + "start_gates": { + "opened": [ + "SilphCo_3F/door_2", + "SilphCo_11F/door" + ] + }, + "start_flags": [ + "card_key_held", + "silph_cleared" + ], + "events": [ + { + "id": "below_center_door", + "kind": "route", + "action": "run", + "args": { + "target": { + "map": "SaffronCity", + "tiles": [ + [ + 24, + 39 + ] + ], + "facing": "north" + } + }, + "why": "back by the pads and stairs, with the doors open and no Rocket left in Silph Co. or Saffron City, out of Silph Co.'s door (33, 30) to below the Center's door (24, 38)" + }, + { + "id": "saffron_nurse", + "kind": "game_action", + "action": "center_enter", + "declared_after": { + "map": "SaffronCity_PokemonCenter_1F", + "tiles": [ + [ + 7, + 4 + ] + ], + "facing": "north" + }, + "why": "the Center script in: through the door and up to the nurse" + }, + { + "id": "heal_saffron", + "kind": "heal", + "why": "full HP and PP before the Gym" + } + ] + }, + "execution": { + "menu": "full", + "notes": { + "checkpoint": [ + "Starts facing the president on 11F, where 16.05 ends. The Rockets are gone from Silph Co. and Saffron City (silph_cleared): the Grunt at Saffron (46, 13) no longer blocks the Gym's door." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": { + "map": "SaffronCity_PokemonCenter_1F", + "tiles": [ + [ + 7, + 4 + ] + ], + "facing": "north" + } + } + } +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 7c832aa506..ba78393b1d 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1587,6 +1587,10 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h Source/Pokemon/AutoStory/Pokemon_StoryPreflight.cpp Source/Pokemon/AutoStory/Pokemon_StoryPreflight.h + Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.cpp + Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff.h + Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp + Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.h Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.cpp Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h Source/Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.cpp @@ -2164,6 +2168,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMember.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPaceSim.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPaceSim.h