From 57acd6e6fd0d6a4191ddbc4640204f658eea2463 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 17:58:49 -0800 Subject: [PATCH 1/7] Test scene start waits across BDSP AutoStory --- ...kemonBDSP_AutoStory_StoryActions_Tests.cpp | 32 +++++++++++++++++++ .../PokemonBDSP_AutoStory_StorySim.cpp | 1 + .../PokemonBDSP_AutoStory_StorySim.h | 1 + 3 files changed, 34 insertions(+) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp index 95bc677c9a..4c62c345c0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp @@ -212,6 +212,34 @@ UnitTestResult test_stubbed_steps_need_the_console(Logger& logger){ return true; } +// Console B, 2026-11-15: three 00.01 scenes each waited the full 15 s +// after the preceding step had already played them. Audit every authored +// scene through the real StoryWalkSteps::mash() seam. +UnitTestResult test_scene_start_waits(Logger& logger){ + SimExecutor sim(logger); + run_rows_on(sim, logger, {.from = "00.00", .to = "01.11"}); + if (!sim.result().error.empty()){ + return "The run failed: " + sim.result().error; + } + size_t scenes = 0; + for (const auto& [row, step] : story_steps()){ + if (step.kind != StoryStepKind::MASH){ + continue; + } + const auto found = sim.misses().dialog_waits.find(step.name); + if (found == sim.misses().dialog_waits.end()){ + return std::format("{} {} did not check for its opening line.", row, step.name); + } + if (found->second > Milliseconds(3000)){ + return std::format("{} {} waits {} ms for an optional opening line; expected at most 3000 ms.", + row, step.name, found->second.count()); + } + scenes++; + } + logger.log(std::format("{} scene steps use the bounded optional-line pre-watch.", scenes)); + return true; +} + struct AutoStoryStoryActionsInput{ @@ -261,6 +289,10 @@ const AutoStoryStoryActionsCase AUTO_STORY_STORY_ACTIONS_CASES[] = { .input = {"Story actions: the steps the sim stubs from 00.00 to 01.11 all need the console", test_stubbed_steps_need_the_console}, .expectation = {}, }, + { + .input = {"Story actions: scene starts do not wait 15 seconds for an optional line", test_scene_start_waits}, + .expectation = {}, + }, }; void add_tests_AutoStory_StoryActions(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index ad14cd0c69..332068a96a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -357,6 +357,7 @@ WalkResult SimKnobRouteIO::slide_on(const SimSlide& slide, WalkResult result){ } bool SimKnobRouteIO::dialog_within(Milliseconds wait, Color color){ + m_misses.dialog_waits[m_step] = wait; const auto late = m_knobs.first_line.find(m_step); if (late != m_knobs.first_line.end() && late->second > wait){ note(std::format("[Sim] {}: the first line comes after {} ms, past the {} ms wait.", m_step, late->second.count(), wait.count()), RouteNote::LOG); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h index d1e5427a4b..04aeb553da 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -81,6 +81,7 @@ struct SimMisses{ bool fading_in = false; bool slid = false; std::string banner_up = {}; + std::map dialog_waits = {}; }; // How a warp's fade looks on the screen (#268's design note); the From deeba2b879ec016a2776361822f3eee7b97b9dad Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 22:40:09 -0800 Subject: [PATCH 2/7] BDSP AutoStory: shorten optional scene pre-watch --- .../PokemonBDSP_AutoStory_StoryWalkSteps.cpp | 12 ++++++++++-- .../PokemonBDSP_AutoStory_StoryActions_Tests.cpp | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp index 8472b10b0c..0812f84564 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp @@ -87,6 +87,11 @@ std::vector traced_tiles(const std::string& map, const std:: namespace{ +// This only watches for an optional first line. settle() then uses +// talk_over(), whose 5 s quiet threshold still gives a delayed scene 8 s +// from the start of this watch to appear before it can be judged over. +constexpr Milliseconds SCENE_START_WAIT = 3000ms; + // "to_catch_grass" as "to catch grass", for the logs. std::string label_of(const StoryStep& step){ std::string label = step.name; @@ -732,8 +737,11 @@ Outcome StoryWalkSteps::mash(RunState& state, const StoryStep& step){ 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); + 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_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 && diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp index 4c62c345c0..d9a0ea2c74 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp @@ -219,7 +219,7 @@ UnitTestResult test_scene_start_waits(Logger& logger){ SimExecutor sim(logger); run_rows_on(sim, logger, {.from = "00.00", .to = "01.11"}); if (!sim.result().error.empty()){ - return "The run failed: " + sim.result().error; + return std::format("The run failed: {}", sim.result().error); } size_t scenes = 0; for (const auto& [row, step] : story_steps()){ From 2edb8e33633ea657fb73f4c3ce38bc691f868f1d Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 12:17:29 -0800 Subject: [PATCH 3/7] Preserve late-scene guard while skipping played scenes --- .../PokemonBDSP_AutoStory_TalkOver.cpp | 8 ++- .../Actions/PokemonBDSP_AutoStory_TalkOver.h | 7 ++- .../Actions/PokemonBDSP_AutoStory_Talks.cpp | 4 +- ...kemonBDSP_AutoStory_RecoveryWalk_Tests.cpp | 2 +- .../PokemonBDSP_AutoStory_StoryStepIO.cpp | 4 +- .../PokemonBDSP_AutoStory_StoryStepIO.h | 5 +- .../PokemonBDSP_AutoStory_StoryWalkSteps.cpp | 32 ++++++---- .../PokemonBDSP_AutoStory_StoryWalkSteps.h | 3 + .../PokemonBDSP_AutoStory_GridSim_Tests.cpp | 3 +- ...onBDSP_AutoStory_SimFailureCases_Tests.cpp | 18 ++++++ ...kemonBDSP_AutoStory_StoryActions_Tests.cpp | 61 +++++++++++++++---- .../PokemonBDSP_AutoStory_StorySim.cpp | 13 +++- .../PokemonBDSP_AutoStory_StorySim.h | 2 +- ...emonBDSP_AutoStory_WallBattleSim_Tests.cpp | 3 +- 14 files changed, 122 insertions(+), 43 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp index 9871501ec0..e5164728c4 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp @@ -17,26 +17,28 @@ namespace NintendoSwitch{ namespace PokemonBDSP{ -TalkOverEnd talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec){ +TalkOverResult talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec){ 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 {TalkOverEnd::QUIET, saw_dialogue}; case SceneMove::BATTLE: if (spec.watch == TalkOverWatch::TRAINER){ stream.log("[Talk-over] " + label + ": a battle started."); - return TalkOverEnd::BATTLE; + return {TalkOverEnd::BATTLE, saw_dialogue}; } stream.log("[Talk-over] " + label + ": in a wild battle; fleeing."); 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: diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h index 9469c3954c..ef590dc74c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h @@ -77,9 +77,14 @@ enum class TalkOverEnd{ BATTLE, // Only with TalkOverWatch::TRAINER. }; +struct TalkOverResult{ + TalkOverEnd end; + bool saw_dialogue; +}; + // Presses through any text and scene on the console until TalkOver says it // is over. Fails with a screenshot after TALK_OVER_LIMIT. -TalkOverEnd talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec = {}); +TalkOverResult talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec = {}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp index 84dda41bbf..e838f3d47c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp @@ -56,11 +56,11 @@ bool dialogue_opens(VideoStream& stream, ProControllerContext& context, Millisec } bool talk_or_fight(VideoStream& stream, ProControllerContext& context, const std::string& label, TalkExpect expect, BattleFormat format){ - const TalkOverEnd end = talk_over(stream, context, label, { + const TalkOverResult result = talk_over(stream, context, label, { .rule = {.end_on_quiet = expect != TalkExpect::BATTLE}, .watch = TalkOverWatch::TRAINER, }); - if (end == TalkOverEnd::QUIET){ + if (result.end == TalkOverEnd::QUIET){ route_status(stream, label + " only talked."); return false; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RecoveryWalk_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RecoveryWalk_Tests.cpp index 3f8104aae0..e9f707f194 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RecoveryWalk_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RecoveryWalk_Tests.cpp @@ -97,7 +97,7 @@ class RecoveryStepIO : public StoryStepIO{ 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 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; }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp index 300ebdbf54..29f50759e0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp @@ -309,9 +309,9 @@ std::optional 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}).saw_dialogue; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.h index 3db291d727..d9377436cb 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.h @@ -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; }; @@ -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 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: diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp index 0812f84564..1aba776f66 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp @@ -87,10 +87,8 @@ std::vector traced_tiles(const std::string& map, const std:: namespace{ -// This only watches for an optional first line. settle() then uses -// talk_over(), whose 5 s quiet threshold still gives a delayed scene 8 s -// from the start of this watch to appear before it can be judged over. -constexpr Milliseconds SCENE_START_WAIT = 3000ms; +// A scene not observed by the previous step keeps the original full guard. +constexpr Milliseconds SCENE_START_WAIT = 15000ms; // "to_catch_grass" as "to catch grass", for the logs. std::string label_of(const StoryStep& step){ @@ -185,6 +183,7 @@ void StoryWalkSteps::begin_attempt(const std::string& row, const std::vector(step.args, "direction"); + m_previous_settle_saw_dialogue = false; if (step.action == "to_banner"){ turn(direction); return tap_to_banner(state.pose, step); @@ -664,7 +666,7 @@ Outcome StoryWalkSteps::step(RunState& state, const StoryStep& step){ 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, @@ -677,7 +679,7 @@ Outcome StoryWalkSteps::step(RunState& state, const StoryStep& step){ // 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); @@ -686,7 +688,9 @@ Outcome StoryWalkSteps::step(RunState& state, const StoryStep& step){ 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); @@ -717,6 +721,7 @@ Outcome StoryWalkSteps::one_step(const RunState& state, const StoryStep& step){ Outcome StoryWalkSteps::talk(RunState& state, const StoryStep& step){ m_warp = {}; m_scene_open = false; + m_previous_settle_saw_dialogue = false; // Face whom we talk to: a route ends facing its last leg, not its goal // (r40 reached Mom facing north). They block the tile, so the tap only turns. if (const std::optional facing = Pokemon::facing_of(state.pose)){ @@ -735,15 +740,16 @@ Outcome StoryWalkSteps::talk(RunState& state, const StoryStep& step){ 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(SCENE_START_WAIT, COLOR_CYAN)){ + const bool already_played = std::exchange(m_previous_settle_saw_dialogue, false); + if (already_played){ + m_route.note(label_of(step) + ": dialogue was played by the previous step; skipping the opening-line wait.", 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_io.settle(step.action == "a" ? BUTTON_A : BUTTON_B, label_of(step), + 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){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h index 9f52467e64..96ae790cd0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h @@ -141,6 +141,9 @@ 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 before observed dialogue while settling. A following scene + // need not wait for an opening line that talk_over() already played. + bool m_previous_settle_saw_dialogue = false; }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp index 48ed98935e..0095b1c3ed 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp @@ -448,8 +448,9 @@ class WalkStepsIO : public StoryStepIO{ 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: diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp index 131924750b..4482ec365f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp @@ -245,6 +245,23 @@ UnitTestResult roark_speaks_late(Logger& logger){ 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 failed; @@ -669,6 +686,7 @@ const FailureCase AUTO_STORY_FAILURE_CASES[] = { {.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 = {}}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp index d9a0ea2c74..f7cb19fab8 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include "Common/Cpp/CancellableScope.h" @@ -212,31 +213,61 @@ UnitTestResult test_stubbed_steps_need_the_console(Logger& logger){ return true; } -// Console B, 2026-11-15: three 00.01 scenes each waited the full 15 s -// after the preceding step had already played them. Audit every authored -// scene through the real StoryWalkSteps::mash() seam. +// Every authored scene keeps the full opening-line guard unless the +// preceding settle actually observed dialogue. UnitTestResult test_scene_start_waits(Logger& logger){ + constexpr std::string_view LAST_ROW = "01.11"; + constexpr size_t EXPECTED_SCENES = 23; SimExecutor sim(logger); - run_rows_on(sim, logger, {.from = "00.00", .to = "01.11"}); + run_rows_on(sim, logger, {.from = "00.00", .to = std::string(LAST_ROW)}); if (!sim.result().error.empty()){ return std::format("The run failed: {}", sim.result().error); } size_t scenes = 0; + size_t guarded = 0; for (const auto& [row, step] : story_steps()){ - if (step.kind != StoryStepKind::MASH){ + if (row > LAST_ROW || step.kind != StoryStepKind::MASH){ continue; } const auto found = sim.misses().dialog_waits.find(step.name); - if (found == sim.misses().dialog_waits.end()){ - return std::format("{} {} did not check for its opening line.", row, step.name); - } - if (found->second > Milliseconds(3000)){ - return std::format("{} {} waits {} ms for an optional opening line; expected at most 3000 ms.", - row, step.name, found->second.count()); + if (found != sim.misses().dialog_waits.end()){ + if (found->second != Milliseconds(15000)){ + return std::format("{} {} waits {} ms for its opening line; expected the full 15000 ms guard.", + row, step.name, found->second.count()); + } + guarded++; } scenes++; } - logger.log(std::format("{} scene steps use the bounded optional-line pre-watch.", scenes)); + if (scenes != EXPECTED_SCENES){ + return std::format("Audited {} scene steps through {}; expected {}.", scenes, LAST_ROW, EXPECTED_SCENES); + } + logger.log(std::format("{} scene steps audited through {}; {} used the full opening-line guard.", scenes, LAST_ROW, guarded)); + return true; +} + +// Console B, 2026-11-15: these arrival scenes had already been played by +// the preceding settle, so their separate 15 s waits did no work. +UnitTestResult test_seen_scene_skips_start_wait(Logger& logger){ + SimWorldKnobs knobs; + knobs.scenes["down_the_stairs"] = {sim_line("Mom calls the player")}; + knobs.scenes["barry_bursts_out"] = {sim_line("Barry goes home")}; + knobs.scenes["up_barrys_stairs"] = {sim_line("Barry runs to the lake")}; + SimExecutor sim(logger, {}, knobs); + run_rows_on(sim, logger, {.from = "00.01", .to = "00.01"}); + if (!sim.result().error.empty()){ + return std::format("The run failed: {}", sim.result().error); + } + const std::pair expected_skips[] = { + {"down_the_stairs", "mom_calls"}, + {"barry_bursts_out", "barry_goes_home"}, + {"up_barrys_stairs", "barry_runs_to_the_lake"}, + }; + for (const auto& [previous, scene] : expected_skips){ + if (sim.misses().dialog_waits.contains(std::string(scene))){ + return std::format("{} repeated an opening-line wait after {} already observed dialogue.", scene, previous); + } + } return true; } @@ -290,7 +321,11 @@ const AutoStoryStoryActionsCase AUTO_STORY_STORY_ACTIONS_CASES[] = { .expectation = {}, }, { - .input = {"Story actions: scene starts do not wait 15 seconds for an optional line", test_scene_start_waits}, + .input = {"Story actions: scene starts retain the full guard until dialogue is observed", test_scene_start_waits}, + .expectation = {}, + }, + { + .input = {"Story actions: a scene played by the preceding settle skips its start wait", test_seen_scene_skips_start_wait}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index 332068a96a..44cad91b79 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -137,18 +137,20 @@ std::string play_scene(const SimScene& scene, const TalkOverRule& rule){ // Plays the step's scene knob through TalkOver if it has one. Without, a // scene may take us to another map (Mom walks us out, 00.04): with a // dialogue open the stub scene plays it. Otherwise only a door fades. -void SimStoryStepIO::settle(Button, const std::string& label, SettleKind kind, const std::string&){ +bool SimStoryStepIO::settle(Button, const std::string& label, SettleKind kind, const std::string&){ const bool fade = kind == SettleKind::AFTER_WARP; m_misses.fading_in = false; + bool saw_dialogue = m_sim.player().dialog; const auto scene = m_knobs.scenes.find(m_step); if (scene != m_knobs.scenes.end()){ m_misses.fade_unseen = false; m_sim.end_dialogue(); + saw_dialogue |= std::ranges::any_of(scene->second, [](const SimBeat& beat){ return beat.line; }); const std::string early = play_scene(scene->second, {.warp = fade, .door = kind == SettleKind::DOOR}); if (!early.empty()){ m_route.note(label + ": talk-over " + early + ".", RouteNote::FAILURE); } - return; + return saw_dialogue; } const bool scene_fades = m_sim.player().dialog && m_far_side(); if (fade && ((!m_sim.player().warped && !scene_fades) || m_misses.fade_unseen)){ @@ -156,6 +158,7 @@ void SimStoryStepIO::settle(Button, const std::string& label, SettleKind kind, c } m_misses.fade_unseen = false; m_sim.end_dialogue(); + return saw_dialogue; } SimStoryStepIO::FadeShown SimStoryStepIO::next_fade(){ @@ -357,12 +360,16 @@ WalkResult SimKnobRouteIO::slide_on(const SimSlide& slide, WalkResult result){ } bool SimKnobRouteIO::dialog_within(Milliseconds wait, Color color){ - m_misses.dialog_waits[m_step] = wait; + Milliseconds& longest = m_misses.dialog_waits[m_step]; + longest = std::max(longest, wait); const auto late = m_knobs.first_line.find(m_step); if (late != m_knobs.first_line.end() && late->second > wait){ note(std::format("[Sim] {}: the first line comes after {} ms, past the {} ms wait.", m_step, late->second.count(), wait.count()), RouteNote::LOG); return false; } + if (late != m_knobs.first_line.end()){ + return true; + } return GridSimRouteIO::dialog_within(wait, color); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h index 04aeb553da..5a4ee21013 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -360,7 +360,7 @@ class SimStoryStepIO : public StoryStepIO{ // run before looked for the banner (run_into_door()), so settle() sees // none here. With a scene in SimWorldKnobs::scenes, the program's // TalkOver plays it instead. - virtual void settle(Button, const std::string& label, SettleKind kind, const std::string&) override; + virtual bool settle(Button, const std::string& label, SettleKind kind, const std::string&) override; virtual std::optional tap_to_banner(Pokemon::Direction direction, const std::string& map, size_t max_taps) override; private: diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.cpp index a5ae179f82..03540e9589 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.cpp @@ -177,8 +177,9 @@ class RouteOnlyStepIO : public StoryStepIO{ 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: From 68d3f7b180d54bc6c471862e39ecd874b3223cfa Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 12:19:04 -0800 Subject: [PATCH 4/7] Fit scene wait review changes within health limits --- .../Actions/PokemonBDSP_AutoStory_TalkOver.cpp | 6 +++--- .../AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h | 10 +++------- .../AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp | 4 ++-- .../AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp | 2 +- .../Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp | 5 +---- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp index e5164728c4..721d967c35 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.cpp @@ -17,7 +17,7 @@ namespace NintendoSwitch{ namespace PokemonBDSP{ -TalkOverResult talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec){ +TalkOverEnd talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec){ 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); @@ -28,11 +28,11 @@ TalkOverResult talk_over(VideoStream& stream, ProControllerContext& context, con 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, saw_dialogue}; + return saw_dialogue ? TalkOverEnd::DIALOGUE : TalkOverEnd::QUIET; case SceneMove::BATTLE: if (spec.watch == TalkOverWatch::TRAINER){ stream.log("[Talk-over] " + label + ": a battle started."); - return {TalkOverEnd::BATTLE, saw_dialogue}; + return TalkOverEnd::BATTLE; } stream.log("[Talk-over] " + label + ": in a wild battle; fleeing."); run_from_wild_battle(stream, context); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h index ef590dc74c..96a3e80c70 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h @@ -73,18 +73,14 @@ 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. }; -struct TalkOverResult{ - TalkOverEnd end; - bool saw_dialogue; -}; - // Presses through any text and scene on the console until TalkOver says it // is over. Fails with a screenshot after TALK_OVER_LIMIT. -TalkOverResult talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec = {}); +TalkOverEnd talk_over(VideoStream& stream, ProControllerContext& context, const std::string& label, const TalkOverSpec& spec = {}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp index e838f3d47c..87ca9f1146 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp @@ -56,11 +56,11 @@ bool dialogue_opens(VideoStream& stream, ProControllerContext& context, Millisec } bool talk_or_fight(VideoStream& stream, ProControllerContext& context, const std::string& label, TalkExpect expect, BattleFormat format){ - const TalkOverResult result = talk_over(stream, context, label, { + const TalkOverEnd end = talk_over(stream, context, label, { .rule = {.end_on_quiet = expect != TalkExpect::BATTLE}, .watch = TalkOverWatch::TRAINER, }); - if (result.end == TalkOverEnd::QUIET){ + if (end != TalkOverEnd::BATTLE){ route_status(stream, label + " only talked."); return false; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp index 29f50759e0..540b24023f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp @@ -311,7 +311,7 @@ std::optional ConsoleStoryStepIO::tap_to_banner(Direction direction, con // missed is over, but its banner comes after it (#268 slice 1). 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}; - return talk_over(m_stream, m_context, label, {.next = button, .rule = rule, .banner = banner}).saw_dialogue; + return talk_over(m_stream, m_context, label, {.next = button, .rule = rule, .banner = banner}) == TalkOverEnd::DIALOGUE; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp index 0095b1c3ed..8427975580 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp @@ -448,10 +448,7 @@ class WalkStepsIO : public StoryStepIO{ unsupported("taps to " + map + "'s banner"); return std::nullopt; } - virtual bool settle(Button, const std::string& label, SettleKind, const std::string&) override{ - unsupported(label + "'s settle"); - return false; - } + 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){ From 3a7f06ebc09910e7fce42b38809d53a8c7d8a03d Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 13:57:46 -0800 Subject: [PATCH 5/7] Pin scene waits to the immediately preceding settle --- .../PokemonBDSP_AutoStory_StoryActions.cpp | 7 +- .../PokemonBDSP_AutoStory_StoryWalkSteps.cpp | 19 ++++-- .../PokemonBDSP_AutoStory_StoryWalkSteps.h | 9 ++- .../PokemonBDSP_AutoStory_GridSim_Tests.cpp | 6 +- ...kemonBDSP_AutoStory_StoryActions_Tests.cpp | 68 ++++++++++++++++++- .../PokemonBDSP_AutoStory_StorySim.cpp | 19 ++++-- .../PokemonBDSP_AutoStory_StorySim.h | 7 +- 7 files changed, 114 insertions(+), 21 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryActions.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryActions.cpp index 6e8da5bcb9..66fd17b61f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryActions.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryActions.cpp @@ -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& backend) - : game(story_game(walks, bound)) + Engine(StoryWalkSteps& walk_steps, const StoryBoundActions& bound, Pokemon::StoryBackend& backend) + : walks(walk_steps) + , game(story_game(walk_steps, bound)) , registry(game) , runner(registry, backend) {} + StoryWalkSteps& walks; Pokemon::StoryGame game; Pokemon::StoryActionRegistry registry; Pokemon::StoryStepRunner runner; @@ -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); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp index 1aba776f66..cb7d2de2f1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp @@ -87,7 +87,8 @@ std::vector traced_tiles(const std::string& map, const std:: namespace{ -// A scene not observed by the previous step keeps the original full guard. +// 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. @@ -184,6 +185,7 @@ void StoryWalkSteps::begin_attempt(const std::string& row, const std::vector(step.args, "direction"); - m_previous_settle_saw_dialogue = false; if (step.action == "to_banner"){ turn(direction); return tap_to_banner(state.pose, step); @@ -721,7 +725,6 @@ Outcome StoryWalkSteps::one_step(const RunState& state, const StoryStep& step){ Outcome StoryWalkSteps::talk(RunState& state, const StoryStep& step){ m_warp = {}; m_scene_open = false; - m_previous_settle_saw_dialogue = false; // Face whom we talk to: a route ends facing its last leg, not its goal // (r40 reached Mom facing north). They block the tile, so the tap only turns. if (const std::optional facing = Pokemon::facing_of(state.pose)){ @@ -740,9 +743,11 @@ Outcome StoryWalkSteps::talk(RunState& state, const StoryStep& step){ Outcome StoryWalkSteps::mash(RunState& state, const StoryStep& step){ m_warp = {}; m_scene_open = false; - const bool already_played = std::exchange(m_previous_settle_saw_dialogue, false); + const bool already_played = std::exchange(m_scene_start_already_played, false); if (already_played){ - m_route.note(label_of(step) + ": dialogue was played by the previous step; skipping the opening-line wait.", RouteNote::STATUS); + 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.", diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h index 96ae790cd0..45ed00b65b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h @@ -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`. @@ -141,9 +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 before observed dialogue while settling. A following scene - // need not wait for an opening line that talk_over() already played. + // 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; }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp index 8427975580..897c53de42 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.cpp @@ -448,8 +448,10 @@ class WalkStepsIO : public StoryStepIO{ unsupported("taps to " + map + "'s banner"); return std::nullopt; } - virtual bool settle(Button, const std::string& label, SettleKind, const std::string&) override{ unsupported(label + "'s settle"); return false; } - + 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); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp index f7cb19fab8..194a7f2bd0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp @@ -218,6 +218,11 @@ UnitTestResult test_stubbed_steps_need_the_console(Logger& logger){ UnitTestResult test_scene_start_waits(Logger& logger){ constexpr std::string_view LAST_ROW = "01.11"; constexpr size_t EXPECTED_SCENES = 23; + const std::set expected_skips{ + "mom_calls", + "barry_goes_home", + "barry_runs_to_the_lake", + }; SimExecutor sim(logger); run_rows_on(sim, logger, {.from = "00.00", .to = std::string(LAST_ROW)}); if (!sim.result().error.empty()){ @@ -230,7 +235,16 @@ UnitTestResult test_scene_start_waits(Logger& logger){ continue; } const auto found = sim.misses().dialog_waits.find(step.name); - if (found != sim.misses().dialog_waits.end()){ + const bool should_skip = expected_skips.contains(step.name); + if (found == sim.misses().dialog_waits.end()){ + if (!should_skip){ + return std::format("{} {} skipped its opening-line guard without preceding dialogue.", row, step.name); + } + }else{ + if (should_skip){ + return std::format("{} {} repeated an opening-line guard after preceding dialogue.", row, step.name); + } + // Mirrors SCENE_START_WAIT in StoryWalkSteps.cpp. if (found->second != Milliseconds(15000)){ return std::format("{} {} waits {} ms for its opening line; expected the full 15000 ms guard.", row, step.name, found->second.count()); @@ -242,6 +256,9 @@ UnitTestResult test_scene_start_waits(Logger& logger){ if (scenes != EXPECTED_SCENES){ return std::format("Audited {} scene steps through {}; expected {}.", scenes, LAST_ROW, EXPECTED_SCENES); } + if (guarded != scenes - expected_skips.size()){ + return std::format("{} of {} scenes kept the guard; expected {}.", guarded, scenes, scenes - expected_skips.size()); + } logger.log(std::format("{} scene steps audited through {}; {} used the full opening-line guard.", scenes, LAST_ROW, guarded)); return true; } @@ -253,7 +270,7 @@ UnitTestResult test_seen_scene_skips_start_wait(Logger& logger){ knobs.scenes["down_the_stairs"] = {sim_line("Mom calls the player")}; knobs.scenes["barry_bursts_out"] = {sim_line("Barry goes home")}; knobs.scenes["up_barrys_stairs"] = {sim_line("Barry runs to the lake")}; - SimExecutor sim(logger, {}, knobs); + SimExecutor sim(logger, /*misses=*/{}, knobs); run_rows_on(sim, logger, {.from = "00.01", .to = "00.01"}); if (!sim.result().error.empty()){ return std::format("The run failed: {}", sim.result().error); @@ -271,6 +288,49 @@ UnitTestResult test_seen_scene_skips_start_wait(Logger& logger){ return true; } +// Dialogue seen before an intervening TALK or BATTLE belongs to the step +// before that action, not to the following scene. +UnitTestResult test_intervening_step_keeps_start_wait(Logger& logger){ + const StoryStepKind intervening_kinds[] = {StoryStepKind::TALK, StoryStepKind::BATTLE}; + for (StoryStepKind kind : intervening_kinds){ + GridSim grid( + {.world = story_plan_world("TwinleafTown", "TwinleafTown")}, + /*start=*/{0, 0}, Pokemon::Direction::NORTH, /*can_run=*/false + ); + std::vector notes; + SimMisses misses; + const std::string io_step = "scene"; + SimWorldKnobs knobs; + knobs.first_line[io_step] = Milliseconds(0); + knobs.scenes[io_step] = {sim_line("the scene's line")}; + SimStoryStepIO io(grid, notes, misses, knobs, io_step, []{ return false; }, [](const Pokemon::Pose&){}); + StoryWalkSteps walks(io); + CancellableHolder scope; + StoryLogBackend backend(Pokemon::StoryBackendKind::SCRIPT, /*log=*/{}, scope); + StoryBoundActions actions = naming_actions(); + actions.battle = [](const StoryStep&, RunState&){ return Pokemon::outcome_ok(); }; + StoryEngineSteps engine(walks, actions, backend); + RunState state; + + StoryStep preceding{.kind = StoryStepKind::MASH, .name = "preceding_scene"}; + engine.act(preceding, state); + misses.dialog_waits.clear(); + StoryStep intervening{.kind = kind, .name = "intervening_step"}; + engine.act(intervening, state); + misses.dialog_waits.clear(); + StoryStep following{.kind = StoryStepKind::MASH, .name = "following_scene"}; + engine.act(following, state); + + const auto found = misses.dialog_waits.find(io_step); + if (found == misses.dialog_waits.end() || found->second != Milliseconds(15000)){ + return std::format("A scene after {} did not keep its full opening-line guard.", + Pokemon::story_step_kind_name(kind)); + } + } + logger.log("Scenes after TALK and BATTLE keep their full opening-line guard."); + return true; +} + struct AutoStoryStoryActionsInput{ @@ -328,6 +388,10 @@ const AutoStoryStoryActionsCase AUTO_STORY_STORY_ACTIONS_CASES[] = { .input = {"Story actions: a scene played by the preceding settle skips its start wait", test_seen_scene_skips_start_wait}, .expectation = {}, }, + { + .input = {"Story actions: an intervening step invalidates a prior settle's dialogue", test_intervening_step_keeps_start_wait}, + .expectation = {}, + }, }; void add_tests_AutoStory_StoryActions(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index 44cad91b79..edafd70b5f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -134,19 +134,24 @@ std::string play_scene(const SimScene& scene, const TalkOverRule& rule){ } } // namespace detail -// Plays the step's scene knob through TalkOver if it has one. Without, a -// scene may take us to another map (Mom walks us out, 00.04): with a -// dialogue open the stub scene plays it. Otherwise only a door fades. +// Settles the simulated screen through the same TalkOver rules as the +// console. A scene knob supplies its beats; otherwise a dialogue may take +// us to another map (Mom walks us out, 00.04), or only a door fades. bool SimStoryStepIO::settle(Button, const std::string& label, SettleKind kind, const std::string&){ const bool fade = kind == SettleKind::AFTER_WARP; m_misses.fading_in = false; bool saw_dialogue = m_sim.player().dialog; + const Milliseconds uncovered = m_route.take_uncovered_first_line(); const auto scene = m_knobs.scenes.find(m_step); if (scene != m_knobs.scenes.end()){ + SimScene beats = scene->second; + if (uncovered > Milliseconds(0)){ + beats.insert(beats.begin(), sim_pause("the first line is still approaching", uncovered, true)); + } m_misses.fade_unseen = false; m_sim.end_dialogue(); - saw_dialogue |= std::ranges::any_of(scene->second, [](const SimBeat& beat){ return beat.line; }); - const std::string early = play_scene(scene->second, {.warp = fade, .door = kind == SettleKind::DOOR}); + saw_dialogue |= std::ranges::any_of(beats, [](const SimBeat& beat){ return beat.line; }); + const std::string early = play_scene(beats, {.warp = fade, .door = kind == SettleKind::DOOR}); if (!early.empty()){ m_route.note(label + ": talk-over " + early + ".", RouteNote::FAILURE); } @@ -360,14 +365,18 @@ WalkResult SimKnobRouteIO::slide_on(const SimSlide& slide, WalkResult result){ } bool SimKnobRouteIO::dialog_within(Milliseconds wait, Color color){ + m_uncovered_first_line = Milliseconds(0); Milliseconds& longest = m_misses.dialog_waits[m_step]; longest = std::max(longest, wait); const auto late = m_knobs.first_line.find(m_step); if (late != m_knobs.first_line.end() && late->second > wait){ + m_uncovered_first_line = late->second - wait; note(std::format("[Sim] {}: the first line comes after {} ms, past the {} ms wait.", m_step, late->second.count(), wait.count()), RouteNote::LOG); return false; } if (late != m_knobs.first_line.end()){ + // The knob is the current step's line; no map dialogue is needed. + m_uncovered_first_line = Milliseconds(0); return true; } return GridSimRouteIO::dialog_within(wait, color); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h index 5a4ee21013..cf218fe547 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -168,7 +168,8 @@ struct SimWorldKnobs{ std::map fade_into = {}; // People with a wander box on their map walk it, a step tried every 2 s. std::optional wander_seed = std::nullopt; - // How long after the A press a talk's first line shows, by step name. + // How long after a step begins watching for dialogue its first line + // shows, by step name. std::map first_line = {}; // The scene a step's talk-over plays, by step name: a scene's or a // door's settle(), or the speeches after a battle step's battle. @@ -227,6 +228,9 @@ class SimKnobRouteIO : public GridSimRouteIO{ virtual WalkResult walk_to_wall(const RouteWallWalk& walk) override; virtual WalkResult walk_taps(Pokemon::Direction direction, size_t tiles, const std::string& label) override; virtual bool dialog_within(Milliseconds wait, Color color) override; + Milliseconds take_uncovered_first_line(){ + return std::exchange(m_uncovered_first_line, Milliseconds(0)); + } // With SimWorldKnobs::slow_fade_in, fails the move `label` if the last // warp is still fading in (SimMisses::fading_in). void check_fade_in(const std::string& label); @@ -242,6 +246,7 @@ class SimKnobRouteIO : public GridSimRouteIO{ const std::string& m_step; std::function m_cross; std::set m_slid_steps; + Milliseconds m_uncovered_first_line{0}; }; } // namespace detail From 1b7bfcd6f4989585c8f729d249b662a6d22e1003 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 14:21:23 -0800 Subject: [PATCH 6/7] Invalidate scene dialogue across every intervening step --- .../PokemonBDSP_AutoStory_StoryWalkSteps.cpp | 4 +-- ...kemonBDSP_AutoStory_StoryActions_Tests.cpp | 30 ++++++------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp index cb7d2de2f1..e961df21c3 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp @@ -208,8 +208,8 @@ void StoryWalkSteps::begin_attempt(const std::string& row, const std::vector expected_skips{ - "mom_calls", - "barry_goes_home", - "barry_runs_to_the_lake", - }; SimExecutor sim(logger); run_rows_on(sim, logger, {.from = "00.00", .to = std::string(LAST_ROW)}); if (!sim.result().error.empty()){ @@ -235,29 +230,22 @@ UnitTestResult test_scene_start_waits(Logger& logger){ continue; } const auto found = sim.misses().dialog_waits.find(step.name); - const bool should_skip = expected_skips.contains(step.name); if (found == sim.misses().dialog_waits.end()){ - if (!should_skip){ - return std::format("{} {} skipped its opening-line guard without preceding dialogue.", row, step.name); - } - }else{ - if (should_skip){ - return std::format("{} {} repeated an opening-line guard after preceding dialogue.", row, step.name); - } - // Mirrors SCENE_START_WAIT in StoryWalkSteps.cpp. - if (found->second != Milliseconds(15000)){ - return std::format("{} {} waits {} ms for its opening line; expected the full 15000 ms guard.", - row, step.name, found->second.count()); - } - guarded++; + return std::format("{} {} skipped its opening-line guard without preceding dialogue.", row, step.name); + } + // Mirrors SCENE_START_WAIT in StoryWalkSteps.cpp. + if (found->second != Milliseconds(15000)){ + return std::format("{} {} waits {} ms for its opening line; expected the full 15000 ms guard.", + row, step.name, found->second.count()); } + guarded++; scenes++; } if (scenes != EXPECTED_SCENES){ return std::format("Audited {} scene steps through {}; expected {}.", scenes, LAST_ROW, EXPECTED_SCENES); } - if (guarded != scenes - expected_skips.size()){ - return std::format("{} of {} scenes kept the guard; expected {}.", guarded, scenes, scenes - expected_skips.size()); + if (guarded != scenes){ + return std::format("{} of {} scenes kept the guard.", guarded, scenes); } logger.log(std::format("{} scene steps audited through {}; {} used the full opening-line guard.", scenes, LAST_ROW, guarded)); return true; From 839c1a61e2f06b5c981f383acb052495f8f96360 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 14:46:21 -0800 Subject: [PATCH 7/7] Pin the simulated scene skip set --- ...kemonBDSP_AutoStory_StoryActions_Tests.cpp | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp index c35d213004..43d38e7c57 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp @@ -218,6 +218,9 @@ UnitTestResult test_stubbed_steps_need_the_console(Logger& logger){ UnitTestResult test_scene_start_waits(Logger& logger){ constexpr std::string_view LAST_ROW = "01.11"; constexpr size_t EXPECTED_SCENES = 23; + // The default grid naturally plays Barry's doorway scene. The two + // other measured doorway scenes are supplied by the test below. + constexpr std::string_view DEFAULT_SKIP = "barry_goes_home"; SimExecutor sim(logger); run_rows_on(sim, logger, {.from = "00.00", .to = std::string(LAST_ROW)}); if (!sim.result().error.empty()){ @@ -230,22 +233,29 @@ UnitTestResult test_scene_start_waits(Logger& logger){ continue; } const auto found = sim.misses().dialog_waits.find(step.name); + const bool should_skip = step.name == DEFAULT_SKIP; if (found == sim.misses().dialog_waits.end()){ - return std::format("{} {} skipped its opening-line guard without preceding dialogue.", row, step.name); - } - // Mirrors SCENE_START_WAIT in StoryWalkSteps.cpp. - if (found->second != Milliseconds(15000)){ - return std::format("{} {} waits {} ms for its opening line; expected the full 15000 ms guard.", - row, step.name, found->second.count()); + if (!should_skip){ + return std::format("{} {} skipped its opening-line guard without preceding dialogue.", row, step.name); + } + }else{ + if (should_skip){ + return std::format("{} {} repeated its opening-line guard after preceding dialogue.", row, step.name); + } + // Mirrors SCENE_START_WAIT in StoryWalkSteps.cpp. + if (found->second != Milliseconds(15000)){ + return std::format("{} {} waits {} ms for its opening line; expected the full 15000 ms guard.", + row, step.name, found->second.count()); + } + guarded++; } - guarded++; scenes++; } if (scenes != EXPECTED_SCENES){ return std::format("Audited {} scene steps through {}; expected {}.", scenes, LAST_ROW, EXPECTED_SCENES); } - if (guarded != scenes){ - return std::format("{} of {} scenes kept the guard.", guarded, scenes); + if (guarded + 1 != scenes){ + return std::format("{} of {} scenes kept the guard; expected one exact skip.", guarded, scenes); } logger.log(std::format("{} scene steps audited through {}; {} used the full opening-line guard.", scenes, LAST_ROW, guarded)); return true;