diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index 704994c2da..849274a7dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -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; 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..eed0e2ed90 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -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)){ 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_AutoStoryFaultSweep_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp index 9ff539b5c6..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"}, }; @@ -263,6 +261,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 +319,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 +371,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_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_AutoStoryMovedTrainers.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp index 92579cfeb0..de9c99c6d9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMovedTrainers.cpp @@ -37,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 @@ -57,6 +65,32 @@ 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; + } + std::optional 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 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..b92201f340 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 `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..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" @@ -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,15 @@ 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 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 @@ -842,12 +852,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..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,7 +49,9 @@ #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" #include "PokemonFRLG_AutoStoryTable.h" #include "PokemonFRLG_AutoStoryUnauthoredStarts_Tests.h" @@ -355,6 +357,21 @@ 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; + for (int c = 0; c < tiles; c++){ + pose = StoryPose{pose.map, pose.tile.next(direction), direction}; + if (note_trainer_walked_up(MapPosition{pose.map, pose.tile}, walk_state().run_flags)){ + 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 +389,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(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}; 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