diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp index d5768918b6..44a9c7872b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryStepIO.cpp @@ -294,7 +294,7 @@ std::optional ConsoleStoryStepIO::tap_to_banner(Direction direction, con m_stream.log("[Banner] a fade, no \"" + banner + "\" banner after it: counting the fade.", COLOR_ORANGE); } if (look != TapLook::NOTHING){ - m_context.wait_for(1000ms); + // No fixed wait: the step settles after it (talk_over()). return tap; } } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp index 2f70e26a01..d5d2415157 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp @@ -129,15 +129,18 @@ CenterEntry run_into_center( const std::function& inside, const std::function& line_up, const std::string& label ){ + // Every way in settles before the walk to the nurse: the inside can + // still fade in whether or not the run saw the fade. + CenterEntry entry = CenterEntry::LINED_UP; if (io.run_into_door(Direction::NORTH, run).any()){ - io.settle(BUTTON_B, label + ": into the Center", false, ""); - return CenterEntry::FADED; - } - if (inside()){ - return CenterEntry::INSIDE; + entry = CenterEntry::FADED; + }else if (inside()){ + entry = CenterEntry::INSIDE; + }else{ + line_up(); } - line_up(); - return CenterEntry::LINED_UP; + io.settle(BUTTON_B, std::format("{}: into the Center", label), false, ""); + return entry; } TappedEnd tapped_end(const StoryWorld& world, const std::string& map, const TilePos& pos, const Pokemon::StoryLeg& leg){ @@ -346,7 +349,11 @@ size_t taps_to_banner(const Pose& from, Direction direction){ Outcome StoryWalkSteps::tap_to_banner(const Pose& from, const StoryStep& step){ const Direction direction = story_arg(step.args, "direction"); const std::string map = step.pose_after ? Pokemon::grid_pose_of(*step.pose_after).map : ""; + // After the way through, the far side may still fade in, and a walk + // 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), false, ""); return Pokemon::outcome_ok(); } const size_t limit = taps_to_banner(from, direction); @@ -360,6 +367,7 @@ Outcome StoryWalkSteps::tap_to_banner(const Pose& from, const StoryStep& step){ }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), false, ""); return Pokemon::outcome_ok(); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp index 389302230d..967b628dcd 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp @@ -9,10 +9,12 @@ */ #include +#include #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "Actions/PokemonBDSP_AutoStory_TalkOver.h" #include "Actions/PokemonBDSP_AutoStory_Talks.h" #include "Actions/PokemonBDSP_AutoStory_WildBattle.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" @@ -229,16 +231,9 @@ void walk_out_of_center(VideoStream& stream, ProControllerContext& context, cons // "No floor" also reads true on the door's black fade, and the game // takes no input until it ends: the first D-pad taps after it were // lost and the gym's door ended a tile away (r215d, r216d; a shot - // per press by hand showed the black frame). Wait for daylight. - const auto start = current_time(); - while (current_time() - start < 6000ms){ - context.wait_for(100ms); - const VideoSnapshot frame = stream.video().snapshot(); - if (frame && mean_brightness(*frame.frame) > 40){ - break; - } - } - context.wait_for(1000ms); + // per press by hand showed the black frame). Settle: the fade + // back up and a quiet overworld, not a fixed wait. + talk_over(stream, context, std::format("{}: out of the Center", label)); return; } } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp index c3beaa348f..8375ffbecc 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp @@ -23,6 +23,10 @@ * (6, 9), lab-B 2026-11-09 17:29: the walk took it for a trainer and * pressed through it). A variant also fails when the walk fights it. * SimWorldKnobs::scene_at_walk_end. + * - SLOW_FADE_IN: every warp's fade-in runs long, so a move after a fade + * with no settle() between goes nowhere (lab-B 2026-11-10, 00.04b + * heal_sandgem: a fixed 1500 ms wait, then the walk to the nurse + * stopped on "transition"). SimWorldKnobs::slow_fade_in. * * Missed and short fades are swept by SimFailureCases_Tests (every single * missed fade, banner and fade hold). @@ -73,6 +77,7 @@ enum class FaultClass{ BATTLE_OPENING, GRASS_BATTLES, SCENE_EARLY, + SLOW_FADE_IN, // Not swept yet: the measured movement table's lost taps (#293). LOST_TAP, }; @@ -86,6 +91,8 @@ std::string_view fault_class_name(FaultClass fault){ return "wild battles on every grass pass"; case FaultClass::SCENE_EARLY: return "scene starts during the walk before it"; + case FaultClass::SLOW_FADE_IN: + return "slow fade-in after every warp"; case FaultClass::LOST_TAP: return "lost tap"; } @@ -317,6 +324,18 @@ UnitTestResult sweep_grass_battles(Logger& logger, const StoryCheckpoint& row){ return sweep_result(logger, FaultClass::GRASS_BATTLES, row.id, 1, failures); } +// Row `row` with every warp's fade-in slow, all through the row. +UnitTestResult sweep_slow_fade_in(Logger& logger, const StoryCheckpoint& row){ + SimWorldKnobs knobs; + knobs.slow_fade_in = true; + const std::string stopped = run_row(logger, row.id, std::move(knobs)); + std::vector failures; + if (!stopped.empty()){ + failures.push_back({"", "a slow fade-in after every warp", stopped}); + } + return sweep_result(logger, FaultClass::SLOW_FADE_IN, row.id, 1, failures); +} + // The route before scene step `c` of `steps`, right before it or before // the plain step onto its trigger; none if there is none. std::optional route_before_scene(const std::vector& steps, size_t c){ @@ -431,6 +450,8 @@ class Test_AutoStoryFaultSweep : public UnitTest{ return sweep_grass_battles(logger, m_row); case FaultClass::SCENE_EARLY: return sweep_scene_early(logger, m_row); + case FaultClass::SLOW_FADE_IN: + return sweep_slow_fade_in(logger, m_row); case FaultClass::LOST_TAP: break; } @@ -448,6 +469,7 @@ const FaultSweepCase FAULT_SWEEP_CASES[] = { {.input = {.fault = FaultClass::BATTLE_OPENING}, .expectation = {}}, {.input = {.fault = FaultClass::GRASS_BATTLES}, .expectation = {}}, {.input = {.fault = FaultClass::SCENE_EARLY}, .expectation = {}}, + {.input = {.fault = FaultClass::SLOW_FADE_IN}, .expectation = {}}, }; void add_tests_AutoStory_FaultSweep(UnitTestDatabase& database){ 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 93561162a1..1e413da917 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 @@ -15,12 +15,14 @@ * */ +#include #include #include #include #include #include #include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" @@ -281,6 +283,42 @@ UnitTestResult roark_badge_speech(Logger& logger){ return passes(early); } +// How long talk_over() takes to settle inside a Pokemon Center after its +// fade (the heal's settle, lab-B 2026-11-10 00.04b), with the inside's +// visitors walking about the whole time. A visitor walking past changes +// the screen by 10 to 13.4 (WALK_TAP_BLOCKED_CHANGE's note, r244a), under +// its 16, so it reads still: settled TALK_OVER_QUIET after the fade. If the +// inside never read still (a screen moving more than that), the calm rule +// still ends it TALK_OVER_CALM after the fade. Either way it is bounded. +UnitTestResult center_inside_settles(Logger& logger){ + struct Inside{ + std::string_view what; + bool moving; + Milliseconds most; + }; + const Milliseconds fade = 1500ms; + // A look per press: the quiet is seen a press or two after it begins + // (7680 ms for the still case). + const Milliseconds slack = 2000ms; + const Inside cases[] = { + {"visitors walking (reads still)", false, fade + Pokemon::TALK_OVER_QUIET + slack}, + {"a screen never still", true, fade + Pokemon::TALK_OVER_CALM + slack}, + }; + for (const Inside& inside : cases){ + const SimScene scene{ + sim_fade("the Center's door fade", fade), + sim_pause(std::string(inside.what), 60000ms, inside.moving), + }; + const std::string over = play_scene(scene, {}); + logger.log(std::format("Center inside, {}: {}", inside.what, over)); + long long ms = -1; + if (std::sscanf(over.c_str(), "judged over %lld ms in", &ms) != 1 || ms < fade.count() || ms > inside.most.count()){ + return std::format("Center inside, {}: not settled between {} and {} ms: {}", inside.what, fade.count(), inside.most.count(), over); + } + } + return true; +} + // 01.07: after the tag battle the screen fades back from the battle and // the grunts run off before anyone speaks: a scene that opens with no box, // 6 s of people moving (Rowan's cutscene shape), then Rowan's and Dawn's @@ -614,6 +652,7 @@ const FailureCase AUTO_STORY_FAILURE_CASES[] = { return wanderers_move(logger, "01.08"); }}, .expectation = {}}, {.input = {"01.04 Roark's badge speech: the fanfare's pause, then a scene", roark_badge_speech}, .expectation = {}}, + {.input = {"inside a Pokemon Center, the settle after the door's fade ends in bounded time with visitors walking", center_inside_settles}, .expectation = {}}, {.input = {"01.07 after the tag battle the grunts run off before anyone speaks", grunts_run_off_before_rowan}, .expectation = {}}, {.input = {"00.03 Rowan's scene opens with no box and fades home", rowans_scene_opens_with_no_box}, .expectation = {}}, {.input = {"00.03 Mom's scene ends with a closing fade: over once it is back up (lab-B 2026-11-09)", moms_scene_ends_with_a_fade}, .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 c3b4a66d99..856635b284 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -182,6 +182,7 @@ WarpSeen SimStoryStepIO::door_fade(const std::string& banner){ // walk's watchers take uniform frames only, so a fade whose hold they // did not see is missed too. void SimStoryStepIO::walk_until_stopped(Direction direction, size_t tiles, const std::string& label){ + m_route.check_fade_in(label); m_sim.tap(direction, ROUTE_TURN_TAP, false); Milliseconds limit = ROUTE_START_DELAY + 800ms + route_ms_per_tile(direction) * (int64_t)(2 * tiles); SimMove move = m_sim.hold(direction, limit, SimPace::WALK); @@ -196,7 +197,8 @@ void SimStoryStepIO::walk_until_stopped(Direction direction, size_t tiles, const // The D-pad, a tile at a time, until `map`'s banner reads; through a door // the walk goes on beyond it (the fade eats no tiles of a hold). -bool SimStoryStepIO::run_until_map(Direction direction, Milliseconds limit, const std::string& map, const std::string&){ +bool SimStoryStepIO::run_until_map(Direction direction, Milliseconds limit, const std::string& map, const std::string& label){ + m_route.check_fade_in(label); const bool miss = banner_missed(); size_t on = 0; for (Milliseconds ran = 0ms; ran < limit; ran += ROUTE_RUN_MS_PER_TILE_ACROSS){ @@ -230,6 +232,12 @@ double SimStoryStepIO::floor_here() const{ // its hold seen or not; with the fade missed whole the look still sees the // banner. std::optional SimStoryStepIO::tap_to_banner(Direction direction, const std::string& map, size_t max_taps){ + const std::optional taps = taps_to_banner(direction, map, max_taps); + // Through: the far side fades in as the step ends. + m_misses.fading_in = taps.has_value(); + return taps; +} +std::optional SimStoryStepIO::taps_to_banner(Direction direction, const std::string& map, size_t max_taps){ if (m_misses.through == m_misses.tap_steps++){ m_misses.missed = true; if (m_far_side() && m_misses.through_banner){ @@ -239,6 +247,7 @@ std::optional SimStoryStepIO::tap_to_banner(Direction direction, const s if (std::exchange(m_misses.banner_up, "") == map){ return 0; } + m_route.check_fade_in(std::format("{}: taps toward {}", m_step, map)); bool crossed = false; for (size_t tap = 1; tap <= max_taps; tap++){ const SimMove move = m_sim.tap(direction, 160ms, false); @@ -259,7 +268,19 @@ std::optional SimStoryStepIO::tap_to_banner(Direction direction, const s return std::nullopt; } +void SimKnobRouteIO::check_fade_in(const std::string& label){ + if (m_knobs.slow_fade_in && std::exchange(m_misses.fading_in, false)){ + note(std::format("{}: moved while the last warp still faded in (no settle after it).", label), RouteNote::FAILURE); + } +} + +WalkResult SimKnobRouteIO::walk_to_wall(const RouteWallWalk& walk){ + check_fade_in(walk.label); + return GridSimRouteIO::walk_to_wall(walk); +} + WalkResult SimKnobRouteIO::walk_taps(Direction direction, size_t tiles, const std::string& label){ + check_fade_in(label); const WalkResult result = GridSimRouteIO::walk_taps(direction, tiles, label); if (result.stop != WalkStop::LIMIT || m_slid_steps.contains(m_step)){ return result; 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 d3b01e85de..3eed905a29 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -14,6 +14,7 @@ #ifndef PokemonAutomation_PokemonBDSP_AutoStory_StorySim_H #define PokemonAutomation_PokemonBDSP_AutoStory_StorySim_H +#include #include #include #include @@ -177,6 +178,11 @@ struct SimWorldKnobs{ // walk's last tiles (its target): its trigger lies on the way, so the // walk runs into it (00.04's Mom's call on (6, 9), lab-B 2026-11-09 17:29). std::function scene_at_walk_end = nullptr; + // Every warp's fade-in runs long: a walk, a tap or a door run after a + // door's fade or a tap step's way through, with no settle() between, + // goes nowhere (lab-B 2026-11-10, 00.04b heal_sandgem walked to the + // nurse 1500 ms after the Center's fade and stopped on "transition"). + bool slow_fade_in = false; }; namespace detail{ @@ -198,8 +204,12 @@ class SimKnobRouteIO : public GridSimRouteIO{ , m_cross(std::move(cross)) {} + 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; + // 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); private: WalkResult slide_on(const SimSlide& slide, WalkResult result); @@ -310,6 +320,7 @@ class SimStoryStepIO : public StoryStepIO{ // (story_arrival_banner(): the sim's maps have no banners of their own). virtual WarpSeen run_into_door(Pokemon::Direction direction, bool run, Milliseconds timeout = Milliseconds(12000), Milliseconds dark_from = Milliseconds(0), const std::string& banner = "") override{ + m_route.check_fade_in(std::format("{}: run into the door", m_step)); const SimPace pace = run ? SimPace::RUN : SimPace::WALK; if (false_dark() && dark_from <= detail::SIM_FALSE_DARK && detail::SIM_FALSE_DARK < timeout){ m_sim.hold(direction, detail::SIM_FALSE_DARK, pace); @@ -331,6 +342,8 @@ class SimStoryStepIO : public StoryStepIO{ virtual std::optional tap_to_banner(Pokemon::Direction direction, const std::string& map, size_t max_taps) override; private: + // tap_to_banner()'s taps, before it marks the far side fading in. + std::optional taps_to_banner(Pokemon::Direction direction, const std::string& map, size_t max_taps); // How the run shows its next fade (SimMisses): whole, its hold unseen, // or not at all. enum class FadeShown{