Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -61,7 +61,7 @@
: SmallDictionaryMatcher(dictionary())
{}

static JsonObject dictionary(){

Check warning on line 64 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::PlaceNameMatcher::dictionary(): function_lines=38 (advisory above 25, limit 50)
JsonObject english;
for (const auto& [slug, name] : {
std::pair<std::string_view, std::string_view>{"pallet-town", "Pallet Town"},
Expand All @@ -73,6 +73,9 @@
{"route-3", "Route 3"},
{"route-4", "Route 4"},
{"cerulean-city", "Cerulean City"},
{"route-21", "Route 21"},
{"route-22", "Route 22"},
{"route-23", "Route 23"},
{"route-24", "Route 24"},
{"route-25", "Route 25"},
{"route-10", "Route 10"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* Overworld Bicycle
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h"
#include "PokemonFRLG_BikeSpinPresses.h"
#include "PokemonFRLG_OverworldBike.h"
#include "PokemonFRLG_PlayerFacingReader.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{
namespace OverworldWalkSteps{

using namespace MovementMechanics;


bool select_onto_bike(const BikeSelectCalls& calls){
for (int press = 1; press <= 2; press++){
calls.press_select();
if (calls.riding()){
return true;
}
if (calls.wait_to_read_again){
calls.wait_to_read_again();
}
if (calls.riding()){
return true;
}
}
return false;
}

bool screen_shows_riding(const ImageViewRGB32& screen, PlayerGender player){
if (StartMenuDetector(COLOR_RED).detect(screen) || SelectionDialogDetector(COLOR_RED).detect(screen)
|| WhiteDialogDetector(COLOR_RED).detect(screen)
){
return false;
}
return !read_player_facing(screen, player).has_value();
}

void get_on_bike(ConsoleHandle& console, ProControllerContext& context, PlayerGender player){
BikeSelectCalls calls;
calls.press_select = [&]{
pbf_press_button(context, BUTTON_MINUS, BIKE_SELECT_PRESS, BIKE_SELECT_SETTLE);
};
calls.riding = [&]{
context.wait_for_all_requests();
VideoSnapshot screen = console.video().snapshot();
const bool riding = screen && screen_shows_riding(*screen.frame, player);
console.log(riding ? "Bike: riding." : "Bike: not riding after SELECT.", riding ? COLOR_BLACK : COLOR_ORANGE);
return riding;
};
calls.wait_to_read_again = [&]{
pbf_wait(context, BIKE_SELECT_SETTLE);
};
console.log("Bike: SELECT (MINUS) onto the Bicycle.");
if (!select_onto_bike(calls)){
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT,
"get_on_bike(): not on the Bicycle after SELECT twice. Is it registered?",
console
);
}
}


} // namespace OverworldWalkSteps
} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
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=701 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -87,6 +87,19 @@
return next.action == RouteAction::WALK && next.to_wall && !next.warps;
}

// Whether `step`, an open leg on the water, is followed by `next`, another
// open leg: nothing between them shows where `step` ended (console B,
// 2026-11-13, 12.03: "south 86 (open)" down Route 21 stopped short at a
// sand bar unseen, and "east 7 (open)" went on from there).
// Only a long leg: the sims' shorter ones (Viridian's pond "east 5",
// Route 23's "north 17") have no walls near enough to check them by, and
// the unseen stop was 86 tiles into the leg.
constexpr int OPEN_WATER_CHECKED_TILES = 20;
bool open_water_chain(const RouteStep& step, const RouteStep& next){
return step.surfing && !step.to_wall && !step.warps && step.tiles > OPEN_WATER_CHECKED_TILES
&& next.action == RouteAction::WALK && !next.to_wall && !next.warps && !next.spin_tiles;
}

// 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)
Expand Down Expand Up @@ -231,7 +244,7 @@
}
}

void run(){

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::RouteRun::run(): function_lines=46 (advisory above 25, limit 50)
m_lines.plan(m_at, m_plan);
while (m_next < m_plan.size()){
const RouteStep step = m_plan[m_next];
Expand All @@ -254,12 +267,9 @@
continue;
}
if (outcome.end == StepEnd::DONE){
const std::optional<MapPosition> start = m_next >= m_unchecked ? m_at : std::nullopt;
remember_walked(step);
m_at = step.end;
m_facing = step.facing_after;
m_lines.done(step, ++m_next, m_holds);
check_open_leg(step, start);
if (!after_done(step)){
return;
}
continue;
}
const std::optional<MapPosition> start = m_next >= m_holds ? m_at : std::nullopt;
Expand All @@ -282,6 +292,25 @@
}

private:
// After `step` ended as planned: false, the route failed, if it lands
// the player and they are still on the water.
bool after_done(const RouteStep& step){
if (step.lands_after > 0 && m_calls.landed_on && !m_calls.landed_on(step.end)){
m_calls.fail(std::format(
"walk_overworld_route(): still surfing after {}: the player didn't land on {}.",
to_string(step), to_string(step.end)
));
return false;
}
const std::optional<MapPosition> start = m_next >= m_unchecked ? m_at : std::nullopt;
remember_walked(step);
m_at = step.end;
m_facing = step.facing_after;
m_lines.done(step, ++m_next, m_holds);
check_open_leg(step, start);
return true;
}

static bool is_gate_step(const RouteStep& step){
return step.action == RouteAction::OPEN_GATE || step.action == RouteAction::PRESS_SWITCH;
}
Expand Down Expand Up @@ -474,8 +503,11 @@
// 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. A leg onto a spinner isn't checked: its
// taps wait out the slide and its settle, and it ends on the stop. The
// route, which isn't checked, except on the water: there an open leg
// followed by another open leg is checked however far the holds walk,
// and stops the route if none find the player (open_water_chain()).
// A leg onto a spinner isn't checked: its taps wait out the slide and
// its settle, and it ends on the stop. The
// tiles short of its arrow left out that stop, and the hold west "to
// the wall (7, 11)" after Rocket Hideout B2F's "east 2" to the stop
// (14, 13) slid from there to (10, 15) (09.02, console B, 2026-11-11).
Expand All @@ -484,20 +516,32 @@
// back over tiles already walked (09.02's B2F, console B, 2026-11-11
// 15:34: a hold back north to (21, 2) after "south 2" and to the wall
// (17, 5) after "north 3").
void check_open_leg(const RouteStep& step, const std::optional<MapPosition>& start){

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::RouteRun::check_open_leg( const RouteStep & step , const std :: optional<MapPosition> & start): function_lines=37 (advisory above 25, limit 50)
if (maps() == nullptr || m_planning->open_leg_check != OpenLegCheck::REANCHOR || !start
|| counts_step_taps(step)
|| step.action != RouteAction::WALK || step.to_wall || step.warps || step.spin_tiles
|| m_next >= m_plan.size() || !(is_wall_hold(m_plan[m_next]) || is_slide(m_plan[m_next]))
|| m_next >= m_plan.size()
){
return;
}
const bool water_chain = open_water_chain(step, m_plan[m_next]);
if (!(is_wall_hold(m_plan[m_next]) || is_slide(m_plan[m_next]) || water_chain)){
return;
}
const std::vector<StopCandidate> candidates = short_candidates(*maps(), *start, step);
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) > OPEN_LEG_CHECK_TILES_PER_TILE * step.tiles){
if (water_chain && (!anchor || anchor->holds.empty())){
m_calls.fail(std::format(
"walk_overworld_route(): {} on the water may have ended short with nothing seen, and {} after it is open too; "
"no holds to walls find the player: stopped rather than go on from a guess.",
to_string(step), to_string(m_plan[m_next])
));
return;
}
if (!anchor || anchor->holds.empty() || (!water_chain && 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ struct RouteCalls{
// caller's interrupts fight the trainer), and returns LATE if anything
// showed, DONE if not. Not set: not watched.
std::function<StepEnd(const RouteStep& step, int approach_tiles)> watch_for_trainer;
// Whether the player stands on foot on `tile`, off the water: checked
// after a leg that lands there (RouteStep::lands_after), which fails
// if not. The console reads only whether they surf. Not set: not
// checked.
std::function<bool(const MapPosition& tile)> landed_on;
};


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Recovery Walk

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=534 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -26,6 +26,7 @@
#include "PokemonFRLG_BikeSpinPresses.h"
#include "PokemonFRLG_OverworldBike.h"
#include "PokemonFRLG_OverworldMaps.h"
#include "PokemonFRLG_PlayerFacingReader.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand Down Expand Up @@ -452,10 +453,30 @@
return change > WALL_TAP_MOVED_RMSD;
}

// Whether the player's walking sprite shows, read up to LANDED_READS
// times LANDED_REREAD apart: the hop off the water and the steps after
// it may still be on. Surfing, the sprite isn't read (PlayerFacingReader).
constexpr size_t LANDED_READS = 4;
constexpr Milliseconds LANDED_REREAD(150);
bool stands_on_foot(ConsoleHandle& console, ProControllerContext& context, PlayerGender player){
for (size_t read = 1; read <= LANDED_READS; read++){
if (read > 1){
pbf_wait(context, LANDED_REREAD);
}
context.wait_for_all_requests();
const VideoSnapshot screen = console.video().snapshot();
if (screen && read_player_facing(screen, player)){
return true;
}
}
console.log("Route: the player's walking sprite doesn't show: still surfing?", COLOR_ORANGE);
return false;
}

} // namespace


void walk_overworld_route_with_recovery(

Check warning on line 479 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_overworld_route_with_recovery( ConsoleHandle & console , ProControllerContext & context , const std :: vector<RouteStep> & route , const RoutePlanning & planning , PlayerGender player , std :: optional<Direction> facing , const OverworldInterruptSet & interrupts , MoveSpeed speed): function_lines=50 (advisory above 25, limit 50)
ConsoleHandle& console, ProControllerContext& context,
const std::vector<RouteStep>& route,
const RoutePlanning& planning,
Expand Down Expand Up @@ -501,6 +522,7 @@
calls.watch_for_trainer = [&](const RouteStep& step, int approach_tiles){
return watch_for_trainer(console, context, step, approach_tiles, interrupts);
};
calls.landed_on = [&](const MapPosition&){ return stands_on_foot(console, context, player); };
run_route(route, facing, &planning, calls);
context.wait_for_all_requests();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Recovery Tests

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=605 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -202,6 +202,59 @@
});
}

// Console B, 2026-11-13 04:15 (12.03, surf_route_21): Surf from Pallet
// Town's shore down Route 21 to Cinnabar. "south 86 (open)" on the water
// stopped short at a sand bar on Route21_South, unseen, and "east 7
// (open)" after it was walked from there: the route was taken as walked
// to (14, 12), with the player still on the water, and the Center entry
// and the heal after it were faked. A surfing open leg followed by another
// open leg is now checked: the player is found again at walls, or the
// route stops, never goes on from a guess.
UnitTestResult test_open_water_legs(){

Check warning on line 213 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::test_open_water_legs(): function_lines=44 (advisory above 25, limit 50)
const std::vector<MapData> maps = overworld_maps();
const MapPosition start{"PalletTown", {10, 17}};
std::optional<std::vector<RouteStep>> route = plan_overworld_route(
maps, start, RouteGoal{{"CinnabarIsland", {14, 12}}, Direction::NORTH}, default_route_costs()
);
if (!route){
return "No route.";
}
// Routes now land on the sand bars and the shore instead of stopping
// on the water (RouteCost::OPEN_WATER_STOP). The leg to the
// first sand bar is made an open stop on the water, as legs were then,
// to keep the check covered.
for (RouteStep& step : *route){
if (step.surfing && step.action == RouteAction::WALK && !step.warps){
step.to_wall = false;
step.lands_after = 0;
break;
}
}
size_t chained = 0;
while (chained + 1 < route->size() && !(
(*route)[chained].surfing && !(*route)[chained].to_wall && !(*route)[chained].warps
&& (*route)[chained + 1].action == RouteAction::WALK && !(*route)[chained + 1].to_wall && !(*route)[chained + 1].warps
)){
chained++;
}
if (chained + 1 >= route->size()){
return "Expected an open leg on the water followed by another open leg:" + describe(*route);

Check warning on line 241 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
}
const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = start, .label = "Route", .wall_check = WallCheck::SKIP};
ScriptedRoute script;
const bool failed = script.run(*route, &planning);
const std::string leg = to_string((*route)[chained]);
if (failed && script.failure.find(leg) != std::string::npos){
return true;
}
const UnitTestResult checked = expect_logged(script.logs, {"Route: position check: " + leg});

Check warning on line 250 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
if (checked.result != UnitTestResult::PASSED){
return "Expected " + leg + " checked or the route stopped, not taken as walked:" + describe(*route)
+ (failed ? "\nfailed: " + script.failure : std::string());
}
return true;
}

// A corridor with a person at each end: nothing finds the player again.
const std::string TEST_CORRIDOR_JSON = R"({
"name": "Corridor", "source": {"decomp_file": "", "revision": "test", "date": "2026-10-31"},
Expand Down Expand Up @@ -529,7 +582,11 @@
{
.input = {.name = "a stop on the grass in a trainer's sight", .body = test_grass_in_sight},
.expectation = {.description = "handles wild encounter in trainer sight line"},
}, {
.input = {.name = "open legs on the water", .body = test_open_water_legs},
.expectation = {.description = "checks a surfing open leg before another open leg"},
},

};

} // namespace
Expand Down
Loading
Loading