From 9cd8545b2da088271974f07609aa8fd0a0c122ab Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 15:18:40 -0800 Subject: [PATCH] BDSP AutoStory: replay console failures on the sim from fault files Moved from nav/leg-replay (#447) onto the rebuild stack unchanged: the 01.02 fault files under Simulation/ConsoleFailures, the generic replay test that runs each of them, and the GridSim/StorySim hooks it injects the faults through. The shared reader (Pokemon_LegReplay) comes from nav/leg-trace (#464). (moved from 98c0b6177, 5363e465f and af66aa3d2) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- SerialPrograms/CMakeLists.txt | 3 + .../Source/PokemonBDSP/PokemonBDSP_Tests.cpp | 2 + .../01.02-18-36-east-mouth-slid.json | 13 ++ .../01.02-20-23-hold-out-the-east-door.json | 15 ++ .../01.02-21-02-camper-drift.json | 16 ++ ...PokemonBDSP_AutoStory_ConsoleFailureData.h | 29 +++ ...P_AutoStory_ConsoleFailureReplay_Tests.cpp | 203 ++++++++++++++++++ ...DSP_AutoStory_ConsoleFailureReplay_Tests.h | 25 +++ .../PokemonBDSP_AutoStory_GridSim.cpp | 5 +- .../PokemonBDSP_AutoStory_GridSim.h | 1 + .../PokemonBDSP_AutoStory_StorySim.cpp | 76 +++++-- .../PokemonBDSP_AutoStory_StorySim.h | 13 ++ SerialPrograms/cmake/SourceFiles.cmake | 3 + 13 files changed, 389 insertions(+), 15 deletions(-) create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-18-36-east-mouth-slid.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-20-23-hold-out-the-east-door.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-21-02-camper-drift.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureData.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 0ce81e4014..28af3d7828 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -231,6 +231,9 @@ add_library(SerialProgramsLib STATIC ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES}) include(cmake/EmbedTextFiles.cmake) pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps Pokemon/Navigation/Pokemon_NavigationTestMaps.h PokemonAutomation::Pokemon navigation_test_map_json) +pa_embed_text_files(SerialProgramsLib Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures + PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureData.h + PokemonAutomation::NintendoSwitch::PokemonBDSP console_failure_json) # Prepared data is validated by the shared publisher tooling. No source-map # fallback or network download is performed during configuration. set(POKESIM_TOOLS_SOURCE "$ENV{POKESIM_TOOLS_SOURCE}" CACHE PATH "Pinned PokemonSimulation tools checkout") diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp index 25793edcd2..c7c32aa18e 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp @@ -31,6 +31,7 @@ #include "Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.h" #include "Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WildBattlePolicy_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.h" +#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h" #include "Programs/RngManipulation/PokemonBDSP_StarterRng_Tests.h" #include "PokemonBDSP_Tests.h" @@ -64,6 +65,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStory_StorySim(database); add_tests_AutoStory_StoryMonteCarlo(database); add_tests_AutoStory_SimFailureCases(database); + add_tests_AutoStory_ConsoleFailureReplay(database); add_tests_AutoStory_FaultSweep(database); add_tests_AutoStory_SimGolden(database); add_tests_AutoStory_StoryActions(database); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-18-36-east-mouth-slid.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-18-36-east-mouth-slid.json new file mode 100644 index 0000000000..ae8a2a4a05 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-18-36-east-mouth-slid.json @@ -0,0 +1,13 @@ +{ + "about": "lab-B 2026-11-12 18:27-18:42, 01.02: by_the_east_mouth's counted taps went two tiles past the leg's end onto the Gate's east warp, its fade unseen; into_oreburgh then saw no fade and no OreburghCity banner.", + "checkpoint": "01.02", + "faults": [ + {"kind": "moved_further", "step": "by_the_east_mouth", "direction": "east", "tiles": 2, "fade": "unseen", "far_pose_of": "into_oreburgh"} + ], + "failed": {"step": "into_oreburgh", "error": "no_banner"}, + "frame": "", + "evidence": [ + "[Leg] by_the_east_mouth leg 7: east 3 planned, moved 2, dead_reckoned at (26, 22)", + "into_oreburgh: no fade and no OreburghCity banner in 4 taps east" + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-20-23-hold-out-the-east-door.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-20-23-hold-out-the-east-door.json new file mode 100644 index 0000000000..d327f785ff --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-20-23-hold-out-the-east-door.json @@ -0,0 +1,15 @@ +{ + "about": "lab-B 2026-11-12 20:20:50, 01.02 past_curtis, after the same one tile of drift as 21:02 (Curtis stopped the east walk at 9 tiles, a fight left tiles 13-16 possible): the hold east to find us again ran along row 22 and out the Gate's east door, its fade unseen; the program took it as ending at (16, 22) and walked on in Oreburgh City, which it took for the Gate, until into_oreburgh saw no banner at 20:23:09.", + "checkpoint": "01.02", + "faults": [ + {"kind": "person_stands", "name": "camper_1", "tile": [17, 22]}, + {"kind": "scene_ends_further", "step": "the_hiker", "direction": "east", "tiles": 1}, + {"kind": "hold_through_warp", "step": "past_curtis", "direction": "east", "fade": "unseen", "far_pose_of": "into_oreburgh"} + ], + "failed": {"step": "into_oreburgh", "error": "no_banner"}, + "frame": "", + "evidence": [ + "[Walk] past curtis: east 3 (to wall) to find us again: screen change 266.96 at 1200 ms (the fade), then limit after 1850 ms", + "[Route] past curtis: found again at OreburghGate (16, 22), after 1 hold(s)." + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-21-02-camper-drift.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-21-02-camper-drift.json new file mode 100644 index 0000000000..92a87cca1a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures/01.02-21-02-camper-drift.json @@ -0,0 +1,16 @@ +{ + "about": "lab-B 2026-11-12 21:02:53, 01.02 past_curtis: the player stood one tile east of the table's (7, 22) after the Hiker's scene (hikers_trigger's step east, the scene after it; the same drift as 20:15), so the east walk from the believed (7, 22) met Camper Curtis's sight line on column 17 after 9 tiles, not 10, and he stopped it at (17, 22) while the program believed (15-16, 22). Its recovery hold east then ran 12 tiles, out of the Gate.", + "checkpoint": "01.02", + "faults": [ + {"kind": "person_stands", "name": "camper_1", "tile": [17, 22]}, + {"kind": "scene_ends_further", "step": "the_hiker", "direction": "east", "tiles": 1} + ], + "failed": {"step": "past_curtis", "error": "operation_failed: past curtis: east 1 (to wall) to find us again: still moving after 12 tiles, past the wall 1 tiles away at most: position unknown."}, + "frame": "20261112-210253120715-attempt0.png", + "evidence": [ + "[Event] 01.02/7 hikers_trigger: a step east, limit.", + "[Walk] past curtis: east 13 (open): blocked after 8800 ms, 9 moved chunks", + "[Route] someone the map lacks is at OreburghGate (17, 22)", + "[Leg] past_curtis leg 1: east, moved 9, seen at (15, 22),(16, 22)" + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureData.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureData.h new file mode 100644 index 0000000000..9c7891b5cb --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureData.h @@ -0,0 +1,29 @@ +/* BDSP AutoStory - Console failure data + * + * From: https://github.com/PokemonAutomation/ + * + * The fault files in ConsoleFailures/, built into the program + * (cmake/EmbedTextFiles.cmake): (file name, text), sorted by name. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureData_H +#define PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureData_H + +#include +#include +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// (file name without ".json", text) of each fault file. +const std::vector>& console_failure_json(); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.cpp new file mode 100644 index 0000000000..0fe3a4f321 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.cpp @@ -0,0 +1,203 @@ +/* BDSP AutoStory - Console failure replay tests + * + * From: https://github.com/PokemonAutomation/ + * + * Every fault file (Pokemon_LegReplay.h) of a console failure runs here on + * the story simulation: trainers, NPCs and walls come from the map, only + * the file's faults are injected, and the checkpoint it names must pass. + * A file is red on the program that failed on the console and green on the + * program that fixed it. No case has code of its own. + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Types/Pokemon_GridPose.h" +#include "Pokemon/Navigation/Pokemon_LegReplay.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.h" +#include "PokemonBDSP_AutoStory_ConsoleFailureData.h" +#include "PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h" +#include "PokemonBDSP_AutoStory_StorySim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +namespace{ + +using Pokemon::ConsoleFailure; +using Pokemon::ReplayFault; +using Pokemon::ReplayFaultKind; +using Pokemon::StoryStep; + +const StoryStep* find_step(const std::vector& rows, const std::string& row, const std::string& name){ + for (const StoryCheckpoint& checkpoint : rows){ + if (checkpoint.id != row){ + continue; + } + for (const StoryStep& step : checkpoint.steps){ + if (step.name == name){ + return &step; + } + } + } + return nullptr; +} + +SimFade sim_fade_of(Pokemon::ReplayFade fade){ + switch (fade){ + case Pokemon::ReplayFade::UNSEEN: + return SimFade::UNSEEN; + case Pokemon::ReplayFade::BLACK: + return SimFade::BLACK; + case Pokemon::ReplayFade::DIM: + return SimFade::DIM; + case Pokemon::ReplayFade::WHITE: + return SimFade::WHITE; + } + return SimFade::UNSEEN; +} + +// The walk that goes on past its end, as the fault says. +SimSlide slide_of(const ConsoleFailure& failure, const std::vector& rows, const ReplayFault& fault){ + SimSlide slide{ + .step = fault.step, .direction = fault.direction, .tiles = fault.tiles, + .fade = sim_fade_of(fault.fade), .banner_up = fault.banner_up, + }; + if (fault.far_pose_of.empty()){ + return slide; + } + const StoryStep* landing = find_step(rows, failure.checkpoint, fault.far_pose_of); + if (landing == nullptr || !landing->pose_after){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, + std::format("{}: step {} has no pose after it", failure.name, fault.far_pose_of)); + } + slide.far = Pokemon::pose_of(*landing->pose_after); + return slide; +} + +// The faults as the simulation's knobs. +void inject(const ConsoleFailure& failure, const std::vector& rows, SimMisses& misses, SimWorldKnobs& knobs){ + if (failure.start){ + knobs.start_at = Pokemon::pose_of(Pokemon::GridPose{ + failure.start->map, {failure.start->tile}, *failure.start_facing + }); + } + for (const ReplayFault& fault : failure.faults){ + switch (fault.kind){ + case ReplayFaultKind::FADE_MISSED: + misses.fade = fault.index; + break; + case ReplayFaultKind::BANNER_MISSED: + misses.banner = fault.index; + break; + case ReplayFaultKind::MOVED_FURTHER: + knobs.slides.push_back(slide_of(failure, rows, fault)); + break; + case ReplayFaultKind::HOLD_THROUGH_WARP: + knobs.hold_slides.push_back(slide_of(failure, rows, fault)); + break; + case ReplayFaultKind::SCENE_ENDS_FURTHER: + knobs.scene_slides.push_back(slide_of(failure, rows, fault)); + break; + case ReplayFaultKind::PERSON_STANDS: + knobs.standing[fault.name] = fault.tile; + break; + case ReplayFaultKind::MOVED_LESS: + // The BDSP story sim takes each hold as walked; only the FRLG overworld sim shortens holds. + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format( + "{}: the fault \"{}\" is not one the BDSP story simulation injects", + failure.name, Pokemon::replay_fault_kind_name(fault.kind) + )); + } + } +} + +struct ReplayInput{ + std::string name; + std::string text; +}; +struct ReplayExpectation{ +}; +struct ReplayCase{ + ReplayInput input; + ReplayExpectation expectation; +}; + +// The note the sim leaves when a fault really happened; empty for kinds with no note. +std::string fault_marker(ReplayFaultKind kind){ + switch (kind){ + case ReplayFaultKind::MOVED_FURTHER: return "[Sim] slid"; + case ReplayFaultKind::HOLD_THROUGH_WARP: return "[Sim] held through a warp"; + case ReplayFaultKind::SCENE_ENDS_FURTHER: return "[Sim] scene ended"; + default: return ""; + } +} + +// The cases are discovered from the embedded fault JSONs, so a new console failure needs no +// C++ edit; the code-health test-case table rule does not fit a data-driven test. +class Test_ConsoleFailureReplay : public UnitTest{ +public: + explicit Test_ConsoleFailureReplay(ReplayCase test_case) + : UnitTest(std::format("PokemonBDSP::AutoStory - Console failure replay: {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + const ConsoleFailure failure = Pokemon::parse_console_failure(m_case.input.name, m_case.input.text); + const std::vector rows = story_checkpoints(); + if (find_step(rows, failure.checkpoint, failure.failed_step) == nullptr){ + return std::format("{}: the step {} it failed at is not in {}", m_case.input.name, failure.failed_step, failure.checkpoint); + } + SimMisses misses{.fade = {}, .banner = {}}; + SimWorldKnobs knobs; + inject(failure, rows, misses, knobs); + SimExecutor executor(logger, std::move(misses), std::move(knobs)); + const Pokemon::SegmentReport report = run_rows_on(executor, logger, {.from = failure.checkpoint, .to = failure.checkpoint}, rows); + // A fault that never happened on the sim replays nothing. + for (const ReplayFault& fault : failure.faults){ + const std::string marker = fault_marker(fault.kind); + if (marker.empty()){ + continue; + } + const auto& notes = executor.notes(); + if (std::none_of(notes.begin(), notes.end(), [&](const std::string& note){ return note.find(marker) != std::string::npos; })){ + return std::format("{}: the {} fault at {} never happened on the sim", m_case.input.name, + Pokemon::replay_fault_kind_name(fault.kind), fault.step); + } + } + if (report.completed){ + return true; + } + return std::format("stopped in {}: {} (the console failed at {}: {})", executor.result().failed_step, + executor.result().error, failure.failed_step, failure.failed_error); + }catch (Exception& e){ + return std::format("{}: {}", e.name(), e.message()); + }catch (std::exception& e){ + return std::string(e.what()); + } + } + +private: + ReplayCase m_case; +}; + +} // namespace + +void add_tests_AutoStory_ConsoleFailureReplay(UnitTestDatabase& database){ + std::vector cases; + for (const auto& [name, text] : console_failure_json()){ + cases.push_back({.input = {name, text}, .expectation = {}}); + } + for (const ReplayCase& item : cases){ + database.add(item); + } +} + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h new file mode 100644 index 0000000000..2f3fbb122a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h @@ -0,0 +1,25 @@ +/* BDSP AutoStory - Console failure replay tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// One test per fault file in ConsoleFailures/: the checkpoint it names runs +// on the story simulation with only the file's faults injected, and must pass. +void add_tests_AutoStory_ConsoleFailureReplay(UnitTestDatabase& database); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.cpp index b989fa548b..fd3b837f4a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.cpp @@ -377,9 +377,12 @@ bool GridSim::press_a(){ m_player.trainer = trainer.name; } } - for (const SimWanderer& wanderer : m_wanderers){ + for (SimWanderer& wanderer : m_wanderers){ if (wanderer.pos == faced){ m_player.dialog = true; + if (wanderer.goes_home){ + wanderer.pos = *wanderer.goes_home; + } } } return m_player.dialog; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.h index 8e366beb9e..2d39e28128 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.h @@ -104,6 +104,7 @@ struct SimWanderer{ Milliseconds step_interval = Milliseconds(2000); // how often the NPC attempts a move Milliseconds elapsed = Milliseconds(0); // time accumulated towards next step Milliseconds time_offset = Milliseconds(0); // initial start time offset + std::optional goes_home = std::nullopt; // where they walk back to once talked to }; // Simulated grid environment. 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 1e85a609ad..916fdcc598 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -2,6 +2,7 @@ * * From: https://github.com/PokemonAutomation/ * +// code-health: allow file_lines -- the sim executor, its knobs and the faults the console failures need share one translation unit */ #include @@ -313,6 +314,23 @@ WalkResult SimKnobRouteIO::walk_to_wall(const RouteWallWalk& walk){ if (result.stop == WalkStop::BLOCKED && pushing){ result.walked += m_knobs.pushing_someone; } + if (result.warp.fade != WarpFade::NONE){ + for (const SimSlide& item : m_knobs.hold_slides){ + if (item.step == m_step && item.direction == walk.direction){ + m_misses.slid = true; + note("[Sim] held through a warp to " + Pokemon::to_string(item.far) + ".", RouteNote::LOG); + result = through_warp(item, result); + // A hold's walk stops on a change of the whole screen that walking cannot + // make when no battle follows (a warp whose fade fell between two frames, + // "its fade unseen", 8a570a642; the console's 21:54 hold), where the + // taps of a slide read the time out. + if (item.fade == SimFade::UNSEEN){ + result.stop = WalkStop::TRANSITION; + } + return result; + } + } + } return result; } @@ -345,19 +363,30 @@ WalkResult SimKnobRouteIO::slide_on(const SimSlide& slide, WalkResult result){ continue; } note("[Sim] slid onto a warp to " + Pokemon::to_string(slide.far) + ".", RouteNote::LOG); - m_cross(slide.far); - m_misses.banner_up = slide.banner_up ? slide.far.map : ""; - if (slide.fade == SimFade::UNSEEN){ - m_misses.banner_soon = slide.far.map; - return result; - } - const double brightness = slide.fade == SimFade::BLACK ? SIM_DOOR_FADE : slide.fade == SimFade::DIM ? SIM_DIM_FADE : SIM_WHITE_FADE; - result.warp.fade = fade_of(sim_screen(brightness, SIM_FADE_STDDEV)); - if (result.warp.fade != WarpFade::NONE){ - result.stop = WalkStop::TRANSITION; + return through_warp(slide, result); + } + return result; +} + +// The player went through a warp to `slide.far` on a walk: the fade as the +// slide says, the walk's own result otherwise. +WalkResult SimKnobRouteIO::through_warp(const SimSlide& slide, WalkResult result){ + m_cross(slide.far); + m_misses.banner_up = slide.banner_up ? slide.far.map : ""; + if (slide.fade == SimFade::UNSEEN){ + m_misses.banner_soon = slide.far.map; + // The console's walk read the time out, not a fade. + result.warp.fade = WarpFade::NONE; + if (result.stop == WalkStop::TRANSITION){ + result.stop = WalkStop::LIMIT; } return result; } + const double brightness = slide.fade == SimFade::BLACK ? SIM_DOOR_FADE : slide.fade == SimFade::DIM ? SIM_DIM_FADE : SIM_WHITE_FADE; + result.warp.fade = fade_of(sim_screen(brightness, SIM_FADE_STDDEV)); + if (result.warp.fade != WarpFade::NONE){ + result.stop = WalkStop::TRANSITION; + } return result; } @@ -488,13 +517,14 @@ std::vector SimExecutor::wanderers(const StoryWorld& world) const{ } for (const auto& object : story_map(map).objects){ const auto stands = m_knobs.standing.find(object.name); - if (!object.wander || (!m_knobs.wander_seed && stands == m_knobs.standing.end())){ + const bool still = stands != m_knobs.standing.end(); + // A person who stays put on the map (a trainer) and stood elsewhere on the console. + if ((!object.wander && !still) || (!m_knobs.wander_seed && !still)){ continue; } const uint64_t seed = m_knobs.wander_seed.value_or(0) * 1000003 + out.size() * 7919 + (uint64_t)(object.x * 31 + object.y); - const TilePos low = story_to_world(world, map, {object.wander->x0, object.wander->y0}); - const TilePos high = story_to_world(world, map, {object.wander->x1, object.wander->y1}); - const bool still = stands != m_knobs.standing.end(); + const TilePos low = story_to_world(world, map, object.wander ? TilePos{object.wander->x0, object.wander->y0} : stands->second); + const TilePos high = story_to_world(world, map, object.wander ? TilePos{object.wander->x1, object.wander->y1} : stands->second); out.push_back({ .name = object.name, .box = {.x0 = low.x, .y0 = low.y, .x1 = high.x, .y1 = high.y}, @@ -503,6 +533,7 @@ std::vector SimExecutor::wanderers(const StoryWorld& world) const{ .step_interval = still ? Milliseconds(0) : Milliseconds(2000), .elapsed = Milliseconds(0), .time_offset = still ? Milliseconds(0) : Milliseconds((int64_t)(seed % 2000)), + .goes_home = object.wander ? std::nullopt : std::optional(story_to_world(world, map, {object.x, object.y})), }); } } @@ -599,6 +630,7 @@ void SimExecutor::start_scene_at_end(const StoryStep& step){ void SimExecutor::land(const std::string& step){ count_coupons(step); + slide_after_scene(step); const auto lands = m_knobs.lands.find(step); if (lands == m_knobs.lands.end()){ return; @@ -612,6 +644,22 @@ void SimExecutor::land(const std::string& step){ } } +// The step's scene ran on: the player stands further along than the table's +// pose says (SimWorldKnobs::scene_slides), and stays there like a slide on (the next walks are not checked against the table). +void SimExecutor::slide_after_scene(const std::string& step){ + for (const SimSlide& item : m_knobs.scene_slides){ + if (item.step != step || !m_placed){ + continue; + } + for (size_t tile = 0; tile < item.tiles; tile++){ + m_sim.tap(item.direction, ROUTE_MS_PER_TILE_ACROSS, false); + } + m_sim.end_dialogue(); + m_astray = true; + m_notes.push_back(std::format("[Sim] scene ended {} tile(s) further, at {}.", item.tiles, to_string(m_sim.player().pos))); + } +} + // Through a door or a cave mouth onto the step's far side, the player's // facing kept: a hold goes on from there. bool SimExecutor::cross(){ 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 5e2b56448c..7108b62067 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -170,6 +170,17 @@ std::string play_scene(const SimScene& scene, const TalkOverRule& rule); // unless set. All of it is deterministic: wanderers walk from `wander_seed`. struct SimWorldKnobs{ std::vector slides = {}; + // A hold of the step `step` toward `direction` (a recovery's hold to a + // wall, a walk to a wall) that runs on through a warp its watchers + // miss: the player lands on `far` (lab-B 2026-11-12 20:20:50, 01.02's + // past_curtis, a hold east along row 22 that went out the Gate's east + // door). `tiles` is not used. + std::vector hold_slides = {}; + // A scene or trigger step `step` that leaves the player `tiles` toward + // `direction` past the pose the table gives it (lab-B 2026-11-12 21:02, + // 01.02's the_hiker: the walk east after it met Curtis a tile sooner than + // counted). The program goes on believing the table's pose. `far` is not used. + std::vector scene_slides = {}; // The mean brightness (0 to 255) of a map's floor, by JSON map name, and // of the fade into a map; a tap step judges its fade from these with the // program's fade_of(), a floor textured, a fade uniform (SIM_FLOOR_STDDEV, @@ -268,6 +279,7 @@ class SimKnobRouteIO : public DisturbedRouteIO{ private: WalkResult slide_on(const SimSlide& slide, WalkResult result); + WalkResult through_warp(const SimSlide& slide, WalkResult result); GridSim& m_grid; SimMisses& m_misses; @@ -579,6 +591,7 @@ class SimExecutor : public Pokemon::TableExecutor{ // Puts the player where SimWorldKnobs::lands says `step` leaves them, if // it says, and counts its coupon or Poketch (count_coupons()). void land(const std::string& step); + void slide_after_scene(const std::string& step); bool cross(); bool cross_to(const Pokemon::Pose& far); std::vector wanderers(const StoryWorld& world) const; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index bd7fe09b70..85bc1e2dd1 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1912,6 +1912,9 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureData.h + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.cpp