From a38a9b24d7ecadd869653be00522d02d9e9fc984 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 17:04:06 -0800 Subject: [PATCH 1/4] FRLG AutoStory: a trainer who walked up stays beside the player for the routes after --- .../PokemonFRLG_OverworldReanchor.cpp | 7 ++-- .../Overworld/PokemonFRLG_OverworldReanchor.h | 5 +++ .../PokemonFRLG_OverworldRecovery_Tests.cpp | 22 +++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 20 +++++++++++ .../PokemonFRLG_AutoStoryFaultSweep_Tests.cpp | 6 +++- .../PokemonFRLG_AutoStoryMovedTrainers.cpp | 29 ++++++++++++++++ .../PokemonFRLG_AutoStoryMovedTrainers.h | 18 ++++++++++ .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 23 ++++++++++++- .../AutoStory/PokemonFRLG_AutoStoryRowSim.h | 7 ++++ .../PokemonFRLG_AutoStoryViridian_Tests.cpp | 33 +++++++++++++++---- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 21 ++++++++++++ 11 files changed, 181 insertions(+), 10 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp index 9801e7a4d7..5571873ea0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp @@ -95,8 +95,9 @@ void add_trainer_stops( } } -// The trainers who may see the player on `tile`, and where each stands -// once walked up. +} // namespace + + std::vector trainers_seeing(const std::vector& maps, const MapPosition& tile){ std::vector stops; const MapData* map = map_named(maps, tile.map); @@ -108,6 +109,8 @@ std::vector trainers_seeing(const std::vector& maps, const return stops; } +namespace{ + // `maps` with a trainer who walked up standing on each of `trainers`: they // stay there after the battle, so the player can't walk through. std::vector with_trainers(const std::vector& maps, const std::vector& trainers){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h index e32947523a..189ffb1308 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h @@ -43,6 +43,11 @@ struct TrainerStop{ bool operator==(const TrainerStop& other) const = default; }; +// The trainers who may see the player on `tile`, and where each stands +// once walked up: one stop for a trainer who stands still, one for each +// side a wanderer may come from. +std::vector trainers_seeing(const std::vector& maps, const MapPosition& tile); + // One way things may stand after a stop: the player's tile, and the // trainer who stopped them there, if one did. struct StopCandidate{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp index 10b16aa3f0..cf8c08c530 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery_Tests.cpp @@ -834,6 +834,24 @@ UnitTestResult test_trainer_stops_leg(){ 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 maps{parse_map(TEST_ROBIN_JSON, "Robin")}; + const RouteStep open = walk(Direction::EAST, 4, robin(4, 1)); + 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 @@ -923,6 +941,10 @@ const OverworldRecoveryTestCase OVERWORLD_RECOVERY_CASES[] = { .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"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index e029891ae9..d8a94895b5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -36,6 +36,7 @@ #include "PokemonFRLG_AutoStoryHealingSteps.h" #include "PokemonFRLG_AutoStoryHideout.h" #include "PokemonFRLG_AutoStoryLegs.h" +#include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryRoutePose.h" #include "PokemonFRLG_AutoStoryScreenEvents.h" #include "PokemonFRLG_AutoStorySlopeRun.h" @@ -223,6 +224,22 @@ Outcome take_warp_step(StoryEnv& env, const RunState& state, const MapPosition& return Pokemon::outcome_ok(); } +// The trainer who saw the player on `tile` walked up to them and stands +// beside them from now on: a run flag says so (TRAINER_AT_FLAG), and the +// routes after the battle plan around them and over the tile they left. +// Planned on the map's tiles, below_giovanni went north from (10, 5) +// through Takashi, who had walked up to (10, 4) (console B, 2026-11-15 +// 16:52, 17.03). +void note_trainer_walked_up(StoryEnv& env, RunState& state, const StoryStep& step, const MapPosition& tile){ + const std::optional move = trainer_walking_up(run_story_maps(state.flags), tile, beaten_trainers(state.flags)); + if (!move){ + env.console.log(std::format("Story: {}: where the trainer who saw the player on {} stands now isn't known.", step.name, to_string(tile)), COLOR_ORANGE); + return; + } + state.flags.insert(trainer_at_flag(*move)); + env.console.log(std::format("Story: {}: {} walked up to ({}, {}) and stays there.", step.name, move->trainer, move->x, move->y)); +} + Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ const Direction direction = arg(step, "direction"); int tiles_stepped = 1; @@ -254,6 +271,9 @@ Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ for (int c = 0; c < tiles_stepped; c++){ onto = onto.next(direction); } + if (step.action == TRAINER_LINE_VARIANT || step.action == TRAINER_WAIT_VARIANT){ + note_trainer_walked_up(env, state, step, MapPosition{state.pose.map, onto}); + } return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, onto, direction})); } 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 9ff539b5c6..043b90f2b7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -263,6 +263,9 @@ struct RowRun{ 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 flags; }; // Where a stubbed step leaves the player instead of its pose_after: by step index. @@ -318,7 +321,7 @@ bool run_row_step( 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& 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)); @@ -370,6 +373,7 @@ RowRun run_row( ){ const SimScript script = with_lifts(with_row_start(row_script, row)); RowRun out; + out.flags = start_flag_set(row); std::optional off_maps; StoryPose at = *story_pose(Pokemon::pose_of(*row.start)); std::vector maps = row_maps(row); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp index 92579cfeb0..893d3b200f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp @@ -10,6 +10,7 @@ #include #include "Common/Cpp/Exceptions.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldObjects.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h" #include "PokemonFRLG_AutoStoryMovedTrainers.h" namespace PokemonAutomation{ @@ -57,6 +58,34 @@ std::vector moved_trainers(const std::set& 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 trainer_walking_up( + const std::vector& maps, const MapPosition& tile, const std::set& beaten +){ + const MapData* map = nullptr; + for (const MapData& candidate : maps){ + map = candidate.name == tile.map ? &candidate : map; + } + if (map == nullptr){ + return std::nullopt; + } + std::optional move; + for (const TrainerStop& stop : trainers_seeing(maps, tile)){ + const std::string trainer = trainer_id(*map, map->objects[stop.object]); + if (beaten.contains(trainer)){ + continue; + } + if (move){ + return std::nullopt; + } + move = TrainerMove{.trainer = trainer, .x = stop.at.point.x, .y = stop.at.point.y}; + } + return move; +} + std::vector with_trainers_moved(std::vector maps, const std::vector& moved){ for (const TrainerMove& move : moved){ for (MapData& map : maps){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.h index e357cbde9b..4c455af64f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.h @@ -9,11 +9,13 @@ #ifndef PokemonAutomation_PokemonFRLG_AutoStoryMovedTrainers_H #define PokemonAutomation_PokemonFRLG_AutoStoryMovedTrainers_H +#include #include #include #include #include #include "Pokemon/Navigation/Pokemon_MapData.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRouteSteps.h" namespace PokemonAutomation{ @@ -46,6 +48,22 @@ inline constexpr std::string_view TRAINER_AT_FLAG = "trainer_at:"; // A flag that doesn't parse throws ParseException. std::vector moved_trainers(const std::set& 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_seeing()). 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 trainer_walking_up( + const std::vector& maps, const MapPosition& tile, const std::set& 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. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index b6379e390b..ffdf44f538 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -16,6 +16,7 @@ #include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "PokemonFRLG_AutoStoryBoulders.h" #include "PokemonFRLG_AutoStoryLegs.h" +#include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryPacedRoute.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" @@ -462,6 +463,7 @@ Pokemon::StoryAction OverworldStepSim::step_action(StoryActionId id){ 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); }); } @@ -613,7 +615,17 @@ std::string OverworldStepSim::step_ahead(const StoryStep& step){ 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 take_step(): 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){ + if (const std::optional move = trainer_walking_up(run_story_maps(m_flags), m_sim.state().position, m_beaten)){ + m_flags.insert(trainer_at_flag(*move)); + } + } + return ""; } // take_warp_step() on the sim: the step, then its fade, with a step more @@ -842,12 +854,21 @@ std::string OverworldStepSim::battle(const StoryStep& step){ std::string row_step_on_sim( OverworldSim& sim, StoryPose& at, const StoryStep& step, const std::string& id, const std::set& run_flags +){ + std::set flags = run_flags; + return row_step_carrying_flags(sim, at, step, id, flags); +} + +std::string row_step_carrying_flags( + OverworldSim& sim, StoryPose& at, const StoryStep& step, const std::string& id, + std::set& 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. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h index 7137b89bb1..511411d774 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h @@ -188,6 +188,13 @@ std::string row_step_on_sim( OverworldSim& sim, StoryPose& at, const StoryStep& step, const std::string& id, const std::set& run_flags = std::set() ); +// 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( + OverworldSim& sim, StoryPose& at, const StoryStep& step, const std::string& id, + std::set& run_flags +); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryViridian_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryViridian_Tests.cpp index 15dc8cc20b..ee14d9dda8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryViridian_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryViridian_Tests.cpp @@ -2,16 +2,15 @@ * * From: https://github.com/PokemonAutomation/ * - * Viridian Gym's spinner tiles and rows 17.02 and 17.04b - * (StoryData/frlg-17.0N.plan.json) on the overworld sim. 17.03 is the - * fault sweep's (a known-failing clean run: Takashi stands in the way - * after his battle). + * Viridian Gym's spinner tiles and rows 17.02 to 17.04b + * (StoryData/frlg-17.0N.plan.json) on the overworld sim. * */ #include #include #include +#include #include #include #include @@ -21,6 +20,7 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin.h" +#include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryPoses.h" #include "PokemonFRLG_AutoStoryRowSim.h" #include "PokemonFRLG_AutoStoryRows_Tests.h" @@ -137,7 +137,8 @@ std::vector beaten_gym_maps(){ // Row `id`'s steps after `after` (from the row's start if empty) up to // `last`, on the sim over `maps` from where `after` leaves the player. It -// must fight only its own battles, break no rule and end on `end`. +// must fight only its own battles, break no rule and end on `end`. The run +// flags go from step to step, as in the program's run state. UnitTestResult walk_row( std::string_view id, std::string_view after, std::string_view last, const std::vector& maps, const MapPosition& end @@ -153,12 +154,13 @@ UnitTestResult walk_row( } std::optional sim; sim.emplace(maps, MapPosition{at.map, at.tile}, at.facing.value_or(Direction::SOUTH)); + std::set flags(row.start_flags.begin(), row.start_flags.end()); size_t battles = 0; for (size_t c = first; c < row.steps.size(); c++){ const StoryStep& step = row.steps[c]; battles += step.kind == StoryStepKind::BATTLE ? 1 : 0; if (sim_walks(step)){ - if (const std::string failure = row_step_on_sim(*sim, at, step, row.id); !failure.empty()){ + if (const std::string failure = row_step_carrying_flags(*sim, at, step, row.id, flags); !failure.empty()){ return failure; } }else if (step.pose_after){ @@ -187,6 +189,21 @@ UnitTestResult test_row_17_02(){ return walk_row("17.02", "fly_viridian", "warren", story_maps(), MapPosition{std::string(GYM), {15, 7}}); } +// 17.03: Takashi, facing south on (10, 2) with a sight of 3, sees the +// player step onto (10, 5) and walks up to (10, 4), where he stays after +// the battle. below_giovanni plans around him: on the map's tiles it went +// north through him, and moved nothing (console B, 2026-11-15 16:52). +UnitTestResult test_row_17_03(){ + const std::optional takashi = trainer_walking_up(story_maps(), MapPosition{std::string(GYM), {10, 5}}, {}); + if (!takashi || takashi->trainer != "ViridianCity_Gym/black_belt@10,2" || takashi->x != 10 || takashi->y != 4){ + return "Expected Takashi (ViridianCity_Gym/black_belt@10,2) to walk up to (10, 4)."; + } + if (trainer_walking_up(story_maps(), MapPosition{std::string(GYM), {10, 5}}, {takashi->trainer})){ + return "Expected no trainer to walk up once Takashi is beaten."; + } + return walk_row("17.03", "", "below_giovanni", story_maps(), MapPosition{std::string(GYM), {2, 3}}); +} + // 17.04b after Giovanni's win: back through the gym past its beaten // trainers (Takashi's line on row 3 among them), out of the door and the // Fly to below the Center's door (26, 27). @@ -199,6 +216,10 @@ const AutoStoryViridianCase AUTO_STORY_VIRIDIAN_CASES[] = { .input = {.name = "17.02: from the Fly to Viridian through the gym into Warren's line", .body = test_row_17_02}, .expectation = {.description = "Warren's battle won on (15, 7), no other trainer met"}, }, + { + .input = {.name = "17.03: Takashi walks up and stays; the way to Giovanni goes around him", .body = test_row_17_03}, + .expectation = {.description = "Takashi on (10, 4) after his battle; on ViridianCity_Gym (2, 3), his battle the only one"}, + }, { .input = {.name = "17.04b: out of the beaten gym and by Fly to below Viridian's Center", .body = test_row_17_04b}, .expectation = {.description = "on ViridianCity (26, 27), no trainer met"}, 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 3ccab42213..2ddca09343 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -50,6 +50,8 @@ #include "PokemonFRLG_AutoStoryPlanGolden20.h" #include "PokemonFRLG_AutoStoryRows_Tests.h" #include "PokemonFRLG_AutoStoryMoveData.h" +#include "PokemonFRLG_AutoStoryMovedTrainers.h" +#include "PokemonFRLG_AutoStoryTrainerLine.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" #include "PokemonFRLG_AutoStoryUnauthoredStarts_Tests.h" @@ -355,6 +357,23 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step, std::vector(step.args, "direction"); + const int tiles = step.action == TRAINER_LINE_VARIANT ? TRAINER_LINE_TILES : 1; + const std::set beaten = beaten_trainers(walk_state().run_flags); + for (int c = 0; c < tiles; c++){ + pose = StoryPose{pose.map, pose.tile.next(direction), direction}; + if (const std::optional move = trainer_walking_up(walk_story_maps(), MapPosition{pose.map, pose.tile}, beaten)){ + walk_state().run_flags.insert(trainer_at_flag(*move)); + return; + } + } +} + // check_checkpoint()'s walk through the steps. UnitTestResult check_checkpoint_steps(const StoryCheckpoint& checkpoint, StoryPose& pose, std::vector& golden){ for (const StoryStep& step : checkpoint.steps){ @@ -372,6 +391,8 @@ UnitTestResult check_checkpoint_steps(const StoryCheckpoint& checkpoint, StoryPo if (result.result != UnitTestResult::PASSED){ return checkpoint.id + " " + result.message; } + }else if (step.kind == StoryStepKind::STEP && (step.action == TRAINER_LINE_VARIANT || step.action == TRAINER_WAIT_VARIANT)){ + step_into_line(pose, step); }else if (step.kind == StoryStepKind::STEP){ const Direction direction = Pokemon::story_arg(step.args, "direction"); pose = StoryPose{pose.map, pose.tile.next(direction), direction}; From ebf0d8ddc56a4f3df54be586f350c9555ebd0455 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 17:23:34 -0800 Subject: [PATCH 2/4] FRLG walker: a hold that moved nothing in a trainer's sight isn't taken as walked --- .../PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp | 6 +++++- .../AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index 704994c2da..e2b57f97d9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -221,7 +221,11 @@ 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}; + // The hold's movement stays: a hold that moved nothing didn't walk, + // whatever the watch saw (judge_movement()). Dropped, a bump into + // Takashi on (10, 4) was taken as "north 2 (open)" walked, and the + // next leg failed (console B, 2026-11-15 16:52, 17.03). + outcome = StepOutcome{.end = m_calls.watch_for_trainer(step, *crossing), .walked = std::nullopt, .movement = outcome.movement}; } m_last = leg; m_last_late = outcome.end == StepEnd::LATE; 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 043b90f2b7..52c2526505 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -107,8 +107,6 @@ const std::map KNOWN_FAILING{ "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"}, }; From 5e7cf6920d76b71c57c25be4ea94679029a2b917 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 17:26:01 -0800 Subject: [PATCH 3/4] FRLG AutoStory: note the trainer who walked up after any step into a line, shared by the program, the row sim and the plan walk --- .../PokemonFRLG_OverworldReanchor.cpp | 7 ++---- .../Overworld/PokemonFRLG_OverworldReanchor.h | 5 ---- .../PokemonFRLG_OverworldRecovery.cpp | 6 +---- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 22 +---------------- .../PokemonFRLG_AutoStoryMovedTrainers.cpp | 23 +++++++++++------- .../PokemonFRLG_AutoStoryMovedTrainers.h | 2 +- .../PokemonFRLG_AutoStoryPacedRoute.cpp | 24 +++++++++++++++++++ .../PokemonFRLG_AutoStoryPacedRoute.h | 16 +++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 7 ++---- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 11 ++++----- 10 files changed, 65 insertions(+), 58 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp index 5571873ea0..9801e7a4d7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp @@ -95,9 +95,8 @@ void add_trainer_stops( } } -} // namespace - - +// The trainers who may see the player on `tile`, and where each stands +// once walked up. std::vector trainers_seeing(const std::vector& maps, const MapPosition& tile){ std::vector stops; const MapData* map = map_named(maps, tile.map); @@ -109,8 +108,6 @@ std::vector trainers_seeing(const std::vector& maps, const return stops; } -namespace{ - // `maps` with a trainer who walked up standing on each of `trainers`: they // stay there after the battle, so the player can't walk through. std::vector with_trainers(const std::vector& maps, const std::vector& trainers){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h index 189ffb1308..e32947523a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h @@ -43,11 +43,6 @@ struct TrainerStop{ bool operator==(const TrainerStop& other) const = default; }; -// The trainers who may see the player on `tile`, and where each stands -// once walked up: one stop for a trainer who stands still, one for each -// side a wanderer may come from. -std::vector trainers_seeing(const std::vector& maps, const MapPosition& tile); - // One way things may stand after a stop: the player's tile, and the // trainer who stopped them there, if one did. struct StopCandidate{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index e2b57f97d9..849274a7dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -221,11 +221,7 @@ class CheckedSteps{ return outcome; } if (outcome.end == StepEnd::DONE && crossing && m_calls.watch_for_trainer){ - // The hold's movement stays: a hold that moved nothing didn't walk, - // whatever the watch saw (judge_movement()). Dropped, a bump into - // Takashi on (10, 4) was taken as "north 2 (open)" walked, and the - // next leg failed (console B, 2026-11-15 16:52, 17.03). - outcome = StepOutcome{.end = m_calls.watch_for_trainer(step, *crossing), .walked = std::nullopt, .movement = outcome.movement}; + 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; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index d8a94895b5..eed0e2ed90 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -36,7 +36,6 @@ #include "PokemonFRLG_AutoStoryHealingSteps.h" #include "PokemonFRLG_AutoStoryHideout.h" #include "PokemonFRLG_AutoStoryLegs.h" -#include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryRoutePose.h" #include "PokemonFRLG_AutoStoryScreenEvents.h" #include "PokemonFRLG_AutoStorySlopeRun.h" @@ -224,22 +223,6 @@ Outcome take_warp_step(StoryEnv& env, const RunState& state, const MapPosition& return Pokemon::outcome_ok(); } -// The trainer who saw the player on `tile` walked up to them and stands -// beside them from now on: a run flag says so (TRAINER_AT_FLAG), and the -// routes after the battle plan around them and over the tile they left. -// Planned on the map's tiles, below_giovanni went north from (10, 5) -// through Takashi, who had walked up to (10, 4) (console B, 2026-11-15 -// 16:52, 17.03). -void note_trainer_walked_up(StoryEnv& env, RunState& state, const StoryStep& step, const MapPosition& tile){ - const std::optional move = trainer_walking_up(run_story_maps(state.flags), tile, beaten_trainers(state.flags)); - if (!move){ - env.console.log(std::format("Story: {}: where the trainer who saw the player on {} stands now isn't known.", step.name, to_string(tile)), COLOR_ORANGE); - return; - } - state.flags.insert(trainer_at_flag(*move)); - env.console.log(std::format("Story: {}: {} walked up to ({}, {}) and stays there.", step.name, move->trainer, move->x, move->y)); -} - Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ const Direction direction = arg(step, "direction"); int tiles_stepped = 1; @@ -271,9 +254,6 @@ Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ for (int c = 0; c < tiles_stepped; c++){ onto = onto.next(direction); } - if (step.action == TRAINER_LINE_VARIANT || step.action == TRAINER_WAIT_VARIANT){ - note_trainer_walked_up(env, state, step, MapPosition{state.pose.map, onto}); - } return Pokemon::outcome_ok(to_pose(StoryPose{state.pose.map, onto, direction})); } @@ -787,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)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp index 893d3b200f..de9c99c6d9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp @@ -10,7 +10,6 @@ #include #include "Common/Cpp/Exceptions.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldObjects.h" -#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h" #include "PokemonFRLG_AutoStoryMovedTrainers.h" namespace PokemonAutomation{ @@ -38,6 +37,14 @@ std::optional> 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 @@ -69,19 +76,17 @@ std::optional trainer_walking_up( for (const MapData& candidate : maps){ map = candidate.name == tile.map ? &candidate : map; } - if (map == nullptr){ - return std::nullopt; - } std::optional move; - for (const TrainerStop& stop : trainers_seeing(maps, tile)){ - const std::string trainer = trainer_id(*map, map->objects[stop.object]); - if (beaten.contains(trainer)){ + 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){ + if (move || object.wander){ return std::nullopt; } - move = TrainerMove{.trainer = trainer, .x = stop.at.point.x, .y = stop.at.point.y}; + 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; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.h index 4c455af64f..b92201f340 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.h @@ -53,7 +53,7 @@ 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_seeing()). Trainers `beaten` +// 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. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp index ec4b6d3b24..9e7e149d78 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp @@ -9,9 +9,11 @@ #include #include #include "Common/Cpp/Concurrency/Mutex.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryPacedRoute.h" +#include "PokemonFRLG_AutoStoryTrainerLine.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -84,6 +86,28 @@ const std::vector& run_story_maps(const std::set& run_flag return it->second; } +std::optional note_trainer_walked_up(const MapPosition& tile, std::set& run_flags){ + const std::optional 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& run_flags){ + const bool line = step.action == TRAINER_LINE_VARIANT || step.action == TRAINER_WAIT_VARIANT; + const std::vector tiles = line && outcome.succeeded() && outcome.pose ? Pokemon::tiles_of(*outcome.pose) : std::vector(); + if (tiles.size() != 1){ + return; + } + const MapPosition tile{outcome.pose->map, tiles[0]}; + if (const std::optional 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); + } +} + std::set beaten_trainers(const std::set& run_flags){ std::set beaten; for (const std::string& flag : run_flags){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h index e7e6e6eb72..77b619b73a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h @@ -15,10 +15,13 @@ #include #include #include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" #include "Pokemon/Navigation/Pokemon_GatedTypes.h" #include "Pokemon/Navigation/Pokemon_Grid.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" +#include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryPoses.h" namespace PokemonAutomation{ @@ -52,6 +55,19 @@ inline constexpr std::string_view TRAINER_BEATEN_FLAG = "trainer_beaten:"; // The trainers `run_flags` says are beaten (TRAINER_BEATEN_FLAG), by // trainer_id(). std::set beaten_trainers(const std::set& run_flags); +// 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 note_trainer_walked_up(const MapPosition& tile, std::set& 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& run_flags); // default_route_costs() without Surf, which the story hasn't got yet: // routes stay on land, even where water is the shorter way (Vermilion // City's harbor). diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index ffdf44f538..83e109071d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -16,7 +16,6 @@ #include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "PokemonFRLG_AutoStoryBoulders.h" #include "PokemonFRLG_AutoStoryLegs.h" -#include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryPacedRoute.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" @@ -618,12 +617,10 @@ std::string OverworldStepSim::step_ahead(const StoryStep& step){ if (!step_until_seen(tiles, tap, seen)){ return "no trainer saw the player."; } - // As take_step(): the trainer who saw the player stands beside them + // 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){ - if (const std::optional move = trainer_walking_up(run_story_maps(m_flags), m_sim.state().position, m_beaten)){ - m_flags.insert(trainer_at_flag(*move)); - } + note_trainer_walked_up(m_sim.state().position, m_flags); } return ""; } 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 2ddca09343..b4581a5d82 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -50,7 +50,6 @@ #include "PokemonFRLG_AutoStoryPlanGolden20.h" #include "PokemonFRLG_AutoStoryRows_Tests.h" #include "PokemonFRLG_AutoStoryMoveData.h" -#include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryTrainerLine.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -360,15 +359,13 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step, std::vector(step.args, "direction"); const int tiles = step.action == TRAINER_LINE_VARIANT ? TRAINER_LINE_TILES : 1; - const std::set beaten = beaten_trainers(walk_state().run_flags); for (int c = 0; c < tiles; c++){ pose = StoryPose{pose.map, pose.tile.next(direction), direction}; - if (const std::optional move = trainer_walking_up(walk_story_maps(), MapPosition{pose.map, pose.tile}, beaten)){ - walk_state().run_flags.insert(trainer_at_flag(*move)); + if (note_trainer_walked_up(MapPosition{pose.map, pose.tile}, walk_state().run_flags)){ return; } } @@ -392,7 +389,7 @@ UnitTestResult check_checkpoint_steps(const StoryCheckpoint& checkpoint, StoryPo return checkpoint.id + " " + result.message; } }else if (step.kind == StoryStepKind::STEP && (step.action == TRAINER_LINE_VARIANT || step.action == TRAINER_WAIT_VARIANT)){ - step_into_line(pose, step); + step_into_line(step, pose); }else if (step.kind == StoryStepKind::STEP){ const Direction direction = Pokemon::story_arg(step.args, "direction"); pose = StoryPose{pose.map, pose.tile.next(direction), direction}; From 6f11f2fef0e63e0ed222f356088a0af390d9e26b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 17:26:53 -0800 Subject: [PATCH 4/4] FRLG AutoStory: the line trainer's walk-up in its own module --- .../AutoStory/PokemonFRLG_AutoStoryEvents.h | 1 + .../PokemonFRLG_AutoStoryLineTrainer.cpp | 45 ++++++++++++++++++ .../PokemonFRLG_AutoStoryLineTrainer.h | 47 +++++++++++++++++++ .../PokemonFRLG_AutoStoryPacedRoute.cpp | 24 ---------- .../PokemonFRLG_AutoStoryPacedRoute.h | 16 ------- .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 1 + .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 1 + SerialPrograms/cmake/SourceFiles.cmake | 2 + 8 files changed, 97 insertions(+), 40 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h index f3242020ce..c86d8dac51 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h @@ -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" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.cpp new file mode 100644 index 0000000000..83221146f3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.cpp @@ -0,0 +1,45 @@ +/* AutoStory Line Trainer + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#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 note_trainer_walked_up(const MapPosition& tile, std::set& run_flags){ + const std::optional 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& run_flags){ + const bool line = step.action == TRAINER_LINE_VARIANT || step.action == TRAINER_WAIT_VARIANT; + const std::vector tiles = line && outcome.succeeded() && outcome.pose ? Pokemon::tiles_of(*outcome.pose) : std::vector(); + if (tiles.size() != 1){ + return; + } + const MapPosition tile{outcome.pose->map, tiles[0]}; + if (const std::optional 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 diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.h new file mode 100644 index 0000000000..51dba6fb89 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.h @@ -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 +#include +#include +#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 note_trainer_walked_up(const MapPosition& tile, std::set& 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& run_flags); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp index 9e7e149d78..ec4b6d3b24 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.cpp @@ -9,11 +9,9 @@ #include #include #include "Common/Cpp/Concurrency/Mutex.h" -#include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryPacedRoute.h" -#include "PokemonFRLG_AutoStoryTrainerLine.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -86,28 +84,6 @@ const std::vector& run_story_maps(const std::set& run_flag return it->second; } -std::optional note_trainer_walked_up(const MapPosition& tile, std::set& run_flags){ - const std::optional 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& run_flags){ - const bool line = step.action == TRAINER_LINE_VARIANT || step.action == TRAINER_WAIT_VARIANT; - const std::vector tiles = line && outcome.succeeded() && outcome.pose ? Pokemon::tiles_of(*outcome.pose) : std::vector(); - if (tiles.size() != 1){ - return; - } - const MapPosition tile{outcome.pose->map, tiles[0]}; - if (const std::optional 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); - } -} - std::set beaten_trainers(const std::set& run_flags){ std::set beaten; for (const std::string& flag : run_flags){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h index 77b619b73a..e7e6e6eb72 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h @@ -15,13 +15,10 @@ #include #include #include -#include "Common/Cpp/Logging/AbstractLogger.h" -#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" #include "Pokemon/Navigation/Pokemon_GatedTypes.h" #include "Pokemon/Navigation/Pokemon_Grid.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" -#include "PokemonFRLG_AutoStoryMovedTrainers.h" #include "PokemonFRLG_AutoStoryPoses.h" namespace PokemonAutomation{ @@ -55,19 +52,6 @@ inline constexpr std::string_view TRAINER_BEATEN_FLAG = "trainer_beaten:"; // The trainers `run_flags` says are beaten (TRAINER_BEATEN_FLAG), by // trainer_id(). std::set beaten_trainers(const std::set& run_flags); -// 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 note_trainer_walked_up(const MapPosition& tile, std::set& 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& run_flags); // default_route_costs() without Surf, which the story hasn't got yet: // routes stay on land, even where water is the shorter way (Vermilion // City's harbor). diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index 83e109071d..78c9d89c0b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -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" 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 b4581a5d82..cca8d41a7c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -49,6 +49,7 @@ #include "PokemonFRLG_AutoStoryPlanGolden19.h" #include "PokemonFRLG_AutoStoryPlanGolden20.h" #include "PokemonFRLG_AutoStoryRows_Tests.h" +#include "PokemonFRLG_AutoStoryLineTrainer.h" #include "PokemonFRLG_AutoStoryMoveData.h" #include "PokemonFRLG_AutoStoryTrainerLine.h" #include "PokemonFRLG_AutoStoryStepTable.h" diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index bada30a983..5f9a28bd42 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2205,6 +2205,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLineTrainer.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoveSteps.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp