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 @@ -221,7 +221,7 @@ class CheckedSteps{
return outcome;
}
if (outcome.end == StepEnd::DONE && crossing && m_calls.watch_for_trainer){
outcome = StepOutcome{.end = m_calls.watch_for_trainer(step, *crossing), .walked = std::nullopt};
outcome = StepOutcome{.end = m_calls.watch_for_trainer(step, *crossing), .walked = std::nullopt, .movement = outcome.movement}; // kept: a bump into Takashi passed for walked (17.03, 2026-11-15)
}
m_last = leg;
m_last_late = outcome.end == StepEnd::LATE;
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=987 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -834,6 +834,24 @@
return true;
}

// A hold across Robin's sight that moved the screen not at all, with
// nothing seen in the watch for her after it: the player never moved, and
// the leg is walked again from its start, as any hold that moved nothing.
// The watch had dropped the hold's movement, so "north 2 (open)" from
// (10, 5), into Takashi on (10, 4), was taken as walked to (10, 3), and
// the next leg moved nothing (console B, 2026-11-15 16:52, 17.03
// below_giovanni).
UnitTestResult test_unmoved_leg_in_sight(){
const std::vector<MapData> maps{parse_map(TEST_ROBIN_JSON, "Robin")};
const RouteStep open = walk(Direction::EAST, 4, robin(4, 1));

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: walk(): literal argument 4 needs a /*param=*/ comment (Google "Function Arguments", user review on fork #590)
const RoutePlanning planning{.maps = &maps, .costs = default_route_costs(), .start = robin(0, 1), .label = "Route", .wall_check = WallCheck::SKIP, .open_leg_check = OpenLegCheck::TRUST};
ScriptedRoute script;
script.ends[0] = no_movement();
if (script.run({open}, &planning) || script.walked.size() != 2){
return std::format("Expected the leg walked again after its hold moved nothing, walked {}: {}", script.walked.size(), script.failure);
}
return expect_logged(script.logs, {"the player never moved", "stopped 0 to 0 tiles in"});
}

// On the grass a stop past Robin's column may be a wild battle's anywhere
// on the leg, or hers on (3, 1), after which she stands on (3, 2): the
Expand Down Expand Up @@ -923,6 +941,10 @@
.input = {.name = "a trainer stops a leg", .body = test_trainer_stops_leg},
.expectation = {.description = "handles forced stop and battle start from trainer challenge"},
},
{
.input = {.name = "a hold in a trainer's sight that moved nothing", .body = test_unmoved_leg_in_sight},
.expectation = {.description = "walked again from its start, not taken as walked"},
},
{
.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"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ ConsoleAction console_action_of(StoryActionId id){
case StoryActionId::LEGS:
return walk_legs;
case StoryActionId::STEP:
return take_step;
return [](StoryEnv& env, RunState& state, const StoryStep& step){ const Outcome outcome = take_step(env, state, step); note_line_trainer(env.console.logger(), step, outcome, state.flags); return outcome; };
case StoryActionId::TALK:
return [](StoryEnv& env, RunState&, const StoryStep& step){
if (!talk_until_message(env.console, env.context, step)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "PokemonFRLG_AutoStoryStepInterrupts.h"
#include "PokemonFRLG_AutoStoryStepTable.h"
#include "PokemonFRLG_AutoStoryCheckpoints.h"
#include "PokemonFRLG_AutoStoryLineTrainer.h"
#include "PokemonFRLG_AutoStoryPacedRoute.h"
#include "PokemonFRLG_AutoStoryPartyRoster.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Fault Sweep Tests

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=883 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -107,8 +107,6 @@
"below_gym_tree walks onto the gym's door warp and sees no fade (VermilionCity_Gym (4, 12)): the door's warp on the sim after trash_cans, which the sim stubs, not yet looked at"},
{"PokemonFRLG::AutoStory - Fault sweep: 09.02, clean run",
"b2f_arrows_to_lift_room moves nothing twice from RocketHideout_B2F (1, 4) after moon_stone, a talk the sim stubs: the arrow tiles' spin from that tile on the sim, not yet looked at"},
{"PokemonFRLG::AutoStory - Fault sweep: 17.03, clean run",
"Takashi (10, 2) walks up to (10, 4) when he sees the player on (10, 5) and stays there after the battle, so below_giovanni's way north up column 10 is blocked (moved nothing twice); on the console too: the route after a line battle planned with the trainer who walked up as a wall (with_trainers()), or a way to Takashi from row 3"},
{"PokemonFRLG::AutoStory - Fault sweep: 08.03, mount lost",
"riding with no fault, route7_underground_exit's warp to UndergroundPath_EastEntrance is not confirmed on the sim (the screen after the fade reads as before the hold): the sim's warp off the Bicycle, before this class can sweep 08.03"},
};
Expand Down Expand Up @@ -263,6 +261,9 @@
Milliseconds in_wild_battles{0};
int moved_step_taps = 0;
int bike_legs = 0;
// The run flags as the steps so far left them: the row's start_flags,
// and a trainer who walked up to the player (TRAINER_AT_FLAG).
std::set<std::string> flags;
};

// Where a stubbed step leaves the player instead of its pose_after: by step index.
Expand Down Expand Up @@ -318,7 +319,7 @@
out.facing_before.emplace(c, sim.state().facing);
out.gates_before.emplace(c, sim.state().gates);
const size_t warps_before = sim.state().warped_from.size();
out.failure = row_step_on_sim(sim, at, row.steps[c], row.id, start_flag_set(row));
out.failure = row_step_carrying_flags(sim, at, row.steps[c], row.id, out.flags);
const std::vector<std::string>& warped = sim.state().warped_from;
out.warped_from[c].assign(warped.begin() + warps_before, warped.end());
const bool let_pass = unscripted(out.failure) && (!scripted || scripted->contains(c));
Expand Down Expand Up @@ -364,12 +365,13 @@
// step that fails as unscripted() is let pass as one the sim does not
// play: in a clean run (`scripted` unset) at any step, else only at the
// steps in `scripted`, where the clean run let it pass.
RowRun run_row(

Check warning on line 368 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::run_row( const StoryCheckpoint & row , const SimScript & row_script , const Landings & landings = { } , const std :: optional<std::set<size_t>> & scripted = std :: nullopt): function_lines=48 (advisory above 25, limit 50)
const StoryCheckpoint& row, const SimScript& row_script, const Landings& landings = {},
const std::optional<std::set<size_t>>& scripted = std::nullopt
){
const SimScript script = with_lifts(with_row_start(row_script, row));
RowRun out;
out.flags = start_flag_set(row);
std::optional<MapPosition> off_maps;
StoryPose at = *story_pose(Pokemon::pose_of(*row.start));
std::vector<MapData> maps = row_maps(row);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* AutoStory Line Trainer
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <vector>
#include "Pokemon/AutoStory/Pokemon_TilePose.h"
#include "PokemonFRLG_AutoStoryLineTrainer.h"
#include "PokemonFRLG_AutoStoryPacedRoute.h"
#include "PokemonFRLG_AutoStoryTrainerLine.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


std::optional<TrainerMove> note_trainer_walked_up(const MapPosition& tile, std::set<std::string>& run_flags){
const std::optional<TrainerMove> move = trainer_walking_up(run_story_maps(run_flags), tile, beaten_trainers(run_flags));
if (move){
run_flags.insert(trainer_at_flag(*move));
}
return move;
}

void note_line_trainer(Logger& logger, const StoryStep& step, const Pokemon::Outcome& outcome, std::set<std::string>& run_flags){
const bool line = step.action == TRAINER_LINE_VARIANT || step.action == TRAINER_WAIT_VARIANT;
const std::vector<TilePos> tiles = line && outcome.succeeded() && outcome.pose ? Pokemon::tiles_of(*outcome.pose) : std::vector<TilePos>();
if (tiles.size() != 1){
return;
}
const MapPosition tile{outcome.pose->map, tiles[0]};
if (const std::optional<TrainerMove> move = note_trainer_walked_up(tile, run_flags)){
logger.log(std::format("Story: {}: {} walked up to ({}, {}) and stays there.", step.name, move->trainer, move->x, move->y));
}else{
logger.log(std::format("Story: {}: where the trainer who saw the player on {} stands now isn't known.", step.name, to_string(tile)), COLOR_ORANGE);
}
}



} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* AutoStory Line Trainer
*
* From: https://github.com/PokemonAutomation/
*
* The trainer who saw the player on a step into their line: they walk up,
* and stand beside the player from then on.
*
*/

#ifndef PokemonAutomation_PokemonFRLG_AutoStoryLineTrainer_H
#define PokemonAutomation_PokemonFRLG_AutoStoryLineTrainer_H

#include <optional>
#include <set>
#include <string>
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h"
#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteSteps.h"
#include "PokemonFRLG_AutoStoryMovedTrainers.h"
#include "PokemonFRLG_AutoStoryPoses.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


// The trainer who saw the player on `tile` walked up to them, and stands
// beside them from now on: adds the TRAINER_AT_FLAG that says so to
// `run_flags`, so the routes after the battle plan around them and over
// the tile they left (trainer_walking_up() on run_story_maps(), the
// trainers beaten_trainers() names seeing no one). Returns the move, or
// nothing, leaving `run_flags` as they were, if where they stand isn't known.
std::optional<TrainerMove> note_trainer_walked_up(const MapPosition& tile, std::set<std::string>& run_flags);

// note_trainer_walked_up() after `step`, a step into a trainer's line
// (TRAINER_LINE_VARIANT, TRAINER_WAIT_VARIANT) that ended on `outcome`'s
// tile, logged. Any other step, or one that failed: nothing. Planned on
// the map's tiles, 17.03's below_giovanni went north from (10, 5) through
// Takashi, who had walked up to (10, 4) (console B, 2026-11-15 16:52).
void note_line_trainer(Logger& logger, const StoryStep& step, const Pokemon::Outcome& outcome, std::set<std::string>& run_flags);



} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ std::optional<std::pair<int, int>> parse_tile(std::string_view text){
return std::pair{x, y};
}

// The way from `from` to `to`, on the same row or column.
Direction towards(const TilePos& from, const TilePos& to){
if (to.x == from.x){
return to.y < from.y ? Direction::NORTH : Direction::SOUTH;
}
return to.x < from.x ? Direction::WEST : Direction::EAST;
}

} // namespace


Expand All @@ -57,6 +65,32 @@ std::vector<TrainerMove> moved_trainers(const std::set<std::string>& run_flags){
return moved;
}

std::string trainer_at_flag(const TrainerMove& move){
return std::format("{}{}={},{}", TRAINER_AT_FLAG, move.trainer, move.x, move.y);
}

std::optional<TrainerMove> trainer_walking_up(
const std::vector<MapData>& maps, const MapPosition& tile, const std::set<std::string>& beaten
){
const MapData* map = nullptr;
for (const MapData& candidate : maps){
map = candidate.name == tile.map ? &candidate : map;
}
std::optional<TrainerMove> move;
for (size_t c = 0; map != nullptr && c < map->objects.size(); c++){
const Pokemon::MapObject& object = map->objects[c];
if (!trainer_may_see(*map, object, tile.point) || beaten.contains(trainer_id(*map, object))){
continue;
}
if (move || object.wander){
return std::nullopt;
}
const TilePos beside = tile.point.next(towards(tile.point, TilePos{object.x, object.y}));
move = TrainerMove{.trainer = trainer_id(*map, object), .x = beside.x, .y = beside.y};
}
return move;
}

std::vector<MapData> with_trainers_moved(std::vector<MapData> maps, const std::vector<TrainerMove>& moved){
for (const TrainerMove& move : moved){
for (MapData& map : maps){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
#ifndef PokemonAutomation_PokemonFRLG_AutoStoryMovedTrainers_H
#define PokemonAutomation_PokemonFRLG_AutoStoryMovedTrainers_H

#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <vector>
#include "Pokemon/Navigation/Pokemon_MapData.h"
#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteSteps.h"


namespace PokemonAutomation{
Expand Down Expand Up @@ -46,6 +48,22 @@ inline constexpr std::string_view TRAINER_AT_FLAG = "trainer_at:";
// A flag that doesn't parse throws ParseException.
std::vector<TrainerMove> moved_trainers(const std::set<std::string>& run_flags);

// The TRAINER_AT_FLAG that says `move`.
std::string trainer_at_flag(const TrainerMove& move);

// The trainer who walks up to the player seen on `tile` of `maps` (a step
// into their line, step_until_seen()), and the tile beside the player they
// stop on, toward where they stood. Trainers `beaten`
// names (trainer_id()) see no one. Nothing if no trainer may see the
// player there, or if where they stop isn't known to one tile: two
// trainers may see it, or one who wanders may come from either side.
// Takashi, facing south on Viridian Gym's (10, 2), saw the player on
// (10, 5) and walked to (10, 4), where 17.03's way north went (console B,
// 2026-11-15 16:52).
std::optional<TrainerMove> trainer_walking_up(
const std::vector<MapData>& maps, const MapPosition& tile, const std::set<std::string>& beaten
);

// `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.
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=889 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -16,6 +16,7 @@
#include "Pokemon/AutoStory/Pokemon_TilePose.h"
#include "PokemonFRLG_AutoStoryBoulders.h"
#include "PokemonFRLG_AutoStoryLegs.h"
#include "PokemonFRLG_AutoStoryLineTrainer.h"
#include "PokemonFRLG_AutoStoryPacedRoute.h"
#include "PokemonFRLG_AutoStoryActions.h"
#include "PokemonFRLG_AutoStoryBattleDecisions.h"
Expand Down Expand Up @@ -433,7 +434,7 @@
return played_action;
}

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

Check warning on line 437 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=33 (advisory above 25, limit 50)
using Body = std::string (OverworldStepSim::*)(const StoryStep&);
Body body = nullptr;
switch (id){
Expand Down Expand Up @@ -462,6 +463,7 @@
m_flags = state.flags;
m_beaten = beaten_trainers(state.flags);
const std::string failure = (this->*body)(step);
state.flags = m_flags;
return failure.empty() ? Pokemon::outcome_ok() : Pokemon::outcome_failed("sim_failure", failure);
});
}
Expand Down Expand Up @@ -579,7 +581,7 @@
// A hop() or step_onto() (a plain step the table says the end of); else
// a step one tap at a time, or for a step into a trainer's line by
// step_until_seen(), each watched for the trainer.
std::string OverworldStepSim::step_ahead(const StoryStep& step){

Check warning on line 584 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_ahead( const StoryStep & step): function_lines=44 (advisory above 25, limit 50)
const Direction direction = Pokemon::story_arg<Direction>(step.args, "direction");
if (step.action.empty() && step.pose_after){
// A step onto a warp waits out its fade, as take_warp_step() does, so
Expand Down Expand Up @@ -613,7 +615,15 @@
return shown.has_value();
};
const int tiles = step.action == TRAINER_LINE_VARIANT ? TRAINER_LINE_TILES : 1;
return step_until_seen(tiles, tap, seen) ? "" : "no trainer saw the player.";
if (!step_until_seen(tiles, tap, seen)){
return "no trainer saw the player.";
}
// As note_line_trainer(): the trainer who saw the player stands beside them
// from now on, for the routes after the battle.
if (step.action == TRAINER_LINE_VARIANT || step.action == TRAINER_WAIT_VARIANT){
note_trainer_walked_up(m_sim.state().position, m_flags);
}
return "";
}

// take_warp_step() on the sim: the step, then its fade, with a step more
Expand Down Expand Up @@ -842,12 +852,21 @@
std::string row_step_on_sim(
OverworldSim& sim, StoryPose& at, const StoryStep& step, const std::string& id,
const std::set<std::string>& run_flags
){
std::set<std::string> flags = run_flags;
return row_step_carrying_flags(sim, at, step, id, flags);
}

std::string row_step_carrying_flags(

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: row_step_carrying_flags: output parameter 'OverworldSim& sim' comes before an input; put inputs (by value, const&) first and non-const references last (Google "Function Parameter Ordering")
OverworldSim& sim, StoryPose& at, const StoryStep& step, const std::string& id,
std::set<std::string>& run_flags
){
OverworldStepSim executor(sim, id, at);
RunState state;
state.flags = run_flags;
const Outcome outcome = executor.run(step, state);
at = executor.at();
run_flags = std::move(state.flags);
if (outcome.succeeded()){
// The step that picks the Card Key up (flags_after) opens the doors the
// next ones walk to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@
OverworldSim& sim, StoryPose& at, const StoryStep& step, const std::string& id,
const std::set<std::string>& run_flags = std::set<std::string>()
);
// row_step_on_sim() with `run_flags` carried on: they become the flags
// the step left, as the program's run state carries them to the next
// step (a trainer who walked up to the player, TRAINER_AT_FLAG).
std::string row_step_carrying_flags(

Check warning on line 194 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: 'row_step_carrying_flags' is public only for PokemonFRLG_AutoStoryFaultSweep_Tests.cpp, PokemonFRLG_AutoStoryViridian_Tests.cpp; test through the public function, or keep it in the .cpp's anonymous namespace (ignore if a later PR in the stack calls it) (user review on fork #590)

Check warning on line 194 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: row_step_carrying_flags: output parameter 'OverworldSim& sim' comes before an input; put inputs (by value, const&) first and non-const references last (Google "Function Parameter Ordering")
OverworldSim& sim, StoryPose& at, const StoryStep& step, const std::string& id,
std::set<std::string>& run_flags
);



Expand Down
Loading
Loading