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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
namespace PokemonBDSP{


TalkOverEnd talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec){

Check warning on line 20 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::talk_over( VideoStream & stream , ProControllerContext & context , const std :: string & label , const TalkOverSpec & spec): function_lines=39 (advisory above 25, limit 50)
const WallClock deadline = current_time() + TALK_OVER_LIMIT;
TalkOver judge(spec.rule);
BdspScreenObserver eyes(spec.watch == TalkOverWatch::TRAINER ? BattleCue::TRAINER : BattleCue::WILD_MENU, spec.banner);
bool saw_dialogue = false;
while (current_time() < deadline){
context.wait_for_all_requests();
const WallClock now = current_time();
switch (judge.look(eyes.observe(stream.video().snapshot(), now), now)){
case SceneMove::DONE:
stream.log(std::format("[Talk-over] {}: over; {}.", label, judge.describe()));
return TalkOverEnd::QUIET;
return saw_dialogue ? TalkOverEnd::DIALOGUE : TalkOverEnd::QUIET;
case SceneMove::BATTLE:
if (spec.watch == TalkOverWatch::TRAINER){
stream.log("[Talk-over] " + label + ": a battle started.");
Expand All @@ -37,6 +38,7 @@
run_from_wild_battle(stream, context);
continue;
case SceneMove::NEXT:
saw_dialogue = true;
pbf_press_button(context, spec.next, TALK_OVER_HOLD, talk_over_release(spec.rule));
continue;
case SceneMove::B:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ struct TalkOverSpec{

// How talk_over() ended.
enum class TalkOverEnd{
QUIET,
QUIET, // Quiet without observing dialogue.
DIALOGUE, // Quiet after pressing through dialogue.
BATTLE, // Only with TalkOverWatch::TRAINER.
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool talk_or_fight(VideoStream& stream, ProControllerContext& context, const std
.rule = {.end_on_quiet = expect != TalkExpect::BATTLE},
.watch = TalkOverWatch::TRAINER,
});
if (end == TalkOverEnd::QUIET){
if (end != TalkOverEnd::BATTLE){
route_status(stream, label + " only talked.");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP Recovery Walk Tests

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RecoveryWalk_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=938 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -97,7 +97,7 @@
virtual bool run_until_map(Direction, Milliseconds, const std::string&, const std::string&) override{ throw GridSimFailure{"unexpected banner walk"}; }
virtual WarpSeen run_into_door(Direction, bool, Milliseconds = Milliseconds(12000), Milliseconds = Milliseconds(0), const std::string& = "") override{ throw GridSimFailure{"unexpected door"}; }
virtual std::optional<size_t> tap_to_banner(Direction, const std::string&, size_t) override{ throw GridSimFailure{"unexpected banner"}; }
virtual void settle(Button, const std::string&, SettleKind, const std::string&) override{ throw GridSimFailure{"unexpected scene"}; }
virtual bool settle(Button, const std::string&, SettleKind, const std::string&) override{ throw GridSimFailure{"unexpected scene"}; }
private:
RouteIO& m_route;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ void StoryLogBackend::log(std::string_view line){

// The game first: the registry and the runner keep references to it.
struct StoryEngineSteps::Engine{
Engine(StoryWalkSteps& walks, const StoryBoundActions& bound, Pokemon::StoryBackend<GridPose>& backend)
: game(story_game(walks, bound))
Engine(StoryWalkSteps& walk_steps, const StoryBoundActions& bound, Pokemon::StoryBackend<GridPose>& backend)
: walks(walk_steps)
, game(story_game(walk_steps, bound))
, registry(game)
, runner(registry, backend)
{}

StoryWalkSteps& walks;
Pokemon::StoryGame<GridPose> game;
Pokemon::StoryActionRegistry<GridPose> registry;
Pokemon::StoryStepRunner<GridPose> runner;
Expand All @@ -207,6 +209,7 @@ StoryEngineSteps::StoryEngineSteps(StoryWalkSteps& walks, const StoryBoundAction
StoryEngineSteps::~StoryEngineSteps() = default;

Outcome StoryEngineSteps::act(const StoryStep& step, RunState& state){
m_engine->walks.begin_step(step);
return m_engine->runner.act(step, state);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ std::optional<size_t> ConsoleStoryStepIO::tap_to_banner(Direction direction, con
// beside the door and walked a whole route in the house. The far map's
// banner `banner`, if it has one, counts as the fade: a fade the run
// missed is over, but its banner comes after it (#268 slice 1).
void ConsoleStoryStepIO::settle(Button button, const std::string& label, SettleKind kind, const std::string& banner){
bool ConsoleStoryStepIO::settle(Button button, const std::string& label, SettleKind kind, const std::string& banner){
const TalkOverRule rule{.warp = kind == SettleKind::AFTER_WARP, .door = kind == SettleKind::DOOR};
talk_over(m_stream, m_context, label, {.next = button, .rule = rule, .banner = banner});
return talk_over(m_stream, m_context, label, {.next = button, .rule = rule, .banner = banner}) == TalkOverEnd::DIALOGUE;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class StoryStepIO{
// Presses through any text until the overworld ends as `kind` says;
// for SettleKind::AFTER_WARP, the warp is a fade or the banner `banner`
// ("" for a fade only). Fails otherwise.
virtual void settle(Button button, const std::string& label, SettleKind kind, const std::string& banner) = 0;
// Returns whether the settle observed and pressed through dialogue.
virtual bool settle(Button button, const std::string& label, SettleKind kind, const std::string& banner) = 0;
};


Expand All @@ -106,7 +107,7 @@ class ConsoleStoryStepIO : public StoryStepIO{
virtual WarpSeen run_into_door(Pokemon::Direction direction, bool run, Milliseconds timeout = Milliseconds(12000),
Milliseconds dark_from = Milliseconds(0), const std::string& banner = "") override;
virtual std::optional<size_t> tap_to_banner(Pokemon::Direction direction, const std::string& map, size_t max_taps) override;
virtual void settle(Button button, const std::string& label, SettleKind kind, const std::string& banner) override;
virtual bool settle(Button button, const std::string& label, SettleKind kind, const std::string& banner) override;


private:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP AutoStory - Story walk steps

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

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

namespace{

// How long a scene waits for its first line when the preceding step did not
// press through its dialogue.
constexpr Milliseconds SCENE_START_WAIT = 15000ms;

// "to_catch_grass" as "to catch grass", for the logs.
std::string label_of(const StoryStep& step){
std::string label = step.name;
Expand Down Expand Up @@ -172,7 +176,7 @@
return Pokemon::tile_pose(from.map, at, legs_list.back().direction);
}

void StoryWalkSteps::begin_attempt(const std::string& row, const std::vector<StoryStep>& steps){

Check warning on line 179 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::StoryWalkSteps::begin_attempt( const std :: string & row , const std :: vector<StoryStep> & steps): function_lines=30 (advisory above 25, limit 50)
m_row = row;
// A row starts from its save: after the shoes' row, the save has them.
m_can_run = row > std::string(RUNNING_SHOES_ROW);
Expand All @@ -180,6 +184,8 @@
m_warp = {};
m_scene_next.clear();
m_scene_open = false;
m_previous_settle_saw_dialogue = false;
m_scene_start_already_played = false;
// A route right before a scene, or before a plain step onto the scene's
// trigger (the decomp's tile, which the console may have elsewhere).
const auto onto_trigger = [](const StoryStep& step){
Expand All @@ -201,6 +207,11 @@
}
}

void StoryWalkSteps::begin_step(const StoryStep& step){
const bool previous_settle_saw_dialogue = std::exchange(m_previous_settle_saw_dialogue, false);
m_scene_start_already_played = step.kind == Pokemon::StoryStepKind::MASH && previous_settle_saw_dialogue;
}

void StoryWalkSteps::turn(Direction direction){
m_route.note(std::string("[Route] Turning ") + direction_name(direction) + ".", RouteNote::LOG);
m_route.press(route_turn_tap(direction));
Expand Down Expand Up @@ -353,7 +364,7 @@
// then goes nowhere (lab-B 2026-11-10, 00.04b's Center): settle, as
// after a door.
if (through_already(step)){
m_io.settle(BUTTON_B, label_of(step), SettleKind::DOOR, "");
m_previous_settle_saw_dialogue = m_io.settle(BUTTON_B, label_of(step), SettleKind::DOOR, "");
return Pokemon::outcome_ok();
}
const size_t limit = taps_to_banner(from, direction);
Expand All @@ -367,7 +378,7 @@
}else{
log(std::format("[{}] {}: through to {} after {} taps {}.", m_row, step.name, map, *taps, direction_name(direction)));
}
m_io.settle(BUTTON_B, label_of(step), SettleKind::DOOR, "");
m_previous_settle_saw_dialogue = m_io.settle(BUTTON_B, label_of(step), SettleKind::DOOR, "");
return Pokemon::outcome_ok();
}

Expand Down Expand Up @@ -645,7 +656,7 @@
return tap_legs(state.pose, step);
}

Outcome StoryWalkSteps::step(RunState& state, const StoryStep& step){

Check warning on line 659 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::StoryWalkSteps::step( RunState & state , const StoryStep & step): function_lines=43 (advisory above 25, limit 50)
const EventTrace trace(m_legs, m_row, step.name);
const Direction direction = story_arg<Direction>(step.args, "direction");
if (step.action == "to_banner"){
Expand All @@ -659,7 +670,7 @@
if (walk.wild_battles > 0){
return Pokemon::outcome_failed("interrupted_step", step.name);
}
m_io.settle(BUTTON_B, label_of(step), SettleKind::TALK, "");
m_previous_settle_saw_dialogue = m_io.settle(BUTTON_B, label_of(step), SettleKind::TALK, "");
return Pokemon::outcome_ok();
}
// A step through a door: walk (or run) on until the screen goes dark,
Expand All @@ -672,7 +683,7 @@
// slice 1); with neither yet, settle() waits for one.
if (step.pose_after && Pokemon::grid_pose_of(*step.pose_after).map != state.pose.map){
if (through_already(step)){
m_io.settle(BUTTON_B, label_of(step), SettleKind::TALK, "");
m_previous_settle_saw_dialogue = m_io.settle(BUTTON_B, label_of(step), SettleKind::TALK, "");
return Pokemon::outcome_ok();
}
const std::string banner = story_arrival_banner(state.pose.map, Pokemon::grid_pose_of(*step.pose_after).map);
Expand All @@ -681,7 +692,9 @@
log(std::format("[{}] {}: {} through the door (timeout {} ms, dark from {} ms): {}.", m_row, step.name,
direction_name(direction), door.timeout.count(), door.dark_from.count(), seen.any() ? describe(seen) : "nothing yet"));
seen = door_from_beside(step, seen, door.timeout, banner);
m_io.settle(BUTTON_B, label_of(step), seen.any() ? SettleKind::TALK : SettleKind::AFTER_WARP, banner);
m_previous_settle_saw_dialogue = m_io.settle(
BUTTON_B, label_of(step), seen.any() ? SettleKind::TALK : SettleKind::AFTER_WARP, banner
);
return Pokemon::outcome_ok();
}
return one_step(state, step);
Expand Down Expand Up @@ -730,12 +743,18 @@
Outcome StoryWalkSteps::mash(RunState& state, const StoryStep& step){
m_warp = {};
m_scene_open = false;
// The step before may have played the scene already (a door step settles
// its arrival scene), so its first line is not required.
if (!m_route.dialog_within(15000ms, COLOR_CYAN)){
m_route.note(label_of(step) + ": no line within 15 s; the step before played it.", RouteNote::WARNING);
}
m_io.settle(step.action == "a" ? BUTTON_A : BUTTON_B, label_of(step),
const bool already_played = std::exchange(m_scene_start_already_played, false);
if (already_played){
m_route.note(std::format(
"{}: dialogue was played by the previous step; skipping the opening-line wait.", label_of(step)
), RouteNote::STATUS);
}else if (!m_route.dialog_within(SCENE_START_WAIT, COLOR_CYAN)){
m_route.note(std::format(
"{}: no line within {} ms; the step before may already have played it.",
label_of(step), SCENE_START_WAIT.count()
), RouteNote::WARNING);
}
m_previous_settle_saw_dialogue = m_io.settle(step.action == "a" ? BUTTON_A : BUTTON_B, label_of(step),
step.pose_after && Pokemon::grid_pose_of(*step.pose_after).map != state.pose.map &&
story_plan_world(state.pose.map, Pokemon::grid_pose_of(*step.pose_after).map) == nullptr ? SettleKind::AFTER_WARP : SettleKind::TALK, "");
if (m_row == RUNNING_SHOES_ROW && step.name == RUNNING_SHOES_STEP){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class StoryWalkSteps{
Pokemon::Outcome mash(Pokemon::RunState& state, const Pokemon::StoryStep& step);

private:
friend class StoryEngineSteps;
// Starts one engine-dispatched step. Only an immediately following
// MASH may reuse dialogue observed by the preceding step's settle().
void begin_step(const Pokemon::StoryStep& step);
Pokemon::Pose walk_to(const Pokemon::Pose& from, const Pokemon::Pose& goal, const Pokemon::StoryStep& step);
// After a wild battle on `leg`'s taps from `starts`: walks to one of
// `goals` from wherever the leg could have left us, then faces `facing`.
Expand Down Expand Up @@ -141,6 +145,10 @@ class StoryWalkSteps{
// The last route ended in the scene of the step after it, or after the
// plain step onto its trigger (RouteEnd::scene); that step is not taken.
bool m_scene_open = false;
// The step just completed observed dialogue while settling.
bool m_previous_settle_saw_dialogue = false;
// The MASH now running immediately follows that settle.
bool m_scene_start_already_played = false;
};


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP AutoStory Grid Simulation Tests

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.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 @@ -448,10 +448,10 @@
unsupported("taps to " + map + "'s banner");
return std::nullopt;
}
virtual void settle(Button, const std::string& label, SettleKind, const std::string&) override{
virtual bool settle(Button, const std::string& label, SettleKind, const std::string&) override{
unsupported(label + "'s settle");
return false;
}

private:
void unsupported(const std::string& what){
m_route.note(what + " is not simulated here.", RouteNote::FAILURE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BDSP AutoStory - Console failure cases on the story simulation

Check warning on line 1 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=727 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -245,6 +245,23 @@
return passes(run_case(logger, "01.03", "01.03", {.fade = {}, .banner = {}}, {.first_line = {{talk, 7000ms}}}));
}

// A MASH scene whose preceding step did not observe dialogue keeps the
// original 15 s opening-line watch. Both delays are therefore handled by
// the real mash/settle path, rather than silently walking on mid-scene.
UnitTestResult mash_scene_speaks_late(Logger& logger){
const Milliseconds delays[] = {7000ms, 9000ms};
for (Milliseconds delay : delays){
SimWorldKnobs knobs;
knobs.first_line["barry_warns_us"] = delay;
knobs.scenes["barry_warns_us"] = {sim_line("Barry warns the player")};
const std::string stopped = run_case(logger, "00.01", "00.01", {.fade = {}, .banner = {}}, knobs);
if (!stopped.empty()){
return std::format("The scene with its first line at {} ms {}", delay.count(), stopped);
}
}
return true;
}

// `row` with everyone on its maps walking their wander boxes, seeds 1 to 8.
UnitTestResult wanderers_move(Logger& logger, const std::string& row){
std::vector<std::string> failed;
Expand Down Expand Up @@ -669,6 +686,7 @@
{.input = {"any one fade with its hold unseen from 00.00 to 01.11: every row still passes", every_single_hold_miss}, .expectation = {}},
{.input = {"01.02 to 01.05 at night, the Gate's dim floor", night_and_dim_floors}, .expectation = {}},
{.input = {"01.03 Roark's first line 7 s after the A press", roark_speaks_late}, .expectation = {}},
{.input = {"00.01 MASH first lines at 7 s and 9 s", mash_scene_speaks_late}, .expectation = {}},
{.input = {"01.03 with Oreburgh's people wandering (the pokefan on 45, 37..39)", [](Logger& logger){
return wanderers_move(logger, "01.03");
}}, .expectation = {}},
Expand Down
Loading
Loading