diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp index 2ea213cec4..339f9c1729 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp @@ -49,6 +49,11 @@ constexpr std::string_view MAP_NAMES[] = { "CeruleanCity_PokemonCenter_1F", "CeruleanCity", "Route24", + // Cerulean City's Mart and Gym, and Route 25 to Bill's Sea Cottage. + "CeruleanCity_Mart", + "CeruleanCity_Gym", + "Route25", + "Route25_SeaCottage", "CeruleanCave_1F", "CeruleanCave_2F", "CeruleanCave_B1F", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h index f561970d25..b73ca440dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h @@ -4,9 +4,10 @@ * * The FRLG maps the overworld routes know about so far: every map from a * new game in Pallet Town through Viridian City, Route 2 and Viridian - * Forest to Brock's gym in Pewter City; and Cerulean City, its Pokemon - * Center, Route 24 to its north, and the three floors of Cerulean Cave, - * where Mewtwo waits on B1F. + * Forest to Brock's gym in Pewter City, Route 3, Mt. Moon and Route 4; + * and Cerulean City, its Pokemon Center, Mart and Gym, Route 24 (Nugget + * Bridge) and Route 25 to Bill's Sea Cottage, and the three floors of + * Cerulean Cave, where Mewtwo waits on B1F. * * Each map is a pinned PokemonSimulation JSON resource, prepared under * Packages/Resources/Pokemon/Maps/frlg and built into the program by CMake diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp index 4c38ba9877..571656588f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps_Tests.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "PokemonFRLG_OverworldMap.h" @@ -325,6 +326,42 @@ UnitTestResult test_mt_moon_closed_floor_wild(){ return true; } +// Whether a route plans from Cerulean's Pokemon Center, at its nurse, to +// `goal` on `maps`. +bool plans_from_cerulean_nurse(const std::vector& maps, const RouteGoal& goal){ + const MapPosition nurse{"CeruleanCity_PokemonCenter_1F", map_point(maps, "CeruleanCity_PokemonCenter_1F", "nurse_front")}; + return plan_overworld_route(maps, nurse, goal, default_route_costs(), Direction::NORTH).has_value(); +} + +// Cerulean City's Mart and Gym and Route 25's Sea Cottage load with the +// points the story walks to, and join the city: from its Pokemon Center +// a route plans to the Mart's clerk, to Misty, and north over Nugget +// Bridge (Route 24) and east along Route 25 into Bill's Sea Cottage. +UnitTestResult test_cerulean_maps(){ + const std::vector maps = overworld_maps(); + for (std::string_view name : {"CeruleanCity_Mart", "CeruleanCity_Gym", "Route25", "Route25_SeaCottage"}){ + if (built_in(maps, std::string(name)) == nullptr){ + return std::format("Missing map {}.", name); + } + } + const MapPosition clerk{"CeruleanCity_Mart", map_point(maps, "CeruleanCity_Mart", "clerk_front")}; + const MapPosition misty{"CeruleanCity_Gym", map_point(maps, "CeruleanCity_Gym", "misty_front")}; + if (clerk.point != TilePos{4, 3} || misty.point != TilePos{8, 7}){ + return "Unexpected clerk_front or misty_front."; + } + if (!plans_from_cerulean_nurse(maps, RouteGoal{clerk, Direction::WEST})){ + return "No route from Cerulean's Pokemon Center to the Mart's clerk."; + } + if (!plans_from_cerulean_nurse(maps, RouteGoal{misty, Direction::NORTH})){ + return "No route from Cerulean's Pokemon Center to Misty."; + } + const MapPosition bill_front{"Route25_SeaCottage", {7, 7}}; + if (!plans_from_cerulean_nurse(maps, RouteGoal{bill_front, Direction::NORTH})){ + return "No route from Cerulean's Pokemon Center over Nugget Bridge and Route 25 into Bill's Sea Cottage."; + } + return true; +} + // A planned step walks where its map doesn't let the player run, and only // there: out of Pewter's Pokemon Center to the Gym. UnitTestResult test_walk_only_indoors(){ @@ -578,6 +615,10 @@ const OverworldMapsTestCase OVERWORLD_MAPS_CASES[] = { .input = {.name = "trainer stops on the story's maps", .body = test_trainer_stops}, .expectation = {.description = "verifies trainer stops along story routes"}, }, + { + .input = {.name = "Cerulean's Mart and Gym, Route 25 and Bill's Sea Cottage", .body = test_cerulean_maps}, + .expectation = {.description = "validates Cerulean City, Gym, Mart, Route 25 and Sea Cottage map data"}, + }, }; } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp index 9a828eed06..c129f8367b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp @@ -786,95 +786,176 @@ UnitTestResult test_mt_moon_way_out(){ return true; } +// Story row 00.14: from Route 4 east of Mt. Moon along the upper road to +// above the ledge row 9, out of Lass Crissy's line (75, 3); one step +// south hops the ledge onto the lower road two tiles down; from there +// into Cerulean City and its Pokemon Center by one door. No route plans +// past the ledge: the upper road reaches the city only by water. +UnitTestResult test_route4_to_cerulean(){ + const SimCase upper{.start = at("Route4", 32, 6), .facing = Direction::SOUTH, .goal = at("Route4", 93, 8)}; + const SimRun walk = run_case(upper); + if (!arrived(walk, upper.goal) || !walk.state.trainers_beaten.empty()){ + return "Expected the upper road walked to above the ledge, no trainer met:" + describe(walk); + } + OverworldSim sim(maps(), at("Route4", 93, 8), Direction::SOUTH); + sim.tap(Direction::SOUTH); + sim.watch({SimWatcher::MESSAGE}, std::chrono::milliseconds(2000)); + if (!(sim.state().position == at("Route4", 93, 10))){ + return "Expected the step south to hop the ledge onto (93, 10), not " + to_string(sim.state().position) + "."; + } + const SimCase lower{.start = at("Route4", 93, 10), .facing = Direction::SOUTH, .goal = at("CeruleanCity_PokemonCenter_1F", 7, 4)}; + const SimRun now = run_case(lower); + if (!arrived(now, lower.goal) || now.state.warps != 1 || !now.state.trainers_beaten.empty()){ + return "Expected Cerulean's Pokemon Center reached by its door, no trainer met:" + describe(now); + } + return true; +} + +// Story rows 00.14b and 00.14c in Cerulean Gym (pokefirered map.json): +// from the Center into the Gym, up column 9 to (9, 13), west to (4, 13), +// then to walls round the pool's west and north sides and west to (9, 7) +// below Misty's platform, meeting no one; and back from beside her (9, 6) +// the same way round to (9, 13) and out to the Center. +UnitTestResult test_cerulean_gym_walks(){ + const SimCase in{.start = at("CeruleanCity_PokemonCenter_1F", 7, 4), .facing = Direction::NORTH, .goal = at("CeruleanCity_Gym", 9, 13)}; + const SimRun entered = run_case(in); + if (!arrived(entered, in.goal) || entered.state.warps != 2 || !entered.state.trainers_beaten.empty()){ + return "Expected the Gym entered and (9, 13) reached, no trainer met:" + describe(entered); + } + SimCase west{.start = in.goal, .facing = Direction::NORTH, .goal = at("CeruleanCity_Gym", 4, 13)}; + west.route = std::vector{leg(Direction::WEST, 5, west.goal, true)}; + const SimRun walkway = run_case(west); + if (!arrived(walkway, west.goal) || !walkway.state.trainers_beaten.empty()){ + return "Expected the wall (4, 13) reached west from (9, 13), no trainer met:" + describe(walkway); + } + SimCase up{.start = west.goal, .facing = Direction::WEST, .goal = at("CeruleanCity_Gym", 9, 7)}; + up.route = std::vector{ + leg(Direction::NORTH, 3, at("CeruleanCity_Gym", 4, 10), true), + leg(Direction::EAST, 8, at("CeruleanCity_Gym", 12, 10), true), + leg(Direction::NORTH, 3, at("CeruleanCity_Gym", 12, 7), true), + leg(Direction::WEST, 3, up.goal, false), + }; + const SimRun walk = run_case(up); + if (!arrived(walk, up.goal) || !walk.state.trainers_beaten.empty()){ + return "Expected (9, 7) below Misty's platform reached round the pool, no trainer met:" + describe(walk); + } + SimCase out{.start = at("CeruleanCity_Gym", 9, 6), .facing = Direction::WEST, .goal = at("CeruleanCity_Gym", 9, 13)}; + out.route = std::vector{ + leg(Direction::SOUTH, 1, at("CeruleanCity_Gym", 9, 7), false), + leg(Direction::EAST, 3, at("CeruleanCity_Gym", 12, 7), true), + leg(Direction::SOUTH, 3, at("CeruleanCity_Gym", 12, 10), true), + leg(Direction::WEST, 8, at("CeruleanCity_Gym", 4, 10), true), + leg(Direction::SOUTH, 3, at("CeruleanCity_Gym", 4, 13), true), + leg(Direction::EAST, 5, out.goal, true), + }; + const SimRun back = run_case(out); + if (!arrived(back, out.goal) || !back.state.trainers_beaten.empty()){ + return "Expected (9, 13) reached from beside Misty round the pool, no trainer met:" + describe(back); + } + const SimCase nurse{.start = out.goal, .facing = Direction::EAST, .goal = at("CeruleanCity_PokemonCenter_1F", 7, 4)}; + const SimRun healed = run_case(nurse); + if (!arrived(healed, nurse.goal) || healed.state.warps != 2 || !healed.state.trainers_beaten.empty()){ + return "Expected the Center reached from (9, 13), no trainer met:" + describe(healed); + } + return true; +} + +// The straight ways in Cerulean Gym that 00.14b and 00.14c keep off: the +// step onto (9, 12) meets Swimmer Luis, and the step onto (8, 7), +// misty_front, Picnicker Diana. +UnitTestResult test_cerulean_gym_lines(){ + const struct{ + MapPosition from; + Direction direction; + MapPosition onto; + std::string_view trainer; + } LINES[] = { + {at("CeruleanCity_Gym", 9, 13), Direction::NORTH, at("CeruleanCity_Gym", 9, 12), "swimmer_m_water"}, + {at("CeruleanCity_Gym", 9, 7), Direction::WEST, at("CeruleanCity_Gym", 8, 7), "picnicker"}, + }; + for (const auto& line : LINES){ + SimCase c{.start = line.from, .facing = line.direction, .goal = line.onto}; + c.route = std::vector{leg(line.direction, 1, c.goal, false)}; + const SimRun now = run_case(c); + if (!arrived(now, c.goal) || now.state.trainers_beaten != std::vector{std::string(line.trainer)}){ + return std::format("Expected the {} fought on the step onto {}:", line.trainer, to_string(line.onto)) + describe(now); + } + } + return true; +} + +// Story rows 00.15 and 00.16: out of Cerulean's Pokemon Center by its mat +// to below the rival's trigger row, and on north across the city's edge +// onto Nugget Bridge, below Cale's row, meeting no one. +UnitTestResult test_cerulean_to_bridge(){ + const MapPosition nurse = at("CeruleanCity_PokemonCenter_1F", 7, 4); + for (const MapPosition& goal : {at("CeruleanCity", 23, 7), at("Route24", 11, 32)}){ + const SimCase c{.start = nurse, .facing = Direction::NORTH, .goal = goal}; + const SimRun now = run_case(c); + if (!arrived(now, c.goal) || now.state.warps != 1 || !now.state.trainers_beaten.empty()){ + return "Expected " + to_string(goal) + " reached by the Center's mat, no trainer met:" + describe(now); + } + } + return true; +} + +// Story row 00.16 up Nugget Bridge: the short legs between the five +// trainers' rows meet no one; and the step from the tile below each row +// onto it is in that trainer's sight, beside them, so they fight there +// without walking: Cale, Ali, Timmy, Reli and Ethan. +UnitTestResult test_nugget_bridge_legs(){ + SimCase between{.start = at("Route24", 11, 31), .facing = Direction::NORTH, .goal = at("Route24", 11, 29)}; + between.route = std::vector{leg(Direction::NORTH, 2, between.goal, false)}; + const SimRun walk = run_case(between); + if (!arrived(walk, between.goal) || !walk.state.trainers_beaten.empty()){ + return "Expected the leg between two rows walked, no trainer met:" + describe(walk); + } + const struct{ + int row; + std::string_view trainer; + } LINES[] = {{31, "bug_catcher"}, {28, "lass"}, {25, "youngster"}, {22, "lass"}, {19, "camper"}}; + for (const auto& line : LINES){ + SimCase c{.start = at("Route24", 11, line.row + 1), .facing = Direction::NORTH, .goal = at("Route24", 11, line.row)}; + c.route = std::vector{leg(Direction::NORTH, 1, c.goal, false)}; + const SimRun now = run_case(c); + if (!arrived(now, c.goal) || now.state.trainers_beaten != std::vector{std::string(line.trainer)}){ + return std::format("Expected the {} on row {} fought beside the player:", line.trainer, line.row) + describe(now); + } + } + return true; +} + } // namespace + const OverworldSimCase OVERWORLD_SIM_CASES[] = { - { - .input = {"the forest's north gate: no fade or black read as a battle", test_forest_north_gate}, - .expectation = {}, - }, - { - .input = {"a battle on a leg onto a warp", test_battle_on_warp_leg}, - .expectation = {}, - }, - { - .input = {"the START menu left open", test_start_menu_open}, - .expectation = {}, - }, - { - .input = {"a battle at the end of a leg", test_battle_at_end_of_leg}, - .expectation = {}, - }, - { - .input = {"a late battle stops an open leg", test_late_battle_mid_leg}, - .expectation = {}, - }, - { - .input = {"a trainer's battle is fought, not fled", test_trainer_not_fled}, - .expectation = {}, - }, - { - .input = {"no hold over a ledge", test_no_hold_over_ledge}, - .expectation = {}, - }, - { - .input = {"a short leg, then a sign", test_short_leg_then_sign}, - .expectation = {}, - }, - { - .input = {"a short leg, nothing seen", test_short_leg_unseen}, - .expectation = {}, - }, - { - .input = {"a trainer on the way out of Pewter Gym", test_trainer_on_way_out}, - .expectation = {}, - }, - { - .input = {"out of Viridian Mart from the clerk's scene", test_mart_exit}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: down the ladders to B2F", test_mt_moon_ladders}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: the Moon Stone is a short detour", test_moon_stone_detour}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: the Grunt who looks around stops a leg to a wall", test_mt_moon_grunt_mid_leg}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: a short open leg before the Grunt's line", test_mt_moon_short_leg}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: a late wild battle in the cave", test_mt_moon_late_battle}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: after the HELIX, out to Route 4", test_mt_moon_way_out}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: a battle on the leg onto 1F's ladder", test_mt_moon_battle_on_ladder_leg}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: a battle seen only after a leg to a wall", test_mt_moon_battle_seen_after_wall_leg}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: black after a leg not marked wild", test_mt_moon_black_after_unmarked_leg}, - .expectation = {}, - }, - { - .input = {"Mt. Moon: a battle seen only before the next leg", test_mt_moon_battle_before_next_leg}, - .expectation = {}, - }, -}; + {.input = {"the forest's north gate: no fade or black read as a battle", test_forest_north_gate}, .expectation = {},}, + {.input = {"a battle on a leg onto a warp", test_battle_on_warp_leg}, .expectation = {},}, + {.input = {"the START menu left open", test_start_menu_open}, .expectation = {},}, + {.input = {"a battle at the end of a leg", test_battle_at_end_of_leg}, .expectation = {},}, + {.input = {"a late battle stops an open leg", test_late_battle_mid_leg}, .expectation = {},}, + {.input = {"a trainer's battle is fought, not fled", test_trainer_not_fled}, .expectation = {},}, + {.input = {"no hold over a ledge", test_no_hold_over_ledge}, .expectation = {},}, + {.input = {"a short leg, then a sign", test_short_leg_then_sign}, .expectation = {},}, + {.input = {"a short leg, nothing seen", test_short_leg_unseen}, .expectation = {},}, + {.input = {"a trainer on the way out of Pewter Gym", test_trainer_on_way_out}, .expectation = {},}, + {.input = {"out of Viridian Mart from the clerk's scene", test_mart_exit}, .expectation = {},}, + {.input = {"Mt. Moon: down the ladders to B2F", test_mt_moon_ladders}, .expectation = {},}, + {.input = {"Mt. Moon: the Moon Stone is a short detour", test_moon_stone_detour}, .expectation = {},}, + {.input = {"Mt. Moon: the Grunt who looks around stops a leg to a wall", test_mt_moon_grunt_mid_leg}, .expectation = {},}, + {.input = {"Mt. Moon: a short open leg before the Grunt's line", test_mt_moon_short_leg}, .expectation = {},}, + {.input = {"Mt. Moon: a late wild battle in the cave", test_mt_moon_late_battle}, .expectation = {},}, + {.input = {"Mt. Moon: after the HELIX, out to Route 4", test_mt_moon_way_out}, .expectation = {},}, + {.input = {"Mt. Moon: a battle on the leg onto 1F's ladder", test_mt_moon_battle_on_ladder_leg}, .expectation = {},}, + {.input = {"Mt. Moon: a battle seen only after a leg to a wall", test_mt_moon_battle_seen_after_wall_leg}, .expectation = {},}, + {.input = {"Mt. Moon: black after a leg not marked wild", test_mt_moon_black_after_unmarked_leg}, .expectation = {},}, + {.input = {"Mt. Moon: a battle seen only before the next leg", test_mt_moon_battle_before_next_leg}, .expectation = {},}, + {.input = {"Route 4 east, down its ledge, to Cerulean's Pokemon Center", test_route4_to_cerulean}, .expectation = {},}, + {.input = {"Cerulean Gym: to Misty and back round the pool, no trainer met", test_cerulean_gym_walks}, .expectation = {},}, + {.input = {"Cerulean Gym: the straight ways meet Luis and Diana", test_cerulean_gym_lines}, .expectation = {},}, + {.input = {"Cerulean: the Center to the rival's row and Nugget Bridge", test_cerulean_to_bridge}, .expectation = {},}, + {.input = {"Nugget Bridge: each trainer met on the step onto their row", test_nugget_bridge_legs}, .expectation = {},},}; void add_tests_OverworldSim(UnitTestDatabase& database){ for (const auto& item : OVERWORLD_SIM_CASES){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp index 7b7ae6cc74..58f0cef9cd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory.cpp @@ -207,10 +207,13 @@ Pokemon::SegmentHooks story_hooks(SingleSwitchProgramEnvironment& env, StoryEnv& return Pokemon::outcome_failed("wrong_save", error); } story.supplies = story.saved_supplies; - // Every reload, so each verify run starts from the bag as the - // save holds it, not from a count once read wrong or not at - // all (console B, 2026-11-03: 0 Potions in all 3 runs). - read_bag_supplies(story, story.start_menu); + // Until read in full, so each verify run starts from the bag + // as the save holds it, not from a count once read wrong or + // not at all (console B, 2026-11-03: 0 Potions in all 3 + // runs). Once read, a reload of the same save restores it. + if (!story.bag_read){ + read_bag_supplies(story, story.start_menu); + } }catch (OperationFailedException& e){ return Pokemon::outcome_failed("reload_failed", e.message()); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp index 7f0789684a..3a4d114578 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.cpp @@ -4,6 +4,7 @@ * */ +#include #include "CommonFramework/Exceptions/ProgramFinishedException.h" #include "PokemonFRLG_AutoStoryAbilities.h" @@ -19,25 +20,30 @@ namespace{ Outcome mart(Logger& logger, const MartPlan& plan, StoryAbilities& abilities){ const MartResult result = run_mart(logger, abilities.mart, plan); const std::string message = mart_message(plan, result); - const bool ok = result.end == MartEnd::DONE || result.end == MartEnd::NOTHING_TO_BUY; logger.log(message, result.end == MartEnd::DONE ? COLOR_BLACK : COLOR_RED); - return ok ? Pokemon::outcome_ok() : Pokemon::outcome_failed(std::string("mart_") + std::string(mart_end_name(result.end)), message); + if (result.end == MartEnd::NOTHING_TO_BUY){ + return Pokemon::outcome_unchanged(); + } + return result.end == MartEnd::DONE ? Pokemon::outcome_ok() : Pokemon::outcome_failed(std::format("mart_{}", mart_end_name(result.end)), message); } Outcome teach(Logger& logger, const TeachPlan& plan, StoryAbilities& abilities){ const TeachResult result = run_teach(logger, abilities.teach, abilities.members, plan); - // NO_ITEM: skipped, with run_teach()'s log line. - if (result.end == TeachEnd::LEARNED || result.end == TeachEnd::ALREADY_KNOWN || result.end == TeachEnd::NO_ITEM){ + if (result.end == TeachEnd::LEARNED){ return Pokemon::outcome_ok(); } - return Pokemon::outcome_failed(std::string("teach_") + std::string(teach_end_name(result.end)), teach_message(plan, result)); + // NO_ITEM: skipped, with run_teach()'s log line. + if (result.end == TeachEnd::ALREADY_KNOWN || result.end == TeachEnd::NO_ITEM){ + return Pokemon::outcome_unchanged(); + } + return Pokemon::outcome_failed(std::format("teach_{}", teach_end_name(result.end)), teach_message(plan, result)); } Outcome level(Logger& logger, const LevelCheck& check, StoryAbilities& abilities){ const LevelResult result = run_level_check(logger, abilities.members, check); switch (result.end){ case LevelEnd::REACHED: - return Pokemon::outcome_ok(); + return Pokemon::outcome_unchanged(); case LevelEnd::BELOW: return Pokemon::outcome_failed("level_below", std::to_string(*result.level) + " < " + std::to_string(check.level)); case LevelEnd::UNREAD: diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h index a6f787b9d1..add8e48eff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h @@ -44,7 +44,8 @@ struct StoryAbilities{ // the segment stops without reloading. Any other end but success is a // failed Outcome; a MART that buys nothing because the money doesn't // cover it, and a TEACH whose TM isn't in the TM CASE, succeed, with the -// reason logged. +// reason logged. Those, a TEACH of a move the member knows and a LEVEL +// reached change nothing in the game (Outcome::changed_nothing). std::optional run_ability_game_step( Logger& logger, VideoStream* stream, const Pokemon::StoryStep& step, StoryAbilities& abilities ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp index 8a7c6f35af..17ff0d486c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryAbilities_Tests.cpp @@ -123,8 +123,9 @@ Pokemon::StoryStep game_step(std::string action, Pokemon::StoryActionArgs args){ return step; } -// The failure name the step ends with ("" for success); "none" if it -// isn't one of these steps. +// The failure name the step ends with ("" for success, "unchanged" for +// one that changed nothing in the game); "none" if it isn't one of these +// steps. std::string run_step(StubGame& game, const Pokemon::StoryStep& step){ QuietLogger logger; const MemberReader members = [&game](size_t slot) -> std::optional{ @@ -135,7 +136,10 @@ std::string run_step(StubGame& game, const Pokemon::StoryStep& step){ }; StoryAbilities abilities{members, game.mart, game.teach, game.patch, game.fossils}; const std::optional outcome = run_ability_game_step(logger, nullptr, step, abilities); - return outcome ? outcome->failure : "none"; + if (!outcome){ + return "none"; + } + return outcome->changed_nothing ? "unchanged" : outcome->failure; } struct StepCase{ @@ -150,13 +154,13 @@ std::vector step_cases(){ const Pokemon::StoryStep mart = mart_step("mart", "", {.map = "PewterCity_Mart", .lines = {{"potion", 5}}, .budget = 2000}); const Pokemon::StoryStep grind = grind_step("grind", "", {.member = 0, .level = 20, .max_encounters = 5, .pace = Pokemon::Direction::EAST, .heal_every = 0}, {}); return { - {"level reached", none, level_step("check", "", {.slot = 0, .level = 16}), ""}, + {"level reached", none, level_step("check", "", {.slot = 0, .level = 16}), "unchanged"}, {"level below", none, level_step("check", "", {.slot = 0, .level = 17}), "level_below"}, {"level unread", [](StubGame& game){ game.level.reset(); }, level_step("check", "", {.slot = 0, .level = 16}), "level_unread"}, - {"a Mart with too little money succeeds", [](StubGame& game){ game.mart.money = 100; }, mart, ""}, + {"a Mart with too little money succeeds", [](StubGame& game){ game.mart.money = 100; }, mart, "unchanged"}, {"a Mart purchase that fails", none, mart, "mart_failed"}, - {"a move it knows already succeeds", none, teach_step("teach", "", {.item = "hm03", .move = "surf", .member = 0}), ""}, - {"a TM not in the TM Case is skipped", none, teach_step("teach", "", {.item = "tm03", .move = "water-pulse", .member = 0, .forget_move = "water-gun"}), ""}, + {"a move it knows already succeeds", none, teach_step("teach", "", {.item = "hm03", .move = "surf", .member = 0}), "unchanged"}, + {"a TM not in the TM Case is skipped", none, teach_step("teach", "", {.item = "tm03", .move = "water-pulse", .member = 0, .forget_move = "water-gun"}), "unchanged"}, {"a level that can't be read stops a GRIND", [](StubGame& game){ game.level.reset(); }, grind, "grind_unread"}, {"a GRIND without a nurse", none, game_step(GRIND_ACTION, {{"slot", int64_t(1)}, {"level", int64_t(20)}}), "bad_args"}, {"no YES/NO at the fossil", none, fossil_step("fossil", "", Fossil::HELIX), "fossil_failed"}, @@ -178,6 +182,27 @@ UnitTestResult test_ability_steps(){ } +// TEACH and MART steps are preparation, once per save: a retry from the +// same save skips one that changed nothing. A LEVEL check, which follows +// a GRIND, and the GRIND run every attempt. +UnitTestResult test_once_per_save_steps(){ + const std::vector once{ + teach_step("teach", "", {.item = "tm03", .move = "water-pulse", .member = 0, .forget_move = "tail-whip"}), + mart_step("mart", "", {.map = "CeruleanCity_Mart", .lines = {{.item = "potion", .quantity = 3}}, .budget = 1500, .money_floor = 1500}), + }; + for (const Pokemon::StoryStep& step : once){ + if (!step.once_per_save){ + return step.name + ": expected once per save."; + } + } + const Pokemon::StoryStep grind = grind_step("grind", "", {.member = 0, .level = 20, .max_encounters = 5, .pace = Pokemon::Direction::EAST, .heal_every = 0}, {}); + if (grind.once_per_save || level_step("level", "", {.slot = 0, .level = 16}).once_per_save){ + return "GRIND and LEVEL: expected every attempt."; + } + return true; +} + + // A shiny in a GRIND stops the program, not the checkpoint: a reload // would lose it. UnitTestResult test_grind_shiny_stops(){ @@ -229,6 +254,10 @@ const AutoStoryAbilitiesCase AUTO_STORY_ABILITIES_CASES[] = { .input = {"the LEVEL step's args", test_level_args}, .expectation = {}, }, + { + .input = {"TEACH and MART run once per save", test_once_per_save_steps}, + .expectation = {}, + }, }; void add_tests_AutoStoryAbilities(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp index 436ad44b6e..79320faca4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.cpp @@ -564,6 +564,34 @@ void step_once(ProControllerContext& context, Direction direction, std::optional context.wait_for_all_requests(); } +std::optional step_until_seen(int max_tiles, const std::function& step, const std::function& seen){ + for (int tiles = 1; tiles <= max_tiles; tiles++){ + step(); + if (seen()){ + return tiles; + } + } + return std::nullopt; +} + +std::optional step_into_line( + ConsoleHandle& console, ProControllerContext& context, + Direction direction, std::optional facing, int max_tiles +){ + return step_until_seen( + max_tiles, + [&]{ + step_once(context, direction, facing); + facing = direction; + }, + [&]{ + WhiteDialogWatcher message(COLOR_RED); + BattleScreenWatcher battle(COLOR_RED); + return wait_until(console, context, TRAINER_LINE_WATCH, {message, battle}) >= 0; + } + ); +} + void face_wall(ProControllerContext& context, Direction direction){ pbf_press_dpad(context, dpad(direction), TURN_TAP, TURN_SETTLE); context.wait_for_all_requests(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h index 17f73ead43..4b813e3f77 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryActions.h @@ -15,6 +15,7 @@ #define PokemonAutomation_PokemonFRLG_AutoStoryActions_H #include +#include #include #include #include diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index 4a83b18511..fb7cb364eb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -74,25 +74,6 @@ constexpr Milliseconds MOVE_LIST_TIMEOUT = 5000ms; // pixel inside. const ImageFloatBox STATUS_BADGE_BOX(146.0 / 240, 99.0 / 160, 12.0 / 240, 4.0 / 160); -StatusCondition read_status_badge(const ImageViewRGB32& badge){ - const ImageStats stats = image_stats(badge); - const double r = stats.average.r; - const double g = stats.average.g; - const double b = stats.average.b; - const double off_white = std::abs(r - 255) + std::abs(g - 255) + std::abs(b - 217); - if (off_white < 60){ - return StatusCondition::NONE; - } - if (r > 200 && g < 200 && b > 180){ - return StatusCondition::POISON; - } - // Not measured yet: PAR's badge is taken to be the yellow one. - if (r > 180 && g > 150 && b < 140){ - return StatusCondition::PARALYSIS; - } - return StatusCondition::OTHER; -} - enum class BattleScreen{ // Keep in step with screen_name(). @@ -610,10 +591,13 @@ class BattleLoop{ const TurnAction action = m_decisions.turn(status); m_evolution.turn_taken(action.choice); m_console.log(std::format( - "Battle: turn {}, HP {} ({:.0f}% of the bar), {}, {} Potions, {} Antidotes, {} Parlyz Heals.", + "Battle: turn {}, HP {} ({:.0f}% of the bar), {}, {} Potions, {} Antidotes, {} Parlyz Heals, {} Awakenings.", m_decisions.turns(), status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green", 100 * status.hp_fill, - status_name(status.status), m_supplies.potions, m_supplies.antidotes, m_supplies.parlyz_heals + status_name(status.status), m_supplies.potions, m_supplies.antidotes, m_supplies.parlyz_heals, m_supplies.awakenings )); + if (!action.heal_reason.empty()){ + m_console.log("Battle: " + action.heal_reason + "."); + } dump_debug_image(m_console, "AutoStory/battle", std::format("turn{}-menu", m_decisions.turns()), screen); switch (action.choice){ case TurnChoice::RUN: @@ -626,6 +610,9 @@ class BattleLoop{ case TurnChoice::ANTIDOTE: m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, item_row(m_supplies, "antidote"), "antidote", m_checks, m_language))); return; + case TurnChoice::AWAKENING: + m_decisions.turn_done(action.choice, item_result(use_item(m_console, m_context, item_row(m_supplies, "awakening"), "awakening", m_checks, m_language))); + return; case TurnChoice::MOVE: m_console.log(std::format("Battle: move {}.", action.slot + 1)); m_refusal.move_chosen(current_time()); @@ -803,12 +790,38 @@ std::string_view status_name(StatusCondition status){ return "PSN"; case StatusCondition::PARALYSIS: return "PAR"; + case StatusCondition::SLEEP: + return "SLP"; case StatusCondition::OTHER: return "a status"; } return "?"; } +StatusCondition read_status_badge(const ImageViewRGB32& badge){ + const ImageStats stats = image_stats(badge); + const double r = stats.average.r; + const double g = stats.average.g; + const double b = stats.average.b; + const double off_white = std::abs(r - 255) + std::abs(g - 255) + std::abs(b - 217); + if (off_white < 60){ + return StatusCondition::NONE; + } + if (r > 200 && g < 200 && b > 180){ + return StatusCondition::POISON; + } + // SLP's grey-olive badge with its cream letters: red and green even, + // blue lower but above the yellow taken for PAR. + if (std::abs(r - g) < 20 && b < g - 15 && b > 140 && r < 235){ + return StatusCondition::SLEEP; + } + // Not measured yet: PAR's badge is taken to be the yellow one. + if (r > 180 && g > 150 && b < 140){ + return StatusCondition::PARALYSIS; + } + return StatusCondition::OTHER; +} + PartyStatus read_party_status(const ImageViewRGB32& screen){ const ImageViewRGB32 game = extract_box_reference(screen, GameSettings::instance().GAME_BOX); const HpBarReading bar = read_player_hp_bar(game); @@ -827,36 +840,35 @@ bool battle_shows(const ImageViewRGB32& screen){ } // The count the story keeps for `item`, or null for an item it doesn't count. -static int* count_slot(Supplies& supplies, const std::string& item){ +static int Supplies::* count_member(const std::string& item){ if (item == "potion"){ - return &supplies.potions; + return &Supplies::potions; } if (item == "antidote"){ - return &supplies.antidotes; + return &Supplies::antidotes; } if (item == "parlyz-heal"){ - return &supplies.parlyz_heals; + return &Supplies::parlyz_heals; + } + if (item == "awakening"){ + return &Supplies::awakenings; } return nullptr; } +static int* count_slot(Supplies& supplies, const std::string& item){ + int Supplies::* const member = count_member(item); + return member == nullptr ? nullptr : &(supplies.*member); +} + int item_count(const Supplies& supplies, const std::string& item){ - if (item == "potion"){ - return supplies.potions; - } - if (item == "antidote"){ - return supplies.antidotes; - } - if (item == "parlyz-heal"){ - return supplies.parlyz_heals; - } - return 0; + int Supplies::* const member = count_member(item); + return member == nullptr ? 0 : supplies.*member; } // Whether the story keeps a count for `item`. static bool counted(const std::string& item){ - Supplies probe; - return count_slot(probe, item) != nullptr; + return count_member(item) != nullptr; } int item_row(const Supplies& supplies, const std::string& item){ @@ -878,6 +890,7 @@ std::vector set_from_bag(Supplies& supplies, const std::vector unread; for (const BagRow& row : rows){ @@ -906,6 +919,7 @@ std::vector set_from_loaded_bag(Supplies& supplies, Supplies& saved saved.potions = supplies.potions; saved.antidotes = supplies.antidotes; saved.parlyz_heals = supplies.parlyz_heals; + saved.awakenings = supplies.awakenings; saved.pocket = supplies.pocket; return unread; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h index cd651c25f5..8b30d6af46 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h @@ -7,7 +7,9 @@ * is put back on FIGHT and the move list's top left, since the game * remembers both, then onto the move BattleDecisions picks. A Potion is * used when the HP bar turns yellow or red, an Antidote (once a battle) - * when the status reads PSN at two turns in a row; after the battle, PSN + * when the status reads PSN at two turns in a row, an Awakening in a + * trainer's battle when it reads SLP; each turn's reason for a Potion or + * none is logged. After the battle, PSN * and PAR are cured from the bag. Move prompts, an evolution after the * battle and a fainted lead are as PokemonFRLG_AutoStoryBattleDecisions.h * says. @@ -35,6 +37,7 @@ #include "PokemonFRLG_AutoStoryBattleData.h" #include "PokemonFRLG_AutoStoryParty.h" #include "PokemonFRLG_AutoStoryItemsPocket.h" +#include "PokemonFRLG_AutoStoryStatusBadge.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -63,7 +66,8 @@ enum class BattleEnd{ // What the HP bar (read_player_hp_bar()) and the status badge of the // player's Pokemon show, on a battle screen with its box. The badge's // place measured on console B's captures (2026-11-01): off-white -// (255, 255, 217) with no status, (228, 168, 212) for PSN. +// (255, 255, 217) with no status, (228, 168, 212) for PSN, (202, 203, 168) +// for SLP (2026-11-03, after the Cerulean rival's Sleep Powder). struct PartyStatus{ bool hp_seen = false; bool hp_yellow = false; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp index 5b60553788..ad3c1eb405 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.cpp @@ -5,7 +5,9 @@ */ #include +#include #include +#include #include "PokemonFRLG_AutoStoryBattleDecisions.h" namespace PokemonAutomation{ @@ -60,10 +62,36 @@ std::optional trainer_attack_slot(const PartyMember& usable, const Suppl return attack_slot_against(usable, supplies.foes); } -// A Potion this turn: whenever the bar isn't green, unless the last hit -// took a Potion's worth or more (`seen_hit`, 0 if not seen). -bool wants_potion(const PartyStatus& status, double seen_hit){ - return (status.hp_red || status.hp_yellow) && seen_hit < POTION_HP; +// The item a turn uses, if any, and why one was or wasn't, for the log. +struct ItemTurn{ + TurnChoice choice = TurnChoice::MOVE; + std::string reason = {}; +}; + +std::string_view bar_name(const PartyStatus& status){ + return status.hp_red ? "red" : status.hp_yellow ? "yellow" : "green"; +} + +// The item this turn, from the bar and the badge as read (`seen_hit` the +// HP the foe's last hit took, 0 if not seen): a Potion whenever the bar +// isn't green, unless the last hit took a Potion's worth or more; asleep, +// an Awakening unless the bar is red. +ItemTurn item_turn(const Supplies& supplies, const PartyStatus& status, double seen_hit, int awakenings){ + const bool hurt = status.hp_red || status.hp_yellow; + const bool asleep = status.status == StatusCondition::SLEEP; + if (hurt && supplies.potions > 0 && seen_hit < POTION_HP){ + return {TurnChoice::POTION, std::format("a Potion: HP {}, its last hit {:.0f} HP", bar_name(status), seen_hit)}; + } + if (asleep && awakenings > 0 && !status.hp_red){ + return {TurnChoice::AWAKENING, std::format("an Awakening: asleep at HP {}", bar_name(status))}; + } + if (!hurt){ + return {}; + } + return {TurnChoice::MOVE, supplies.potions <= 0 + ? std::string("no Potion: none left") + : std::format("no Potion: the foe's last hit {:.0f} HP would undo one", seen_hit) + }; } // The lead's HP from the bar's share, if it showed and POKEMON SKILLS was @@ -135,14 +163,19 @@ TurnAction BattleDecisions::lead_turn(const PartyStatus& status){ return TurnAction{.choice = TurnChoice::RUN}; } see_hit(status); - if (!m_items_off && m_supplies.potions > 0 && wants_potion(status, m_seen_hit)){ - return TurnAction{.choice = TurnChoice::POTION}; + // Awakenings are kept for trainers: a wild battle with a status is run from. + const int awakenings = m_kind == BattleKind::TRAINER ? m_supplies.awakenings : 0; + const ItemTurn items = m_items_off ? ItemTurn{} : item_turn(m_supplies, status, m_seen_hit, awakenings); + if (items.choice != TurnChoice::MOVE){ + return TurnAction{.choice = items.choice, .heal_reason = items.reason}; } if (!m_items_off && m_psn_reads >= PSN_READS && !m_antidote_used && m_supplies.antidotes > 0){ m_antidote_used = true; - return TurnAction{.choice = TurnChoice::ANTIDOTE}; + return TurnAction{.choice = TurnChoice::ANTIDOTE, .heal_reason = items.reason}; } - return move_turn(); + TurnAction action = move_turn(); + action.heal_reason = items.reason; + return action; } void BattleDecisions::see_hit(const PartyStatus& status){ @@ -229,6 +262,10 @@ void BattleDecisions::turn_done(TurnChoice choice, TurnResult result){ case TurnChoice::ANTIDOTE: m_supplies.antidotes--; return; + case TurnChoice::AWAKENING: + m_supplies.awakenings--; + m_supplies.status = StatusCondition::NONE; + return; case TurnChoice::RUN: case TurnChoice::MOVE: return; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h index 2d4c0730ff..9d07983f3d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleDecisions.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "Common/Cpp/Time.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "PokemonFRLG_AutoStoryBattle.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h index 4de3040e02..ece6d6522b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleTurns.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "Common/Cpp/Time.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "PokemonFRLG_AutoStoryBattle.h" @@ -29,6 +30,7 @@ enum class TurnChoice{ RUN, POTION, ANTIDOTE, + AWAKENING, MOVE, }; @@ -37,6 +39,9 @@ struct TurnAction{ TurnChoice choice = TurnChoice::MOVE; // For MOVE, the move list's slot. size_t slot = BOTTOM_LEFT_MOVE; + // Why a Potion was or wasn't used, for the log; empty when none was + // weighed (green HP, awake). + std::string heal_reason = {}; }; // What came of a TurnAction. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 9886e3cfd3..dfee2a6e47 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -164,12 +164,26 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ const Direction direction = arg(step, "direction"); - step_once(env.context, direction, facing_of(state.pose)); + int tiles_stepped = 1; + if (step.action == TRAINER_LINE_VARIANT){ + const std::optional stepped = step_into_line(env.console, env.context, direction, facing_of(state.pose), TRAINER_LINE_TILES); + if (!stepped){ + return Pokemon::outcome_failed("no_trainer", std::format("{} tiles {}", TRAINER_LINE_TILES, direction_name(direction))); + } + env.console.log(std::format("Story: {}: a trainer saw the player after {} tile(s).", step.name, *stepped)); + tiles_stepped = *stepped; + }else{ + step_once(env.context, direction, facing_of(state.pose)); + } const std::vector tiles = Pokemon::tiles_of(state.pose); if (tiles.size() != 1){ return Pokemon::outcome_ok(); } - return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, tiles[0].next(direction), direction})); + TilePos onto = tiles[0]; + for (int c = 0; c < tiles_stepped; c++){ + onto = onto.next(direction); + } + return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, onto, direction})); } Outcome battle(StoryEnv& env, const StoryStep& step){ @@ -319,6 +333,7 @@ std::string save_card_place(const std::string& map){ {"PewterCity", "pewter-city"}, {"Route3", "route-3"}, {"Route4", "route-4"}, + {"CeruleanCity", "cerulean-city"}, }; for (const auto& [prefix, place] : PLACES){ if (map == prefix || map.rfind(prefix + "_", 0) == 0){ @@ -683,11 +698,13 @@ void read_bag_supplies(StoryEnv& env, StartMenu menu){ env.console.log("Couldn't read the Items pocket; going on with the checkpoint's items.", COLOR_ORANGE); return; } - for (const std::string& item : set_from_loaded_bag(env.supplies, env.saved_supplies, rows)){ + const std::vector unread = set_from_loaded_bag(env.supplies, env.saved_supplies, rows); + for (const std::string& item : unread){ env.console.log(std::format( "Story: couldn't read how many {} the bag holds; counting {}.", item, item_count(env.supplies, item) ), COLOR_ORANGE); } + env.bag_read = unread.empty(); } namespace{ @@ -723,7 +740,7 @@ Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& // card's place is checked when the save is loaded (check_save_place()), // and the start check compares the screen with the frame kept when the // program last saved there. With none kept, it passes. - Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor); + Pokemon::Checkpoint checkpoint = Pokemon::build_story_checkpoint(data, executor, &env.prepared); add_start_check( checkpoint, start_pose(data), [&env, id = data.id]{ return read_console_start(env, id); }, @@ -738,6 +755,8 @@ Pokemon::Checkpoint build_checkpoint(const StoryCheckpoint& data, StoryExecutor& keep_next_start_frame(env, id); env.has_save = true; env.saved_supplies = env.supplies; + env.prepared.clear(); + env.bag_read = false; return Pokemon::outcome_ok(); }); }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index 803c3b73fe..d61515f3a3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -67,6 +67,12 @@ struct StoryEnv{ std::string start_map = {}; // That checkpoint's START menu: a reload reads the bag again with it. StartMenu start_menu = StartMenu::BEFORE_POKEMON; + // The once_per_save steps done from the last save that changed + // nothing: a retry after a reload skips them. Emptied by a save. + Pokemon::PreparedSteps prepared = {}; + // The last save's Items pocket was read in full (read_bag_supplies()): + // a reload restores `saved_supplies` without reading it again. + bool bag_read = false; // The frames of where each checkpoint starts, for the start check: a // save at a checkpoint's end keeps one for the next checkpoint. StartFrameStore start_frames = {}; @@ -90,7 +96,8 @@ void read_lead_moves(StoryEnv& env, StartMenu menu); // After a save is loaded, with START's menu `menu`: the Items pocket's // counts as read (set_from_loaded_bag()), in place of the row's, which // are kept if nothing can be read. Only with the full menu: the rows -// before it carry the items they have. +// before it carry the items they have. Sets `bag_read` when every count +// was read. void read_bag_supplies(StoryEnv& env, StartMenu menu); // Does FRLG's kinds of story step on the console, each with its row of diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h index 3be3a52f88..c3a445e01e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryIntro.h @@ -22,7 +22,7 @@ #include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckLevel.h" #include "Pokemon/Navigation/Pokemon_Grid.h" -#include "PokemonFRLG_AutoStoryPresses.h" +#include "PokemonFRLG_AutoStoryTrainerLine.h" #include "PokemonFRLG_AutoStoryRngReturns.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp index bad42981d9..79cccc6be2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryItems_Tests.cpp @@ -8,11 +8,14 @@ */ #include +#include #include #include #include #include +#include #include +#include "Common/Cpp/Color.h" #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Logging/AbstractLogger.h" #include "Common/Cpp/TestRunners/UnitTest.h" @@ -202,6 +205,42 @@ UnitTestResult test_loaded_bag_other_items(Logger&){ return true; } +// Awakenings, bought at Cerulean after a MOON STONE took its row: counted +// from the bag and found in their row. +UnitTestResult test_loaded_bag_awakenings(Logger&){ + Supplies row; + Supplies saved = row; + set_from_loaded_bag(row, saved, {{"", 1}, {"parlyz-heal", 1}, {"potion", 15}, {"awakening", 3}}); + if (row.awakenings != 3 || saved.awakenings != 3 || item_count(row, "awakening") != 3 || item_row(row, "awakening") != 3){ + return std::format( + "Expected 3 Awakenings in row 3, now and for a reload; got {} and {}, row {}.", + row.awakenings, saved.awakenings, item_row(row, "awakening") + ); + } + return true; +} + +// The status badge's mean color on console B's captures: none and PSN +// (2026-11-01), and SLP after the Cerulean rival's Sleep Powder +// (2026-11-03, m56 run 2, turns 6 and 7 at 34/65 and 13/65 HP), which +// read as "a status". +UnitTestResult test_status_badge(Logger&){ + const std::vector> cases = { + {combine_rgb(255, 255, 217), StatusCondition::NONE}, + {combine_rgb(228, 168, 212), StatusCondition::POISON}, + {combine_rgb(202, 203, 168), StatusCondition::SLEEP}, + }; + for (const auto& [color, expected] : cases){ + ImageRGB32 badge(12, 4); + badge.fill(color); + const StatusCondition read = read_status_badge(badge); + if (read != expected){ + return std::format("Badge 0x{:08x}: expected {}, got {}.", color, status_name(expected), status_name(read)); + } + } + return true; +} + // The pocket's rows as read: an unread name keeps its row, so the rows // below it are still read; the rows end at CANCEL, or at the last name read. UnitTestResult test_pocket_rows_unread(Logger&){ @@ -384,6 +423,14 @@ const AutoStoryItemsTestCase AUTO_STORY_ITEMS_CASES[] = { .input = {.name = "a wild battle seen late is placed where it stopped the leg", .body = test_late_battle_placed}, .expectation = {.description = "places late wild battle at interruption point"}, }, + { + .input = {.name = "Awakenings counted from the bag", .body = test_loaded_bag_awakenings}, + .expectation = {.description = "verifies awakenings are read and tracked from bag contents"}, + }, + { + .input = {.name = "the status badge: none, PSN, SLP", .body = test_status_badge}, + .expectation = {.description = "detects status conditions accurately from status bar image"}, + }, }; } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp index 1fa3030b4d..594ed80b7d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp @@ -145,6 +145,7 @@ Pokemon::StoryStep mart_step(std::string name, std::string why, const MartPlan& step.why = std::move(why); step.action = MART_ACTION; step.args = mart_args(plan); + step.once_per_save = true; return step; } @@ -404,6 +405,8 @@ void count_supplies(Supplies& supplies, std::string_view item, size_t quantity){ count = &Supplies::antidotes; }else if (item == "parlyz-heal"){ count = &Supplies::parlyz_heals; + }else if (item == "awakening"){ + count = &Supplies::awakenings; } if (count == nullptr){ return; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h index 672297f7be..c49592fbe7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h @@ -87,15 +87,15 @@ std::string mart_message(const MartPlan& plan, const MartResult& result); // Counts `quantity` of `item` into `supplies`, if it is one the battles -// use (Potions, Antidotes, Parlyz Heals); a new one goes to the end of the +// use (Potions, Antidotes, Parlyz Heals, Awakenings); a new one goes to the end of the // pocket, where the bag adds it. void count_supplies(Supplies& supplies, std::string_view item, size_t quantity); // The console's Mart. The money box and the quantity box have no reader // yet, so the money is the table's floor and the quantity is typed by -// presses. Potions, Antidotes and Parlyz Heals bought are counted into -// `supplies`. +// presses. Potions, Antidotes, Parlyz Heals and Awakenings bought are +// counted into `supplies`. class ConsoleMartActions : public MartActions{ public: ConsoleMartActions(ConsoleHandle& console, ProControllerContext& context, Language language, Supplies& supplies); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartPlan.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartPlan.h index a9b7237109..c806683bab 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartPlan.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartPlan.h @@ -69,7 +69,8 @@ Pokemon::StoryActionArgs mart_args(const MartPlan& plan); // names an item its Mart doesn't sell. std::optional mart_plan_of(const Pokemon::StoryActionArgs& args); -// The table's Mart step. +// The table's Mart step, once per save (StoryStep::once_per_save): a +// retry from the same save skips it when it had nothing to buy. Pokemon::StoryStep mart_step(std::string name, std::string why, const MartPlan& plan); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp index 7605472336..29a1d701ba 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart_Tests.cpp @@ -379,7 +379,8 @@ UnitTestResult test_mart_stock(){ } -// Potions, Antidotes and Parlyz Heals bought go into the battles' supplies. +// Potions, Antidotes, Parlyz Heals and Awakenings bought go into the +// battles' supplies. UnitTestResult test_count_supplies(){ Supplies supplies; supplies.pocket = {"potion"}; @@ -388,9 +389,11 @@ UnitTestResult test_count_supplies(){ count_supplies(supplies, "potion", 2); count_supplies(supplies, "repel", 4); count_supplies(supplies, "poke-ball", 5); - if (supplies.potions != 3 || supplies.antidotes != 3 || supplies.pocket != std::vector{"potion", "antidote"}){ - return std::format("Supplies {} potions, {} antidotes, {} pocket rows.", - supplies.potions, supplies.antidotes, supplies.pocket.size()); + count_supplies(supplies, "awakening", 3); + const std::vector pocket{"potion", "antidote", "awakening"}; + if (supplies.potions != 3 || supplies.antidotes != 3 || supplies.awakenings != 3 || supplies.pocket != pocket){ + return std::format("Supplies {} potions, {} antidotes, {} awakenings, {} pocket rows.", + supplies.potions, supplies.antidotes, supplies.awakenings, supplies.pocket.size()); } return true; } 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 c2b984aaf5..890686ab36 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp @@ -3,18 +3,26 @@ * From: https://github.com/PokemonAutomation/ * * Which rows of the story table a run takes (plan_story_run()) with the - * RNG programs' handoffs on and off, and the rows the handoffs split or - * join. + * RNG programs' handoffs on and off, the rows the handoffs split or + * join, Misty in Cerulean Gym, and what 00.15 runs before the rival. * */ +#include #include +#include #include #include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryGrind.h" +#include "PokemonFRLG_AutoStoryMart.h" #include "PokemonFRLG_AutoStoryTable.h" +#include "PokemonFRLG_AutoStoryTeach.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -131,7 +139,7 @@ class Test_RunPlan : public UnitTest{ const RunPlanScenario m_scenario; }; -const std::string TODAY = "00.01 00.02 00.03 00.04 00.05 00.06 00.07 00.08 00.09 00.10 00.11 00.12 00.12c 00.13"; +const std::string TODAY = "00.01 00.02 00.03 00.04 00.05 00.06 00.07 00.08 00.09 00.10 00.11 00.12 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16"; const RunPlanScenario RUN_PLAN_CASES[] = { { @@ -142,6 +150,10 @@ const RunPlanScenario RUN_PLAN_CASES[] = { .input = {.name = "handoffs off: a range", .first = "00.02", .last = "00.04"}, .expectation = {.expected_ids = "00.02 00.03 00.04"}, }, + { + .input = {.name = "handoffs off: Mt. Moon to Nugget Bridge", .first = "00.13", .last = "00.16"}, + .expectation = {.expected_ids = "00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16"}, + }, { .input = { .name = "SID Helper: 00.01 stops on the keyboard", @@ -219,11 +231,11 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Gift RNG off: 00.12b is passed over", .first = "00.11"}, - .expectation = {.expected_ids = "00.11 00.12 00.12c 00.13"}, + .expectation = {.expected_ids = "00.11 00.12 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16"}, }, { .input = {.name = "Gift RNG off: 00.12b runs when started at", .first = "00.12b"}, - .expectation = {.expected_ids = "00.12b 00.12c 00.13"}, + .expectation = {.expected_ids = "00.12b 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16"}, }, { .input = { @@ -249,7 +261,7 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Starter RNG alone: 00.12b runs when started at", .first = "00.12b", .handoffs = {.starter_rng = true}}, - .expectation = {.expected_ids = "00.12b 00.12c 00.13"}, + .expectation = {.expected_ids = "00.12b 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16"}, }, { .input = { @@ -325,6 +337,275 @@ UnitTestResult test_after_sid_helper_row(){ return true; } +// The index of the first step of `steps` from `from` that `matches`, or +// steps.size(). +size_t find_step(const std::vector& steps, size_t from, const std::function& matches){ + for (size_t c = from; c < steps.size(); c++){ + if (matches(steps[c])){ + return c; + } + } + return steps.size(); +} + +// `step`'s pose arg `key`, or nothing. +std::optional pose_arg(const StoryStep& step, std::string_view key){ + const Pokemon::GridPose* pose = Pokemon::value_if_at_it(step.args, step.args.find(key)); + return pose == nullptr ? std::nullopt : std::optional(Pokemon::pose_of(*pose)); +} + +// `step`'s pose arg `key` as a StoryPose, or nothing. +std::optional story_pose_arg(const StoryStep& step, std::string_view key){ + const std::optional pose = pose_arg(step, key); + return pose ? story_pose(*pose) : std::nullopt; +} + +// `step`'s MART, TEACH or GRIND plan, or nothing when it is another step. +std::optional mart_of(const StoryStep& step){ + return step.action == MART_ACTION ? mart_plan_of(step.args) : std::nullopt; +} +std::optional teach_of(const StoryStep& step){ + return step.action == TEACH_ACTION ? teach_plan_of(step.args) : std::nullopt; +} +std::optional grind_of(const StoryStep& step){ + return step.action == GRIND_ACTION ? grind_plan_of(step.args) : std::nullopt; +} + +// The GRIND at `grind`'s patch, the target of the route right before it, +// and its nurse; nothing without either. +std::optional> grind_trip(const std::vector& steps, size_t grind){ + const std::optional patch = grind == 0 || grind >= steps.size() ? std::nullopt : pose_arg(steps[grind - 1], "target"); + const std::optional nurse = grind >= steps.size() ? std::nullopt : pose_arg(steps[grind], "nurse"); + if (!patch || !nurse){ + return std::nullopt; + } + return std::pair{*patch, *nurse}; +} + +// Whether a route plans from `from` to `to` (ending facing as `to` does). +bool plans(const Pokemon::Pose& from, const Pokemon::Pose& to){ + const std::optional start = story_pose(from); + const std::optional goal = story_pose(to); + if (!start || !goal){ + return false; + } + return plan_overworld_route( + story_maps(), MapPosition{start->map, start->tile}, RouteGoal{MapPosition{goal->map, goal->tile}, goal->facing}, + default_route_costs(), start->facing.value_or(Direction::NORTH) + ).has_value(); +} + +// 00.15, before the rival, from the Center: first TM03 Water Pulse over +// Tail Whip if the lead doesn't know it, so the sim plays it in the +// GRIND; Potions from Cerulean's Mart (a loaded save's bag may hold too +// few for the wild battles a GRIND fights), and at its money floor 2 or +// more Awakenings for the rival's Sleep Powder; then a GRIND on Route 4's +// grass east of Mt. Moon to Lv22, where console B's lead beat the rival +// 00.15b fights, healing at Cerulean's Center; its trip there plans both ways. +UnitTestResult test_cerulean_mart_and_grind(){ + const StoryCheckpoint& row = story_checkpoints()[row_index("00.15")]; + const std::vector& steps = row.steps; + const std::optional start = row.start ? story_pose(Pokemon::pose_of(*row.start)) : std::nullopt; + if (!start || start->map != "CeruleanCity_PokemonCenter_1F"){ + return "00.15: expected it to start in Cerulean's Center."; + } + const std::optional teach = steps.empty() ? std::nullopt : teach_of(steps[0]); + if (!teach || teach->item != "tm03" || teach->move != "water-pulse" || teach->member != 0 || teach->forget_move != "tail-whip"){ + return "00.15: expected it to start with TM03 Water Pulse over the lead's Tail Whip."; + } + const size_t mart = find_step(steps, 0, [](const StoryStep& step){ + const std::optional plan = mart_of(step); + return plan && plan->map == "CeruleanCity_Mart" && !plan->lines.empty() && plan->lines[0].item == "potion"; + }); + const size_t grind = find_step(steps, mart, [&](const StoryStep& step){ + const std::optional plan = grind_of(step); + return plan && plan->member == 0 && plan->level >= 22; + }); + if (mart == steps.size() || grind == steps.size()){ + return "00.15: expected a Cerulean Mart step buying Potions, then a GRIND of the lead to Lv22 or more."; + } + const MartPlan plan = *mart_of(steps[mart]); + const std::optional> buys = plan.money_floor + ? plan_mart_buys(mart_stock(plan.map), plan, *plan.money_floor) + : std::nullopt; + const bool awakenings = buys && std::ranges::any_of(*buys, [](const MartBuy& buy){ + return buy.item == "awakening" && buy.quantity >= 2; + }); + if (!awakenings){ + return "00.15: expected the Mart step to buy 2 or more Awakenings at its money floor."; + } + const std::optional clerk = mart > 0 ? story_pose_arg(steps[mart - 1], "target") : std::nullopt; + if (!clerk || clerk->map != "CeruleanCity_Mart"){ + return "00.15: expected the Mart step right after a route to the clerk."; + } + const auto trip = grind_trip(steps, grind); + if (!trip){ + return "00.15: expected the GRIND right after a route to its patch, with the nurse as its target."; + } + const auto& [patch, nurse] = *trip; + const std::optional nurse_pose = story_pose(nurse); + if (!nurse_pose || nurse_pose->map != "CeruleanCity_PokemonCenter_1F" || !plans(patch, nurse) || !plans(nurse, patch)){ + return "00.15: expected the GRIND's trips to Cerulean's nurse and back to plan."; + } + return true; +} + +// 00.15b, the rival's battle as its own checkpoint, as every battle lost +// twice or more gets: it starts from a save, 00.15's on (23, 7) below his +// trigger with the nurse just before, so a verify run or a retry reloads +// right before him; and his is its only battle. First Water Pulse over +// Tail Whip if the lead doesn't know it: console B's save (2026-11-03) is +// past the TEACH that failed there, which does nothing once it is known. +UnitTestResult test_cerulean_rival_row(){ + const std::vector& checkpoints = story_checkpoints(); + const size_t index = row_index("00.15b"); + const StoryCheckpoint& rival = checkpoints[index]; + const std::optional start = rival.start ? story_pose(Pokemon::pose_of(*rival.start)) : std::nullopt; + if (!start || rival.live_start || start->map != "CeruleanCity" || !(start->tile == TilePos{23, 7}) + || save_card_place(start->map).empty() + ){ + return "00.15b: expected it to start from a save on (23, 7) in Cerulean City."; + } + std::string battles; + for (const StoryStep& step : rival.steps){ + battles += step.kind == StoryStepKind::BATTLE ? " " + step.name : ""; + } + if (battles != " rival_cerulean" || rival.steps.size() != 3 || rival.steps[1].name != "rival_trigger"){ + return "00.15b: expected a TEACH, the step onto his trigger and his battle; its battles:" + battles; + } + const std::optional teach = teach_of(rival.steps[0]); + if (rival.steps[0].kind != StoryStepKind::GAME || !teach || teach->item != "tm03" || teach->move != "water-pulse" + || teach->member != 0 || teach->forget_move != "tail-whip" + ){ + return "00.15b: expected it to start with TM03 Water Pulse over the lead's Tail Whip."; + } + const StoryCheckpoint& before = checkpoints[index - 1]; + const size_t n = before.steps.size(); + const std::optional end = n > 0 ? story_pose_arg(before.steps[n - 1], "target") : std::nullopt; + if (before.id != "00.15" || n < 2 || before.steps[n - 2].kind != StoryStepKind::HEAL + || !end || end->map != start->map || !(end->tile == start->tile) + ){ + return "00.15: expected it to end with the nurse, then the walk to (23, 7) where 00.15b starts."; + } + for (const StoryStep& step : before.steps){ + if (step.kind == StoryStepKind::BATTLE){ + return "00.15: expected no trainer battle before its save; found " + step.name + "."; + } + } + return true; +} + +// The battles in `row`, each name after a space. +std::string battle_names(const StoryCheckpoint& row){ + std::string battles; + for (const StoryStep& step : row.steps){ + battles += step.kind == StoryStepKind::BATTLE ? " " + step.name : ""; + } + return battles; +} + +// 00.14b, before Misty: Potions at Cerulean's Mart, then into the Gym to +// a save on (9, 7), below her platform; no battle. 00.14c, Misty's battle +// as its own checkpoint: it starts from that save, talks to her from +// beside her, (9, 6), and hers is its only battle; then TM03 Water Pulse +// in place of Tail Whip. +UnitTestResult test_misty_rows(){ + const std::vector& checkpoints = story_checkpoints(); + const StoryCheckpoint& gym = checkpoints[row_index("00.14b")]; + const StoryCheckpoint& misty = checkpoints[row_index("00.14c")]; + if (checkpoints[row_index("00.14b") - 1].id != "00.14" || checkpoints[row_index("00.14c") + 1].id != "00.15"){ + return "Expected 00.14b and 00.14c between 00.14 and 00.15."; + } + const std::vector& steps = gym.steps; + const size_t mart = find_step(steps, 0, [](const StoryStep& step){ + const std::optional plan = mart_of(step); + return plan && plan->map == "CeruleanCity_Mart" && !plan->lines.empty() && plan->lines[0].item == "potion"; + }); + if (mart == steps.size() || !battle_names(gym).empty()){ + return "00.14b: expected a Cerulean Mart step buying Potions and no battle; its battles:" + battle_names(gym); + } + const std::optional start = misty.start ? story_pose(Pokemon::pose_of(*misty.start)) : std::nullopt; + if (!start || misty.live_start || start->map != "CeruleanCity_Gym" || !(start->tile == TilePos{9, 7}) + || save_card_place(start->map).empty() + ){ + return "00.14c: expected it to start from a save on (9, 7) in Cerulean Gym."; + } + if (battle_names(misty) != " misty" || misty.steps.size() < 3 || misty.steps[1].kind != StoryStepKind::TALK + || misty.steps[2].name != "misty" + ){ + return "00.14c: expected a walk beside Misty, the talk and her battle, the only one; its battles:" + battle_names(misty); + } + const std::optional beside = story_pose_arg(misty.steps[0], "target"); + if (!beside || !(beside->tile == TilePos{9, 6}) || beside->facing != Direction::WEST){ + return "00.14c: expected the talk from (9, 6), facing Misty (8, 6)."; + } + const size_t teach = find_step(misty.steps, 0, [](const StoryStep& step){ + const std::optional plan = teach_of(step); + return plan && plan->item == "tm03" && plan->move == "water-pulse" && plan->member == 0 && plan->forget_move == "tail-whip"; + }); + if (teach == misty.steps.size()){ + return "00.14c: expected TM03 Water Pulse taught to the lead in place of Tail Whip."; + } + return true; +} + +// 00.14b in order (Misty lost to at Lv20, console B, run m51): the Mart +// first, Potions then Super Potions, the Potions enough for the GRIND's +// wild battles at the table's money floor and at least one Super Potion +// after them; a GRIND of the lead to Lv23 on Route 4, from a route to its +// patch, with Cerulean's nurse as its target; the nurse; then the walk +// into the Gym, ending on (9, 7). +UnitTestResult test_misty_grind_order(){ + const std::vector& steps = story_checkpoints()[row_index("00.14b")].steps; + std::optional plan; + const size_t mart = find_step(steps, 0, [&](const StoryStep& step){ + plan = mart_of(step); + return plan && plan->map == "CeruleanCity_Mart"; + }); + if (mart == steps.size() || plan->lines.size() < 2 || plan->lines[0].item != "potion" || plan->lines[1].item != "super-potion" + || !plan->money_floor + ){ + return "00.14b: expected a Cerulean Mart step buying Potions, then Super Potions, with a money floor."; + } + const std::optional> buys = plan_mart_buys(mart_stock(plan->map), *plan, *plan->money_floor); + if (!buys || buys->size() < 2 || (*buys)[0].quantity < 2 || (*buys)[1].item != "super-potion"){ + return "00.14b: expected the money floor to buy 2 or more Potions and a Super Potion."; + } + const size_t grind = find_step(steps, mart, [](const StoryStep& step){ + const std::optional grind_plan = grind_of(step); + return grind_plan && grind_plan->member == 0 && grind_plan->level >= 23; + }); + const auto trip = grind_trip(steps, grind); + if (!trip){ + return "00.14b: expected a GRIND of the lead to Lv23 after the Mart, right after a route to its patch, the nurse its target."; + } + const std::optional patch = story_pose(trip->first), nurse = story_pose(trip->second); + if (!patch || patch->map != "Route4" || !nurse || nurse->map != "CeruleanCity_PokemonCenter_1F" + || !plans(trip->first, trip->second) || !plans(trip->second, trip->first) + ){ + return "00.14b: expected the GRIND on Route 4, its trips to Cerulean's nurse and back planning."; + } + const size_t heal = find_step(steps, grind + 1, [](const StoryStep& step){ + return step.name == "heal_cerulean"; + }); + const size_t gym = find_step(steps, grind + 1, [](const StoryStep& step){ + const std::optional pose = story_pose_arg(step, "target"); + return pose && pose->map == "CeruleanCity_Gym"; + }); + if (heal == steps.size() || gym == steps.size() || heal > gym){ + return "00.14b: expected the nurse after the GRIND, then the walk into the Gym."; + } + StoryPose end; + for (const StoryStep& step : steps){ + const std::optional pose = story_pose_arg(step, "target"); + end = pose ? *pose : end; + } + if (end.map != "CeruleanCity_Gym"){ + return "00.14b: expected the row to end in Cerulean Gym."; + } + return true; +} + } // namespace @@ -337,6 +618,22 @@ const AutoStoryCase AUTO_STORY_CASES[] = { .input = {"00.04 and 00.04b: one checkpoint with Starter RNG off", test_starter_rows_joined}, .expectation = {}, }, + { + .input = {"00.15: Potions at Cerulean's Mart and a GRIND before the rival", test_cerulean_mart_and_grind}, + .expectation = {}, + }, + { + .input = {"00.15b: the rival's battle alone, from a save before him", test_cerulean_rival_row}, + .expectation = {}, + }, + { + .input = {"00.14b and 00.14c: Cerulean Gym, then Misty alone from a save before her", test_misty_rows}, + .expectation = {}, + }, + { + .input = {"00.14b: Potions and Super Potions, a GRIND to Lv23, the nurse, then the Gym", test_misty_grind_order}, + .expectation = {}, + }, }; void add_tests_AutoStoryRunPlan(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp index a0272973e9..6146a78589 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySimulation_Tests.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include "Common/Cpp/Exceptions.h" @@ -24,6 +25,9 @@ #include "Pokemon/AutoStory/Pokemon_StorySegments.h" #include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" +#include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -182,13 +186,32 @@ class FakeGame : public Pokemon::StoryStepExecutor{ } return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); } + // A step into a trainer's line goes on until a trainer can see the + // player, as step_until_seen() does on the console. Outcome take_step(RunState& state, const StoryStep& step){ const std::optional at = story_pose(state.pose); if (!at){ return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); } const Direction direction = Pokemon::story_arg(step.args, "direction"); - return Pokemon::outcome_ok(to_pose(StoryPose{at->map, at->tile.next(direction), direction})); + const MapData* map = map_named(at->map); + if (step.action != TRAINER_LINE_VARIANT || map == nullptr){ + return Pokemon::outcome_ok(to_pose(StoryPose{at->map, at->tile.next(direction), direction})); + } + TilePos onto = at->tile; + const std::optional stepped = step_until_seen( + TRAINER_LINE_TILES, + [&]{ onto = onto.next(direction); }, + [&]{ + return std::any_of(map->objects.begin(), map->objects.end(), [&](const MapObject& object){ + return object.trainer && trainer_may_see(*map, object, onto); + }); + } + ); + if (!stepped){ + return Pokemon::outcome_failed("no_trainer", to_string(MapPosition{at->map, onto})); + } + return Pokemon::outcome_ok(to_pose(StoryPose{at->map, onto, direction})); } // The nurse's way must plan too, but the run goes on from where it stands. Outcome ready(RunState& state, const StoryStep& step){ @@ -439,6 +462,159 @@ UnitTestResult test_gives_up_after_attempts(){ return true; } +// The route the program walks for `step`, a ROUTE or LEGS, from `at`: +// planned, or the legs laid out. +std::optional> walked_route(const StoryPose& at, const StoryStep& step){ + const MapPosition start{at.map, at.tile}; + if (step.kind == StoryStepKind::LEGS){ + return fixed_route(story_maps(), start, Pokemon::story_arg>(step.args, "legs")); + } + const std::optional target = story_pose(Pokemon::pose_of(Pokemon::story_arg(step.args, "target"))); + const RouteGoal goal{{target->map, target->tile}, target->facing}; + return plan_overworld_route(story_maps(), start, goal, default_route_costs(), at.facing); +} + +// Walks `step` of 00.14 on `sim` from `at`, where the table says the +// player stands, and moves `at` to where it says the step ends. Returns +// the failure, or empty. +std::string walk_on_sim(OverworldSim& sim, StoryPose& at, const StoryStep& step){ + const std::string where = "00.14/" + step.name + ": "; + // A walk that ends on an open leg may leave the player short of it. + bool open_end = false; + if (step.kind == StoryStepKind::ROUTE || step.kind == StoryStepKind::LEGS){ + const std::optional> route = walked_route(at, step); + if (!route || route->empty()){ + return where + "no route from " + to_string(MapPosition{at.map, at.tile}) + "."; + } + const RoutePlanning planning{.maps = &story_maps(), .start = MapPosition{at.map, at.tile}, .label = step.name}; + const std::string failure = OverworldSimWalker(sim).run(*route, planning); + if (!failure.empty()){ + return where + failure + " On " + to_string(sim.state().position) + "."; + } + const RouteStep& last = route->back(); + open_end = last.action == RouteAction::WALK && !last.to_wall && !last.warps; + at = StoryPose{last.end.map, last.end.point, last.facing_after}; + }else if (step.kind == StoryStepKind::STEP){ + const Direction direction = Pokemon::story_arg(step.args, "direction"); + if (sim.state().facing != direction){ + sim.tap(direction); + } + sim.tap(direction); + sim.watch({SimWatcher::MESSAGE}, std::chrono::milliseconds(2000)); + at = *story_pose(Pokemon::pose_of(*step.pose_after)); + } + if (!open_end && !(sim.state().position == MapPosition{at.map, at.tile})){ + return where + "expected " + to_string(MapPosition{at.map, at.tile}) + ", but on " + to_string(sim.state().position) + "."; + } + return ""; +} + +// Console B, 2026-11-03 (row 00.14): the open leg east from Route 4 +// into Cerulean City ended a tile short, on (6, 20), with nothing on +// screen. No hold to a wall finds the player there, and the walk went on +// a column off, the hold south stopped by the fence on (6, 23), to a +// wall below a row of houses, not the Pokemon Center's door. From the +// foot of Route 4's ledge, the row's walks on the sim reach the nurse +// with that leg whole or a tile short. +UnitTestResult test_cerulean_entry_short(){ + const std::vector& rows = story_checkpoints(); + const auto row = std::find_if(rows.begin(), rows.end(), [](const StoryCheckpoint& data){ return data.id == "00.14"; }); + if (row == rows.end()){ + return "No checkpoint 00.14."; + } + const auto hop = std::find_if(row->steps.begin(), row->steps.end(), [](const StoryStep& step){ return step.name == "ledge_hop"; }); + if (hop == row->steps.end() || !hop->pose_after){ + return "00.14: no ledge_hop."; + } + for (int short_by : {0, 1}){ + StoryPose at = *story_pose(Pokemon::pose_of(*hop->pose_after)); + SimScript script; + script.short_holds[1] = short_by; + OverworldSim sim(story_maps(), MapPosition{at.map, at.tile}, *at.facing, script); + for (auto step = hop + 1; step != row->steps.end() && step->kind != StoryStepKind::HEAL; ++step){ + const std::string failure = walk_on_sim(sim, at, *step); + if (!failure.empty()){ + return std::format("Entry {} tile(s) short: ", short_by) + failure; + } + } + } + return true; +} + +// Runs `step` of 00.16 on `sim` as the program does: legs by the sim's +// walker from `at`, where the table says the player stands; a step one +// tap at a time, or for a step into a trainer's line by +// step_until_seen(), each watched for the trainer; a battle from the +// trainer's message, which must be up. Moves `at` to where the table +// says the step ends. Returns the failure, or empty. +std::string bridge_step_on_sim(OverworldSim& sim, StoryPose& at, const StoryStep& step){ + const std::string where = "00.16/" + step.name + ": "; + const auto on = [&sim]{ return " On " + to_string(sim.state().position) + "."; }; + if (step.kind == StoryStepKind::LEGS){ + const std::optional> route = walked_route(at, step); + const RoutePlanning planning{.maps = &story_maps(), .start = MapPosition{at.map, at.tile}, .label = step.name}; + const std::string failure = route ? OverworldSimWalker(sim).run(*route, planning) : "no legs."; + at = route ? StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after} : at; + return failure.empty() ? "" : where + failure + on(); + } + if (step.kind == StoryStepKind::STEP){ + const Direction direction = Pokemon::story_arg(step.args, "direction"); + const auto tap = [&sim, direction]{ + if (sim.state().facing != direction){ + sim.tap(direction); + } + sim.tap(direction); + }; + const auto seen = [&sim]{ + return sim.watch({SimWatcher::MESSAGE, SimWatcher::BATTLE_SCREEN}, TRAINER_LINE_WATCH).has_value(); + }; + const int tiles = step.action == TRAINER_LINE_VARIANT ? TRAINER_LINE_TILES : 1; + return step_until_seen(tiles, tap, seen) ? "" : where + "no trainer saw the player." + on(); + } + if (step.kind == StoryStepKind::BATTLE){ + if (!sim.close_message() || sim.handle_battle(SimBattleChoice::FIGHT) != SimBattleEnd::ENDED){ + return where + "no_battle." + on(); + } + at = *story_pose(Pokemon::pose_of(*step.pose_after)); + if (!(sim.state().position == MapPosition{at.map, at.tile})){ + return where + "expected " + to_string(MapPosition{at.map, at.tile}) + "." + on(); + } + } + return ""; +} + +// Console B, 2026-11-03 (row 00.16), twice: the open leg north from +// Cerulean City onto Nugget Bridge ended on (11, 33), a tile short of +// (11, 32), and the one step onto Cale's row reached only (11, 32), out +// of his sight: "bug_catcher_cale: failed: no_battle". From the walk's +// end, whole or a tile short, the five trainers are met and beaten on +// the sim, each battle on the trainer's row. +UnitTestResult test_nugget_bridge_short(){ + const std::vector& rows = story_checkpoints(); + const auto row = std::find_if(rows.begin(), rows.end(), [](const StoryCheckpoint& data){ return data.id == "00.16"; }); + if (row == rows.end()){ + return "No checkpoint 00.16."; + } + const auto walk = std::find_if(row->steps.begin(), row->steps.end(), [](const StoryStep& step){ return step.name == "below_cale_line"; }); + if (walk == row->steps.end() || !walk->args.contains("target")){ + return "No step 00.16/below_cale_line."; + } + for (int short_by : {0, 1}){ + StoryPose at = *story_pose(Pokemon::pose_of(Pokemon::story_arg(walk->args, "target"))); + OverworldSim sim(story_maps(), MapPosition{at.map, {at.tile.x, at.tile.y + short_by}}, Direction::NORTH); + for (auto step = walk + 1; step != row->steps.end() && step->kind != StoryStepKind::READY; ++step){ + const std::string failure = bridge_step_on_sim(sim, at, *step); + if (!failure.empty()){ + return std::format("Walk {} tile(s) short: ", short_by) + failure; + } + } + if (sim.state().trainers_beaten.size() != 5){ + return std::format("Walk {} tile(s) short: expected 5 trainers beaten, got {}.", short_by, sim.state().trainers_beaten.size()); + } + } + return true; +} + const AutoStorySimulationTestCase AUTO_STORY_SIMULATION_CASES[] = { { .input = {.name = "new game to Brock, in order, each start where the last save stood", .body = test_whole_story}, @@ -456,6 +632,14 @@ const AutoStorySimulationTestCase AUTO_STORY_SIMULATION_CASES[] = { .input = {.name = "a battle lost every time stops after 3 attempts", .body = test_gives_up_after_attempts}, .expectation = {.description = "aborts after three consecutive battle blackouts"}, }, + { + .input = {.name = "00.14 into Cerulean, the entry leg a tile short", .body = test_cerulean_entry_short}, + .expectation = {.description = "recovers when entering Cerulean City if movement ends one tile short"}, + }, + { + .input = {.name = "00.16 Nugget Bridge, the walk onto it a tile short", .body = test_nugget_bridge_short}, + .expectation = {.description = "completes Nugget Bridge battles even if initial approach stops short"}, + }, { .input = {.name = "a save off the start pose stops before any step", .body = test_save_off_start_pose}, .expectation = {.description = "fails the start check without walking or saving"}, @@ -471,6 +655,7 @@ void add_tests_AutoStorySimulation(UnitTestDatabase& database){ for (const auto& scenario : AUTO_STORY_SIMULATION_CASES){ database.add(scenario); } + } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStatusBadge.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStatusBadge.h new file mode 100644 index 0000000000..514cbbf6aa --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStatusBadge.h @@ -0,0 +1,29 @@ +/* AutoStory Status Badge + * + * From: https://github.com/PokemonAutomation/ + * + * The status badge left of the player's HP numbers in a battle, read by + * its mean color. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryStatusBadge_H +#define PokemonAutomation_PokemonFRLG_AutoStoryStatusBadge_H + +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "PokemonFRLG_AutoStorySupplies.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The status badge left of the player's HP numbers, by its mean color. +StatusCondition read_status_badge(const ImageViewRGB32& badge); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp index 55ab05f110..767ea8f311 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -156,6 +156,9 @@ std::span story_action_specs(){ run.name = "run"; specs.push_back(std::move(run)); } + Pokemon::StoryActionSpec trainer_line = *Pokemon::find_story_action(builtin, StoryStepKind::STEP, ""); + trainer_line.name = TRAINER_LINE_VARIANT; + specs.push_back(std::move(trainer_line)); specs.push_back({.kind = StoryStepKind::GAME, .name = CLOSE_TRAINER_CARD, .args = {}}); specs.push_back({.kind = StoryStepKind::GAME, .name = LEAVE_GIFT_SUMMARY, .args = {}}); for (Pokemon::StoryActionSpec spec : { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h index 27914fe6db..bb902aadc8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.h @@ -60,7 +60,8 @@ const std::vector& story_action_rows(); // The actions FRLG's steps name, with the args each takes: the built-in // ones (Pokemon_BuiltinStoryActions.h), then a ROUTE and a LEGS named // "run" (RUN_VARIANT), which take the same args and run with B held, -// then FRLG's GAME actions: closing the Trainer Card or the Gift RNG +// a STEP named "trainer_line" (TRAINER_LINE_VARIANT), which steps on +// until a trainer sees the player, then FRLG's GAME actions: closing the Trainer Card or the Gift RNG // summary, a PC transfer, a capture, the fossil, a LEVEL check, a Mart, // a TEACH and a GRIND, each with the args it declares. // A story file is read against these. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h index b02d288b9a..2cf0c6069a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySupplies.h @@ -29,23 +29,25 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// A status condition, as far as the story treats them: the two it carries +// A status condition, as far as the story treats them: the ones it carries // items for, and the rest, which only a nurse cures. enum class StatusCondition{ NONE, POISON, PARALYSIS, - OTHER, // SLP, BRN, FRZ + SLEEP, + OTHER, // BRN, FRZ }; // String representation of a status condition. std::string_view status_name(StatusCondition status); // The healing items in the Items pocket, in the order they were bought: -// Potions, Antidotes, then Parlyz Heals. +// Potions, Antidotes, then Parlyz Heals; Awakenings from Cerulean's Mart. struct Supplies{ int potions = 0; int antidotes = 0; int parlyz_heals = 0; + int awakenings = 0; // The Items pocket's order, by slug (see read_item_list_name()): the // order bought, or as read from the bag, with "" for a row whose name // couldn't be read. A counted item with none left takes no row; the diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 666fd4e56c..82b2aab8a0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -10,9 +10,11 @@ #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" #include "Pokemon/AutoStory/Data/Pokemon_AuthoredCheckpointJson.h" +#include "PokemonFRLG_AutoStoryMart.h" #include "PokemonFRLG_AutoStoryParty.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" +#include "PokemonFRLG_AutoStoryTeach.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -163,6 +165,10 @@ StoryCheckpoint read_story_checkpoint_file(const JsonValue& value, std::string_v throw ParseException(std::format("{}: notes for unknown step {}", source, key)); } } + // A Mart spends money and a TEACH a TM: once per save. + for (StoryStep& step : checkpoint.steps){ + step.once_per_save = step.action == MART_ACTION || step.action == TEACH_ACTION; + } return checkpoint; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index e9dcead69c..9aeaf0fcb3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -3,10 +3,11 @@ * From: https://github.com/PokemonAutomation/ * * FireRed from a new game to the Boulder Badge, the Running Shoes, Route - * 3 to the Magikarp salesman in Route 4's Pokemon Center, and through Mt. - * Moon to Route 4 east of it, as story checkpoints 00.01 to 00.13, each - * saved at its end. After 00.10 every route and leg runs. Taken from a - * by-hand run on console B (2026-11-01) and the pokefirered map scripts. + * 3 to the Magikarp salesman in Route 4's Pokemon Center, through Mt. + * Moon to Route 4 east of it, and on to Cerulean City, Misty, its rival + * and Nugget Bridge, as story checkpoints 00.01 to 00.16, each saved at its + * end. After 00.10 every route and leg runs. Taken from a by-hand run on + * console B (2026-11-01) and the pokefirered map scripts. * * Each checkpoint is an authored JSON file in StoryData/ * (frlg-.plan.json, format pokesim-authored-checkpoint/1): the shared @@ -57,11 +58,13 @@ const std::vector>& autostory_checkpoint_jso // action args it doesn't take, or has notes for a step it doesn't have. StoryCheckpoint read_story_checkpoint_file(const JsonValue& value, std::string_view source); -// Checkpoints 00.01 to 00.13, in order: every file in StoryData/. With -// 00.01b, the way back in after SID Helper, after 00.01, 00.04 split in -// two at Squirtle's ball for Starter RNG: 00.04 and 00.04b, 00.12b, the -// way back in after Gift RNG, after 00.12, and 00.12c, the Magikarp put -// in BOX 1, after it. +// Checkpoints 00.01 to 00.16, in order: every file in StoryData/. With +// 00.01b, the way back in after SID Helper, after 00.01, 00.04 split in two at Squirtle's ball for +// Starter RNG: 00.04 and 00.04b, 00.12b, the way back in after Gift RNG, +// after 00.12, 00.12c, the Magikarp put in BOX 1, after it, 00.14b and +// 00.14c, Cerulean Gym to a save below Misty's platform and Misty alone +// from it, and 00.15b, the rival in Cerulean alone, from 00.15's save +// below his trigger. const std::vector& story_checkpoints(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp index 40cf6b3203..59d978227b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp @@ -88,6 +88,7 @@ Pokemon::StoryStep teach_step(std::string name, std::string why, const TeachPlan step.why = std::move(why); step.action = TEACH_ACTION; step.args = teach_args(plan); + step.once_per_save = true; return step; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachPlan.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachPlan.h index ca5600c9eb..0d63b818f6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachPlan.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachPlan.h @@ -54,7 +54,9 @@ Pokemon::StoryActionArgs teach_args(const TeachPlan& plan); // TM or HM or a slot is out of range. std::optional teach_plan_of(const Pokemon::StoryActionArgs& args); -// Constructs an auto-story step for teaching a TM or HM. +// The table's TEACH step, once per save (StoryStep::once_per_save): a +// retry from the same save skips it when the lead knew the move or there +// was no TM. Pokemon::StoryStep teach_step(std::string name, std::string why, const TeachPlan& plan); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerLine.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerLine.h new file mode 100644 index 0000000000..244178f9dc --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerLine.h @@ -0,0 +1,61 @@ +/* AutoStory Trainer Line + * + * From: https://github.com/PokemonAutomation/ + * + * Steps into a trainer's line of sight a tile at a time, until the + * trainer sees the player. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryTrainerLine_H +#define PokemonAutomation_PokemonFRLG_AutoStoryTrainerLine_H + +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonFRLG_AutoStoryPresses.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Steps with `step` a tile at a time, at most `max_tiles`, until `seen` +// says a trainer saw the player. Returns the tiles stepped, or nothing +// if no trainer did. A walk that ended a tile short of a trainer's line +// still meets them (console B, 2026-11-03, Nugget Bridge: the walk ended +// on (11, 33), one step reached (11, 32), and Cale on row 31 never saw +// the player). +std::optional step_until_seen(int max_tiles, const std::function& step, const std::function& seen); + +// How long after a step into a trainer's line their message shows: the +// "!", then their words, as the route walker watches for a trainer +// with no tiles to walk up (PokemonFRLG_OverworldRecoveryWalk.cpp). +inline constexpr Milliseconds TRAINER_LINE_WATCH(2500); + +// The variant of a STEP into a trainer's line: a tile at a time, at most +// TRAINER_LINE_TILES, until the trainer sees the player +// (step_until_seen()). The battle after it starts on the trainer's row +// whether the walk before ended on its tile or a tile short. +inline const std::string TRAINER_LINE_VARIANT = "trainer_line"; +// Maximum tiles to step into a trainer's line of sight. +inline constexpr int TRAINER_LINE_TILES = 3; + +// From the overworld: step_until_seen() `direction`, turning first +// unless `facing` is `direction`, each step watched TRAINER_LINE_WATCH +// for a trainer's message or battle. +std::optional step_into_line( + ConsoleHandle& console, ProControllerContext& context, + Pokemon::Direction direction, std::optional facing, int max_tiles +); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index cbca6c2f93..349b0605db 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -8,6 +8,8 @@ * */ +// code-health: allow file_lines -- stage 4 adds the Cerulean trigger and Nugget Bridge walk tests, which share this file's walk helpers; split with them later + #include #include #include @@ -24,6 +26,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryGrind.h" #include "PokemonFRLG_AutoStoryPcStorage.h" #include "PokemonFRLG_AutoStoryMoveData.h" #include "PokemonFRLG_AutoStoryStepTable.h" @@ -33,7 +36,6 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ - namespace{ struct AutoStoryInput{ @@ -231,8 +233,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po UnitTestResult test_routes_and_chain(){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 17 || checkpoints[0].start){ - return "Expected 17 checkpoints, the first from a new game."; + if (checkpoints.size() != 23 || checkpoints[0].start){ + return "Expected 23 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ @@ -394,6 +396,25 @@ const MapObject* trainer_seeing(const MapData& map, const TilePos& tile, const s return nullptr; } +// The tile a STEP from `pose` ends on: the next one; for a step into a +// trainer's line, the first within TRAINER_LINE_TILES that a trainer +// other than the `beaten` sees, where step_until_seen() stops, else the +// last. +TilePos step_end(const StoryPose& pose, const StoryStep& step, const std::set& beaten){ + const MapData* map = find_map_named(pose.map); + const Direction direction = Pokemon::story_arg(step.args, "direction"); + if (step.action != TRAINER_LINE_VARIANT || map == nullptr){ + return pose.tile.next(direction); + } + TilePos tile = pose.tile; + step_until_seen( + TRAINER_LINE_TILES, + [&]{ tile = tile.next(direction); }, + [&]{ return trainer_seeing(*map, tile, beaten) != nullptr; } + ); + return tile; +} + // Whether every floor tile of `map` has wild encounters, as in a cave: // every open tile is tall grass, but for warps. No route keeps out of // its grass. @@ -524,8 +545,7 @@ UnitTestResult advance(StoryPose& pose, const StoryStep& step){ return check_legs(pose, step); } if (step.kind == StoryStepKind::STEP){ - const Direction direction = Pokemon::story_arg(step.args, "direction"); - pose = StoryPose{pose.map, pose.tile.next(direction), direction}; + pose = StoryPose{pose.map, step_end(pose, step, {}), Pokemon::story_arg(step.args, "direction")}; } if (step.pose_after){ pose = one_tile(Pokemon::grid_pose_of(*step.pose_after)); @@ -541,8 +561,12 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set{}){ - if (const std::string problem = tile_problem(tile, beaten); !problem.empty()){ + 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 && problem.starts_with("in the grass"))){ return where + problem; } } @@ -554,7 +578,7 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set(step.args, "direction")), beaten) : nullptr; + const MapObject* trainer = step.kind == StoryStepKind::STEP && map ? trainer_seeing(*map, step_end(pose, step, beaten), beaten) : nullptr; if (trainer != nullptr && (c + 1 == checkpoint.steps.size() || checkpoint.steps[c + 1].kind != StoryStepKind::BATTLE)){ return where + "steps into a trainer's line with no battle after it."; } @@ -569,12 +593,12 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set beaten; bool has_shoes = false; @@ -586,8 +610,8 @@ UnitTestResult test_trainer_lines(){ } has_shoes = has_shoes || checkpoint.id == "00.10"; } - if (beaten.size() != 4){ - return "Expected to fight Colton, Greg and James on Route 3 and the Grunt at (12, 20) in Mt. Moon; the table fights " + if (beaten.size() != 9){ + return "Expected to fight Colton, Greg and James on Route 3, the Grunt at (12, 20) in Mt. Moon and Nugget Bridge's five; the table fights " + std::to_string(beaten.size()) + " trainers."; } return true; @@ -611,6 +635,105 @@ UnitTestResult test_robin_crossing(){ return "No step 00.12/route4_nurse."; } +// A scene the table starts on a step onto its trigger, and the walks of +// its checkpoint before that step, which keep off the trigger's tiles: +// the maps have no triggers, so a route over one would start the scene +// part-way. +struct TriggerCase{ + std::string checkpoint; + std::string step; + std::string map; + // The trigger's tiles: row `y` from `x0` to `x1`. + int y = 0; + int x0 = 0; + int x1 = 0; + // The tile the step lands on. + int onto_x = 0; +}; + +const StoryCheckpoint* find_checkpoint(const std::string& id){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + if (checkpoint.id == id){ + return &checkpoint; + } + } + return nullptr; +} + +UnitTestResult check_trigger(const TriggerCase& c){ + const StoryCheckpoint* checkpoint = find_checkpoint(c.checkpoint); + if (checkpoint == nullptr){ + return "No checkpoint " + c.checkpoint + "."; + } + const MapPosition onto{c.map, {c.onto_x, c.y}}; + StoryPose pose = one_tile(Pokemon::grid_pose_of(*checkpoint->start)); + for (const StoryStep& step : checkpoint->steps){ + const std::string where = c.checkpoint + "/" + step.name + ": "; + if (step.name == c.step && step.kind == StoryStepKind::STEP && onto == MapPosition{pose.map, pose.tile.next(Pokemon::story_arg(step.args, "direction"))}){ + return true; + } + if (step.name == c.step){ + return where + "expected a step onto " + to_string(onto) + ", from " + describe(pose) + "."; + } + const bool walks = step.kind == StoryStepKind::ROUTE || step.kind == StoryStepKind::LEGS; + for (const MapPosition& tile : walks ? tiles_walked(pose, step) : std::vector{}){ + if (tile.map == c.map && tile.point.y == c.y && tile.point.x >= c.x0 && tile.point.x <= c.x1){ + return where + "walks over the trigger at " + to_string(tile) + "."; + } + } + if (UnitTestResult result = advance(pose, step); result.result != UnitTestResult::PASSED){ + return c.checkpoint + " " + result.message; + } + } + return "No step " + c.checkpoint + "/" + c.step + "."; +} + +// 00.15b meets the rival on the middle of his three trigger tiles, row 6 +// at x 22..24 north of Cerulean (VAR_MAP_SCENE_CERULEAN_CITY_RIVAL 0), +// and 00.16 the Rocket on the east one of his two, (10..11, 15) on Nugget +// Bridge (VAR_MAP_SCENE_ROUTE24 0), each from the tile below. +UnitTestResult test_cerulean_triggers(){ + const TriggerCase CASES[] = { + {.checkpoint = "00.15b", .step = "rival_trigger", .map = "CeruleanCity", .y = 6, .x0 = 22, .x1 = 24, .onto_x = 23}, + {.checkpoint = "00.16", .step = "rocket_trigger", .map = "Route24", .y = 15, .x0 = 10, .x1 = 11, .onto_x = 11}, + }; + for (const TriggerCase& c : CASES){ + if (UnitTestResult result = check_trigger(c); result.result != UnitTestResult::PASSED){ + return result; + } + } + return true; +} + +// 00.16 steps beside Nugget Bridge's five trainers from the south, one +// step at a time, each battle right after its step: Cale, Ali, Timmy, +// Reli and Ethan, by where they stand. +UnitTestResult test_nugget_bridge_order(){ + const StoryCheckpoint* checkpoint = find_checkpoint("00.16"); + if (checkpoint == nullptr){ + return "No checkpoint 00.16."; + } + const std::vector& steps = checkpoint->steps; + std::string met; + StoryPose pose = one_tile(Pokemon::grid_pose_of(*checkpoint->start)); + for (size_t c = 0; c < steps.size(); c++){ + const MapData* map = find_map_named(pose.map); + const MapObject* trainer = steps[c].kind == StoryStepKind::STEP && map ? trainer_seeing(*map, step_end(pose, steps[c], {}), {}) : nullptr; + if (trainer != nullptr && (c + 1 == steps.size() || steps[c + 1].kind != StoryStepKind::BATTLE)){ + return "00.16/" + steps[c].name + ": no battle right after the step."; + } + met += trainer ? " " + to_string(TilePos{trainer->x, trainer->y}) : ""; + if (UnitTestResult result = advance(pose, steps[c]); result.result != UnitTestResult::PASSED){ + return "00.16 " + result.message; + } + } + const std::string expected = " (12, 31) (10, 28) (12, 25) (10, 22) (12, 19)"; + if (met != expected){ + return "00.16: expected the five bridge trainers south to north," + expected + "; met" + met + "."; + } + return true; +} + // Every checkpoint that starts from a save has a place the save card // names, so a save left elsewhere is caught before it runs; and the // places of the starts that matter differ. @@ -628,6 +751,9 @@ UnitTestResult test_save_places(){ if (save_card_place("Route3") != "route-3" || save_card_place("Route4_PokemonCenter_1F") != "route-4"){ return "Wrong save card places on Route 3 and 4."; } + if (save_card_place("CeruleanCity_PokemonCenter_1F") != "cerulean-city"){ + return "Wrong save card place in Cerulean City."; + } // Not Route 2's or Route 4's: a map name is a place's or a building's in it. if (!save_card_place("Route22").empty() || !save_card_place("Route24").empty() || !save_card_place("Route2").empty()){ return "A place for a map the table doesn't use."; @@ -820,7 +946,6 @@ UnitTestResult test_intro_names(){ return true; } - // 00.12c stores the Magikarp Gift RNG bought; with Gift RNG off there is // none, and the deposit is skipped instead of refused. UnitTestResult test_magikarp_deposit_skippable(){ @@ -940,11 +1065,18 @@ const AutoStoryTestCase AUTO_STORY_CASES[] = { .input = {.name = "00.12c: the Magikarp's deposit is skipped without Gift RNG", .body = test_magikarp_deposit_skippable}, .expectation = {.description = "skips magikarp deposit when gift rng is disabled"}, }, + { + .input = {.name = "Cerulean: the rival's and the Rocket's triggers", .body = test_cerulean_triggers}, + .expectation = {.description = "verifies the Cerulean rival's and the Nugget Bridge Rocket's triggers"}, + }, + { + .input = {.name = "Nugget Bridge: its five trainers, south to north", .body = test_nugget_bridge_order}, + .expectation = {.description = "verifies the Nugget Bridge trainers' order"}, + }, }; } // namespace - void add_tests_AutoStory(UnitTestDatabase& database){ add_tests_AutoStoryRunPlan(database); for (const auto& scenario : AUTO_STORY_CASES){ @@ -952,8 +1084,6 @@ void add_tests_AutoStory(UnitTestDatabase& database){ } } - - } // namespace PokemonFRLG } // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.14.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.14.plan.json new file mode 100644 index 0000000000..b0fdc32c3f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.14.plan.json @@ -0,0 +1,87 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.14", + "title": "Route 4 east to Cerulean's Pokemon Center", + "start": {"map": "Route4", "tiles": [[32, 6]], "facing": "south"}, + "events": [ + { + "id": "above_ledge", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route4", "tiles": [[93, 8]], "facing": "south"} + }, + "why": "east along Route 4's upper road to above the ledge row 9" + }, + { + "id": "ledge_hop", + "kind": "step", + "args": { + "direction": "south" + }, + "declared_after": {"map": "Route4", "tiles": [[93, 10]], "facing": "south"}, + "why": "down the ledge (93, 9) to the lower road" + }, + { + "id": "cerulean_entry", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity", "tiles": [[9, 20]], "facing": "east"} + }, + "why": "east into Cerulean City, to (9, 20) below column 9" + }, + { + "id": "above_city_ledge", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 8}, {"direction": "west", "tiles": 1}, {"direction": "east", "tiles": 22}, {"direction": "south", "tiles": 5}, {"direction": "west", "tiles": 5}] + }, + "why": "to walls: (9, 12), (8, 12), (30, 12), (30, 17), (25, 17)" + }, + { + "id": "city_ledge_hop", + "kind": "step", + "args": { + "direction": "south" + }, + "declared_after": {"map": "CeruleanCity", "tiles": [[25, 19]], "facing": "south"}, + "why": "down the ledge (25, 18)" + }, + { + "id": "cerulean_nurse", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "west along row 20 to the Pokemon Center's door (22, 19)" + }, + { + "id": "heal_cerulean", + "kind": "heal", + "why": "full HP" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "Route 4 east of Mt. Moon (Route4 map.json) joins Cerulean City at its east end (x 107; Route 4's row 3 is the city's row 13). Its upper road (rows 2..8) reaches the city only by water: the way on by land is down the ledge row 9 at x 90..96 to the lower road (rows 10..12), which joins the city's rows 20..22. Lass Crissy (75, 3) faces east, sight 4, over row 3 from x 76 to 79; the way east keeps out of her line and off the grass south of the road (75..87, 11..17).", + "A ledge is taken as one step the way it faces, from the tile before it: the player hops it and lands two tiles on. Planned routes never hop a ledge (they hold into walls, and a held ledge hops), so where the only way on is down a ledge the row takes it as this one step." + ], + "cerulean_entry": [ + "The open leg east across the city's edge ended a tile short on the console (2026-11-03: on (6, 20), not (7, 20)), and no hold to a wall in the city's west end finds the player from there: the next hold south met the fence on (6, 23) and the walk went on a column off. So the entry ends on (9, 20), and only legs to walls follow." + ], + "above_city_ledge": [ + "North up column 9 (or 8, a tile short) to row 12, west to (8, 12), east to (30, 12) beside the policeman (31, 12), south to (30, 17), west to (25, 17). The way keeps out of the boy's (16, 18..24) and the balding man's (8..10, 22..24) wander boxes." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.14b.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.14b.plan.json new file mode 100644 index 0000000000..40e06f9bf6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.14b.plan.json @@ -0,0 +1,108 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.14b", + "title": "Cerulean: Potions, a GRIND to Lv23, then into the Gym, saved below Misty's platform", + "start": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"}, + "events": [ + { + "id": "mart_clerk", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity_Mart", "tiles": [[4, 3]], "facing": "west"} + }, + "why": "out of the Center to the Mart's clerk" + }, + { + "id": "buy_potions", + "kind": "game_action", + "action": "mart", + "args": { + "map": "CeruleanCity_Mart", + "budget": 3000, + "items": [{"item": "potion", "quantity": 5}, {"item": "super-potion", "quantity": 3}], + "floor": 3000 + }, + "why": "5 Potions for the GRIND's wild battles, then Super Potions as the money allows" + }, + { + "id": "grind_patch", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route4", "tiles": [[86, 16]], "facing": "west"} + }, + "why": "west out of the city along Route 4's lower road onto its grass's east edge" + }, + { + "id": "grind_to_lv23", + "kind": "game_action", + "action": "grind", + "args": { + "slot": 1, + "level": 23, + "encounters": 100, + "pace": "west", + "heal_every": 0, + "nurse": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "wild battles until the lead is Lv23, where Bite takes Starmie in three" + }, + { + "id": "cerulean_nurse", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "back to the Center: Misty's battle starts at full HP and PP" + }, + { + "id": "heal_cerulean", + "kind": "heal", + "why": "full HP" + }, + { + "id": "gym_below_luis", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity_Gym", "tiles": [[9, 13]]} + }, + "why": "into the Gym, up column 9 to row 13, short of Luis's (9, 12)" + }, + { + "id": "gym_west_walkway", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "west", "tiles": 5}] + }, + "why": "west to the wall (4, 13)" + }, + { + "id": "below_misty_platform", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 3}, {"direction": "east", "tiles": 8}, {"direction": "north", "tiles": 3}, {"direction": "west", "tiles": 3}] + }, + "why": "walls (4, 10), (12, 10), (12, 7), then to (9, 7), out of Diana's line" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "Cerulean Gym (pokefirered CeruleanCity_Gym map.json and scripts.inc): a pool with walkways. Misty (8, 6) stands on a platform (7..9, 6) above row 7. Picnicker Diana (4, 7) faces east, sight 4, over (5..8, 7), so misty_front (8, 7) is in her line; Swimmer Luis (10, 12) in the water faces west, sight 1, over (9, 12), on column 9 north of the door. No gym trainer has to be fought for Misty, so neither is: from the door up column 9 to row 13 (a route there, so the planner's walk to a wall doesn't run on past it through (9, 12)), west to (4, 13), and to walls round the pool's west and north sides, (4, 10), (12, 10), (12, 7), then west to (9, 7), the tile below the platform's east end, out of Diana's line. 00.14c steps up onto (9, 6) and talks to Misty from beside her.", + "Misty beat a Lv20 Wartortle (console B, run m51), so first a GRIND to Lv23 on 00.15's patch. Gen 3 numbers (pokefirered: her mons have IV 0; Wartortle taken at IV 15, no EVs): Starmie Lv21 has 56 HP, Atk 36, SpA 47, SpD 40. Bite is Dark, special in Gen 3, no STAB, x2 on Psychic: at Lv23 (SpA 39) it does 23..28, three hits (two on top rolls); at Lv20, 20..24. Her Swift (physical, 60) does 9..11 to a Lv23 Wartortle (about 67 HP, Def 45) and Water Pulse (STAB, resisted) 8..10: 6 or more hits, though m51 saw about 20 a turn. Her Recover (28) and Super Potion undo a Bite, so the margin is in Bite's damage.", + "The Mart comes before the GRIND: its wild battles are fought only with 2 or more Potions, and 00.14's save has none (m51 met Misty with only the 5 this row bought). 5 Potions (row 3, 300 each), then up to 3 Super Potions (row 2, 700), last so they take the Items pocket's last row; the battle doesn't use them yet. The money box can't be read, so the floor stands for it, and a floor above the money fails the step (the quantity box wraps). Prizes (pokefirered: 4 x last level x the class's factor) from a new game's 3000, less Viridian's 2000 and the Magikarp's 500: Liam 220, Brock 1400, Route 3's bug catchers 360, the Mt. Moon grunt 416 and Miguel 288 (the first rival's 80 only if won), at least 3184 here. Floor and budget 3000: 5 Potions and 2 Super Potions, 2900. Misty's 2100 (4 x 21 x 25) then leaves 00.15 its floor of 1500. Then the nurse, and the save before Misty, so her battle is its own checkpoint, 00.14c, verified and retried from it. 00.15's GRIND then fights until the sim beats the Cerulean rival often enough." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.14c.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.14c.plan.json new file mode 100644 index 0000000000..9b82cdb2a4 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.14c.plan.json @@ -0,0 +1,80 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.14c", + "title": "Cerulean Gym: Misty, then Water Pulse", + "start": {"map": "CeruleanCity_Gym", "tiles": [[9, 7]], "facing": "west"}, + "events": [ + { + "id": "beside_misty", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity_Gym", "tiles": [[9, 6]], "facing": "west"} + }, + "why": "up onto (9, 6), facing Misty (8, 6)" + }, + { + "id": "challenge_misty", + "kind": "talk", + "why": "Misty's speech" + }, + { + "id": "misty", + "kind": "battle", + "args": { + "trainer": "TRAINER_LEADER_MISTY", + "foes": ["staryu", "starmie"] + }, + "declared_after": {"map": "CeruleanCity_Gym", "tiles": [[9, 6]], "facing": "west"}, + "why": "Staryu and Starmie, with Bite; CASCADE BADGE and TM03" + }, + { + "id": "gym_way_out", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "south", "tiles": 1}, {"direction": "east", "tiles": 3}, {"direction": "south", "tiles": 3}, {"direction": "west", "tiles": 8}, {"direction": "south", "tiles": 3}, {"direction": "east", "tiles": 5}] + }, + "why": "walls (12, 7), (12, 10), (4, 10), (4, 13), (9, 13), round Luis's (9, 12)" + }, + { + "id": "cerulean_nurse", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "down column 9 out of the Gym, to the Center" + }, + { + "id": "heal_cerulean", + "kind": "heal", + "why": "full HP" + }, + { + "id": "teach_water_pulse", + "kind": "game_action", + "action": "teach", + "args": { + "item": "tm03", + "move": "water-pulse", + "slot": 1, + "forget": "tail-whip" + }, + "why": "TM03 Water Pulse in place of Tail Whip" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "Misty (TRAINER_LEADER_MISTY: Staryu Lv18, Starmie Lv21), talked to from (9, 6), beside her on the platform. Her win text runs on to the CASCADE BADGE, TM03 (Water Pulse) and its explanation, all read with the battle's. Bite is chosen against her party (Starmie is Water/Psychic). Back to the nurse round the pool's west side, out of Luis's line; then Water Pulse in place of Tail Whip, last, at the Center, from the bag's TM CASE. Ends where 00.15 starts." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.15.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.15.plan.json new file mode 100644 index 0000000000..ac04f2b8e0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.15.plan.json @@ -0,0 +1,100 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.15", + "title": "Cerulean: Water Pulse, Potions, a GRIND until the rival is winnable, then saved below his trigger", + "start": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"}, + "events": [ + { + "id": "teach_water_pulse", + "kind": "game_action", + "action": "teach", + "args": { + "item": "tm03", + "move": "water-pulse", + "slot": 1, + "forget": "tail-whip" + }, + "why": "TM03 Water Pulse in place of Tail Whip, unless the lead knows it or there is no TM03" + }, + { + "id": "mart_clerk", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity_Mart", "tiles": [[4, 3]], "facing": "west"} + }, + "why": "out of the Center to the Mart's clerk" + }, + { + "id": "buy_potions", + "kind": "game_action", + "action": "mart", + "args": { + "map": "CeruleanCity_Mart", + "budget": 1500, + "items": [{"item": "potion", "quantity": 3}, {"item": "awakening", "quantity": 2}], + "floor": 1500 + }, + "why": "3 Potions: the GRIND fights wild battles only with 2 or more; 2 Awakenings for the rival's Sleep Powder" + }, + { + "id": "grind_patch", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route4", "tiles": [[86, 16]], "facing": "west"} + }, + "why": "west out of the city along Route 4's lower road onto its grass's east edge" + }, + { + "id": "grind_for_rival", + "kind": "game_action", + "action": "grind", + "args": { + "slot": 1, + "level": 22, + "encounters": 150, + "pace": "west", + "heal_every": 0, + "nurse": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "wild battles to Lv22, where console B's Wartortle beat the rival (m56); the nurse when hurt or low on PP" + }, + { + "id": "cerulean_nurse", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "back to the Center: the rival's battle starts at full HP and PP" + }, + { + "id": "heal_cerulean", + "kind": "heal", + "why": "full HP" + }, + { + "id": "below_rival_trigger", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity", "tiles": [[23, 7]], "facing": "north"} + }, + "why": "out of the Center, north up to (23, 7), short of the trigger row 6" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "Before the rival north of Cerulean (00.15b), from the Center: first TM03 Water Pulse over Tail Whip, if the lead doesn't know it yet, so the GRIND's sim plays it (a run without TM03 from Misty skips the step). Then 3 Potions at the Mart (CeruleanCity_Mart_Items: POTION is row 3, 300 each; Mt. Moon's trainers leave well over the floor) and 2 Awakenings (row 6, 250 each; pokefirered items.json) for the rival's Bulbasaur's Sleep Powder (console B, m56: asleep at 34/65 HP, it fainted two turns later with 15 Potions), 1400 of the floor's 1500. Then a GRIND on Route 4's grass east of Mt. Moon (75..86, 11..17; Spearow, Rattata, Ekans and Mankey around Lv10, about 80 EXP each), healing at the Center, until the battle sim beats the rival 00.15b fights 50% or more: the win chance his battle refuses below. Console B's Wartortle (Lv22, 65 HP, Water Pulse) is about 42% there and 62% at Lv23; Lv28 (about 88%, some 120 battles from Lv22) is the cap. Then the nurse, and the save on (23, 7), the tile below his trigger: his battle is its own checkpoint, 00.15b, verified and retried from this save." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.15b.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.15b.plan.json new file mode 100644 index 0000000000..383136aa45 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.15b.plan.json @@ -0,0 +1,51 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.15b", + "title": "Cerulean: Water Pulse if not known, then the rival north of the city", + "start": {"map": "CeruleanCity", "tiles": [[23, 7]], "facing": "north"}, + "events": [ + { + "id": "teach_water_pulse", + "kind": "game_action", + "action": "teach", + "args": { + "item": "tm03", + "move": "water-pulse", + "slot": 1, + "forget": "tail-whip" + }, + "why": "TM03 Water Pulse in place of Tail Whip, unless the lead knows it" + }, + { + "id": "rival_trigger", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "onto (23, 6), the middle trigger: \"Yo! !\"" + }, + { + "id": "rival_cerulean", + "kind": "battle", + "args": { + "trainer": "TRAINER_RIVAL_CERULEAN_BULBASAUR", + "foes": ["pidgeotto", "abra", "rattata", "bulbasaur"] + }, + "declared_after": {"map": "CeruleanCity", "tiles": [[23, 6]], "facing": "south"}, + "why": "Pidgeotto, Abra, Rattata and Bulbasaur; then the FAME CHECKER" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "The rival north of Cerulean (CeruleanCity scripts.inc): the only way north to Nugget Bridge is columns 22..24, and a step onto row 6 there (CeruleanCity_EventScript_RivalTrigger*, VAR_MAP_SCENE_CERULEAN_CITY_RIVAL 0) brings him down to the player. From the middle, (23, 6), he stops at (23, 5); after the battle he walks round the player and off south, and the player, turning to watch him, ends facing south. His FAME CHECKER's text is read to the overworld with the battle's. For a player who took Squirtle he has Pidgeotto Lv17, Abra Lv16, Rattata Lv15 and Bulbasaur Lv18 (sParty_RivalCeruleanBulbasaur), whose Vine Whip and Sleep Powder are the danger. The row starts from 00.15's save below the trigger, and saves after him. First TM03 Water Pulse over Tail Whip (from the bag, where the player stands), if the lead doesn't know it yet: console B's save (2026-11-03) is past Misty's TEACH, which failed there. Where she taught it, the step reads the moves and does nothing." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.16.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.16.plan.json new file mode 100644 index 0000000000..0d19759910 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-00.16.plan.json @@ -0,0 +1,213 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.16", + "title": "Nugget Bridge: the nurse, five trainers and the Rocket", + "start": {"map": "CeruleanCity", "tiles": [[23, 6]], "facing": "south"}, + "events": [ + { + "id": "cerulean_nurse", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "back to the Center after the rival, before Nugget Bridge" + }, + { + "id": "heal_cerulean", + "kind": "heal", + "why": "full HP" + }, + { + "id": "below_cale_line", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route24", "tiles": [[11, 32]], "facing": "north"} + }, + "why": "out of the Center, north past the rival's row onto the bridge, below Cale's row" + }, + { + "id": "cale_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "north" + }, + "why": "onto (11, 31), beside Cale" + }, + { + "id": "bug_catcher_cale", + "kind": "battle", + "args": { + "trainer": "TRAINER_BUG_CATCHER_CALE", + "foes": ["caterpie", "weedle", "metapod", "kakuna"] + }, + "declared_after": {"map": "Route24", "tiles": [[11, 31]], "facing": "north"}, + "why": "his Bug Pokemon" + }, + { + "id": "below_ali_line", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 2}] + }, + "why": "up to (11, 29)" + }, + { + "id": "ali_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "north" + }, + "why": "onto (11, 28), beside Ali" + }, + { + "id": "lass_ali", + "kind": "battle", + "args": { + "trainer": "TRAINER_LASS_ALI", + "foes": ["pidgey", "oddish", "bellsprout"] + }, + "declared_after": {"map": "Route24", "tiles": [[11, 28]], "facing": "north"}, + "why": "her Pokemon" + }, + { + "id": "below_timmy_line", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 2}] + }, + "why": "up to (11, 26)" + }, + { + "id": "timmy_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "north" + }, + "why": "onto (11, 25), beside Timmy" + }, + { + "id": "youngster_timmy", + "kind": "battle", + "args": { + "trainer": "TRAINER_YOUNGSTER_TIMMY", + "foes": ["sandshrew", "ekans"] + }, + "declared_after": {"map": "Route24", "tiles": [[11, 25]], "facing": "north"}, + "why": "his Pokemon" + }, + { + "id": "below_reli_line", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 2}] + }, + "why": "up to (11, 23)" + }, + { + "id": "reli_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "north" + }, + "why": "onto (11, 22), beside Reli" + }, + { + "id": "lass_reli", + "kind": "battle", + "args": { + "trainer": "TRAINER_LASS_RELI", + "foes": ["nidoran-m", "nidoran-f"] + }, + "declared_after": {"map": "Route24", "tiles": [[11, 22]], "facing": "north"}, + "why": "her Pokemon" + }, + { + "id": "below_ethan_line", + "kind": "legs", + "action": "run", + "args": { + "legs": [{"direction": "north", "tiles": 2}] + }, + "why": "up to (11, 20)" + }, + { + "id": "ethan_line", + "kind": "step", + "action": "trainer_line", + "args": { + "direction": "north" + }, + "why": "onto (11, 19), beside Ethan" + }, + { + "id": "camper_ethan", + "kind": "battle", + "args": { + "trainer": "TRAINER_CAMPER_ETHAN", + "foes": ["mankey"] + }, + "declared_after": {"map": "Route24", "tiles": [[11, 19]], "facing": "north"}, + "why": "his Pokemon" + }, + { + "id": "ready_for_rocket", + "kind": "ready", + "args": { + "target": {"map": "CeruleanCity_PokemonCenter_1F", "tiles": [[7, 4]], "facing": "north"} + }, + "why": "items for a status or low HP; the nurse only if they can't" + }, + { + "id": "below_rocket_trigger", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "Route24", "tiles": [[11, 16]], "facing": "north"} + }, + "why": "up the bridge to below the Rocket's trigger (11, 15)" + }, + { + "id": "rocket_trigger", + "kind": "step", + "args": { + "direction": "north" + }, + "why": "onto (11, 15), beside the Rocket" + }, + { + "id": "rocket_grunt", + "kind": "battle", + "args": { + "trainer": "TRAINER_TEAM_ROCKET_GRUNT_6", + "foes": ["ekans", "zubat"] + }, + "declared_after": {"map": "Route24", "tiles": [[11, 15]], "facing": "east"}, + "why": "the NUGGET, then Ekans and Zubat, Lv15" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "Nugget Bridge (Route24 map.json) is x 10..12 from row 32 north to row 16, the city's columns 22..24 (offset 12). Its five trainers stand on it facing across, sight 2, so each line crosses the middle column 11 on the trainer's row: Bug Catcher Cale (12, 31), Lass Ali (10, 28), Youngster Timmy (12, 25), Lass Reli (10, 22) and Camper Ethan (12, 19). Each is fought on the step onto their row, beside them: they don't walk, and the player keeps facing north. Two tiles separate the rows, walked as one short leg; the step onto a row goes on a tile at a time until the trainer sees the player (\"trainer_line\"), as the open leg onto the bridge ended a tile short twice on console B (2026-11-03), on (11, 33), and one step left the player out of Cale's sight. Then the Rocket (12, 15): the step onto (11, 15) (Route24_EventScript_RocketTriggerRight, VAR_MAP_SCENE_ROUTE24 0) gives the NUGGET, \"join Team Rocket\", and his battle; he only turns, and the player turns east to him. Camper Shane (5, 21) looks north from the west bank, off the way." + ], + "ready_for_rocket": [ + "A route, not legs: the nurse may have been needed." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 533ee863b3..684bb69a45 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2148,6 +2148,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachScreens.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachScreens.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeachScreens_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStatusBadge.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrainerLine.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/BoxOrganization/PokemonFRLG_BoxOrganization.cpp Source/VideoGames/PokemonFRLG/Programs/BoxOrganization/PokemonFRLG_BoxOrganization.h