Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
92a3502
FRLG AutoStory stage 5: Route 25 and Bill's S.S. Ticket
dayfine Nov 3, 2026
df1e266
Merge remote-tracking branch 'origin/frlg/stage4-cerulean' into frlg/…
dayfine Nov 3, 2026
db1a21a
FRLG AutoStory teach: move tutors, as for Route 4's Mega Kick
dayfine Nov 3, 2026
ff5bf0a
FRLG AutoStory 00.20: an Oddish from Route 24's grass
dayfine Nov 3, 2026
413dee4
FRLG AutoStory 00.18: walk around Bill on the way out of the Sea Cottage
dayfine Nov 3, 2026
dc384b1
FRLG image tests: expected values from the file names
dayfine Nov 3, 2026
7e5a549
FRLG AutoStory 00.14: Mega Kick from Route 4's tutor on the way to Ce…
dayfine Nov 3, 2026
7a05318
FRLG AutoStory: hold a tile longer per map connection a leg crosses
dayfine Nov 3, 2026
b5e3a2e
FRLG AutoStory 00.20: mark the Oddish row a stopgap for console B's save
dayfine Nov 3, 2026
51eb5de
FRLG AutoStory: plan the walk after pacing from both of its tiles
dayfine Nov 3, 2026
1c22de0
FRLG AutoStory 00.20: walk west to the cliff, out of Shane's sight
dayfine Nov 3, 2026
360701b
FRLG AutoStory: fight a trainer who sees the player while pacing
dayfine Nov 3, 2026
7b6a28c
Merge commit '4e3cf21ebd0c94f71196c7468d0606cf773ef5b5' into HEAD
dayfine Nov 5, 2026
0cbf80f
FRLG AutoStory stage 5: align with PR #231 lint conventions
dayfine Nov 6, 2026
0ea1d97
Merge origin/frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 6, 2026
6484afe
Merge origin/frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 7, 2026
e1afaa5
Merge remote-tracking branch 'origin/frlg/stage4-cerulean' into frlg/…
dayfine Nov 8, 2026
79bb621
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 8, 2026
115defd
Merge remote-tracking branch 'origin/frlg/stage4-cerulean' into HEAD
dayfine Nov 9, 2026
4112bf7
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 9, 2026
bbef25b
Merge frlg/stage4-cerulean (story action table) into frlg/stage5-bill
dayfine Nov 9, 2026
2574ea5
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 9, 2026
219902a
Merge frlg/stage4-cerulean: check the save stands at the checkpoint's…
dayfine Nov 9, 2026
356b927
FRLG AutoStory: keep the simulation tests' line endings
dayfine Nov 9, 2026
dd8ce6d
Merge frlg/stage4-cerulean: time an interrupt's step from its screen …
dayfine Nov 9, 2026
3ce2b45
Merge frlg/stage4-cerulean: check a loaded save's start against a kep…
dayfine Nov 9, 2026
755329d
Merge frlg/stage4-cerulean: check a loaded save's start against a kep…
dayfine Nov 9, 2026
2ab5af7
Merge 19d082561 (#122 via parent) into frlg/stage5-bill
dayfine Nov 9, 2026
b93d1d3
Merge FRLG between-step interrupts (0ec989dd4) into #219
dayfine Nov 9, 2026
82e3821
Merge FRLG between-step interrupts (3f472f67a) into #219
dayfine Nov 9, 2026
12c744e
Merge FRLG interrupt actions move (4b520be72) into #219
dayfine Nov 9, 2026
480f132
Merge frlg/stage4-cerulean into frlg/stage5-bill (hold watchers for t…
dayfine Nov 9, 2026
24a17a1
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 9, 2026
8f6fdc5
Merge frlg/stage4-cerulean into frlg/stage5-bill (wait for a battle's…
dayfine Nov 9, 2026
93c1b56
Merge frlg/stage4-cerulean into frlg/stage5-bill (scene ends after it…
dayfine Nov 9, 2026
5c8b08f
Merge frlg/stage4-cerulean into frlg/stage5-bill: a step on the Switc…
dayfine Nov 9, 2026
bb75eb0
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 10, 2026
bec6662
Merge origin/frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 10, 2026
b28ee6e
Merge frlg/stage4-cerulean (#334) into frlg/stage5-json: stage 5's ro…
dayfine Nov 10, 2026
0d47b00
FRLG AutoStory: delete stage 5's C++ story rows, parity proven
dayfine Nov 10, 2026
c4b55d7
Merge pull request #336 from dayfine/frlg/stage5-json
dayfine Nov 10, 2026
182af70
Merge frlg/stage4-cerulean (detectors split, maps from Packages, no b…
dayfine Nov 10, 2026
61f9a91
Merge branch 'frlg/stage4-cerulean' into frlg/stage5-bill
dayfine Nov 11, 2026
a94f97e
Merge branch 'frlg/stage4-cerulean' into frlg/stage5-bill
dayfine Nov 11, 2026
bdb46c1
Merge origin/frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 12, 2026
b5f0f30
Merge origin/frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 13, 2026
349dbb0
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 14, 2026
f0aa599
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 14, 2026
84dad09
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 14, 2026
3113936
Merge frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 14, 2026
fd851e6
Merge origin/frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 14, 2026
f933703
Merge origin/frlg/stage4-cerulean into frlg/stage5-bill
dayfine Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,23 @@ std::optional<Reanchor> plan_reanchor(
return std::nullopt;
}

std::optional<std::vector<RouteStep>> holds_to_one_tile(
const std::vector<MapData>& maps, const std::vector<MapPosition>& tiles
){
std::vector<Hypothesis> positions;
for (const MapPosition& tile : tiles){
add_unique(positions, Hypothesis{0, tile});
}
if (positions.empty()){
return std::nullopt;
}
const std::vector<Found> found = find_player({maps}, positions, false);
if (found.empty()){
return std::nullopt;
}
return found[0].holds;
}



} // namespace PokemonFRLG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Re-anchor

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<header>: header_symbols=8 (advisory above 6, limit 8)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -90,6 +90,15 @@
const RouteCosts& costs = default_route_costs()
);

// Holds to walls that bring the player to one tile from every one of
// `tiles`, found as plan_reanchor() finds them, with no trainer about: for
// a player known to be on one of a few tiles without a stop (a wild
// battle's pacing). Empty if `tiles` are one tile; the last hold ends on
// it otherwise. Nothing if no holds bring them together.
std::optional<std::vector<RouteStep>> holds_to_one_tile(
const std::vector<MapData>& maps, const std::vector<MapPosition>& tiles
);


// Registers overworld reanchor unit tests.
void add_tests_OverworldReanchor(UnitTestDatabase& database);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Pokemon::LegSpec leg_spec(const RouteStep& step, MoveSpeed speed){
leg.tile_time = tile_time(step, speed);
leg.stop_on_interrupt = !step.to_wall;
leg.stop_if_blocked = step.to_wall;
leg.stalled_steps = step.connection_steps;
return leg;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Route

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=1000 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -7,6 +7,7 @@
#include <algorithm>
#include <format>
#include <functional>
#include <ranges>
#include <string>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/TestRunners/UnitTest.h"
Expand Down Expand Up @@ -333,7 +334,7 @@
return leg_costs;
}

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

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::to_route_step( const std :: vector<MapData> & maps , const Pokemon :: Leg<Located> & leg): function_lines=33 (advisory above 25, limit 50)
RouteStep step;
switch (leg.kind){
case Pokemon::LegKind::WALK:
Expand All @@ -360,6 +361,10 @@
// wasn't watched for battles (console B, 2026-11-01).
step.wild = leg.wild || leg.start.state.surfing || leg.kind == Pokemon::LegKind::ACTION;
}
const std::vector<MapPosition> tiles = leg_tiles(maps, MapPosition{maps[leg.start.map].name, leg.start.state.position}, step);
for (int c : std::views::iota(1, (int)tiles.size()) | std::views::filter([&](int n){ return tiles[n].map != tiles[n - 1].map; })){
step.connection_steps.push_back(c);
}
return step;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ struct RouteStep{
// tall grass or water. Elsewhere (indoors, streets) no wild battle can
// start, so the walker doesn't watch for one.
bool wild = false;
// WALK: the steps (from 1) onto a connected map. The game holds the
// player up a tile before each while it loads the map: a hold timed
// by the tiles alone ended a tile short (console B, 2026-11-03, rows
// 00.14, 00.16 and 00.20).
std::vector<int> connection_steps = {};
// Which way the player faces after the step. Arriving at a door or a
// cave mouth, the game walks the player a tile out, facing south.
Direction facing_after = Direction::NORTH;
Expand Down
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=753 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -355,7 +355,7 @@
}

// The steps a hold of `duration` takes, `short_by` fewer.
void OverworldSim::walk_hold(Direction direction, Milliseconds duration, int short_by){

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::walk_hold( Direction direction , Milliseconds duration , int short_by): function_lines=34 (advisory above 25, limit 50)
const Milliseconds tile = m_script.timing.tile;
const Milliseconds end = m_now + duration;
Milliseconds pressed = m_now;
Expand All @@ -371,6 +371,15 @@
bump(direction, pressed);
return;
}
if (step->map != m_map && !step->warped){
// The step onto a connected map waits a tile while the game
// loads it: a hold timed by its tiles alone ended a tile short
// (console B, 2026-11-03, rows 00.14, 00.16 and 00.20).
pressed += tile;
if (pressed >= end){
return;
}
}
if (step->walked_out){
m_state.facing = Direction::SOUTH;
}
Expand Down Expand Up @@ -590,7 +599,7 @@
fail("walk_overworld_route(): a wild battle, not the warp to " + step.end.map + ": the player is off the route.");
}

std::optional<WalkedTiles> OverworldSimWalker::walk_step(const RouteStep& step, std::optional<Direction> facing){

Check warning on line 602 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::OverworldSimWalker::walk_step( const RouteStep & step , std :: optional<Direction> facing): function_lines=46 (advisory above 25, limit 50)
if (step.action == RouteAction::FACE){
m_sim.tap(step.direction);
return std::nullopt;
Expand All @@ -610,6 +619,9 @@
leg.tile_time = TILE_TIME;
leg.stop_on_interrupt = !step.to_wall;
leg.stop_if_blocked = step.to_wall && m_rules.stop_if_blocked;
if (m_rules.hold_over_connections){
leg.stalled_steps = step.connection_steps;
}
Pokemon::LegCalls calls;
calls.hold_watching = [&](Milliseconds hold) -> std::optional<Pokemon::HoldOutcome>{
const std::optional<SimSeen> seen = hold_watching(step, hold, ints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* with the walker's rules as switches, so a test can show a failure with
* the rule that was missing and its absence with the rule.
*
* A step onto a connected map waits a tile first, as the console does
* while the game loads the map.
*
* Not modelled: Surf, bikes, running, HP and status. Wandering people
* stand on their tile.
*
Expand Down Expand Up @@ -177,6 +180,11 @@ struct SimWalkerRules{
// on for, and the step before it taken as stopped part-way, not the
// step held from where the battle left the player.
bool battle_before_step = true;
// A hold over a step onto a connected map is a tile longer for it
// (RouteStep::connection_steps). Without it the open leg north from
// Cerulean City onto Nugget Bridge ended a tile short (console B,
// 2026-11-03, rows 00.16 and 00.20).
bool hold_over_connections = true;
};

// The console side of run_route() on an OverworldSim, as
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Overworld Walk

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

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


Pokemon::LegSpec leg_spec(const RouteStep& step, MoveSpeed speed){
return Pokemon::LegSpec{step.direction, step.tiles, step.to_wall, tile_time(step, speed)};
Pokemon::LegSpec leg{step.direction, step.tiles, step.to_wall, tile_time(step, speed)};
leg.stalled_steps = step.connection_steps;
return leg;
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "Programs/PokemonFRLG_NamingScreenKeyboard_Tests.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryBattle.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryCapture.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryPaceSim.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryAbilities.h"
#include "Programs/AutoStory/PokemonFRLG_AutoStoryRngLoop.h"
Expand Down Expand Up @@ -94,7 +95,7 @@
add_tests_GiftRngAttempts(database);
}

void add_tests(UnitTestDatabase& database){

Check warning on line 98 in SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::add_tests( UnitTestDatabase & database): function_lines=50 (advisory above 25, limit 50)
add_tests_AdvanceWhiteDialogDetector(database);
add_tests_AdvanceBattleDialogDetector(database);
add_tests_BagDetector(database);
Expand Down Expand Up @@ -135,6 +136,7 @@
add_tests_AutoStory(database);
add_tests_AutoStoryExport(database);
add_tests_AutoStorySimulation(database);
add_tests_AutoStoryPaceSim(database);
add_tests_AutoStoryItems(database);
add_tests_AutoStoryRngLoop(database);
add_tests_AutoStoryCapture(database);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Battle

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

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=994 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -764,13 +764,7 @@
return 400ms;
}
virtual void clear(ConsoleHandle& console, ProControllerContext& context) const override{
if (advance_text(console, context, AFTER_BATTLE_TEXT, true) == TextEnd::OVERWORLD){
return;
}
console.log("Story: a trainer's battle after a message on the overworld.");
fail_on_blackout(console, fight_battle(console, context, m_supplies, BattleKind::TRAINER, m_checks, m_language));
mash_until_overworld(console, context, AFTER_BATTLE_TEXT);
recover_after_battle(console, context, m_supplies, m_checks, m_language);
clear_overworld_message(console, context, m_supplies, m_checks, m_language);
}

private:
Expand Down Expand Up @@ -973,6 +967,16 @@
return BattleLoop(console, context, supplies, kind, checks, language).run();
}

void clear_overworld_message(ConsoleHandle& console, ProControllerContext& context, Supplies& supplies, Pokemon::StoryCheckLevel checks, Language language){

Check warning on line 970 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: clear_overworld_message: output parameter 'Supplies& supplies' comes before an input; put inputs (by value, const&) first and non-const references last (Google "Function Parameter Ordering")
if (advance_text(console, context, AFTER_BATTLE_TEXT, true) == TextEnd::OVERWORLD){
return;
}
console.log("Story: a trainer's battle after a message on the overworld.");
fail_on_blackout(console, fight_battle(console, context, supplies, BattleKind::TRAINER, checks, language));
mash_until_overworld(console, context, AFTER_BATTLE_TEXT);
recover_after_battle(console, context, supplies, checks, language);
}

OverworldInterruptSet story_interrupts(Supplies& supplies, bool fight_wild, Pokemon::StoryCheckLevel checks, Language language){
// Battles first: their screens are checked before the message box's.
OverworldInterruptSet ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "PokemonFRLG_AutoStoryParty.h"
#include "PokemonFRLG_AutoStoryItemsPocket.h"
#include "PokemonFRLG_AutoStoryStatusBadge.h"
#include "PokemonFRLG_AutoStoryTrainerMessage.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "CommonTools/Async/InferenceRoutines.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h"
#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_BagDetector.h"
#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_ItemListReader.h"
#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleFlashWatcher.h"
Expand Down Expand Up @@ -393,6 +394,13 @@ bool pace_until_battle(Logger& logger, PatchSteps& steps, size_t max_steps){
logger.log(std::format("Pacing: a battle shows after step {}; its flash was missed.", c + 1), COLOR_ORANGE);
return true;
}
// Console B, 2026-11-03 (m63): Camper Shane on Route 24 saw the
// player pace in his sight and walked up; his message stayed up
// while the rest of the steps paced in vain.
if (steps.message_shows()){
const std::string trainer = steps.fight_trainer();
logger.log(std::format("Pacing: trainer battle during pacing: {}, after step {}.", trainer, c + 1), COLOR_ORANGE);
}
}
if (steps.overworld_shows()){
return false;
Expand All @@ -407,11 +415,15 @@ bool pace_until_battle(Logger& logger, PatchSteps& steps, size_t max_steps){
}


ConsolePatchSteps::ConsolePatchSteps(ConsoleHandle& console, ProControllerContext& context, Direction pace, PaceSpot& spot)
ConsolePatchSteps::ConsolePatchSteps(
ConsoleHandle& console, ProControllerContext& context, Direction pace, PaceSpot& spot,
const PaceTrainerBattle& trainer_battle
)
: m_console(console)
, m_context(context)
, m_pace(pace)
, m_spot(spot)
, m_trainer_battle(trainer_battle)
{}

bool ConsolePatchSteps::step(){
Expand All @@ -438,21 +450,38 @@ bool ConsolePatchSteps::overworld_shows(){
return PokemonFRLG::overworld_shows(m_console, m_context);
}

bool ConsolePatchSteps::message_shows(){
m_context.wait_for_all_requests();
VideoSnapshot screen = m_console.video().snapshot();
return screen && WhiteDialogDetector(COLOR_RED).detect(screen);
}

std::string ConsolePatchSteps::fight_trainer(){
m_trainer_battle();
// Back on the patch's tile, facing as the walk back left it.
m_spot = {};
return "a trainer";
}

void ConsolePatchSteps::dump_screen(std::string_view label){
m_context.wait_for_all_requests();
dump_debug_image(m_console, "AutoStory/pace", std::string(label), m_console.video().snapshot());
}


ConsoleCaptureActions::ConsoleCaptureActions(ConsoleHandle& console, ProControllerContext& context, Language language)
ConsoleCaptureActions::ConsoleCaptureActions(
ConsoleHandle& console, ProControllerContext& context, Language language,
PaceTrainerBattle trainer_battle
)
: m_console(console)
, m_context(context)
, m_language(language)
, m_trainer_battle(std::move(trainer_battle))
{}

bool ConsoleCaptureActions::find_encounter(Direction pace){
PaceSpot spot;
ConsolePatchSteps steps(m_console, m_context, pace, spot);
ConsolePatchSteps steps(m_console, m_context, pace, spot, m_trainer_battle);
return pace_until_battle(m_console.logger(), steps, PACE_MAX_STEPS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define PokemonAutomation_PokemonFRLG_AutoStoryCapture_H

#include <cstddef>
#include <functional>
#include <optional>
#include <string>
#include <string_view>
Expand All @@ -39,6 +40,7 @@
#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h"
#include "Pokemon/Navigation/Pokemon_Grid.h"
#include "PokemonFRLG_AutoStoryPcStorage.h"
#include "PokemonFRLG_AutoStoryTrainerMessage.h"
#include "PokemonFRLG_AutoStoryCaptureRun.h"
#include "PokemonFRLG_AutoStoryCaptureTurns.h"
#include "PokemonFRLG_AutoStoryCaptureStep.h"
Expand Down Expand Up @@ -80,45 +82,64 @@ class PatchSteps{
virtual bool battle_shows() = 0;
// Whether the overworld is up, with no text or menu open.
virtual bool overworld_shows() = 0;
// Whether a message shows on the overworld: a trainer who saw the
// player walked up and speaks.
virtual bool message_shows() = 0;
// From that message: closes it, fights the trainer's battle after it,
// and stands the player back on the patch's tile, from either tile
// pacing may have left them on. Returns who was fought, for the log.
virtual std::string fight_trainer() = 0;
// Saves the screen as a debug image, named `label`.
virtual void dump_screen(std::string_view label) = 0;
};

// From the overworld, in the patch: steps until a wild battle starts,
// `max_steps` at most. True once one has.
// `max_steps` at most. True once one has. A trainer who sees the player
// meanwhile is fought (PatchSteps::fight_trainer()) and pacing goes on;
// their battle isn't a wild one.
bool pace_until_battle(Logger& logger, PatchSteps& steps, size_t max_steps);

// Steps in a patch before pacing gives up: about 10 % of steps in grass
// start a battle at Route 4's rates.
constexpr size_t PACE_MAX_STEPS = 200;

// The console's PatchSteps: `pace` and back from `spot`, which each step
// updates.
// updates; a trainer is fought by `trainer_battle`.
class ConsolePatchSteps : public PatchSteps{
public:
ConsolePatchSteps(ConsoleHandle& console, ProControllerContext& context, Pokemon::Direction pace, PaceSpot& spot);
ConsolePatchSteps(
ConsoleHandle& console, ProControllerContext& context, Pokemon::Direction pace, PaceSpot& spot,
const PaceTrainerBattle& trainer_battle
);

virtual bool step() override;
virtual bool battle_shows() override;
virtual bool overworld_shows() override;
virtual bool message_shows() override;
virtual std::string fight_trainer() override;
virtual void dump_screen(std::string_view label) override;

private:
ConsoleHandle& m_console;
ProControllerContext& m_context;
Pokemon::Direction m_pace;
PaceSpot& m_spot;
const PaceTrainerBattle& m_trainer_battle;
};


// The console's capture steps. Encounters are found as the overworld
// shiny hunt finds them, a shiny heard as the shiny hunts hear it
// (handle_encounter()), and runs as they run (flee_battle()). The wild
// Pokemon's HP bar has no reader yet, so it reads UNKNOWN and nothing is
// weakened on the console.
// weakened on the console. A trainer who sees the player while pacing is
// fought by `trainer_battle`.
class ConsoleCaptureActions : public CaptureActions{
public:
ConsoleCaptureActions(ConsoleHandle& console, ProControllerContext& context, Language language);
ConsoleCaptureActions(
ConsoleHandle& console, ProControllerContext& context, Language language,
PaceTrainerBattle trainer_battle
);

virtual bool find_encounter(Pokemon::Direction pace) override;
virtual EncounterSeen read_encounter() override;
Expand All @@ -137,6 +158,7 @@ class ConsoleCaptureActions : public CaptureActions{
ConsoleHandle& m_console;
ProControllerContext& m_context;
Language m_language;
PaceTrainerBattle m_trainer_battle;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ struct FakePatch : public PatchSteps{
virtual bool overworld_shows() override{
return !battle_started() && overworld;
}
virtual bool message_shows() override{
return false;
}
virtual std::string fight_trainer() override{
return "";
}
virtual void dump_screen(std::string_view label) override{
dumps.emplace_back(label);
}
Expand Down
Loading
Loading