Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Sim

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

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

std::optional<OverworldSim::Step> OverworldSim::take_warp(int map_index, const TilePos& tile) const{
const MapWarp* warp = warp_at(m_maps[map_index], tile);
if (warp == nullptr){
if (warp == nullptr || m_script.dead_warp_maps.contains(m_maps[map_index].name)){
return std::nullopt;
}
if (m_lift_floor && m_script.lift_floors.contains(m_maps[map_index].name)){
Expand Down Expand Up @@ -355,11 +355,14 @@

// The player has taken `step`, pressed at `pressed`. Returns whether the
// game stopped them there: a warp, a trainer, a wild battle.
bool OverworldSim::after_step(const Step& step, Milliseconds pressed){

Check warning on line 358 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::OverworldSim::after_step( const Step & step , Milliseconds pressed): function_lines=38 (advisory above 25, limit 50)
const SimTiming& timing = m_script.timing;
if (step.warped && black_without_warp(pressed)){
return true;
}
if (step.warped){
m_state.warped_from.push_back(map().name);
}
m_map = step.map;
m_player = step.player;
m_state.steps++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ struct SimScript{
// fade's black and clear with the player where they were, not warped
// (console B, 2026-11-10 01:44, 09.01 run 4, "east 1 (warp)" on B4F).
std::set<int> black_without_warp;
// Fault injection: maps whose warps do nothing: a step or press onto
// one leaves the player where they were, with no fade, as a wall would
// (the warp no-op fault class, PokemonFRLG_AutoStoryFaultSweep_Tests.cpp).
std::set<std::string> dead_warp_maps;
// The player rides the Bicycle: a tap facing another way takes a step
// too, a hold through a turn loses no tile
// (MovementMechanics::BIKE_TAP_ONLY_TURNS), and no step tap is
Expand Down Expand Up @@ -98,6 +102,8 @@ struct SimState{
bool dark = false;
int steps = 0;
int warps = 0;
// The map each warp was taken from, oldest first.
std::vector<std::string> warped_from;
int wild_battles = 0;
// From each wild battle's step to the overworld after it, together.
Milliseconds in_wild_battles{0};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Events

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=936 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -200,7 +200,19 @@
return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after}));
}

// A step onto a warp (a door, a mat, stairs): done only once its fade
// shows and the screen after it leaves the scene, else it fails
// (wait_out_warp()). The pose after it is the table's.
Outcome take_warp_step(StoryEnv& env, const RunState& state, const RouteStep& warp){
env.context.wait_for_all_requests();
const VideoSnapshot before = env.console.video().snapshot();
step_once(env.console, env.context, warp.direction, facing_of(state.pose));
OverworldWalkSteps::wait_out_warp(env.console, env.context, warp, before);
env.console.log(std::format("Story: the step took the warp to {}.", warp.end.map));
return Pokemon::outcome_ok();
}

Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){

Check warning on line 215 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::take_step( StoryEnv & env , RunState & state , const StoryStep & step): function_lines=32 (advisory above 25, limit 50)
const Direction direction = arg<Direction>(step, "direction");
int tiles_stepped = 1;
if (step.action == TRAINER_LINE_VARIANT){
Expand All @@ -214,6 +226,11 @@
if (!step_into_line(env.console, env.context, direction, facing_of(state.pose), 1, TRAINER_WAIT_WATCH)){
return Pokemon::outcome_failed("no_trainer", std::format("{} s on the tile {}", TRAINER_WAIT_WATCH.count() / 1000, direction_name(direction)));
}
}else if (const std::optional<StoryPose> from = story_pose(state.pose)){
if (const std::optional<RouteStep> warp = warp_press(story_maps(), MapPosition{from->map, from->tile}, direction)){
return take_warp_step(env, state, *warp);
}
step_once(env.console, env.context, direction, facing_of(state.pose));
}else{
step_once(env.console, env.context, direction, facing_of(state.pose));
}
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=693 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -25,6 +25,10 @@
* back, inside the lockout after a battle (08.01 winston_line, console
* B, 2026-11-09 15:50). The step alone, from where the clean run took
* it, on its map made a wild floor.
* - WARP_NO_OP: the warps of each map the row warps from do nothing,
* no fade and no move, so the step that walks onto the first of them
* must stop there, not go on as if warped (09.01's B4F stairs, console
* B, 2026-11-10, reported as walked to B3F).
*
* Not swept here: a missed fade, which needs a knob in OverworldSim; a
* battle's opening at a step's start, which needs one in OverworldStepSim;
Expand Down Expand Up @@ -76,6 +80,7 @@
SLOW_FADE_IN,
DARK_CAVE,
LOST_TAP,
WARP_NO_OP,
};
std::string_view fault_class_name(FaultClass fault){
switch (fault){
Expand All @@ -91,6 +96,8 @@
return "dark cave without Flash";
case FaultClass::LOST_TAP:
return "lost tap after a battle in a trainer's line";
case FaultClass::WARP_NO_OP:
return "warp no-op";
}
return "?";
}
Expand Down Expand Up @@ -162,6 +169,10 @@
// Where the player stood before each step, by index.
std::map<size_t, MapPosition> before;
std::map<size_t, Direction> facing_before;
// The maps each step warped from, by index.
std::map<size_t, std::vector<std::string>> warped_from;
// The step `failure` is from; none for a violation or a row's end.
std::optional<size_t> failed_at;
MapPosition end;
Milliseconds time{0};
int steps = 0;
Expand Down Expand Up @@ -212,13 +223,36 @@
return true;
}

// Row `row`'s step `c` on `sim` from `at`, recorded in `out`. Returns
// whether it failed as unscripted() and was let pass (run_row()).
bool run_row_step(

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: run_row_step: output parameter 'RowRun& out' comes before an input; put inputs (by value, const&) first and non-const references last (Google "Function Parameter Ordering")
RowRun& out, OverworldSim& sim, StoryPose& at, const StoryCheckpoint& row, size_t c,
const std::optional<std::set<size_t>>& scripted
){
out.before.emplace(c, sim.state().position);
out.facing_before.emplace(c, sim.state().facing);
const size_t warps_before = sim.state().warped_from.size();
out.failure = row_step_on_sim(sim, at, row.steps[c], row.id);
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));
if (let_pass){
out.failure.clear();
out.scripted.insert(c);
}
if (!out.failure.empty()){
out.failed_at = c;
}
return let_pass;
}

// Row `row` on the sim with `script`, from its start. After a step the sim
// does not play, the player is put on its pose_after, or on `landings`'
// tile for it, the program going on from the pose_after either way. A
// 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 255 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 & script , const Landings & landings = { } , const std :: optional<std::set<size_t>> & scripted = std :: nullopt): function_lines=43 (advisory above 25, limit 50)
const StoryCheckpoint& row, const SimScript& script, const Landings& landings = {},
const std::optional<std::set<size_t>>& scripted = std::nullopt
){
Expand All @@ -235,14 +269,7 @@
};
for (size_t c = 0; c < row.steps.size() && out.failure.empty(); c++){
const StoryStep& step = row.steps[c];
out.before.emplace(c, sim->state().position);
out.facing_before.emplace(c, sim->state().facing);
out.failure = row_step_on_sim(*sim, at, step, row.id);
const bool let_pass = unscripted(out.failure) && (!scripted || scripted->contains(c));
if (let_pass){
out.failure.clear();
out.scripted.insert(c);
}
const bool let_pass = run_row_step(out, *sim, at, row, c, scripted);
if (!out.failure.empty() || (sim_plays(step) && !let_pass) || !step.pose_after){
continue;
}
Expand Down Expand Up @@ -504,6 +531,47 @@
return sweep_result(logger, FaultClass::LOST_TAP, row.id, variants, failures);
}

// The steps of the clean run `clean` of `row` that warp, by index: the
// first from each map, with that map.
std::vector<std::pair<size_t, std::string>> first_warps_by_map(const StoryCheckpoint& row, const RowRun& clean){
std::vector<std::pair<size_t, std::string>> out;
std::set<std::string> maps;
for (size_t c = 0; c < row.steps.size(); c++){
const auto warped = clean.warped_from.find(c);
if (warped == clean.warped_from.end()){
continue;
}
for (const std::string& map : warped->second){
if (maps.insert(map).second){
out.emplace_back(c, map);
}
}
}
return out;
}

// Row `row` with the warps of each map it warps from doing nothing, one
// map at a time: the step onto the first of them must stop the row.
UnitTestResult sweep_warp_no_op(Logger& logger, const StoryCheckpoint& row, const RowRun& clean){
std::vector<SweepFailure> failures;
const std::vector<std::pair<size_t, std::string>> warps = first_warps_by_map(row, clean);
for (const auto& [c, map] : warps){
SimScript script;
script.dead_warp_maps = {map};
const RowRun run = run_row(row, script, {}, clean.scripted);
if (run.failed_at == c){
continue;
}
const std::string variant = "every warp on " + map + " does nothing";

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: build strings with std::format, not + on a literal / std::to_string / std::string (fork AGENTS.md "Strings")
if (run.failure.empty()){
failures.push_back({row.steps[c].name, variant, std::format("not stopped: the row went on and ended on {}.", to_string(run.end))});
}else{
failures.push_back({row.steps[c].name, variant, std::format("stopped at {}, not here: {}", run.failed_at ? row.steps[*run.failed_at].name : "the row's end", run.failure)});
}
}
return sweep_result(logger, FaultClass::WARP_NO_OP, row.id, warps.size(), failures);
}

// A fault class swept over row `row` (empty in FAULT_SWEEP_CASES: each
// row with a start).
struct FaultSweepInput{
Expand Down Expand Up @@ -573,6 +641,8 @@
return sweep_dark_cave(logger, m_row, clean);
case FaultClass::LOST_TAP:
return sweep_lost_tap(logger, m_row, clean);
case FaultClass::WARP_NO_OP:
return sweep_warp_no_op(logger, m_row, clean);
}
return true;
}
Expand All @@ -591,6 +661,7 @@
{.input = {.fault = FaultClass::SLOW_FADE_IN}, .expectation = {}},
{.input = {.fault = FaultClass::DARK_CAVE}, .expectation = {}},
{.input = {.fault = FaultClass::LOST_TAP}, .expectation = {}},
{.input = {.fault = FaultClass::WARP_NO_OP}, .expectation = {}},
};

std::optional<std::string> talk_battle_hide_flag(const StoryStep& step){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
*/

#include <algorithm>
#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h"
#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin.h"
#include "PokemonFRLG_AutoStoryLegs.h"
Expand Down Expand Up @@ -71,6 +72,31 @@ std::optional<std::vector<RouteStep>> fixed_route(
return route;
}

std::optional<RouteStep> warp_press(const std::vector<MapData>& maps, const MapPosition& from, Direction direction){
const auto map = std::find_if(maps.begin(), maps.end(), [&](const MapData& data){ return data.name == from.map; });
if (map == maps.end() || !in_bounds(*map, from.point)){
return std::nullopt;
}
const TilePos ahead = from.point.next(direction);
TilePos warp_tile = ahead;
if (exit_mat(*map, from.point) == direction){
warp_tile = from.point;
}else if (!in_bounds(*map, ahead) || !((direction == Direction::NORTH && is_door(*map, ahead)) || warps_on_step(*map, ahead))){
return std::nullopt;
}
const MapWarp* warp = warp_at(*map, warp_tile);
if (warp == nullptr){
return std::nullopt;
}
RouteStep step;
step.direction = direction;
step.tiles = 1;
step.warps = true;
step.facing_after = direction;
step.end = MapPosition{warp->to ? warp->to->map : map->name, warp_tile};
return step;
}


} // namespace PokemonFRLG
} // namespace NintendoSwitch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ std::optional<std::vector<RouteStep>> fixed_route(
const std::vector<MapData>& maps, const MapPosition& start, const std::vector<Pokemon::StoryLeg>& legs
);

// The one-tile walk a press of `direction` from `from` makes, if it takes
// a warp: an exit mat stood on, a door ahead going north, or a warp tile
// stepped onto. Its fade and the scene after it must then be confirmed
// (OverworldWalkSteps::wait_out_warp()), not taken as walked.
std::optional<RouteStep> warp_press(const std::vector<MapData>& maps, const MapPosition& from, Direction direction);



} // namespace PokemonFRLG
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=681 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -14,6 +14,7 @@
#include "Common/Cpp/Exceptions.h"
#include "Pokemon/AutoStory/Pokemon_TilePose.h"
#include "PokemonFRLG_AutoStoryLegs.h"
#include "PokemonFRLG_AutoStoryPacedRoute.h"
#include "PokemonFRLG_AutoStoryActions.h"
#include "PokemonFRLG_AutoStoryBattleDecisions.h"
#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h"
Expand Down Expand Up @@ -484,11 +485,16 @@
// 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 488 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=29 (advisory above 25, limit 50)
if (step.action.empty() && step.pose_after){
return step_onto(step);
}
const Direction direction = Pokemon::story_arg<Direction>(step.args, "direction");
if (step.action.empty()){
if (const std::optional<RouteStep> warp = warp_press(story_maps(), MapPosition{m_at.map, m_at.tile}, direction)){
return step_onto_warp(*warp);
}
}
const auto tap = [this, direction]{
sim_step_once(m_sim, direction);
};
Expand All @@ -509,6 +515,21 @@
return step_until_seen(tiles, tap, seen) ? "" : "no trainer saw the player.";
}

// take_warp_step() on the sim: the step, then its fade, with a step more
// twice while none shows (wait_out_warp()).
std::string OverworldStepSim::step_onto_warp(const RouteStep& warp){
const int warps_before = m_sim.state().warps;
sim_step_once(m_sim, warp.direction);
for (int tap = 0; tap < 2 && m_sim.state().warps == warps_before; tap++){
sim_step_once(m_sim, warp.direction);
}
if (m_sim.state().warps == warps_before){
return std::format("no fade in and out after stepping onto the warp to {}.", warp.end.map);
}
m_sim.watch({}, OverworldWalkSteps::AFTER_WARP);
return "";
}

// A hop() or step_onto(): one step, ending where the table says.
std::string OverworldStepSim::step_onto(const StoryStep& step){
sim_step_once(m_sim, Pokemon::story_arg<Direction>(step.args, "direction"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class OverworldStepSim : public Pokemon::TableExecutor{
std::string walk(const StoryStep& step);
std::string step_ahead(const StoryStep& step);
std::string step_onto(const StoryStep& step);
std::string step_onto_warp(const RouteStep& warp);
std::string cut(const StoryStep& step);
std::string battle(const StoryStep& step);
Pokemon::StoryAction hideout_or_stub();
Expand Down
Loading