Skip to content
Merged
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 @@ -31,7 +31,8 @@ namespace OverworldWalkSteps{
// Whether a WALK `step` at `speed` starts with a turn tap, for a player
// facing `facing`: on foot facing another way (or an unknown way), so the
// hold starts facing the right way. Never on the Bicycle, where a tap
// takes a step (MovementMechanics::BIKE_TAP_ONLY_TURNS).
// takes a step (MovementMechanics::BIKE_TAP_ONLY_TURNS). Never off an exit
// mat its way (RouteStep::off_exit_mat), where the tap takes the warp.
bool turns_first(const RouteStep& step, MoveSpeed speed, std::optional<Direction> facing);

// Whether `step` at `speed` is walked a tap at a time, each a tile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Route

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=941 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -566,7 +566,7 @@
return RouteAction::WALK;
}

RouteStep to_route_step(const std::vector<MapData>& maps, const Pokemon::Leg<Located>& leg){

Check warning on line 569 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::to_route_step( const std :: vector<MapData> & maps , const Pokemon :: Leg<Located> & leg): function_lines=38 (advisory above 25, limit 50)
RouteStep step;
step.action = route_action(leg);
step.direction = leg.direction;
Expand Down Expand Up @@ -595,6 +595,7 @@
}
step.to_wall = step.to_wall && !step.spin_tiles;
step.tapped = !step.surfing && onto_warp_sideways(maps[leg.end.map], step);
step.off_exit_mat = step.warps && exit_mat(maps[leg.start.map], leg.start.state.position) == step.direction;
step.sign_ahead = !step.to_wall && !step.warps && reads_sign_ahead(maps[leg.end.map], leg.end.state.position, step.direction);
}
const std::vector<MapPosition> tiles = leg_tiles(maps, MapPosition{maps[leg.start.map].name, leg.start.state.position}, step);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ struct RouteStep{
// floors, where a hold that ends a tile off slides the player
// elsewhere (console B, 2026-11-10, 09.01 r1).
bool tapped = false;
// WALK onto a warp: the leg starts on an exit mat (walk_<direction>)
// and goes its way, so the first press takes the warp from any facing,
// and the leg has no turn tap (turns_first()). The turn tap east on
// Route 7's gate door (15, 10) took the warp, its fade passed while the
// turn was read, and the hold walked on inside the gate (console B,
// 2026-11-14 22:27, 15.01 west_of_tea_guard).
bool off_exit_mat = 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
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ void OverworldSim::walk_hold(Direction direction, Milliseconds duration, int sho
const Milliseconds end = m_now + duration;
Milliseconds pressed = m_now;
if (m_state.facing != direction){
// Holding through a turn lost a tile on the console, on foot.
pressed += m_state.on_bike ? Milliseconds(0) : tile;
// Holding through a turn lost a tile on the console, on foot; off an exit mat its way, none.
pressed += m_state.on_bike || exit_mat(map(), m_player.position) == direction ? Milliseconds(0) : tile;
m_state.facing = direction;
}
take_steps(direction, pressed, end, (int)((end - pressed + tile - 1ms) / tile) - short_by);
Expand Down Expand Up @@ -544,9 +544,9 @@ void OverworldSim::tap(Direction direction, Milliseconds duration, Milliseconds
hold_on(direction, start + duration);
}else if (m_state.on_bike && drops_bike_tap(start)){
m_last_tap.reset();
}else if (m_state.facing != direction && !m_state.on_bike){
// From a standstill a tap only turns the player, even one as long
// as LONGEST_TAP. Not on the Bicycle: there it steps.
}else if (m_state.facing != direction && !m_state.on_bike && exit_mat(map(), m_player.position) != direction){
// From a standstill a tap only turns the player, even one as long as LONGEST_TAP. Not on the Bicycle: there it steps.
// Nor off an exit mat its way: there it takes the warp (console B, 2026-11-14: 14.02b Cinnabar Gym, 15.01 Route 7's gate).
m_last_tap = TapPress{direction, start, start + duration, m_state.facing, 0};
if (drops_turn_tap()){
m_state.turn_taps_dropped++;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Walk

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=977 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -244,7 +244,7 @@
}

bool turns_first(const RouteStep& step, MoveSpeed speed, std::optional<Direction> facing){
if (facing == step.direction){
if (facing == step.direction || step.off_exit_mat){
return false;
}
return step.surfing || step_speed(step, speed) != MoveSpeed::BIKE || BIKE_TAP_ONLY_TURNS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* AutoStory Moved Trainers
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <charconv>
#include <format>
#include <optional>
#include <utility>
#include "Common/Cpp/Exceptions.h"
#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldObjects.h"
#include "PokemonFRLG_AutoStoryMovedTrainers.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{

namespace{

// "<x>,<y>" of a TRAINER_AT_FLAG, or nothing if it isn't that.
std::optional<std::pair<int, int>> parse_tile(std::string_view text){
const size_t comma = text.find(',');
if (comma == std::string_view::npos){
return std::nullopt;
}
int x = 0;
int y = 0;
const std::string_view x_text = text.substr(0, comma);
const std::string_view y_text = text.substr(comma + 1);
const std::from_chars_result x_read = std::from_chars(x_text.data(), x_text.data() + x_text.size(), x);
const std::from_chars_result y_read = std::from_chars(y_text.data(), y_text.data() + y_text.size(), y);
if (x_read.ec != std::errc() || x_read.ptr != x_text.data() + x_text.size()
|| y_read.ec != std::errc() || y_read.ptr != y_text.data() + y_text.size()){
return std::nullopt;
}
return std::pair{x, y};
}

} // namespace


std::vector<TrainerMove> moved_trainers(const std::set<std::string>& run_flags){
std::vector<TrainerMove> moved;
for (const std::string& flag : run_flags){
if (!flag.starts_with(TRAINER_AT_FLAG)){
continue;
}
const std::string_view rest = std::string_view(flag).substr(TRAINER_AT_FLAG.size());
const size_t equals = rest.find('=');
const std::optional<std::pair<int, int>> tile = equals == std::string_view::npos ? std::nullopt : parse_tile(rest.substr(equals + 1));
if (!tile || equals == 0){
throw ParseException(std::format("run flag \"{}\" isn't \"{}<trainer>=<x>,<y>\"", flag, TRAINER_AT_FLAG));
}
moved.emplace_back(TrainerMove{.trainer = std::string(rest.substr(0, equals)), .x = tile->first, .y = tile->second});
}
return moved;
}

std::vector<MapData> with_trainers_moved(std::vector<MapData> maps, const std::vector<TrainerMove>& moved){
for (const TrainerMove& move : moved){
for (MapData& map : maps){
for (Pokemon::MapObject& object : map.objects){
if (!object.trainer || trainer_id(map, object) != move.trainer){
continue;
}
object.x = move.x;
object.y = move.y;
object.wander.reset();
object.trainer.reset();
}
}
}
return maps;
}



} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* AutoStory Moved Trainers
*
* From: https://github.com/PokemonAutomation/
*
* Trainers who walked up to the player, and stand there from then on.
*
*/

#ifndef PokemonAutomation_PokemonFRLG_AutoStoryMovedTrainers_H
#define PokemonAutomation_PokemonFRLG_AutoStoryMovedTrainers_H

#include <set>
#include <string>
#include <string_view>
#include <vector>
#include "Pokemon/Navigation/Pokemon_MapData.h"


namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{

// The maps a story is planned on (Pokemon_MapData.h).
using Pokemon::MapData;


// A trainer who saw the player walked up to the tile beside them and
// fought: the game leaves them standing there, not on the map's tile. The
// trainer (trainer_id(), from the map's tile) and where they stand now.
struct TrainerMove{
std::string trainer;
int x = 0;
int y = 0;
};

// A run flag that says where a trainer stands since they walked up to the
// player: this prefix, then the trainer's trainer_id(), "=", the tile
// ("trainer_at:SilphCo_5F/rocket_m@9,21=11,21"). The step that fought
// them sets it in flags_after and the checkpoints after start with it:
// the Rocket of 16.02 walked from 5F's (9, 21) up to (11, 21) and stood
// across 16.03's leg along row 21, which the planner had through his
// map tile's neighbour (console B, 2026-11-14, run 4).
inline constexpr std::string_view TRAINER_AT_FLAG = "trainer_at:";

// The trainers `run_flags` says walked up to the player (TRAINER_AT_FLAG).
// A flag that doesn't parse throws ParseException.
std::vector<TrainerMove> moved_trainers(const std::set<std::string>& run_flags);

// `maps` with each trainer of `moved` standing on its new tile, no longer
// a trainer: they fought the player when they walked up, and they stop
// no one. A trainer not found is left as is.
std::vector<MapData> with_trainers_moved(std::vector<MapData> maps, const std::vector<TrainerMove>& moved);



} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
*
*/

#include <format>
#include <map>
#include <set>
#include <string>
#include "Common/Cpp/Concurrency/Mutex.h"
#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h"
#include "PokemonFRLG_AutoStoryMovedTrainers.h"
#include "PokemonFRLG_AutoStoryPacedRoute.h"

namespace PokemonAutomation{
Expand Down Expand Up @@ -46,12 +50,38 @@ const std::vector<MapData>& story_maps(){
return maps;
}

namespace{

// story_maps() without the Rockets (SILPH_CLEARED_FLAG).
const std::vector<MapData>& cleared_story_maps(){
static const std::vector<MapData> maps = make_story_maps(true);
return maps;
}

} // namespace

const std::vector<MapData>& run_story_maps(const std::set<std::string>& run_flags){
if (run_flags.contains(std::string(SILPH_CLEARED_FLAG))){
static const std::vector<MapData> cleared = make_story_maps(true);
return cleared;
const bool cleared = run_flags.contains(std::string(SILPH_CLEARED_FLAG));
const std::vector<MapData>& base = cleared ? cleared_story_maps() : story_maps();
const std::vector<TrainerMove> moved = moved_trainers(run_flags);
if (moved.empty()){
return base;
}
// One copy per set of trainers moved, kept while the program runs:
// callers hold references into it. `run_flags` is a set, so the key
// lists the moves in one order.
std::string key = cleared ? "cleared" : "all";
for (const TrainerMove& move : moved){
key += std::format("|{}={},{}", move.trainer, move.x, move.y);
}
static Mutex lock;
static std::map<std::string, std::vector<MapData>> moved_maps;
LockGuard<Mutex> guard(lock);
auto it = moved_maps.find(key);
if (it == moved_maps.end()){
it = moved_maps.emplace(key, with_trainers_moved(base, moved)).first;
}
return story_maps();
return it->second;
}

std::set<std::string> beaten_trainers(const std::set<std::string>& run_flags){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* FRLG AutoStory Plan Golden

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=892 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -837,9 +837,8 @@
"09.01 face west -> RocketHideout_B4F (5, 3)",
"09.01 below_lift_key from RocketHideout_B4F (3, 3) facing west to RocketHideout_B4F (3, 3) facing north",
"09.01 face north -> RocketHideout_B4F (3, 3)",
"09.01 b3f_from_b4f from RocketHideout_B4F (11, 15) facing south to RocketHideout_B3F (15, 18) facing west",
"09.01 b3f_from_b4f from RocketHideout_B4F (11, 15) facing south to RocketHideout_B3F (15, 18) facing east",
"09.01 walk east 1 (warp) -> RocketHideout_B3F (15, 18)",
"09.01 face west -> RocketHideout_B3F (15, 18)",
"09.01 beside_b3f_rare_candy from RocketHideout_B3F (10, 13) facing north to RocketHideout_B3F (12, 13) facing north",
"09.01 walk east 2 (to wall) -> RocketHideout_B3F (12, 13)",
"09.01 face north -> RocketHideout_B3F (12, 13)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN_16[] = {
"16.02 walk east 4 (warp) -> SilphCo_5F (10, 20)",
"16.02 walk east 2 (to wall) -> SilphCo_5F (12, 20)",
"16.03 to_3f_trainer from SilphCo_5F (21, 21) facing east to SilphCo_3F (22, 9) facing south",
"16.03 walk west 11 -> SilphCo_5F (10, 21)",
"16.03 walk north 1 (warp) -> SilphCo_9F (22, 18)",
"16.03 walk west 9 -> SilphCo_5F (12, 21)",
"16.03 walk north 1 -> SilphCo_5F (12, 20)",
"16.03 walk west 2 (warp) -> SilphCo_9F (22, 18)",
"16.03 walk west 4 (to wall) -> SilphCo_9F (18, 18)",
"16.03 walk east 4 (warp) -> SilphCo_5F (10, 20)",
"16.03 walk north 12 -> SilphCo_5F (10, 8)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Row Sim

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=870 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -433,7 +433,7 @@
return played_action;
}

Pokemon::StoryAction OverworldStepSim::step_action(StoryActionId id){

Check warning on line 436 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::OverworldStepSim::step_action( StoryActionId id): function_lines=32 (advisory above 25, limit 50)
using Body = std::string (OverworldStepSim::*)(const StoryStep&);
Body body = nullptr;
switch (id){
Expand All @@ -459,6 +459,7 @@
return m_stubs.stub();
}
return played([this, body](const StoryStep& step, RunState& state){
m_flags = state.flags;
m_beaten = beaten_trainers(state.flags);
const std::string failure = (this->*body)(step);
return failure.empty() ? Pokemon::outcome_ok() : Pokemon::outcome_failed("sim_failure", failure);
Expand Down Expand Up @@ -544,11 +545,13 @@

// A ROUTE or LEGS by the sim's walker, fighting a trainer who sees the
// player on the way.
std::string OverworldStepSim::walk(const StoryStep& step){

Check warning on line 548 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::OverworldStepSim::walk( const StoryStep & step): function_lines=30 (advisory above 25, limit 50)
// The story's maps, as the planner and the program have them (the grunt the sim has
// hidden stands on them, and the stairs a switch opens are open); the gates are the sim's,
// which the walker's steps open.
const std::vector<MapData>& maps = story_maps();
// The story's maps as the program plans on them with the step's run flags
// (run_story_maps(): a beaten trainer who walked up to the player stands
// where he stopped, the Rockets are gone once Silph Co. is cleared; the
// stairs a switch opens are open); the gates are the sim's, which the
// walker's steps open.
const std::vector<MapData>& maps = run_story_maps(m_flags);
const Pokemon::GateState& gates = m_sim.state().gates;
const std::optional<std::vector<RouteStep>> route = walked_route(m_at, step, maps, gates, Pokemon::GateRules{.card_key_held = m_sim.card_key_held()});
if (route && route->empty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ class OverworldStepSim : public Pokemon::TableExecutor{

OverworldSim& m_sim;
StoryPose m_at;
// The trainers the step's run flags say are beaten (beaten_trainers()):
// the walker doesn't watch for them.
// The step's run flags: the maps the program plans on are theirs
// (run_story_maps()), and the walker doesn't watch for the trainers they
// say are beaten (m_beaten, beaten_trainers()).
std::set<std::string> m_flags;
std::set<std::string> m_beaten;
SimStepGuard m_guard;
SimStubs m_stubs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,43 @@
return true;
}

// 15.01 west_of_tea_guard as console B ran it (2026-11-14 22:27, run 3):
// from the gate's wall (15, 11) facing north, "north 1" onto the door's
// tile (15, 10), an exit mat taken east, then "east 1 (warp)". The turn
// tap east took the warp, its fade passed while the turn was read, and the
// hold and the two steps more walked on inside the gate: "no fade in and
// out after walking onto the warp".
UnitTestResult test_route7_gate_door_turn_tap(){

Check warning on line 157 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySaffron_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::test_route7_gate_door_turn_tap(): function_lines=30 (advisory above 25, limit 50)
const StoryCheckpoint& row = checkpoint("15.01");
StoryPose at{"Route7", {15, 11}, Direction::NORTH};
SimScript script;
script.timing.tile = MovementMechanics::RUN_TILE_TIME;
OverworldSim sim(story_maps(), MapPosition{at.map, at.tile}, *at.facing, script);
SimWalkerRules rules;
rules.speed = MoveSpeed::RUN;
for (const StoryStep& step : row.steps){
if (step.name != "west_of_tea_guard"){
continue;
}
const std::optional<std::vector<RouteStep>> route = walked_route(at, step, story_maps(), sim.state().gates);
if (!route || route->empty()){
return std::format("15.01 {}: no route from {}.", step.name, to_string(MapPosition{at.map, at.tile}));
}
const RoutePlanning planning{
.maps = &story_maps(), .gates = sim.state().gates, .costs = story_route_costs(),
.start = MapPosition{at.map, at.tile}, .label = step.name
};
if (const std::string failure = OverworldSimWalker(sim, rules).run(*route, planning); !failure.empty()){
return std::format("15.01 {}: ended on {}; {}", step.name, to_string(sim.state().position), failure);
}
}
const MapPosition west_of_trigger{"Route7_EastEntrance", {5, 4}};
if (!(sim.state().position == west_of_trigger)){
return std::format("15.01: ended on {}, not west of the guard's trigger, {}.", to_string(sim.state().position), to_string(west_of_trigger));
}
return true;
}

const AutoStorySaffronCase AUTO_STORY_SAFFRON_CASES[] = {
{
.input = {.name = "15.01 Route 7's gate with the TEA to Saffron's Center", .body = test_route7_to_saffron},
Expand All @@ -157,6 +194,10 @@
.input = {.name = "15.01 running, the crossing onto Route 7 not held up", .body = test_route7_gate_running_crossing_not_held_up},
.expectation = {.description = "a column long after the crossing, the walk still ends at the gate's guard"},
},
{
.input = {.name = "15.01 west_of_tea_guard from the gate's wall, the door an exit mat", .body = test_route7_gate_door_turn_tap},
.expectation = {.description = "the press east off the door's tile takes the warp with no turn tap first; ends west of the guard's trigger"},
},
};

} // namespace
Expand Down
Loading
Loading