Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1d619d9
FRLG AutoStory 00.31: Celadon Game Corner to the Rocket Hideout's LIF…
dayfine Nov 10, 2026
21861ce
FRLG AutoStory: the fault sweep's trainer hiding in its own function,…
dayfine Nov 10, 2026
3ed6b4c
FRLG Overworld: red sim test, a short first leg off the Rocket Hideou…
dayfine Nov 10, 2026
9da5d77
FRLG Overworld: check open legs whose wall holds and way back walk up…
dayfine Nov 10, 2026
e81230c
FRLG Overworld: the B3F short-leg sim test in the spinner tests, keep…
dayfine Nov 10, 2026
9562615
FRLG Overworld: the open-leg check's tiles-per-tile limit in the .cpp…
dayfine Nov 10, 2026
3484975
FRLG Overworld: check an open leg before a step onto a spinner
dayfine Nov 10, 2026
f23905d
FRLG AutoStory 00.31: B3F's arrow floor as pokeguy's legs, a checked …
dayfine Nov 10, 2026
6f3974e
fixup: no ms literal
dayfine Nov 10, 2026
9cb0488
FRLG AutoStory: LEGS take the taps variant
dayfine Nov 10, 2026
515782a
FRLG AutoStory: three step taps per tile, the run check skips taps legs
dayfine Nov 10, 2026
ada1353
FRLG AutoStory 00.31: the golden trace with the taps legs; the B3F ta…
dayfine Nov 10, 2026
fcde135
FRLG AutoStory 00.31: golden trace from the old one, only 00.31 chang…
dayfine Nov 10, 2026
ab60d97
FRLG AutoStory: fixed_route in its own file, AutoStoryLegs.cpp, keepi…
dayfine Nov 10, 2026
421a651
FRLG AutoStory: TAPS_VARIANT and fixed_route() in AutoStoryLegs.h, of…
dayfine Nov 10, 2026
5ba4c26
FRLG AutoStory: JsonParser includes AutoStoryLegs.h; AutoStory_Tests …
dayfine Nov 10, 2026
62e1ced
FRLG AutoStory: close JsonParser's AutoStoryLegs.h include
dayfine Nov 10, 2026
bd86cf7
FRLG AutoStory: Lavender tests include AutoStoryLegs.h
dayfine Nov 10, 2026
55ff73b
FRLG AutoStory 00.31: a talk fails unless A opens a message
dayfine Nov 10, 2026
3f53ca1
FRLG AutoStory 00.31: keep the talk check beside its step
dayfine Nov 10, 2026
5fb0054
FRLG AutoStory 00.31: tap B4F's open floor after the LIFT KEY
dayfine Nov 10, 2026
d9190da
FRLG overworld: confirm a warp's destination after its fade
dayfine Nov 10, 2026
17c8115
FRLG overworld: keep warp confirmation within code health limits
dayfine Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <algorithm>
#include <format>
#include "PokemonFRLG_BikeSpinPresses.h"
#include "PokemonFRLG_OverworldBikeTaps.h"

namespace PokemonAutomation{
Expand All @@ -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){
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Bicycle Taps

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=7 (advisory above 6, limit 8)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -32,13 +32,21 @@
// 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<BikeTap()> tap;
std::function<BikeTap(int tap)> tap;
std::function<void(size_t interrupt)> clear;
std::function<void(const std::string& message)> 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;
Expand All @@ -53,6 +61,16 @@
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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<MapData>& 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<MapData>& 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<MapData>& all_maps(){
static const std::vector<MapData> MAPS = []{
std::vector<MapData> maps;
for (const char* name : MAP_NAMES){
maps.push_back(load_map(name));
}
add_unmapped_centers(maps);
return maps;
}();
return MAPS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Recovery

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=608 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -59,6 +59,13 @@
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<StopCandidate> short_candidates(const std::vector<MapData>& maps, const MapPosition& start, const RouteStep& step){
Expand All @@ -75,6 +82,15 @@
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<MapData>& maps, const std::vector<StopCandidate>& candidates, const RouteStep& next){
Expand Down Expand Up @@ -417,25 +433,25 @@
// 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
// route, which isn't checked.
void check_open_leg(const RouteStep& step, const std::optional<MapPosition>& 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<StopCandidate> 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<Reanchor> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,23 @@
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();
Expand All @@ -96,8 +105,8 @@
const int ret = run_until<ProControllerContext>(
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
Expand All @@ -122,9 +131,32 @@
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;
Expand Down Expand Up @@ -157,9 +189,8 @@
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);
}
Expand All @@ -168,6 +199,7 @@
}
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);
Expand All @@ -180,7 +212,7 @@
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);
Expand Down Expand Up @@ -253,7 +285,7 @@
// also after a leg the maps see no wild tiles on. One on its way before
// the step starts was set off before it: the step isn't walked, and is
// BATTLE_BEFORE (clear_battle_before()).
StepOutcome walk_and_watch(

Check warning on line 288 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::walk_and_watch( ConsoleHandle & console , ProControllerContext & context , const RouteStep & step , std :: optional<Direction> facing , const OverworldInterruptSet & interrupts , MoveSpeed speed): function_lines=42 (advisory above 25, limit 50)
ConsoleHandle& console, ProControllerContext& context,
const RouteStep& step, std::optional<Direction> facing,
const OverworldInterruptSet& interrupts, MoveSpeed speed
Expand All @@ -264,9 +296,14 @@
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};
}
Expand Down Expand Up @@ -298,7 +335,7 @@
// after a wild battle, so holding on reaches the warp however far they
// got (console B, 2026-11-01: Camper Liam stopped "south 9 (warp)" out of
// Pewter Gym). After a trainer the player faces them, so this turns first.
void hold_to_warp(

Check warning on line 338 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::hold_to_warp( ConsoleHandle & console , ProControllerContext & context , const RouteStep & step , const OverworldInterrupts & interrupts , MoveSpeed speed): function_lines=40 (advisory above 25, limit 50)
ConsoleHandle& console, ProControllerContext& context,
const RouteStep& step, const OverworldInterrupts& interrupts, MoveSpeed speed
){
Expand All @@ -312,6 +349,7 @@
callbacks.emplace_back(*watchers.back());
}
context.wait_for_all_requests();
const VideoSnapshot before = console.video().snapshot();
const int ret = run_until<ProControllerContext>(
console, context,
[&](ProControllerContext& context){
Expand All @@ -321,7 +359,7 @@
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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.
Expand Down
Loading
Loading