diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp index 4704fca85c..b1a6852e36 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp @@ -12,6 +12,8 @@ * */ +#include +#include #include #include #include @@ -503,6 +505,274 @@ UnitTestResult test_mart_exit(){ return true; } +// Mt. Moon (story row 00.13): every floor tile has wild encounters, and +// the floors join by ladders taken on stepping onto them. From the Moon +// Stone (3, 2) on 1F down to the foot of B2F's ladder: two ladders, each +// a fade. +UnitTestResult test_mt_moon_ladders(){ + const SimCase c{.start = at("MtMoon_1F", 3, 3), .facing = Direction::NORTH, .goal = at("MtMoon_B2F", 26, 21)}; + const SimRun now = run_case(c); + if (!arrived(now, c.goal) || now.state.warps != 2){ + return "Expected B2F reached by two ladders:" + describe(now); + } + return true; +} + +// The Moon Stone's ball (3, 2) on Mt. Moon 1F is a short way off the way +// down: from (11, 3), where 00.13's walk up column 11 ends, to face it +// and then on to B1F costs a few tiles more than going straight, and +// both walks end where they were planned to. +UnitTestResult test_moon_stone_detour(){ + const MapPosition from = at("MtMoon_1F", 11, 3); + const MapPosition ball_front = at("MtMoon_1F", 3, 3); + const MapPosition b1f = arrival("MtMoon_B1F", "warp_0"); + const auto tiles = [](const std::vector& route){ + int count = 0; + for (const RouteStep& step : route){ + count += step.tiles; + } + return count; + }; + const SimCase straight{.start = from, .facing = Direction::NORTH, .goal = b1f}; + const SimCase to_ball{.start = from, .facing = Direction::NORTH, .goal = ball_front}; + const SimCase on{.start = ball_front, .facing = Direction::NORTH, .goal = b1f}; + const int extra = tiles(planned(to_ball)) + tiles(planned(on)) - tiles(planned(straight)); + if (extra > 8){ + return std::format("Expected the detour to cost 8 tiles or fewer, not {}:", extra) + describe(planned(to_ball)) + describe(planned(on)); + } + for (const SimCase& c : {to_ball, on}){ + const SimRun run = run_case(c); + if (!arrived(run, c.goal)){ + return "Expected the detour walked:" + describe(run); + } + } + return true; +} + +// Mt. Moon B2F: the Grunt at (37, 21) looks around (sight 3) over the +// only way east. 00.13 crosses his room on legs to walls; the sim's +// trainers see every way they may look, so he sees the player on +// (37, 22), is fought, and the leg is held on to its wall. +UnitTestResult test_mt_moon_grunt_mid_leg(){ + SimCase c{.start = at("MtMoon_B2F", 32, 22), .facing = Direction::SOUTH, .goal = at("MtMoon_B2F", 39, 14)}; + c.route = std::vector{ + leg(Direction::EAST, 8, at("MtMoon_B2F", 40, 22), true), + leg(Direction::NORTH, 3, at("MtMoon_B2F", 40, 19), true), + leg(Direction::WEST, 1, at("MtMoon_B2F", 39, 19), false), + leg(Direction::NORTH, 5, c.goal, true), + }; + const SimRun now = run_case(c); + if (!arrived(now, c.goal) || now.state.trainers_beaten != std::vector{"rocket_m"}){ + return "Expected the Grunt fought once and the legs walked:" + describe(now); + } + return true; +} + +// Mt. Moon B2F: 00.13's open leg east along the bottom row, (8, 38) to +// (11, 38), ends a tile short with nothing on screen. The hold north +// after it would end on (10, 21), a column west of the Grunt's line the +// table steps into from (11, 21): the walker finds the player at walls +// and walks back first. Taken as walked, the route ends on (10, 21). +UnitTestResult test_mt_moon_short_leg(){ + SimCase c{.start = at("MtMoon_B2F", 8, 38), .facing = Direction::WEST, .goal = at("MtMoon_B2F", 11, 21)}; + c.route = std::vector{ + leg(Direction::EAST, 3, at("MtMoon_B2F", 11, 38), false), + leg(Direction::NORTH, 17, c.goal, true), + }; + c.script.short_holds[1] = 1; + const SimRun now = run_case(c); + if (!arrived(now, c.goal)){ + return "Expected the player found at walls after the short leg, and the route walked:" + describe(now); + } + SimCase trusted = c; + trusted.open_leg_check = OpenLegCheck::TRUST; + const SimRun old = run_case(trusted); + if (!old.failure.empty() || !(old.state.position == at("MtMoon_B2F", 10, 21))){ + return "Expected the walk claimed done on (10, 21) without the check:" + describe(old); + } + return true; +} + +// Mt. Moon: a wild battle whose flashes are missed stops a leg to a wall +// part-way (every cave tile can start one); it is run from and the leg +// walked again, and the route goes on down the ladders. +UnitTestResult test_mt_moon_late_battle(){ + SimCase c{.start = at("MtMoon_1F", 3, 3), .facing = Direction::NORTH, .goal = at("MtMoon_B2F", 26, 21)}; + c.script.encounters = {{.grass_step = 9, .seen_late = true}}; + const SimRun now = run_case(c); + if (!arrived(now, c.goal)){ + return "Expected the battle run from, then B2F reached:" + describe(now); + } + return true; +} + +// Console B, 2026-11-03 (row 00.13, b2f_ladder_foot): a wild battle whose +// flashes were missed started on "south 3 (warp)" from (5, 3) to 1F's +// ladder; its wipe passed for the ladder's fade, and the walker stopped as +// off the route, with the player on (5, 5). A battle on the leg's first or +// second step is now run from, the player found again on the leg, and the +// route goes on down both ladders. Without the rule it stops as it did. +UnitTestResult test_mt_moon_battle_on_ladder_leg(){ + const SimCase c{.start = at("MtMoon_1F", 3, 3), .facing = Direction::NORTH, .goal = at("MtMoon_B2F", 26, 21)}; + for (size_t tile : {1, 2}){ + const std::optional now = run_with_battle_on_warp_leg(c, tile); + if (!now){ + return std::format("Expected a leg onto 1F's ladder with a cave step {}:", tile) + describe(planned(c)); + } + if (!arrived(*now, c.goal) || now->state.warps != 2){ + return std::format("Expected the battle on step {} run from, then B1F and B2F reached:", tile) + describe(*now); + } + } + SimCase off = c; + off.rules.find_player_after_warp_battle = false; + const std::optional old = run_with_battle_on_warp_leg(off, 2); + if (!old || !stopped_with(*old, "a wild battle, not the warp to MtMoon_B1F: the player is off the route.") + || !(old->state.position == at("MtMoon_1F", 5, 5)) + ){ + return "Expected a stop as off the route on (5, 5) without the rule:" + (old ? describe(*old) : ""); + } + return true; +} + +// Console B, 2026-11-03 (row 00.13, b2f_ladder_foot): on B1F a wild +// battle started part-way down "south 15 (to wall)" from (3, 3), with its +// flashes missed. Its HP boxes came over 5 s after the step, after the +// leg's watch had ended on the battle's empty text box: the leg was taken +// as walked to (3, 18), and "east 19 (warp)" was walked into the battle +// from a tile it wasn't on. The console ran (133 ms a tile) and the sim +// walks, so the battle starts a few steps later here, for the same +// timing. The text box after the watch is now watched on for, the leg +// walked again to its wall, and the route reaches B2F's ladder. Without +// the rule the leg is taken as walked, and the run stops on no fade onto +// the ladder down to B2F, as it did. +UnitTestResult test_mt_moon_battle_seen_after_wall_leg(){ + SimCase c{.start = at("MtMoon_B1F", 3, 3), .facing = Direction::SOUTH, .goal = at("MtMoon_B2F", 26, 21)}; + c.script.encounters = {{.grass_step = 13, .seen_late = true}}; + c.script.timing.battle_opening = Milliseconds(4500); + c.script.timing.battle_screen = Milliseconds(5300); + const std::vector route = planned(c); + if (route.empty() || to_string(route[0]) != "walk south 15 (to wall) -> MtMoon_B1F (3, 18)"){ + return "Expected the route to start with \"south 15 (to wall)\":" + describe(route); + } + const SimRun now = run_case(c); + if (!arrived(now, c.goal) || now.state.warps != 1){ + return "Expected the battle run from, the leg walked again and B2F reached:" + describe(now); + } + SimCase off = c; + off.rules.watch_on_for_unseen_battle = false; + off.rules.battle_before_step = false; + const SimRun old = run_case(off); + const bool taken_as_walked = std::any_of(old.log.begin(), old.log.end(), [](const std::string& line){ + return line.find("south 15 (to wall): ended at MtMoon_B1F (3, 18) (walked)") != std::string::npos; + }); + if (!taken_as_walked || !stopped_with(old, "no fade in and out after walking onto the warp to MtMoon_B2F.")){ + return "Expected the leg taken as walked and the run stopped on no fade, as on the console, without the rule:" + describe(old); + } + return true; +} + +// Console B, 2026-11-03 (row 00.13, b2f_south): on Mt. Moon B2F a wild +// battle started on the first step of "east 7 (to wall)" from (39, 14), +// along tiles closed on their north side, which the maps didn't mark as +// wild then: the leg watched only for messages, and the screen was black +// after it. The leg was taken as walked to (46, 14); "south 14 (to +// wall)" saw the battle, ran, and was held again from (40, 14), to +// (40, 17), and every leg after it went on about 6 tiles off. The sim +// walks the route from (39, 14) on to below Miguel's trigger (14, 12), +// with the battle's wipe black from 1 s after its step and its HP boxes +// at 5.3 s, as on the console. +SimCase b2f_east_battle_case(){ + SimCase c{.start = at("MtMoon_B2F", 39, 14), .facing = Direction::NORTH, .goal = at("MtMoon_B2F", 14, 12)}; + c.route = std::vector{ + leg(Direction::EAST, 7, at("MtMoon_B2F", 46, 14), true), + leg(Direction::SOUTH, 14, at("MtMoon_B2F", 46, 28), true), + leg(Direction::WEST, 9, at("MtMoon_B2F", 37, 28), true), + leg(Direction::SOUTH, 10, at("MtMoon_B2F", 37, 38), true), + leg(Direction::WEST, 29, at("MtMoon_B2F", 8, 38), true), + leg(Direction::EAST, 3, at("MtMoon_B2F", 11, 38), false), + leg(Direction::NORTH, 17, at("MtMoon_B2F", 11, 21), true), + leg(Direction::EAST, 3, at("MtMoon_B2F", 14, 21), false), + leg(Direction::NORTH, 9, c.goal, false), + }; + // As the planner marked them on the console: all but "east 7", whose + // floor closed on the north the maps didn't yet mark wild. + for (RouteStep& step : *c.route){ + step.wild = to_string(step) != "walk east 7 (to wall) -> MtMoon_B2F (46, 14)"; + } + c.script.wild_floor_maps = {"MtMoon_B2F"}; + c.script.encounters = {{.grass_step = 1, .seen_late = true}}; + c.script.timing.battle_wipe = Milliseconds(1000); + c.script.timing.battle_opening = Milliseconds(4500); + c.script.timing.battle_screen = Milliseconds(5300); + return c; +} + +bool logged(const SimRun& run, const std::string& text){ + return std::any_of(run.log.begin(), run.log.end(), [&](const std::string& line){ + return line.find(text) != std::string::npos; + }); +} + +// The black after "east 7" is now a battle on its way: it is run from, +// the leg walked again to its wall, and the route reaches (14, 12). +// Without the rule, and without the check before the next step, the sim +// goes the console's way: "east 7" is taken as walked, and the route ends +// far from (14, 12). +UnitTestResult test_mt_moon_black_after_unmarked_leg(){ + const SimCase c = b2f_east_battle_case(); + const std::vector planned_route = plan_overworld_route(maps(), c.start, RouteGoal{at("MtMoon_B2F", 46, 14), std::nullopt}).value_or(std::vector{}); + if (planned_route.size() != 1 || to_string(planned_route[0]) != "walk east 7 (to wall) -> MtMoon_B2F (46, 14)"){ + return "Expected the planner's \"east 7 (to wall)\" from (39, 14):" + describe(planned_route); + } + const SimRun now = run_case(c); + if (!arrived(now, c.goal) || !logged(now, "a battle's wipe after walk east 7 (to wall)")){ + return "Expected the black after \"east 7\" watched on, the battle run from and (14, 12) reached:" + describe(now); + } + SimCase off = c; + off.rules.watch_on_after_unmarked_leg = false; + off.rules.battle_before_step = false; + const SimRun old = run_case(off); + const int off_by = std::abs(old.state.position.point.x - c.goal.point.x) + std::abs(old.state.position.point.y - c.goal.point.y); + if (!logged(old, "east 7 (to wall): ended at MtMoon_B2F (46, 14) (walked)") || (old.failure.empty() && off_by < 6)){ + return "Expected \"east 7\" taken as walked and the route ended or stopped far from (14, 12), as on the console, without the rules:" + describe(old); + } + return true; +} + +// The same battle, its black seen only before the next step (on the +// console the check after the leg can come before the wipe): the step +// isn't walked, and the player is found on "east 7", walked again to its +// wall, not on "south 14"'s line. +UnitTestResult test_mt_moon_battle_before_next_leg(){ + SimCase c = b2f_east_battle_case(); + c.rules.watch_on_after_unmarked_leg = false; + c.wall_check = WallCheck::SKIP; + const SimRun now = run_case(c); + if (!arrived(now, c.goal) || !logged(now, "a battle's wipe before walk south 14 (to wall)")){ + return "Expected the battle seen before \"south 14\", \"east 7\" walked again and (14, 12) reached:" + describe(now); + } + SimCase off = c; + off.rules.battle_before_step = false; + const SimRun old = run_case(off); + if (old.state.position == c.goal){ + return "Expected the route to end off (14, 12) without the check before a step:" + describe(old); + } + return true; +} + +// Mt. Moon B2F, after the HELIX FOSSIL: the player steps onto (14, 7), +// where it lay, and the way out goes north through the gap, west to the +// ladder (5, 10), up to B1F and out of its east end onto Route 4, walked +// a tile south of the cave mouth. +UnitTestResult test_mt_moon_way_out(){ + const SimCase c{.start = at("MtMoon_B2F", 14, 7), .facing = Direction::NORTH, .goal = at("Route4", 32, 6)}; + const SimRun now = run_case(c); + if (!arrived(now, c.goal) || now.state.warps != 2 || now.state.facing != Direction::SOUTH){ + return "Expected Route 4 east of the mountain reached by two warps, facing south:" + describe(now); + } + return true; +} + } @@ -518,6 +788,16 @@ void add_tests_OverworldSim(UnitTestDatabase& database){ database.add("a short leg, nothing seen", test_short_leg_unseen); database.add("a trainer on the way out of Pewter Gym", test_trainer_on_way_out); database.add("out of Viridian Mart from the clerk's scene", test_mart_exit); + database.add("Mt. Moon: down the ladders to B2F", test_mt_moon_ladders); + database.add("Mt. Moon: the Moon Stone is a short detour", test_moon_stone_detour); + database.add("Mt. Moon: the Grunt who looks around stops a leg to a wall", test_mt_moon_grunt_mid_leg); + database.add("Mt. Moon: a short open leg before the Grunt's line", test_mt_moon_short_leg); + database.add("Mt. Moon: a late wild battle in the cave", test_mt_moon_late_battle); + database.add("Mt. Moon: after the HELIX, out to Route 4", test_mt_moon_way_out); + database.add("Mt. Moon: a battle on the leg onto 1F's ladder", test_mt_moon_battle_on_ladder_leg); + database.add("Mt. Moon: a battle seen only after a leg to a wall", test_mt_moon_battle_seen_after_wall_leg); + database.add("Mt. Moon: black after a leg not marked wild", test_mt_moon_black_after_unmarked_leg); + database.add("Mt. Moon: a battle seen only before the next leg", test_mt_moon_battle_before_next_leg); } 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 f26fd1ed33..6036ac956f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp @@ -111,7 +111,7 @@ class Test_RunPlan : public UnitTest{ }; void add_tests_RunPlan(UnitTestDatabase& database){ - 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"; + 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 RunPlanScenario scenarios[] = { {.name = "handoffs off: the story as before", .first = "00.01", .expected_ids = TODAY}, {.name = "handoffs off: a range", .first = "00.02", .last = "00.04", .expected_ids = "00.02 00.03 00.04"}, @@ -163,8 +163,8 @@ void add_tests_GiftRunPlan(UnitTestDatabase& database){ .expected_ids = "00.11 00.12", .expected_stop = StoryHandoff::GIFT_RNG, }, - {.name = "Gift RNG off: 00.12b is passed over", .first = "00.11", .expected_ids = "00.11 00.12"}, - {.name = "Gift RNG off: 00.12b runs when started at", .first = "00.12b", .expected_ids = "00.12b"}, + {.name = "Gift RNG off: 00.12b is passed over", .first = "00.11", .expected_ids = "00.11 00.12 00.12c 00.13"}, + {.name = "Gift RNG off: 00.12b runs when started at", .first = "00.12b", .expected_ids = "00.12b 00.12c 00.13"}, { .name = "Gift RNG: started at 00.12b, from the save beside the salesman", .first = "00.12b", @@ -179,7 +179,7 @@ void add_tests_GiftRunPlan(UnitTestDatabase& database){ .expected_ids = "", .expected_stop = StoryHandoff::GIFT_RNG, }, - {.name = "Starter RNG alone: 00.12b runs when started at", .first = "00.12b", .handoffs = {.starter_rng = true}, .expected_ids = "00.12b"}, + {.name = "Starter RNG alone: 00.12b runs when started at", .first = "00.12b", .handoffs = {.starter_rng = true}, .expected_ids = "00.12b 00.12c 00.13"}, { .name = "Starter RNG first, with both on", .first = "00.03", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 1e4e1a960a..91d4112d97 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -4,6 +4,9 @@ * */ +#include "PokemonFRLG_AutoStoryCapture.h" +#include "PokemonFRLG_AutoStoryChoice.h" +#include "PokemonFRLG_AutoStoryPcStorage.h" #include "PokemonFRLG_AutoStoryTable.h" namespace PokemonAutomation{ @@ -30,7 +33,10 @@ const char* const PEWTER = "PewterCity"; const char* const PEWTER_CENTER = "PewterCity_PokemonCenter_1F"; const char* const GYM = "PewterCity_Gym"; const char* const ROUTE3 = "Route3"; +const char* const ROUTE4 = "Route4"; const char* const ROUTE4_CENTER = "Route4_PokemonCenter_1F"; +const char* const MT_MOON_1F = "MtMoon_1F"; +const char* const MT_MOON_B2F = "MtMoon_B2F"; Pokemon::Pose at(const char* map, int x, int y, std::optional facing = std::nullopt){ return to_pose(StoryPose{map, {x, y}, facing}); @@ -381,13 +387,94 @@ StoryCheckpoint after_gift_rng(){ return checkpoint; } +// The Magikarp goes to BOX 1 at the Center's PC (11, 1), so Mt. Moon is +// fought with the starter alone (console B, 2026-11-02: done by hand and +// saved at (11, 2), facing the PC, where this row ends). The wandering +// boy (4..6, 3..5) is walked around. The Magikarp comes from Gift RNG: +// with Gift RNG off the party is the starter alone, and the deposit is +// skipped. +StoryCheckpoint magikarp_to_box(){ + return row("00.12c", "Route 4 Center: the Magikarp into BOX 1", at(ROUTE4_CENTER, 2, 3, WEST), after_brock(), StartMenu::FULL, { + running(route("pc_front", at(ROUTE4_CENTER, 11, 2, NORTH), "below the PC (11, 1), facing it")), + pc_step("magikarp_to_box", "DEPOSIT the party's second slot into BOX 1, if it has one", PcTransfer{ + .action = PcAction::DEPOSIT, .party_slot = 1, .box = 0, .if_missing = PcMissing::SKIP, + }), + }); +} + +// Mt. Moon (pokefirered data/maps/MtMoon_1F, _B1F, _B2F). Every floor tile +// of the cave has wild encounters, which are run from, so its legs end on +// walls, ladders or someone standing still, which the walker holds again +// after a battle; the few open ones are short. The way through: up 1F's +// middle and west side, its north-west ladder, B1F's west ladder down to +// B2F's south-east, round B2F's south edge to its west, north past +// Miguel and the fossils, and the ladder up to B1F's east end, which +// leads out to Route 4 east of the mountain. +// - 1F's trainers are walked around: Youngster Josh (13, 17) sees east +// along row 17 to x 17, so the way west into the west room is down +// column 18 and up column 11; Lass Miriam walks round (32..33, 4..5), +// sight 2, so the way east keeps to row 9 and columns 38 and 40; Hiker +// Marcos wanders (5..9, 8..12) and sees one tile, so the way north is +// column 11 and row 3. +// - The Moon Stone ball (3, 2) on 1F (FLAG_HIDE_MT_MOON_1F_MOON_STONE) is +// a few tiles off the way to the ladder (5, 6). +// - The Grunt at (37, 21) on B2F looks around (sight 3) over the only way +// east round B2F. His room is crossed on legs to walls, at one tile of +// his sight each, (37, 22) and (40, 21); if he looks the player's way, +// he walks up beside the leg, story_interrupts() fights him, and the +// leg is held on to its wall. +// - The Grunt at (12, 20) faces south (sight 2) over (12, 21..22), across +// rows 21..22, the only way north to Miguel: stepped into from the +// west, he is next to the player and doesn't walk. +// - Super Nerd Miguel (13, 11) battles on the step onto (14, 11) +// (MtMoon_B2F_EventScript_MiguelTrigger, VAR_MAP_SCENE_MT_MOON_B2F 0), +// then "We'll each take one!" +// - The fossils: DOME (13, 7), HELIX (14, 7). After the HELIX, Miguel +// walks up to (13, 8) and takes the DOME, which opens the gap north. +// The save is on Route 4: the save card's places don't include Mt. Moon. +StoryCheckpoint mt_moon(){ + return row("00.13", "Mt. Moon: a Moon Stone, a Rocket, Miguel and the Helix Fossil", at(ROUTE4_CENTER, 11, 2, NORTH), after_brock(), StartMenu::FULL, { + running(route("route4_nurse", at(ROUTE4_CENTER, 7, 4, NORTH), "the nurse, below the counter")), + heal("heal_route4"), + running(route("mt_moon_entrance", at(MT_MOON_1F, 18, 37, NORTH), "out of the Center, west into Mt. Moon")), + running(legs("mt_moon_1f", { + {NORTH, 12}, {EAST, 8}, {NORTH, 12}, {EAST, 3}, {SOUTH, 1}, {EAST, 9}, + {NORTH, 1}, {EAST, 2}, {NORTH, 4}, {WEST, 24}, {EAST, 2}, {SOUTH, 12}, + {WEST, 7}, {NORTH, 18}, {WEST, 9}, {EAST, 1}, + }, "up the middle, east of Miriam, west along row 9, down column 18 past Josh, up column 11 past Marcos, to (3, 3)")), + running(route("below_moon_stone", at(MT_MOON_1F, 3, 3, NORTH), "facing the Moon Stone (3, 2)")), + talk("moon_stone_ball", "A on the item ball"), + // No reader for the text yet: the scene's end is the overworld. + scene("found_moon_stone", at(MT_MOON_1F, 3, 3, NORTH), "\" found a MOON STONE!\", then the pocket line; the ball is gone"), + running(route("b2f_ladder_foot", at(MT_MOON_B2F, 26, 21, EAST), "1F's ladder (5, 6), down B1F's west side to its ladder (22, 18), onto B2F")), + running(legs("b2f_south", { + {NORTH, 4}, {EAST, 8}, {WEST, 2}, {SOUTH, 5}, {EAST, 8}, {NORTH, 3}, {WEST, 1}, {NORTH, 5}, + {EAST, 7}, {SOUTH, 14}, {WEST, 9}, {SOUTH, 10}, {WEST, 29}, {EAST, 3}, {NORTH, 17}, + }, "through the Grunt's room at (37, 21), round the south edge, up column 11 to (11, 21)")), + step_into("grunt_line", EAST, "onto (12, 21), below the Grunt at (12, 20)"), + battle("rocket_grunt", at(MT_MOON_B2F, 12, 21, EAST), false, "Rattata and Zubat, Lv13"), + ready("ready_for_miguel", at(ROUTE4_CENTER, 7, 4, NORTH), "items for a status or low HP; the nurse, back through the cave, only if they can't"), + // Up column 13 to Miguel, who stops the leg on (13, 12), then east + // to the wall: the tile below his trigger. + running(legs("below_miguel_trigger", {{EAST, 1}, {NORTH, 9}, {EAST, 1}}, "to (14, 12), below Miguel's trigger (14, 11)")), + step_into("miguel_trigger", NORTH, "onto (14, 11), beside Miguel"), + battle("super_nerd_miguel", at(MT_MOON_B2F, 14, 11, NORTH), false, "Grimer, Voltorb and Koffing, Lv12; \"We'll each take one!\""), + running(legs("below_helix_fossil", {{NORTH, 3}}, "up column 14 to the HELIX FOSSIL (14, 7)")), + fossil_step("helix_fossil", "the HELIX FOSSIL; Miguel takes the DOME FOSSIL", Fossil::HELIX), + // The maps keep the fossils, which the game removes after the + // choice: the step onto the HELIX's tile is taken on its own. + step_into("helix_gap", NORTH, "onto (14, 7), where the HELIX FOSSIL lay"), + running(route("route4_east", at(ROUTE4, 32, 6, SOUTH), "west to B2F's ladder (5, 10), up to B1F, east to its exit onto Route 4")), + }); +} + } const std::vector& story_checkpoints(){ static const std::vector checkpoints{ new_game(), after_sid_helper(), leave_house(), oaks_trigger(), to_starter_ball(), starter(), parcel(), pokedex(), shopping(), forest(), brock(), - running_shoes(), route3(), magikarp_salesman(), after_gift_rng(), + running_shoes(), route3(), magikarp_salesman(), after_gift_rng(), magikarp_to_box(), mt_moon(), }; return checkpoints; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 50cda6d409..d7421214f1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -2,11 +2,11 @@ * * From: https://github.com/PokemonAutomation/ * - * FireRed from a new game to the Boulder Badge, the Running Shoes and Route - * 3 to the Magikarp salesman in Route 4's Pokemon Center, as story - * checkpoints 00.01 to 00.12b, 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. + * 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. * */ @@ -22,10 +22,10 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Checkpoints 00.01 to 00.12, in order, with 00.01b, the way back in after +// Checkpoints 00.01 to 00.13, in order, with 00.01b, the way back in after // SID Helper, after 00.01, 00.04 split in two at Squirtle's ball for -// Starter RNG: 00.04 and 00.04b, and 00.12b, the way back in after Gift -// RNG, after 00.12. +// Starter RNG: 00.04 and 00.04b, 00.12b, the way back in after Gift RNG, +// after 00.12, and 00.12c, the Magikarp put in BOX 1, after it. const std::vector& story_checkpoints(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 59b57df20f..cd22061a59 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -23,6 +23,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "PokemonFRLG_AutoStoryActions.h" +#include "PokemonFRLG_AutoStoryPcStorage.h" #include "PokemonFRLG_AutoStoryTable.h" namespace PokemonAutomation{ @@ -214,8 +215,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po UnitTestResult test_routes_and_chain(){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 15 || checkpoints[0].start){ - return "Expected 15 checkpoints, the first from a new game."; + if (checkpoints.size() != 17 || checkpoints[0].start){ + return "Expected 17 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ @@ -358,18 +359,40 @@ UnitTestResult test_runs_after_shoes(){ return true; } +// A trainer who stands still but turns to look more than one way (Mt. +// Moon B2F's Grunt at (37, 21) looks around): whether they see the player +// depends on where they look as the player passes. +bool looks_around(const MapObject& object){ + return object.trainer && !object.wander && object.trainer->looks.size() > 1; +} + // The trainer on `map` who would see the player on `tile`, other than the -// `beaten`. Wanderers are left out: no route can plan around one (see -// wanderer_stops()). +// `beaten`. Wanderers and those who look around are left out: no route +// can plan around one (see wanderer_stops() and held_past_lookers()). const MapObject* trainer_seeing(const MapData& map, const TilePos& tile, const std::set& beaten){ for (const MapObject& object : map.objects){ - if (object.trainer && !object.wander && !beaten.contains(&object) && trainer_may_see(map, object, tile)){ + if (object.trainer && !object.wander && !looks_around(object) && !beaten.contains(&object) && trainer_may_see(map, object, tile)){ return &object; } } return nullptr; } +// 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. +bool wild_everywhere(const MapData& map){ + for (int y = 0; y < map.tiles.height; y++){ + for (int x = 0; x < map.tiles.width; x++){ + const TilePos tile{x, y}; + if (map.tiles.at(tile) == TileKind::OPEN && warp_at(map, tile) == nullptr){ + return false; + } + } + } + return true; +} + // The legs a ROUTE or LEGS `step` from `pose` walks; none if it plans none. std::vector legs_walked(const StoryPose& pose, const StoryStep& step){ const MapPosition start{pose.map, pose.tile}; @@ -418,6 +441,28 @@ std::vector> wanderer_stops(const StoryPose& pose, co return stops; } +// Where a leg of a ROUTE or LEGS `step` from `pose` crosses the sight of a +// trainer who looks around, the leg ends on a wall: if the trainer looks +// the player's way, they walk up beside the leg, and the walker holds it +// on to its wall after the battle. Empty if so, else the leg that doesn't. +std::string held_past_lookers(const StoryPose& pose, const StoryStep& step){ + MapPosition from{pose.map, pose.tile}; + for (const RouteStep& leg : legs_walked(pose, step)){ + const MapData* map = find_map_named(from.map); + bool crosses = false; + for (const MapPosition& tile : leg.action == RouteAction::WALK ? leg_tiles(story_maps(), from, leg) : std::vector{}){ + for (const MapObject& object : map ? map->objects : std::vector{}){ + crosses |= looks_around(object) && trainer_may_see(*map, object, tile.point); + } + } + if (crosses && !leg.to_wall){ + return "crosses a trainer's sight on " + to_string(leg) + ", not a leg to a wall."; + } + from = leg.end; + } + return ""; +} + // The tiles a ROUTE or LEGS `step` from `pose` walks onto, in order. std::vector tiles_walked(const StoryPose& pose, const StoryStep& step){ std::vector tiles; @@ -440,7 +485,7 @@ std::string tile_problem(const MapPosition& tile, const std::set 0){ return where + "crosses a wandering trainer's sight where the walk can't tell where they'd stop the player."; } + if (const std::string problem = walks ? held_past_lookers(pose, step) : ""; !problem.empty()){ + return where + problem; + } const MapData* map = find_map_named(pose.map); const MapObject* trainer = step.kind == StoryStepKind::STEP && map ? trainer_seeing(*map, pose.tile.next(step.direction), beaten) : nullptr; if (trainer != nullptr && (c + 1 == checkpoint.steps.size() || checkpoint.steps[c + 1].kind != StoryStepKind::BATTLE)){ @@ -503,11 +551,13 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set beaten; bool has_shoes = false; @@ -519,8 +569,9 @@ UnitTestResult test_trainer_lines(){ } has_shoes = has_shoes || checkpoint.id == "00.10"; } - if (beaten.size() != 3){ - return "Expected to fight Colton, Greg and James on Route 3; the table fights " + std::to_string(beaten.size()) + " trainers."; + 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 " + + std::to_string(beaten.size()) + " trainers."; } return true; } @@ -722,6 +773,24 @@ UnitTestResult test_intro_names(){ } +// 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(){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + if (checkpoint.id != "00.12c"){ + continue; + } + for (const StoryStep& step : checkpoint.steps){ + const std::optional transfer = parse_pc_variant(step.variant); + if (transfer && transfer->party_slot == 1 && transfer->if_missing == PcMissing::SKIP){ + return true; + } + } + return "00.12c: expected a deposit of the second slot, skipped if the party hasn't got it."; + } + return "No checkpoint 00.12c."; +} + // set_options()'s RIGHT presses from each value an old save can leave: // on console B a save with FAST and SET became SLOW and SHIFT when the // presses assumed MID and SHIFT. @@ -780,6 +849,7 @@ void add_tests_AutoStory(UnitTestDatabase& database){ database.add("Route 3: Lass Robin stops the walk on (40, 9)", test_robin_crossing); database.add("intro: names, the rival's from the list", test_intro_names); database.add("options: RIGHT presses from the shown value", test_option_presses); + database.add("00.12c: the Magikarp's deposit is skipped without Gift RNG", test_magikarp_deposit_skippable); }