diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp index fa2871e6d7..4dad679747 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp @@ -6,6 +6,7 @@ #include #include +#include "PokemonFRLG_BikeSpinPresses.h" #include "PokemonFRLG_OverworldBikeTaps.h" namespace PokemonAutomation{ @@ -16,7 +17,11 @@ namespace PokemonFRLG{ StepOutcome count_bike_taps(const RouteStep& step, const BikeTapCalls& calls){ int moved = 0; for (int tap = 1; tap <= step.tiles; tap++){ - const BikeTap result = calls.tap(); + BikeTap result = calls.tap(tap); + for (int retry = 1; retry < calls.tries && !result.moved && !result.interrupt && !result.cleared_late; retry++){ + calls.log(std::format("Taps: tap {} of {} didn't move: tapping again, it may only have turned the player.", tap, step.tiles)); + result = calls.tap(tap); + } if (result.interrupt || result.cleared_late){ calls.log(std::format("Bike: tap {} of {}: interrupted after {} tile(s).", tap, step.tiles, moved)); if (result.interrupt){ @@ -34,6 +39,19 @@ StepOutcome count_bike_taps(const RouteStep& step, const BikeTapCalls& calls){ return StepOutcome{}; } +bool counts_step_taps(const RouteStep& step){ + return step.tapped && step.action == RouteAction::WALK && step.tiles > 0 + && !step.surfing && !step.warps && step.connection_steps.empty(); +} + +Milliseconds step_tap_settle(const RouteStep& step, int tap){ + using namespace MovementMechanics; + if (tap != step.tiles || !step.spin_tiles){ + return Milliseconds(0); + } + return SPIN_TILE_TIME * *step.spin_tiles + SPIN_STOP_SETTLE; +} + } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h index c1018ce17f..fb5bb67188 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h @@ -32,13 +32,21 @@ struct BikeTap{ // cleared already: a trainer who saw the player, a battle seen late. bool cleared_late = false; }; -// The console side of count_bike_taps(): `tap` taps once and judges it; +// The console side of count_bike_taps(): `tap` taps once, for the leg's +// `tap`th tile (from 1), and judges it; // `clear` clears interrupt i. struct BikeTapCalls{ - std::function tap; + std::function tap; std::function clear; std::function log; + // Taps per tile before one that doesn't move counts as blocked: on + // foot a tap facing another way only turns the player + // (STEP_TAP_TRIES). + int tries = 1; }; +// Taps per tile on foot: the first tap of a leg may only turn, and the +// game may miss a turn tap (MovementMechanics::MAX_TURN_TAPS). +constexpr int STEP_TAP_TRIES = 3; // How far a sure start may be off before a blocked tap finds the player: // three runs of 00.30 stood 3 tiles off (console B, 2026-11-09). constexpr int BLOCKED_TAP_SLACK = 3; @@ -53,6 +61,16 @@ constexpr int BLOCKED_TAP_SLACK = 3; // and one more, which may have moved before its battle showed. StepOutcome count_bike_taps(const RouteStep& step, const BikeTapCalls& calls); +// Whether `step` is walked on foot a tap at a time (RouteStep::tapped), +// each a tile, by count_bike_taps() with STEP_TAP_TRIES: an open leg or +// one to a wall or onto a spinner, not onto a warp or over a connection. +bool counts_step_taps(const RouteStep& step); + +// How long after a step tap of `step`, the `tap`th (from 1), the screen +// is still: the step, and on the last tap of a leg onto a spinner the +// slide (RouteStep::spin_tiles) and its settle. +Milliseconds step_tap_settle(const RouteStep& step, int tap); + } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp index 69ac64c188..4c9eeb3f6c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp @@ -8,6 +8,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Json/JsonValue.h" #include "PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_PokemonCenterRoom.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -92,18 +93,45 @@ const char* const MAP_NAMES[] = { "UndergroundPath_WestEntrance", "Route7", "CeladonCity", + // The Game Corner's poster and the Rocket Hideout down to B4F. + "CeladonCity_GameCorner", + "RocketHideout_B1F", + "RocketHideout_B2F", + "RocketHideout_B3F", + "RocketHideout_B4F", "CeruleanCave_1F", "CeruleanCave_2F", "CeruleanCave_B1F", }; +// Whether `maps` has a map named `name`. +bool has_map(const std::vector& maps, const std::string& name){ + return std::any_of(maps.begin(), maps.end(), [&](const MapData& map){ return map.name == name; }); +} + +// The coded room (pokemon_center_room()) of each Pokemon Center whose +// door is on one of `maps` but which has no map file of its own: +// Celadon City's. +void add_unmapped_centers(std::vector& maps){ + const size_t towns = maps.size(); + for (size_t town = 0; town < towns; town++){ + for (const MapWarp& warp : maps[town].warps){ + if (warp.to && is_pokemon_center(warp.to->map) && !has_map(maps, warp.to->map)){ + add_pokemon_center_room(maps, town); + break; + } + } + } +} + const std::vector& all_maps(){ static const std::vector MAPS = []{ std::vector maps; for (const char* name : MAP_NAMES){ maps.push_back(load_map(name)); } + add_unmapped_centers(maps); return maps; }(); return MAPS; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index 8cec6277b7..c9f6dfc447 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -59,6 +59,13 @@ int sight_onto(const std::vector& maps, const MapPosition& tile){ return sight; } +// How far the holds that find the player after an open leg, and the way +// back, may walk, per tile of the leg. 2 left Rocket Hideout B3F's "west +// 7" off the stairs unchecked: the hold to its west wall and back walk up +// to 18, and the leg ended short (00.31 r1, console B, 2026-11-10). Route +// 1's "west 4", whose holds walk 30, stays unchecked. +constexpr int OPEN_LEG_CHECK_TILES_PER_TILE = 3; + // The tiles an open `step` from `start` may have ended on with nothing // seen: its end, and up to OPEN_LEG_SHORTFALL tiles before it. std::vector short_candidates(const std::vector& maps, const MapPosition& start, const RouteStep& step){ @@ -75,6 +82,15 @@ bool is_wall_hold(const RouteStep& next){ return next.action == RouteAction::WALK && next.to_wall && !next.warps; } +// Whether `next` steps onto a spinner. From a tile short of its start it +// misses the arrow, or walks onto another, and ends elsewhere in the maze: +// "south 2" before Rocket Hideout B3F's "east 2" onto the arrow (3, 16) +// ended a tile short, the east leg walked into a wall, and the walk after +// it slid up to (10, 13) (00.31 r1 run 3, console B, 2026-11-10). +bool is_slide(const RouteStep& next){ + return next.action == RouteAction::WALK && next.spin_tiles && !next.warps; +} + // Whether `next`, a hold to a wall, ends on its planned tile from each of // `candidates`: then it finds the player itself. bool hold_finds(const std::vector& maps, const std::vector& candidates, const RouteStep& next){ @@ -417,7 +433,7 @@ class RouteRun{ // with nothing to show it (r16), unless it ends on its tile from // wherever the leg left the player. If it doesn't, finds the player at // walls first; without such holds, or if they and the way back walk - // farther than the leg there and back, trusts the leg. Only there, and + // farther than OPEN_LEG_CHECK_TILES_PER_TILE times the leg, trusts the leg. Only there, and // only that far, to keep the check cheap: in Viridian Forest (r16) it // walks 10 tiles after "west 6", while after Route 1's "west 4" the // only holds walk 30. An open leg after a short one walks on off the @@ -425,17 +441,17 @@ class RouteRun{ void check_open_leg(const RouteStep& step, const std::optional& start){ if (maps() == nullptr || m_planning->open_leg_check != OpenLegCheck::REANCHOR || !start || step.action != RouteAction::WALK || step.to_wall || step.warps - || m_next >= m_plan.size() || !is_wall_hold(m_plan[m_next]) + || m_next >= m_plan.size() || !(is_wall_hold(m_plan[m_next]) || is_slide(m_plan[m_next])) ){ return; } const std::vector candidates = short_candidates(*maps(), *start, step); - if (candidates.size() < 2 || hold_finds(*maps(), candidates, m_plan[m_next])){ + if (candidates.size() < 2 || (is_wall_hold(m_plan[m_next]) && hold_finds(*maps(), candidates, m_plan[m_next]))){ return; } const std::optional anchor = plan_reanchor(*maps(), candidates, step, m_planning->costs); - if (!anchor || anchor->holds.empty() || reanchor_tiles(*anchor) > 2 * step.tiles){ - m_calls.log("Route: no holds to walls within " + std::to_string(2 * step.tiles) + " tiles find the player if " + to_string(step) + " ended short; taken as walked."); + if (!anchor || anchor->holds.empty() || reanchor_tiles(*anchor) > OPEN_LEG_CHECK_TILES_PER_TILE * step.tiles){ + m_calls.log("Route: no holds to walls within " + std::to_string(OPEN_LEG_CHECK_TILES_PER_TILE * step.tiles) + " tiles find the player if " + to_string(step) + " ended short; taken as walked."); return; } m_calls.log(std::format( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h index 88e18a679b..52cbb9e1d1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h @@ -22,7 +22,8 @@ * (walked_before_warp()), and the way back goes on through the warp; * - an open leg that ended with nothing seen may still have ended up to * OPEN_LEG_SHORTFALL tiles short. When the next step is a hold to a - * wall that doesn't end on its tile from each of those, the player is + * wall that doesn't end on its tile from each of those, or a step onto + * a spinner (which a short start misses), the player is * found at walls the same way and walked back to the leg's end first. * When no holds find them, the leg is taken as walked, as before. * diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp index e7fbd0e42a..d2d935c811 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp @@ -76,14 +76,23 @@ double top_band_change(const ImageViewRGB32& before, const ImageViewRGB32& after return ImageMatch::pixel_RMSD(extract_box_reference(before, band), extract_box_reference(after, band)); } -// One tap of a leg counted out on the Bicycle (count_bike_taps()): a -// BIKE_TAP press released to a BIKE_TAP_PERIOD period, then -// BIKE_TAP_SETTLE for the screen to show the step, watching `interrupts` -// throughout. A tap that didn't scroll the screen is watched on for a -// late interrupt, which is cleared. +// A counted tap's press, its release and the wait after it for the +// screen to show the step. +struct TapTiming{ + Milliseconds press; + Milliseconds release; + Milliseconds settle; +}; +// On the Bicycle: a BIKE_TAP press released to a BIKE_TAP_PERIOD period, +// then BIKE_TAP_SETTLE. +constexpr TapTiming BIKE_TAP_TIMING{BIKE_TAP, BIKE_TAP_PERIOD - BIKE_TAP, BIKE_TAP_SETTLE}; + +// One tap of a leg counted out (count_bike_taps()), timed by `timing`, +// watching `interrupts` throughout. A tap that didn't scroll the screen +// is watched on for a late interrupt, which is cleared. BikeTap console_bike_tap( ConsoleHandle& console, ProControllerContext& context, - const RouteStep& step, const OverworldInterrupts& interrupts + const RouteStep& step, const OverworldInterrupts& interrupts, const TapTiming& timing ){ context.wait_for_all_requests(); const VideoSnapshot before = console.video().snapshot(); @@ -96,8 +105,8 @@ BikeTap console_bike_tap( const int ret = run_until( console, context, [&](ProControllerContext& context){ - pbf_press_dpad(context, dpad(step.direction), BIKE_TAP, BIKE_TAP_PERIOD - BIKE_TAP); - pbf_wait(context, BIKE_TAP_SETTLE); + pbf_press_dpad(context, dpad(step.direction), timing.press, timing.release); + pbf_wait(context, timing.settle); context.wait_for_all_requests(); }, callbacks @@ -122,9 +131,32 @@ StepWalk walk_bike_taps( StepWalk out{std::nullopt, current_time(), false, false}; const OverworldInterrupts& watched = step.wild ? interrupts.wild : interrupts.other; BikeTapCalls calls; - calls.tap = [&]{ return console_bike_tap(console, context, step, watched); }; + calls.tap = [&](int){ return console_bike_tap(console, context, step, watched, BIKE_TAP_TIMING); }; + calls.clear = [&](size_t index){ watched[index]->clear(console, context); }; + calls.log = [&](const std::string& message){ console.log(message, COLOR_ORANGE); }; + const StepOutcome outcome = count_bike_taps(step, calls); + out.stopped = outcome.walked; + out.blocked = outcome.blocked; + return out; +} + +// A leg on foot, a step tap at a time (counts_step_taps()): STEP_TAP +// pressed and STEP_TAP_RELEASE let go, past the step's lockout, then the +// slide off a spinner waited out (step_tap_settle()). +StepWalk walk_step_taps( + ConsoleHandle& console, ProControllerContext& context, + const RouteStep& step, const OverworldInterruptSet& interrupts +){ + StepWalk out{std::nullopt, current_time(), false, false}; + const OverworldInterrupts& watched = step.wild ? interrupts.wild : interrupts.other; + BikeTapCalls calls; + calls.tap = [&](int tap){ + const TapTiming timing{STEP_TAP, STEP_TAP_RELEASE, step_tap_settle(step, tap)}; + return console_bike_tap(console, context, step, watched, timing); + }; calls.clear = [&](size_t index){ watched[index]->clear(console, context); }; calls.log = [&](const std::string& message){ console.log(message, COLOR_ORANGE); }; + calls.tries = STEP_TAP_TRIES; const StepOutcome outcome = count_bike_taps(step, calls); out.stopped = outcome.walked; out.blocked = outcome.blocked; @@ -157,9 +189,8 @@ StepWalk walk_step( StepWalk out{std::nullopt, current_time(), false, false}; switch (step.action){ case RouteAction::WALK:{ - // Turning first, with a tap, makes the hold start from a standstill - // facing the right way: holding through a turn lost a tile on the - // console, while holds from a standstill were exact over 15 tiles. + // Turning first, with a tap, starts the hold from a standstill facing + // the right way: exact over 15 tiles, where a turn lost one. if (turns_first(step, speed, facing)){ turn_to(console, context, step.direction); } @@ -168,6 +199,7 @@ StepWalk walk_step( } context.wait_for_all_requests(); out.dark = on_dark_cave(console); + const VideoSnapshot before = console.video().snapshot(); out.hold_start = current_time(); BlackScreenOverWatcher arrival(COLOR_RED); Pokemon::WatchAlong fade(arrival); @@ -180,7 +212,7 @@ StepWalk walk_step( return out; } if (step.warps){ - wait_out_warp(console, context, step, fade); + wait_out_warp(console, context, step, fade, before); static_assert(AFTER_WARP_BATTLE_WATCH >= AFTER_WARP); if (run_from_battle_after_warp(console, context)){ console.log("Route: a wild battle, not the warp to " + step.end.map + "; the player is on " + to_string(step) + " before the warp.", COLOR_ORANGE); @@ -264,9 +296,14 @@ StepOutcome walk_and_watch( clear_open_message(console, context, step.wild ? interrupts.wild : interrupts.other, step); check_overworld(console, context, step); const LegRecorder recorder(console, context, interrupts, step); - const StepWalk walked = counts_bike_taps(step, speed) - ? walk_bike_taps(console, context, step, interrupts) - : walk_step(console, context, step, facing, interrupts, speed); + StepWalk walked; + if (counts_step_taps(step)){ + walked = walk_step_taps(console, context, step, interrupts); + }else if (counts_bike_taps(step, speed)){ + walked = walk_bike_taps(console, context, step, interrupts); + }else{ + walked = walk_step(console, context, step, facing, interrupts, speed); + } if (walked.stopped){ return StepOutcome{.end = StepEnd::STOPPED, .walked = walked.stopped, .blocked = walked.blocked}; } @@ -312,6 +349,7 @@ void hold_to_warp( callbacks.emplace_back(*watchers.back()); } context.wait_for_all_requests(); + const VideoSnapshot before = console.video().snapshot(); const int ret = run_until( console, context, [&](ProControllerContext& context){ @@ -321,7 +359,7 @@ void hold_to_warp( callbacks ); if (ret == 0){ - wait_out_warp(console, context, step); + wait_out_warp(console, context, step, before); check_warp_was_no_battle(console, context, step); return; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h index 2d5f45f8e4..8841226edd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h @@ -80,6 +80,11 @@ struct RouteStep{ // tiles on, to `end` (spin_slide()). The hold must end on the spinner: // held on, the player walks on after the slide. std::optional spin_tiles; + // WALK on foot: walked a tap at a time, each a tile, and each checked + // to have moved (count_step_taps()), as through the hideout's arrow + // floors, where a hold that ends a tile off slides the player + // elsewhere (console B, 2026-11-10, 00.31 r1). + bool tapped = false; // WALK, SURF: a wild Pokemon can appear on the way: the step crosses // tall grass or water. Elsewhere (indoors, streets) no wild battle can // start, so the walker doesn't watch for one. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp index 14129e9086..cd3c1f38d4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp @@ -358,6 +358,9 @@ bool OverworldSim::trainer_sees(Milliseconds pressed){ // game stopped them there: a warp, a trainer, a wild battle. bool OverworldSim::after_step(const Step& step, Milliseconds pressed){ const SimTiming& timing = m_script.timing; + if (step.warped && black_without_warp(pressed)){ + return true; + } m_map = step.map; m_player = step.player; m_state.steps++; @@ -780,23 +783,15 @@ std::optional OverworldSimWalker::hold_watching(const RouteStep& step, } // Whether a warp's fade showed and was over between `from` and now. -bool OverworldSimWalker::fade_over_since(Milliseconds from) const{ - const SimState& state = m_sim.state(); - if (state.screen == SimScreen::FADE){ - return false; - } - return std::any_of( - state.shown.begin(), state.shown.end(), - [&](const SimShown& shown){ return shown.screen == SimScreen::FADE && shown.at >= from; } - ); -} - // wait_out_warp(), then run_from_battle_after_warp(): false if the fade // was a wild battle's, run from. wait_out_warp()'s watcher takes a wild // battle's wipe for the fade (run 7; console B, 2026-11-03, Mt. Moon 1F): // the battle screen stands in for the wipe. The fade is watched for from // `watched_from`: a fade over by then is missed. bool OverworldSimWalker::after_warp(const RouteStep& step, int warps_before, Milliseconds watched_from){ + if (black_without_warp(step, warps_before, watched_from)){ + return true; + } if (m_sim.state().warps == warps_before){ if (!m_sim.watch({SimWatcher::BATTLE_SCREEN}, WARP_TIMEOUT)){ fail("walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + "."); @@ -880,8 +875,8 @@ StepOutcome OverworldSimWalker::walk_ridden(const RouteStep& step, std::optional clear_late(interrupts(step), OPEN_MESSAGE_WATCH, 1); } check_overworld(step); - if (m_rules.count_bike_taps && counts_bike_taps(step, m_speed)){ - const StepOutcome outcome = walk_bike_taps(step); + if (counts_step_taps(step) || (m_rules.count_bike_taps && counts_bike_taps(step, m_speed))){ + const StepOutcome outcome = counts_step_taps(step) ? walk_step_taps(step) : walk_bike_taps(step); if (outcome.end != StepEnd::DONE){ return outcome; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index 3b847ecc70..2eb49aedbe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -141,6 +141,10 @@ struct SimScript{ // (SimWalkerRules::confirm_turn) after 00.28 run 2 (console B, // 2026-11-09), where a one-tile leg only turned the player. std::set dropped_turn_taps; + // Fault injection: steps onto a warp, by number from 1, that show the + // fade's black and clear with the player where they were, not warped + // (console B, 2026-11-10 01:44, 00.31 run 4, "east 1 (warp)" on B4F). + std::set black_without_warp; // The player rides the Bicycle: a tap facing another way takes a step // too, a hold through a turn loses no tile // (MovementMechanics::BIKE_TAP_ONLY_TURNS), and no step tap is @@ -387,6 +391,10 @@ class OverworldSim{ int m_encounter_rate_buff = 0; // The turn taps so far, for SimScript::dropped_turn_taps. int m_turn_taps = 0; + // Steps onto a warp so far, and the fault on one + // (SimScript::black_without_warp): its black without the warp. + int m_warp_steps = 0; + bool black_without_warp(Milliseconds pressed); // The last tap, until a hold. std::optional m_last_tap; // When the last Bicycle tap started, and how many came too soon. @@ -465,6 +473,11 @@ struct SimWalkerRules{ // 2026-11-09 01:41, 00.27, the warp to CeruleanCity: the watch started // about 1.3 s into the hold). bool watch_fade_along_hold = true; + // A warp's fade is taken as the warp only once the screen after it + // shows the player off the map they held from (warp_left_scene()). + // Without it a black that cleared with the player where they were was + // taken as the warp (console B, 2026-11-10 01:44, 00.31 run 4). + bool confirm_warp_destination = true; // A turn tap is checked by the facing on screen, and tapped again // while the player faces another way (OverworldWalkSteps::turn_to()). // Without it a dropped tap left a one-tile leg turning the player @@ -553,6 +566,9 @@ class OverworldSimWalker{ // count_bike_taps() on the sim. StepOutcome walk_bike_taps(const RouteStep& step); BikeTap bike_tap(const RouteStep& step); + // count_bike_taps() on foot (counts_step_taps()). + StepOutcome walk_step_taps(const RouteStep& step); + BikeTap step_tap(const RouteStep& step, int tap); std::optional late_stop(const RouteStep& step); // stop_tiles(); without SimWalkerRules::whole_leg_in_dark, the dark // screen places the stop at the hold's start. @@ -565,6 +581,9 @@ class OverworldSimWalker{ std::optional walk_step(const RouteStep& step, std::optional facing); bool after_warp(const RouteStep& step, int warps_before, Milliseconds watched_from); bool fade_over_since(Milliseconds from) const; + // after_warp() on a fade seen with no warp: fails, or with + // SimWalkerRules::confirm_warp_destination off, takes it as the warp. + bool black_without_warp(const RouteStep& step, int warps_before, Milliseconds watched_from); [[noreturn]] void fail_off_route(const RouteStep& step); std::optional hold_watching(const RouteStep& step, Milliseconds hold, const std::vector& interrupts); size_t clear_late(const std::vector& interrupts, Milliseconds watch, size_t max); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp index 197d4d7355..578d0fb1e9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp @@ -70,7 +70,7 @@ BikeTap OverworldSimWalker::bike_tap(const RouteStep& step){ StepOutcome OverworldSimWalker::walk_bike_taps(const RouteStep& step){ const std::vector& ints = interrupts(step); BikeTapCalls calls; - calls.tap = [&]{ return bike_tap(step); }; + calls.tap = [&](int){ return bike_tap(step); }; calls.clear = [&](size_t index){ clear(ints[index]); }; calls.log = [&](const std::string& message){ m_log.push_back(message); }; m_leg_start = m_sim.state().time; @@ -78,6 +78,28 @@ StepOutcome OverworldSimWalker::walk_bike_taps(const RouteStep& step){ return count_bike_taps(step, calls); } +BikeTap OverworldSimWalker::step_tap(const RouteStep& step, int tap){ + const MapPosition before = m_sim.state().position; + m_sim.tap(step.direction, STEP_TAP, STEP_TAP_RELEASE); + m_sim.watch({}, step_tap_settle(step, tap)); + if (!(m_sim.state().position == before)){ + return BikeTap{.moved = true}; + } + return BikeTap{.moved = false, .interrupt = std::nullopt, .cleared_late = clear_late(interrupts(step), AFTER_LEG_WATCH, MAX_INTERRUPTIONS_PER_LEG) > 0}; +} + +StepOutcome OverworldSimWalker::walk_step_taps(const RouteStep& step){ + const std::vector& ints = interrupts(step); + BikeTapCalls calls; + calls.tap = [&](int tap){ return step_tap(step, tap); }; + calls.clear = [&](size_t index){ clear(ints[index]); }; + calls.log = [&](const std::string& message){ m_log.push_back(message); }; + calls.tries = STEP_TAP_TRIES; + m_leg_start = m_sim.state().time; + m_leg_dark = m_sim.state().dark; + return count_bike_taps(step, calls); +} + // walk_and_watch(), getting on the Bicycle first where // walk_overworld_route_with_recovery() does. StepOutcome OverworldSimWalker::walk(const RouteStep& step, std::optional facing){ @@ -118,6 +140,44 @@ void sim_step_once(OverworldSim& sim, Direction direction){ } +bool OverworldSimWalker::fade_over_since(Milliseconds from) const{ + const SimState& state = m_sim.state(); + if (state.screen == SimScreen::FADE){ + return false; + } + return std::any_of( + state.shown.begin(), state.shown.end(), + [&](const SimShown& shown){ return shown.screen == SimScreen::FADE && shown.at >= from; } + ); +} + + +// A fade seen with no warp: the console's screen check +// (warp_left_scene()) finds the scene from before the hold. +bool OverworldSimWalker::black_without_warp(const RouteStep& step, int warps_before, Milliseconds watched_from){ + const bool black_only = m_sim.state().warps == warps_before + && (m_sim.state().screen == SimScreen::FADE || fade_over_since(watched_from)); + if (!black_only){ + return false; + } + if (m_rules.confirm_warp_destination){ + fail("walk_overworld_route(): the warp to " + step.end.map + " not confirmed: the screen after the fade shows the scene from before the hold."); + } + m_sim.watch({}, OverworldWalkSteps::AFTER_WARP); + return true; +} + +bool OverworldSim::black_without_warp(Milliseconds pressed){ + if (!m_script.black_without_warp.contains(++m_warp_steps)){ + return false; + } + m_frozen = true; + schedule(pressed + m_script.timing.tile, SimScreen::FADE, false); + schedule(pressed + m_script.timing.tile + m_script.timing.fade, SimScreen::OVERWORLD, true); + note("black without a warp; the player stays at " + to_string(m_state.position) + "."); + return true; +} + } // namespace PokemonFRLG } // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin_Tests.cpp index e17a69bda4..433eb39443 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin_Tests.cpp @@ -193,6 +193,71 @@ UnitTestResult test_sim_walker_walks_slide(){ } +// 00.31 r1 (console B, 2026-11-10), Rocket Hideout B3F: off the stairs from +// B2F, the open leg west along the top corridor ended short, so the hold +// south to the wall stayed in the corridor, and the legs through the +// spinners after it all ran there: the walk ended a few tiles west of the +// stairs it came down, with no warp to B4F. +UnitTestResult test_short_leg_off_hideout_stairs(){ + static const std::vector maps = overworld_maps(); + const MapPosition start{"RocketHideout_B3F", {18, 2}}; + const MapPosition goal{"RocketHideout_B4F", map_point(maps, "RocketHideout_B4F", "warp_0")}; + const auto route = plan_overworld_route(maps, start, RouteGoal{goal, std::nullopt}, default_route_costs(), Direction::EAST); + if (!route){ + return std::string("No route from B3F's stairs to B4F."); + } + for (const int short_by : {1, 2}){ + SimScript script; + script.short_holds = {{1, short_by}}; + OverworldSim sim(maps, start, Direction::EAST, script); + OverworldSimWalker walker(sim); + const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = start, .label = "Sim"}; + const std::string failure = walker.run(*route, planning); + if (!failure.empty() || !(sim.state().position == goal)){ + return std::format( + "With the first leg {} tile(s) short, walked to {}, failure \"{}\".", + short_by, to_string(sim.state().position), failure + ); + } + } + return true; +} + + +// 00.31 r1 run 3 (console B, 2026-11-10), Rocket Hideout B3F: "south 2" +// from (1, 14), at the wall, ended a tile short at (1, 15) with nothing +// seen. "east 2", meant to step onto the arrow (3, 16), walked into the +// wall east of (1, 15); the position check after the next leg took that +// wall for the one east of the stop tile (7, 20) and found the player +// there. From column 1 the hold "east 11" stepped onto the arrow (2, 17), +// which slid them up round (6, 17) and (6, 13) to the stop tile (10, 13); +// the hold west onto the warp slid them back there round (6, 13) (frame: +// the player on (10, 13), the north arrow (10, 14) below). +UnitTestResult test_short_leg_before_hideout_arrows(){ + static const std::vector maps = overworld_maps(); + const MapPosition start{"RocketHideout_B3F", {1, 14}}; + const MapPosition goal{"RocketHideout_B4F", map_point(maps, "RocketHideout_B4F", "warp_0")}; + const auto route = plan_overworld_route(maps, start, RouteGoal{goal, std::nullopt}, default_route_costs(), Direction::WEST); + if (!route){ + return std::string("No route from B3F's west wall to B4F."); + } + for (const int short_by : {1, 2}){ + SimScript script; + script.short_holds = {{1, short_by}}; + OverworldSim sim(maps, start, Direction::WEST, script); + OverworldSimWalker walker(sim); + const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = start, .label = "Sim"}; + const std::string failure = walker.run(*route, planning); + if (!failure.empty() || !(sim.state().position == goal)){ + return std::format( + "With the first leg {} tile(s) short, walked to {}, failure \"{}\":{}", + short_by, to_string(sim.state().position), failure, describe(*route) + ); + } + } + return true; +} + // A lift whose door, the exit mat (1, 2), lets out on the floor picked. std::vector lift_maps(){ const std::string FLOOR = R"({ @@ -304,6 +369,14 @@ const SpinCase SPIN_CASES[] = { .input = {.name = "sim walker walks a slide", .body = test_sim_walker_walks_slide}, .expectation = {.description = "sim walker walks a slide"}, }, + { + .input = {.name = "a short leg off the hideout's stairs", .body = test_short_leg_off_hideout_stairs}, + .expectation = {.description = "B4F reached after a short first leg on B3F"}, + }, + { + .input = {.name = "a short leg before the hideout's arrows", .body = test_short_leg_before_hideout_arrows}, + .expectation = {.description = "B4F reached after a short leg to the arrow row on B3F"}, + }, { .input = {.name = "lift lets out on the floor picked", .body = test_lift_floor}, .expectation = {.description = "lift lets out on the floor picked"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp index 104d07542f..54987045d8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp @@ -7,7 +7,9 @@ #include #include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include #include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageDiff.h" #include "CommonFramework/ImageTools/ImageStats.h" #include "CommonTools/Async/InferenceRoutines.h" #include "CommonTools/VisualDetectors/BlackScreenDetector.h" @@ -293,9 +295,66 @@ std::vector warp_hold_watchers(const RouteStep& step, Poke return {&fade}; } +namespace{ + +// How close (pixel RMSD) the overlap of two screens is for the same scene. +constexpr double SAME_SCENE_RMSD = 25; +// The GBA screen's tiles across and down. +constexpr int SCREEN_TILES_X = 15; +constexpr int SCREEN_TILES_Y = 10; +// From the fade's end until the new map is in full light. +constexpr Milliseconds WARP_FADE_IN(300); + +// The RMSD of `before` and `after` where they overlap, with the scene +// scrolled `dx`, `dy` pixels: `after` at (x, y) shows `before` at +// (x + dx, y + dy). +double scrolled_rmsd(const ImageViewRGB32& before, const ImageViewRGB32& after, int dx, int dy){ + const size_t width = before.width() - (size_t)std::abs(dx); + const size_t height = before.height() - (size_t)std::abs(dy); + const ImageViewRGB32 old_part = before.sub_image(dx > 0 ? dx : 0, dy > 0 ? dy : 0, width, height); + const ImageViewRGB32 new_part = after.sub_image(dx < 0 ? -dx : 0, dy < 0 ? -dy : 0, width, height); + return ImageMatch::pixel_RMSD(old_part, new_part); +} + +// Whether `after` no longer shows the scene `before` showed, scrolled 0 to +// `max_tiles` tiles on toward `direction` inside the game box `game`: black +// then clear with the old scene back is no warp. A screen too dark to +// compare (a dark cave) counts as left. +bool warp_left_scene( + const ImageViewRGB32& before, const ImageViewRGB32& after, + const ImageFloatBox& game, Direction direction, int max_tiles +){ + const ImageViewRGB32 old_box = extract_box_reference(before, game); + const ImageViewRGB32 new_box = extract_box_reference(after, game); + if (old_box.width() != new_box.width() || old_box.height() != new_box.height()){ + return true; + } + if (dark_cave_screen(before) || dark_cave_screen(after)){ + return true; + } + const int tile_x = (int)old_box.width() / SCREEN_TILES_X; + const int tile_y = (int)old_box.height() / SCREEN_TILES_Y; + // Keep at least 5 tiles of overlap to compare. + const int most = std::min(max_tiles, (direction == Direction::NORTH || direction == Direction::SOUTH ? SCREEN_TILES_Y : SCREEN_TILES_X) - 5); + for (int tiles = 0; tiles <= most; tiles++){ + int dx = 0; + int dy = 0; + switch (direction){ + case Direction::NORTH: dy = -tiles * tile_y; break; + case Direction::SOUTH: dy = tiles * tile_y; break; + case Direction::WEST: dx = -tiles * tile_x; break; + case Direction::EAST: dx = tiles * tile_x; break; + } + if (scrolled_rmsd(old_box, new_box, dx, dy) < SAME_SCENE_RMSD){ + return false; + } + } + return true; +} + // One watcher for the whole fade: a ladder's black is short enough to be // over before a second watcher, started once the fade is seen, looks. -void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, Pokemon::WatchAlong& fade){ +void wait_out_fade(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, Pokemon::WatchAlong& fade){ if (fade.fired()){ console.log("Route: the fade to " + step.end.map + " was over before the hold ended."); return; @@ -310,10 +369,38 @@ void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const } } -void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step){ +} // namespace + +// A black screen that clears with the player where they were is no warp +// (console B, 2026-11-10 01:44, 00.31 run 4: "east 1 (warp)" was taken as +// walked while the player stayed on B4F). +void wait_out_warp( + ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, + Pokemon::WatchAlong& fade, const VideoSnapshot& before +){ + wait_out_fade(console, context, step, fade); + if (!before){ + return; + } + pbf_wait(context, WARP_FADE_IN); + context.wait_for_all_requests(); + const VideoSnapshot after = console.video().snapshot(); + if (!after){ + return; + } + if (!warp_left_scene(*before.frame, *after.frame, GameSettings::instance().GAME_BOX, step.direction, step.tiles + step.warp_slack + 2)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "walk_overworld_route(): the warp to " + step.end.map + " not confirmed: the screen after the fade shows the scene from before the hold.", + console + ); + } +} + +void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, const VideoSnapshot& before){ BlackScreenOverWatcher arrival(COLOR_RED); Pokemon::WatchAlong fade(arrival); - wait_out_warp(console, context, step, fade); + wait_out_warp(console, context, step, fade, before); } // Fails unless the overworld is up. Under the START menu or a message the @@ -606,6 +693,8 @@ void walk_step_leg( ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, const OverworldInterruptSet& interrupts, MoveSpeed speed ){ + context.wait_for_all_requests(); + const VideoSnapshot before = console.video().snapshot(); BlackScreenOverWatcher arrival(COLOR_RED); Pokemon::WatchAlong fade(arrival); Pokemon::walk_leg( @@ -619,7 +708,7 @@ void walk_step_leg( if (!step.warps){ return; } - wait_out_warp(console, context, step, fade); + wait_out_warp(console, context, step, fade, before); static_assert(AFTER_WARP_BATTLE_WATCH >= AFTER_WARP); check_warp_was_no_battle(console, context, step); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h index 5666f54367..8ec2f7cacf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h @@ -23,7 +23,9 @@ #include #include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" #include "Pokemon/AutoStory/Pokemon_ScreenEvents.h" #include "Pokemon/Navigation/Pokemon_LegWalker.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" @@ -176,10 +178,15 @@ std::vector warp_hold_watchers(const RouteStep& step, Poke // After a hold onto `step`'s warp: waits out its fade, unless `fade`, a // BlackScreenOverWatcher watched along the hold, saw it over already; -// else waits on with that watcher, which may have seen the black. -void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, Pokemon::WatchAlong& fade); +// else waits on with that watcher, which may have seen the black. Then +// fails unless the screen after the fade differs from `before`, taken +// before the hold (warp_left_scene()). +void wait_out_warp( + ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, + Pokemon::WatchAlong& fade, const VideoSnapshot& before +); // The same, watching only from now: for a caller that saw the black itself. -void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step); +void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, const VideoSnapshot& before); // Before `step`: fails unless the overworld is up. void check_overworld(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp index de344c2dc1..dbaa49462c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp @@ -8,6 +8,7 @@ */ #include +#include #include #include #include "Common/Cpp/Exceptions.h" @@ -31,11 +32,15 @@ struct WarpFadeInput{ Milliseconds fade{0}; // SimWalkerRules::watch_fade_along_hold. bool watch_along_hold = true; + // SimScript::black_without_warp and SimWalkerRules::confirm_warp_destination. + std::set black_without_warp = {}; + bool confirm_destination = true; }; struct WarpFadeExpectation{ // The failure the walk stops on; empty: the route is walked. std::string failure; + int warps = 1; }; struct WarpFadeCase{ @@ -73,15 +78,17 @@ class Test_OverworldWarpFade : public UnitTest{ out.end = OUTSIDE; SimScript script; script.timing.fade = m_case.input.fade; + script.black_without_warp = m_case.input.black_without_warp; SimWalkerRules rules; rules.watch_fade_along_hold = m_case.input.watch_along_hold; + rules.confirm_warp_destination = m_case.input.confirm_destination; OverworldSim sim(maps(), MART, Direction::SOUTH, script); OverworldSimWalker walker(sim, rules); const RoutePlanning planning{.maps = &maps(), .costs = default_route_costs(), .start = MART, .label = "Sim"}; const std::string failure = walker.run({out}, planning); const std::string& expected = m_case.expectation.failure; const bool as_expected = expected.empty() ? failure.empty() : failure.find(expected) != std::string::npos; - if (as_expected && sim.state().warps == 1){ + if (as_expected && sim.state().warps == m_case.expectation.warps){ return true; } std::string log; @@ -89,8 +96,8 @@ class Test_OverworldWarpFade : public UnitTest{ log += "\n " + line; } return std::format( - "Expected failure \"{}\" after 1 warp; got \"{}\" after {}:{}", - expected, failure, sim.state().warps, log + "Expected failure \"{}\" after {} warp(s); got \"{}\" after {}:{}", + expected, m_case.expectation.warps, failure, sim.state().warps, log ); } @@ -114,6 +121,15 @@ const WarpFadeCase WARP_FADE_CASES[] = { .input = {.name = "a fade still on when the hold ends, watched from its end", .fade = 1000ms, .watch_along_hold = false}, .expectation = {.failure = ""}, }, + { + .input = {.name = "black without a warp, destination confirmed", .fade = 1000ms, .black_without_warp = {1}}, + .expectation = {.failure = "the warp to ViridianCity not confirmed", .warps = 0}, + }, + { + // 00.31 run 4 (console B, 2026-11-10 01:44): taken as walked. + .input = {.name = "black without a warp, any black taken as the warp", .fade = 1000ms, .black_without_warp = {1}, .confirm_destination = false}, + .expectation = {.failure = "", .warps = 0}, + }, }; void add_tests_OverworldWarpFade(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/Data/JsonParser.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/Data/JsonParser.cpp index efc9dfe566..f0a4649081 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/Data/JsonParser.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/Data/JsonParser.cpp @@ -22,6 +22,7 @@ #include "VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryParty.h" #include "VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.h" #include "VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRooms.h" +#include "VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h" #include "VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h" #include "VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTrashCans.h" #include "LegacyJsonFormat.h" @@ -236,8 +237,9 @@ bool known_game_step(const StoryStep& step){ bool known_variant(const StoryStep& step){ switch (step.kind){ case StoryStepKind::ROUTE: - case StoryStepKind::LEGS: return step.variant.empty() || step.variant == RUN_VARIANT || step.variant == BIKE_VARIANT; + case StoryStepKind::LEGS: + return step.variant.empty() || step.variant == RUN_VARIANT || step.variant == BIKE_VARIANT || step.variant == TAPS_VARIANT; case StoryStepKind::STEP: return step.variant.empty() || step.variant == TRAINER_LINE_VARIANT || step.variant == TRAINER_WAIT_VARIANT; case StoryStepKind::GAME: diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index b089da5379..be8410780d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -9,9 +9,11 @@ #include #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "Pokemon/Navigation/Pokemon_RouteLog.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.h" @@ -23,6 +25,7 @@ #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStoryGrind.h" #include "PokemonFRLG_AutoStoryHideout.h" +#include "PokemonFRLG_AutoStoryLegs.h" #include "PokemonFRLG_AutoStoryScreenEvents.h" #include "PokemonFRLG_AutoStorySummary.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -166,7 +169,12 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ if (!facing){ facing = face_a_wall(env, start); } - const std::optional> route = fixed_route(story_maps(), start, step.legs); + std::optional> route = fixed_route(story_maps(), start, step.legs); + if (route && step.variant == TAPS_VARIANT){ + for (RouteStep& leg : *route){ + leg.tapped = true; + } + } if (!facing || !route || route->empty()){ return Pokemon::outcome_failed("bad_legs", to_string(start)); } @@ -439,42 +447,6 @@ void add_start_pose_check( add_start_check(checkpoint, start, std::move(reader), std::move(log)); } -std::optional> fixed_route( - const std::vector& maps, const MapPosition& start, const std::vector& legs -){ - const MapData* map = nullptr; - for (const MapData& candidate : maps){ - if (candidate.name == start.map){ - map = &candidate; - } - } - if (map == nullptr || !in_bounds(*map, start.point)){ - return std::nullopt; - } - std::vector route; - PlayerState player{start.point, elevation_at(*map, start.point), false}; - for (const StoryLeg& leg : legs){ - RouteStep step; - step.direction = leg.direction; - step.tiles = leg.tiles; - step.facing_after = leg.direction; - step.walk_only = !map->allow_running; - for (int c = 0; c < leg.tiles; c++){ - const StepKind kind = classify_step(*map, player, leg.direction); - const TilePos next = player.position.next(leg.direction); - if (kind != StepKind::WALK || !in_bounds(*map, next) || warps_on_step(*map, next)){ - return std::nullopt; - } - step.wild |= is_tall_grass(*map, next); - player = after_step(*map, player, leg.direction, kind); - } - step.to_wall = classify_step(*map, player, leg.direction) == StepKind::BLOCKED; - step.end = MapPosition{map->name, player.position}; - route.push_back(step); - } - return route; -} - Pokemon::Pose paced_pose(const Pokemon::Pose& patch, const StoryStep& step){ std::optional pace; if (const std::optional grind = parse_grind_step(step)){ @@ -524,6 +496,22 @@ std::optional wall_beside(const MapData& map, const TilePos& tile){ namespace{ +// A talk to a person or an item ball opens a message; an A that opens +// none faced nothing (00.31 b3f_rare_candy, console B, 2026-11-10: one A, +// "done", on the wrong floor). The message is left open for the next step. +bool talk_opens_message(ConsoleHandle& console, ProControllerContext& context){ + WhiteDialogWatcher opened(COLOR_RED); + const int shown = run_until( + console, context, + [](ProControllerContext& context){ + pbf_press_button(context, BUTTON_A, 160ms, 2000ms); + }, + {opened} + ); + return shown >= 0; +} + + bool walked(StoryEnv& env, RunState& state, const StoryStep& step){ const Outcome outcome = walk_route(env, state, step); if (outcome.succeeded() && outcome.pose){ @@ -749,7 +737,9 @@ ConsoleAction console_action_of(StoryActionId id){ return take_step; case StoryActionId::TALK: return [](StoryEnv& env, RunState&, const StoryStep&){ - pbf_press_button(env.context, BUTTON_A, 160ms, 800ms); + if (!talk_opens_message(env.console, env.context)){ + return Pokemon::outcome_failed("no_message", "talk: A opened no message; nothing to talk to or pick up here."); + } return Pokemon::outcome_ok(); }; case StoryActionId::ANSWER: diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index ee7cb5dced..74631b27cf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -212,13 +212,6 @@ void add_start_pose_check( Pokemon::Checkpoint& checkpoint, const std::optional& start, SavePoseReader read, StoryLog log ); -// `legs` from `start` as route steps for the walker, each checked against -// the map: nothing if a step is blocked or leaves the map. A leg ends "to -// wall" if the next step its way is blocked. -std::optional> fixed_route( - const std::vector& maps, const MapPosition& start, const std::vector& legs -); - // Where a GRIND or capture `step` that paces (pace = ...) leaves the // player who started it on `patch`: the patch's tile or the one its pace // leads to, as the last battle came, facing unknown. `patch` for any diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp index 61a208d570..288a6c4fb7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -174,6 +174,12 @@ bool walks_after(const StoryCheckpoint& row, size_t c){ }); } +// By the battle's map and name. The Game Corner's Grunt walks off once +// beaten (CeladonCity_GameCorner_Text_DefeatedGrunt: removeobject). +const std::map, std::string> TALK_BATTLE_HIDE_FLAGS{ + {{"CeladonCity_GameCorner", "rocket_grunt"}, "FLAG_HIDE_GAME_CORNER_ROCKET"}, +}; + // Whether `failure` is a script the sim does not have: a scene's trigger // stepped onto (no trainer sees the player there) or a leader's battle // after a talk (no trainer's message up). @@ -182,6 +188,19 @@ bool unscripted(const std::string& failure){ || failure.find(": no_battle.") != std::string::npos; } +// Hides from `maps` the trainer who leaves after `step`, a battle a talk +// starts (talk_battle_hide_flag()). Returns whether there was one. +bool hide_talk_battle_trainer(std::vector& maps, const StoryStep& step){ + const std::optional hidden = talk_battle_hide_flag(step); + if (!hidden){ + return false; + } + for (MapData& map : maps){ + hide_objects(map, {*hidden}); + } + return true; +} + // Row `row` on the sim with `script`, from its start. After a step the sim // does not play, the player is put on its pose_after, or on `landings`' // tile for it, the program going on from the pose_after either way. A @@ -195,7 +214,8 @@ RowRun run_row( RowRun out; std::optional off_maps; StoryPose at = *story_pose(*row.start); - auto sim = std::make_unique(sweep_maps(), MapPosition{at.map, at.tile}, at.facing.value_or(Direction::SOUTH), script); + std::vector maps = sweep_maps(); + auto sim = std::make_unique(maps, MapPosition{at.map, at.tile}, at.facing.value_or(Direction::SOUTH), script); const auto add = [&out](const SimState& state){ out.time += state.time; out.steps += state.steps; @@ -216,6 +236,7 @@ RowRun run_row( continue; } at = *story_pose(*step.pose_after); + const bool hidden = let_pass && hide_talk_battle_trainer(maps, step); const auto landing = landings.find(c); const MapPosition land{at.map, landing == landings.end() ? at.tile : landing->second}; if (!map_loaded(land.map)){ @@ -224,9 +245,9 @@ RowRun run_row( out.failure = walks_after(row, c) ? std::format("{}/{}: ends on {}, which has no map, with a walk after it.", row.id, step.name, land.map) : ""; break; } - if (!(sim->state().position == land)){ + if (!(sim->state().position == land) || hidden){ add(sim->state()); - sim = std::make_unique(sweep_maps(), land, at.facing.value_or(sim->state().facing), script); + sim = std::make_unique(maps, land, at.facing.value_or(sim->state().facing), script); } } if (out.failure.empty() && !sim->state().violations.empty()){ @@ -545,6 +566,17 @@ const FaultSweepCase FAULT_SWEEP_CASES[] = { {.input = {.fault = FaultClass::LOST_TAP}, .expectation = {}}, }; +std::optional talk_battle_hide_flag(const StoryStep& step){ + if (step.kind != StoryStepKind::BATTLE || !step.pose_after){ + return std::nullopt; + } + const auto found = TALK_BATTLE_HIDE_FLAGS.find({step.pose_after->map, step.name}); + if (found == TALK_BATTLE_HIDE_FLAGS.end()){ + return std::nullopt; + } + return found->second; +} + void add_tests_AutoStoryFaultSweep(UnitTestDatabase& database){ for (const FaultSweepCase& item : FAULT_SWEEP_CASES){ for (const StoryCheckpoint& row : story_checkpoints()){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.h index cda979a2f3..32f3fd1951 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.h @@ -7,13 +7,21 @@ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryFaultSweep_Tests_H #define PokemonAutomation_PokemonFRLG_AutoStoryFaultSweep_Tests_H +#include +#include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Pokemon_StorySteps.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ +// The hide flag the script of `step`, a battle a talk starts, sets when +// the trainer leaves after it: the sim, which plays no such battle, must +// hide them for the row to go on. +std::optional talk_battle_hide_flag(const Pokemon::StoryStep& step); + // Each class of console failure injected at every row of the story on the // overworld sim; the rows the program still fails are known failing // (PokemonFRLG_AutoStoryFaultSweep_Tests.cpp). diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout_Tests.cpp index e84ba87ea8..6e678803fa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout_Tests.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include "Common/Cpp/TestRunners/UnitTest.h" @@ -15,6 +16,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" #include "PokemonFRLG_AutoStoryHideout.h" #include "PokemonFRLG_AutoStoryHideoutLift.h" +#include "PokemonFRLG_AutoStoryLegs.h" #include "PokemonFRLG_AutoStoryRowSim.h" #include "PokemonFRLG_AutoStoryTableSteps.h" #include "PokemonFRLG_AutoStoryFieldSteps.h" @@ -212,6 +214,112 @@ UnitTestResult test_coded_spinners(){ return true; } +// `legs` from `start` tapped out on the sim (RouteStep::tapped), facing +// `facing`: as planned, and with each of the turns the taps make dropped +// in turn (a tap facing another way only turns the player, and a +// dropped one doesn't even turn them). Empty if each run ends on `goal`. +std::string tap_legs_on_sim( + const MapPosition& start, Direction facing, const std::vector& legs, const MapPosition& goal, + const std::vector& maps = story_maps() +){ + std::optional> route = fixed_route(maps, start, legs); + if (!route || !(route->back().end == goal)){ + return "The legs from " + to_string(start) + " don't end on " + to_string(goal) + "."; + } + for (RouteStep& step : *route){ + step.tapped = true; + } + for (int dropped = 0; dropped <= (int)legs.size(); dropped++){ + SimScript script; + if (dropped > 0){ + script.dropped_turn_taps = {dropped}; + } + OverworldSim sim(maps, start, facing, script); + OverworldSimWalker walker(sim); + const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = start, .label = "Sim"}; + const std::string failure = walker.run(*route, planning); + if (!failure.empty() || !(sim.state().position == goal)){ + return std::format("With turn tap {} dropped, walked to {}, failure \"{}\".", dropped, to_string(sim.state().position), failure); + } + } + return ""; +} + +// The planned route from `start` to `goal` on the sim, with each of its +// holds 1 and 2 tiles short in turn. Empty if each run ends on `goal`. +std::string short_holds_on_sim(const MapPosition& start, Direction facing, const MapPosition& goal){ + const std::vector& maps = story_maps(); + const auto route = plan_overworld_route(maps, start, RouteGoal{goal, std::nullopt}, default_route_costs(), facing); + if (!route){ + return "No route from " + to_string(start) + "."; + } + for (int hold = 1; hold <= (int)route->size(); hold++){ + for (const int short_by : {1, 2}){ + SimScript script; + script.short_holds = {{hold, short_by}}; + OverworldSim sim(maps, start, facing, script); + OverworldSimWalker walker(sim); + const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = start, .label = "Sim"}; + const std::string failure = walker.run(*route, planning); + if (!failure.empty() || !(sim.state().position == goal)){ + return std::format("Hold {} {} short from {}: walked to {}, failure \"{}\".", hold, short_by, to_string(start), to_string(sim.state().position), failure); + } + } + } + return ""; +} + +// 00.31's taps through B3F's arrow floor (frlg-00.31.plan.json's +// b3f_arrow_maze and b3f_back_to_candy_row, pokeguy's way): down from +// the stairs (18, 2) to below the stairs to B4F (15, 19), and back from +// them (15, 18) to the stop (10, 13). The routes planned after them, +// onto the stairs to B4F and east to below the Rare Candy, have no +// arrow on the way: a short hold there is found again. B4F after the +// LIFT KEY, a tap a tile from the Grunt's line to below the key and on +// to the stairs (11, 15) with any one turn dropped, and the stairs up. +UnitTestResult test_b3f_maze_taps(){ + using Pokemon::StoryLeg; + const MapPosition below_stairs{"RocketHideout_B3F", {15, 19}}; + const MapPosition candy_stop{"RocketHideout_B3F", {10, 13}}; + const MapPosition b4f_below_key{"RocketHideout_B4F", {3, 3}}; + const MapPosition b4f_stairs{"RocketHideout_B4F", {11, 15}}; + // The Lift Key Grunt (4, 2) is beaten by then: (4, 3), in his line, is + // open floor. + std::vector key_grunt_beaten = story_maps(); + for (MapData& map : key_grunt_beaten){ + for (MapObject& object : map.objects){ + if (map.name == "RocketHideout_B4F" && object.x == 4 && object.y == 2){ + object.trainer.reset(); + } + } + } + const std::vector failures{ + tap_legs_on_sim({"RocketHideout_B3F", {18, 2}}, Direction::EAST, { + {Direction::WEST, 6}, {Direction::SOUTH, 5}, {Direction::WEST, 7}, {Direction::SOUTH, 2}, {Direction::WEST, 1}, + {Direction::SOUTH, 2}, {Direction::WEST, 2}, {Direction::SOUTH, 3}, {Direction::WEST, 3}, {Direction::SOUTH, 2}, + {Direction::EAST, 2}, {Direction::WEST, 2}, {Direction::SOUTH, 5}, {Direction::EAST, 10}, {Direction::NORTH, 6}, + }, below_stairs), + tap_legs_on_sim({"RocketHideout_B3F", {15, 18}}, Direction::WEST, { + {Direction::SOUTH, 2}, {Direction::WEST, 5}, {Direction::NORTH, 6}, + }, candy_stop), + short_holds_on_sim(below_stairs, Direction::NORTH, {"RocketHideout_B4F", map_point(story_maps(), "RocketHideout_B4F", "warp_0")}), + short_holds_on_sim(candy_stop, Direction::NORTH, {"RocketHideout_B3F", {12, 13}}), + tap_legs_on_sim({"RocketHideout_B4F", {4, 3}}, Direction::WEST, { + {Direction::WEST, 1}, + }, b4f_below_key), + tap_legs_on_sim(b4f_below_key, Direction::NORTH, { + {Direction::EAST, 3}, {Direction::SOUTH, 4}, {Direction::EAST, 5}, {Direction::SOUTH, 8}, + }, b4f_stairs, key_grunt_beaten), + short_holds_on_sim(b4f_stairs, Direction::SOUTH, {"RocketHideout_B3F", {15, 18}}), + }; + for (const std::string& failure : failures){ + if (!failure.empty()){ + return failure; + } + } + return true; +} + struct AutoStoryHideoutBodyInput{ std::string name; UnitTestResult (*body)(); @@ -251,6 +359,10 @@ const AutoStoryHideoutBodyCase HIDEOUT_BODY_CASES[] = { .input = {.name = "coded spinners", .body = test_coded_spinners}, .expectation = {.description = "B2F's and B3F's arrows come from code, not the map"}, }, + { + .input = {.name = "B3F's arrow floor a tap at a time", .body = test_b3f_maze_taps}, + .expectation = {.description = "below the stairs to B4F, with any one turn dropped"}, + }, }; const LiftCase LIFT_CASES[] = { diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp index 3b4c0f3fc6..b90d21a91b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" +#include "PokemonFRLG_AutoStoryLegs.h" #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStoryFaultSweep_Tests.h" #include "PokemonFRLG_AutoStoryResources.h" @@ -709,6 +711,47 @@ UnitTestResult test_celadon_save_place(Logger&){ return true; } +// 00.31 on the sim: out of Celadon's Center, the Game Corner's poster +// Grunt, the switch, the Rocket Hideout down to B4F's Lift Key Grunt, the +// LIFT KEY, and back up to B3F below its Rare Candy. +// A battle a talk starts (the poster Grunt's) is the sim's to skip: it +// leaves the player where the plan says, and the trainer walks off +// (talk_battle_hide_flag()). +UnitTestResult test_hideout_row(Logger&){ + const StoryCheckpoint& row = checkpoint("00.31"); + StoryPose at = *story_pose(*row.start); + std::vector maps = maps_after_route10(); + auto sim = std::make_unique(maps, MapPosition{at.map, at.tile}, *at.facing); + std::vector fought; + for (const StoryStep& step : row.steps){ + const std::optional hidden = talk_battle_hide_flag(step); + if (!hidden){ + if (const std::string failure = row_step_on_sim(*sim, at, step, row.id); !failure.empty()){ + return "00.31: ended on " + to_string(sim->state().position) + "; " + failure; + } + continue; + } + at = *story_pose(*step.pose_after); + for (MapData& map : maps){ + hide_objects(map, {*hidden}); + } + fought = sim->state().trainers_beaten; + sim = std::make_unique(maps, MapPosition{at.map, at.tile}, *at.facing); + } + fought.insert(fought.end(), sim->state().trainers_beaten.begin(), sim->state().trainers_beaten.end()); + if (fought != std::vector{"rocket_m"}){ + return std::format("00.31: fought {} trainers on the sim, not the Lift Key Grunt alone.", fought.size()); + } + if (!sim->state().violations.empty()){ + return "00.31: a violation on the way: " + sim->state().violations.back(); + } + const MapPosition end{"RocketHideout_B3F", {12, 13}}; + if (!(sim->state().position == end)){ + return "00.31: ended on " + to_string(sim->state().position) + ", not " + to_string(end) + "."; + } + return true; +} + } // namespace @@ -731,6 +774,7 @@ const AutoStoryLavenderCase AUTO_STORY_LAVENDER_CASES[] = { {.input = {"00.30 a wild battle on the step into Route 7's grass", test_route7_grass_battles}, .expectation = {}}, {.input = {"00.30 Route 8 west from a start up to 3 tiles off", test_route8_west_off_start}, .expectation = {}}, {.input = {"00.30 saves in Celadon City's Pokemon Center", test_celadon_save_place}, .expectation = {}}, + {.input = {"00.31 the Game Corner's poster, the Rocket Hideout to B4F's LIFT KEY and B3F's Rare Candy", test_hideout_row}, .expectation = {}}, }; void add_tests_AutoStoryLavender(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp new file mode 100644 index 0000000000..420268e05a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp @@ -0,0 +1,77 @@ +/* AutoStory Legs + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin.h" +#include "PokemonFRLG_AutoStoryLegs.h" +#include "PokemonFRLG_AutoStoryEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +// A leg's step onto a spinner: only its last (`last`), which slides +// `player` on to where the slide ends, facing its way (spin_slide()). +// False mid-leg, or for a slide that loops or leaves through a warp. +bool land_on_spinner(const MapData& map, PlayerState& player, bool last, RouteStep& step){ + const std::optional slide = spin_slide(map, player); + if (!last || !slide){ + return false; + } + player = slide->end; + step.spin_tiles = slide->tiles; + step.facing_after = slide->facing; + return true; +} + +} // namespace + +std::optional> fixed_route( + const std::vector& maps, const MapPosition& start, const std::vector& legs +){ + const MapData* map = nullptr; + for (const MapData& candidate : maps){ + if (candidate.name == start.map){ + map = &candidate; + } + } + if (map == nullptr || !in_bounds(*map, start.point)){ + return std::nullopt; + } + std::vector route; + PlayerState player{start.point, elevation_at(*map, start.point), false}; + for (const StoryLeg& leg : legs){ + RouteStep step; + step.direction = leg.direction; + step.tiles = leg.tiles; + step.facing_after = leg.direction; + step.walk_only = !map->allow_running; + for (int c = 0; c < leg.tiles; c++){ + const StepKind kind = classify_step(*map, player, leg.direction); + const TilePos next = player.position.next(leg.direction); + if (kind != StepKind::WALK || !in_bounds(*map, next) || warps_on_step(*map, next)){ + return std::nullopt; + } + step.wild |= is_tall_grass(*map, next); + player = after_step(*map, player, leg.direction, kind); + if (spin_direction(*map, player.position) && !land_on_spinner(*map, player, c + 1 == leg.tiles, step)){ + return std::nullopt; + } + } + step.to_wall = !step.spin_tiles && classify_step(*map, player, leg.direction) == StepKind::BLOCKED; + step.end = MapPosition{map->name, player.position}; + route.push_back(step); + } + return route; +} + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h new file mode 100644 index 0000000000..d19c8fd42f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h @@ -0,0 +1,39 @@ +/* AutoStory Legs + * + * From: https://github.com/PokemonAutomation/ + * + * LEGS steps: a fixed list of legs, as the walker's route steps. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryLegs_H +#define PokemonAutomation_PokemonFRLG_AutoStoryLegs_H + +#include +#include +#include +#include "Pokemon/AutoStory/Types/Pokemon_StoryStep.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +// The variant of LEGS walked on foot a tap at a time, each tap checked to +// have moved the player a tile (RouteStep::tapped): the Rocket Hideout's +// arrow floors, where a hold a tile off slides the player elsewhere. +inline const std::string TAPS_VARIANT = "taps"; + +// `legs` from `start` as route steps for the walker, each checked against +// the map: nothing if a step is blocked or leaves the map. A leg ends "to +// wall" if the next step its way is blocked. +std::optional> fixed_route( + const std::vector& maps, const MapPosition& start, const std::vector& legs +); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRooms.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRooms.cpp index e6dbf9cb22..290f50c27d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRooms.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRooms.cpp @@ -71,7 +71,12 @@ void walk_room_legs( facing = leg.direction; continue; } + VideoSnapshot before; for (int tile = 0; tile < leg.tiles; tile++){ + if (leg.warps && tile + 1 == leg.tiles){ + context.wait_for_all_requests(); + before = console.video().snapshot(); + } step_once(console, context, leg.direction, facing); facing = leg.direction; } @@ -80,7 +85,7 @@ void walk_room_legs( step.direction = leg.direction; step.tiles = 1; step.warps = true; - OverworldWalkSteps::wait_out_warp(console, context, step); + OverworldWalkSteps::wait_out_warp(console, context, step, before); } } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index 91ce25068e..a3fbdc9155 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -13,6 +13,7 @@ #include #include "Common/Cpp/Exceptions.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "PokemonFRLG_AutoStoryLegs.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" 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 430c754d9e..a5d02a435d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp @@ -138,7 +138,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 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29 00.30"; +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 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29 00.30 00.31"; const RunPlanScenario RUN_PLAN_CASES[] = { { @@ -229,11 +229,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 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29 00.30"}, + .expectation = {.expected_ids = "00.11 00.12 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29 00.30 00.31"}, }, { .input = {.name = "Gift RNG off: 00.12b runs when started at", .first = "00.12b"}, - .expectation = {.expected_ids = "00.12b 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29 00.30"}, + .expectation = {.expected_ids = "00.12b 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29 00.30 00.31"}, }, { .input = { .name = "Gift RNG: started at 00.12b, from the save beside the salesman", @@ -258,7 +258,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 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29 00.30"}, + .expectation = {.expected_ids = "00.12b 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29 00.30 00.31"}, }, { .input = { .name = "Starter RNG first, with both on", 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 174473bdc1..48a3e724dc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -22,6 +22,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_AutoStoryLegs.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryCapture.h" #include "PokemonFRLG_AutoStoryGrind.h" @@ -230,8 +231,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po UnitTestResult test_routes_and_chain(){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 37 || checkpoints[0].start){ - return "Expected 37 checkpoints, the first from a new game."; + if (checkpoints.size() != 38 || checkpoints[0].start){ + return "Expected 38 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ @@ -359,7 +360,7 @@ UnitTestResult test_runs_after_shoes(){ size_t runs = 0; for (const StoryCheckpoint& checkpoint : story_checkpoints()){ for (const StoryStep& step : checkpoint.steps){ - if (step.kind != StoryStepKind::ROUTE && step.kind != StoryStepKind::LEGS){ + if ((step.kind != StoryStepKind::ROUTE && step.kind != StoryStepKind::LEGS) || step.variant == TAPS_VARIANT){ continue; } const MoveSpeed expected = has_shoes ? MoveSpeed::RUN : MoveSpeed::WALK; @@ -603,7 +604,7 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set