diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 928a5c4bd0..80ef896adb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -77,6 +77,14 @@ AutoStory::AutoStory() LockMode::LOCK_WHILE_RUNNING, false ) + , STOP_FOR_STARTER_RNG( + "Stop for Starter RNG:
Off by default. At the end of 00.04, save south of the table facing Squirtle's ball " + "and stop, where the Starter RNG program starts. After Starter RNG, save right after the rival's battle without moving " + "and start AutoStory at 00.05.
" + "With this off, 00.04 and 00.04b run as one checkpoint, as before.", + LockMode::LOCK_WHILE_RUNNING, + false + ) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, &NOTIFICATION_ERROR_FATAL, @@ -86,6 +94,7 @@ AutoStory::AutoStory() PA_ADD_OPTION(NEW_GAME_FROM_TITLE); PA_ADD_OPTION(PLAYER_NAME); PA_ADD_OPTION(STOP_FOR_SID_HELPER); + PA_ADD_OPTION(STOP_FOR_STARTER_RNG); PA_ADD_OPTION(NOTIFICATIONS); } @@ -281,7 +290,9 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex const size_t last = RUN.end_index(); const std::string player_name = PLAYER_NAME; check_setup(env.console, checkpoints, first, last, NEW_GAME_FROM_TITLE, player_name); - const StoryRunPlan plan = plan_story_run(checkpoints, first, last, StoryHandoffs{.sid_helper = STOP_FOR_SID_HELPER}); + const StoryRunPlan plan = plan_story_run( + checkpoints, first, last, StoryHandoffs{.sid_helper = STOP_FOR_SID_HELPER, .starter_rng = STOP_FOR_STARTER_RNG} + ); if (plan.stop == StoryHandoff::SID_HELPER){ play_new_game_to_player_name(env.console, context, player_name); stop_for_handoff(env, NOTIFICATION_PROGRAM_FINISH, @@ -308,6 +319,13 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex Pokemon::record_story_stats(env.current_stats(), report); env.update_stats(); throw_if_failed(report); + if (plan.stop == StoryHandoff::STARTER_RNG){ + stop_for_handoff(env, NOTIFICATION_PROGRAM_FINISH, + "Stopped for Starter RNG: saved south of the table, facing Squirtle's ball. Run Starter RNG now. " + "Then save right after the rival's battle, without moving, and start AutoStory at 00.05." + ); + return; + } env.console.log("AutoStory: done through " + plan.rows.back().id + "."); send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h index 3915332642..8fd043efb9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.h @@ -49,6 +49,7 @@ class AutoStory : public SingleSwitchProgramInstance{ StringOption PLAYER_NAME; // The RNG programs the run stops for (StoryHandoff). BooleanCheckBoxOption STOP_FOR_SID_HELPER; + BooleanCheckBoxOption STOP_FOR_STARTER_RNG; EventNotificationsOption NOTIFICATIONS; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 60796919a0..a39e555328 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -452,6 +452,23 @@ Outcome StoryExecutor::game(RunState&, const StoryStep& step){ } +namespace{ + +// `first` and `second` as one checkpoint: `first`'s id, start and +// supplies, `second`'s title and START menu, both rows' steps. +StoryCheckpoint joined_rows(const StoryCheckpoint& first, const StoryCheckpoint& second){ + StoryCheckpoint row = second; + row.id = first.id; + row.start = first.start; + row.supplies = first.supplies; + row.live_start = first.live_start; + row.steps = first.steps; + row.steps.insert(row.steps.end(), second.steps.begin(), second.steps.end()); + return row; +} + +} + StoryRunPlan plan_story_run( const std::vector& checkpoints, size_t first, size_t last, const StoryHandoffs& handoffs ){ @@ -466,6 +483,16 @@ StoryRunPlan plan_story_run( plan.stop = StoryHandoff::SID_HELPER; return plan; } + if (row.handoff == StoryHandoff::STARTER_RNG && handoffs.starter_rng){ + plan.rows.emplace_back(row); + plan.stop = StoryHandoff::STARTER_RNG; + return plan; + } + if (row.handoff == StoryHandoff::STARTER_RNG && c + 1 < checkpoints.size()){ + plan.rows.emplace_back(joined_rows(row, checkpoints[c + 1])); + c++; + continue; + } plan.rows.emplace_back(row); } return plan; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 053cadbdeb..b716973374 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -70,6 +70,10 @@ enum class StoryHandoff{ // The checkpoint's new game stops on the player's keyboard, the name // typed and OK not pressed, which is where SID Helper starts. SID_HELPER, + // The checkpoint saves south of the table, facing the starter's ball, + // which is where Starter RNG starts. With the handoff off, it runs on + // into the next checkpoint as one, as the story did before the split. + STARTER_RNG, }; // A shared checkpoint with what FRLG adds to it. @@ -89,6 +93,7 @@ struct StoryCheckpoint : public Pokemon::StoryCheckpoint{ // The handoffs a run stops for (AutoStory's options). struct StoryHandoffs{ bool sid_helper = false; + bool starter_rng = false; }; // What a run from table row `first` to `last` does. @@ -97,12 +102,16 @@ struct StoryRunPlan{ std::vector rows; // NONE: the run ends after `rows`. SID_HELPER: `rows` is empty; the run // plays the new game to the player's keyboard and stops there. + // STARTER_RNG: the run stops after `rows`, the last of which saves at + // the starter's ball. StoryHandoff stop = StoryHandoff::NONE; }; // The rows of `checkpoints` from `first` to `last`, both inclusive, as a // run with `handoffs` takes them: live-start rows only when the run -// starts there, and a run that reaches a handoff that is on stops for it. +// starts there, a run that reaches a handoff that is on stops for it, and +// a STARTER_RNG row whose handoff is off is joined with the row after it, +// under its own id. StoryRunPlan plan_story_run( const std::vector& checkpoints, size_t first, size_t last, const StoryHandoffs& handoffs ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 9905a6cf5d..eb29f6d463 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -194,9 +194,17 @@ StoryCheckpoint oaks_trigger(){ }); } -StoryCheckpoint starter(){ - return row("00.04", "Squirtle, then the rival's battle", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEDEX, { +// Starter RNG starts from a save south of the table, facing the ball. +StoryCheckpoint to_starter_ball(){ + StoryCheckpoint checkpoint = row("00.04", "to Squirtle's ball, south of the table", at(LAB, 6, 4, NORTH), {}, StartMenu::BEFORE_POKEMON, { route("below_squirtle", at(LAB, 9, 5, NORTH), "under Squirtle's ball (9, 4)"), + }); + checkpoint.handoff = StoryHandoff::STARTER_RNG; + return checkpoint; +} + +StoryCheckpoint starter(){ + return row("00.04b", "Squirtle, then the rival's battle", at(LAB, 9, 5, NORTH), {}, StartMenu::BEFORE_POKEDEX, { talk("squirtle_ball", "\"So, you want the WATER POKEMON SQUIRTLE?\""), answer("choose_squirtle", true, "take Squirtle"), answer("no_nickname", false, "\"give a nickname?\" NO"), @@ -309,7 +317,7 @@ StoryCheckpoint running_shoes(){ const std::vector& story_checkpoints(){ static const std::vector checkpoints{ - new_game(), after_sid_helper(), leave_house(), oaks_trigger(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), + new_game(), after_sid_helper(), leave_house(), oaks_trigger(), to_starter_ball(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), running_shoes(), }; return checkpoints; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 37531a70c7..e93c6058f9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -22,7 +22,8 @@ namespace PokemonFRLG{ // Checkpoints 00.01 to 00.10, in order, with 00.01b, the way back in after -// SID Helper, after 00.01. +// SID Helper, after 00.01, and 00.04 split in two at Squirtle's ball for +// Starter RNG: 00.04 and 00.04b. const std::vector& story_checkpoints(); 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 8b0ab92acb..d282fd40bd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -212,8 +212,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po UnitTestResult test_routes_and_chain(){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 11 || checkpoints[0].start){ - return "Expected 11 checkpoints, the first from a new game."; + if (checkpoints.size() != 12 || checkpoints[0].start){ + return "Expected 12 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ @@ -553,6 +553,8 @@ const char* handoff_name(StoryHandoff handoff){ return "none"; case StoryHandoff::SID_HELPER: return "SID Helper"; + case StoryHandoff::STARTER_RNG: + return "Starter RNG"; } return "?"; } @@ -614,12 +616,68 @@ void add_tests_RunPlan(UnitTestDatabase& database){ }, {.name = "00.01b runs when started at, option off", .first = "00.01b", .last = "00.02", .expected_ids = "00.01b 00.02"}, {.name = "SID Helper: a later start passes over it", .first = "00.02", .last = "00.03", .handoffs = {.sid_helper = true}, .expected_ids = "00.02 00.03"}, + {.name = "handoffs off: an end at 00.04 still takes the rival's battle", .first = "00.03", .last = "00.04", .expected_ids = "00.03 00.04"}, + { + .name = "Starter RNG: stops after 00.04's save", + .first = "00.02", + .handoffs = {.starter_rng = true}, + .expected_ids = "00.02 00.03 00.04", + .expected_stop = StoryHandoff::STARTER_RNG, + }, + {.name = "00.04b runs from its own save", .first = "00.04b", .last = "00.05", .expected_ids = "00.04b 00.05"}, + {.name = "Starter RNG: a later start doesn't stop", .first = "00.05", .last = "00.06", .handoffs = {.starter_rng = true}, .expected_ids = "00.05 00.06"}, + { + .name = "both handoffs, back in after SID Helper", + .first = "00.01b", + .handoffs = {.sid_helper = true, .starter_rng = true}, + .expected_ids = "00.01b 00.02 00.03 00.04", + .expected_stop = StoryHandoff::STARTER_RNG, + }, }; for (const RunPlanScenario& scenario : scenarios){ database.add(scenario); } } +std::string step_names(const StoryCheckpoint& checkpoint){ + std::string text; + for (const StoryStep& step : checkpoint.steps){ + text += (text.empty() ? "" : " ") + step.name; + } + return text; +} + +// With Starter RNG's handoff off, 00.04 and 00.04b run as the one 00.04 +// the story had before the split: from the lab's table to the rival's +// battle, saving once with the starter's START menu. +UnitTestResult test_starter_rows_joined(){ + const std::vector& checkpoints = story_checkpoints(); + const StoryRunPlan plan = plan_story_run(checkpoints, row_index("00.04"), row_index("00.04b"), StoryHandoffs{}); + const std::string expected_steps = + "below_squirtle squirtle_ball choose_squirtle no_nickname rival_takes_bulbasaur above_rival_trigger rival_trigger rival_battle"; + if (plan.rows.size() != 1){ + return "Expected one checkpoint, got \"" + joined_ids(plan.rows) + "\"."; + } + const StoryCheckpoint& row = plan.rows[0]; + if (row.id != "00.04" || row.title != "Squirtle, then the rival's battle" || step_names(row) != expected_steps){ + return "Expected 00.04 \"Squirtle, then the rival's battle\": " + expected_steps + + "; got " + row.id + " \"" + row.title + "\": " + step_names(row); + } + const std::optional start = story_pose(*row.start); + if (!start || start->map != "PalletTown_ProfessorOaksLab" || !(start->tile == TilePos{6, 4}) || row.menu != StartMenu::BEFORE_POKEDEX){ + return "Expected the joined 00.04 to start at the table (6, 4) and save with the starter's START menu."; + } + // Split, 00.04 saves under the ball facing it, before the starter. + const StoryCheckpoint& to_ball = checkpoints[row_index("00.04")]; + const std::optional ball = story_pose(*checkpoints[row_index("00.04b")].start); + if (to_ball.handoff != StoryHandoff::STARTER_RNG || to_ball.menu != StartMenu::BEFORE_POKEMON + || !ball || !(ball->tile == TilePos{9, 5}) || ball->facing != Direction::NORTH + ){ + return "Expected 00.04 to end under Squirtle's ball (9, 5) facing north, saving before the starter."; + } + return true; +} + // The way back in after SID Helper loads no save and starts where 00.01 // leaves the player, so 00.02 follows it unchanged. UnitTestResult test_after_sid_helper_row(){ @@ -681,6 +739,7 @@ UnitTestResult test_option_presses(){ void add_tests_AutoStory(UnitTestDatabase& database){ add_tests_RunPlan(database); database.add("00.01b: back in after SID Helper", test_after_sid_helper_row); + database.add("00.04 and 00.04b: one checkpoint with Starter RNG off", test_starter_rows_joined); database.add("every route plans, and checkpoints chain", test_routes_and_chain); database.add("step names are unique per checkpoint", test_unique_names); database.add("every save has a place on the save card", test_save_places);