From a326cc8e1703a9cfa6e6a22c6b28dc4637e2c8e6 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 31 Oct 2026 21:58:46 -0700 Subject: [PATCH 1/2] BDSP AutoStory: 00.01 to 00.03 as lines on the decomp grids, with the scenes' triggers; the Oreburgh Gym's inside Checkpoints 00.01 to 00.03 replay recorded stick holds. This writes the same walks down as lines on the Twinleaf, Route 201 (a decomp stand-in until the re-derived grid lands), Verity Lakefront and Sandgem grids, corner to corner, each line ending on the tile that fires the next scene. The scenes' trigger rectangles are read off the Diamond decomp's coord events (Barry's door, his tall-grass warning, the lake's entrance, Rowan on the way back, Dawn at Sandgem), and a test plans every stretch as one straight leg and checks each line steps into its scene on its last tile only. Route records for the three checkpoints trace on the grids. The Oreburgh Gym's inside is decoded so 01.04's "north until a trainer stops us" traces too. The segment code keeps its replays; a TODO points at the lines. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Source/PokemonBDSP/PokemonBDSP_Tests.cpp | 2 + .../Programs/AutoStory/Data/MAPS.md | 13 +- .../PokemonBDSP_AutoStory_OreburghGym.cpp | 95 +++++++ .../Data/PokemonBDSP_AutoStory_OreburghGym.h | 38 +++ .../PokemonBDSP_AutoStory_RouteRecords.cpp | 129 +++++++-- .../PokemonBDSP_AutoStory_Segment00Lines.cpp | 238 ++++++++++++++++ .../PokemonBDSP_AutoStory_Segment00Lines.h | 90 ++++++ .../PokemonBDSP_AutoStory_Segment00_Tests.cpp | 266 ++++++++++++++++++ .../PokemonBDSP_AutoStory_Segment00_Tests.h | 27 ++ .../PokemonBDSP_AutoStory_Segment_00.cpp | 6 +- .../Utils/PokemonBDSP_AutoStory_RouteWalk.h | 1 + SerialPrograms/cmake/SourceFiles.cmake | 6 + 12 files changed, 886 insertions(+), 25 deletions(-) create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp index 10dd5da86f..3f7412b76b 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp @@ -19,6 +19,7 @@ #include "PokemonBDSP_Tests.h" #include "Inference/PokemonBDSP_MenuDetector.h" #include "Programs/AutoStory/PokemonBDSP_AutoStory_Tests.h" +#include "Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -290,6 +291,7 @@ void add_tests(UnitTestDatabase& database){ database.add(); add_tests_MenuDetector(database); add_tests_AutoStory(database); + add_tests_AutoStory_Segment00(database); } } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md index b75f9f3292..3f7926e320 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md @@ -27,11 +27,18 @@ Each map file's header starts with the same three lines, kept current with the c | Oreburgh City | decomp (pokediamond) | none yet (01.04, 01.05 run as records) | probe the Center doorstep (x 46 or 47) | | Oreburgh Gate | decomp (pokediamond) | none yet | | | Floaroma Town | decomp (pokediamond), the old couple from the console | 01.11 (1x, as a record) | | -| Twinleaf Town | decomp (pokediamond) | none: 00.01 to 00.03 replay recorded stick inputs (#1717), no route on the grid | redo 00.01 to 00.03 as planned walks | -| Verity Lakefront, Lake Verity | decomp (pokediamond) | none: 00.02, 00.03 replay recorded stick inputs (#1717) | redo as planned walks | +| Twinleaf Town | decomp (pokediamond) | none: 00.01 replays recorded stick inputs (#1717); its lines and records are on the grid (Segment00Lines, task #22), tested offline | a new-game run of the lines, then switch 00.01 to them | +| Verity Lakefront | decomp (pokediamond) | none: 00.01 to 00.03 replay recorded stick inputs (#1717); lines and records on the grid, tested offline | the run must say which entrance tile the lake's scene leaves us on | +| Lake Verity | decomp (pokediamond) | none, and no walk: the scene carries us in and the game warps us out | none | +| Route 201 (decomp stand-in, Segment00Lines) | decomp (pokediamond), scene actors as open ground | none: the 00.01 and 00.03 lines are planned and traced on it | fold into Route 201 once that file is the decomp's | +| Oreburgh Gym | decomp (pokediamond) | none: 01.04 walks it as a record (north until a trainer stops us), traced on the grid | a plan on it if the record ever fails | Rules: terrain from the decomp, people and Platinum-only edits from the console; a route is coded only over tiles a human or a probe has walked; a map change -re-runs every checkpoint listed on it. The decomp comparison that found the 3/4 +re-runs every checkpoint listed on it. Scenes' trigger rectangles come from the +decomp too (the events files' coord events: Diamond's binaries parsed by hand, +Platinum's JSON readable), listed in `Segment00Lines::scene_triggers()` for +00.01 to 00.03; a line into a scene must step into its rectangle on its last +tile only, which the Segment 00 tests check. The decomp comparison that found the 3/4 rows is the 2026-10-31 report (`compare.md`, with the decoded grids), to be checked in with the re-derivation. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp new file mode 100644 index 0000000000..ffbb406719 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp @@ -0,0 +1,95 @@ +/* BDSP AutoStory - Oreburgh Gym tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_OreburghGym.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace OreburghGym{ + +using namespace Pokemon; + + +// Map source: the decomp (Diamond land_data 0228, 2026-10-31) with the +// objects from its events file. +// Console checks: none yet. 01.04 walks it as a record (north until a +// trainer stops us), not as a plan. +// Status: no checkpoint passes on this grid yet. +// +// Decoded from Pokemon Diamond's collision table for this map (the +// pret/pokediamond decompilation, +// files/fielddata/land_data/land_data_release/narc_0228: the only cell of +// matrix 113, at column 0, row 0; MAP_OREBURGH_GYM in +// include/constants/maps.h), with the objects from its events file +// (zone_event narc_0046, events_oreburgh_gym.json in Platinum); BDSP keeps +// Diamond/Pearl's layout. Local (x, y) = world (x - 0, z - 0) in the Gym's +// own matrix; 32 x 32 tiles, of which the floor is columns 1 to 10, rows 3 +// to 24. The tiers' edges and the pillars are '#'. +// Door: (5, 24), walked into heading south to leave; coming in puts us on +// (5, 23). Column 5 runs straight from there to Roark on row 3: the Gym is +// walked north up the middle. Objects, from the events file: +// Roark (5, 3), looks south; +// Gym Guide (6, 23), looks south, beside the entrance; +// Youngster (4, 18), looks east, sees 3: (5..7, 18); +// Youngster (7, 11), looks west, sees 4: (3..6, 11); +// the two wall signs, (3, 23) and (7, 23), read from row 23: 'S'. +// Both trainers see the middle column, so a walk north from the entrance +// is stopped twice before Roark (01.04's record). +const TileGrid& grid(){ + static const TileGrid grid({ + // 0 1 2 3 + R"(################################)", // 0 + R"(################################)", // 1 + R"(################################)", // 2 + R"(#....N.....#####################)", // 3 + R"(#..........#####################)", // 4 + R"(#..........#####################)", // 5 + R"(#..##.##...#####################)", // 6 + R"(#..........#####################)", // 7 + R"(#..##.##...#####################)", // 8 + R"(#..........#####################)", // 9 + R"(#..........#####################)", // 10 + R"(###....N#.######################)", // 11 + R"(#..........#####################)", // 12 + R"(#####.##...#####################)", // 13 + R"(#####.##...#####################)", // 14 + R"(#..........#####################)", // 15 + R"(#..........#####################)", // 16 + R"(#..........#####################)", // 17 + R"(#...N......#####################)", // 18 + R"(##.#....########################)", // 19 + R"(##.#....########################)", // 20 + R"(#..........#####################)", // 21 + R"(#..#...#...#####################)", // 22 + R"(#..S..NS...#####################)", // 23 + R"(#....D.....#####################)", // 24 + R"(################################)", // 25 + R"(################################)", // 26 + R"(################################)", // 27 + R"(################################)", // 28 + R"(################################)", // 29 + R"(################################)", // 30 + R"(################################)", // 31 + }); + return grid; +} + +const TilePos ENTRANCE{5, 23}; +const TilePos ROARK{5, 3}; + +std::vector trainer_sights(){ + return { + {"Youngster (first tier)", {4, 18}, Direction::EAST, 3}, + {"Youngster (second tier)", {7, 11}, Direction::WEST, 4}, + }; +} + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.h new file mode 100644 index 0000000000..2cb6dc8489 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.h @@ -0,0 +1,38 @@ +/* BDSP AutoStory - Oreburgh Gym tiles + * + * From: https://github.com/PokemonAutomation/ + * + * The Gym's inside, decoded from the Pokemon Diamond decompilation + * (pret/pokediamond); see the .cpp's header for the cell, the offset and + * the objects. For checkpoint 01.04's walk up to Roark. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_OreburghGym_H +#define PokemonAutomation_PokemonBDSP_AutoStory_OreburghGym_H + +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace OreburghGym{ + + +const Pokemon::TileGrid& grid(); + +// Where coming in through the door puts us: the tile above it, beside the +// Gym Guide. Roark stands at the top of the same column. +extern const Pokemon::TilePos ENTRANCE; +extern const Pokemon::TilePos ROARK; + +// The two Youngsters, who face the column up the middle from either side: +// walking north from the entrance meets both. +std::vector trainer_sights(); + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp index 3c1e8c6df4..1341b81182 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp @@ -10,7 +10,12 @@ #include "PokemonBDSP_AutoStory_Route204.h" #include "PokemonBDSP_AutoStory_RavagedPath.h" #include "PokemonBDSP_AutoStory_OreburghCity.h" +#include "PokemonBDSP_AutoStory_OreburghGym.h" #include "PokemonBDSP_AutoStory_FloaromaTown.h" +#include "PokemonBDSP_AutoStory_SandgemTown.h" +#include "PokemonBDSP_AutoStory_Segment00Lines.h" +#include "PokemonBDSP_AutoStory_TwinleafTown.h" +#include "PokemonBDSP_AutoStory_VerityLakefront.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -20,30 +25,82 @@ namespace RouteRecords{ using namespace Pokemon; namespace{ +const TileGrid* twinleaf(){ return &TwinleafTown::grid(); } +const TileGrid* route201_decomp(){ return &Segment00Lines::route201_decomp_grid(); } +const TileGrid* lakefront(){ return &VerityLakefront::grid(); } +const TileGrid* sandgem(){ return &SandgemTown::grid(); } const TileGrid* jubilife(){ return &JubilifeCity::grid(); } const TileGrid* route203(){ return &Route203::grid(); } const TileGrid* ravaged_path(){ return &RavagedPath::grid(); } const TileGrid* route204_north(){ return &Route204::north_grid(); } const TileGrid* oreburgh_city(){ return &OreburghCity::grid(); } +const TileGrid* oreburgh_gym(){ return &OreburghGym::grid(); } const TileGrid* floaroma(){ return &FloaromaTown::grid(); } -const TileGrid* none(){ return nullptr; } + +// 00.01: the house, Twinleaf, Route 201 and the Lakefront out to the lake. +std::vector checkpoint_0001_records(){ + return { + {"00.01", "The house's doorstep to Barry's door", "Twinleaf Town", twinleaf, true, Segment00Lines::HOUSE_DOORSTEP, { + {Direction::WEST, 7, LegEnd::COUNT, "along row 22 to column 13, clear of the south-west house"}, + {Direction::NORTH, 10, LegEnd::COUNT, "up column 13 to row 12, below Barry's mailbox"}, + {Direction::WEST, 4, LegEnd::COUNT, "onto (9, 12), the one tile that starts Barry's scene: he bursts out of his door"}, + {Direction::NORTH, 1, LegEnd::DOOR, "after the scene, into Barry's house; the stairs, his room and the way back out are replays"}, + }, "Segment00Lines line 1, not walked by the program yet; the Twinleaf grid and the scene's tile from the Diamond decomp (land_data 0000, zone_event 0389)"}, + {"00.01", "Barry's doorstep to Route 201", "Twinleaf Town", twinleaf, true, Segment00Lines::BARRY_DOORSTEP, { + {Direction::EAST, 6, LegEnd::COUNT, "along row 12 to column 15"}, + {Direction::NORTH, 12, LegEnd::COUNT, "up column 15 to (15, 0), the last tile in town; the guitarist's stop on row 3 is inert once Barry has talked upstairs"}, + {Direction::NORTH, 0, LegEnd::BANNER, "on north onto Route 201"}, + }, "Segment00Lines line 2, not walked by the program yet"}, + {"00.01", "Route 201: Barry's tall-grass warning, then west to the Lakefront", "Route 201", route201_decomp, true, Segment00Lines::ROUTE_201_ARRIVAL, { + {Direction::NORTH, 6, LegEnd::COUNT, "up the exit path to (15, 25): Barry's warning fires on that row"}, + {Direction::WEST, 3, LegEnd::COUNT, "after the scene, along row 25 to column 12"}, + {Direction::NORTH, 2, LegEnd::COUNT, "to row 23, the lower level's row to the Lakefront"}, + {Direction::WEST, 12, LegEnd::COUNT, "to (0, 23), the route's last tile"}, + {Direction::WEST, 0, LegEnd::BANNER, "on west onto the Verity Lakefront"}, + }, "Segment00Lines lines 2 and 3, not walked by the program yet; traced on the decomp's Route 201 (route201_decomp_grid), not Route201::grid(), whose rows are the image's"}, + {"00.01", "Verity Lakefront: to below the lake's entrance", "Verity Lakefront", lakefront, true, Segment00Lines::LAKEFRONT_ARRIVAL, { + {Direction::WEST, 11, LegEnd::COUNT, "along row 23 to column 20"}, + {Direction::NORTH, 2, LegEnd::COUNT, "to row 21"}, + {Direction::WEST, 3, LegEnd::COUNT, "to column 17, the entrance path's east column"}, + {Direction::NORTH, 7, LegEnd::COUNT, "up column 17 to (17, 14), two tiles short of the lake's scene; 00.01 ends here"}, + }, "Segment00Lines line 3, not walked by the program yet"}, + }; } -// The walks planned on a grid (00.04 and 00.05's walk_route goals, 01.03's -// Mine legs, 01.06's Route 203 and Jubilife legs, 01.08's Route 204 South, -// 01.09's Ravaged Path, 01.10's waypoints) are data already, tested in -// PokemonBDSP_AutoStory_Tests.cpp; these are the rest. -// -// Not recorded, because they are not routes: 00.01 to 00.03 (the house, -// Twinleaf, Route 201, the Lakefront and the lake) replay the stick inputs -// Butters recorded for #1717 (tutorial_part_1_navigation, entry_visible, -// tutorial_part_2_navigation, starter_nav: timed holds, diagonals among -// them, and "move until transition"). No tile count can be read off them. -// They get redone as planned walks on the Twinleaf, Verity Lakefront and -// Lake Verity grids (decoded 2026-11-01) in the compact series; until then -// those grids carry no route and no trace. -const std::vector& all(){ - static const std::vector records{ +// 00.02 and 00.03: into the lake's scene, and back to Sandgem. +std::vector checkpoints_0002_0003_records(){ + return { + {"00.02", "Into the lake's scene", "Verity Lakefront", lakefront, true, Segment00Lines::BELOW_LAKE_ENTRANCE, { + {Direction::NORTH, 2, LegEnd::COUNT, "onto (17, 12): Barry hears Rowan and the two of us walk into Lake Verity"}, + {Direction::NORTH, 0, LegEnd::SCENE, "the starter, the Starly and the way back out to (17, 12) are the game's; nothing is walked at the lake"}, + }, "starter_nav() presses north twice from where 00.01 ends; Segment00Lines line 3's last two tiles; the scene's tiles from the Diamond decomp (zone_event 0319)"}, + {"00.03", "Verity Lakefront: from the lake's entrance back onto Route 201", "Verity Lakefront", lakefront, true, Segment00Lines::LAKE_ENTRANCE, { + {Direction::SOUTH, 9, LegEnd::COUNT, "down column 17 to row 21"}, + {Direction::EAST, 12, LegEnd::COUNT, "along row 21 to column 29"}, + {Direction::EAST, 0, LegEnd::BANNER, "on east onto Route 201"}, + }, "Segment00Lines line 4, not walked by the program yet; which of the two entrance tiles the scene leaves us on is for the console"}, + {"00.03", "Route 201: Rowan's scene, then east through the grass to Sandgem", "Route 201", route201_decomp, true, Segment00Lines::ROUTE_201_RETURN, { + {Direction::EAST, 5, LegEnd::COUNT, "to (5, 21): Rowan and Dawn's scene fires on that column"}, + {Direction::EAST, 12, LegEnd::COUNT, "after the scene, along row 21 to column 17"}, + {Direction::EAST, 12, LegEnd::COUNT, "through the tall grass to column 29; the Breeder wanders rows 21 to 23 there"}, + {Direction::EAST, 12, LegEnd::COUNT, "to column 41"}, + {Direction::NORTH, 7, LegEnd::COUNT, "up column 41 to row 14, beside the north-east grass"}, + {Direction::EAST, 1, LegEnd::COUNT, "into the grass"}, + {Direction::NORTH, 2, LegEnd::COUNT, "to row 12"}, + {Direction::EAST, 10, LegEnd::COUNT, "through the grass to (52, 12), its last tile"}, + {Direction::EAST, 11, LegEnd::COUNT, "to (63, 12), the route's last tile"}, + {Direction::EAST, 0, LegEnd::BANNER, "on east into Sandgem Town"}, + }, "Segment00Lines lines 4 and 5, not walked by the program yet; the grass legs need the wild-battle handling of the replay's walk_through_grass(); traced on route201_decomp_grid"}, + {"00.03", "Sandgem Town: Dawn at the entrance", "Sandgem Town", sandgem, true, Segment00Lines::SANDGEM_ARRIVAL, { + {Direction::EAST, 4, LegEnd::COUNT, "along row 8 to (4, 8): Dawn's scene, which leads us into Rowan's lab for the Pokedex"}, + {Direction::EAST, 0, LegEnd::SCENE, "the lab is the game's; 00.03 ends in front of Rowan"}, + }, "Segment00Lines line 5, not walked by the program yet; Sandgem's row 8 is the decomp's row 12, where its coord event (zone_event 0396) is"}, + }; +} + +// 01.01 to 01.05: Jubilife to Oreburgh and back out. +std::vector segment01_records_to_oreburgh(){ + return { {"01.01", "Jubilife Pokemon Center to Barry on Route 203", "Jubilife City", jubilife, false, std::nullopt, { {Direction::SOUTH, 0, LegEnd::NPC, "out of the Center's door; a girl below it stops us"}, {Direction::WEST, 4, LegEnd::COUNT, "stick 720 ms: onto the main road", false}, @@ -62,9 +119,9 @@ const std::vector& all(){ {Direction::WEST, 20, LegEnd::COUNT, "D-pad taps along the Center's row to below the Gym's door"}, {Direction::NORTH, 1, LegEnd::DOOR, "into the Gym (the fade)"}, }, "oreburgh_street_to_gym(); 20 taps measured on the console (r204 to r215, 3 runs on the same tile); the decomp's Center door is at x 47, the taps say the doorstep is x 46"}, - {"01.04", "Inside the Oreburgh Gym", "", none, false, std::nullopt, { - {Direction::NORTH, 0, LegEnd::NPC, "up the Gym to its trainers and Roark"}, - }, "oreburgh_gym_battles(); no grid for the Gym's inside"}, + {"01.04", "Inside the Oreburgh Gym", "Oreburgh Gym", oreburgh_gym, true, OreburghGym::ENTRANCE, { + {Direction::NORTH, 0, LegEnd::NPC, "up column 5 from the entrance to Roark on row 3; the Youngsters at (4, 18) and (7, 11) see the column and stop us on rows 18 and 11 on the way"}, + }, "oreburgh_gym_battles(); the Gym's grid from the Diamond decomp (land_data 0228), its trainers and their sight from the events file (zone_event 0046)"}, {"01.05", "Oreburgh Gym to the Gate and out onto Route 203", "Oreburgh City", oreburgh_city, true, OreburghCity::GYM_DOORSTEP, { {Direction::EAST, 20, LegEnd::COUNT, "D-pad taps from the Gym's doorstep back to the Center's door"}, {Direction::WEST, 0, LegEnd::WALL, "to the stairs' cliff"}, @@ -76,6 +133,12 @@ const std::vector& all(){ {Direction::WEST, 0, LegEnd::TRANSITION, "into the Oreburgh Gate (a row probed when a wall comes first)"}, {Direction::WEST, 0, LegEnd::BANNER, "through the Gate until Route 203's banner"}, }, "oreburgh_gym_to_center(), oreburgh_to_route203(); the Center visit between the two taps legs is not a walk"}, + }; +} + +// 01.07 to 01.11: Jubilife north to Floaroma. +std::vector segment01_records_from_jubilife(){ + return { {"01.07", "Jubilife's east edge to Rowan's scene", "Jubilife City", jubilife, false, std::nullopt, { {Direction::WEST, 14, LegEnd::COUNT, "stick 2 x 1120 ms along the long road to the crossroads with the north street", false}, {Direction::NORTH, 0, LegEnd::SCENE, "up the street until Rowan's scene starts (about 6 s); the green-haired man may stand in the way"}, @@ -97,6 +160,34 @@ const std::vector& all(){ {Direction::NORTH, 0, LegEnd::NPC, "until the old man stops us (a turn)"}, }, "floaroma_old_couple(); by hand 2026-10-31 (batches m1 to m9), r251a"}, }; +} + +} + +// The walks planned on a grid (00.04 and 00.05's walk_route goals, 01.03's +// Mine legs, 01.06's Route 203 and Jubilife legs, 01.08's Route 204 South, +// 01.09's Ravaged Path, 01.10's waypoints) are data already, tested in +// PokemonBDSP_AutoStory_Tests.cpp; these are the rest. +// +// 00.01 to 00.03 (the house, Twinleaf, Route 201, the Lakefront and the +// lake) still replay the stick inputs Butters recorded for #1717 +// (tutorial_part_1_navigation, entry_visible, tutorial_part_2_navigation, +// starter_nav: timed holds, diagonals among them, and "move until +// transition"), off which no tile count can be read. Their records below +// are the same walks as lines on the decomp grids +// (Data/PokemonBDSP_AutoStory_Segment00Lines, task #22), legs the program +// does not walk yet: a new-game run has to confirm where each scene leaves +// the player before Segment_00 switches to them. The house interiors (the +// player's, Barry's) have no grid and stay replays. +const std::vector& all(){ + static const std::vector records = []{ + std::vector all; + for (auto part : {checkpoint_0001_records, checkpoints_0002_0003_records, segment01_records_to_oreburgh, segment01_records_from_jubilife}){ + const std::vector records = part(); + all.insert(all.end(), records.begin(), records.end()); + } + return all; + }(); return records; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp new file mode 100644 index 0000000000..2778041b8e --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp @@ -0,0 +1,238 @@ +/* BDSP AutoStory - Segment 00's walked lines + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonBDSP_AutoStory_SandgemTown.h" +#include "PokemonBDSP_AutoStory_StoryMaps.h" +#include "PokemonBDSP_AutoStory_TwinleafTown.h" +#include "PokemonBDSP_AutoStory_VerityLakefront.h" +#include "PokemonBDSP_AutoStory_Segment00Lines.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Segment00Lines{ + +using namespace Pokemon; + + +const char* const MAP_TWINLEAF_TOWN = "Twinleaf Town"; +const char* const MAP_VERITY_LAKEFRONT = "Verity Lakefront"; + + +// Offsets are the decomp's world coordinates of each map's tile (0, 0): +// the Sinnoh matrix's cells are 32 tiles square, the Lakefront is cell +// (column 2, row 26), Route 201 cells (3..4, 26), Twinleaf (3, 27) and +// Sandgem (5, 26). SandgemTown::grid()'s rows are the game's from row 7 +// on, each the decomp's row less 4 (its header), so it sits 4 rows lower +// than its cell; the lines touch only its row 8. +const MapSet& segment00_maps(){ + static const MapSet maps = []{ + MapSet maps; + maps.add(MAP_TWINLEAF_TOWN, TwinleafTown::grid(), {96, 864}); + maps.add(MAP_ROUTE_201, route201_decomp_grid(), {96, 832}); + maps.add(MAP_VERITY_LAKEFRONT, VerityLakefront::grid(), {64, 832}); + maps.add(MAP_SANDGEM_TOWN, SandgemTown::grid(), {160, 836}); + return maps; + }(); + return maps; +} + + +// From the Diamond decomp's coord events (zone_event narc_0389 Twinleaf, +// 0327 Route 201, 0319 Verity Lakefront, 0396 Sandgem; Lake Verity's +// narc_0298 has none: its scene is the map's own script, run on arrival). +// Each is a rectangle in world tiles with the story variable and value it +// fires at; Platinum's readable events files name the variables and carry +// the same rectangles for Twinleaf and the Lakefront. Listed as local +// tiles of our grids. Not here, having no grid: the player's house's door +// tile (6, 10), where Mom's warning fires on the way out (narc_0392, value +// 1). +const std::vector& scene_triggers(){ + static const std::vector triggers{ + {"Barry's door", MAP_TWINLEAF_TOWN, {9, 12}, 1, 1, + "before Barry has burst out of his house (var 0x40e6 = 0)"}, + {"the guitarist stops us leaving", MAP_TWINLEAF_TOWN, {12, 3}, 8, 1, + "between Barry's door and his talk upstairs (var 0x4070 = 1; 2 after it)"}, + {"Barry's tall-grass warning", MAP_ROUTE_201, {14, 25}, 6, 1, + "the first time north of Twinleaf (var 0x4086 = 0)"}, + {"Route 201's row 26 after the warning", MAP_ROUTE_201, {14, 26}, 6, 1, + "after the warning and before the lake (var 0x4086 = 1); its script is Diamond's binary, not read"}, + {"Rowan and Dawn on the way back", MAP_ROUTE_201, {5, 21}, 1, 3, + "after the lake (var 0x4086 = 2)"}, + {"Barry at the lake's entrance", MAP_VERITY_LAKEFRONT, {16, 12}, 2, 1, + "the first visit (var 0x4082 = 0): he hears Rowan and the two walk into Lake Verity; the same tiles fire again at 3, later in the story"}, + {"Dawn at Sandgem's entrance", MAP_SANDGEM_TOWN, {4, 7}, 1, 5, + "the first time in from Route 201 (var 0x4071 = 0): she leads us to Rowan's lab"}, + }; + return triggers; +} + +bool trigger_covers(const SceneTrigger& trigger, const MapTile& tile){ + return tile.map == trigger.map && + tile.pos.x >= trigger.corner.x && tile.pos.x < trigger.corner.x + trigger.width && + tile.pos.y >= trigger.corner.y && tile.pos.y < trigger.corner.y + trigger.height; +} + + +const TilePos HOUSE_DOORSTEP{20, 22}; +const TilePos BARRY_DOORSTEP{9, 12}; +const TilePos TWINLEAF_NORTH_EXIT{15, 0}; +const TilePos ROUTE_201_ARRIVAL{15, 31}; +const TilePos BARRY_WARNING{15, 25}; +const TilePos LAKEFRONT_ARRIVAL{31, 23}; +const TilePos BELOW_LAKE_ENTRANCE{17, 14}; +const TilePos LAKE_ENTRANCE{17, 12}; +const TilePos ROUTE_201_RETURN{0, 21}; +const TilePos ROWAN_STOP{5, 21}; +const TilePos ROUTE_201_EAST_END{63, 12}; +const TilePos SANDGEM_ARRIVAL{0, 8}; +const TilePos DAWN_STOP{4, 8}; + +// Corners are chosen on the maps' features (a row clear of the houses, +// the exit path, a map's last tile, the tile a scene fires on); where a +// straight run is longer than the planner's 12-tile open leg (the row +// through the Lakefront, the row along Route 201) it is split at the +// twelfth tile. The lower level of Route 201 (rows 20 to 23) is the way +// both to and from the lake: the upper level's ledges only drop onto it. +// Row 23 is used westward and row 21 eastward: on the way out Rowan and +// the counterpart are not yet on (8, 21..22) and Barry is gone from (16, +// 23), but 23 keeps the line one row off the Breeder's range; on the way +// back 21 reaches Rowan's column with the fewest corners. +// +// What a new-game run must confirm before the segment switches to these: +// where each scene leaves the player (Barry's warning and Rowan's scene +// are assumed to leave us on the trigger tile; the lake's scene to warp +// us back onto (17, 12), the right-hand entrance tile, facing south), and +// that the stretches through tall grass are walked with the wild-battle +// handling the replay's walk_through_grass() has, which walk_waypoints() +// does not. +namespace{ +// Corners on each map, and a line from them: parentheses keep the table +// flat enough for the code-health linter's brace limit. +MapTile twinleaf(const TilePos& pos){ return {MAP_TWINLEAF_TOWN, pos}; } +MapTile route201(const TilePos& pos){ return {MAP_ROUTE_201, pos}; } +MapTile lakefront(const TilePos& pos){ return {MAP_VERITY_LAKEFRONT, pos}; } +MapTile sandgem(const TilePos& pos){ return {MAP_SANDGEM_TOWN, pos}; } +WalkedLine walked( + std::string checkpoint, std::string name, std::vector corners, + std::string ends_in, std::vector live_triggers +){ + return {std::move(checkpoint), std::move(name), std::move(corners), std::move(ends_in), std::move(live_triggers)}; +} +} + +const std::vector& lines(){ + static const std::vector lines{ + walked("00.01", "the house's doorstep to Barry's door", { + twinleaf(HOUSE_DOORSTEP), twinleaf({13, 22}), twinleaf({13, 12}), twinleaf(BARRY_DOORSTEP), + }, "Barry's door", {"Barry's door"}), + walked("00.01", "Barry's doorstep to Route 201", { + twinleaf(BARRY_DOORSTEP), twinleaf({15, 12}), twinleaf(TWINLEAF_NORTH_EXIT), route201(BARRY_WARNING), + }, "Barry's tall-grass warning", {"Barry's tall-grass warning"}), + walked("00.01", "Route 201's west half to the lake's entrance", { + route201(BARRY_WARNING), route201({12, 25}), route201({12, 23}), route201({0, 23}), + lakefront({20, 23}), lakefront({20, 21}), lakefront({17, 21}), lakefront(LAKE_ENTRANCE), + }, "Barry at the lake's entrance", {"Barry at the lake's entrance", "Route 201's row 26 after the warning"}), + walked("00.03", "the lake's entrance back to Rowan", { + lakefront(LAKE_ENTRANCE), lakefront({17, 21}), lakefront({29, 21}), route201(ROWAN_STOP), + }, "Rowan and Dawn on the way back", {"Rowan and Dawn on the way back"}), + walked("00.03", "Rowan to Dawn at Sandgem's entrance", { + route201(ROWAN_STOP), route201({17, 21}), route201({29, 21}), route201({41, 21}), + route201({41, 14}), route201({42, 14}), route201({42, 12}), route201({52, 12}), + route201(ROUTE_201_EAST_END), sandgem(DAWN_STOP), + }, "Dawn at Sandgem's entrance", {"Dawn at Sandgem's entrance"}), + }; + return lines; +} + + +// Last in the file so the rows' odd count of tall-grass quotes does not +// upset the code-health linter's measure of the functions after it (lizard +// reads R"(...)" rows as ordinary string literals). +// Map source: the decomp (Diamond land_data 0005 and 0006, 2026-10-31) +// with the objects from its events file. +// Console checks: none on these rows. Route201::grid() carries the console +// anchors (the north-east ledge row, the Twinleaf and Sandgem gaps). +// Status: a stand-in for the Segment 00 lines until Route201::grid() is the +// decomp's (bdsp/maps-rederive); no checkpoint runs on it. +// +// Decoded from Pokemon Diamond's collision table for this map (the +// pret/pokediamond decompilation, two cells of the Sinnoh matrix: +// files/fielddata/land_data/land_data_release/narc_0005 (column 3, row 26) +// and narc_0006 (column 4, row 26)), with the objects from its events file +// (zone_event narc_0327, events_route_201.json in Platinum); BDSP keeps +// Diamond/Pearl's layout. Local (x, y) = world (x - 96, z - 832); 64 x 32 +// tiles. Twinleaf Town is the cell below (its row 0 is this map's row 32, +// its exit columns 12 to 19 meet the path at columns 14 to 17); the Verity +// Lakefront is the cell to the west (its column 31 is this map's column +// -1, open on rows 14 to 18 and 20 to 23); Sandgem Town the cell to the +// east (its column 0 is this map's column 64, open on rows 11 to 15). +// The ledges on row 19, 'v', drop south from the upper level (rows 14 to +// 18) to the lower (rows 20 to 25): the lower level's only way east is +// through the tall grass (20..29, 20..23), and its way back up is the gap +// at (32..39, 19). The north-east grass, (42..52, 10..13) and (42..50, +// 14..19), is the way into Sandgem from the west. Objects, from the events +// file: +// arrow signposts (13, 24) and (55, 11), trainer tips signpost (40, 19): +// 'S'; +// Cashier M (44, 10), looks south and east, not a trainer (the Potions): +// 'N'; +// School Kid M (57, 15), looks west, not a trainer: 'N'; +// Pokemon Breeder M wanders around (27, 22), columns 26 to 28, rows 21 +// to 23: off the grid, the walker waits for him; +// Lass wanders west and east from (46, 23), columns 44 to 48, row 23: +// off the grid. +// The scene actors are hidden until their scene and gone after it, and +// each scene fires before its actors' tiles are reached (the triggers are +// in scene_triggers()), so their tiles are open ground here, not 'N': +// Barry (16, 23) (the tall-grass warning, flag 400), Prof. Rowan (8, 21) +// and the counterpart (8, 22) (the way back, flags 406 and 407). +// No trainers. +const TileGrid& route201_decomp_grid(){ + static const TileGrid grid({ + // 0 1 2 3 4 5 6 + // 0123456789012345678901234567890123456789012345678901234567890123 + R"(################################################################)", // 0 + R"(################################################################)", // 1 + R"(################################################################)", // 2 + R"(################################################################)", // 3 + R"(################################################################)", // 4 + R"(################################################################)", // 5 + R"(################################################################)", // 6 + R"(################################################################)", // 7 + R"(################################################################)", // 8 + R"(################################################################)", // 9 + R"(##########################################""N""""""""...........)", // 10 + R"(##########################################"""""""""""..S........)", // 11 + R"(##########################################"""""""""""...........)", // 12 + R"(##########################################"""""""""""...........)", // 13 + R"(....####..........######..##....##..####.."""""""""##...........)", // 14 + R"(....####..........######..##....##..####.."""""""""##....N......)", // 15 + R"(##........####............................"""""""""##vvvvv######)", // 16 + R"(##........####............................"""""""""##.....######)", // 17 + R"(.........................................."""""""""##.....######)", // 18 + R"(vvvv####vvvvvvvvvvvvvvvvvvvvvvvv........S."""""""""##.....######)", // 19 + R"(....####............""""""""""............................######)", // 20 + R"(....................""""""""""............................######)", // 21 + R"(....................""""""""""............................######)", // 22 + R"(....................""""""""""............................######)", // 23 + R"(########.....S......##########............................######)", // 24 + R"(########............##########............""""""""""""""""######)", // 25 + R"(##############....############################""""""""""""######)", // 26 + R"(##############....############################""""""""""""######)", // 27 + R"(##############....##############################################)", // 28 + R"(##############....##############################################)", // 29 + R"(##############....##############################################)", // 30 + R"(##############....##############################################)", // 31 + }); + return grid; +} + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h new file mode 100644 index 0000000000..4b6b1e01e9 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h @@ -0,0 +1,90 @@ +/* BDSP AutoStory - Segment 00's walked lines + * + * From: https://github.com/PokemonAutomation/ + * + * Checkpoints 00.01 to 00.03 (the house, Twinleaf, Route 201, the Verity + * Lakefront, the lake, and back to Sandgem) replay recorded stick holds + * today. These are the same walks as lines on the grids: corner to corner, + * each stretch one straight leg, ending on the tile that starts the next + * scene. The scenes' trigger rectangles come from the Diamond decomp's + * events files, so a test can show each line steps into its scene on its + * last tile and not before. Nothing runs them on the console yet (task + * #22); the segment keeps its replays until a new-game run has checked + * the lines. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Segment00Lines_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Segment00Lines_H + +#include +#include +#include "Pokemon/Navigation/Pokemon_MapSet.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Segment00Lines{ + + +// Map names in segment00_maps(); Route 201 and Sandgem Town go by +// StoryMaps' MAP_ROUTE_201 and MAP_SANDGEM_TOWN. +extern const char* const MAP_TWINLEAF_TOWN; +extern const char* const MAP_VERITY_LAKEFRONT; + +// Route 201 as the Diamond decomp has it. A stand-in for Route201::grid(), +// which is traced from the DP image (rows 3/4 of a tile) and is being +// re-derived; the lines here need the game's rows. Drop it for +// Route201::grid() once that file is the decomp's. +const Pokemon::TileGrid& route201_decomp_grid(); + +// Twinleaf Town, Route 201, the Verity Lakefront and Sandgem Town joined on +// one grid at their world offsets from the decomp. Lake Verity is not in +// it: its own matrix, and the scene walks us in and the game warps us out, +// so no line is walked there. +const Pokemon::MapSet& segment00_maps(); + +// A rectangle of tiles that starts a scene when the player steps in while +// the story is in `when`. From the decomp's coord events, as local tiles. +struct SceneTrigger{ + std::string name; + std::string map; + Pokemon::TilePos corner; // north-west tile + int width; + int height; + std::string when; // the story state it fires in +}; +const std::vector& scene_triggers(); +bool trigger_covers(const SceneTrigger& trigger, const Pokemon::MapTile& tile); + +// A line walked corner to corner: every stretch between two corners is one +// straight open leg (whole tiles, as the D-pad walks them). +struct WalkedLine{ + std::string checkpoint; + std::string name; + std::vector corners; // the first is where the line starts + std::string ends_in; // the scene the last corner steps into, "" for none + std::vector live_triggers; // the scenes armed while this line is walked +}; +const std::vector& lines(); + +// Named tiles on the lines, where the route records start and end. +extern const Pokemon::TilePos HOUSE_DOORSTEP; // Twinleaf: below the player's door +extern const Pokemon::TilePos BARRY_DOORSTEP; // Twinleaf: below Barry's door; his scene's tile +extern const Pokemon::TilePos TWINLEAF_NORTH_EXIT; // Twinleaf: the last tile before Route 201 +extern const Pokemon::TilePos ROUTE_201_ARRIVAL; // Route 201: the first tile north of Twinleaf +extern const Pokemon::TilePos BARRY_WARNING; // Route 201: Barry's tall-grass warning +extern const Pokemon::TilePos LAKEFRONT_ARRIVAL; // Lakefront: the first tile west of Route 201 +extern const Pokemon::TilePos BELOW_LAKE_ENTRANCE; // Lakefront: two tiles short of the lake's scene +extern const Pokemon::TilePos LAKE_ENTRANCE; // Lakefront: the lake's scene; where it leaves us +extern const Pokemon::TilePos ROUTE_201_RETURN; // Route 201: the first tile east of the Lakefront +extern const Pokemon::TilePos ROWAN_STOP; // Route 201: Rowan and Dawn's scene +extern const Pokemon::TilePos ROUTE_201_EAST_END; // Route 201: the last tile before Sandgem +extern const Pokemon::TilePos SANDGEM_ARRIVAL; // Sandgem: the first tile east of Route 201 +extern const Pokemon::TilePos DAWN_STOP; // Sandgem: Dawn's scene + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp new file mode 100644 index 0000000000..6256a5e6dd --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp @@ -0,0 +1,266 @@ +/* BDSP AutoStory Segment 00 Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/Navigation/Pokemon_MapSet.h" +#include "Pokemon/Navigation/Pokemon_TileGrid.h" +#include "Data/PokemonBDSP_AutoStory_OreburghGym.h" +#include "Data/PokemonBDSP_AutoStory_Segment00Lines.h" +#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" +#include "Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "PokemonBDSP_AutoStory_Segment00_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +using Pokemon::Direction; +using Pokemon::MapSet; +using Pokemon::MapTile; +using Pokemon::TileGrid; +using Pokemon::TilePos; +using Pokemon::TileType; +using Segment00Lines::SceneTrigger; +using Segment00Lines::WalkedLine; + +std::string describe(const MapTile& tile){ + return tile.map + " " + Pokemon::to_string(tile.pos); +} + +const SceneTrigger* find_trigger(const std::string& name){ + for (const SceneTrigger& trigger : Segment00Lines::scene_triggers()){ + if (trigger.name == name){ + return &trigger; + } + } + return nullptr; +} + +// Plans one stretch of a line with the waypoint costs and returns the leg, +// or an error. The stretch must be the one straight leg a human took: to a +// wall or open, as the grid has it, ending exactly on the corner. +struct Stretch{ + Pokemon::TileLeg leg; + std::string error; +}; +Stretch plan_stretch(const MapSet& maps, const TilePos& from, const TilePos& to, const std::string& name){ + const auto plan = Pokemon::plan_robust_route(maps.world(), std::vector{from}, + [&](const TilePos& pos){ return pos == to; }, waypoint_plan_costs()); + if (!plan){ + return {{}, name + ": no plan."}; + } + if (plan->size() != 1){ + std::string text = name + ": " + std::to_string(plan->size()) + " legs, expected the one straight leg:"; + for (const Pokemon::PlannedLeg& leg : *plan){ + text += " " + to_string(leg.leg); + } + return {{}, text}; + } + const Pokemon::PlannedLeg& leg = (*plan)[0]; + if (leg.after.size() != 1 || !(leg.after[0] == to)){ + return {{}, name + ": the leg " + to_string(leg.leg) + " does not end exactly on the corner."}; + } + return {leg.leg, ""}; +} + +// Every tile a line stands on, its start first, as local tiles; logs each +// stretch's leg. Empty with `error` set when a stretch does not plan. +std::vector line_tiles(Logger& logger, const MapSet& maps, const WalkedLine& line, std::string& error){ + const std::string name = line.checkpoint + " " + line.name; + std::vector tiles{line.corners[0]}; + TilePos at = maps.to_world(line.corners[0].map, line.corners[0].pos); + std::string text = name + ": from " + describe(line.corners[0]); + for (size_t i = 1; i < line.corners.size(); i++){ + const MapTile& corner = line.corners[i]; + const TilePos goal = maps.to_world(corner.map, corner.pos); + const Stretch stretch = plan_stretch(maps, at, goal, name + " stretch " + std::to_string(i) + " to " + describe(corner)); + if (!stretch.error.empty()){ + error = stretch.error; + return {}; + } + text += "\n " + to_string(stretch.leg) + " to " + describe(corner); + for (size_t k = 0; k < stretch.leg.tiles; k++){ + at = at.next(stretch.leg.direction); + const std::optional local = maps.to_local(at); + if (!local){ + error = name + ": the line leaves the maps at " + Pokemon::to_string(at) + "."; + return {}; + } + tiles.push_back(*local); + } + } + logger.log(text); + return tiles; +} + +// The last tile steps into the line's scene; no earlier tile is in any +// scene armed while the line is walked (an inert one is only logged). +std::string check_triggers(Logger& logger, const WalkedLine& line, const std::vector& tiles){ + const std::string name = line.checkpoint + " " + line.name; + for (const std::string& live : line.live_triggers){ + if (find_trigger(live) == nullptr){ + return name + ": no scene trigger named \"" + live + "\"."; + } + } + const auto armed = [&](const std::string& trigger){ + return std::ranges::find(line.live_triggers, trigger) != line.live_triggers.end(); + }; + if (!line.ends_in.empty() && !armed(line.ends_in)){ + return name + ": the scene it ends in, \"" + line.ends_in + "\", is not among its live triggers."; + } + for (size_t i = 0; i < tiles.size(); i++){ + for (const SceneTrigger& trigger : Segment00Lines::scene_triggers()){ + if (!Segment00Lines::trigger_covers(trigger, tiles[i])){ + continue; + } + const bool live = armed(trigger.name); + const bool last = i + 1 == tiles.size(); + logger.log(name + ": tile " + std::to_string(i + 1) + " of " + std::to_string(tiles.size()) + ", " + describe(tiles[i]) + + ", is in \"" + trigger.name + "\" (" + (live ? "armed" : "inert: " + trigger.when) + ")."); + if (live && !(last && trigger.name == line.ends_in)){ + return name + ": steps into the armed scene \"" + trigger.name + "\" at " + describe(tiles[i]) + ", before its end."; + } + } + } + if (!line.ends_in.empty() && !Segment00Lines::trigger_covers(*find_trigger(line.ends_in), tiles.back())){ + return name + ": its last tile " + describe(tiles.back()) + " is not in \"" + line.ends_in + "\"."; + } + return ""; +} + +// The tiles the route records start and end on, each of which must lie on +// one of the lines. +struct NamedTile{ + const char* name; + MapTile tile; +}; +std::vector named_tiles(){ + return { + {"HOUSE_DOORSTEP", {Segment00Lines::MAP_TWINLEAF_TOWN, Segment00Lines::HOUSE_DOORSTEP}}, + {"BARRY_DOORSTEP", {Segment00Lines::MAP_TWINLEAF_TOWN, Segment00Lines::BARRY_DOORSTEP}}, + {"TWINLEAF_NORTH_EXIT", {Segment00Lines::MAP_TWINLEAF_TOWN, Segment00Lines::TWINLEAF_NORTH_EXIT}}, + {"ROUTE_201_ARRIVAL", {MAP_ROUTE_201, Segment00Lines::ROUTE_201_ARRIVAL}}, + {"BARRY_WARNING", {MAP_ROUTE_201, Segment00Lines::BARRY_WARNING}}, + {"LAKEFRONT_ARRIVAL", {Segment00Lines::MAP_VERITY_LAKEFRONT, Segment00Lines::LAKEFRONT_ARRIVAL}}, + {"BELOW_LAKE_ENTRANCE", {Segment00Lines::MAP_VERITY_LAKEFRONT, Segment00Lines::BELOW_LAKE_ENTRANCE}}, + {"LAKE_ENTRANCE", {Segment00Lines::MAP_VERITY_LAKEFRONT, Segment00Lines::LAKE_ENTRANCE}}, + {"ROUTE_201_RETURN", {MAP_ROUTE_201, Segment00Lines::ROUTE_201_RETURN}}, + {"ROWAN_STOP", {MAP_ROUTE_201, Segment00Lines::ROWAN_STOP}}, + {"ROUTE_201_EAST_END", {MAP_ROUTE_201, Segment00Lines::ROUTE_201_EAST_END}}, + {"SANDGEM_ARRIVAL", {MAP_SANDGEM_TOWN, Segment00Lines::SANDGEM_ARRIVAL}}, + {"DAWN_STOP", {MAP_SANDGEM_TOWN, Segment00Lines::DAWN_STOP}}, + }; +} + +// The lines 00.01 to 00.03 would walk (Data/PokemonBDSP_AutoStory_Segment00Lines): +// every stretch plans as one straight leg on the decomp grids, and each +// line enters its scene's trigger rectangle on its last tile only. The +// named tiles the route records start from all lie on the lines. +class Test_Segment00Lines : public UnitTest{ +public: + Test_Segment00Lines() + : UnitTest("PokemonBDSP::AutoStory - Segment 00: the lines into each scene") + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const MapSet& maps = Segment00Lines::segment00_maps(); + for (const SceneTrigger& trigger : Segment00Lines::scene_triggers()){ + if (trigger.width <= 0 || trigger.height <= 0){ + return "Scene trigger \"" + trigger.name + "\" has no tiles."; + } + maps.to_world(trigger.map, trigger.corner); // throws for a map not in the set + } + std::vector walked; + for (const WalkedLine& line : Segment00Lines::lines()){ + if (line.corners.size() < 2){ + return line.checkpoint + " " + line.name + ": a line needs two corners."; + } + std::string error; + const std::vector tiles = line_tiles(logger, maps, line, error); + if (!error.empty()){ + return error; + } + error = check_triggers(logger, line, tiles); + if (!error.empty()){ + return error; + } + walked.insert(walked.end(), tiles.begin(), tiles.end()); + } + for (const NamedTile& tile : named_tiles()){ + const bool on_a_line = std::ranges::any_of(walked, [&](const MapTile& t){ + return t.map == tile.tile.map && t.pos == tile.tile.pos; + }); + if (!on_a_line){ + return std::string(tile.name) + " " + describe(tile.tile) + " is on none of the lines."; + } + } + return true; + } +}; + +// The Oreburgh Gym's inside (Data/PokemonBDSP_AutoStory_OreburghGym): the +// column up from the entrance runs to Roark with nothing in the way but the +// two Youngsters' sight lines, which is what 01.04's "north until a trainer +// stops us" relies on. +class Test_OreburghGymGrid : public UnitTest{ +public: + Test_OreburghGymGrid() + : UnitTest("PokemonBDSP::AutoStory - Oreburgh Gym: the column up to Roark") + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const TileGrid& gym = OreburghGym::grid(); + if (!gym.standable(OreburghGym::ENTRANCE)){ + return "The entrance tile is not standable."; + } + if (gym.at(OreburghGym::ENTRANCE.next(Direction::SOUTH)) != TileType::DOOR){ + return "The door is not below the entrance tile."; + } + if (gym.at(OreburghGym::ROARK) != TileType::NPC){ + return "Roark is not on an NPC tile."; + } + const Pokemon::WallHit up = Pokemon::walk_to_wall(gym, OreburghGym::ENTRANCE, Direction::NORTH); + if (!(up.wall == OreburghGym::ROARK)){ + return "North from the entrance stops at " + Pokemon::to_string(up.stop) + ", not in front of Roark."; + } + logger.log("Oreburgh Gym: north from the entrance walks " + std::to_string(up.tiles) + " tiles to Roark."); + for (const Pokemon::TrainerSight& trainer : OreburghGym::trainer_sights()){ + if (gym.at(trainer.pos) != TileType::NPC){ + return trainer.name + " is not on an NPC tile."; + } + const std::vector seen = Pokemon::sight_tiles(gym, trainer); + const bool sees_column = std::ranges::any_of(seen, [&](const TilePos& pos){ + return pos.x == OreburghGym::ENTRANCE.x && pos.y < OreburghGym::ENTRANCE.y && pos.y > OreburghGym::ROARK.y; + }); + if (!sees_column){ + return trainer.name + " does not see the column up to Roark."; + } + std::string text = "Oreburgh Gym: " + trainer.name + " sees"; + for (const TilePos& pos : seen){ + text += " " + Pokemon::to_string(pos); + } + logger.log(text); + } + return true; + } +}; + +} + + +void add_tests_AutoStory_Segment00(UnitTestDatabase& database){ + database.add(); + database.add(); +} + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h new file mode 100644 index 0000000000..a956b4073c --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h @@ -0,0 +1,27 @@ +/* BDSP AutoStory Segment 00 Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Segment00_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Segment00_Tests_H + +#include "Common/Cpp/TestRunners/UnitTest.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + + +// Offline checks of Segment 00's walked lines against the grids and the +// scenes' trigger rectangles, and of the Oreburgh Gym's inside. +void add_tests_AutoStory_Segment00(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StorySegments/PokemonBDSP_AutoStory_Segment_00.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StorySegments/PokemonBDSP_AutoStory_Segment_00.cpp index bcb9af0256..69f8773164 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StorySegments/PokemonBDSP_AutoStory_Segment_00.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StorySegments/PokemonBDSP_AutoStory_Segment_00.cpp @@ -175,9 +175,9 @@ namespace PokemonAutomation { stream.log("[DEBUG] Piplup Selection: Selection complete"); } - // Navigation functions for each part of the tutorial. These functions are meant to be used - // in order and rely on the state of the game being what it is at the end of the previous function. - // They may also be modified or removed without warning. + // Navigation functions for each part of the tutorial, used in order; each relies on the game state the one before left. + // TODO (task #22): they replay Butters' recorded stick holds; the same walks are lines on the decomp grids in Data/PokemonBDSP_AutoStory_Segment00Lines, + // tested offline with the route records. Swap in walk_waypoints() over Segment00Lines::lines() only after a new-game run has confirmed where each scene leaves the player, with walk_through_grass()'s battle handling on the Route 201 grass. // --------------------------------------------------------------------------- // Segment 00-01 begins diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h index 45b11164d2..3d53dcf980 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h @@ -16,6 +16,7 @@ #include #include #include "Common/Cpp/Time.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "Pokemon/Navigation/Pokemon_MapSet.h" diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index e80970e878..8766a3ca5d 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1557,6 +1557,10 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.h @@ -1564,6 +1568,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_NewGame.cpp From 6045574d31f0172fcdf91b2596511506605d52d1 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 09:32:56 -0800 Subject: [PATCH 2/2] BDSP maps: the Oreburgh Gym's grid is a JSON file too The Gym's grid, which this PR added, moves to OreburghGym.json like #111's maps (converted once, cell for cell); its C++ table goes and OreburghGym::grid() returns story_grid("OreburghGym"). bdsp_maps.py embeds it, and the test data is regenerated with it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonBDSP_AutoStory_Maps_TestData.cpp | 2 + .../PokemonBDSP_AutoStory_Maps_TestData_2.cpp | 71 +++++++++++++++++++ .../PokemonBDSP_AutoStory_OreburghGym.cpp | 38 +--------- devtools/maps/bdsp_maps.py | 2 + 4 files changed, 77 insertions(+), 36 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps_TestData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps_TestData.cpp index 0d836d47c5..9576b72729 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps_TestData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps_TestData.cpp @@ -28,6 +28,7 @@ extern const char* const TEST_MAP_JSON_Route204South; extern const char* const TEST_MAP_JSON_RavagedPath; extern const char* const TEST_MAP_JSON_Route204North; extern const char* const TEST_MAP_JSON_FloaromaTown; +extern const char* const TEST_MAP_JSON_OreburghGym; const std::vector>& test_map_json(){ @@ -47,6 +48,7 @@ const std::vector>& test_map_json(){ {"RavagedPath", TEST_MAP_JSON_RavagedPath}, {"Route204North", TEST_MAP_JSON_Route204North}, {"FloaromaTown", TEST_MAP_JSON_FloaromaTown}, + {"OreburghGym", TEST_MAP_JSON_OreburghGym}, }; return maps; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps_TestData_2.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps_TestData_2.cpp index 130ffd216c..70e99f02ef 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps_TestData_2.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps_TestData_2.cpp @@ -250,6 +250,77 @@ R"json({ } )json"; +extern const char* const TEST_MAP_JSON_OreburghGym = +R"json({ + "name": "OreburghGym", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp", + "revision": "ce701d495c94", + "date": "2026-11-01" + }, + "tiles": [ + "################################", + "################################", + "################################", + "#..........#####################", + "#..........#####################", + "#..........#####################", + "#..##.##...#####################", + "#..........#####################", + "#..##.##...#####################", + "#..........#####################", + "#..........#####################", + "###.....#.######################", + "#..........#####################", + "#####.##...#####################", + "#####.##...#####################", + "#..........#####################", + "#..........#####################", + "#..........#####################", + "#..........#####################", + "##.#....########################", + "##.#....########################", + "#..........#####################", + "#..#...#...#####################", + "#..S...S...#####################", + "#....D.....#####################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################" + ], + "objects": [ + { + "name": "npc_5_3", + "kind": "npc", + "x": 5, + "y": 3 + }, + { + "name": "npc_7_11", + "kind": "npc", + "x": 7, + "y": 11 + }, + { + "name": "npc_4_18", + "kind": "npc", + "x": 4, + "y": 18 + }, + { + "name": "npc_6_23", + "kind": "npc", + "x": 6, + "y": 23 + } + ] +} +)json"; + diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp index ffbb406719..915bdc1474 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp @@ -4,6 +4,7 @@ * */ +#include "PokemonBDSP_AutoStory_MapGrids.h" #include "PokemonBDSP_AutoStory_OreburghGym.h" namespace PokemonAutomation{ @@ -40,42 +41,7 @@ using namespace Pokemon; // Both trainers see the middle column, so a walk north from the entrance // is stopped twice before Roark (01.04's record). const TileGrid& grid(){ - static const TileGrid grid({ - // 0 1 2 3 - R"(################################)", // 0 - R"(################################)", // 1 - R"(################################)", // 2 - R"(#....N.....#####################)", // 3 - R"(#..........#####################)", // 4 - R"(#..........#####################)", // 5 - R"(#..##.##...#####################)", // 6 - R"(#..........#####################)", // 7 - R"(#..##.##...#####################)", // 8 - R"(#..........#####################)", // 9 - R"(#..........#####################)", // 10 - R"(###....N#.######################)", // 11 - R"(#..........#####################)", // 12 - R"(#####.##...#####################)", // 13 - R"(#####.##...#####################)", // 14 - R"(#..........#####################)", // 15 - R"(#..........#####################)", // 16 - R"(#..........#####################)", // 17 - R"(#...N......#####################)", // 18 - R"(##.#....########################)", // 19 - R"(##.#....########################)", // 20 - R"(#..........#####################)", // 21 - R"(#..#...#...#####################)", // 22 - R"(#..S..NS...#####################)", // 23 - R"(#....D.....#####################)", // 24 - R"(################################)", // 25 - R"(################################)", // 26 - R"(################################)", // 27 - R"(################################)", // 28 - R"(################################)", // 29 - R"(################################)", // 30 - R"(################################)", // 31 - }); - return grid; + return story_grid("OreburghGym"); } const TilePos ENTRANCE{5, 23}; diff --git a/devtools/maps/bdsp_maps.py b/devtools/maps/bdsp_maps.py index ec113b7634..1e99fd8988 100644 --- a/devtools/maps/bdsp_maps.py +++ b/devtools/maps/bdsp_maps.py @@ -28,6 +28,8 @@ 'Route202', 'JubilifeCity', 'Route203', 'OreburghGate', 'OreburghCity', 'OreburghMine', 'Route204South', 'RavagedPath', 'Route204North', 'FloaromaTown', + # #112 + 'OreburghGym', ] MAX_LITERAL = 16000