From a40f0e034b406b342d9c9e4925d2ea51931543be Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 12:00:36 -0800 Subject: [PATCH 01/18] BDSP navigation: the story maps as JSON, their grids and plan costs, with tests The BDSP maps from new game to Floaroma (Twinleaf to Floaroma, the Oreburgh Mine and Gym, the Ravaged Path), built into the program from JSON by CMake, their tile grids and the joined StoryMaps world, the recorded routes and segment 00's walked lines, and the costs the story's walks are planned with. Carries Pokemon_TileGrid and Pokemon_MapSet unchanged from the BDSP chain (fork #109). Tests: the built-in maps parse, and the planned walks out of the catch area and into Sandgem, the Oreburgh Gym and segment 00's lines plan on the grids. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- SerialPrograms/CMakeLists.txt | 2 + .../Pokemon/Navigation/Pokemon_MapSet.cpp | 102 ++++ .../Pokemon/Navigation/Pokemon_MapSet.h | 63 +++ .../Pokemon/Navigation/Pokemon_TileGrid.cpp | 503 ++++++++++++++++++ .../Pokemon/Navigation/Pokemon_TileGrid.h | 191 +++++++ .../Source/PokemonBDSP/PokemonBDSP_Tests.cpp | 4 + .../Programs/AutoStory/Data/MAPS.md | 45 ++ .../PokemonBDSP_AutoStory_FloaromaTown.cpp | 81 +++ .../Data/PokemonBDSP_AutoStory_FloaromaTown.h | 36 ++ .../PokemonBDSP_AutoStory_JubilifeCity.cpp | 113 ++++ .../Data/PokemonBDSP_AutoStory_JubilifeCity.h | 45 ++ .../Data/PokemonBDSP_AutoStory_LakeVerity.cpp | 66 +++ .../Data/PokemonBDSP_AutoStory_LakeVerity.h | 27 + .../Data/PokemonBDSP_AutoStory_MapGrids.cpp | 115 ++++ .../Data/PokemonBDSP_AutoStory_MapGrids.h | 52 ++ .../PokemonBDSP_AutoStory_OreburghCity.cpp | 92 ++++ .../Data/PokemonBDSP_AutoStory_OreburghCity.h | 37 ++ .../PokemonBDSP_AutoStory_OreburghGate.cpp | 51 ++ .../Data/PokemonBDSP_AutoStory_OreburghGate.h | 27 + .../PokemonBDSP_AutoStory_OreburghGym.cpp | 61 +++ .../Data/PokemonBDSP_AutoStory_OreburghGym.h | 38 ++ .../PokemonBDSP_AutoStory_OreburghMine.cpp | 65 +++ .../Data/PokemonBDSP_AutoStory_OreburghMine.h | 39 ++ .../Data/PokemonBDSP_AutoStory_PlanCosts.cpp | 47 ++ .../Data/PokemonBDSP_AutoStory_PlanCosts.h | 46 ++ .../PokemonBDSP_AutoStory_RavagedPath.cpp | 62 +++ .../Data/PokemonBDSP_AutoStory_RavagedPath.h | 47 ++ .../Data/PokemonBDSP_AutoStory_Route201.cpp | 82 +++ .../Data/PokemonBDSP_AutoStory_Route201.h | 37 ++ .../Data/PokemonBDSP_AutoStory_Route202.cpp | 101 ++++ .../Data/PokemonBDSP_AutoStory_Route202.h | 49 ++ .../Data/PokemonBDSP_AutoStory_Route203.cpp | 78 +++ .../Data/PokemonBDSP_AutoStory_Route203.h | 32 ++ .../Data/PokemonBDSP_AutoStory_Route204.cpp | 91 ++++ .../Data/PokemonBDSP_AutoStory_Route204.h | 43 ++ .../PokemonBDSP_AutoStory_Route204South.cpp | 87 +++ .../PokemonBDSP_AutoStory_Route204South.h | 44 ++ .../PokemonBDSP_AutoStory_RouteRecords.cpp | 199 +++++++ .../Data/PokemonBDSP_AutoStory_RouteRecords.h | 67 +++ .../PokemonBDSP_AutoStory_SandgemTown.cpp | 96 ++++ .../Data/PokemonBDSP_AutoStory_SandgemTown.h | 49 ++ .../PokemonBDSP_AutoStory_Segment00Lines.cpp | 156 ++++++ .../PokemonBDSP_AutoStory_Segment00Lines.h | 84 +++ .../Data/PokemonBDSP_AutoStory_StoryMaps.cpp | 246 +++++++++ .../Data/PokemonBDSP_AutoStory_StoryMaps.h | 108 ++++ .../PokemonBDSP_AutoStory_TwinleafTown.cpp | 61 +++ .../Data/PokemonBDSP_AutoStory_TwinleafTown.h | 27 + .../PokemonBDSP_AutoStory_VerityLakefront.cpp | 56 ++ .../PokemonBDSP_AutoStory_VerityLakefront.h | 27 + .../Programs/AutoStory/Maps/FloaromaTown.json | 92 ++++ .../Programs/AutoStory/Maps/JubilifeCity.json | 136 +++++ .../Programs/AutoStory/Maps/LakeVerity.json | 62 +++ .../Programs/AutoStory/Maps/OreburghCity.json | 88 +++ .../Programs/AutoStory/Maps/OreburghGate.json | 62 +++ .../Programs/AutoStory/Maps/OreburghGym.json | 68 +++ .../Programs/AutoStory/Maps/OreburghMine.json | 80 +++ .../Programs/AutoStory/Maps/RavagedPath.json | 64 +++ .../Programs/AutoStory/Maps/Route201.json | 43 ++ .../Programs/AutoStory/Maps/Route202.json | 62 +++ .../Programs/AutoStory/Maps/Route203.json | 60 +++ .../AutoStory/Maps/Route204North.json | 74 +++ .../AutoStory/Maps/Route204South.json | 62 +++ .../Programs/AutoStory/Maps/SandgemTown.json | 42 ++ .../Programs/AutoStory/Maps/TwinleafTown.json | 56 ++ .../AutoStory/Maps/VerityLakefront.json | 42 ++ .../PokemonBDSP_AutoStory_MapGrid_Tests.cpp | 256 +++++++++ .../PokemonBDSP_AutoStory_MapGrid_Tests.h | 28 + .../PokemonBDSP_AutoStory_Segment00_Tests.cpp | 266 +++++++++ .../PokemonBDSP_AutoStory_Segment00_Tests.h | 27 + SerialPrograms/cmake/SourceFiles.cmake | 50 ++ devtools/maps/bdsp_maps.py | 53 ++ 71 files changed, 5650 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.cpp create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.h create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.cpp create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h 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_OreburghMine.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.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/Data/PokemonBDSP_AutoStory_StoryMaps.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/FloaromaTown.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/JubilifeCity.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/LakeVerity.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghCity.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghGate.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghGym.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghMine.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/RavagedPath.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route201.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route202.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route203.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route204North.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route204South.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/SandgemTown.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/TwinleafTown.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/VerityLakefront.json create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.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 create mode 100644 devtools/maps/bdsp_maps.py diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index d0966df32f..021c06a41f 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -197,6 +197,8 @@ 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_Navigation_Tests.h PokemonAutomation::Pokemon navigation_test_map_json) +pa_embed_text_files(SerialProgramsLib Source/PokemonBDSP/Programs/AutoStory/Maps + PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.h PokemonAutomation::NintendoSwitch::PokemonBDSP bdsp_map_json) # Create binary target diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.cpp new file mode 100644 index 0000000000..533dc4f12f --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.cpp @@ -0,0 +1,102 @@ +/* Map Set + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Common/Cpp/Exceptions.h" +#include "Pokemon_MapSet.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +void MapSet::add(std::string name, const TileGrid& grid, const TilePos& offset){ + for (const Placed& placed : m_maps){ + if (placed.name == name){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Map placed twice: " + name); + } + // Map images show a border of trees past their edges, so two maps + // may share blocked tiles, but nothing else. + for (int y = 0; y < grid.height(); y++){ + for (int x = 0; x < grid.width(); x++){ + const TilePos other{offset.x + x - placed.offset.x, offset.y + y - placed.offset.y}; + if (!placed.grid.in_bounds(other)){ + continue; + } + if (grid.at({x, y}) != TileType::BLOCKED || placed.grid.at(other) != TileType::BLOCKED){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Map " + name + " overlaps " + placed.name + " at its tile " + to_string(TilePos{x, y}) + "." + ); + } + } + } + } + m_maps.push_back(Placed{std::move(name), grid, offset}); + + // Rebuild the joined grid. + TilePos low = m_maps[0].offset; + TilePos high = low; + for (const Placed& placed : m_maps){ + low.x = std::min(low.x, placed.offset.x); + low.y = std::min(low.y, placed.offset.y); + high.x = std::max(high.x, placed.offset.x + placed.grid.width()); + high.y = std::max(high.y, placed.offset.y + placed.grid.height()); + } + m_origin = low; + std::vector rows(high.y - low.y, std::string(high.x - low.x, tile_char(TileType::UNKNOWN))); + for (const Placed& placed : m_maps){ + const std::vector map_rows = placed.grid.rows(); + for (size_t y = 0; y < map_rows.size(); y++){ + rows[placed.offset.y - low.y + y].replace(placed.offset.x - low.x, map_rows[y].size(), map_rows[y]); + } + } + m_world.emplace(rows); +} + +const TileGrid& MapSet::world() const{ + if (!m_world){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No maps placed."); + } + return *m_world; +} + +TilePos MapSet::to_world(const std::string& map, const TilePos& local) const{ + for (const Placed& placed : m_maps){ + if (placed.name == map){ + return { + placed.offset.x - m_origin.x + local.x, + placed.offset.y - m_origin.y + local.y, + }; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown map: " + map); +} + +std::optional MapSet::to_local(const TilePos& world) const{ + for (const Placed& placed : m_maps){ + const TilePos local{ + world.x + m_origin.x - placed.offset.x, + world.y + m_origin.y - placed.offset.y, + }; + if (placed.grid.in_bounds(local)){ + return MapTile{placed.name, local}; + } + } + return std::nullopt; +} + +std::string MapSet::describe(const TilePos& world) const{ + const std::optional local = to_local(world); + if (!local){ + return "world " + to_string(world); + } + return local->map + " " + to_string(local->pos); +} + + + +} +} diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.h new file mode 100644 index 0000000000..468213c481 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.h @@ -0,0 +1,63 @@ +/* Map Set + * + * From: https://github.com/PokemonAutomation/ + * + * Several tile grids placed side by side on one world grid, so one plan + * can cross from a route into a town. + */ + +#ifndef PokemonAutomation_Pokemon_MapSet_H +#define PokemonAutomation_Pokemon_MapSet_H + +#include +#include +#include +#include "Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +struct MapTile{ + std::string map; + TilePos pos; +}; + + +class MapSet{ +public: + // Places `grid` with its tile (0,0) at `offset`. Offsets are relative to + // each other and may be negative. Maps may overlap only where both are + // blocked; the map placed first holds those tiles. Throws + // InternalProgramError if the name is taken or the maps conflict. + void add(std::string name, const TileGrid& grid, const TilePos& offset); + + // The maps joined on one grid. Tiles no map covers are UNKNOWN. World + // tile (0,0) is the top-left corner of all the maps together. + const TileGrid& world() const; + + // Throws InternalProgramError for an unknown map name. + TilePos to_world(const std::string& map, const TilePos& local) const; + + // The map that holds a world tile, or nothing between maps. + std::optional to_local(const TilePos& world) const; + + // "Route 201 (45,3)", or the world tile if no map holds it. + std::string describe(const TilePos& world) const; + +private: + struct Placed{ + std::string name; + TileGrid grid; + TilePos offset; + }; + std::vector m_maps; + TilePos m_origin; // offset of world tile (0,0) + std::optional m_world; +}; + + + +} +} +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.cpp new file mode 100644 index 0000000000..e0a70bc8e5 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.cpp @@ -0,0 +1,503 @@ +/* Tile Grid + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Pokemon_LegPlanner.h" +#include "Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +char tile_char(TileType type){ + switch (type){ + case TileType::BLOCKED: return '#'; + case TileType::WALKABLE: return '.'; + case TileType::TALL_GRASS: return '"'; + case TileType::LEDGE: return 'v'; + case TileType::NPC: return 'N'; + case TileType::SIGN: return 'S'; + case TileType::DOOR: return 'D'; + case TileType::UNKNOWN: return '?'; + } + return '?'; +} + + + + +TileGrid::TileGrid(const std::vector& rows) + : m_width(rows.empty() ? 0 : (int)rows[0].size()) + , m_height((int)rows.size()) +{ + m_tiles.reserve((size_t)m_width * m_height); + for (size_t y = 0; y < rows.size(); y++){ + const std::string& row = rows[y]; + if ((int)row.size() != m_width){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Tile grid row " + std::to_string(y) + " has " + std::to_string(row.size()) + + " tiles, expected " + std::to_string(m_width) + "." + ); + } + for (size_t x = 0; x < row.size(); x++){ + switch (row[x]){ + case '#': m_tiles.push_back(TileType::BLOCKED); break; + case '.': m_tiles.push_back(TileType::WALKABLE); break; + case '"': m_tiles.push_back(TileType::TALL_GRASS); break; + case 'v': m_tiles.push_back(TileType::LEDGE); break; + case 'N': m_tiles.push_back(TileType::NPC); break; + case 'S': m_tiles.push_back(TileType::SIGN); break; + case 'D': m_tiles.push_back(TileType::DOOR); break; + case '?': m_tiles.push_back(TileType::UNKNOWN); break; + default: + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + std::string("Unknown tile '") + row[x] + "' at " + + to_string(TilePos{(int)x, (int)y}) + "." + ); + } + } + } +} + +std::vector TileGrid::rows() const{ + std::vector rows; + for (int y = 0; y < m_height; y++){ + std::string row; + for (int x = 0; x < m_width; x++){ + row += tile_char(at({x, y})); + } + rows.push_back(std::move(row)); + } + return rows; +} + +bool TileGrid::in_bounds(const TilePos& pos) const{ + return 0 <= pos.x && pos.x < m_width && 0 <= pos.y && pos.y < m_height; +} + +TileType TileGrid::at(const TilePos& pos) const{ + if (!in_bounds(pos)){ + return TileType::UNKNOWN; + } + return m_tiles[(size_t)pos.y * m_width + pos.x]; +} + +void TileGrid::set(const TilePos& pos, TileType type){ + if (in_bounds(pos)){ + m_tiles[(size_t)pos.y * m_width + pos.x] = type; + } +} + +bool TileGrid::standable(const TilePos& pos) const{ + const TileType type = at(pos); + return type == TileType::WALKABLE || type == TileType::TALL_GRASS; +} + +std::optional TileGrid::step(const TilePos& from, Direction direction) const{ + const TilePos next = from.next(direction); + if (standable(next)){ + return next; + } + if (at(next) == TileType::LEDGE && direction == Direction::SOUTH){ + const TilePos landing = next.next(direction); + if (standable(landing)){ + return landing; + } + } + return std::nullopt; +} + +bool TileGrid::at_wall(const TilePos& pos, Direction direction) const{ + const TileType next = at(pos.next(direction)); + return next != TileType::DOOR && next != TileType::UNKNOWN && !step(pos, direction).has_value(); +} + + + +WallHit walk_to_wall(const TileGrid& grid, const TilePos& from, Direction direction){ + WallHit hit; + hit.stop = from; + while (true){ + const TilePos before = hit.stop; + const std::optional next = grid.step(before, direction); + if (!next){ + hit.wall = before.next(direction); + hit.anchored = grid.at_wall(before, direction); + return hit; + } + hit.tiles += std::abs(next->x - before.x) + std::abs(next->y - before.y); + hit.stop = *next; + } +} + + + +std::string to_string(const TileLeg& leg){ + return std::string(direction_name(leg.direction)) + " " + std::to_string(leg.tiles) + + (leg.ends_at_wall ? " (to wall)" : " (open)"); +} + + +namespace{ + +// The grid's step rules for the shared leg planner. A ledge hop is one +// press that moves two tiles. +class TileGridModel{ +public: + using State = TilePos; + using StateHash = std::hash; + + TileGridModel(const TileGrid& grid, const TilePlanCosts& costs) + : m_grid(grid) + , m_costs(costs) + {} + + std::optional> press(const State& pos, Direction direction) const{ + const std::optional next = m_grid.step(pos, direction); + if (!next){ + return std::nullopt; + } + Step step; + step.next = *next; + step.facing = direction; + const int tiles = std::abs(next->x - pos.x) + std::abs(next->y - pos.y); + step.extra_cost = m_costs.per_tile * (tiles - 1); + if (m_grid.at(*next) == TileType::TALL_GRASS){ + step.extra_cost += m_costs.per_grass_tile; + } + return step; + } + bool held_at(const State& pos, Direction direction) const{ + return m_grid.at_wall(pos, direction); + } + +private: + const TileGrid& m_grid; + const TilePlanCosts& m_costs; +}; + +} + +std::optional> plan_tile_route( + const TileGrid& grid, + const TilePos& from, const TilePos& to, + const TilePlanCosts& costs +){ + if (!grid.standable(from) || !grid.standable(to)){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Route ends must be standable: " + to_string(from) + " -> " + to_string(to) + "." + ); + } + if (from == to){ + return std::vector(); + } + LegCosts leg_costs; + leg_costs.per_tile = costs.per_tile; + leg_costs.per_turn = costs.per_leg; + leg_costs.per_open_stop = costs.leg_not_at_wall; + const std::optional>> legs = plan_legs( + TileGridModel(grid, costs), from, std::nullopt, + std::function([&](const TilePos& pos){ return pos == to; }), + std::nullopt, leg_costs + ); + if (!legs){ + return std::nullopt; + } + std::vector ret; + for (const Leg& leg : *legs){ + const size_t tiles = std::abs(leg.end.x - leg.start.x) + std::abs(leg.end.y - leg.start.y); + ret.push_back(TileLeg{leg.direction, tiles, leg.to_wall}); + } + return ret; +} + +std::vector sight_tiles(const TileGrid& grid, const TrainerSight& trainer){ + std::vector tiles; + TilePos pos = trainer.pos; + for (int i = 0; i < trainer.range; i++){ + pos = pos.next(trainer.facing); + if (!grid.standable(pos)){ + break; + } + tiles.push_back(pos); + } + return tiles; +} + +std::vector> legs_crossing_sight( + const TileGrid& grid, + const TilePos& from, + const std::vector& legs, + const std::vector& trainers +){ + std::vector> sights; + for (const TrainerSight& trainer : trainers){ + sights.push_back(sight_tiles(grid, trainer)); + } + std::vector> crossings; + TilePos pos = from; + for (const TileLeg& leg : legs){ + const std::vector tiles = trace_legs(grid, pos, {leg}); + std::vector seen_by; + for (size_t t = 0; t < trainers.size(); t++){ + for (size_t i = 1; i < tiles.size(); i++){ + if (std::find(sights[t].begin(), sights[t].end(), tiles[i]) != sights[t].end()){ + seen_by.push_back(trainers[t].name); + break; + } + } + } + crossings.push_back(std::move(seen_by)); + pos = tiles.back(); + } + return crossings; +} + +std::vector trace_legs( + const TileGrid& grid, + const TilePos& from, + const std::vector& legs +){ + std::vector tiles{from}; + for (const TileLeg& leg : legs){ + size_t travelled = 0; + while (travelled < leg.tiles){ + const TilePos pos = tiles.back(); + const std::optional next = grid.step(pos, leg.direction); + if (!next){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Leg " + to_string(leg) + " is stopped at " + to_string(pos) + "." + ); + } + travelled += std::abs(next->x - pos.x) + std::abs(next->y - pos.y); + tiles.push_back(*next); + } + if (travelled != leg.tiles){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Leg " + to_string(leg) + " overshoots on a ledge hop." + ); + } + } + return tiles; +} + + + +std::string to_string(const PlannedLeg& leg){ + std::string out = to_string(leg.leg) + " to"; + for (const TilePos& pos : leg.after){ + out += " " + to_string(pos); + } + return out; +} + +namespace{ + +// Where `from` ends up after `tiles` steps in `direction`, stopping early at +// anything that stops the player. Nothing if a step would leave the map or +// enter a door: the plan cannot tell what happens then. +std::optional step_tiles( + const TileGrid& grid, TilePos from, Direction direction, int tiles, int& grass +){ + int travelled = 0; + while (travelled < tiles){ + const std::optional next = grid.step(from, direction); + if (!next){ + if (!grid.at_wall(from, direction)){ + return std::nullopt; + } + break; + } + travelled += std::abs(next->x - from.x) + std::abs(next->y - from.y); + if (grid.at(*next) == TileType::TALL_GRASS){ + grass++; + } + from = *next; + } + return from; +} + +using Spread = std::vector; + +bool spread_less(const TilePos& a, const TilePos& b){ + return a.y != b.y ? a.y < b.y : a.x < b.x; +} +void normalize(Spread& spread){ + std::sort(spread.begin(), spread.end(), spread_less); + spread.erase(std::unique(spread.begin(), spread.end()), spread.end()); +} +struct SpreadLess{ + bool operator()(const Spread& a, const Spread& b) const{ + return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), spread_less); + } +}; + +} + +std::optional> plan_robust_route( + const TileGrid& grid, + const TilePos& from, const TilePos& to, + const RobustPlanCosts& costs +){ + if (!grid.standable(from) || !grid.standable(to)){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Route ends must be standable: " + to_string(from) + " -> " + to_string(to) + "." + ); + } + return plan_robust_route(grid, std::vector{from}, [&](const TilePos& pos){ return pos == to; }, costs); +} + +std::optional> plan_robust_route( + const TileGrid& grid, + const std::vector& from, const std::function& goal, + const RobustPlanCosts& costs +){ + for (const TilePos& pos : from){ + if (!grid.standable(pos)){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, + "Route starts must be standable: " + to_string(pos) + "." + ); + } + } + // Only the start may be wider than costs.max_spread: every leg must bring + // the player within it. + const size_t max_spread = costs.max_spread; + auto reached = [&](const Spread& spread){ + return std::all_of(spread.begin(), spread.end(), goal); + }; + + struct Node{ + long long cost; + Spread parent; + PlannedLeg leg; + bool done = false; + }; + std::map nodes; + using Entry = std::pair; + auto entry_greater = [](const Entry& a, const Entry& b){ return a.first > b.first; }; + std::priority_queue, decltype(entry_greater)> queue(entry_greater); + + Spread start = from; + normalize(start); + nodes[start] = Node{0, {}, {}}; + queue.emplace(0, start); + + auto relax = [&](const Spread& spread, long long cost, Spread next, PlannedLeg leg){ + normalize(next); + if (next.size() > max_spread || next == spread){ + return; + } + auto iter = nodes.find(next); + if (iter != nodes.end() && iter->second.cost <= cost){ + return; + } + leg.after = next; + nodes[next] = Node{cost, spread, std::move(leg)}; + queue.emplace(cost, std::move(next)); + }; + + size_t searched = 0; + while (!queue.empty()){ + const Entry top = queue.top(); + queue.pop(); + const long long cost = top.first; + const Spread& spread = top.second; + Node& node = nodes[spread]; + if (node.done || node.cost != cost){ + continue; + } + node.done = true; + if (++searched > costs.max_searched){ + return std::nullopt; + } + if (reached(spread)){ + std::vector legs; + for (Spread at = spread; at != start; ){ + const Node& step = nodes[at]; + legs.push_back(step.leg); + at = step.parent; + } + std::reverse(legs.begin(), legs.end()); + return legs; + } + + for (Direction direction : ALL_DIRECTIONS){ + // To the wall: every position walks until stopped. + { + Spread next; + size_t longest = 0; + int grass = 0; + bool ok = true; + for (const TilePos& pos : spread){ + const WallHit hit = walk_to_wall(grid, pos, direction); + if (!hit.anchored){ + ok = false; + break; + } + int leg_grass = 0; + step_tiles(grid, pos, direction, (int)hit.tiles, leg_grass); + grass = std::max(grass, leg_grass); + longest = std::max(longest, hit.tiles); + next.push_back(hit.stop); + } + if (ok && longest > 0){ + const long long step = (long long)costs.per_leg + + (long long)costs.per_tile * longest + (long long)costs.per_grass_tile * grass; + relax(spread, cost + step, std::move(next), PlannedLeg{TileLeg{direction, longest, true}, {}}); + } + } + // Open: about `tiles` tiles, give or take `open_error`. + for (int tiles = 1; tiles <= costs.max_open_tiles; tiles++){ + Spread next; + int grass = 0; + bool ok = true; + for (const TilePos& pos : spread){ + const int error = tiles <= costs.exact_open_tiles ? 0 : costs.open_error + tiles / costs.open_error_per; + for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ + int leg_grass = 0; + const std::optional end = step_tiles(grid, pos, direction, n, leg_grass); + if (!end){ + ok = false; + break; + } + grass = std::max(grass, leg_grass); + next.push_back(*end); + } + if (!ok){ + break; + } + } + if (!ok){ + break; + } + const long long step = (long long)costs.per_leg + costs.leg_not_at_wall + + (long long)(costs.per_tile + costs.per_open_tile) * tiles + (long long)costs.per_grass_tile * grass; + relax(spread, cost + step, std::move(next), PlannedLeg{TileLeg{direction, (size_t)tiles, false}, {}}); + } + } + } + + return std::nullopt; +} + + + +} +} diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.h new file mode 100644 index 0000000000..c8ae8ba9d9 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.h @@ -0,0 +1,191 @@ +/* Tile Grid + * + * From: https://github.com/PokemonAutomation/ + * + * An overworld map as a grid of tiles, and a planner that turns a walk from + * one tile to another into straight legs. Timed stick holds drift by a tile; + * a leg that ends against a wall does not, because the player stops there + * however long the stick is held. The planner prefers such legs. + */ + +#ifndef PokemonAutomation_Pokemon_TileGrid_H +#define PokemonAutomation_Pokemon_TileGrid_H + +#include +#include +#include +#include +#include +#include "Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Legend of the ASCII rows a grid is parsed from. +enum class TileType{ + BLOCKED, // '#': trees, walls, items on the ground + WALKABLE, // '.': open ground and paths + TALL_GRASS, // '"': walkable, with wild encounters + LEDGE, // 'v': crossed only southward, hopping to the tile past it + NPC, // 'N': a standing NPC or trainer; blocks like a wall + SIGN, // 'S': a sign; blocks like a wall + DOOR, // 'D': walking into it enters a building + UNKNOWN, // '?': off the map; an exit or ground we have no map of +}; +char tile_char(TileType type); + +class TileGrid{ +public: + // Every row must have the same length and use only the legend's characters. + // Throws InternalProgramError otherwise. + explicit TileGrid(const std::vector& rows); + + // The grid as the ASCII rows it parses from. + std::vector rows() const; + + int width() const{ return m_width; } + int height() const{ return m_height; } + bool in_bounds(const TilePos& pos) const; + + // Out-of-bounds tiles read as UNKNOWN. + TileType at(const TilePos& pos) const; + + // Changes one tile, e.g. to block one found in the way on the console. + // Out-of-bounds tiles are left alone. + void set(const TilePos& pos, TileType type); + + // Whether the player can stand on this tile. + bool standable(const TilePos& pos) const; + + // Where one step from `from` lands, or nothing if the player is stopped. + // A south step onto a ledge hops to the tile past it. + std::optional step(const TilePos& from, Direction direction) const; + + // Whether a step from `pos` is refused by a tile that holds the player + // in place. Doors and unknown tiles are not walls: walking into a door + // enters the building, and unknown ground may be an exit. + bool at_wall(const TilePos& pos, Direction direction) const; + +private: + int m_width = 0; + int m_height = 0; + std::vector m_tiles; +}; + + +// Where the player stops when walking in one direction until stopped. +struct WallHit{ + TilePos stop; + size_t tiles = 0; // tiles travelled; a ledge hop counts 2 + TilePos wall; // the first tile the player could not enter + bool anchored = false; // the player is held at `stop` (see TileGrid::at_wall()) +}; +WallHit walk_to_wall(const TileGrid& grid, const TilePos& from, Direction direction); + + +// A straight run in one direction. +struct TileLeg{ + Direction direction; + size_t tiles = 0; // tiles travelled; a ledge hop counts 2 + bool ends_at_wall = false; // the next tile in `direction` stops the player +}; +std::string to_string(const TileLeg& leg); + +struct TilePlanCosts{ + int per_tile = 1; + int per_grass_tile = 4; // extra for each tall-grass tile entered + int per_leg = 8; + int leg_not_at_wall = 50; // extra for a leg that stops in the open +}; + +// Cheapest legs from `from` to `to`, moving 4 ways, or nothing if `to` +// cannot be reached. Both tiles must be standable. +std::optional> plan_tile_route( + const TileGrid& grid, + const TilePos& from, const TilePos& to, + const TilePlanCosts& costs = TilePlanCosts() +); + +// A trainer sees the tiles in a straight line in front of them, up to +// `range` tiles or the first tile the player cannot stand on. +struct TrainerSight{ + std::string name; + TilePos pos; + Direction facing; + int range = 4; +}; +std::vector sight_tiles(const TileGrid& grid, const TrainerSight& trainer); + +// For each leg, the trainers whose sight line it enters. +std::vector> legs_crossing_sight( + const TileGrid& grid, + const TilePos& from, + const std::vector& legs, + const std::vector& trainers +); + +// The tiles a list of legs visits, starting with `from`. Throws +// InternalProgramError if a leg is stopped before its end. +std::vector trace_legs( + const TileGrid& grid, + const TilePos& from, + const std::vector& legs +); + + +// A leg of a plan that allows for open legs going a tile short or long. A +// leg to a wall is walked until the player stops; an open leg is walked for +// `leg.tiles` tiles' worth of time. `after` lists every tile the player may +// stand on once the leg is done. +struct PlannedLeg{ + TileLeg leg; + std::vector after; +}; +std::string to_string(const PlannedLeg& leg); + +struct RobustPlanCosts : TilePlanCosts{ + // An open leg of n tiles may end open_error + n / open_error_per tiles + // short or long: on the console 7 tiles went 9. + int open_error = 1; + int open_error_per = 5; + // Open legs this many tiles or shorter land exactly: a short hold moves + // whole tiles. 0 keeps every open leg uncertain. + int exact_open_tiles = 0; + // Extra per tile of an open leg: its timing error grows with its length, + // so a short step after a wall beats a long open leg. + int per_open_tile = 0; + int max_open_tiles = 12; // longest open leg to consider + size_t max_spread = 5; // most tiles the player may be on after a leg + // Most sets of possible tiles to search before giving up. The search is + // over sets, not tiles, so it grows far faster than the map: all of + // Jubilife City from six start tiles ran for minutes with no plan + // (r224a, 2026-10-31); 200000 sets took 31 s there, so this gives up + // after about 3. Use town costs in towns (a whole-Jubilife plan then + // takes 1 s) and crop the map to the part a leg needs rather than + // raising this. + size_t max_searched = 20000; +}; + +// Cheapest legs that take the player from any of the tiles in `from` to tiles +// that are all `goal`, even if every open leg ends up to `open_error` tiles +// off: the walls of later legs must bring the possible positions together. +// Legs that would leave the map or enter a door are not used. Nothing if no +// such plan exists, or none is found within `costs.max_searched` sets. +std::optional> plan_robust_route( + const TileGrid& grid, + const std::vector& from, const std::function& goal, + const RobustPlanCosts& costs = RobustPlanCosts() +); +// The same, from one tile to exactly `to`. +std::optional> plan_robust_route( + const TileGrid& grid, + const TilePos& from, const TilePos& to, + const RobustPlanCosts& costs = RobustPlanCosts() +); + + + +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp index b8ff5e26a5..608126f0db 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp @@ -5,6 +5,8 @@ */ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h" +#include "Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h" #include "PokemonBDSP_Tests.h" namespace PokemonAutomation{ @@ -14,6 +16,8 @@ namespace PokemonBDSP{ void add_tests(UnitTestDatabase& database){ + add_tests_AutoStory_MapGrids(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 new file mode 100644 index 0000000000..2c37d39a69 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md @@ -0,0 +1,45 @@ +# AutoStory map grids: source and status + +Each map file's header starts with the same three lines, kept current with the code: + +- **Map source**: where the tiles come from. "Decomp" means a decompilation's + collision table (pret/pokediamond `land_data` narc, or pret/pokeplatinum + `map_data_NNN.bin`) with the objects from its events file; BDSP keeps + Diamond/Pearl's layout, and Platinum's few changes show up on the console. "DP image" means a Bulbapedia map image + traced by hand or by colour; those images have 12 px rows for 16 px columns, so + a traced grid has 3/4 of a tile per row and drifts by the map's height + differences (cliffs are painted taller than their tiles). +- **Console checks**: the anchors measured on the Switch (D-pad taps, sign reads, + recorded human walks), with the run or date. +- **Status**: the checkpoints that pass on this exact grid, and the next change. + +| map | source | checkpoints passing | next | +|---|---|---|---| +| Route 201 | decomp (Diamond) | none yet (00.02-00.04 and mart_lady passed on the image grid) | re-run them | +| Route 202 | decomp (Diamond) | none yet (00.04 passed on the image grid) | re-run 00.04; the save-spot legs grew three rows | +| Sandgem Town | decomp (Diamond) | none yet (00.04, 00.05 passed with image rows 0-6) | re-run; the Route 202 entry stop is (29,1) | +| Jubilife City | decomp (Diamond), console NPCs | none yet (00.05, 01.01, 01.06, 01.07 passed on the image grid) | re-run; re-anchor the Mart clown and the steps walk | +| Oreburgh Mine B2F | decomp (Diamond) | none yet (01.02, 01.03 passed 3x on the stretched image grid) | re-run both | +| Route 203 | decomp (Diamond) | none yet (01.06 passed on the image grid) | re-run; the row to Jubilife is 18, four sand rows | +| Route 204 South | decomp | 01.08 (1x) | more passes | +| Ravaged Path | decomp rows 30-53 | 01.09 by hand | program pass | +| Route 204 North | decomp | 01.10 (1x) | probe column 23; (12,6) marked from the console | +| 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 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 | +| 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. 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); the +re-derivation of 2026-10-31 took every grid above from `devtools/maps decomp +--repo pret/pokediamond` and translated each file's named tiles with its +console anchors. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp new file mode 100644 index 0000000000..c91f67d5ea --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp @@ -0,0 +1,81 @@ +/* BDSP AutoStory - Floaroma Town tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_FloaromaTown.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace FloaromaTown{ + +using namespace Pokemon; + + +// Console: the old couple stands at (2, 25) and (3, 25) ('N'), placed from +// the 2026-10-31 walk; they are not in the DP data (a Camper and a Lass are). +// Map source: the decomp (Diamond land_data 0032 = Platinum map_data_032, +// 2026-10-31) with the objects from its events file. +// Console checks: none yet. +// 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_0032: one cell of the +// Sinnoh matrix at column 5, row 20; map_data_032 in pret/pokeplatinum), +// with the objects from its events file (zone_event narc_0404, +// events_floaroma_town.json in Platinum); BDSP keeps Diamond/Pearl's layout. +// Local (x, y) = world (x - 160, z - 640); 32 x 32 tiles. The cell above +// (column 5, row 19, land_data 0033) carries the same map header but is cut +// off from the town (its bottom rows are wall; the town's row 0 is a +// dead-end strip under them), so it is left out. +// The flower field is the west half, columns 0 to 17, rows 2 to 22; +// Diamond's data puts a Camper at (6, 10) and a Lass wandering row 5 in it. +// The old couple BDSP shows there are not in the Diamond/Pearl data: place +// them as 'N' from the console. Exits: Route 204 south through (10..12, +// 30..31) (and the one-tile gap (8, 30..31), which joins a side path on the +// route); Route 205 east at (31, 19..22). Warp tiles the player stands on +// are written as '.': (20, 11), the Flower Shop's entrance, and (2, 1), (3, +// 1) into Floaroma Meadow, where the two Galactic grunts stand ('N' wins +// there) until the Valley Windworks is cleared (flag 447). Objects, from the +// events file: +// door (16, 26) to the Pokemon Center; door (24, 26) to the south-east +// house; +// door (24, 17) to the Poke Mart; its signboard (29, 15); +// door (11, 14) to the middle house; +// Flower Shop entrance (20, 11), its signboard (17, 11) and the two berry +// patches (18, 11) and (22, 11), as '#'; +// map signpost (13, 19); +// Grunt M (2, 1), looks east, and Grunt M (3, 1), looks west, not +// trainers, hidden by flag 447; +// Camper (6, 10), looks around, not a trainer; +// Lass (23, 11), looks west, not a trainer; +// Pokemon Breeder F (19, 21), looks around, not a trainer; +// a man with Cyrus's sprite (11, 26), looks around, not a trainer, hidden +// by flag 449 (Diamond/Pearl only; whether he is there when the story +// arrives is for the console); +// Lass wanders west and east from (10, 5), columns 9 to 11, row 5: off the +// grid; +// School Kid M wanders around (16, 16), columns 15 to 17, rows 15 to 17: +// off the grid. +// No trainers. Platinum differs in one row and one person: its row 30 opens +// columns 8 to 13 where Diamond opens 8 and 10 to 12 (Route 204 North's top +// rows are '########.#...###' in both games, so Diamond's is the border BDSP +// has), and it has a Beauty at (10, 19) looking south instead of the man at +// (11, 26). +const TileGrid& grid(){ + return story_grid("FloaromaTown"); +} + +const TilePos ROUTE_204_ARRIVAL{11, 29}; +const TilePos OLD_WOMAN{3, 25}; +const TilePos OLD_MAN{2, 25}; +const TilePos POKEMON_CENTER_DOOR{16, 26}; + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h new file mode 100644 index 0000000000..43384adc6b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h @@ -0,0 +1,36 @@ +/* BDSP AutoStory - Floaroma Town tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see + * the .cpp's header for the cells, the offset and the objects. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_FloaromaTown_H +#define PokemonAutomation_PokemonBDSP_AutoStory_FloaromaTown_H + +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace FloaromaTown{ + + +const Pokemon::TileGrid& grid(); + +// Where 01.10's walk north from Route 204 ends on the town's banner and +// saves (r248a, r251a): the path's middle column, three rows in. +extern const Pokemon::TilePos ROUTE_204_ARRIVAL; +// The old couple in the flower field, placed from the console (2026-10-31 +// hand walk and r251a: eight tiles west of the arrival, then three north +// to the tile below her); not in the DP data. +extern const Pokemon::TilePos OLD_WOMAN; +extern const Pokemon::TilePos OLD_MAN; +extern const Pokemon::TilePos POKEMON_CENTER_DOOR; + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp new file mode 100644 index 0000000000..16089d130c --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp @@ -0,0 +1,113 @@ +/* BDSP AutoStory - Jubilife City tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_JubilifeCity.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace JubilifeCity{ + +using namespace Pokemon; + + +// Map source: the decomp (pret/pokediamond land_data narc_0018, 0016, 0017 +// and 0015, 2026-10-31) with the objects from its events file. Platinum +// differs only around the Global Terminal (columns 14..26, rows 30..45). +// Console checks (2026-10-30/31): the lamps (43,53) and (49,53), north from +// (52,53) to the Pokemon Center's door, the School's door from the +// Center's doorstep, the east street to Route 203 (01.06, r230a), the +// north street (01.07), and the four 00.05 people, placed from the +// console on the tiles the events file gives them. +// Status: no checkpoint has run on this grid yet. 00.05, 01.01, 01.06 and +// 01.07 passed on the colour-classified image grid it replaces (48 rows +// for 64) and must be re-run; re-check the Mart clown's tile (he wanders +// 182..184 on row 33 in Diamond) and the hand walk from the steps' top +// east to the house and north to the Center (the decomp has the plaza +// only 171..177 wide on rows 58..59). +// +// Decoded from Pokemon Diamond's collision table: cells (23..24, 4..5) of +// the Sinnoh matrix, with the objects from its events file. Local (x, y) = +// world (x - 128, z - 736); 64 x 64 tiles. The console's measurements on +// the image grid were a column east of its doors; on this grid the lamps, +// the doors and the four people all land where the console put them. +// +// Exits: south, the 3-wide neck (45..47, 61) down to Route 202; east, the +// street (rows 21..24) to Route 203; north, (42..55, 0..1) to Route 204; +// west, the Route 218 gate on rows 22..23 (its warp tiles are 'D'). Doors +// are 'D' tiles walked into from below; the Trainers' School's doorway +// (40,40) and the Global Terminal's (21,42) are warp tiles stepped onto and +// marked 'D' as well, so a plan never steps on them. The main road runs +// from the steps (46..47, 60..62) north between the lamps (43,53), (49,53) +// and on up to the north exit; the doors' row 40 is open between the School +// and the Center (43..49), and the plaza below it is rows 41..52. +// People who stand still, from the events file: the Poketch president +// (46,35) and the clown west of the TV station (36,16), the 00.05 story +// people (hidden by flags before and after); an Ace Trainer (36,25) on the +// north road's west side, a Cashier (26,42), an Expert (44,44), two kids +// (52,46), (54,46) on the plaza and a School Kid (17,55): none of these +// five has been seen on the console yet. The clown by the Mart (55,33) and +// the one by the Poketch Company (15,18) wander three tiles in Diamond but +// stood still on the console (00.05, three runs): on the grid at their +// spawn tiles. Wanderers left off: an Ace Trainer along row 20 (21..23), +// one along row 21 (45..47), a Twin around (33,18), a School Kid on column +// 51 (rows 33..35), a Pokefan around (41,30). Rowan and the grunts at the +// north exit, the Collectors and Dawn are hidden by story flags. +const TileGrid& grid(){ + return story_grid("JubilifeCity"); +} + +// Checked on the console (2026-10-30, CFR "walk"): 00.05's save stands +// below the steps, against the wall just east of them (the banner reads +// Jubilife City). West along that wall does not stop at the steps (it runs +// to the trees); a tile west, then north, climbs them. North up the main +// road from the steps passes the lamps (43,53), (49,53) and does not stop +// before the north exit. From the lamps' row, west stops at the house at +// (37..42, 47..52) and east at the house at (53..57, 49..56); north from +// (52,53) stops in front of the Pokemon Center. The steps are columns +// 45..47 of row 61; the save stands at (48,62) against (48,61), and the +// tile west then north puts us on column 47, a few rows up. On this grid +// east from rows 58..60 stops at column 49 and north from there at the lamp +// (49,53), not the Center: the climb must end on row 57 or above, or BDSP's +// plaza is wider than Diamond's there (re-check on the console). +const std::vector& up_the_steps(){ + static const std::vector tiles{{46, 58}, {47, 58}, {46, 59}, {47, 59}, {46, 60}, {47, 60}}; + return tiles; +} + +// The School's doorway is a warp tile stepped onto from (40,41); the +// Center's door is walked into from (52,41). On the console (2026-10-30) +// eleven one-tile holds west from the Center's doorstep put us under the +// School's door: the doorstep was the tile east of the door's column, as +// story_door_front() allows. +const TilePos TRAINERS_SCHOOL_DOOR{40, 40}; +const TilePos POKEMON_CENTER_DOOR{52, 40}; +const TilePos TV_STATION_DOOR{36, 15}; + +// On the main road, five rows north of the School's and the Center's +// doors' row and six columns west of the Center's door. Talked to from the +// east, facing west (also works from the south). +const TilePos POKETCH_PRESIDENT{46, 35}; +// Below the Poke Mart's planters, where the road meets the plaza: his spawn +// tile; he wanders a tile either side in Diamond, and the console had him +// a tile east of it. +const TilePos CLOWN_MART{55, 33}; +// West of the TV station door, right below it. +const TilePos CLOWN_TV_STATION{36, 16}; +// East of the Poketch Company's sign, a row below it. Talked to from the +// south on the console; from the east a walk west along row 18 stops right +// beside him. +const TilePos CLOWN_POKETCH_COMPANY{15, 18}; + + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h new file mode 100644 index 0000000000..941b89ff77 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h @@ -0,0 +1,45 @@ +/* BDSP AutoStory - Jubilife City tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Jubilife City as a tile grid, from the Diamond decompilation's collision + * table, with the places and people of checkpoint 00.05. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_JubilifeCity_H +#define PokemonAutomation_PokemonBDSP_AutoStory_JubilifeCity_H + +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace JubilifeCity{ + + +const Pokemon::TileGrid& grid(); + +// Where we may stand after climbing the steps from where 00.05 starts: +// below them, against the wall just east of them, then a tile west and +// about two tiles north. +const std::vector& up_the_steps(); + +// Doors: walk north from the tile below to enter. +extern const Pokemon::TilePos TRAINERS_SCHOOL_DOOR; +extern const Pokemon::TilePos POKEMON_CENTER_DOOR; +extern const Pokemon::TilePos TV_STATION_DOOR; + +// The Poketch Company president and the three coupon clowns. +extern const Pokemon::TilePos POKETCH_PRESIDENT; +extern const Pokemon::TilePos CLOWN_MART; +extern const Pokemon::TilePos CLOWN_TV_STATION; +extern const Pokemon::TilePos CLOWN_POKETCH_COMPANY; + + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp new file mode 100644 index 0000000000..3198d18e18 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp @@ -0,0 +1,66 @@ +/* BDSP AutoStory - Lake Verity tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_LakeVerity.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace LakeVerity{ + +using namespace Pokemon; + + +// Map source: the decomp (Diamond land_data 0512 = Platinum map_data_541, +// 2026-10-31) with the objects from its events file. +// Console checks: none yet. +// 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_0512: the cell at column +// 1, row 1 of the lake's own matrix 101, which is 3 x 2 cells; map_data_541 +// of matrix 102 in pret/pokeplatinum), with the objects from its events file +// (zone_event narc_0298, events_lake_verity.json in Platinum); BDSP keeps +// Diamond/Pearl's layout. Local (x, y) = world (x - 32, z - 32) in that +// matrix; 32 x 32 tiles. Only this cell is reachable on foot: the shore +// where the starter scene plays, columns 10 to 25, rows 4 to 22. The lake is +// '#'; the tiles at (0..6, 4..9) are shallow water (puddle, behaviour 0x16), +// walkable in the data but closed in by the lake. The west shore with TM38 +// (cells to the west) needs Surf. +// Entrance: the warp tiles (14, 22) and (15, 22), arrived on from Verity +// Lakefront, written as '.'; walking south off them leaves. The scene's +// actors are hidden-flag objects, drawn where the events file puts them +// because that is where the walk ends: Rowan and the briefcase on (16, 11) +// and the player's counterpart on (17, 11), at the water's edge. Objects, +// from the events file: +// Prof. Rowan (16, 11), looks north, hidden by flag 403; the briefcase on +// the same tile, hidden by flag 404; +// the counterpart (Dawn/Lucas, object "Var 0") (17, 11), looks north, +// hidden by flag 434; +// Starly (16, 19), looks north, hidden by flag 429, drawn as 'N' (a scene +// actor on open ground); +// Starly (25, 11), looks west, hidden by flag 429, perched on a blocked +// tile: stays '#'; +// Barry (15, 22), looks north, hidden by flag 436, on the entrance warp +// tile: '.' wins; +// no one wanders here, and no trainers. +// Platinum differs: it stages its scene elsewhere (Rowan (21, 7), the +// counterpart (22, 6), Mars (23, 6), four Galactic grunts with sight 4 to 6, +// no Starly or Barry), walls off the puddle tiles at (0..6, 4..9) and opens +// a path to the Verity Cavern warp at (0, 0). The shore, columns 10 to 25, +// decodes the same tile for tile. Diamond keeps its Galactic version as a +// separate map (MAP_LAKE_VERITY_GALACTIC), reached from the same Lakefront +// warp tiles. +const TileGrid& grid(){ + return story_grid("LakeVerity"); +} + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h new file mode 100644 index 0000000000..a5eb838e8f --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h @@ -0,0 +1,27 @@ +/* BDSP AutoStory - Lake Verity tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see + * the .cpp's header for the cells, the offset and the objects. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_LakeVerity_H +#define PokemonAutomation_PokemonBDSP_AutoStory_LakeVerity_H + +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace LakeVerity{ + + +const Pokemon::TileGrid& grid(); + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp new file mode 100644 index 0000000000..0b7a20d966 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp @@ -0,0 +1,115 @@ +/* BDSP AutoStory - Map grids + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "PokemonBDSP_AutoStory_MapGrids.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using Pokemon::MapData; +using Pokemon::TileGrid; +using Pokemon::TileKind; +using Pokemon::TilePos; +using Pokemon::TileType; + + +namespace{ + +std::optional tile_type_of(TileKind kind){ + switch (kind){ + case TileKind::WALL: return TileType::BLOCKED; + case TileKind::OPEN: return TileType::WALKABLE; + case TileKind::TALL_GRASS: return TileType::TALL_GRASS; + case TileKind::LEDGE_SOUTH: return TileType::LEDGE; + case TileKind::DOOR: return TileType::DOOR; + case TileKind::SIGN: return TileType::SIGN; + default: return std::nullopt; + } +} + +} + +TileGrid tile_grid_from_map(const MapData& map){ + std::vector rows; + for (int y = 0; y < map.tiles.height; y++){ + std::string row; + for (int x = 0; x < map.tiles.width; x++){ + const TileKind kind = map.tiles.at(TilePos{x, y}); + const std::optional type = tile_type_of(kind); + if (!type){ + throw ParseException(std::format( + "{}: glyph '{}' at {} has no BDSP tile.", map.name, Pokemon::glyph_of(kind), Pokemon::to_string(TilePos{x, y}) + )); + } + row += Pokemon::tile_char(*type); + } + rows.push_back(std::move(row)); + } + for (const Pokemon::MapObject& object : map.objects){ + if (object.kind != Pokemon::ObjectKind::NPC || object.wander){ + throw ParseException(std::format("{}: object {} is not a person standing still.", map.name, object.name)); + } + rows[object.y][object.x] = Pokemon::tile_char(TileType::NPC); + } + return TileGrid(rows); +} + +std::optional grid_difference(const TileGrid& here, const TileGrid& there){ + if (here.width() != there.width() || here.height() != there.height()){ + return std::format("{} x {} here, {} x {} there", here.width(), here.height(), there.width(), there.height()); + } + for (int y = 0; y < here.height(); y++){ + for (int x = 0; x < here.width(); x++){ + const TilePos pos{x, y}; + if (here.at(pos) != there.at(pos)){ + return std::format( + "{}: '{}' here, '{}' there", + Pokemon::to_string(pos), Pokemon::tile_char(here.at(pos)), Pokemon::tile_char(there.at(pos)) + ); + } + } + } + return std::nullopt; +} + + +namespace{ + +const std::map& story_grids(){ + static const std::map grids = []{ + std::map parsed; + for (const auto& [name, json] : bdsp_map_json()){ + const MapData map = Pokemon::parse_map(parse_json(json), name + ".json"); + if (map.name != name){ + throw ParseException(std::format("{}.json: name is \"{}\".", name, map.name)); + } + parsed.emplace(name, tile_grid_from_map(map)); + } + return parsed; + }(); + return grids; +} + +} + +const TileGrid& story_grid(const std::string& name){ + const std::map& grids = story_grids(); + if (auto iter = grids.find(name); iter != grids.end()){ + return iter->second; + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No BDSP story map named \"" + name + "\"."); +} + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.h new file mode 100644 index 0000000000..41f0d61d64 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.h @@ -0,0 +1,52 @@ +/* BDSP AutoStory - Map grids + * + * From: https://github.com/PokemonAutomation/ + * + * The story's maps are JSON files in the shared map schema + * (Pokemon_MapData.h), PokemonBDSP/Programs/AutoStory/Maps, built into the + * program by CMake, read with the shared loader and turned into the tile + * grids the planner walks. Each map's X::grid() returns story_grid("X"). + * + * TODO: move the maps to PokemonAutomation/Packages (Resources/PokemonBDSP/Maps) when ready + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_MapGrids_H +#define PokemonAutomation_PokemonBDSP_AutoStory_MapGrids_H + +#include +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_MapData.h" +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// (name, JSON text) of each map in PokemonBDSP/Programs/AutoStory/Maps/, +// built into the program by pa_embed_text_files() (cmake/EmbedTextFiles.cmake). +const std::vector>& bdsp_map_json(); + +// A map's tiles as a tile grid: walls, open ground, tall grass, south +// ledges, doors and signs; a standing person ("npc" object) is an NPC tile. +// Throws ParseException, naming the map, for what BDSP's grids have no +// tile for (water, ledges other than south, items, wanderers). +Pokemon::TileGrid tile_grid_from_map(const Pokemon::MapData& map); + +// "(x, y): 'N' here, '.' there", or nothing when the grids are the same +// size and equal cell for cell. +std::optional grid_difference(const Pokemon::TileGrid& here, const Pokemon::TileGrid& there); + +// The grid of the map `name`, read from bdsp_map_json() once. Throws +// InternalProgramError for a name it does not have. +const Pokemon::TileGrid& story_grid(const std::string& name); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp new file mode 100644 index 0000000000..781af0c643 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp @@ -0,0 +1,92 @@ +/* BDSP AutoStory - Oreburgh City tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_OreburghCity.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace OreburghCity{ + +using namespace Pokemon; + + +// Map source: the decomp (Diamond land_data 0022, 0023, 0175, 0024 = +// Platinum map_data_022/023/175/024, 2026-10-31) with the objects from +// its events file. +// Console checks: none yet. +// 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_0022, 0023, 0175 and +// 0024: four cells of the Sinnoh matrix, columns 8 and 9, rows 23 and 24; +// the same cells are map_data_022, 023, 175 and 024 in pret/pokeplatinum), +// with the objects from its events file (zone_event narc_0044, +// events_oreburgh_city.json in Platinum); BDSP keeps Diamond/Pearl's layout. +// Local (x, y) = world (x - 256, z - 736); 64 x 64 tiles. The town sits on +// the upper rows (10 to 26); row 27 is the cliff, and the stairs down it are +// the road at columns 44 to 48 (rows 27 to 43), which opens into the mine +// yard at row 44. The two one-tile stubs south of the gym, (24, 27..29) and +// (31, 27..29), and the pocket at (35..42, 28..29) are walkable in the data +// but closed off: dead ends, not stairs. +// Exits: Oreburgh Gate west through the cave mouth (1, 13), entered from the +// warp tile (2, 13); Route 207 north up columns 41 to 46 (rows 0 to 9); the +// Mine south over the warp tiles (44..48, 59), walked onto heading south. +// Warp tiles the player stands on are written as '.': (2, 13), (44..48, 59), +// and (49, 11), the Mining Museum's entrance. Objects, from the events file: +// door (26, 20) to the Gym; its signpost (22, 20); +// door (47, 20) to the Pokemon Center; +// door (29, 10) to the Poke Mart; doors (15, 10) and (22, 10) to the +// north-west and north houses; door (17, 20) to the west house; door (37, +// 16) to the middle house; door (56, 28) to the east house; door (51, 36) +// to the south house; +// map signposts (4, 11) and (44, 1); signboards (45, 12) and (45, 56); +// steam vents (9, 26), (11, 26), (13, 26), (60, 52), (60, 53), objects +// that block, as '#'; +// Youngster (10, 16), looks north, not a trainer; +// Worker (11, 25), looks south and west, not a trainer; +// Hiker wanders around (47, 26), columns 46 to 48, rows 25 to 27: off the +// grid; +// School Kid F wanders around (32, 18), column 32, rows 16 to 20: off the +// grid; +// Guitarist wanders around (23, 13), columns 22 to 24, rows 10 to 16: off +// the grid; +// Camper walks back and forth from (36, 19), columns 33 to 39, row 19: off +// the grid; +// Battle Girl wanders around (36, 23), column 36, rows 21 to 25: off the +// grid; +// Pokefan F wanders around (45, 38), column 45, rows 37 to 39: off the +// grid; +// Worker wanders around (37, 39), columns 36 to 38, rows 38 to 40: off the +// grid; +// Worker wanders around (50, 41), column 50, rows 38 to 44: off the grid; +// Worker wanders around (56, 57), columns 55 to 57, rows 54 to 60: off the +// grid; +// Machop wanders around (55, 56), columns 53 to 57, rows 54 to 58: off the +// grid; +// Barry (26, 21), in front of the Gym door, "wander" with no range (hidden +// by flag 410 once the story moves on): off the grid, listed so the route +// knows he may stand there. +// None of the people here is a trainer. Platinum (pret/pokeplatinum) decodes +// the same terrain tile for tile; it adds items on the ground at (35, 37) +// and (39, 38), a Battle Girl at (51, 21), a Machop at (56, 46) and a +// wandering Machop around (35, 45), none of which Diamond has. +const TileGrid& grid(){ + return story_grid("OreburghCity"); +} + +const TilePos POKEMON_CENTER_DOOR{47, 20}; +const TilePos POKEMON_CENTER_DOORSTEP{46, 21}; +const TilePos GYM_DOOR{26, 20}; +const TilePos GYM_DOORSTEP{26, 21}; +const TilePos GATE_MOUTH{1, 13}; + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h new file mode 100644 index 0000000000..7a3f66901b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h @@ -0,0 +1,37 @@ +/* BDSP AutoStory - Oreburgh City tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see + * the .cpp's header for the cells, the offset and the objects. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_OreburghCity_H +#define PokemonAutomation_PokemonBDSP_AutoStory_OreburghCity_H + +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace OreburghCity{ + + +const Pokemon::TileGrid& grid(); + +// Doors are the tiles walked into. The Center's doorstep: the decomp's door +// tile is (47, 20), and 20 D-pad taps west from the doorstep stand under +// the Gym's door (26, 20) on the console (r204 to r215), which puts the +// doorstep at x 46: one of the two is a tile off, a probe decides. +extern const Pokemon::TilePos POKEMON_CENTER_DOOR; +extern const Pokemon::TilePos POKEMON_CENTER_DOORSTEP; +extern const Pokemon::TilePos GYM_DOOR; +extern const Pokemon::TilePos GYM_DOORSTEP; +// The Oreburgh Gate's east mouth, walked into heading west from (2, 13). +extern const Pokemon::TilePos GATE_MOUTH; + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp new file mode 100644 index 0000000000..310728cda5 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp @@ -0,0 +1,51 @@ +/* BDSP AutoStory - Oreburgh Gate 1F tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_OreburghGate.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace OreburghGate{ + +using namespace Pokemon; + + +// Map source: the decomp (Diamond land_data 0418 = Platinum map_data_441, +// 2026-10-31) with the objects from its events file. +// Console checks: none yet. +// 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_0418: one cell, the only +// one of matrix 003, at column 0, row 0; map_data_441 in pret/pokeplatinum), +// with the objects from its events file (zone_event narc_0250, +// events_oreburgh_gate_1f.json in Platinum); BDSP keeps Diamond/Pearl's +// layout. Local (x, y) = world (x - 0, z - 0) in the cave's own matrix; 32 x +// 32 tiles. The cave floor is '.'; the rocks Rock Smash breaks are '#' +// (eight of them, each hidden once smashed). +// Exits: the warp tiles the player stands on are written as '.': (4, 22) +// leaves west to Route 203 and (27, 22) east to Oreburgh City; the cave +// mouths behind them, (3, 22) and (28, 22), are 'D'. (20, 5) is the stairs +// down to B1F (a warp tile too). Objects, from the events file: +// Picnicker Diana (24, 21), looks south, sees 3; +// Camper Curtis (17, 25), looks north, sees 3; +// Hiker (7, 20), looks south, not a trainer (the Rock Smash HM); +// rocks (19, 6), (14, 4), (12, 10), (11, 11), (11, 25), (13, 26), (15, +// 26), (25, 24), as '#'. +// The two trainers face the row-22 corridor from either side: Diana sees +// (24, 22..24) and Curtis (17, 22..24). Platinum decodes this cave +// identically, terrain and objects. +const TileGrid& grid(){ + return story_grid("OreburghGate"); +} + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h new file mode 100644 index 0000000000..f0e2984230 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h @@ -0,0 +1,27 @@ +/* BDSP AutoStory - Oreburgh Gate tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see + * the .cpp's header for the cells, the offset and the objects. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_OreburghGate_H +#define PokemonAutomation_PokemonBDSP_AutoStory_OreburghGate_H + +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace OreburghGate{ + + +const Pokemon::TileGrid& grid(); + + +} +} +} +} +#endif 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..915bdc1474 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp @@ -0,0 +1,61 @@ +/* BDSP AutoStory - Oreburgh Gym tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#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(){ + return story_grid("OreburghGym"); +} + +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_OreburghMine.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.cpp new file mode 100644 index 0000000000..53e2d1dd6d --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.cpp @@ -0,0 +1,65 @@ +/* BDSP AutoStory - Oreburgh Mine tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_OreburghMine.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace OreburghMine{ + +using namespace Pokemon; + + +// Map source: the decomp (pret/pokediamond land_data narc_0314, matrix 006; +// 2026-10-31) with the objects from its events file; Platinum's +// map_data_337 is the same. +// Console checks (2026-10-28): the corridor's rocks zigzag a row at a time, +// the room's second row passes under the worker on the first, Roark +// stands a row above the bottom row between two rocks; the walk north +// from the corridor's corner reached the entrance hall (r99). +// Status: no checkpoint has run on this grid yet. 01.02 and 01.03 passed +// 3x on the stretched image grid it replaces, which had every row one +// lower, the top corridor a row short, the room's second row blocked +// and no ledge in the west corridor; re-run both. +// +// Decoded from Pokemon Diamond's collision table: the one cell of matrix +// 006, with the objects from its events file. Local (x, y) = world (x, z); +// 32 x 32 tiles. The way up to the entrance hall is the warp tile (15,1), +// marked 'D': stepping onto it leaves the room. The console walked north +// into the hall from column 14 (r99), where this table has the way up only +// at column 15: a stick hold drifts, or BDSP's stairs are wider. +// The corridor from the top (13..17, 2..6) zigzags down to the room's first +// row (15); the room's second row (17) is open from 2 to 29 and passes +// under the worker and his Machop on the first; the coal block fills +// (7..24, 18..25) with the corridors either side; the west corridor has a +// ledge (2..4, 19), crossed southward only; the bottom rows 28..29 run +// under the block. +// Objects, from the events file: Roark (18,28), between two rocks (17,28) +// and (19,28); workers who stand still at (8,28) looking north, (26,20) +// looking west and (21,15) with Machop at (20,15) and (27,15); Poke Balls +// at (4,28) and (26,24), walls until picked up. A Machop wanders along row +// 28, columns 11..13, and is left off the grid. +const TileGrid& grid(){ + return story_grid("OreburghMine"); +} + +// The first open row below the warp tile, where the walk in from the hall +// leaves us (or the row below: the plan's first legs run to walls and meet). +const std::vector& corridor_top(){ + static const std::vector tiles{{14, 2}, {15, 2}, {16, 2}}; + return tiles; +} + +const TilePos ROARK{18, 28}; +const TilePos CORRIDOR_EXIT_START{14, 10}; + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h new file mode 100644 index 0000000000..4dc823b486 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h @@ -0,0 +1,39 @@ +/* BDSP AutoStory - Oreburgh Mine tiles + * + * From: https://github.com/PokemonAutomation/ + * + * The Oreburgh Mine's coal room (Bulbapedia's "B2F") as a tile grid, with + * Roark, for checkpoint 01.03. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_OreburghMine_H +#define PokemonAutomation_PokemonBDSP_AutoStory_OreburghMine_H + +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace OreburghMine{ + + +const Pokemon::TileGrid& grid(); + +// Where the walk in from the entrance hall leaves us: the top of the rocky +// corridor, the first open row below the warp tile. +const std::vector& corridor_top(); + +// Roark, between two rocks a row above the room's bottom row. Talked to from +// the tile below him, facing north. +extern const Pokemon::TilePos ROARK; +// The corridor's corner a wall-to-wall route ends on, below a straight +// walk north out into the entrance hall. +extern const Pokemon::TilePos CORRIDOR_EXIT_START; + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp new file mode 100644 index 0000000000..1593266d18 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp @@ -0,0 +1,47 @@ +/* BDSP AutoStory - Plan Costs + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_PlanCosts.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using Pokemon::RobustPlanCosts; + + +RobustPlanCosts route_plan_costs(){ + RobustPlanCosts costs; + costs.exact_open_tiles = costs.max_open_tiles; + costs.per_open_tile = 2; + costs.leg_not_at_wall = 6; + return costs; +} + +RobustPlanCosts waypoint_plan_costs(){ + RobustPlanCosts costs; + costs.exact_open_tiles = costs.max_open_tiles; + costs.per_open_tile = 0; + costs.leg_not_at_wall = 0; + return costs; +} + +RobustPlanCosts town_plan_costs(){ + RobustPlanCosts costs; + // A tile's hold moves exactly a tile; a longer open leg may end a tile + // either way ("south 5" went 6 in r134a), so the plan ends on a wall. + costs.exact_open_tiles = 1; + costs.open_error_per = 8; + costs.leg_not_at_wall = 6; + costs.per_open_tile = 2; + return costs; +} + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h new file mode 100644 index 0000000000..825ef24312 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h @@ -0,0 +1,46 @@ +/* BDSP AutoStory - Plan Costs + * + * From: https://github.com/PokemonAutomation/ + * + * The costs the story's walks are planned with on the BDSP maps + * (Pokemon::plan_robust_route()), apart from the walker, so the map + * tests plan each walk the way the program does. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_PlanCosts_H +#define PokemonAutomation_PokemonBDSP_AutoStory_PlanCosts_H + +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// The default: open legs are whole tiles on the D-pad, so they land exactly +// at any length; a wall at a leg's end is still worth a little, and each +// open tile a little more. +Pokemon::RobustPlanCosts route_plan_costs(); + +// Between two corners of a walked line: whole tiles on the D-pad land +// exactly, so an open leg costs nothing extra and the straight leg to the +// corner beats a run to a wall and a tap back (r244a: "west 10 to the +// wall, east 1" through the wandering Youngster lost the count; "west 9" +// in taps keeps it). +Pokemon::RobustPlanCosts waypoint_plan_costs(); + +// In town: a one-tile step lands exactly, a short open leg a tile either +// way, and both cost little more than a leg to a wall, so a plan steps a +// tile across and walks straight through a gap rather than going round the +// town to end every leg on a wall (Sandgem: 13 legs, r127a and r128b +// walked into the Lab and the Mart). Pair it with a check at the end (a +// sign read) for the timed legs. +Pokemon::RobustPlanCosts town_plan_costs(); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp new file mode 100644 index 0000000000..500bc58358 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp @@ -0,0 +1,62 @@ +/* BDSP AutoStory - Ravaged Path tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_RavagedPath.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace RavagedPath{ + +using namespace Pokemon; + + +// Map source: rows 30 to 53 from the decomp (map_data_435/436, 2026-10-31); +// the rows above from the DP image, unused by any route. +// Console checks: entrance (19,50), the stairs, the three-wide corridor, the +// rocks, the east end and the exit tile (2026-10-31 probes). +// Status: 01.09 reaches the exit by hand; no program pass yet. +// +// Rows 30 to 53 are decoded from Pokemon Platinum's collision table for +// this map (the pret/pokeplatinum decompilation, land data 435/436 of map +// matrix 051) with the objects from its events file; BDSP keeps the layout. +// Water and the items on the ground are '#'; the smashable rocks are '#' +// too and listed in rocks(). Checked on the console 2026-10-31 (r235b and +// D-pad probes): in from the south door onto (19, 50), up the stairs +// (rows 45 to 47, columns 18 to 20) and north to the wall at row 39; the +// corridor is three wide up to row 41 and opens east on rows 42 to 44, +// with the rocks at (22, 42) and (22, 43), the Potion ball at (22, 44) and +// a rock at (23, 44). Rows 0 to 29 are still the hand trace from +// Bulbapedia's Ravaged_Path_DP.png (stretched from 528x672 to 528x864), with +// '?' where the untraced west chambers continue; nothing we walk is there. +const TileGrid& grid(){ + return story_grid("RavagedPath"); +} + +const std::vector& rocks(){ + static const std::vector tiles{ + {11, 36}, {7, 37}, {12, 37}, {8, 38}, {10, 38}, {10, 39}, {13, 39}, + {7, 40}, {9, 40}, {17, 40}, {12, 41}, {22, 42}, {22, 43}, {23, 44}, + }; + return tiles; +} + +const TilePos ENTRANCE{19, 50}; + +const std::vector& before_rocks(){ + static const std::vector tiles{{21, 42}, {21, 43}}; + return tiles; +} + +const TilePos EAST_END{29, 44}; +const TilePos ABOVE_EXIT{28, 44}; + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h new file mode 100644 index 0000000000..4f03dacf39 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h @@ -0,0 +1,47 @@ +/* BDSP AutoStory - Ravaged Path tiles + * + * From: https://github.com/PokemonAutomation/ + * + * The Ravaged Path (the cave on Route 204) as a tile grid, for checkpoint + * 01.05: from its south door, where Route 204's south half enters, east + * along its lower corridor to the door out onto Route 204's north half. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RavagedPath_H +#define PokemonAutomation_PokemonBDSP_AutoStory_RavagedPath_H + +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace RavagedPath{ + + +// With every Rock Smash rock in place (blocked). +const Pokemon::TileGrid& grid(); + +// The Rock Smash rocks of the traced part, blocked in grid(). Each breaks +// for good once smashed, so a plan after a smash opens that tile. +const std::vector& rocks(); + +// Where walking in from Route 204's south half leaves us: the tile above the +// south door, at the foot of the room below the stairs. +extern const Pokemon::TilePos ENTRANCE; +// The tiles west of the two rocks across the lower corridor: from either, +// facing east, A offers Rock Smash, and the corridor is open to its east end. +const std::vector& before_rocks(); +// The corridor's east end on its bottom row, where walls stop a walk east +// and south: a route can end here, and nowhere else near the way out. +extern const Pokemon::TilePos EAST_END; +// The tile above the door out onto Route 204's north half, a tile west of +// EAST_END: walk south. +extern const Pokemon::TilePos ABOVE_EXIT; + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp new file mode 100644 index 0000000000..2a79840580 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp @@ -0,0 +1,82 @@ +/* BDSP AutoStory - Route 201 tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_Route201.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route201{ + +using namespace Pokemon; + + +// Map source: the decomp (pret/pokediamond land_data narc_0005 and +// narc_0006, 2026-10-31) with the objects from its events file; +// Platinum's map_data_005/006 have the same terrain. +// Console checks: the border sign read from (54,4) facing east, row 3 open +// east of the grass to Sandgem's fence, row 5 to Sandgem without a stop, +// the Potion lady on row 3 (2026-10-28 to 30, CFR "walk"). +// Status: no checkpoint has run on this grid yet. 00.02 to 00.04 and the +// mart_lady checkpoint passed on the image-traced grid it replaces (3/4 +// of a tile per row) and must be re-run. +// +// Decoded from Pokemon Diamond's collision table: cells (26,3) and (26,4) +// of the Sinnoh matrix, with the objects from its events file. Local (x, y) +// = world (x - 96, z - 839); 64 x 25 tiles, rows 0..2 are padding. The +// columns are the ones the image-traced grid had (its anchors matched the +// decomp exactly); the rows are the game's: the image gave 20 rows for 25. +// Sandgem Town's grid joins at column 64, row -3 (its front row is row 4). +// +// Edges: west, rows 6..7 and 11 (Lake Verity, off the map); south, the +// Twinleaf gap (14..17, 21..24); east, rows 3..6, into Sandgem. Ledges: +// row 12 (0..3 and 8..31) and (53..57, 9) in the north-east; both are +// jumped southward only. The north-east grass (42..52, 3..6) is four rows +// deep and its tree stub (51..52) stands on rows 7..12; the middle grass +// (20..29, 13..16) four rows; the south-east grass (42..57, 18) and +// (46..57, 19..20). +// Objects, from the events file: the signs (55,4) to Sandgem (BORDER_SIGN), +// (13,17) to Twinleaf and the Trainer Tips sign (40,12); a School Kid who +// stands at (57,8) looking west (not yet seen on the console). Route 201 +// has no trainers and no items on the ground. Wanderers, left off the grid: +// a Breeder around (27,15), columns 26..28, rows 14..16; a Lass along row +// 16, columns 44..48. The Poke Mart lady, who gives 10 Potions, stands +// still at (44,3) in Diamond's events file and on the console (the user, +// 2026-11-01): left off the grid, since her talk is walked to, not planned +// (r113a..r120a missed her by the walk, not by her moving). Rowan, Barry +// and the briefcase by the lake are hidden by story flags and left off. +const TileGrid& grid(){ + return story_grid("Route201"); +} + + +// The arrow sign to Sandgem Town, world (151,843), on the row of Sandgem's +// doors (its row 7). Checked on the console (2026-10-30, CFR "walk"): a row +// south of the lady's row (row 3), east stops at the sign's west side and A +// reads "Route 201 -> Sandgem Town" (a green box); north from there is one +// row, to row 3. Row 3 runs on east past the sign's north side to the Lab's +// fence. Row 5, the path, runs from the grass's west edge to Sandgem without +// a stop. +const TilePos BORDER_SIGN{55, 4}; +// Her spawn tile in Diamond is (44,3), the east end of the top grass row. +// On the console (by hand, then through the Lab Console; 99715d5d6 and +// f823453e9 on bdsp/new-game-intro-v2) she stood at (43,3), and walking +// west along row 3 from the trees at its east end stopped at (44,3), facing +// her; her lines need one A each, 1.5 s apart. r113a..r120a +// missed her talk walking to her, not because she moved. +// Checked on the console (2026-10-30, CFR "walk"), twice: from the grass's +// west edge on row 5, north stops at the trees 2 rows up, and east from +// there stops at her. r135a missed her walking west along row 4. +const TilePos POTION_GIVER{43, 3}; +const TilePos POTION_GIVER_TALK_FROM{44, 3}; + + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h new file mode 100644 index 0000000000..24481753bf --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h @@ -0,0 +1,37 @@ +/* BDSP AutoStory - Route 201 tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Route 201 (Twinleaf Town to Sandgem Town) as a tile grid, from the + * Diamond decompilation's collision table; BDSP keeps DP's tile layout. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route201_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Route201_H + +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route201{ + + +const Pokemon::TileGrid& grid(); + +// The sign by the Sandgem Town border, at the east end of the route. +extern const Pokemon::TilePos BORDER_SIGN; +// The Poke Mart lady, who gives 10 Potions: at the west end of the top +// grass row. Not on the grid: she turns and may wander. +extern const Pokemon::TilePos POTION_GIVER; +// East of her: walking west along her row from the open ground east of the +// grass stops here, facing her. +extern const Pokemon::TilePos POTION_GIVER_TALK_FROM; + + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp new file mode 100644 index 0000000000..9bb6b1a2a3 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp @@ -0,0 +1,101 @@ +/* BDSP AutoStory - Route 202 tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_Route202.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route202{ + +using namespace Pokemon; + + +// Map source: the decomp (pret/pokediamond land_data narc_0014, with the +// margins from narc_0006, 0007 and 0173; 2026-10-31) and the objects +// from its events file; Platinum's map_data_014 has the same terrain. +// Console checks: the player under the south ledge at (22,24) beside the +// trees at (21,24), the sign a row below at (24,25), the save spot +// (30,24) against the east trees, Natalie's challenge at (22,22), east +// along the row above the ledge stops at column 30 and column 30 runs +// north to row 4 (r75), the catch spot's walls (2026-10-29/30); trees, +// not grass, at (15..20, 28..29) below the catch patch (r253: west +// along row 29 stopped at column 21, beside the trees); a tree at +// (21, 30), south of the pocket at (21, 29) where the catch's save +// loads (r254: south from there was blocked at once). +// Status: no checkpoint has run on this grid yet. 00.04 passed on the +// image-traced grid it replaces (26 rows for 32) and must be re-run; +// its legs south of the catch spot are three rows longer here. +// +// Decoded from Pokemon Diamond's collision table: cell (25,5) of the Sinnoh +// matrix, with the objects from its events file. Local (x, y) = world +// (x - 159, z - 800); 36 x 32 tiles, the whole cell, so the grid's edges +// are where the game changes its location banner. The columns are the ones +// the image-traced grid had (its ledges, tree pillars and signs matched the +// decomp exactly); the rows are the game's: the image gave 26 rows for 32. +// Sandgem Town's grid starts on the row below row 31, at column 1. +// +// Exits: north, the gap (11..18, 0) to Jubilife City (EXIT_JUBILIFE in its +// middle); south, (21..30, 31) into Sandgem, where the road narrows to +// 25..30 for two rows. Ledges: row 10 (9..13 and +// 22..27) and row 23 (9..13 and 22..30), jumped southward only. The east +// wall is column 33 from row 10 to 20, column 32 on row 21 and column 31 on +// row 22, the row right above the south ledge: east along that row stops at +// column 30 (r75), and column 30 is open north from there to row 4 under +// Logan's row. +// Objects, from the events file: three trainers who stand still, Youngster +// Tristan (7,13), Lass Natalie (22,18) and Youngster Logan (26,4), all +// facing south, with the sight ranges the events give; a Potion ball (3,6), +// a wall until picked up; the signs (17,4) to Jubilife, (15,16) Trainer Tips +// and (24,25) to Sandgem. BDSP has trees where Diamond's catch patch has +// its two bottom rows, (15..20, 28..29): the console's patch is three rows +// between tree rows, as the image-traced grid had it. A Youngster who is not a trainer wanders along row +// 8, columns 9..11, and is left off the grid (the image-traced grid had him +// as a fourth trainer facing east). Dawn's tile (15,27) is hidden by a +// story flag. +const TileGrid& grid(){ + return story_grid("Route202"); +} + + +// Where 00.03's save after the catch stands: the bottom row of the +// tall-grass patch at (15..20, 25..27), world (178,827). On the console the +// sign at (24,25) is 5 columns right and 2 rows up, walking east stops at +// the trees after 11 tiles and north at the trees after 2; south are trees +// (the decomp's two more grass rows are trees in BDSP, r253). +const TilePos CATCH_SPOT{19, 27}; +// Where 00.04 saves once it has Potions, before Route 202's trainers (the +// console's saves from r113a..r117a stand here too): under the south ledge, +// against the east trees, world (189,824). +const TilePos SAVE_SPOT{30, 24}; + +// From the events file: each trainer's tile, facing and sight range. +// Natalie challenged us at (22,22), walking east along the row above the +// ledge (r75), the fourth tile of her sight. +const TilePos TRAINER_TRISTAN{7, 13}; +const TilePos TRAINER_NATALIE{22, 18}; +const TilePos TRAINER_LOGAN{26, 4}; + +const std::vector& trainer_sights(){ + static const std::vector sights{ + {"tristan", TRAINER_TRISTAN, Direction::SOUTH, 5}, + {"natalie", TRAINER_NATALIE, Direction::SOUTH, 4}, + {"logan", TRAINER_LOGAN, Direction::SOUTH, 5}, + }; + return sights; +} + +// The middle of the 8-tile gap at (11..18, 0), world (174,800), below the +// 3-wide neck of Jubilife's south exit (173..175). +const TilePos EXIT_JUBILIFE{15, 0}; + + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h new file mode 100644 index 0000000000..cee0a1e49a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h @@ -0,0 +1,49 @@ +/* BDSP AutoStory - Route 202 tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Route 202 (Sandgem Town to Jubilife City) as a tile grid, from the + * Diamond decompilation's collision table; BDSP keeps DP's tile layout. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route202_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Route202_H + +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route202{ + + +const Pokemon::TileGrid& grid(); + +// Where the player stands in the tall grass after the catching tutorial. +extern const Pokemon::TilePos CATCH_SPOT; +// Under the south ledge, against the east trees: where the console's 00.04 +// save stands. Two walls pin it. +extern const Pokemon::TilePos SAVE_SPOT; + +// The three trainers, from the events file: Youngster Tristan in the west +// field, Lass Natalie above the south ledge, Youngster Logan by the east +// grass. All face south. +extern const Pokemon::TilePos TRAINER_TRISTAN; +extern const Pokemon::TilePos TRAINER_NATALIE; +extern const Pokemon::TilePos TRAINER_LOGAN; + +// Their sight lines, in this map's tiles. The story wants these battles. +const std::vector& trainer_sights(); + +// A tile in the gap of the north edge; walking north from it leaves for +// Jubilife City. +extern const Pokemon::TilePos EXIT_JUBILIFE; + + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp new file mode 100644 index 0000000000..642168d015 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp @@ -0,0 +1,78 @@ +/* BDSP AutoStory - Route 203 tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_Route203.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route203{ + +using namespace Pokemon; + + +// Map source: the decomp (pret/pokediamond land_data narc_0019 and +// narc_0020, with Jubilife's column 0 from narc_0016; 2026-10-31) and +// the objects from its events file. Platinum adds an X Defense ball at +// (40,14). +// Console checks (r227 hand pass, 2026-10-31): the Gate's warp at column +// 55, the ledge on row 15 (38..48), the beaten girl at column 43 on the +// second sand row, the row below her straight west to Jubilife (35 +// taps, no row change), the blue-haired trainer at the sand's west end. +// Status: no checkpoint has run on this grid yet. 01.06 passed on the +// image-traced grid it replaces (its east stretch corrected on the +// console) and must be re-run: the decomp has four sand rows under the +// ledge where the console counted three (9 taps south from (55,9); the +// decomp has 10 open tiles, so the first tap may only have turned). +// +// Decoded from Pokemon Diamond's collision table: cells (23,6) and (23,7) +// of the Sinnoh matrix, with the objects from its events file. Local +// (x, y) = world (x - 191, z - 740); 61 x 24 tiles. Column 0 is Jubilife's +// east edge. The columns are the ones the image-traced grid had (its gate +// warp, ledge and signs matched the decomp exactly); the rows are the +// game's: the image squeezed the west and middle stretches. +// - West stretch (columns 5..22): the field (5..22, 4..19) with grass at +// 5..8 (8..13), a ledge (18..22, 13), and the road on rows 17..19 that +// runs to Jubilife at column 0. +// - Middle stretch (23..37): the pond (29..34, 7..11) cuts the strip north +// of it, by the Repel ball (31,5), off from the rest: r222g's walk got +// stuck up there. The way through is along the bottom, rows 16..19. +// - East stretch (38..55): the Gate's mouth is (56,9), its warp tile +// (55,9). South from (55,9) is open to row 19. The ledge on row 15 +// (38..48) is crossed southward only. The sand below it is four rows, +// 16..19: the blue-haired trainer (Youngster Dallas, looks south, sees +// 4) at the sand's west end on its first row, the girl (Youngster +// Sebastian in the events file, looks west, sees 5) at (43,17) on its +// second. +// Row 18 runs in one straight line west from the sand to Jubilife; row 17 +// is blocked by the girl and the trainer, row 19 by trees at (36..37, 19). +// Objects, from the events file: trainers who stand still, 'N': Youngster +// Michael (13,10), looks west, sees 2; Dallas (31,16); Sebastian (43,17); +// Lass Madeline (49,8), looks south, sees 5. Items that block their tile +// until picked up, '#': a Poke Ball (20,10) and a Repel (31,5). Signs: to +// Jubilife (9,16), Trainer Tips (26,10) and (47,12), to Oreburgh (53,7); +// Jubilife's own sign to Route 203 stands at (7,16) in its events, not in +// this map's. Left off: a Lass who wanders along row 17 (14..16) and the +// Youngster at (54,16) who stands still in Diamond but wanders in BDSP (the +// blue-haired man near the Gate, on the console); Barry (10,17) is hidden +// by a story flag. +const TileGrid& grid(){ + return story_grid("Route203"); +} + +// The warp tile the Gate puts us on, and its open neighbours. +const std::vector& gate_exit(){ + static const std::vector tiles{{55, 9}, {54, 9}, {55, 8}, {55, 10}}; + return tiles; +} + + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h new file mode 100644 index 0000000000..9bf526197b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h @@ -0,0 +1,32 @@ +/* BDSP AutoStory - Route 203 tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Route 203 as a tile grid, for checkpoint 01.06: from the Oreburgh Gate's + * west exit to Jubilife City's east edge. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route203_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Route203_H + +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route203{ + + +const Pokemon::TileGrid& grid(); + +// Where stepping out of the Oreburgh Gate may leave us when Route 203's +// banner shows: the warp tile west of the cave's mouth and its neighbours. +const std::vector& gate_exit(); + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp new file mode 100644 index 0000000000..eee289d1ce --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp @@ -0,0 +1,91 @@ +/* BDSP AutoStory - Route 204 tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_Route204.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route204{ + +using namespace Pokemon; + + +// Map source: the decomp (map_data_031, 2026-10-31) with the objects from +// its events file; before that the DP image, 3/4 rows. +// Console checks: row 27 open under the cliff, the stairs, Taylor's sight at +// column 17 (recorded human walk, 2026-10-31). Suspects: column 23 rows +// 12 to 19 blocked on the console (r242a); three open rows under the +// cave, not four (r241a, r243a). +// Status: 01.10 not passed yet; the route is the recorded human line +// (floaroma_waypoints()). +// +// Decoded from Pokemon Platinum's collision table for this map (the +// pret/pokeplatinum decompilation, map_data_031.bin: one cell of the Sinnoh +// matrix, column 5, row 21; local (x, y) = world (x - 160, z - 672)) with +// the objects from its events file; BDSP keeps the layout. Water and the +// items on the ground are '#'. Objects: the Ravaged Path's door, arriving +// on (20, 26); the twins (15, 7) and (16, 7) looking south; Aroma Lady +// Taylor (17, 20) looking south and east; Bug Catcher Brandon walking back +// and forth, on row 12 on the console (r246a), drawn at (20, 12) by the DP +// map, (22, 13) in Platinum's data; the arrow signpost +// (17, 9); a Youngster who is not a trainer wanders rows 27 and 28 below +// the cave, off the grid. The path north into Floaroma is columns 10 to 12 +// at the top. +// The 2026-10-29 hand run went out of the cave, west to the stairs, up them +// into the pocket the ledge (row 15) closes, back down, east and north +// through the tall grass, and west below the flower beds past the twins. +// Before 2026-10-31 this grid was traced from Bulbapedia's DP map image, +// whose rows are 12 px to the columns' 16: every row was 3/4 of a tile. +const TileGrid& north_grid(){ + return story_grid("Route204North"); +} + +const TilePos CAVE_EXIT{20, 26}; + +bool in_floaroma_path(const TilePos& pos){ + return pos.x >= 10 && pos.x <= 12 && pos.y <= 5; +} + +std::vector north_trainer_sights(){ + return { + {"Twins (left)", {15, 7}, Direction::SOUTH, 3}, + {"Twins (right)", {16, 7}, Direction::SOUTH, 4}, + {"Aroma Lady Taylor", {17, 20}, Direction::SOUTH, 4}, + {"Aroma Lady Taylor", {17, 20}, Direction::EAST, 4}, + // Bug Catcher Brandon paces east and west below the flower beds + // and stopped us on row 12 (r246a: "Say, what's your opinion on bug + // Pokemon?"); the DP map draws him at (20, 12), Platinum's data + // has him at (22, 13). The tile is a guess until a shot fixes it. + {"Bug Catcher Brandon", {20, 12}, Direction::WEST, 4}, + {"Bug Catcher Brandon", {20, 12}, Direction::EAST, 4}, + }; +} + +std::vector floaroma_waypoints(){ + // The line a human walked on 2026-10-31 (recorded; drawn over the DP + // map image): a tile south out of the cave's mouth; west along the row + // under the cliff, where the Youngster wanders (he stood a row below + // as we passed; the walker waits for him when he is in the way); north + // up the middle of the stairs; east along the corridor, where Aroma + // Lady Taylor sees us at column 17 and walks over for her battle; north + // up column 19 through the tall grass; west below the flower beds; + // north between the beds. The DP image shows a trainer sprite at + // (20, 12), by the corner where the line turns west: not seen yet on + // the console. The ledge on row 15 closes the stairs' column going + // north, so the line goes round through the grass. + // Column 11 for the last stretch: (12, 6) is blocked on the console + // (r248a, twice), grass in Platinum's data; the detour through (11, 6) + // passed. + return {{20, 27}, {11, 27}, {11, 22}, {19, 22}, {19, 12}, {11, 12}, {11, 5}}; +} + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.h new file mode 100644 index 0000000000..edd4b29cc0 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.h @@ -0,0 +1,43 @@ +/* BDSP AutoStory - Route 204 tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Route 204's north half as a tile grid, for checkpoint 01.05: from the + * door out of the Ravaged Path up to the path into Floaroma Town. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route204_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Route204_H + +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route204{ + + +const Pokemon::TileGrid& north_grid(); + +// Where leaving the Ravaged Path puts us: the tile below its door. +extern const Pokemon::TilePos CAVE_EXIT; + +// Whether a tile is in the path north into Floaroma, between the flower +// beds' fences: walking north from here leaves the route. +bool in_floaroma_path(const Pokemon::TilePos& pos); + +// The twins below the right-hand flower bed: a double battle when they see +// us walk past below them. +std::vector north_trainer_sights(); + +// The corners of the line into Floaroma from the cave's exit, as a human +// walked it (2026-10-31): the last is in the path into Floaroma. +std::vector floaroma_waypoints(); + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp new file mode 100644 index 0000000000..4f022f4dce --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp @@ -0,0 +1,87 @@ +/* BDSP AutoStory - Route 204 South tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_Route204South.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route204South{ + +using namespace Pokemon; + + +// Map source: the decomp (map_data_021, 2026-10-31) with the objects from +// its events file. +// Console checks: column 14 stops at the signpost (14,17), column 13 is +// grass to the cliff, Sarah fights on row 21 (r233a, r234a, probes). +// Status: 01.08 passes once (r235a). +// +// Decoded from Pokemon Platinum's collision table for this map (the +// pret/pokeplatinum decompilation, res/field/maps/data/map_data_021.bin: +// 32 x 32 tiles, one cell of the Sinnoh matrix at column 5, row 22), with +// the objects from its events file (events_route_204_south.json); BDSP +// keeps Diamond/Pearl's layout. Local (x, y) = world (x - 160, z - 704). +// Water is '#'. Objects, from the events file: +// door to the Ravaged Path (11, 1); its signboard (10, 2); +// the "204" arrow signpost (14, 17), which stops a walk north up the +// street's column 14 (r233a, r234a); +// Lass Samantha (11, 8), looks south; Lass Sarah (12, 21), looks north +// and east by turns; Youngster Tyler (7, 18), looks west and east; +// items on the ground (17, 18), (29, 12), (2, 28), as '#'; +// a Youngster who is not a trainer wanders west and east along row 2 in +// front of the door: off the grid, the walker waits for him. +// Checked on the console 2026-10-31 (r233a, r234a, probes): north up +// column 14 from Jubilife stops at the signpost (14, 17); column 13 is +// tall grass all the way up and stops at the cliff (13, 2), the door two +// columns west; Sarah walked up and fought us once on row 21. +// Row 31, columns 12 to 15, joins the top of Jubilife's north street: +// walking south there leaves the route. +const TileGrid& grid(){ + return story_grid("Route204South"); +} + +std::vector jubilife_entry(){ + // The walk north looks between 400 ms holds, so it may stop up to two + // tiles past the border. + return {{14, 31}, {14, 30}, {14, 29}}; +} + +const TilePos BELOW_DOOR{11, 2}; + +std::vector trainer_sights(){ + // Sarah turns between north and east; her east line crosses the + // street's columns, so a walk north meets it or not by luck (r233a + // passed, r234a fought). The planner cannot avoid it: she is listed + // so the route knows whom it may meet, with the range that fits. + return { + {"Lass Samantha", {11, 8}, Direction::SOUTH, 4}, + {"Lass Sarah", {12, 21}, Direction::NORTH, 4}, + {"Lass Sarah", {12, 21}, Direction::EAST, 4}, + {"Youngster Tyler", {7, 18}, Direction::EAST, 4}, + {"Youngster Tyler", {7, 18}, Direction::WEST, 4}, + }; +} + +std::vector tiles_to_avoid(){ + std::vector tiles; + for (const TrainerSight& trainer : trainer_sights()){ + if (trainer.name == "Lass Sarah" && trainer.facing == Direction::EAST){ + continue; + } + for (const TilePos& pos : sight_tiles(grid(), trainer)){ + tiles.push_back(pos); + } + } + return tiles; +} + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h new file mode 100644 index 0000000000..d03ed47c1b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h @@ -0,0 +1,44 @@ +/* BDSP AutoStory - Route 204 South tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Route 204's south half as a tile grid, for checkpoint 01.08: from the top + * of Jubilife City's north street to the door of the Ravaged Path. The + * north half (Route204::north_grid) is reached only through the cave, so + * the two halves are separate maps. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route204South_H +#define PokemonAutomation_PokemonBDSP_AutoStory_Route204South_H + +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Route204South{ + + +const Pokemon::TileGrid& grid(); + +// Where walking north out of Jubilife's street puts us: its column on the +// route's bottom rows: the walk stops within two tiles of the border. +std::vector jubilife_entry(); + +// The tile below the Ravaged Path's door; walking north from it enters. +extern const Pokemon::TilePos BELOW_DOOR; + +// The trainers whose sight lines a route may cross. +std::vector trainer_sights(); + +// The sight-line tiles a route can keep out of: all but Sarah's east line, +// which crosses the whole street. +std::vector tiles_to_avoid(); + + +} +} +} +} +#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 new file mode 100644 index 0000000000..fc0c0b7b61 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp @@ -0,0 +1,199 @@ +/* BDSP AutoStory - Route records + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_RouteRecords.h" +#include "PokemonBDSP_AutoStory_JubilifeCity.h" +#include "PokemonBDSP_AutoStory_Route201.h" +#include "PokemonBDSP_AutoStory_Route203.h" +#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{ +namespace PokemonBDSP{ +namespace RouteRecords{ + +using namespace Pokemon; + +namespace{ +const TileGrid* twinleaf(){ return &TwinleafTown::grid(); } +const TileGrid* route201(){ return &Route201::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(); } + +// 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, true, Segment00Lines::ROUTE_201_ARRIVAL, { + {Direction::NORTH, 6, LegEnd::COUNT, "up the exit path to (15, 18): Barry's warning fires on that row"}, + {Direction::WEST, 3, LegEnd::COUNT, "after the scene, along row 18 to column 12"}, + {Direction::NORTH, 2, LegEnd::COUNT, "to row 16, the lower level's row to the Lakefront"}, + {Direction::WEST, 12, LegEnd::COUNT, "to (0, 16), 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 Route201::grid(), the decomp's since #111"}, + {"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"}, + }; +} + +// 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, true, Segment00Lines::ROUTE_201_RETURN, { + {Direction::EAST, 5, LegEnd::COUNT, "to (5, 14): Rowan and Dawn's scene fires on that column"}, + {Direction::EAST, 12, LegEnd::COUNT, "after the scene, along row 14 to column 17"}, + {Direction::EAST, 12, LegEnd::COUNT, "through the tall grass to column 29; the Breeder wanders rows 14 to 16 there"}, + {Direction::EAST, 12, LegEnd::COUNT, "to column 41"}, + {Direction::NORTH, 7, LegEnd::COUNT, "up column 41 to row 7, beside the north-east grass"}, + {Direction::EAST, 1, LegEnd::COUNT, "into the grass"}, + {Direction::NORTH, 2, LegEnd::COUNT, "to row 5"}, + {Direction::EAST, 10, LegEnd::COUNT, "through the grass to (52, 5), its last tile"}, + {Direction::EAST, 11, LegEnd::COUNT, "to (63, 5), 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::grid()"}, + {"00.03", "Sandgem Town: Dawn at the entrance", "Sandgem Town", sandgem, true, Segment00Lines::SANDGEM_ARRIVAL, { + {Direction::EAST, 4, LegEnd::COUNT, "along row 12 to (4, 12): 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; on Sandgem'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, true, 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}, + {Direction::NORTH, 16, LegEnd::COUNT, "stick 3960 ms: up to the street east to Route 203", false}, + {Direction::SOUTH, 2, LegEnd::COUNT, "stick 600 ms: back onto the street", false}, + {Direction::EAST, 0, LegEnd::NPC, "along the street onto Route 203 until Barry stops us; rows retried 0, +1, +1, -3, -1 when a wall comes first"}, + }, "jubilife_to_barry(); stick holds from the console, 2026-10-29, counted in tiles on the image grid's 3/4 rows: recount in taps before giving this record a start tile (task #21)"}, + {"01.02", "Barry to Oreburgh City through the Oreburgh Gate", "Route 203", route203, true, std::nullopt, { + {Direction::EAST, 0, LegEnd::WALL, "along the row Barry stopped us on"}, + {Direction::NORTH, 0, LegEnd::WALL, "to the top wall, then a row south at a time until east goes on (up to ten)"}, + {Direction::EAST, 0, LegEnd::NPC, "to the Hiker"}, + {Direction::EAST, 0, LegEnd::TRANSITION, "into the Oreburgh Gate"}, + {Direction::EAST, 0, LegEnd::TRANSITION, "through the Gate into Oreburgh City"}, + }, "route203_to_oreburgh(); no start tile: Barry stops us on whichever row we came along"}, + {"01.04", "Oreburgh Pokemon Center doorstep to the Gym", "Oreburgh City", oreburgh_city, true, OreburghCity::POKEMON_CENTER_DOORSTEP, { + {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", "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"}, + {Direction::NORTH, 0, LegEnd::WALL, "along the cliff"}, + {Direction::EAST, 2, LegEnd::COUNT, "to the stairs' column"}, + {Direction::NORTH, 0, LegEnd::WALL, "up the stairs"}, + {Direction::WEST, 0, LegEnd::WALL, "along the platform"}, + {Direction::SOUTH, 1, LegEnd::COUNT, "onto the Gate's row"}, + {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, true, 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"}, + }, "jubilife_to_rowan(); by hand 2026-10-31 (18 presses), r230b; the stick hold's count was taken on the image grid's 3/4 rows, so no start tile yet"}, + {"01.08", "Jubilife's north street onto Route 204", "Jubilife City", jubilife, true, std::nullopt, { + {Direction::NORTH, 0, LegEnd::BANNER, "up the street until Route 204's banner; the planned walk to the Ravaged Path door follows"}, + }, "jubilife_to_ravaged_path() step 1"}, + {"01.09", "Ravaged Path's east end out onto Route 204 North", "Ravaged Path", ravaged_path, true, RavagedPath::EAST_END, { + {Direction::WEST, 1, LegEnd::COUNT, "onto the tile above the way out"}, + {Direction::SOUTH, 0, LegEnd::TRANSITION, "out of the cave"}, + }, "ravaged_path() exit; the planned legs before it are tested as plans"}, + {"01.10", "Route 204 North's path into Floaroma", "Route 204 North", route204_north, true, TilePos{11, 5}, { + {Direction::NORTH, 0, LegEnd::BANNER, "from (11, 5) until Floaroma Town's banner; the waypoint line before it is tested as plans"}, + }, "route204_to_floaroma(); r248a"}, + {"01.11", "Floaroma's old couple", "Floaroma Town", floaroma, true, FloaromaTown::ROUTE_204_ARRIVAL, { + {Direction::WEST, 8, LegEnd::COUNT, "D-pad taps along the flower field's bottom row"}, + {Direction::NORTH, 0, LegEnd::NPC, "until the old woman stops us (3 tiles on r251a)"}, + {Direction::WEST, 1, LegEnd::COUNT, "below the old man"}, + {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_RouteRecords.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h new file mode 100644 index 0000000000..5fbcc8b09d --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h @@ -0,0 +1,67 @@ +/* BDSP AutoStory - Route records + * + * From: https://github.com/PokemonAutomation/ + * + * Every walk a checkpoint makes that is not planned on a grid, written + * down as legs: the direction, the count or the thing that ends the leg + * (a wall, a person, a door, a location banner, a map transition, a + * scene). The checkpoints run their own code today; these records say + * what that code does, so a test can trace each leg on the map once the + * map is right, and so the next version can run the record instead. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RouteRecords_H +#define PokemonAutomation_PokemonBDSP_AutoStory_RouteRecords_H + +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace RouteRecords{ + + +// What ends a leg. +enum class LegEnd{ + COUNT, // exactly `tiles` tiles (D-pad taps, or a stick hold timed for them) + WALL, // walks until the map stops the player; `tiles` is the expected count, 0 if unknown + NPC, // walks until a person stops the player + DOOR, // walks into a door or cave mouth (a fade) + BANNER, // walks until the next map's location banner shows + TRANSITION, // walks until a map transition (the screen goes dark) + SCENE, // walks until a cutscene takes over +}; + +struct RouteLeg{ + Pokemon::Direction direction; + size_t tiles; + LegEnd end; + std::string note; + // A counted leg walked by D-pad taps (or a leg the map ends) is exact; + // a count from a timed stick hold is an estimate, a tile or two either + // way, until someone counts it on the console in taps. + bool exact = true; +}; + +struct RouteRecord{ + std::string checkpoint; // "01.05" + std::string title; + std::string map; // the map the legs are on ("" when none exists yet) + const Pokemon::TileGrid* (*grid)(); // that map's grid, nullptr when none + bool traceable; // the grid's rows are the game's (decomp or console), so legs can be traced + std::optional start; // where the record starts on that grid + std::vector legs; + std::string source; // the code and the console runs behind it +}; + +const std::vector& all(); + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp new file mode 100644 index 0000000000..84afae03f1 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp @@ -0,0 +1,96 @@ +/* BDSP AutoStory - Sandgem Town tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_SandgemTown.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace SandgemTown{ + +using namespace Pokemon; + + +// Map source: the decomp (pret/pokediamond land_data narc_0007, 2026-10-31) +// with the signs and doors from its events file; Platinum's map_data_007 +// is the same. The rows from the doors down have been the decomp's since +// 2026-10-29; the four rows above the doors were the image's, and the +// grid now starts where the game's map does, four rows higher. +// Console checks: all three doors, five signs, the row below the doors east +// to the trees and north from it, the Lab's sign read facing west, the +// walk south from Route 202 stopping above the Mart (2026-10-29/30). +// Status: no checkpoint has run on this grid yet. 00.04, 00.05 and the +// Sandgem Center and Mart lady checkpoints passed with the image's rows +// above the doors; changed since: every tile is 4 rows lower (the grid +// begins at the map's edge), the road from Route 202 narrows on row 6 +// (the walk south from Route 202 stops at (29,5)), and the gap between +// the Lab's fence and the Center on the doors' row is four wide (11..14). +// Re-run them all. +// +// Decoded from Pokemon Diamond's collision table: cell (26,5) of the Sinnoh +// matrix, with the signs and doors from its events file. Local (x, y) = +// world (x - 160, z - 832); 34 x 32 tiles, the whole cell, so the grid's +// edges are where the game changes its location banner. Route 201 joins at +// column -64, row 7 (its row 4 is this grid's row 11); Route 202's road +// comes down onto row 0 at columns 24..29. +// +// Buildings are blocked; each door is the tile the player walks into, on +// the building's front row (row 10). Top left: Professor Rowan's lab, with a +// fence running west along row 10 to the map edge. Top middle: Pokemon +// Center. Top right: Poke Mart. Exits: west, rows 11..15 (Route 201); north, +// (24..29, 0) (Route 202: the road is 6 wide on rows 0..1, 10 wide on rows +// 2..5 and 6 wide again, columns 20..25, on rows 6..9); south, (20..25, 31) +// (the beach). +// +// The image squeezed the rows below the doors: it put both houses' doors +// three rows too high and the east house's wall where the game has open +// ground; r123a planned a west leg to that wall, ran on past it and entered +// the west house's door going north. The townspeople south of the Mart (a +// youngster and two breeders, who stand still in Diamond at (11,22) and +// (23,20)) wander on the console: not marked. Rowan, Barry and Dawn are +// hidden by story flags. +// +// Checked on the console: walking south from Route 202 along its column 30 +// stops above the Poke Mart, where the road narrows (counted as two rows +// above the signs' row on the image grid; the decomp has the wall at (29,6), +// so the stop is (29,5)), and walking west from there stops at (20,5). The +// lab's sign stands on row 11, in front of the fence: walking west along +// row 11 stops at it. +const TileGrid& grid(){ + return story_grid("SandgemTown"); +} + + +const TilePos ROUTE_202_ENTRY_STOP{29, 5}; +// The lab's door, between its two front windows. +const TilePos LAB_DOOR{8, 10}; +// The Pokemon Center's glass door. +const TilePos POKEMON_CENTER_DOOR{17, 10}; +// On the console, walking south along the road's west edge above it stops +// at (20,9), above it. +const TilePos POKEMON_CENTER_SIGN{20, 10}; +// The Poke Mart's door. +const TilePos POKE_MART_DOOR{27, 10}; +// Walking east along the doors' front row stops here, against the trees. +// Checked on the console (2026-10-30, CFR "walk"): east along row 12 (the +// path under the Lab's sign) from Route 201 stops at (29,12), and north from +// there stops here. From below the Center's sign (20,11), west stops at the +// Lab's sign, which reads facing west; south from there stops at the house +// 4 rows down, and north back at the sign's row; west of the house's north +// side is trees. A 200 ms hold south took one row; 300 ms took one or two. +const TilePos FRONT_ROW_EAST_END{29, 11}; + +std::vector below_sign_gap(){ + return {{21, 11}, {22, 11}, {23, 11}, {24, 11}}; +} + + + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.h new file mode 100644 index 0000000000..cb5d223828 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.h @@ -0,0 +1,49 @@ +/* BDSP AutoStory - Sandgem Town tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Sandgem Town as a tile grid, from the Diamond decompilation's collision + * table; BDSP keeps DP's tile layout. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_SandgemTown_H +#define PokemonAutomation_PokemonBDSP_AutoStory_SandgemTown_H + +#include +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace SandgemTown{ + + +const Pokemon::TileGrid& grid(); + +// Where the walk south from Route 202 down the road's east side stops, +// above the Poke Mart where the road narrows. +extern const Pokemon::TilePos ROUTE_202_ENTRY_STOP; +extern const Pokemon::TilePos LAB_DOOR; +extern const Pokemon::TilePos POKEMON_CENTER_DOOR; +// The sign east of the Pokemon Center's door. Walking north from row 14 in +// its column stops on the tile below it. +extern const Pokemon::TilePos POKEMON_CENTER_SIGN; +extern const Pokemon::TilePos POKE_MART_DOOR; +// The east end of the row below the Center's and the Mart's doors, at the +// trees: one known tile to plan the way north to Route 202 from. From the +// Mart's door, a tile either side of its column, no plan north is robust. +extern const Pokemon::TilePos FRONT_ROW_EAST_END; +// The doors' front row below the gap between the Center's sign and the +// Mart's, columns 21..24: the only way north from that row that passes no +// door. Walking north from any of them leaves town for Route 202. Walking +// north from anywhere else on the row between columns 18 and 26 stops at a +// sign or a wall; the Center's door is at 17, the Mart's at 27. +std::vector below_sign_gap(); + + + +} +} +} +} +#endif 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..fe4bed1a06 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp @@ -0,0 +1,156 @@ +/* BDSP AutoStory - Segment 00's walked lines + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonBDSP_AutoStory_Route201.h" +#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). Route201::grid() leaves off the cell's seven wall rows +// at the top, so it starts 7 rows lower; SandgemTown::grid() is its whole +// cell. +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::grid(), {96, 839}); + maps.add(MAP_VERITY_LAKEFRONT, VerityLakefront::grid(), {64, 832}); + maps.add(MAP_SANDGEM_TOWN, SandgemTown::grid(), {160, 832}); + 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, 18}, 6, 1, + "the first time north of Twinleaf (var 0x4086 = 0)"}, + {"Route 201's row 19 after the warning", MAP_ROUTE_201, {14, 19}, 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, 14}, 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, 11}, 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, 24}; +const TilePos BARRY_WARNING{15, 18}; +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, 14}; +const TilePos ROWAN_STOP{5, 14}; +const TilePos ROUTE_201_EAST_END{63, 5}; +const TilePos SANDGEM_ARRIVAL{0, 12}; +const TilePos DAWN_STOP{4, 12}; + +// 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 13 to 16) is the way +// both to and from the lake: the upper level's ledges only drop onto it. +// Row 16 is used westward and row 14 eastward: on the way out Rowan and +// the counterpart are not yet on (8, 14..15) and Barry is gone from (16, +// 16), but 16 keeps the line one row off the Breeder's range; on the way +// back 14 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, 18}), route201({12, 16}), route201({0, 16}), + 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 19 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, 14}), route201({29, 14}), route201({41, 14}), + route201({41, 7}), route201({42, 7}), route201({42, 5}), route201({52, 5}), + route201(ROUTE_201_EAST_END), sandgem(DAWN_STOP), + }, "Dawn at Sandgem's entrance", {"Dawn at Sandgem's entrance"}), + }; + return lines; +} + +} +} +} +} 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..8269643c84 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h @@ -0,0 +1,84 @@ +/* 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; + +// 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/Data/PokemonBDSP_AutoStory_StoryMaps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp new file mode 100644 index 0000000000..25f7180d5f --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp @@ -0,0 +1,246 @@ +/* BDSP AutoStory - Story maps + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_JubilifeCity.h" +#include "PokemonBDSP_AutoStory_OreburghMine.h" +#include "PokemonBDSP_AutoStory_RavagedPath.h" +#include "PokemonBDSP_AutoStory_Route203.h" +#include "PokemonBDSP_AutoStory_Route204.h" +#include "PokemonBDSP_AutoStory_Route204South.h" +#include "PokemonBDSP_AutoStory_OreburghCity.h" +#include "PokemonBDSP_AutoStory_FloaromaTown.h" +#include "PokemonBDSP_AutoStory_Route201.h" +#include "PokemonBDSP_AutoStory_Route202.h" +#include "PokemonBDSP_AutoStory_SandgemTown.h" +#include "PokemonBDSP_AutoStory_StoryMaps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace Pokemon; + + +const char* const MAP_ROUTE_201 = "Route 201"; +const char* const MAP_SANDGEM_TOWN = "Sandgem Town"; +const char* const MAP_ROUTE_202 = "Route 202"; +const char* const MAP_JUBILIFE_CITY = "Jubilife City"; +const char* const MAP_OREBURGH_MINE = "Oreburgh Mine"; +const char* const MAP_RAVAGED_PATH = "Ravaged Path"; +const char* const MAP_ROUTE_204 = "Route 204"; +const char* const MAP_OREBURGH_CITY = "Oreburgh City"; +const char* const MAP_FLOAROMA_TOWN = "Floaroma Town"; +const char* const MAP_ROUTE_204_SOUTH = "Route 204 South"; +const char* const MAP_ROUTE_203 = "Route 203"; + + +// Offsets are the maps' places in the game's world grid (the decomp's +// cells): Route 201 at world (96,839), Sandgem Town at (160,832), Route 202 +// at (159,800). Route 201's row 4 is Sandgem's row 11, below the doors, and +// Route 202's road comes down off its row 31 onto Sandgem's row 0. +const MapSet& story_maps(){ + static const MapSet maps = []{ + MapSet maps; + maps.add(MAP_ROUTE_201, Route201::grid(), {0, 0}); + maps.add(MAP_SANDGEM_TOWN, SandgemTown::grid(), {64, -7}); + maps.add(MAP_ROUTE_202, Route202::grid(), {63, -39}); + return maps; + }(); + return maps; +} + +const MapSet& jubilife_maps(){ + static const MapSet maps = []{ + MapSet maps; + maps.add(MAP_JUBILIFE_CITY, JubilifeCity::grid(), {0, 0}); + return maps; + }(); + return maps; +} + +// Planned one map at a time: Route 203 and Jubilife joined ran for minutes +// without a plan (r224a, 2026-10-31). +const MapSet& route203_maps(){ + static const MapSet maps = []{ + MapSet maps; + maps.add(MAP_ROUTE_203, Route203::grid(), {0, 0}); + return maps; + }(); + return maps; +} + +bool on_route203_west_line(const TilePos& pos){ + return pos.y == 18 && pos.x >= 24 && pos.x <= 42; +} + +// Columns 42..63, rows 12..25 of the Jubilife grid (world x 170..191, +// z 748..761), as a map of its own: the cut is the map's edge, which no leg +// may cross or stop on, not a wall a plan could walk "to". +namespace{ +const TilePos JUBILIFE_EAST_CORNER{42, 12}; +const int JUBILIFE_EAST_BOTTOM = 25; +} +const MapSet& jubilife_east_maps(){ + static const MapSet maps = []{ + const TileGrid& city = JubilifeCity::grid(); + const TilePos corner = JUBILIFE_EAST_CORNER; + std::vector rows; + for (int y = corner.y; y <= JUBILIFE_EAST_BOTTOM; y++){ + std::string row; + for (int x = corner.x; x < city.width(); x++){ + row += tile_char(city.at({x, y})); + } + rows.push_back(row); + } + MapSet maps; + maps.add(MAP_JUBILIFE_CITY, TileGrid(rows), {0, 0}); + return maps; + }(); + return maps; +} + +// Route 203's road (rows 17..19 of its grid) meets Jubilife's east street, +// rows 21..24 of its grid, at its east edge; the banner shows a tile or two +// in. Both in the corner map's tiles, from the Jubilife grid's. +const std::vector& jubilife_east_entrance(){ + static const std::vector tiles = []{ + std::vector tiles; + for (int y = 21; y <= 24; y++){ + for (int x = 61; x <= 63; x++){ + tiles.push_back({x - JUBILIFE_EAST_CORNER.x, y - JUBILIFE_EAST_CORNER.y}); + } + } + return tiles; + }(); + return tiles; +} + +// The north road where it leaves the plaza, columns 44..48 of rows 16..20. +bool on_jubilife_north_road(const TilePos& pos){ + const int x = pos.x + JUBILIFE_EAST_CORNER.x; + const int y = pos.y + JUBILIFE_EAST_CORNER.y; + return x >= 44 && x <= 48 && y >= 16 && y <= 20; +} + +const MapSet& oreburgh_mine_maps(){ + static const MapSet maps = []{ + MapSet maps; + maps.add(MAP_OREBURGH_MINE, OreburghMine::grid(), {0, 0}); + return maps; + }(); + return maps; +} + +MapSet ravaged_path_maps(const std::vector& smashed){ + TileGrid grid = RavagedPath::grid(); + for (const TilePos& rock : smashed){ + grid.set(rock, TileType::WALKABLE); + } + MapSet maps; + maps.add(MAP_RAVAGED_PATH, grid, {0, 0}); + return maps; +} + +const MapSet& oreburgh_city_maps(){ + static const MapSet maps = []{ + MapSet maps; + maps.add(MAP_OREBURGH_CITY, OreburghCity::grid(), {0, 0}); + return maps; + }(); + return maps; +} + +const MapSet& floaroma_maps(){ + static const MapSet maps = []{ + MapSet maps; + maps.add(MAP_FLOAROMA_TOWN, FloaromaTown::grid(), {0, 0}); + return maps; + }(); + return maps; +} + +const MapSet& route204_north_maps(){ + static const MapSet maps = []{ + MapSet maps; + maps.add(MAP_ROUTE_204, Route204::north_grid(), {0, 0}); + return maps; + }(); + return maps; +} + +const MapSet& route204_south_maps(){ + static const MapSet maps = []{ + MapSet maps; + maps.add(MAP_ROUTE_204_SOUTH, Route204South::grid(), {0, 0}); + return maps; + }(); + return maps; +} + +bool story_map_plannable(const std::string& map){ + return map == MAP_ROUTE_201 || map == MAP_ROUTE_202; +} + +bool story_at_jubilife_exit(const TilePos& world){ + const std::optional tile = story_maps().to_local(world); + return tile && tile->map == MAP_ROUTE_202 && tile->pos.y <= 3; +} + +std::vector story_save_spots(){ + const MapSet& maps = story_maps(); + return { + maps.to_world(MAP_ROUTE_202, Route202::CATCH_SPOT), + maps.to_world(MAP_ROUTE_202, Route202::SAVE_SPOT), + }; +} + +std::vector story_door_front(const char* map, const TilePos& door){ + const TilePos below = story_maps().to_world(map, door.next(Direction::SOUTH)); + return {below.next(Direction::WEST), below, below.next(Direction::EAST)}; +} + +std::vector story_catch_save_area(){ + const MapSet& maps = story_maps(); + std::vector area; + for (int y = 25; y <= 29; y++){ + for (int x = 15; x <= 21; x++){ + const TilePos pos = maps.to_world(MAP_ROUTE_202, {x, y}); + if (maps.world().standable(pos)){ + area.push_back(pos); + } + } + } + return area; +} + +std::vector story_after_training_area(){ + const MapSet& maps = story_maps(); + const TilePos catch_spot = maps.to_world(MAP_ROUTE_202, Route202::CATCH_SPOT); + std::vector area; + for (int y = catch_spot.y - 2; y <= catch_spot.y + 2; y++){ + for (int x = catch_spot.x - 1; x <= catch_spot.x + 1; x++){ + // The rows below the catch spot are trees in BDSP. + if (maps.world().standable({x, y})){ + area.push_back({x, y}); + } + } + } + return area; +} + +std::vector story_trainer_sights(){ + std::vector sights = Route202::trainer_sights(); + for (TrainerSight& sight : sights){ + sight.pos = story_maps().to_world(MAP_ROUTE_202, sight.pos); + } + return sights; +} + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h new file mode 100644 index 0000000000..3e27b3dc7a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h @@ -0,0 +1,108 @@ +/* BDSP AutoStory - Story maps + * + * From: https://github.com/PokemonAutomation/ + * + * The maps the story walks through, joined on one grid. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_H + +#include "Pokemon/Navigation/Pokemon_MapSet.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +extern const char* const MAP_ROUTE_201; +extern const char* const MAP_SANDGEM_TOWN; +extern const char* const MAP_ROUTE_202; +extern const char* const MAP_JUBILIFE_CITY; +extern const char* const MAP_OREBURGH_MINE; +extern const char* const MAP_RAVAGED_PATH; +extern const char* const MAP_ROUTE_204; +extern const char* const MAP_ROUTE_204_SOUTH; +extern const char* const MAP_ROUTE_203; + +// Route 201, Sandgem Town and Route 202. +const Pokemon::MapSet& story_maps(); + +// Jubilife City on its own: 00.05 starts there after Dawn's scene, so it is +// not joined to Route 202. +const Pokemon::MapSet& jubilife_maps(); +// Route 203 on its own (01.06), and whether a tile is on row 18 between the +// two cliffs: row 18 runs straight west from there under the west cliff +// into Jubilife, so the plan ends there (no leg may leave the map) and a +// walk west until Jubilife's banner shows goes on from there. +const Pokemon::MapSet& route203_maps(); +bool on_route203_west_line(const Pokemon::TilePos& pos); +// Jubilife City's north-east corner (01.06), at Jubilife's own tile +// coordinates: the rest of the city is walled off, so the plan searches only +// the part the walk needs. Where Route 203's road enters it, and whether a +// tile is on the north road below the plaza: walking north from there goes +// up the road to Route 204 (and Rowan's scene). +const Pokemon::MapSet& jubilife_east_maps(); +const std::vector& jubilife_east_entrance(); +bool on_jubilife_north_road(const Pokemon::TilePos& pos); +// The Oreburgh Mine's coal room on its own (01.03). +const Pokemon::MapSet& oreburgh_mine_maps(); + +// The Ravaged Path on its own (01.05), with the rocks in `smashed` open. +Pokemon::MapSet ravaged_path_maps(const std::vector& smashed = {}); + +// Route 204's north half on its own (01.05). +const Pokemon::MapSet& route204_north_maps(); + +// Route 204's south half on its own (01.08): it joins the north half only +// through the Ravaged Path, so the two are separate maps. +const Pokemon::MapSet& route204_south_maps(); + +// Oreburgh City alone (01.04, 01.05), and Floaroma Town alone (01.11). +extern const char* const MAP_OREBURGH_CITY; +extern const char* const MAP_FLOAROMA_TOWN; +const Pokemon::MapSet& oreburgh_city_maps(); +const Pokemon::MapSet& floaroma_maps(); + +// Whether a plan may cross this map. Routes are traced from the DP maps and +// their tree walls carried over to BDSP; towns changed more in the remake, so +// a town is crossed by screen-driven legs until the console has confirmed its +// grid. +bool story_map_plannable(const std::string& map); + +// The open rows at the top of Route 202, in world tiles: walking north from +// any of them enters Jubilife City. +bool story_at_jubilife_exit(const Pokemon::TilePos& world); + +// Where the post-catch half of 00.04 may start, in world tiles: the catch +// spot (00.03 saves there after the catch) and the save spot under the +// ledge (00.04 saves there once it has Potions, before Route 202's trainers). +std::vector story_save_spots(); + +// Where 00.04b's save after the catch may stand, in world tiles: wherever +// the catch's walks in the grass ended, the patch (15..20, 25..27) and the +// lawn column east of it, (21, 25..29), down to the pocket behind the tree +// row where r252's catch ended and saved (the save loads there: (21, 29) +// by the screen, the 202 sign 3 columns right and 4 rows up). +std::vector story_catch_save_area(); + +// Where a walk out of the door `door` of `map` may leave us, in world tiles: +// the tile below it and its neighbours either side, since the door opening +// is not lined up with one tile (Jubilife's Center, r85). +std::vector story_door_front(const char* map, const Pokemon::TilePos& door); + +// Where we may stand after training in the catch grass, in world tiles: the +// training walks up and down the catch spot's column, between the tree walls +// north and south of the grass, so a battle may stop us on any of its +// three rows. A column either side allows for where the catch left us. +std::vector story_after_training_area(); + +// Route 202's trainers, in world tiles of story_maps(). +std::vector story_trainer_sights(); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp new file mode 100644 index 0000000000..b7d0f60bb6 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp @@ -0,0 +1,61 @@ +/* BDSP AutoStory - Twinleaf Town tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_TwinleafTown.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace TwinleafTown{ + +using namespace Pokemon; + + +// Map source: the decomp (Diamond land_data 0000 = Platinum map_data_000, +// 2026-10-31) with the objects from its events file. +// Console checks: none yet. +// 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_0000: one cell of the +// Sinnoh matrix at column 3, row 27; map_data_000 in pret/pokeplatinum), +// with the objects from its events file (zone_event narc_0389, +// events_twinleaf_town.json in Platinum); BDSP keeps Diamond/Pearl's layout. +// Local (x, y) = world (x - 96, z - 864); 32 x 32 tiles. The pond at the +// bottom, (12..19, 27..31), is water, '#'. The pockets (7..10, 1..2) and +// (21..24, 1..2) are walkable in the data but closed in. +// Exit: Route 201 north through columns 12 to 19 at row 0 (the route's +// bottom rows open the same eight columns). The player's house is the +// south-east one, door (20, 21), and Barry's the north-west one, door (9, +// 11): behind (20, 21) the interior has Mom and the TV, behind (9, 11) only +// Barry's mother, and Platinum's scripts name the mailbox at (18, 21) the +// player's. pret/pokediamond's map constants call them the other way round +// (MAP_TWINLEAF_PLAYER_HOUSE_1F is the house behind (9, 11)); the interiors +// say otherwise. Objects, from the events file: +// door (20, 21), the player's house; its mailbox (18, 21), read like a +// sign, 'S'; +// door (9, 11), Barry's house; its mailbox (13, 11), 'S'; Barry himself +// stands on the door tile at the start (looks south, hidden by flag 402): +// the door keeps its 'D'; +// door (20, 11) to the north-east house; door (10, 21) to the south-west +// house; +// map signpost (16, 14); +// Guitarist (12, 5), looks north, west and east, not a trainer; +// Collector (12, 25), looks around, not a trainer; +// Pokemon Breeder F wanders around (23, 14), columns 22 to 24, row 14: off +// the grid. +// No trainers. Platinum decodes the same terrain and objects; its one extra, +// an arrow signpost at world (109, 856), stands in Route 201's cell. +const TileGrid& grid(){ + return story_grid("TwinleafTown"); +} + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h new file mode 100644 index 0000000000..7e4de02893 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h @@ -0,0 +1,27 @@ +/* BDSP AutoStory - Twinleaf Town tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see + * the .cpp's header for the cells, the offset and the objects. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_TwinleafTown_H +#define PokemonAutomation_PokemonBDSP_AutoStory_TwinleafTown_H + +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace TwinleafTown{ + + +const Pokemon::TileGrid& grid(); + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp new file mode 100644 index 0000000000..a696281964 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp @@ -0,0 +1,56 @@ +/* BDSP AutoStory - Verity Lakefront tiles + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_MapGrids.h" +#include "PokemonBDSP_AutoStory_VerityLakefront.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace VerityLakefront{ + +using namespace Pokemon; + + +// Map source: the decomp (Diamond land_data 0004 = Platinum map_data_004, +// 2026-10-31) with the objects from its events file. +// Console checks: none yet. +// 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_0004: one cell of the +// Sinnoh matrix at column 2, row 26; map_data_004 in pret/pokeplatinum), +// with the objects from its events file (zone_event narc_0319, +// events_verity_lakefront.json in Platinum); BDSP keeps Diamond/Pearl's +// layout. Local (x, y) = world (x - 64, z - 832); 32 x 32 tiles. The map +// header covers four cells (columns 1 and 2, rows 25 and 26); the other +// three are trees and an 8 x 8 patch of shallow water, so only this one is +// kept. The pocket (0..3, 0..3) is that water (puddle, behaviour 0x16), +// closed in. +// Route 201's west edge is this cell's column 31: open on rows 14 to 18 (the +// upper level) and 20 to 23 (the lower), with Route 201's x = 96 at our x = +// 32. From the upper level the way west is over the ledge at column 20 (rows +// 14 to 18, jumped west, shown as a wall), landing on columns 14 to 19; the +// lower level joins it at (16..19, 20). The ledges on row 19, 'v', drop +// south onto the lower level. The lake's entrance is the warp tiles (16, 11) +// and (17, 11), walked onto heading north, written as '.'; their destination +// is Lake Verity, or its Galactic version once that story state is set. +// Objects, from the events file: +// arrow signpost (15, 14), beside the path to the lake; +// Barry (16, 11), looks south, hidden by flag 435, standing on the warp +// tile: '.' wins; +// no one else, and no trainers. +// Platinum decodes the same terrain; it has no Barry object here and calls +// the sign a trainer-tips signpost. +const TileGrid& grid(){ + return story_grid("VerityLakefront"); +} + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.h new file mode 100644 index 0000000000..3ededdc534 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.h @@ -0,0 +1,27 @@ +/* BDSP AutoStory - Verity Lakefront tiles + * + * From: https://github.com/PokemonAutomation/ + * + * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see + * the .cpp's header for the cells, the offset and the objects. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_VerityLakefront_H +#define PokemonAutomation_PokemonBDSP_AutoStory_VerityLakefront_H + +#include "Pokemon/Navigation/Pokemon_TileGrid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace VerityLakefront{ + + +const Pokemon::TileGrid& grid(); + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/FloaromaTown.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/FloaromaTown.json new file mode 100644 index 0000000000..733c172f5c --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/FloaromaTown.json @@ -0,0 +1,92 @@ +{ + "name": "FloaromaTown", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "######........................##", + "##..##........................##", + "..............................##", + "..............................##", + "..............................##", + "..............................##", + "..............................##", + "..................#####.......##", + "..................#####.......##", + "..................#####.......##", + "..................#####.......##", + "..........####...S##.##.......##", + "..........####................##", + "..........####................##", + "..........#D##................##", + ".......................####..S##", + ".......................####...##", + ".......................#D##...##", + "..............................##", + ".............S..................", + "................................", + "................................", + "................................", + "..............#####....####...##", + "..............#####....####...##", + "..............#####....####...##", + "..............##D##....#D##...##", + "..............................##", + "..............................##", + "..............................##", + "########.#...###################", + "########.#...###################" + ], + "objects": [ + { + "name": "npc_2_1", + "kind": "npc", + "x": 2, + "y": 1 + }, + { + "name": "npc_3_1", + "kind": "npc", + "x": 3, + "y": 1 + }, + { + "name": "npc_6_10", + "kind": "npc", + "x": 6, + "y": 10 + }, + { + "name": "npc_23_11", + "kind": "npc", + "x": 23, + "y": 11 + }, + { + "name": "npc_19_21", + "kind": "npc", + "x": 19, + "y": 21 + }, + { + "name": "npc_2_23", + "kind": "npc", + "x": 2, + "y": 23 + }, + { + "name": "npc_3_23", + "kind": "npc", + "x": 3, + "y": 23 + }, + { + "name": "npc_11_26", + "kind": "npc", + "x": 11, + "y": 26 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/JubilifeCity.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/JubilifeCity.json new file mode 100644 index 0000000000..7c7c5574c0 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/JubilifeCity.json @@ -0,0 +1,136 @@ +{ + "name": "JubilifeCity", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "##########################################..............########", + "##########################################..............########", + "############################################.....###############", + "############################################......##############", + "############################################......##############", + "############################################......##############", + "############################################......##############", + "#############################################....###############", + "############################....#########.......S.##############", + "############################....#########.........##############", + "#########..#########..######....#########.........##############", + "#########..#########..######....#########.........##############", + "#########..#########..######....#########.........##############", + "#########..#########..######....#########.........##############", + "#########..#########..######....#########.........##############", + "#########..##D###D##..######....####D####.........##############", + "#########.............######...............#.....#######....####", + "#########.............######......................######....####", + "..#######.............######......................######....####", + "..###########S......########...........S.........S##D###....####", + "..#.S.#.......................#..........................#.S####", + "................................................................", + "D...............................................................", + "D...............................................................", + "................................................................", + "..#...#.......................#..........................#..####", + "..############.............####......####...................####", + "..############.............####......####................#######", + "##############.################...##.####..#.....######..#######", + "##############.################...##.####.........#####..#######", + "##############.################...................#D############", + "################################.........................#######", + "################################.........................##D####", + "################################.........................#######", + "################################.........................#######", + "###############............#####.........................#######", + "###############............#####......#####..............#######", + "###############..#########.#####.##########.......######.#######", + "###############..#########.#####.##########.......######.#######", + "###############..#########.#####.###########.....#######.#######", + "##################################..S.##D##.......##D###########", + "###############..#########.#####.........................#######", + "##############...####D####..###..........................#######", + "##############...........................................#######", + "##############.....S.....................................#######", + "##############...........................................#######", + "##############.............#########.....................#######", + "###############............#########.#####...............#######", + "###############............#########.#####...............#######", + "###############.####..####.###############...............#######", + "###############.####..####.###############...............#######", + "###############.####..####.###############...........###########", + "############D##.####..####.############D##...........###########", + "##########.................#########.......#.....#...########.##", + "##########.................#########.................########.##", + "##########............#..#.#########......S..........########.##", + "##########............#..#.#########.................########.##", + "##########.................#########.................########.##", + "###########################################.......##############", + "###########################################.......##############", + "########################################.##.......##############", + "########################################.####...################", + "########################################..........##############", + "########################################..........##############" + ], + "objects": [ + { + "name": "npc_36_16", + "kind": "npc", + "x": 36, + "y": 16 + }, + { + "name": "npc_15_18", + "kind": "npc", + "x": 15, + "y": 18 + }, + { + "name": "npc_36_25", + "kind": "npc", + "x": 36, + "y": 25 + }, + { + "name": "npc_55_33", + "kind": "npc", + "x": 55, + "y": 33 + }, + { + "name": "npc_46_35", + "kind": "npc", + "x": 46, + "y": 35 + }, + { + "name": "npc_26_42", + "kind": "npc", + "x": 26, + "y": 42 + }, + { + "name": "npc_44_44", + "kind": "npc", + "x": 44, + "y": 44 + }, + { + "name": "npc_52_46", + "kind": "npc", + "x": 52, + "y": 46 + }, + { + "name": "npc_54_46", + "kind": "npc", + "x": 54, + "y": 46 + }, + { + "name": "npc_17_55", + "kind": "npc", + "x": 17, + "y": 55 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/LakeVerity.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/LakeVerity.json new file mode 100644 index 0000000000..74cc0b162e --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/LakeVerity.json @@ -0,0 +1,62 @@ +{ + "name": "LakeVerity", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "################################", + "################################", + "################################", + "################################", + "......############....##########", + "......############....##########", + ".......###########......########", + ".......###########......########", + ".......###########~.....########", + ".......###########~~....########", + "################~~~~....########", + "################..~~....########", + "##############.~~~~~..##########", + "##############.~~~~...##########", + "############...~~~..############", + "############........############", + "##########..........############", + "##########..........############", + "############......##############", + "############......##############", + "############......##############", + "############......##############", + "##############..################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################" + ], + "objects": [ + { + "name": "npc_16_11", + "kind": "npc", + "x": 16, + "y": 11 + }, + { + "name": "npc_17_11", + "kind": "npc", + "x": 17, + "y": 11 + }, + { + "name": "npc_16_19", + "kind": "npc", + "x": 16, + "y": 19 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghCity.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghCity.json new file mode 100644 index 0000000000..2e5dfc89b8 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghCity.json @@ -0,0 +1,88 @@ +{ + "name": "OreburghCity", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "#########################################......#################", + "#########################################...S..#################", + "#########################################......#################", + "#########################################......#################", + "#########################################...####################", + "#########################################...####################", + "#########################################....###################", + "############.#####.######.#.############.....###################", + "###########..#####..#####...############.....###################", + "#########....#####..#####...############.....###################", + "##.....########D######D######D##########.....###################", + "##..S..###..........................####........#.#...##########", + "##..................................####.....S........##########", + "#D..................................####..............##########", + "##..................................####..............####.#####", + "##..................................####..............####.#####", + "##.....###.............#######......#D##..............####.#####", + "##.....##.......####...#######...............#####....####.#####", + "#########.......####.#.#######..............######......#.######", + "#########.......####...#######..............######.....#########", + "#########.......#D####S###D###...............##D##.....#########", + "#########........................................#.....#########", + "#########........................................#.....#########", + "#########........................................#....##########", + "#########........................................#....##########", + "#########........................................#....##########", + "##########.#.#..########.........................#....##########", + "########################.######.############.....#....##########", + "########################.######.###........#.....#....##D#######", + "########################.######.###.#..#...#.....#.........#####", + "############################################.....###############", + "############################################.....###############", + "############################################.....###############", + "############################################.....###############", + "############################################.....###############", + "############################################.....###############", + "############################################.....##D############", + "###################################.########.....#...........###", + "###################################.....####.....#...........###", + "###################################.....####.....#...........###", + "###################################....#####.....#...........###", + "#####################################..#.........#...........###", + "#####################################..#..#.#....#....#.#....###", + "#####################################..#..#.#....#....#.#....###", + "###################################....#.....................###", + "###################################....#.....................###", + "###################################....#.....................###", + "###################################....#.....................###", + "###################################....#.....................###", + "###################################..###..#.#................###", + "###################################..###..#.#...#.#########.####", + "###################################..###........#.#########.####", + "###################################....#..........#####.....####", + "###################################...............#####.....####", + "#####################################.............##.........###", + "#####################################..####.#.....###.....######", + "#####################################..####.#S....###.....######", + "###########################################.......####.......###", + "############################################.....#####.......###", + "############################################.....#####.....#####", + "######################################################..#..#####", + "################################################################", + "################################################################", + "################################################################" + ], + "objects": [ + { + "name": "npc_10_16", + "kind": "npc", + "x": 10, + "y": 16 + }, + { + "name": "npc_11_25", + "kind": "npc", + "x": 11, + "y": 25 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghGate.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghGate.json new file mode 100644 index 0000000000..4d5c076f41 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghGate.json @@ -0,0 +1,62 @@ +{ + "name": "OreburghGate", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "################################", + "################################", + "################################", + "################################", + "############..#......###########", + "###########..........###########", + "###########........#.###########", + "###########..###################", + "###########..###################", + "###########..###################", + "###########.####################", + "############.###################", + "###########.####################", + "###########..###################", + "###########..###################", + "###########..###################", + "###########..###################", + "###########..###################", + "############.###################", + "###########..###################", + "#####...##...##########...#.####", + "####....##...##########.....####", + "###D........................D###", + "####...#....................####", + "###########..............#.#####", + "############.......#############", + "###########..#.#...#############", + "################################", + "################################", + "################################", + "################################", + "################################" + ], + "objects": [ + { + "name": "npc_7_20", + "kind": "npc", + "x": 7, + "y": 20 + }, + { + "name": "npc_24_21", + "kind": "npc", + "x": 24, + "y": 21 + }, + { + "name": "npc_17_25", + "kind": "npc", + "x": 17, + "y": 25 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghGym.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghGym.json new file mode 100644 index 0000000000..ad30eae0d7 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghGym.json @@ -0,0 +1,68 @@ +{ + "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 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghMine.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghMine.json new file mode 100644 index 0000000000..64d1f82b96 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/OreburghMine.json @@ -0,0 +1,80 @@ +{ + "name": "OreburghMine", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "################################", + "###############D################", + "#############.....##############", + "#############.....##############", + "#############.....##############", + "#############.....##############", + "#############.....##############", + "#############...################", + "#############...################", + "#############.....##############", + "#############..#..##############", + "###############...##############", + "#############...################", + "#############.....##############", + "###############...##############", + "########...####..............###", + "######.....##.................##", + "##.#..........................##", + "##....####################....##", + "##vvv##..................#....##", + "##....#..................#....##", + "##.##.#..................#....##", + "##..###..................###..##", + "##..###..................###..##", + "##....#..................##...##", + "##.##.#..................#....##", + "####..####################....##", + "####..####################....##", + "#####............#.#........####", + "######......................####", + "################################", + "################################" + ], + "objects": [ + { + "name": "npc_20_15", + "kind": "npc", + "x": 20, + "y": 15 + }, + { + "name": "npc_21_15", + "kind": "npc", + "x": 21, + "y": 15 + }, + { + "name": "npc_27_15", + "kind": "npc", + "x": 27, + "y": 15 + }, + { + "name": "npc_26_20", + "kind": "npc", + "x": 26, + "y": 20 + }, + { + "name": "npc_8_28", + "kind": "npc", + "x": 8, + "y": 28 + }, + { + "name": "npc_18_28", + "kind": "npc", + "x": 18, + "y": 28 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/RavagedPath.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/RavagedPath.json new file mode 100644 index 0000000000..3f366c4d02 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/RavagedPath.json @@ -0,0 +1,64 @@ +{ + "name": "RavagedPath", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "#################################", + "..#####################.........#", + "....############................#", + "....############................#", + "....############................#", + "....############................#", + "....############................#", + "....##.#####.###................#", + "....##.#....#.##................#", + "....##.##.#...#########.........#", + "....##....#..##########.........#", + "....##.#.#.......#...############", + "....###.....######...############", + "....##############....#.......###", + "....##############....#.......###", + "..............####....##......###", + "..............####...#######D####", + "..............####...############", + "..............####...####.......#", + "..............####...####.......#", + "..............####...####.......#", + "..............####...####.......#", + "..............#####D#####.......#", + "..............###########.......#", + "..............###########.......#" + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route201.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route201.json new file mode 100644 index 0000000000..e2e53e12d1 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route201.json @@ -0,0 +1,43 @@ +{ + "name": "Route201", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "################################################################", + "################################################################", + "################################################################", + "##########################################~~~~~~~~~~~...........", + "##########################################~~~~~~~~~~~..S........", + "##########################################~~~~~~~~~~~...........", + "##########################################~~~~~~~~~~~...........", + "....####..........######..##....##..####..~~~~~~~~~##...........", + "....####..........######..##....##..####..~~~~~~~~~##...........", + "##........####............................~~~~~~~~~##vvvvv######", + "##........####............................~~~~~~~~~##.....######", + "..........................................~~~~~~~~~##.....######", + "vvvv####vvvvvvvvvvvvvvvvvvvvvvvv........S.~~~~~~~~~##.....######", + "....####............~~~~~~~~~~............................######", + "....................~~~~~~~~~~............................######", + "....................~~~~~~~~~~............................######", + "....................~~~~~~~~~~............................######", + "########.....S......##########............................######", + "########............##########............~~~~~~~~~~~~~~~~######", + "##############....############################~~~~~~~~~~~~######", + "##############....############################~~~~~~~~~~~~######", + "##############....##############################################", + "##############....##############################################", + "##############....##############################################", + "##############....##############################################" + ], + "objects": [ + { + "name": "npc_57_8", + "kind": "npc", + "x": 57, + "y": 8 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route202.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route202.json new file mode 100644 index 0000000000..362f4e0df8 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route202.json @@ -0,0 +1,62 @@ +{ + "name": "Route202", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "###########........#################", + "###########........#################", + "###########........#################", + "###########........#################", + "###~~~~~~........S..~~~~~......#####", + "###~~~~~~...........~~~~~......#####", + "####~~~~~...........~~~~~......#####", + "###~~~~~~...........~~~~~......#####", + "###~~~~~~...........~~~~~......#####", + "###~~~~~~.....########.........#####", + "#########vvvvv########vvvvvv...~~###", + "#########.....########~~~~~~~~~~~###", + "#######.......########~~~~~~~~~~~###", + "#######...........####~~~~~~~~~~~###", + "###...............####~~~~~~~~~~~###", + "###...............####~~~~~~~~~~~###", + "###............S..####~~~~~~~~~~~###", + "###...............####~~~~~~~~~~~###", + "###...............####..~~~~~~~~~###", + "###~~~~##...............~~~~~~~~~###", + "###~~~~##.................~~~~~~~###", + "###~~~~##....................~~~~###", + "###~~~~##......................#####", + "###~~~~##vvvvv########vvvvvvvvv#####", + "###~~~~##.....########.........#####", + "###~~~~~~......~~~~~~...S......#####", + "###~~~~~~......~~~~~~..........#####", + "###~~~~~~......~~~~~~..........#####", + "###~~~~~~......######..........#####", + "###~~~~~~......######..........#####", + "######################.........#####", + "#####################..........#####" + ], + "objects": [ + { + "name": "npc_26_4", + "kind": "npc", + "x": 26, + "y": 4 + }, + { + "name": "npc_7_13", + "kind": "npc", + "x": 7, + "y": 13 + }, + { + "name": "npc_22_18", + "kind": "npc", + "x": 22, + "y": 18 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route203.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route203.json new file mode 100644 index 0000000000..b646ec65c9 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route203.json @@ -0,0 +1,60 @@ +{ + "name": "Route203", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "#############################################################", + "#############################################################", + "#############################################################", + "#############################################################", + "#####..............###########..~~~~#########################", + "#####..............###########.#.~~~..~~~~~~~~~~~~~~#########", + "#####..................#######........~~~~~~~~~~~~~.....#####", + "#####..................###############~~~~~~~~~~~....S..#####", + "#####~~~~##...####.....#......########~~~~~~~~~~~.......#####", + "#####~~~~##...####.....#......########~~~~~~~~~~~.......D####", + "#####~~~~##...####..#..#..S...########~~~~~~~~~~~.......#####", + "#####~~~~##...####.....#......########~~~~~~~~~~~.......#####", + "#####~~~~##...####.....#....~~~~~~~~##~~~~~~~~~S...~~~..#####", + "#####~~~~##...####vvvvv#...~~...~.~~##~~~~~~~~~....~~~..#####", + "#####~~................#....######~~##.....~~....##~~~..#####", + "#####..................#....######~~##vvvvvvvvvvv##~~~..#####", + "#####....S.............#....~~~..~~~.............~~~~~..#####", + "...........................~~~~...~~.............~~~~~..#####", + "...........................~~.....~~.............~~~~~..#####", + "..........................~~~~.....~##..........~~~~~~..#####", + "..........................~~~~~.~~~~#########################", + "#############################################################", + "#############################################################", + "#############################################################" + ], + "objects": [ + { + "name": "npc_49_8", + "kind": "npc", + "x": 49, + "y": 8 + }, + { + "name": "npc_13_10", + "kind": "npc", + "x": 13, + "y": 10 + }, + { + "name": "npc_31_16", + "kind": "npc", + "x": 31, + "y": 16 + }, + { + "name": "npc_43_17", + "kind": "npc", + "x": 43, + "y": 17 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route204North.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route204North.json new file mode 100644 index 0000000000..6ec036b174 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route204North.json @@ -0,0 +1,74 @@ +{ + "name": "Route204North", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "########.#...###################", + "########.#...###################", + "####.....#...########.##########", + "##########...#......#.##########", + "#####....#...#......#...........", + "#####....#~~~#......#...######..", + "#####....#~~####################", + "##########~~~.........##########", + "##........~~~~~.......##########", + "##..######.~~~~..S....##########", + "###.#....#.~~~........##########", + "##..#....#.~~.........##########", + "##########..............########", + "##########..............########", + "##########...####~~~~~~~########", + "##########vvv####~~~~~~~########", + "##########...######~~~~~########", + "##########...######~~~~~########", + "##########...######~~~~~########", + "##########...######~.~~~########", + "##########............~~########", + "##########............##########", + "##########............##########", + "##########...##.....#.##########", + "##########...##.......##########", + "##########...###################", + "##########...#######.###########", + "##########............##########", + "##########............##########", + "##########............##########", + "##########............##########", + "##########...###################" + ], + "objects": [ + { + "name": "npc_31_4", + "kind": "npc", + "x": 31, + "y": 4 + }, + { + "name": "npc_15_7", + "kind": "npc", + "x": 15, + "y": 7 + }, + { + "name": "npc_16_7", + "kind": "npc", + "x": 16, + "y": 7 + }, + { + "name": "npc_20_12", + "kind": "npc", + "x": 20, + "y": 12 + }, + { + "name": "npc_17_20", + "kind": "npc", + "x": 17, + "y": 20 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route204South.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route204South.json new file mode 100644 index 0000000000..752d5baf82 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/Route204South.json @@ -0,0 +1,62 @@ +{ + "name": "Route204South", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "################################", + "###########D###.################", + "########..S.....################", + "########........################", + "########........################", + "##########...~##################", + "##########...~##################", + "##########..~~##################", + "##########..~~##################", + "####~~~~~~~~~~##################", + "####~~~~~~~~~~##################", + "####~~~~~~~~~~##################", + "####~~~~~~~~~~############...###", + "####~~~~~~~~~~############....##", + "####~~~~~~~~~~#..###############", + "##~~~~~~~~~~~~#..###############", + "##~~~~~~~~~~~~#..###############", + "##~~~~~~~~~~~~S.################", + "##~~~~~.........################", + "##~~~~~.........#.##############", + "##~~~~~.........#.##############", + "##.#########....#.##############", + "############....#......~########", + "############....######~~########", + "############....######~~########", + "############....######~~########", + "############....######~~########", + "############....######~~########", + "###.######.#....#..~~~~~########", + "##..######.#....#...~~~~########", + "##########.#....#.......########", + "############....######..########" + ], + "objects": [ + { + "name": "npc_11_8", + "kind": "npc", + "x": 11, + "y": 8 + }, + { + "name": "npc_7_18", + "kind": "npc", + "x": 7, + "y": 18 + }, + { + "name": "npc_12_21", + "kind": "npc", + "x": 12, + "y": 21 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/SandgemTown.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/SandgemTown.json new file mode 100644 index 0000000000..b7fcdb8c29 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/SandgemTown.json @@ -0,0 +1,42 @@ +{ + "name": "SandgemTown", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "########################......####", + "########################......####", + "####################..........####", + "####################..........####", + "####################..........####", + "####################..........####", + "####################......########", + "####################......########", + "####################......########", + "####################......########", + "########D##....##D##S....S#D######", + ".....S........................####", + "..............................####", + "..............................####", + "..............................####", + "..............................####", + "######........................####", + "######........................####", + "######.........#####..........####", + "##########.....#####..........####", + "##########.....#####..........####", + "##########.....#####..........####", + "#######D##....S#D###..S.......####", + "######........................####", + "######........................####", + "######........................####", + "######....................########", + "####################......########", + "####################......########", + "####################......########", + "####################......########", + "####################......########" + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/TwinleafTown.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/TwinleafTown.json new file mode 100644 index 0000000000..92dfcf72c1 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/TwinleafTown.json @@ -0,0 +1,56 @@ +{ + "name": "TwinleafTown", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "############........############", + "#######....#........#....#######", + "#######....#........#....#######", + "############........############", + "######....................######", + "######....................######", + "######....................######", + "######..#####.............######", + "######..#####......####...######", + "######..#####......####...######", + "######..######.....####...######", + "######..#D###S.....#D##...######", + "######....................######", + "######....................######", + "######..........S.........######", + "######....................######", + "######....................######", + "######.............#####..######", + "######...####......#####..######", + "######...####......#####..######", + "######...####.....######..######", + "######...#D##.....S#D###..######", + "######....................######", + "######....................######", + "######....................######", + "######....................######", + "######....................######", + "######......########......######", + "################################", + "################################", + "################################", + "################################" + ], + "objects": [ + { + "name": "npc_12_5", + "kind": "npc", + "x": 12, + "y": 5 + }, + { + "name": "npc_12_25", + "kind": "npc", + "x": 12, + "y": 25 + } + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/VerityLakefront.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/VerityLakefront.json new file mode 100644 index 0000000000..d82818b601 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/VerityLakefront.json @@ -0,0 +1,42 @@ +{ + "name": "VerityLakefront", + "source": { + "decomp_file": "SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp", + "revision": "ddcbdb21c1dc", + "date": "2026-11-01" + }, + "tiles": [ + "....############################", + "....############################", + "....############################", + "....############################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################..##############", + "################..##############", + "################..##############", + "##############.S....#...........", + "##############......#.....####..", + "##############......#.....####..", + "##############......#...........", + "##############......#...........", + "##############......#vvvvv##vvvv", + "################..........##....", + "################................", + "##################..............", + "##################..............", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################", + "################################" + ] +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp new file mode 100644 index 0000000000..a42684c862 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp @@ -0,0 +1,256 @@ +/* BDSP AutoStory Map Grid Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "Pokemon/Navigation/Pokemon_MapSet.h" +#include "Pokemon/Navigation/Pokemon_TileGrid.h" +#include "Data/PokemonBDSP_AutoStory_MapGrids.h" +#include "Data/PokemonBDSP_AutoStory_Route202.h" +#include "Data/PokemonBDSP_AutoStory_SandgemTown.h" +#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" +#include "Data/PokemonBDSP_AutoStory_PlanCosts.h" +#include "PokemonBDSP_AutoStory_MapGrid_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +using Pokemon::Direction; +using Pokemon::MapSet; +using Pokemon::TileGrid; +using Pokemon::TilePos; +using Pokemon::TileType; + +// 00.04's training walks up and down the catch patch, three grass rows +// between tree rows, and needs the walk there to end in its grass: r253 +// and r254 loaded the catch's save in the pocket behind the trees at +// (21, 29), planned from the catch spot instead, and walked up and down +// the lawn east of the grass for three minutes without a battle. +class Test_Route202CatchGrass : public UnitTest{ +public: + Test_Route202CatchGrass() + : UnitTest("PokemonBDSP::AutoStory - Route 202: the catch patch and the walk to it") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const TileGrid& route = Route202::grid(); + for (int x = 15; x <= 20; x++){ + const Pokemon::WallHit up = Pokemon::walk_to_wall(route, {x, 27}, Direction::NORTH); + const Pokemon::WallHit down = Pokemon::walk_to_wall(route, {x, 25}, Direction::SOUTH); + if (!(up.stop == TilePos{x, 25}) || !(down.stop == TilePos{x, 27})){ + return "Catch patch column " + std::to_string(x) + ": north from row 27 stops at " + + Pokemon::to_string(up.stop) + ", south from row 25 at " + Pokemon::to_string(down.stop) + + "; expected rows 25 and 27, between tree rows."; + } + } + const MapSet& maps = story_maps(); + const std::vector area = story_after_training_area(); + const auto in_grass = [&](const TilePos& pos){ + return maps.world().at(pos) == TileType::TALL_GRASS && std::find(area.begin(), area.end(), pos) != area.end(); + }; + // As walk_route() plans: the route costs, else the default costs. + // From the whole area the catch's save may stand in, and from the + // pocket behind the trees alone, where r252 saved. + const TilePos pocket = maps.to_world(MAP_ROUTE_202, {21, 29}); + const std::vector>> starts{ + {"the catch's save area", story_catch_save_area()}, + {"the pocket behind the trees", {pocket}}, + }; + std::optional> legs; + for (const auto& [name, from] : starts){ + legs = Pokemon::plan_robust_route(maps.world(), from, in_grass, route_plan_costs()); + if (!legs){ + legs = Pokemon::plan_robust_route(maps.world(), from, in_grass, Pokemon::RobustPlanCosts()); + } + if (!legs || legs->empty()){ + return "From " + name + " to the catch grass: no plan."; + } + for (const TilePos& pos : legs->back().after){ + if (!in_grass(pos)){ + return "From " + name + " to the catch grass: the walk may end on " + maps.describe(pos) + ", not in the grass."; + } + } + logger.log("From " + name + " to the catch grass: " + std::to_string(legs->size()) + " legs, ending in the grass."); + } + return true; + } +}; + +// 00.04's way to Sandgem's Pokemon Center ends below the Center's sign, +// walking north into it, then taps west along the doors' row to below the +// door: the row must be open there, the door straight north of where the +// taps end, and nothing else (a sign, the Mart's door) on the way. +class Test_SandgemCenterApproach : public UnitTest{ +public: + Test_SandgemCenterApproach() + : UnitTest("PokemonBDSP::AutoStory - Sandgem Town: below the Center's sign to below its door") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const TileGrid& town = SandgemTown::grid(); + const TilePos sign = SandgemTown::POKEMON_CENTER_SIGN; + const TilePos door = SandgemTown::POKEMON_CENTER_DOOR; + if (town.at(sign) != TileType::SIGN || town.at(door) != TileType::DOOR || door.y != sign.y || door.x >= sign.x){ + return "The Center's sign " + Pokemon::to_string(sign) + " and door " + Pokemon::to_string(door) + + " are not a sign and a door west of it on one row."; + } + TilePos pos = sign.next(Direction::SOUTH); + for (int tap = 0; tap < sign.x - door.x; tap++){ + const std::optional next = town.step(pos, Direction::WEST); + if (!next){ + return "West from " + Pokemon::to_string(pos) + " is blocked."; + } + if (town.at(next->next(Direction::NORTH)) != TileType::BLOCKED && *next != door.next(Direction::SOUTH)){ + return "Above " + Pokemon::to_string(*next) + " is not the Center's wall."; + } + pos = *next; + } + if (!(pos == door.next(Direction::SOUTH))){ + return "The taps end at " + Pokemon::to_string(pos) + ", not below the door " + Pokemon::to_string(door) + "."; + } + logger.log("Sandgem: below the sign " + Pokemon::to_string(sign.next(Direction::SOUTH)) + ", " + + std::to_string(sign.x - door.x) + " taps west to below the door " + Pokemon::to_string(door) + "."); + return true; + } +}; + +// After training, 00.04 walks from wherever the training left us into +// Sandgem, to where the road stops above the Mart, with the default costs +// (heal_at_sandgem_center()): from the whole area and from each of its +// tiles alone, a plan must exist and end there. +class Test_TrainingToSandgem : public UnitTest{ +public: + Test_TrainingToSandgem() + : UnitTest("PokemonBDSP::AutoStory - Route 202: from every tile of the training area into Sandgem") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const MapSet& maps = story_maps(); + const TilePos entry = maps.to_world(MAP_SANDGEM_TOWN, SandgemTown::ROUTE_202_ENTRY_STOP); + const std::vector area = story_after_training_area(); + std::vector> starts{area}; + for (const TilePos& pos : area){ + starts.push_back({pos}); + } + for (const std::vector& from : starts){ + const auto legs = Pokemon::plan_robust_route(maps.world(), from, + [&](const TilePos& pos){ return pos == entry; }, Pokemon::RobustPlanCosts()); + const std::string name = from.size() == 1 ? maps.describe(from[0]) : "the whole training area"; + if (!legs || legs->empty()){ + return "From " + name + " into Sandgem: no plan."; + } + if (legs->back().after.size() != 1 || !(legs->back().after[0] == entry)){ + return "From " + name + " into Sandgem: the plan does not end on " + maps.describe(entry) + "."; + } + logger.log("From " + name + " into Sandgem: " + std::to_string(legs->size()) + " legs."); + } + return true; + } +}; + +// The maps (the JSON files built in, bdsp_map_json()) all parse through +// the shared loader into tile grids, each named as its file. +class Test_BuiltInMaps : public UnitTest{ +public: + Test_BuiltInMaps() + : UnitTest("PokemonBDSP::AutoStory - Map grids: the built-in JSON maps load") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + if (bdsp_map_json().empty()){ + return std::string("No built-in maps."); + } + for (const auto& [name, json] : bdsp_map_json()){ + try{ + const TileGrid& grid = story_grid(name); + logger.log(std::format("{}: {} x {}", name, grid.width(), grid.height())); + }catch (Exception& e){ + return std::format("{}: {}: {}", name, e.name(), e.message()); + } + } + return true; + } +}; + +// The JSON glyphs as BDSP tiles: every BDSP tile and a person standing; +// water and a wanderer have none. +struct GlyphCase{ + std::string name; + std::string json; + // The grid's rows, or empty when reading it must throw. + std::vector rows; +}; + +class Test_MapGlyphs : public UnitTest{ +public: + Test_MapGlyphs() + : UnitTest("PokemonBDSP::AutoStory - Map grids: JSON glyphs as tile grids") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::vector cases{ + { + .name = "every BDSP tile, and a person standing", + .json = R"({"name": "T", "source": {"decomp_file": "f", "revision": "r", "date": "d"}, + "tiles": ["#.~", "vDS"], + "objects": [{"name": "npc_1_0", "kind": "npc", "x": 1, "y": 0}]})", + .rows = {"#N\"", "vDS"}, + }, + { + .name = "water has no BDSP tile", + .json = R"({"name": "T", "source": {"decomp_file": "f", "revision": "r", "date": "d"}, "tiles": ["#w"]})", + .rows = {}, + }, + { + .name = "a wanderer has no BDSP tile", + .json = R"({"name": "T", "source": {"decomp_file": "f", "revision": "r", "date": "d"}, "tiles": ["#.."], + "objects": [{"name": "lass", "kind": "npc", "x": 1, "y": 0, "wander": {"x0": 1, "y0": 0, "x1": 2, "y1": 0}}]})", + .rows = {}, + }, + }; + for (const GlyphCase& item : cases){ + std::optional grid; + std::string error; + try{ + grid = tile_grid_from_map(Pokemon::parse_map(parse_json(item.json), item.name)); + }catch (ParseException& e){ + error = e.message(); + } + if (item.rows.empty() != !grid){ + return item.name + (grid ? ": read a grid, expected a ParseException." : ": expected a grid, read: " + error); + } + if (grid){ + if (const std::optional difference = grid_difference(*grid, TileGrid(item.rows))){ + return item.name + ": differs from the expected rows at " + *difference + "."; + } + } + } + return true; + } +}; + +} + + +void add_tests_AutoStory_MapGrids(UnitTestDatabase& database){ + database.add(); + database.add(); + database.add(); + database.add(); + database.add(); +} + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h new file mode 100644 index 0000000000..a7f7250b2b --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h @@ -0,0 +1,28 @@ +/* BDSP AutoStory Map Grid Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_MapGrid_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_MapGrid_Tests_H + +#include "Common/Cpp/TestRunners/UnitTest.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + + +// Offline checks of the decomp grids against what the console showed: +// Route 202's catch patch between tree rows and the walks in and out of +// it, and Sandgem's Pokemon Center door, its sign and the row below them. +void add_tests_AutoStory_MapGrids(UnitTestDatabase& database); + + + +} +} +} +#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..4f85f52a85 --- /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 "Data/PokemonBDSP_AutoStory_PlanCosts.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/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index a97fc4ebb0..d0c16d6bac 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1452,6 +1452,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_MapData.cpp Source/Pokemon/Navigation/Pokemon_MapData.h Source/Pokemon/Navigation/Pokemon_MapData_Tests.cpp + Source/Pokemon/Navigation/Pokemon_MapSet.cpp + Source/Pokemon/Navigation/Pokemon_MapSet.h Source/Pokemon/Navigation/Pokemon_Navigation_Tests.h Source/Pokemon/Navigation/Pokemon_RouteLog.cpp Source/Pokemon/Navigation/Pokemon_RouteLog.h @@ -1459,6 +1461,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_StoryEvents.cpp Source/Pokemon/Navigation/Pokemon_StoryEvents.h Source/Pokemon/Navigation/Pokemon_StoryEvents_Tests.cpp + Source/Pokemon/Navigation/Pokemon_TileGrid.cpp + Source/Pokemon/Navigation/Pokemon_TileGrid.h Source/Pokemon/Navigation/Pokemon_StorySegments.cpp Source/Pokemon/Navigation/Pokemon_StorySegments.h Source/Pokemon/Navigation/Pokemon_StorySegments_Tests.cpp @@ -1526,6 +1530,52 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Resources/Pokemon_PokemonNames.h Source/Pokemon/Resources/Pokemon_PokemonSlugs.cpp Source/Pokemon/Resources/Pokemon_PokemonSlugs.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.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 + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleBallReader.cpp Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleBallReader.h Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.cpp diff --git a/devtools/maps/bdsp_maps.py b/devtools/maps/bdsp_maps.py new file mode 100644 index 0000000000..51e8e3c2e0 --- /dev/null +++ b/devtools/maps/bdsp_maps.py @@ -0,0 +1,53 @@ +"""Checks that Packages' BDSP AutoStory maps are the ones in this repository. + +Usage: + python3 devtools/maps/bdsp_maps.py --check --json-dir Packages/Resources/PokemonBDSP/Maps + +The maps are JSON files in the shared map schema +(SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapData.h). They live in +SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps, where CMake builds +them into the program (pa_embed_text_files()). Once Packages has copies in +Resources/PokemonBDSP/Maps, the two must be the same files: --check exits +1, naming the first that differs, if they are not. + +TODO: move the maps to PokemonAutomation/Packages (Resources/PokemonBDSP/Maps) when ready. +Until then the program reads only the repository's copies, and this check +is for that move. + +The files were converted once (at ddcbdb21c) from the C++ tables that +pret/pokediamond's maps had been decoded into; nothing builds them now. +""" +import argparse +import os +import sys + +REPO_MAPS = 'SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps' + + +def json_files(folder): + return sorted(name for name in os.listdir(folder) if name.endswith('.json')) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.split('\n')[0]) + parser.add_argument('--check', action='store_true', required=True, + help='compare the repository\'s maps with --json-dir\'s, byte for byte') + parser.add_argument('--json-dir', required=True, help='Packages\' Resources/PokemonBDSP/Maps') + parser.add_argument('--repo', default='.', help='Arduino-Source checkout') + args = parser.parse_args() + repo_maps = os.path.join(args.repo, REPO_MAPS) + ours, theirs = json_files(repo_maps), json_files(args.json_dir) + if ours != theirs: + print('The map files differ: only here ' + str(sorted(set(ours) - set(theirs))) + + ', only in ' + args.json_dir + ' ' + str(sorted(set(theirs) - set(ours))) + '.') + sys.exit(1) + for name in ours: + with open(os.path.join(repo_maps, name), 'rb') as a, open(os.path.join(args.json_dir, name), 'rb') as b: + if a.read() != b.read(): + print(name + ': differs from ' + os.path.join(args.json_dir, name) + '.') + sys.exit(1) + print(str(len(ours)) + ' maps: the same files.') + + +if __name__ == '__main__': + main() From 4383d4e324f105bd460be107f03ee04b342dd62d Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 12:33:08 -0800 Subject: [PATCH 02/18] Unit tests: run the PokemonBDSP tests PokemonBDSP::add_tests() was never called, so the BDSP map tests did not run in CI. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 592144c1f1..20068e308d 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -29,6 +29,7 @@ #include "NintendoSwitch/Programs/Typewriter/NintendoSwitch_Typewriter_Tests.h" #include "Pokemon/Navigation/Pokemon_Navigation_Tests.h" +#include "PokemonBDSP/PokemonBDSP_Tests.h" #include "VideoGames/PokemonHome/PokemonHome_Tests.h" #include "VideoGames/PokemonSwSh/PokemonSwSh_Tests.h" #include "VideoGames/PokemonLA/PokemonLA_Tests.h" @@ -71,6 +72,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ NintendoSwitch::add_tests_FailedToConnectDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); NintendoSwitch::Typewriter::add_tests_TypewriterTextMapping(ret); + NintendoSwitch::PokemonBDSP::add_tests(ret); NintendoSwitch::PokemonFRLG::add_tests(ret); NintendoSwitch::PokemonRSE::add_tests(ret); NintendoSwitch::PokemonHome::add_tests(ret); From 22aea3340afe1ed4a4efdd12d6e55ba2c825f345 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 13:37:44 -0800 Subject: [PATCH 03/18] BDSP navigation: the story world and the route planner on the shared MapData StoryWorld joins story maps at world offsets (what Pokemon::MapSet did), with BDSP's step rules on Pokemon::TileKind: ledges hop the arrow's way, water and signs stop, objects standing still block, wanderers don't, and tiles no map covers are off the maps. RoutePlanner is Pokemon_TileGrid's planner moved onto it unchanged in behaviour (walk_to_wall, plan_tile_route, plan_robust_route, sight lines), now in PokemonBDSP; plan_robust_route's search is split into functions under the length limit. Synthetic-map tests for both. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Pokemon/Navigation/Pokemon_MapSet.cpp | 102 ---- .../Pokemon/Navigation/Pokemon_MapSet.h | 63 --- .../Pokemon/Navigation/Pokemon_TileGrid.cpp | 503 ------------------ .../Programs/AutoStory/Data/MAPS.md | 45 -- .../PokemonBDSP_AutoStory_FloaromaTown.cpp | 81 --- .../Data/PokemonBDSP_AutoStory_FloaromaTown.h | 36 -- .../PokemonBDSP_AutoStory_JubilifeCity.cpp | 113 ---- .../Data/PokemonBDSP_AutoStory_JubilifeCity.h | 45 -- .../Data/PokemonBDSP_AutoStory_LakeVerity.cpp | 66 --- .../Data/PokemonBDSP_AutoStory_LakeVerity.h | 27 - .../Data/PokemonBDSP_AutoStory_MapGrids.cpp | 115 ---- .../Data/PokemonBDSP_AutoStory_MapGrids.h | 52 -- .../PokemonBDSP_AutoStory_OreburghCity.cpp | 92 ---- .../Data/PokemonBDSP_AutoStory_OreburghCity.h | 37 -- .../PokemonBDSP_AutoStory_OreburghGate.cpp | 51 -- .../Data/PokemonBDSP_AutoStory_OreburghGate.h | 27 - .../PokemonBDSP_AutoStory_OreburghGym.cpp | 61 --- .../Data/PokemonBDSP_AutoStory_OreburghGym.h | 38 -- .../PokemonBDSP_AutoStory_OreburghMine.cpp | 65 --- .../Data/PokemonBDSP_AutoStory_OreburghMine.h | 39 -- .../PokemonBDSP_AutoStory_RavagedPath.cpp | 62 --- .../Data/PokemonBDSP_AutoStory_RavagedPath.h | 47 -- .../Data/PokemonBDSP_AutoStory_Route201.cpp | 82 --- .../Data/PokemonBDSP_AutoStory_Route201.h | 37 -- .../Data/PokemonBDSP_AutoStory_Route202.cpp | 101 ---- .../Data/PokemonBDSP_AutoStory_Route202.h | 49 -- .../Data/PokemonBDSP_AutoStory_Route203.cpp | 78 --- .../Data/PokemonBDSP_AutoStory_Route203.h | 32 -- .../Data/PokemonBDSP_AutoStory_Route204.cpp | 91 ---- .../Data/PokemonBDSP_AutoStory_Route204.h | 43 -- .../PokemonBDSP_AutoStory_Route204South.cpp | 87 --- .../PokemonBDSP_AutoStory_Route204South.h | 44 -- .../PokemonBDSP_AutoStory_RoutePlanner.cpp | 434 +++++++++++++++ .../PokemonBDSP_AutoStory_RoutePlanner.h} | 335 +++++------- .../PokemonBDSP_AutoStory_SandgemTown.cpp | 96 ---- .../Data/PokemonBDSP_AutoStory_SandgemTown.h | 49 -- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 232 ++++++++ .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 112 ++++ .../PokemonBDSP_AutoStory_TwinleafTown.cpp | 61 --- .../Data/PokemonBDSP_AutoStory_TwinleafTown.h | 27 - .../PokemonBDSP_AutoStory_VerityLakefront.cpp | 56 -- .../PokemonBDSP_AutoStory_VerityLakefront.h | 27 - .../PokemonBDSP_AutoStory_MapGrid_Tests.cpp | 256 --------- .../PokemonBDSP_AutoStory_MapGrid_Tests.h | 28 - ...kemonBDSP_AutoStory_RoutePlanner_Tests.cpp | 195 +++++++ ...PokemonBDSP_AutoStory_RoutePlanner_Tests.h | 24 + ...PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 193 +++++++ .../PokemonBDSP_AutoStory_StoryWorld_Tests.h | 24 + 48 files changed, 1358 insertions(+), 3202 deletions(-) delete mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.cpp delete mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.h delete mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp rename SerialPrograms/Source/{Pokemon/Navigation/Pokemon_TileGrid.h => PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h} (52%) delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.h delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp delete mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.cpp deleted file mode 100644 index 533dc4f12f..0000000000 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* Map Set - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include "Common/Cpp/Exceptions.h" -#include "Pokemon_MapSet.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -void MapSet::add(std::string name, const TileGrid& grid, const TilePos& offset){ - for (const Placed& placed : m_maps){ - if (placed.name == name){ - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Map placed twice: " + name); - } - // Map images show a border of trees past their edges, so two maps - // may share blocked tiles, but nothing else. - for (int y = 0; y < grid.height(); y++){ - for (int x = 0; x < grid.width(); x++){ - const TilePos other{offset.x + x - placed.offset.x, offset.y + y - placed.offset.y}; - if (!placed.grid.in_bounds(other)){ - continue; - } - if (grid.at({x, y}) != TileType::BLOCKED || placed.grid.at(other) != TileType::BLOCKED){ - throw InternalProgramError( - nullptr, PA_CURRENT_FUNCTION, - "Map " + name + " overlaps " + placed.name + " at its tile " + to_string(TilePos{x, y}) + "." - ); - } - } - } - } - m_maps.push_back(Placed{std::move(name), grid, offset}); - - // Rebuild the joined grid. - TilePos low = m_maps[0].offset; - TilePos high = low; - for (const Placed& placed : m_maps){ - low.x = std::min(low.x, placed.offset.x); - low.y = std::min(low.y, placed.offset.y); - high.x = std::max(high.x, placed.offset.x + placed.grid.width()); - high.y = std::max(high.y, placed.offset.y + placed.grid.height()); - } - m_origin = low; - std::vector rows(high.y - low.y, std::string(high.x - low.x, tile_char(TileType::UNKNOWN))); - for (const Placed& placed : m_maps){ - const std::vector map_rows = placed.grid.rows(); - for (size_t y = 0; y < map_rows.size(); y++){ - rows[placed.offset.y - low.y + y].replace(placed.offset.x - low.x, map_rows[y].size(), map_rows[y]); - } - } - m_world.emplace(rows); -} - -const TileGrid& MapSet::world() const{ - if (!m_world){ - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No maps placed."); - } - return *m_world; -} - -TilePos MapSet::to_world(const std::string& map, const TilePos& local) const{ - for (const Placed& placed : m_maps){ - if (placed.name == map){ - return { - placed.offset.x - m_origin.x + local.x, - placed.offset.y - m_origin.y + local.y, - }; - } - } - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown map: " + map); -} - -std::optional MapSet::to_local(const TilePos& world) const{ - for (const Placed& placed : m_maps){ - const TilePos local{ - world.x + m_origin.x - placed.offset.x, - world.y + m_origin.y - placed.offset.y, - }; - if (placed.grid.in_bounds(local)){ - return MapTile{placed.name, local}; - } - } - return std::nullopt; -} - -std::string MapSet::describe(const TilePos& world) const{ - const std::optional local = to_local(world); - if (!local){ - return "world " + to_string(world); - } - return local->map + " " + to_string(local->pos); -} - - - -} -} diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.h deleted file mode 100644 index 468213c481..0000000000 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapSet.h +++ /dev/null @@ -1,63 +0,0 @@ -/* Map Set - * - * From: https://github.com/PokemonAutomation/ - * - * Several tile grids placed side by side on one world grid, so one plan - * can cross from a route into a town. - */ - -#ifndef PokemonAutomation_Pokemon_MapSet_H -#define PokemonAutomation_Pokemon_MapSet_H - -#include -#include -#include -#include "Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -struct MapTile{ - std::string map; - TilePos pos; -}; - - -class MapSet{ -public: - // Places `grid` with its tile (0,0) at `offset`. Offsets are relative to - // each other and may be negative. Maps may overlap only where both are - // blocked; the map placed first holds those tiles. Throws - // InternalProgramError if the name is taken or the maps conflict. - void add(std::string name, const TileGrid& grid, const TilePos& offset); - - // The maps joined on one grid. Tiles no map covers are UNKNOWN. World - // tile (0,0) is the top-left corner of all the maps together. - const TileGrid& world() const; - - // Throws InternalProgramError for an unknown map name. - TilePos to_world(const std::string& map, const TilePos& local) const; - - // The map that holds a world tile, or nothing between maps. - std::optional to_local(const TilePos& world) const; - - // "Route 201 (45,3)", or the world tile if no map holds it. - std::string describe(const TilePos& world) const; - -private: - struct Placed{ - std::string name; - TileGrid grid; - TilePos offset; - }; - std::vector m_maps; - TilePos m_origin; // offset of world tile (0,0) - std::optional m_world; -}; - - - -} -} -#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.cpp deleted file mode 100644 index e0a70bc8e5..0000000000 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.cpp +++ /dev/null @@ -1,503 +0,0 @@ -/* Tile Grid - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "Pokemon_LegPlanner.h" -#include "Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -char tile_char(TileType type){ - switch (type){ - case TileType::BLOCKED: return '#'; - case TileType::WALKABLE: return '.'; - case TileType::TALL_GRASS: return '"'; - case TileType::LEDGE: return 'v'; - case TileType::NPC: return 'N'; - case TileType::SIGN: return 'S'; - case TileType::DOOR: return 'D'; - case TileType::UNKNOWN: return '?'; - } - return '?'; -} - - - - -TileGrid::TileGrid(const std::vector& rows) - : m_width(rows.empty() ? 0 : (int)rows[0].size()) - , m_height((int)rows.size()) -{ - m_tiles.reserve((size_t)m_width * m_height); - for (size_t y = 0; y < rows.size(); y++){ - const std::string& row = rows[y]; - if ((int)row.size() != m_width){ - throw InternalProgramError( - nullptr, PA_CURRENT_FUNCTION, - "Tile grid row " + std::to_string(y) + " has " + std::to_string(row.size()) + - " tiles, expected " + std::to_string(m_width) + "." - ); - } - for (size_t x = 0; x < row.size(); x++){ - switch (row[x]){ - case '#': m_tiles.push_back(TileType::BLOCKED); break; - case '.': m_tiles.push_back(TileType::WALKABLE); break; - case '"': m_tiles.push_back(TileType::TALL_GRASS); break; - case 'v': m_tiles.push_back(TileType::LEDGE); break; - case 'N': m_tiles.push_back(TileType::NPC); break; - case 'S': m_tiles.push_back(TileType::SIGN); break; - case 'D': m_tiles.push_back(TileType::DOOR); break; - case '?': m_tiles.push_back(TileType::UNKNOWN); break; - default: - throw InternalProgramError( - nullptr, PA_CURRENT_FUNCTION, - std::string("Unknown tile '") + row[x] + "' at " + - to_string(TilePos{(int)x, (int)y}) + "." - ); - } - } - } -} - -std::vector TileGrid::rows() const{ - std::vector rows; - for (int y = 0; y < m_height; y++){ - std::string row; - for (int x = 0; x < m_width; x++){ - row += tile_char(at({x, y})); - } - rows.push_back(std::move(row)); - } - return rows; -} - -bool TileGrid::in_bounds(const TilePos& pos) const{ - return 0 <= pos.x && pos.x < m_width && 0 <= pos.y && pos.y < m_height; -} - -TileType TileGrid::at(const TilePos& pos) const{ - if (!in_bounds(pos)){ - return TileType::UNKNOWN; - } - return m_tiles[(size_t)pos.y * m_width + pos.x]; -} - -void TileGrid::set(const TilePos& pos, TileType type){ - if (in_bounds(pos)){ - m_tiles[(size_t)pos.y * m_width + pos.x] = type; - } -} - -bool TileGrid::standable(const TilePos& pos) const{ - const TileType type = at(pos); - return type == TileType::WALKABLE || type == TileType::TALL_GRASS; -} - -std::optional TileGrid::step(const TilePos& from, Direction direction) const{ - const TilePos next = from.next(direction); - if (standable(next)){ - return next; - } - if (at(next) == TileType::LEDGE && direction == Direction::SOUTH){ - const TilePos landing = next.next(direction); - if (standable(landing)){ - return landing; - } - } - return std::nullopt; -} - -bool TileGrid::at_wall(const TilePos& pos, Direction direction) const{ - const TileType next = at(pos.next(direction)); - return next != TileType::DOOR && next != TileType::UNKNOWN && !step(pos, direction).has_value(); -} - - - -WallHit walk_to_wall(const TileGrid& grid, const TilePos& from, Direction direction){ - WallHit hit; - hit.stop = from; - while (true){ - const TilePos before = hit.stop; - const std::optional next = grid.step(before, direction); - if (!next){ - hit.wall = before.next(direction); - hit.anchored = grid.at_wall(before, direction); - return hit; - } - hit.tiles += std::abs(next->x - before.x) + std::abs(next->y - before.y); - hit.stop = *next; - } -} - - - -std::string to_string(const TileLeg& leg){ - return std::string(direction_name(leg.direction)) + " " + std::to_string(leg.tiles) + - (leg.ends_at_wall ? " (to wall)" : " (open)"); -} - - -namespace{ - -// The grid's step rules for the shared leg planner. A ledge hop is one -// press that moves two tiles. -class TileGridModel{ -public: - using State = TilePos; - using StateHash = std::hash; - - TileGridModel(const TileGrid& grid, const TilePlanCosts& costs) - : m_grid(grid) - , m_costs(costs) - {} - - std::optional> press(const State& pos, Direction direction) const{ - const std::optional next = m_grid.step(pos, direction); - if (!next){ - return std::nullopt; - } - Step step; - step.next = *next; - step.facing = direction; - const int tiles = std::abs(next->x - pos.x) + std::abs(next->y - pos.y); - step.extra_cost = m_costs.per_tile * (tiles - 1); - if (m_grid.at(*next) == TileType::TALL_GRASS){ - step.extra_cost += m_costs.per_grass_tile; - } - return step; - } - bool held_at(const State& pos, Direction direction) const{ - return m_grid.at_wall(pos, direction); - } - -private: - const TileGrid& m_grid; - const TilePlanCosts& m_costs; -}; - -} - -std::optional> plan_tile_route( - const TileGrid& grid, - const TilePos& from, const TilePos& to, - const TilePlanCosts& costs -){ - if (!grid.standable(from) || !grid.standable(to)){ - throw InternalProgramError( - nullptr, PA_CURRENT_FUNCTION, - "Route ends must be standable: " + to_string(from) + " -> " + to_string(to) + "." - ); - } - if (from == to){ - return std::vector(); - } - LegCosts leg_costs; - leg_costs.per_tile = costs.per_tile; - leg_costs.per_turn = costs.per_leg; - leg_costs.per_open_stop = costs.leg_not_at_wall; - const std::optional>> legs = plan_legs( - TileGridModel(grid, costs), from, std::nullopt, - std::function([&](const TilePos& pos){ return pos == to; }), - std::nullopt, leg_costs - ); - if (!legs){ - return std::nullopt; - } - std::vector ret; - for (const Leg& leg : *legs){ - const size_t tiles = std::abs(leg.end.x - leg.start.x) + std::abs(leg.end.y - leg.start.y); - ret.push_back(TileLeg{leg.direction, tiles, leg.to_wall}); - } - return ret; -} - -std::vector sight_tiles(const TileGrid& grid, const TrainerSight& trainer){ - std::vector tiles; - TilePos pos = trainer.pos; - for (int i = 0; i < trainer.range; i++){ - pos = pos.next(trainer.facing); - if (!grid.standable(pos)){ - break; - } - tiles.push_back(pos); - } - return tiles; -} - -std::vector> legs_crossing_sight( - const TileGrid& grid, - const TilePos& from, - const std::vector& legs, - const std::vector& trainers -){ - std::vector> sights; - for (const TrainerSight& trainer : trainers){ - sights.push_back(sight_tiles(grid, trainer)); - } - std::vector> crossings; - TilePos pos = from; - for (const TileLeg& leg : legs){ - const std::vector tiles = trace_legs(grid, pos, {leg}); - std::vector seen_by; - for (size_t t = 0; t < trainers.size(); t++){ - for (size_t i = 1; i < tiles.size(); i++){ - if (std::find(sights[t].begin(), sights[t].end(), tiles[i]) != sights[t].end()){ - seen_by.push_back(trainers[t].name); - break; - } - } - } - crossings.push_back(std::move(seen_by)); - pos = tiles.back(); - } - return crossings; -} - -std::vector trace_legs( - const TileGrid& grid, - const TilePos& from, - const std::vector& legs -){ - std::vector tiles{from}; - for (const TileLeg& leg : legs){ - size_t travelled = 0; - while (travelled < leg.tiles){ - const TilePos pos = tiles.back(); - const std::optional next = grid.step(pos, leg.direction); - if (!next){ - throw InternalProgramError( - nullptr, PA_CURRENT_FUNCTION, - "Leg " + to_string(leg) + " is stopped at " + to_string(pos) + "." - ); - } - travelled += std::abs(next->x - pos.x) + std::abs(next->y - pos.y); - tiles.push_back(*next); - } - if (travelled != leg.tiles){ - throw InternalProgramError( - nullptr, PA_CURRENT_FUNCTION, - "Leg " + to_string(leg) + " overshoots on a ledge hop." - ); - } - } - return tiles; -} - - - -std::string to_string(const PlannedLeg& leg){ - std::string out = to_string(leg.leg) + " to"; - for (const TilePos& pos : leg.after){ - out += " " + to_string(pos); - } - return out; -} - -namespace{ - -// Where `from` ends up after `tiles` steps in `direction`, stopping early at -// anything that stops the player. Nothing if a step would leave the map or -// enter a door: the plan cannot tell what happens then. -std::optional step_tiles( - const TileGrid& grid, TilePos from, Direction direction, int tiles, int& grass -){ - int travelled = 0; - while (travelled < tiles){ - const std::optional next = grid.step(from, direction); - if (!next){ - if (!grid.at_wall(from, direction)){ - return std::nullopt; - } - break; - } - travelled += std::abs(next->x - from.x) + std::abs(next->y - from.y); - if (grid.at(*next) == TileType::TALL_GRASS){ - grass++; - } - from = *next; - } - return from; -} - -using Spread = std::vector; - -bool spread_less(const TilePos& a, const TilePos& b){ - return a.y != b.y ? a.y < b.y : a.x < b.x; -} -void normalize(Spread& spread){ - std::sort(spread.begin(), spread.end(), spread_less); - spread.erase(std::unique(spread.begin(), spread.end()), spread.end()); -} -struct SpreadLess{ - bool operator()(const Spread& a, const Spread& b) const{ - return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), spread_less); - } -}; - -} - -std::optional> plan_robust_route( - const TileGrid& grid, - const TilePos& from, const TilePos& to, - const RobustPlanCosts& costs -){ - if (!grid.standable(from) || !grid.standable(to)){ - throw InternalProgramError( - nullptr, PA_CURRENT_FUNCTION, - "Route ends must be standable: " + to_string(from) + " -> " + to_string(to) + "." - ); - } - return plan_robust_route(grid, std::vector{from}, [&](const TilePos& pos){ return pos == to; }, costs); -} - -std::optional> plan_robust_route( - const TileGrid& grid, - const std::vector& from, const std::function& goal, - const RobustPlanCosts& costs -){ - for (const TilePos& pos : from){ - if (!grid.standable(pos)){ - throw InternalProgramError( - nullptr, PA_CURRENT_FUNCTION, - "Route starts must be standable: " + to_string(pos) + "." - ); - } - } - // Only the start may be wider than costs.max_spread: every leg must bring - // the player within it. - const size_t max_spread = costs.max_spread; - auto reached = [&](const Spread& spread){ - return std::all_of(spread.begin(), spread.end(), goal); - }; - - struct Node{ - long long cost; - Spread parent; - PlannedLeg leg; - bool done = false; - }; - std::map nodes; - using Entry = std::pair; - auto entry_greater = [](const Entry& a, const Entry& b){ return a.first > b.first; }; - std::priority_queue, decltype(entry_greater)> queue(entry_greater); - - Spread start = from; - normalize(start); - nodes[start] = Node{0, {}, {}}; - queue.emplace(0, start); - - auto relax = [&](const Spread& spread, long long cost, Spread next, PlannedLeg leg){ - normalize(next); - if (next.size() > max_spread || next == spread){ - return; - } - auto iter = nodes.find(next); - if (iter != nodes.end() && iter->second.cost <= cost){ - return; - } - leg.after = next; - nodes[next] = Node{cost, spread, std::move(leg)}; - queue.emplace(cost, std::move(next)); - }; - - size_t searched = 0; - while (!queue.empty()){ - const Entry top = queue.top(); - queue.pop(); - const long long cost = top.first; - const Spread& spread = top.second; - Node& node = nodes[spread]; - if (node.done || node.cost != cost){ - continue; - } - node.done = true; - if (++searched > costs.max_searched){ - return std::nullopt; - } - if (reached(spread)){ - std::vector legs; - for (Spread at = spread; at != start; ){ - const Node& step = nodes[at]; - legs.push_back(step.leg); - at = step.parent; - } - std::reverse(legs.begin(), legs.end()); - return legs; - } - - for (Direction direction : ALL_DIRECTIONS){ - // To the wall: every position walks until stopped. - { - Spread next; - size_t longest = 0; - int grass = 0; - bool ok = true; - for (const TilePos& pos : spread){ - const WallHit hit = walk_to_wall(grid, pos, direction); - if (!hit.anchored){ - ok = false; - break; - } - int leg_grass = 0; - step_tiles(grid, pos, direction, (int)hit.tiles, leg_grass); - grass = std::max(grass, leg_grass); - longest = std::max(longest, hit.tiles); - next.push_back(hit.stop); - } - if (ok && longest > 0){ - const long long step = (long long)costs.per_leg + - (long long)costs.per_tile * longest + (long long)costs.per_grass_tile * grass; - relax(spread, cost + step, std::move(next), PlannedLeg{TileLeg{direction, longest, true}, {}}); - } - } - // Open: about `tiles` tiles, give or take `open_error`. - for (int tiles = 1; tiles <= costs.max_open_tiles; tiles++){ - Spread next; - int grass = 0; - bool ok = true; - for (const TilePos& pos : spread){ - const int error = tiles <= costs.exact_open_tiles ? 0 : costs.open_error + tiles / costs.open_error_per; - for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ - int leg_grass = 0; - const std::optional end = step_tiles(grid, pos, direction, n, leg_grass); - if (!end){ - ok = false; - break; - } - grass = std::max(grass, leg_grass); - next.push_back(*end); - } - if (!ok){ - break; - } - } - if (!ok){ - break; - } - const long long step = (long long)costs.per_leg + costs.leg_not_at_wall + - (long long)(costs.per_tile + costs.per_open_tile) * tiles + (long long)costs.per_grass_tile * grass; - relax(spread, cost + step, std::move(next), PlannedLeg{TileLeg{direction, (size_t)tiles, false}, {}}); - } - } - } - - return std::nullopt; -} - - - -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md deleted file mode 100644 index 2c37d39a69..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/MAPS.md +++ /dev/null @@ -1,45 +0,0 @@ -# AutoStory map grids: source and status - -Each map file's header starts with the same three lines, kept current with the code: - -- **Map source**: where the tiles come from. "Decomp" means a decompilation's - collision table (pret/pokediamond `land_data` narc, or pret/pokeplatinum - `map_data_NNN.bin`) with the objects from its events file; BDSP keeps - Diamond/Pearl's layout, and Platinum's few changes show up on the console. "DP image" means a Bulbapedia map image - traced by hand or by colour; those images have 12 px rows for 16 px columns, so - a traced grid has 3/4 of a tile per row and drifts by the map's height - differences (cliffs are painted taller than their tiles). -- **Console checks**: the anchors measured on the Switch (D-pad taps, sign reads, - recorded human walks), with the run or date. -- **Status**: the checkpoints that pass on this exact grid, and the next change. - -| map | source | checkpoints passing | next | -|---|---|---|---| -| Route 201 | decomp (Diamond) | none yet (00.02-00.04 and mart_lady passed on the image grid) | re-run them | -| Route 202 | decomp (Diamond) | none yet (00.04 passed on the image grid) | re-run 00.04; the save-spot legs grew three rows | -| Sandgem Town | decomp (Diamond) | none yet (00.04, 00.05 passed with image rows 0-6) | re-run; the Route 202 entry stop is (29,1) | -| Jubilife City | decomp (Diamond), console NPCs | none yet (00.05, 01.01, 01.06, 01.07 passed on the image grid) | re-run; re-anchor the Mart clown and the steps walk | -| Oreburgh Mine B2F | decomp (Diamond) | none yet (01.02, 01.03 passed 3x on the stretched image grid) | re-run both | -| Route 203 | decomp (Diamond) | none yet (01.06 passed on the image grid) | re-run; the row to Jubilife is 18, four sand rows | -| Route 204 South | decomp | 01.08 (1x) | more passes | -| Ravaged Path | decomp rows 30-53 | 01.09 by hand | program pass | -| Route 204 North | decomp | 01.10 (1x) | probe column 23; (12,6) marked from the console | -| 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 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 | -| 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. 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); the -re-derivation of 2026-10-31 took every grid above from `devtools/maps decomp ---repo pret/pokediamond` and translated each file's named tiles with its -console anchors. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp deleted file mode 100644 index c91f67d5ea..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* BDSP AutoStory - Floaroma Town tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_FloaromaTown.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace FloaromaTown{ - -using namespace Pokemon; - - -// Console: the old couple stands at (2, 25) and (3, 25) ('N'), placed from -// the 2026-10-31 walk; they are not in the DP data (a Camper and a Lass are). -// Map source: the decomp (Diamond land_data 0032 = Platinum map_data_032, -// 2026-10-31) with the objects from its events file. -// Console checks: none yet. -// 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_0032: one cell of the -// Sinnoh matrix at column 5, row 20; map_data_032 in pret/pokeplatinum), -// with the objects from its events file (zone_event narc_0404, -// events_floaroma_town.json in Platinum); BDSP keeps Diamond/Pearl's layout. -// Local (x, y) = world (x - 160, z - 640); 32 x 32 tiles. The cell above -// (column 5, row 19, land_data 0033) carries the same map header but is cut -// off from the town (its bottom rows are wall; the town's row 0 is a -// dead-end strip under them), so it is left out. -// The flower field is the west half, columns 0 to 17, rows 2 to 22; -// Diamond's data puts a Camper at (6, 10) and a Lass wandering row 5 in it. -// The old couple BDSP shows there are not in the Diamond/Pearl data: place -// them as 'N' from the console. Exits: Route 204 south through (10..12, -// 30..31) (and the one-tile gap (8, 30..31), which joins a side path on the -// route); Route 205 east at (31, 19..22). Warp tiles the player stands on -// are written as '.': (20, 11), the Flower Shop's entrance, and (2, 1), (3, -// 1) into Floaroma Meadow, where the two Galactic grunts stand ('N' wins -// there) until the Valley Windworks is cleared (flag 447). Objects, from the -// events file: -// door (16, 26) to the Pokemon Center; door (24, 26) to the south-east -// house; -// door (24, 17) to the Poke Mart; its signboard (29, 15); -// door (11, 14) to the middle house; -// Flower Shop entrance (20, 11), its signboard (17, 11) and the two berry -// patches (18, 11) and (22, 11), as '#'; -// map signpost (13, 19); -// Grunt M (2, 1), looks east, and Grunt M (3, 1), looks west, not -// trainers, hidden by flag 447; -// Camper (6, 10), looks around, not a trainer; -// Lass (23, 11), looks west, not a trainer; -// Pokemon Breeder F (19, 21), looks around, not a trainer; -// a man with Cyrus's sprite (11, 26), looks around, not a trainer, hidden -// by flag 449 (Diamond/Pearl only; whether he is there when the story -// arrives is for the console); -// Lass wanders west and east from (10, 5), columns 9 to 11, row 5: off the -// grid; -// School Kid M wanders around (16, 16), columns 15 to 17, rows 15 to 17: -// off the grid. -// No trainers. Platinum differs in one row and one person: its row 30 opens -// columns 8 to 13 where Diamond opens 8 and 10 to 12 (Route 204 North's top -// rows are '########.#...###' in both games, so Diamond's is the border BDSP -// has), and it has a Beauty at (10, 19) looking south instead of the man at -// (11, 26). -const TileGrid& grid(){ - return story_grid("FloaromaTown"); -} - -const TilePos ROUTE_204_ARRIVAL{11, 29}; -const TilePos OLD_WOMAN{3, 25}; -const TilePos OLD_MAN{2, 25}; -const TilePos POKEMON_CENTER_DOOR{16, 26}; - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h deleted file mode 100644 index 43384adc6b..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h +++ /dev/null @@ -1,36 +0,0 @@ -/* BDSP AutoStory - Floaroma Town tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see - * the .cpp's header for the cells, the offset and the objects. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_FloaromaTown_H -#define PokemonAutomation_PokemonBDSP_AutoStory_FloaromaTown_H - -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace FloaromaTown{ - - -const Pokemon::TileGrid& grid(); - -// Where 01.10's walk north from Route 204 ends on the town's banner and -// saves (r248a, r251a): the path's middle column, three rows in. -extern const Pokemon::TilePos ROUTE_204_ARRIVAL; -// The old couple in the flower field, placed from the console (2026-10-31 -// hand walk and r251a: eight tiles west of the arrival, then three north -// to the tile below her); not in the DP data. -extern const Pokemon::TilePos OLD_WOMAN; -extern const Pokemon::TilePos OLD_MAN; -extern const Pokemon::TilePos POKEMON_CENTER_DOOR; - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp deleted file mode 100644 index 16089d130c..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* BDSP AutoStory - Jubilife City tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_JubilifeCity.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace JubilifeCity{ - -using namespace Pokemon; - - -// Map source: the decomp (pret/pokediamond land_data narc_0018, 0016, 0017 -// and 0015, 2026-10-31) with the objects from its events file. Platinum -// differs only around the Global Terminal (columns 14..26, rows 30..45). -// Console checks (2026-10-30/31): the lamps (43,53) and (49,53), north from -// (52,53) to the Pokemon Center's door, the School's door from the -// Center's doorstep, the east street to Route 203 (01.06, r230a), the -// north street (01.07), and the four 00.05 people, placed from the -// console on the tiles the events file gives them. -// Status: no checkpoint has run on this grid yet. 00.05, 01.01, 01.06 and -// 01.07 passed on the colour-classified image grid it replaces (48 rows -// for 64) and must be re-run; re-check the Mart clown's tile (he wanders -// 182..184 on row 33 in Diamond) and the hand walk from the steps' top -// east to the house and north to the Center (the decomp has the plaza -// only 171..177 wide on rows 58..59). -// -// Decoded from Pokemon Diamond's collision table: cells (23..24, 4..5) of -// the Sinnoh matrix, with the objects from its events file. Local (x, y) = -// world (x - 128, z - 736); 64 x 64 tiles. The console's measurements on -// the image grid were a column east of its doors; on this grid the lamps, -// the doors and the four people all land where the console put them. -// -// Exits: south, the 3-wide neck (45..47, 61) down to Route 202; east, the -// street (rows 21..24) to Route 203; north, (42..55, 0..1) to Route 204; -// west, the Route 218 gate on rows 22..23 (its warp tiles are 'D'). Doors -// are 'D' tiles walked into from below; the Trainers' School's doorway -// (40,40) and the Global Terminal's (21,42) are warp tiles stepped onto and -// marked 'D' as well, so a plan never steps on them. The main road runs -// from the steps (46..47, 60..62) north between the lamps (43,53), (49,53) -// and on up to the north exit; the doors' row 40 is open between the School -// and the Center (43..49), and the plaza below it is rows 41..52. -// People who stand still, from the events file: the Poketch president -// (46,35) and the clown west of the TV station (36,16), the 00.05 story -// people (hidden by flags before and after); an Ace Trainer (36,25) on the -// north road's west side, a Cashier (26,42), an Expert (44,44), two kids -// (52,46), (54,46) on the plaza and a School Kid (17,55): none of these -// five has been seen on the console yet. The clown by the Mart (55,33) and -// the one by the Poketch Company (15,18) wander three tiles in Diamond but -// stood still on the console (00.05, three runs): on the grid at their -// spawn tiles. Wanderers left off: an Ace Trainer along row 20 (21..23), -// one along row 21 (45..47), a Twin around (33,18), a School Kid on column -// 51 (rows 33..35), a Pokefan around (41,30). Rowan and the grunts at the -// north exit, the Collectors and Dawn are hidden by story flags. -const TileGrid& grid(){ - return story_grid("JubilifeCity"); -} - -// Checked on the console (2026-10-30, CFR "walk"): 00.05's save stands -// below the steps, against the wall just east of them (the banner reads -// Jubilife City). West along that wall does not stop at the steps (it runs -// to the trees); a tile west, then north, climbs them. North up the main -// road from the steps passes the lamps (43,53), (49,53) and does not stop -// before the north exit. From the lamps' row, west stops at the house at -// (37..42, 47..52) and east at the house at (53..57, 49..56); north from -// (52,53) stops in front of the Pokemon Center. The steps are columns -// 45..47 of row 61; the save stands at (48,62) against (48,61), and the -// tile west then north puts us on column 47, a few rows up. On this grid -// east from rows 58..60 stops at column 49 and north from there at the lamp -// (49,53), not the Center: the climb must end on row 57 or above, or BDSP's -// plaza is wider than Diamond's there (re-check on the console). -const std::vector& up_the_steps(){ - static const std::vector tiles{{46, 58}, {47, 58}, {46, 59}, {47, 59}, {46, 60}, {47, 60}}; - return tiles; -} - -// The School's doorway is a warp tile stepped onto from (40,41); the -// Center's door is walked into from (52,41). On the console (2026-10-30) -// eleven one-tile holds west from the Center's doorstep put us under the -// School's door: the doorstep was the tile east of the door's column, as -// story_door_front() allows. -const TilePos TRAINERS_SCHOOL_DOOR{40, 40}; -const TilePos POKEMON_CENTER_DOOR{52, 40}; -const TilePos TV_STATION_DOOR{36, 15}; - -// On the main road, five rows north of the School's and the Center's -// doors' row and six columns west of the Center's door. Talked to from the -// east, facing west (also works from the south). -const TilePos POKETCH_PRESIDENT{46, 35}; -// Below the Poke Mart's planters, where the road meets the plaza: his spawn -// tile; he wanders a tile either side in Diamond, and the console had him -// a tile east of it. -const TilePos CLOWN_MART{55, 33}; -// West of the TV station door, right below it. -const TilePos CLOWN_TV_STATION{36, 16}; -// East of the Poketch Company's sign, a row below it. Talked to from the -// south on the console; from the east a walk west along row 18 stops right -// beside him. -const TilePos CLOWN_POKETCH_COMPANY{15, 18}; - - - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h deleted file mode 100644 index 941b89ff77..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h +++ /dev/null @@ -1,45 +0,0 @@ -/* BDSP AutoStory - Jubilife City tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Jubilife City as a tile grid, from the Diamond decompilation's collision - * table, with the places and people of checkpoint 00.05. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_JubilifeCity_H -#define PokemonAutomation_PokemonBDSP_AutoStory_JubilifeCity_H - -#include -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace JubilifeCity{ - - -const Pokemon::TileGrid& grid(); - -// Where we may stand after climbing the steps from where 00.05 starts: -// below them, against the wall just east of them, then a tile west and -// about two tiles north. -const std::vector& up_the_steps(); - -// Doors: walk north from the tile below to enter. -extern const Pokemon::TilePos TRAINERS_SCHOOL_DOOR; -extern const Pokemon::TilePos POKEMON_CENTER_DOOR; -extern const Pokemon::TilePos TV_STATION_DOOR; - -// The Poketch Company president and the three coupon clowns. -extern const Pokemon::TilePos POKETCH_PRESIDENT; -extern const Pokemon::TilePos CLOWN_MART; -extern const Pokemon::TilePos CLOWN_TV_STATION; -extern const Pokemon::TilePos CLOWN_POKETCH_COMPANY; - - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp deleted file mode 100644 index 3198d18e18..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* BDSP AutoStory - Lake Verity tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_LakeVerity.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace LakeVerity{ - -using namespace Pokemon; - - -// Map source: the decomp (Diamond land_data 0512 = Platinum map_data_541, -// 2026-10-31) with the objects from its events file. -// Console checks: none yet. -// 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_0512: the cell at column -// 1, row 1 of the lake's own matrix 101, which is 3 x 2 cells; map_data_541 -// of matrix 102 in pret/pokeplatinum), with the objects from its events file -// (zone_event narc_0298, events_lake_verity.json in Platinum); BDSP keeps -// Diamond/Pearl's layout. Local (x, y) = world (x - 32, z - 32) in that -// matrix; 32 x 32 tiles. Only this cell is reachable on foot: the shore -// where the starter scene plays, columns 10 to 25, rows 4 to 22. The lake is -// '#'; the tiles at (0..6, 4..9) are shallow water (puddle, behaviour 0x16), -// walkable in the data but closed in by the lake. The west shore with TM38 -// (cells to the west) needs Surf. -// Entrance: the warp tiles (14, 22) and (15, 22), arrived on from Verity -// Lakefront, written as '.'; walking south off them leaves. The scene's -// actors are hidden-flag objects, drawn where the events file puts them -// because that is where the walk ends: Rowan and the briefcase on (16, 11) -// and the player's counterpart on (17, 11), at the water's edge. Objects, -// from the events file: -// Prof. Rowan (16, 11), looks north, hidden by flag 403; the briefcase on -// the same tile, hidden by flag 404; -// the counterpart (Dawn/Lucas, object "Var 0") (17, 11), looks north, -// hidden by flag 434; -// Starly (16, 19), looks north, hidden by flag 429, drawn as 'N' (a scene -// actor on open ground); -// Starly (25, 11), looks west, hidden by flag 429, perched on a blocked -// tile: stays '#'; -// Barry (15, 22), looks north, hidden by flag 436, on the entrance warp -// tile: '.' wins; -// no one wanders here, and no trainers. -// Platinum differs: it stages its scene elsewhere (Rowan (21, 7), the -// counterpart (22, 6), Mars (23, 6), four Galactic grunts with sight 4 to 6, -// no Starly or Barry), walls off the puddle tiles at (0..6, 4..9) and opens -// a path to the Verity Cavern warp at (0, 0). The shore, columns 10 to 25, -// decodes the same tile for tile. Diamond keeps its Galactic version as a -// separate map (MAP_LAKE_VERITY_GALACTIC), reached from the same Lakefront -// warp tiles. -const TileGrid& grid(){ - return story_grid("LakeVerity"); -} - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h deleted file mode 100644 index a5eb838e8f..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h +++ /dev/null @@ -1,27 +0,0 @@ -/* BDSP AutoStory - Lake Verity tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see - * the .cpp's header for the cells, the offset and the objects. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_LakeVerity_H -#define PokemonAutomation_PokemonBDSP_AutoStory_LakeVerity_H - -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace LakeVerity{ - - -const Pokemon::TileGrid& grid(); - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp deleted file mode 100644 index 0b7a20d966..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* BDSP AutoStory - Map grids - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/Json/JsonValue.h" -#include "PokemonBDSP_AutoStory_MapGrids.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ - -using Pokemon::MapData; -using Pokemon::TileGrid; -using Pokemon::TileKind; -using Pokemon::TilePos; -using Pokemon::TileType; - - -namespace{ - -std::optional tile_type_of(TileKind kind){ - switch (kind){ - case TileKind::WALL: return TileType::BLOCKED; - case TileKind::OPEN: return TileType::WALKABLE; - case TileKind::TALL_GRASS: return TileType::TALL_GRASS; - case TileKind::LEDGE_SOUTH: return TileType::LEDGE; - case TileKind::DOOR: return TileType::DOOR; - case TileKind::SIGN: return TileType::SIGN; - default: return std::nullopt; - } -} - -} - -TileGrid tile_grid_from_map(const MapData& map){ - std::vector rows; - for (int y = 0; y < map.tiles.height; y++){ - std::string row; - for (int x = 0; x < map.tiles.width; x++){ - const TileKind kind = map.tiles.at(TilePos{x, y}); - const std::optional type = tile_type_of(kind); - if (!type){ - throw ParseException(std::format( - "{}: glyph '{}' at {} has no BDSP tile.", map.name, Pokemon::glyph_of(kind), Pokemon::to_string(TilePos{x, y}) - )); - } - row += Pokemon::tile_char(*type); - } - rows.push_back(std::move(row)); - } - for (const Pokemon::MapObject& object : map.objects){ - if (object.kind != Pokemon::ObjectKind::NPC || object.wander){ - throw ParseException(std::format("{}: object {} is not a person standing still.", map.name, object.name)); - } - rows[object.y][object.x] = Pokemon::tile_char(TileType::NPC); - } - return TileGrid(rows); -} - -std::optional grid_difference(const TileGrid& here, const TileGrid& there){ - if (here.width() != there.width() || here.height() != there.height()){ - return std::format("{} x {} here, {} x {} there", here.width(), here.height(), there.width(), there.height()); - } - for (int y = 0; y < here.height(); y++){ - for (int x = 0; x < here.width(); x++){ - const TilePos pos{x, y}; - if (here.at(pos) != there.at(pos)){ - return std::format( - "{}: '{}' here, '{}' there", - Pokemon::to_string(pos), Pokemon::tile_char(here.at(pos)), Pokemon::tile_char(there.at(pos)) - ); - } - } - } - return std::nullopt; -} - - -namespace{ - -const std::map& story_grids(){ - static const std::map grids = []{ - std::map parsed; - for (const auto& [name, json] : bdsp_map_json()){ - const MapData map = Pokemon::parse_map(parse_json(json), name + ".json"); - if (map.name != name){ - throw ParseException(std::format("{}.json: name is \"{}\".", name, map.name)); - } - parsed.emplace(name, tile_grid_from_map(map)); - } - return parsed; - }(); - return grids; -} - -} - -const TileGrid& story_grid(const std::string& name){ - const std::map& grids = story_grids(); - if (auto iter = grids.find(name); iter != grids.end()){ - return iter->second; - } - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No BDSP story map named \"" + name + "\"."); -} - - - -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.h deleted file mode 100644 index 41f0d61d64..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.h +++ /dev/null @@ -1,52 +0,0 @@ -/* BDSP AutoStory - Map grids - * - * From: https://github.com/PokemonAutomation/ - * - * The story's maps are JSON files in the shared map schema - * (Pokemon_MapData.h), PokemonBDSP/Programs/AutoStory/Maps, built into the - * program by CMake, read with the shared loader and turned into the tile - * grids the planner walks. Each map's X::grid() returns story_grid("X"). - * - * TODO: move the maps to PokemonAutomation/Packages (Resources/PokemonBDSP/Maps) when ready - * - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_MapGrids_H -#define PokemonAutomation_PokemonBDSP_AutoStory_MapGrids_H - -#include -#include -#include -#include -#include "Pokemon/Navigation/Pokemon_MapData.h" -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ - - -// (name, JSON text) of each map in PokemonBDSP/Programs/AutoStory/Maps/, -// built into the program by pa_embed_text_files() (cmake/EmbedTextFiles.cmake). -const std::vector>& bdsp_map_json(); - -// A map's tiles as a tile grid: walls, open ground, tall grass, south -// ledges, doors and signs; a standing person ("npc" object) is an NPC tile. -// Throws ParseException, naming the map, for what BDSP's grids have no -// tile for (water, ledges other than south, items, wanderers). -Pokemon::TileGrid tile_grid_from_map(const Pokemon::MapData& map); - -// "(x, y): 'N' here, '.' there", or nothing when the grids are the same -// size and equal cell for cell. -std::optional grid_difference(const Pokemon::TileGrid& here, const Pokemon::TileGrid& there); - -// The grid of the map `name`, read from bdsp_map_json() once. Throws -// InternalProgramError for a name it does not have. -const Pokemon::TileGrid& story_grid(const std::string& name); - - - -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp deleted file mode 100644 index 781af0c643..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* BDSP AutoStory - Oreburgh City tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_OreburghCity.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace OreburghCity{ - -using namespace Pokemon; - - -// Map source: the decomp (Diamond land_data 0022, 0023, 0175, 0024 = -// Platinum map_data_022/023/175/024, 2026-10-31) with the objects from -// its events file. -// Console checks: none yet. -// 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_0022, 0023, 0175 and -// 0024: four cells of the Sinnoh matrix, columns 8 and 9, rows 23 and 24; -// the same cells are map_data_022, 023, 175 and 024 in pret/pokeplatinum), -// with the objects from its events file (zone_event narc_0044, -// events_oreburgh_city.json in Platinum); BDSP keeps Diamond/Pearl's layout. -// Local (x, y) = world (x - 256, z - 736); 64 x 64 tiles. The town sits on -// the upper rows (10 to 26); row 27 is the cliff, and the stairs down it are -// the road at columns 44 to 48 (rows 27 to 43), which opens into the mine -// yard at row 44. The two one-tile stubs south of the gym, (24, 27..29) and -// (31, 27..29), and the pocket at (35..42, 28..29) are walkable in the data -// but closed off: dead ends, not stairs. -// Exits: Oreburgh Gate west through the cave mouth (1, 13), entered from the -// warp tile (2, 13); Route 207 north up columns 41 to 46 (rows 0 to 9); the -// Mine south over the warp tiles (44..48, 59), walked onto heading south. -// Warp tiles the player stands on are written as '.': (2, 13), (44..48, 59), -// and (49, 11), the Mining Museum's entrance. Objects, from the events file: -// door (26, 20) to the Gym; its signpost (22, 20); -// door (47, 20) to the Pokemon Center; -// door (29, 10) to the Poke Mart; doors (15, 10) and (22, 10) to the -// north-west and north houses; door (17, 20) to the west house; door (37, -// 16) to the middle house; door (56, 28) to the east house; door (51, 36) -// to the south house; -// map signposts (4, 11) and (44, 1); signboards (45, 12) and (45, 56); -// steam vents (9, 26), (11, 26), (13, 26), (60, 52), (60, 53), objects -// that block, as '#'; -// Youngster (10, 16), looks north, not a trainer; -// Worker (11, 25), looks south and west, not a trainer; -// Hiker wanders around (47, 26), columns 46 to 48, rows 25 to 27: off the -// grid; -// School Kid F wanders around (32, 18), column 32, rows 16 to 20: off the -// grid; -// Guitarist wanders around (23, 13), columns 22 to 24, rows 10 to 16: off -// the grid; -// Camper walks back and forth from (36, 19), columns 33 to 39, row 19: off -// the grid; -// Battle Girl wanders around (36, 23), column 36, rows 21 to 25: off the -// grid; -// Pokefan F wanders around (45, 38), column 45, rows 37 to 39: off the -// grid; -// Worker wanders around (37, 39), columns 36 to 38, rows 38 to 40: off the -// grid; -// Worker wanders around (50, 41), column 50, rows 38 to 44: off the grid; -// Worker wanders around (56, 57), columns 55 to 57, rows 54 to 60: off the -// grid; -// Machop wanders around (55, 56), columns 53 to 57, rows 54 to 58: off the -// grid; -// Barry (26, 21), in front of the Gym door, "wander" with no range (hidden -// by flag 410 once the story moves on): off the grid, listed so the route -// knows he may stand there. -// None of the people here is a trainer. Platinum (pret/pokeplatinum) decodes -// the same terrain tile for tile; it adds items on the ground at (35, 37) -// and (39, 38), a Battle Girl at (51, 21), a Machop at (56, 46) and a -// wandering Machop around (35, 45), none of which Diamond has. -const TileGrid& grid(){ - return story_grid("OreburghCity"); -} - -const TilePos POKEMON_CENTER_DOOR{47, 20}; -const TilePos POKEMON_CENTER_DOORSTEP{46, 21}; -const TilePos GYM_DOOR{26, 20}; -const TilePos GYM_DOORSTEP{26, 21}; -const TilePos GATE_MOUTH{1, 13}; - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h deleted file mode 100644 index 7a3f66901b..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h +++ /dev/null @@ -1,37 +0,0 @@ -/* BDSP AutoStory - Oreburgh City tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see - * the .cpp's header for the cells, the offset and the objects. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_OreburghCity_H -#define PokemonAutomation_PokemonBDSP_AutoStory_OreburghCity_H - -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace OreburghCity{ - - -const Pokemon::TileGrid& grid(); - -// Doors are the tiles walked into. The Center's doorstep: the decomp's door -// tile is (47, 20), and 20 D-pad taps west from the doorstep stand under -// the Gym's door (26, 20) on the console (r204 to r215), which puts the -// doorstep at x 46: one of the two is a tile off, a probe decides. -extern const Pokemon::TilePos POKEMON_CENTER_DOOR; -extern const Pokemon::TilePos POKEMON_CENTER_DOORSTEP; -extern const Pokemon::TilePos GYM_DOOR; -extern const Pokemon::TilePos GYM_DOORSTEP; -// The Oreburgh Gate's east mouth, walked into heading west from (2, 13). -extern const Pokemon::TilePos GATE_MOUTH; - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp deleted file mode 100644 index 310728cda5..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* BDSP AutoStory - Oreburgh Gate 1F tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_OreburghGate.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace OreburghGate{ - -using namespace Pokemon; - - -// Map source: the decomp (Diamond land_data 0418 = Platinum map_data_441, -// 2026-10-31) with the objects from its events file. -// Console checks: none yet. -// 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_0418: one cell, the only -// one of matrix 003, at column 0, row 0; map_data_441 in pret/pokeplatinum), -// with the objects from its events file (zone_event narc_0250, -// events_oreburgh_gate_1f.json in Platinum); BDSP keeps Diamond/Pearl's -// layout. Local (x, y) = world (x - 0, z - 0) in the cave's own matrix; 32 x -// 32 tiles. The cave floor is '.'; the rocks Rock Smash breaks are '#' -// (eight of them, each hidden once smashed). -// Exits: the warp tiles the player stands on are written as '.': (4, 22) -// leaves west to Route 203 and (27, 22) east to Oreburgh City; the cave -// mouths behind them, (3, 22) and (28, 22), are 'D'. (20, 5) is the stairs -// down to B1F (a warp tile too). Objects, from the events file: -// Picnicker Diana (24, 21), looks south, sees 3; -// Camper Curtis (17, 25), looks north, sees 3; -// Hiker (7, 20), looks south, not a trainer (the Rock Smash HM); -// rocks (19, 6), (14, 4), (12, 10), (11, 11), (11, 25), (13, 26), (15, -// 26), (25, 24), as '#'. -// The two trainers face the row-22 corridor from either side: Diana sees -// (24, 22..24) and Curtis (17, 22..24). Platinum decodes this cave -// identically, terrain and objects. -const TileGrid& grid(){ - return story_grid("OreburghGate"); -} - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h deleted file mode 100644 index f0e2984230..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h +++ /dev/null @@ -1,27 +0,0 @@ -/* BDSP AutoStory - Oreburgh Gate tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see - * the .cpp's header for the cells, the offset and the objects. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_OreburghGate_H -#define PokemonAutomation_PokemonBDSP_AutoStory_OreburghGate_H - -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace OreburghGate{ - - -const Pokemon::TileGrid& grid(); - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp deleted file mode 100644 index 915bdc1474..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* BDSP AutoStory - Oreburgh Gym tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#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(){ - return story_grid("OreburghGym"); -} - -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 deleted file mode 100644 index 2cb6dc8489..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGym.h +++ /dev/null @@ -1,38 +0,0 @@ -/* 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_OreburghMine.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.cpp deleted file mode 100644 index 53e2d1dd6d..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* BDSP AutoStory - Oreburgh Mine tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_OreburghMine.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace OreburghMine{ - -using namespace Pokemon; - - -// Map source: the decomp (pret/pokediamond land_data narc_0314, matrix 006; -// 2026-10-31) with the objects from its events file; Platinum's -// map_data_337 is the same. -// Console checks (2026-10-28): the corridor's rocks zigzag a row at a time, -// the room's second row passes under the worker on the first, Roark -// stands a row above the bottom row between two rocks; the walk north -// from the corridor's corner reached the entrance hall (r99). -// Status: no checkpoint has run on this grid yet. 01.02 and 01.03 passed -// 3x on the stretched image grid it replaces, which had every row one -// lower, the top corridor a row short, the room's second row blocked -// and no ledge in the west corridor; re-run both. -// -// Decoded from Pokemon Diamond's collision table: the one cell of matrix -// 006, with the objects from its events file. Local (x, y) = world (x, z); -// 32 x 32 tiles. The way up to the entrance hall is the warp tile (15,1), -// marked 'D': stepping onto it leaves the room. The console walked north -// into the hall from column 14 (r99), where this table has the way up only -// at column 15: a stick hold drifts, or BDSP's stairs are wider. -// The corridor from the top (13..17, 2..6) zigzags down to the room's first -// row (15); the room's second row (17) is open from 2 to 29 and passes -// under the worker and his Machop on the first; the coal block fills -// (7..24, 18..25) with the corridors either side; the west corridor has a -// ledge (2..4, 19), crossed southward only; the bottom rows 28..29 run -// under the block. -// Objects, from the events file: Roark (18,28), between two rocks (17,28) -// and (19,28); workers who stand still at (8,28) looking north, (26,20) -// looking west and (21,15) with Machop at (20,15) and (27,15); Poke Balls -// at (4,28) and (26,24), walls until picked up. A Machop wanders along row -// 28, columns 11..13, and is left off the grid. -const TileGrid& grid(){ - return story_grid("OreburghMine"); -} - -// The first open row below the warp tile, where the walk in from the hall -// leaves us (or the row below: the plan's first legs run to walls and meet). -const std::vector& corridor_top(){ - static const std::vector tiles{{14, 2}, {15, 2}, {16, 2}}; - return tiles; -} - -const TilePos ROARK{18, 28}; -const TilePos CORRIDOR_EXIT_START{14, 10}; - - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h deleted file mode 100644 index 4dc823b486..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h +++ /dev/null @@ -1,39 +0,0 @@ -/* BDSP AutoStory - Oreburgh Mine tiles - * - * From: https://github.com/PokemonAutomation/ - * - * The Oreburgh Mine's coal room (Bulbapedia's "B2F") as a tile grid, with - * Roark, for checkpoint 01.03. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_OreburghMine_H -#define PokemonAutomation_PokemonBDSP_AutoStory_OreburghMine_H - -#include -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace OreburghMine{ - - -const Pokemon::TileGrid& grid(); - -// Where the walk in from the entrance hall leaves us: the top of the rocky -// corridor, the first open row below the warp tile. -const std::vector& corridor_top(); - -// Roark, between two rocks a row above the room's bottom row. Talked to from -// the tile below him, facing north. -extern const Pokemon::TilePos ROARK; -// The corridor's corner a wall-to-wall route ends on, below a straight -// walk north out into the entrance hall. -extern const Pokemon::TilePos CORRIDOR_EXIT_START; - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp deleted file mode 100644 index 500bc58358..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* BDSP AutoStory - Ravaged Path tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_RavagedPath.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace RavagedPath{ - -using namespace Pokemon; - - -// Map source: rows 30 to 53 from the decomp (map_data_435/436, 2026-10-31); -// the rows above from the DP image, unused by any route. -// Console checks: entrance (19,50), the stairs, the three-wide corridor, the -// rocks, the east end and the exit tile (2026-10-31 probes). -// Status: 01.09 reaches the exit by hand; no program pass yet. -// -// Rows 30 to 53 are decoded from Pokemon Platinum's collision table for -// this map (the pret/pokeplatinum decompilation, land data 435/436 of map -// matrix 051) with the objects from its events file; BDSP keeps the layout. -// Water and the items on the ground are '#'; the smashable rocks are '#' -// too and listed in rocks(). Checked on the console 2026-10-31 (r235b and -// D-pad probes): in from the south door onto (19, 50), up the stairs -// (rows 45 to 47, columns 18 to 20) and north to the wall at row 39; the -// corridor is three wide up to row 41 and opens east on rows 42 to 44, -// with the rocks at (22, 42) and (22, 43), the Potion ball at (22, 44) and -// a rock at (23, 44). Rows 0 to 29 are still the hand trace from -// Bulbapedia's Ravaged_Path_DP.png (stretched from 528x672 to 528x864), with -// '?' where the untraced west chambers continue; nothing we walk is there. -const TileGrid& grid(){ - return story_grid("RavagedPath"); -} - -const std::vector& rocks(){ - static const std::vector tiles{ - {11, 36}, {7, 37}, {12, 37}, {8, 38}, {10, 38}, {10, 39}, {13, 39}, - {7, 40}, {9, 40}, {17, 40}, {12, 41}, {22, 42}, {22, 43}, {23, 44}, - }; - return tiles; -} - -const TilePos ENTRANCE{19, 50}; - -const std::vector& before_rocks(){ - static const std::vector tiles{{21, 42}, {21, 43}}; - return tiles; -} - -const TilePos EAST_END{29, 44}; -const TilePos ABOVE_EXIT{28, 44}; - - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h deleted file mode 100644 index 4f03dacf39..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h +++ /dev/null @@ -1,47 +0,0 @@ -/* BDSP AutoStory - Ravaged Path tiles - * - * From: https://github.com/PokemonAutomation/ - * - * The Ravaged Path (the cave on Route 204) as a tile grid, for checkpoint - * 01.05: from its south door, where Route 204's south half enters, east - * along its lower corridor to the door out onto Route 204's north half. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RavagedPath_H -#define PokemonAutomation_PokemonBDSP_AutoStory_RavagedPath_H - -#include -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace RavagedPath{ - - -// With every Rock Smash rock in place (blocked). -const Pokemon::TileGrid& grid(); - -// The Rock Smash rocks of the traced part, blocked in grid(). Each breaks -// for good once smashed, so a plan after a smash opens that tile. -const std::vector& rocks(); - -// Where walking in from Route 204's south half leaves us: the tile above the -// south door, at the foot of the room below the stairs. -extern const Pokemon::TilePos ENTRANCE; -// The tiles west of the two rocks across the lower corridor: from either, -// facing east, A offers Rock Smash, and the corridor is open to its east end. -const std::vector& before_rocks(); -// The corridor's east end on its bottom row, where walls stop a walk east -// and south: a route can end here, and nowhere else near the way out. -extern const Pokemon::TilePos EAST_END; -// The tile above the door out onto Route 204's north half, a tile west of -// EAST_END: walk south. -extern const Pokemon::TilePos ABOVE_EXIT; - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp deleted file mode 100644 index 2a79840580..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* BDSP AutoStory - Route 201 tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_Route201.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route201{ - -using namespace Pokemon; - - -// Map source: the decomp (pret/pokediamond land_data narc_0005 and -// narc_0006, 2026-10-31) with the objects from its events file; -// Platinum's map_data_005/006 have the same terrain. -// Console checks: the border sign read from (54,4) facing east, row 3 open -// east of the grass to Sandgem's fence, row 5 to Sandgem without a stop, -// the Potion lady on row 3 (2026-10-28 to 30, CFR "walk"). -// Status: no checkpoint has run on this grid yet. 00.02 to 00.04 and the -// mart_lady checkpoint passed on the image-traced grid it replaces (3/4 -// of a tile per row) and must be re-run. -// -// Decoded from Pokemon Diamond's collision table: cells (26,3) and (26,4) -// of the Sinnoh matrix, with the objects from its events file. Local (x, y) -// = world (x - 96, z - 839); 64 x 25 tiles, rows 0..2 are padding. The -// columns are the ones the image-traced grid had (its anchors matched the -// decomp exactly); the rows are the game's: the image gave 20 rows for 25. -// Sandgem Town's grid joins at column 64, row -3 (its front row is row 4). -// -// Edges: west, rows 6..7 and 11 (Lake Verity, off the map); south, the -// Twinleaf gap (14..17, 21..24); east, rows 3..6, into Sandgem. Ledges: -// row 12 (0..3 and 8..31) and (53..57, 9) in the north-east; both are -// jumped southward only. The north-east grass (42..52, 3..6) is four rows -// deep and its tree stub (51..52) stands on rows 7..12; the middle grass -// (20..29, 13..16) four rows; the south-east grass (42..57, 18) and -// (46..57, 19..20). -// Objects, from the events file: the signs (55,4) to Sandgem (BORDER_SIGN), -// (13,17) to Twinleaf and the Trainer Tips sign (40,12); a School Kid who -// stands at (57,8) looking west (not yet seen on the console). Route 201 -// has no trainers and no items on the ground. Wanderers, left off the grid: -// a Breeder around (27,15), columns 26..28, rows 14..16; a Lass along row -// 16, columns 44..48. The Poke Mart lady, who gives 10 Potions, stands -// still at (44,3) in Diamond's events file and on the console (the user, -// 2026-11-01): left off the grid, since her talk is walked to, not planned -// (r113a..r120a missed her by the walk, not by her moving). Rowan, Barry -// and the briefcase by the lake are hidden by story flags and left off. -const TileGrid& grid(){ - return story_grid("Route201"); -} - - -// The arrow sign to Sandgem Town, world (151,843), on the row of Sandgem's -// doors (its row 7). Checked on the console (2026-10-30, CFR "walk"): a row -// south of the lady's row (row 3), east stops at the sign's west side and A -// reads "Route 201 -> Sandgem Town" (a green box); north from there is one -// row, to row 3. Row 3 runs on east past the sign's north side to the Lab's -// fence. Row 5, the path, runs from the grass's west edge to Sandgem without -// a stop. -const TilePos BORDER_SIGN{55, 4}; -// Her spawn tile in Diamond is (44,3), the east end of the top grass row. -// On the console (by hand, then through the Lab Console; 99715d5d6 and -// f823453e9 on bdsp/new-game-intro-v2) she stood at (43,3), and walking -// west along row 3 from the trees at its east end stopped at (44,3), facing -// her; her lines need one A each, 1.5 s apart. r113a..r120a -// missed her talk walking to her, not because she moved. -// Checked on the console (2026-10-30, CFR "walk"), twice: from the grass's -// west edge on row 5, north stops at the trees 2 rows up, and east from -// there stops at her. r135a missed her walking west along row 4. -const TilePos POTION_GIVER{43, 3}; -const TilePos POTION_GIVER_TALK_FROM{44, 3}; - - - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h deleted file mode 100644 index 24481753bf..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h +++ /dev/null @@ -1,37 +0,0 @@ -/* BDSP AutoStory - Route 201 tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Route 201 (Twinleaf Town to Sandgem Town) as a tile grid, from the - * Diamond decompilation's collision table; BDSP keeps DP's tile layout. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route201_H -#define PokemonAutomation_PokemonBDSP_AutoStory_Route201_H - -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route201{ - - -const Pokemon::TileGrid& grid(); - -// The sign by the Sandgem Town border, at the east end of the route. -extern const Pokemon::TilePos BORDER_SIGN; -// The Poke Mart lady, who gives 10 Potions: at the west end of the top -// grass row. Not on the grid: she turns and may wander. -extern const Pokemon::TilePos POTION_GIVER; -// East of her: walking west along her row from the open ground east of the -// grass stops here, facing her. -extern const Pokemon::TilePos POTION_GIVER_TALK_FROM; - - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp deleted file mode 100644 index 9bb6b1a2a3..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* BDSP AutoStory - Route 202 tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_Route202.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route202{ - -using namespace Pokemon; - - -// Map source: the decomp (pret/pokediamond land_data narc_0014, with the -// margins from narc_0006, 0007 and 0173; 2026-10-31) and the objects -// from its events file; Platinum's map_data_014 has the same terrain. -// Console checks: the player under the south ledge at (22,24) beside the -// trees at (21,24), the sign a row below at (24,25), the save spot -// (30,24) against the east trees, Natalie's challenge at (22,22), east -// along the row above the ledge stops at column 30 and column 30 runs -// north to row 4 (r75), the catch spot's walls (2026-10-29/30); trees, -// not grass, at (15..20, 28..29) below the catch patch (r253: west -// along row 29 stopped at column 21, beside the trees); a tree at -// (21, 30), south of the pocket at (21, 29) where the catch's save -// loads (r254: south from there was blocked at once). -// Status: no checkpoint has run on this grid yet. 00.04 passed on the -// image-traced grid it replaces (26 rows for 32) and must be re-run; -// its legs south of the catch spot are three rows longer here. -// -// Decoded from Pokemon Diamond's collision table: cell (25,5) of the Sinnoh -// matrix, with the objects from its events file. Local (x, y) = world -// (x - 159, z - 800); 36 x 32 tiles, the whole cell, so the grid's edges -// are where the game changes its location banner. The columns are the ones -// the image-traced grid had (its ledges, tree pillars and signs matched the -// decomp exactly); the rows are the game's: the image gave 26 rows for 32. -// Sandgem Town's grid starts on the row below row 31, at column 1. -// -// Exits: north, the gap (11..18, 0) to Jubilife City (EXIT_JUBILIFE in its -// middle); south, (21..30, 31) into Sandgem, where the road narrows to -// 25..30 for two rows. Ledges: row 10 (9..13 and -// 22..27) and row 23 (9..13 and 22..30), jumped southward only. The east -// wall is column 33 from row 10 to 20, column 32 on row 21 and column 31 on -// row 22, the row right above the south ledge: east along that row stops at -// column 30 (r75), and column 30 is open north from there to row 4 under -// Logan's row. -// Objects, from the events file: three trainers who stand still, Youngster -// Tristan (7,13), Lass Natalie (22,18) and Youngster Logan (26,4), all -// facing south, with the sight ranges the events give; a Potion ball (3,6), -// a wall until picked up; the signs (17,4) to Jubilife, (15,16) Trainer Tips -// and (24,25) to Sandgem. BDSP has trees where Diamond's catch patch has -// its two bottom rows, (15..20, 28..29): the console's patch is three rows -// between tree rows, as the image-traced grid had it. A Youngster who is not a trainer wanders along row -// 8, columns 9..11, and is left off the grid (the image-traced grid had him -// as a fourth trainer facing east). Dawn's tile (15,27) is hidden by a -// story flag. -const TileGrid& grid(){ - return story_grid("Route202"); -} - - -// Where 00.03's save after the catch stands: the bottom row of the -// tall-grass patch at (15..20, 25..27), world (178,827). On the console the -// sign at (24,25) is 5 columns right and 2 rows up, walking east stops at -// the trees after 11 tiles and north at the trees after 2; south are trees -// (the decomp's two more grass rows are trees in BDSP, r253). -const TilePos CATCH_SPOT{19, 27}; -// Where 00.04 saves once it has Potions, before Route 202's trainers (the -// console's saves from r113a..r117a stand here too): under the south ledge, -// against the east trees, world (189,824). -const TilePos SAVE_SPOT{30, 24}; - -// From the events file: each trainer's tile, facing and sight range. -// Natalie challenged us at (22,22), walking east along the row above the -// ledge (r75), the fourth tile of her sight. -const TilePos TRAINER_TRISTAN{7, 13}; -const TilePos TRAINER_NATALIE{22, 18}; -const TilePos TRAINER_LOGAN{26, 4}; - -const std::vector& trainer_sights(){ - static const std::vector sights{ - {"tristan", TRAINER_TRISTAN, Direction::SOUTH, 5}, - {"natalie", TRAINER_NATALIE, Direction::SOUTH, 4}, - {"logan", TRAINER_LOGAN, Direction::SOUTH, 5}, - }; - return sights; -} - -// The middle of the 8-tile gap at (11..18, 0), world (174,800), below the -// 3-wide neck of Jubilife's south exit (173..175). -const TilePos EXIT_JUBILIFE{15, 0}; - - - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h deleted file mode 100644 index cee0a1e49a..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h +++ /dev/null @@ -1,49 +0,0 @@ -/* BDSP AutoStory - Route 202 tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Route 202 (Sandgem Town to Jubilife City) as a tile grid, from the - * Diamond decompilation's collision table; BDSP keeps DP's tile layout. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route202_H -#define PokemonAutomation_PokemonBDSP_AutoStory_Route202_H - -#include -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route202{ - - -const Pokemon::TileGrid& grid(); - -// Where the player stands in the tall grass after the catching tutorial. -extern const Pokemon::TilePos CATCH_SPOT; -// Under the south ledge, against the east trees: where the console's 00.04 -// save stands. Two walls pin it. -extern const Pokemon::TilePos SAVE_SPOT; - -// The three trainers, from the events file: Youngster Tristan in the west -// field, Lass Natalie above the south ledge, Youngster Logan by the east -// grass. All face south. -extern const Pokemon::TilePos TRAINER_TRISTAN; -extern const Pokemon::TilePos TRAINER_NATALIE; -extern const Pokemon::TilePos TRAINER_LOGAN; - -// Their sight lines, in this map's tiles. The story wants these battles. -const std::vector& trainer_sights(); - -// A tile in the gap of the north edge; walking north from it leaves for -// Jubilife City. -extern const Pokemon::TilePos EXIT_JUBILIFE; - - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp deleted file mode 100644 index 642168d015..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* BDSP AutoStory - Route 203 tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_Route203.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route203{ - -using namespace Pokemon; - - -// Map source: the decomp (pret/pokediamond land_data narc_0019 and -// narc_0020, with Jubilife's column 0 from narc_0016; 2026-10-31) and -// the objects from its events file. Platinum adds an X Defense ball at -// (40,14). -// Console checks (r227 hand pass, 2026-10-31): the Gate's warp at column -// 55, the ledge on row 15 (38..48), the beaten girl at column 43 on the -// second sand row, the row below her straight west to Jubilife (35 -// taps, no row change), the blue-haired trainer at the sand's west end. -// Status: no checkpoint has run on this grid yet. 01.06 passed on the -// image-traced grid it replaces (its east stretch corrected on the -// console) and must be re-run: the decomp has four sand rows under the -// ledge where the console counted three (9 taps south from (55,9); the -// decomp has 10 open tiles, so the first tap may only have turned). -// -// Decoded from Pokemon Diamond's collision table: cells (23,6) and (23,7) -// of the Sinnoh matrix, with the objects from its events file. Local -// (x, y) = world (x - 191, z - 740); 61 x 24 tiles. Column 0 is Jubilife's -// east edge. The columns are the ones the image-traced grid had (its gate -// warp, ledge and signs matched the decomp exactly); the rows are the -// game's: the image squeezed the west and middle stretches. -// - West stretch (columns 5..22): the field (5..22, 4..19) with grass at -// 5..8 (8..13), a ledge (18..22, 13), and the road on rows 17..19 that -// runs to Jubilife at column 0. -// - Middle stretch (23..37): the pond (29..34, 7..11) cuts the strip north -// of it, by the Repel ball (31,5), off from the rest: r222g's walk got -// stuck up there. The way through is along the bottom, rows 16..19. -// - East stretch (38..55): the Gate's mouth is (56,9), its warp tile -// (55,9). South from (55,9) is open to row 19. The ledge on row 15 -// (38..48) is crossed southward only. The sand below it is four rows, -// 16..19: the blue-haired trainer (Youngster Dallas, looks south, sees -// 4) at the sand's west end on its first row, the girl (Youngster -// Sebastian in the events file, looks west, sees 5) at (43,17) on its -// second. -// Row 18 runs in one straight line west from the sand to Jubilife; row 17 -// is blocked by the girl and the trainer, row 19 by trees at (36..37, 19). -// Objects, from the events file: trainers who stand still, 'N': Youngster -// Michael (13,10), looks west, sees 2; Dallas (31,16); Sebastian (43,17); -// Lass Madeline (49,8), looks south, sees 5. Items that block their tile -// until picked up, '#': a Poke Ball (20,10) and a Repel (31,5). Signs: to -// Jubilife (9,16), Trainer Tips (26,10) and (47,12), to Oreburgh (53,7); -// Jubilife's own sign to Route 203 stands at (7,16) in its events, not in -// this map's. Left off: a Lass who wanders along row 17 (14..16) and the -// Youngster at (54,16) who stands still in Diamond but wanders in BDSP (the -// blue-haired man near the Gate, on the console); Barry (10,17) is hidden -// by a story flag. -const TileGrid& grid(){ - return story_grid("Route203"); -} - -// The warp tile the Gate puts us on, and its open neighbours. -const std::vector& gate_exit(){ - static const std::vector tiles{{55, 9}, {54, 9}, {55, 8}, {55, 10}}; - return tiles; -} - - - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h deleted file mode 100644 index 9bf526197b..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h +++ /dev/null @@ -1,32 +0,0 @@ -/* BDSP AutoStory - Route 203 tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Route 203 as a tile grid, for checkpoint 01.06: from the Oreburgh Gate's - * west exit to Jubilife City's east edge. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route203_H -#define PokemonAutomation_PokemonBDSP_AutoStory_Route203_H - -#include -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route203{ - - -const Pokemon::TileGrid& grid(); - -// Where stepping out of the Oreburgh Gate may leave us when Route 203's -// banner shows: the warp tile west of the cave's mouth and its neighbours. -const std::vector& gate_exit(); - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp deleted file mode 100644 index eee289d1ce..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* BDSP AutoStory - Route 204 tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_Route204.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route204{ - -using namespace Pokemon; - - -// Map source: the decomp (map_data_031, 2026-10-31) with the objects from -// its events file; before that the DP image, 3/4 rows. -// Console checks: row 27 open under the cliff, the stairs, Taylor's sight at -// column 17 (recorded human walk, 2026-10-31). Suspects: column 23 rows -// 12 to 19 blocked on the console (r242a); three open rows under the -// cave, not four (r241a, r243a). -// Status: 01.10 not passed yet; the route is the recorded human line -// (floaroma_waypoints()). -// -// Decoded from Pokemon Platinum's collision table for this map (the -// pret/pokeplatinum decompilation, map_data_031.bin: one cell of the Sinnoh -// matrix, column 5, row 21; local (x, y) = world (x - 160, z - 672)) with -// the objects from its events file; BDSP keeps the layout. Water and the -// items on the ground are '#'. Objects: the Ravaged Path's door, arriving -// on (20, 26); the twins (15, 7) and (16, 7) looking south; Aroma Lady -// Taylor (17, 20) looking south and east; Bug Catcher Brandon walking back -// and forth, on row 12 on the console (r246a), drawn at (20, 12) by the DP -// map, (22, 13) in Platinum's data; the arrow signpost -// (17, 9); a Youngster who is not a trainer wanders rows 27 and 28 below -// the cave, off the grid. The path north into Floaroma is columns 10 to 12 -// at the top. -// The 2026-10-29 hand run went out of the cave, west to the stairs, up them -// into the pocket the ledge (row 15) closes, back down, east and north -// through the tall grass, and west below the flower beds past the twins. -// Before 2026-10-31 this grid was traced from Bulbapedia's DP map image, -// whose rows are 12 px to the columns' 16: every row was 3/4 of a tile. -const TileGrid& north_grid(){ - return story_grid("Route204North"); -} - -const TilePos CAVE_EXIT{20, 26}; - -bool in_floaroma_path(const TilePos& pos){ - return pos.x >= 10 && pos.x <= 12 && pos.y <= 5; -} - -std::vector north_trainer_sights(){ - return { - {"Twins (left)", {15, 7}, Direction::SOUTH, 3}, - {"Twins (right)", {16, 7}, Direction::SOUTH, 4}, - {"Aroma Lady Taylor", {17, 20}, Direction::SOUTH, 4}, - {"Aroma Lady Taylor", {17, 20}, Direction::EAST, 4}, - // Bug Catcher Brandon paces east and west below the flower beds - // and stopped us on row 12 (r246a: "Say, what's your opinion on bug - // Pokemon?"); the DP map draws him at (20, 12), Platinum's data - // has him at (22, 13). The tile is a guess until a shot fixes it. - {"Bug Catcher Brandon", {20, 12}, Direction::WEST, 4}, - {"Bug Catcher Brandon", {20, 12}, Direction::EAST, 4}, - }; -} - -std::vector floaroma_waypoints(){ - // The line a human walked on 2026-10-31 (recorded; drawn over the DP - // map image): a tile south out of the cave's mouth; west along the row - // under the cliff, where the Youngster wanders (he stood a row below - // as we passed; the walker waits for him when he is in the way); north - // up the middle of the stairs; east along the corridor, where Aroma - // Lady Taylor sees us at column 17 and walks over for her battle; north - // up column 19 through the tall grass; west below the flower beds; - // north between the beds. The DP image shows a trainer sprite at - // (20, 12), by the corner where the line turns west: not seen yet on - // the console. The ledge on row 15 closes the stairs' column going - // north, so the line goes round through the grass. - // Column 11 for the last stretch: (12, 6) is blocked on the console - // (r248a, twice), grass in Platinum's data; the detour through (11, 6) - // passed. - return {{20, 27}, {11, 27}, {11, 22}, {19, 22}, {19, 12}, {11, 12}, {11, 5}}; -} - - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.h deleted file mode 100644 index edd4b29cc0..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.h +++ /dev/null @@ -1,43 +0,0 @@ -/* BDSP AutoStory - Route 204 tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Route 204's north half as a tile grid, for checkpoint 01.05: from the - * door out of the Ravaged Path up to the path into Floaroma Town. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route204_H -#define PokemonAutomation_PokemonBDSP_AutoStory_Route204_H - -#include -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route204{ - - -const Pokemon::TileGrid& north_grid(); - -// Where leaving the Ravaged Path puts us: the tile below its door. -extern const Pokemon::TilePos CAVE_EXIT; - -// Whether a tile is in the path north into Floaroma, between the flower -// beds' fences: walking north from here leaves the route. -bool in_floaroma_path(const Pokemon::TilePos& pos); - -// The twins below the right-hand flower bed: a double battle when they see -// us walk past below them. -std::vector north_trainer_sights(); - -// The corners of the line into Floaroma from the cave's exit, as a human -// walked it (2026-10-31): the last is in the path into Floaroma. -std::vector floaroma_waypoints(); - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp deleted file mode 100644 index 4f022f4dce..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* BDSP AutoStory - Route 204 South tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_Route204South.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route204South{ - -using namespace Pokemon; - - -// Map source: the decomp (map_data_021, 2026-10-31) with the objects from -// its events file. -// Console checks: column 14 stops at the signpost (14,17), column 13 is -// grass to the cliff, Sarah fights on row 21 (r233a, r234a, probes). -// Status: 01.08 passes once (r235a). -// -// Decoded from Pokemon Platinum's collision table for this map (the -// pret/pokeplatinum decompilation, res/field/maps/data/map_data_021.bin: -// 32 x 32 tiles, one cell of the Sinnoh matrix at column 5, row 22), with -// the objects from its events file (events_route_204_south.json); BDSP -// keeps Diamond/Pearl's layout. Local (x, y) = world (x - 160, z - 704). -// Water is '#'. Objects, from the events file: -// door to the Ravaged Path (11, 1); its signboard (10, 2); -// the "204" arrow signpost (14, 17), which stops a walk north up the -// street's column 14 (r233a, r234a); -// Lass Samantha (11, 8), looks south; Lass Sarah (12, 21), looks north -// and east by turns; Youngster Tyler (7, 18), looks west and east; -// items on the ground (17, 18), (29, 12), (2, 28), as '#'; -// a Youngster who is not a trainer wanders west and east along row 2 in -// front of the door: off the grid, the walker waits for him. -// Checked on the console 2026-10-31 (r233a, r234a, probes): north up -// column 14 from Jubilife stops at the signpost (14, 17); column 13 is -// tall grass all the way up and stops at the cliff (13, 2), the door two -// columns west; Sarah walked up and fought us once on row 21. -// Row 31, columns 12 to 15, joins the top of Jubilife's north street: -// walking south there leaves the route. -const TileGrid& grid(){ - return story_grid("Route204South"); -} - -std::vector jubilife_entry(){ - // The walk north looks between 400 ms holds, so it may stop up to two - // tiles past the border. - return {{14, 31}, {14, 30}, {14, 29}}; -} - -const TilePos BELOW_DOOR{11, 2}; - -std::vector trainer_sights(){ - // Sarah turns between north and east; her east line crosses the - // street's columns, so a walk north meets it or not by luck (r233a - // passed, r234a fought). The planner cannot avoid it: she is listed - // so the route knows whom it may meet, with the range that fits. - return { - {"Lass Samantha", {11, 8}, Direction::SOUTH, 4}, - {"Lass Sarah", {12, 21}, Direction::NORTH, 4}, - {"Lass Sarah", {12, 21}, Direction::EAST, 4}, - {"Youngster Tyler", {7, 18}, Direction::EAST, 4}, - {"Youngster Tyler", {7, 18}, Direction::WEST, 4}, - }; -} - -std::vector tiles_to_avoid(){ - std::vector tiles; - for (const TrainerSight& trainer : trainer_sights()){ - if (trainer.name == "Lass Sarah" && trainer.facing == Direction::EAST){ - continue; - } - for (const TilePos& pos : sight_tiles(grid(), trainer)){ - tiles.push_back(pos); - } - } - return tiles; -} - - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h deleted file mode 100644 index d03ed47c1b..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h +++ /dev/null @@ -1,44 +0,0 @@ -/* BDSP AutoStory - Route 204 South tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Route 204's south half as a tile grid, for checkpoint 01.08: from the top - * of Jubilife City's north street to the door of the Ravaged Path. The - * north half (Route204::north_grid) is reached only through the cave, so - * the two halves are separate maps. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_Route204South_H -#define PokemonAutomation_PokemonBDSP_AutoStory_Route204South_H - -#include -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace Route204South{ - - -const Pokemon::TileGrid& grid(); - -// Where walking north out of Jubilife's street puts us: its column on the -// route's bottom rows: the walk stops within two tiles of the border. -std::vector jubilife_entry(); - -// The tile below the Ravaged Path's door; walking north from it enters. -extern const Pokemon::TilePos BELOW_DOOR; - -// The trainers whose sight lines a route may cross. -std::vector trainer_sights(); - -// The sight-line tiles a route can keep out of: all but Sarah's east line, -// which crosses the whole street. -std::vector tiles_to_avoid(); - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp new file mode 100644 index 0000000000..65111d657a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp @@ -0,0 +1,434 @@ +/* BDSP AutoStory - Route planner + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Pokemon/Navigation/Pokemon_LegPlanner.h" +#include "PokemonBDSP_AutoStory_RoutePlanner.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using Pokemon::Direction; +using Pokemon::TileKind; +using Pokemon::TilePos; + + +namespace{ + +size_t distance(const TilePos& a, const TilePos& b){ + return std::abs(a.x - b.x) + std::abs(a.y - b.y); +} + +bool tall_grass(const StoryWorld& world, const TilePos& pos){ + return world.tile(pos) == TileKind::TALL_GRASS; +} + +} + + +WallHit walk_to_wall(const StoryWorld& world, const TilePos& from, Direction direction){ + WallHit hit; + hit.stop = from; + while (true){ + const TilePos before = hit.stop; + const std::optional next = world.step(before, direction); + if (!next){ + hit.wall = before.next(direction); + hit.anchored = world.at_wall(before, direction); + return hit; + } + hit.tiles += distance(*next, before); + hit.stop = *next; + } +} + + +std::string to_string(const TileLeg& leg){ + return std::format("{} {}{}", Pokemon::direction_name(leg.direction), leg.tiles, leg.ends_at_wall ? " (to wall)" : " (open)"); +} + + +namespace{ + +// The world's step rules for the shared leg planner. A ledge hop is one +// press that moves two tiles. +class StoryWorldModel{ +public: + using State = TilePos; + using StateHash = std::hash; + + StoryWorldModel(const StoryWorld& world, const TilePlanCosts& costs) + : m_world(world) + , m_costs(costs) + {} + + std::optional> press(const State& pos, Direction direction) const{ + const std::optional next = m_world.step(pos, direction); + if (!next){ + return std::nullopt; + } + Pokemon::Step step; + step.next = *next; + step.facing = direction; + step.extra_cost = m_costs.per_tile * ((int)distance(*next, pos) - 1); + if (tall_grass(m_world, *next)){ + step.extra_cost += m_costs.per_grass_tile; + } + return step; + } + bool held_at(const State& pos, Direction direction) const{ + return m_world.at_wall(pos, direction); + } + +private: + const StoryWorld& m_world; + const TilePlanCosts& m_costs; +}; + +void check_standable(const StoryWorld& world, const TilePos& from, const TilePos& to){ + if (!world.standable(from) || !world.standable(to)){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format( + "Route ends must be standable: {} -> {}.", Pokemon::to_string(from), Pokemon::to_string(to) + )); + } +} + +} + +std::optional> plan_tile_route( + const StoryWorld& world, + const TilePos& from, const TilePos& to, + const TilePlanCosts& costs +){ + check_standable(world, from, to); + if (from == to){ + return std::vector(); + } + Pokemon::LegCosts leg_costs; + leg_costs.per_tile = costs.per_tile; + leg_costs.per_turn = costs.per_leg; + leg_costs.per_open_stop = costs.leg_not_at_wall; + const auto legs = Pokemon::plan_legs( + StoryWorldModel(world, costs), from, std::nullopt, + std::function([&](const TilePos& pos){ return pos == to; }), + std::nullopt, leg_costs + ); + if (!legs){ + return std::nullopt; + } + std::vector ret; + for (const Pokemon::Leg& leg : *legs){ + ret.push_back(TileLeg{leg.direction, distance(leg.end, leg.start), leg.to_wall}); + } + return ret; +} + +std::vector sight_tiles(const StoryWorld& world, const TrainerSight& trainer){ + std::vector tiles; + TilePos pos = trainer.pos; + for (int i = 0; i < trainer.range; i++){ + pos = pos.next(trainer.facing); + if (!world.standable(pos)){ + break; + } + tiles.push_back(pos); + } + return tiles; +} + +std::vector> legs_crossing_sight( + const StoryWorld& world, + const TilePos& from, + const std::vector& legs, + const std::vector& trainers +){ + std::vector> sights; + for (const TrainerSight& trainer : trainers){ + sights.push_back(sight_tiles(world, trainer)); + } + std::vector> crossings; + TilePos pos = from; + for (const TileLeg& leg : legs){ + const std::vector tiles = trace_legs(world, pos, {leg}); + std::vector seen_by; + for (size_t t = 0; t < trainers.size(); t++){ + const bool seen = std::any_of(tiles.begin() + 1, tiles.end(), [&](const TilePos& tile){ + return std::ranges::find(sights[t], tile) != sights[t].end(); + }); + if (seen){ + seen_by.push_back(trainers[t].name); + } + } + crossings.push_back(std::move(seen_by)); + pos = tiles.back(); + } + return crossings; +} + +std::vector trace_legs( + const StoryWorld& world, + const TilePos& from, + const std::vector& legs +){ + std::vector tiles{from}; + for (const TileLeg& leg : legs){ + size_t travelled = 0; + while (travelled < leg.tiles){ + const TilePos pos = tiles.back(); + const std::optional next = world.step(pos, leg.direction); + if (!next){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format( + "Leg {} is stopped at {}.", to_string(leg), Pokemon::to_string(pos) + )); + } + travelled += distance(*next, pos); + tiles.push_back(*next); + } + if (travelled != leg.tiles){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("Leg {} overshoots on a ledge hop.", to_string(leg))); + } + } + return tiles; +} + + +std::string to_string(const PlannedLeg& leg){ + std::string out = to_string(leg.leg) + " to"; + for (const TilePos& pos : leg.after){ + out += " " + Pokemon::to_string(pos); + } + return out; +} + +namespace{ + +// Where `from` ends up after `tiles` steps in `direction`, stopping early at +// anything that stops the player, and how many tall-grass tiles it enters. +// Nothing if a step would leave the maps or enter a door: the plan cannot +// tell what happens then. +struct Stepped{ + TilePos end; + int grass = 0; +}; +std::optional step_tiles(const StoryWorld& world, TilePos from, Direction direction, int tiles){ + Stepped stepped; + int travelled = 0; + while (travelled < tiles){ + const std::optional next = world.step(from, direction); + if (!next){ + if (!world.at_wall(from, direction)){ + return std::nullopt; + } + break; + } + travelled += (int)distance(*next, from); + if (tall_grass(world, *next)){ + stepped.grass++; + } + from = *next; + } + stepped.end = from; + return stepped; +} + +using Spread = std::vector; + +bool spread_less(const TilePos& a, const TilePos& b){ + return a.y != b.y ? a.y < b.y : a.x < b.x; +} +void normalize(Spread& spread){ + std::sort(spread.begin(), spread.end(), spread_less); + spread.erase(std::unique(spread.begin(), spread.end()), spread.end()); +} +struct SpreadLess{ + bool operator()(const Spread& a, const Spread& b) const{ + return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), spread_less); + } +}; + +// A leg out of a spread: where every tile of it ends, and its cost. +struct Expansion{ + long long cost = 0; + Spread next; + TileLeg leg; +}; + +// To the wall: every position walks until stopped. Nothing unless each is +// held at a wall, and one moves. +std::optional to_wall_leg(const StoryWorld& world, const Spread& spread, Direction direction, const RobustPlanCosts& costs){ + Expansion expansion; + size_t longest = 0; + int grass = 0; + for (const TilePos& pos : spread){ + const WallHit hit = walk_to_wall(world, pos, direction); + if (!hit.anchored){ + return std::nullopt; + } + if (const std::optional stepped = step_tiles(world, pos, direction, (int)hit.tiles)){ + grass = std::max(grass, stepped->grass); + } + longest = std::max(longest, hit.tiles); + expansion.next.push_back(hit.stop); + } + if (longest == 0){ + return std::nullopt; + } + expansion.cost = (long long)costs.per_leg + (long long)costs.per_tile * longest + (long long)costs.per_grass_tile * grass; + expansion.leg = TileLeg{direction, longest, true}; + return expansion; +} + +// Open: about `tiles` tiles, give or take the error. Nothing if any +// possible end leaves the maps or enters a door. +std::optional open_leg(const StoryWorld& world, const Spread& spread, Direction direction, int tiles, const RobustPlanCosts& costs){ + Expansion expansion; + int grass = 0; + const int error = tiles <= costs.exact_open_tiles ? 0 : costs.open_error + tiles / costs.open_error_per; + for (const TilePos& pos : spread){ + for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ + const std::optional stepped = step_tiles(world, pos, direction, n); + if (!stepped){ + return std::nullopt; + } + grass = std::max(grass, stepped->grass); + expansion.next.push_back(stepped->end); + } + } + expansion.cost = (long long)costs.per_leg + costs.leg_not_at_wall + + (long long)(costs.per_tile + costs.per_open_tile) * tiles + (long long)costs.per_grass_tile * grass; + expansion.leg = TileLeg{direction, (size_t)tiles, false}; + return expansion; +} + +// Dijkstra over sets of tiles the player may stand on. +class RobustSearch{ +public: + RobustSearch(const StoryWorld& world, const RobustPlanCosts& costs) + : m_world(world) + , m_costs(costs) + {} + + std::optional> run(Spread start, const std::function& goal){ + normalize(start); + m_start = start; + m_nodes[start] = Node{0, {}, {}}; + m_queue.emplace(0, start); + size_t searched = 0; + while (!m_queue.empty()){ + const auto [cost, spread] = m_queue.top(); + m_queue.pop(); + Node& node = m_nodes[spread]; + if (node.done || node.cost != cost){ + continue; + } + node.done = true; + if (++searched > m_costs.max_searched){ + return std::nullopt; + } + if (std::all_of(spread.begin(), spread.end(), goal)){ + return legs_to(spread); + } + expand(spread, cost); + } + return std::nullopt; + } + +private: + struct Node{ + long long cost = 0; + Spread parent; + PlannedLeg leg; + bool done = false; + }; + using Entry = std::pair; + struct EntryGreater{ + bool operator()(const Entry& a, const Entry& b) const{ return a.first > b.first; } + }; + + void expand(const Spread& spread, long long cost){ + for (Direction direction : Pokemon::ALL_DIRECTIONS){ + if (std::optional wall = to_wall_leg(m_world, spread, direction, m_costs)){ + relax(spread, cost, std::move(*wall)); + } + for (int tiles = 1; tiles <= m_costs.max_open_tiles; tiles++){ + std::optional open = open_leg(m_world, spread, direction, tiles, m_costs); + if (!open){ + break; + } + relax(spread, cost, std::move(*open)); + } + } + } + + // Only the start may be wider than costs.max_spread: every leg must + // bring the player within it. + void relax(const Spread& spread, long long cost, Expansion expansion){ + normalize(expansion.next); + if (expansion.next.size() > m_costs.max_spread || expansion.next == spread){ + return; + } + const long long total = cost + expansion.cost; + auto iter = m_nodes.find(expansion.next); + if (iter != m_nodes.end() && iter->second.cost <= total){ + return; + } + m_nodes[expansion.next] = Node{total, spread, PlannedLeg{expansion.leg, expansion.next}}; + m_queue.emplace(total, std::move(expansion.next)); + } + + std::vector legs_to(const Spread& end) const{ + std::vector legs; + for (Spread at = end; at != m_start; ){ + const Node& step = m_nodes.at(at); + legs.push_back(step.leg); + at = step.parent; + } + std::reverse(legs.begin(), legs.end()); + return legs; + } + + const StoryWorld& m_world; + const RobustPlanCosts& m_costs; + Spread m_start; + std::map m_nodes; + std::priority_queue, EntryGreater> m_queue; +}; + +} + +std::optional> plan_robust_route( + const StoryWorld& world, + const TilePos& from, const TilePos& to, + const RobustPlanCosts& costs +){ + check_standable(world, from, to); + return plan_robust_route(world, std::vector{from}, [&](const TilePos& pos){ return pos == to; }, costs); +} + +std::optional> plan_robust_route( + const StoryWorld& world, + const std::vector& from, const std::function& goal, + const RobustPlanCosts& costs +){ + for (const TilePos& pos : from){ + if (!world.standable(pos)){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Route starts must be standable: " + Pokemon::to_string(pos) + "."); + } + } + return RobustSearch(world, costs).run(from, goal); +} + + + +} +} +} diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h similarity index 52% rename from SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.h rename to SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h index c8ae8ba9d9..f5b9d6d730 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_TileGrid.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h @@ -1,191 +1,144 @@ -/* Tile Grid - * - * From: https://github.com/PokemonAutomation/ - * - * An overworld map as a grid of tiles, and a planner that turns a walk from - * one tile to another into straight legs. Timed stick holds drift by a tile; - * a leg that ends against a wall does not, because the player stops there - * however long the stick is held. The planner prefers such legs. - */ - -#ifndef PokemonAutomation_Pokemon_TileGrid_H -#define PokemonAutomation_Pokemon_TileGrid_H - -#include -#include -#include -#include -#include -#include "Pokemon_Grid.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -// Legend of the ASCII rows a grid is parsed from. -enum class TileType{ - BLOCKED, // '#': trees, walls, items on the ground - WALKABLE, // '.': open ground and paths - TALL_GRASS, // '"': walkable, with wild encounters - LEDGE, // 'v': crossed only southward, hopping to the tile past it - NPC, // 'N': a standing NPC or trainer; blocks like a wall - SIGN, // 'S': a sign; blocks like a wall - DOOR, // 'D': walking into it enters a building - UNKNOWN, // '?': off the map; an exit or ground we have no map of -}; -char tile_char(TileType type); - -class TileGrid{ -public: - // Every row must have the same length and use only the legend's characters. - // Throws InternalProgramError otherwise. - explicit TileGrid(const std::vector& rows); - - // The grid as the ASCII rows it parses from. - std::vector rows() const; - - int width() const{ return m_width; } - int height() const{ return m_height; } - bool in_bounds(const TilePos& pos) const; - - // Out-of-bounds tiles read as UNKNOWN. - TileType at(const TilePos& pos) const; - - // Changes one tile, e.g. to block one found in the way on the console. - // Out-of-bounds tiles are left alone. - void set(const TilePos& pos, TileType type); - - // Whether the player can stand on this tile. - bool standable(const TilePos& pos) const; - - // Where one step from `from` lands, or nothing if the player is stopped. - // A south step onto a ledge hops to the tile past it. - std::optional step(const TilePos& from, Direction direction) const; - - // Whether a step from `pos` is refused by a tile that holds the player - // in place. Doors and unknown tiles are not walls: walking into a door - // enters the building, and unknown ground may be an exit. - bool at_wall(const TilePos& pos, Direction direction) const; - -private: - int m_width = 0; - int m_height = 0; - std::vector m_tiles; -}; - - -// Where the player stops when walking in one direction until stopped. -struct WallHit{ - TilePos stop; - size_t tiles = 0; // tiles travelled; a ledge hop counts 2 - TilePos wall; // the first tile the player could not enter - bool anchored = false; // the player is held at `stop` (see TileGrid::at_wall()) -}; -WallHit walk_to_wall(const TileGrid& grid, const TilePos& from, Direction direction); - - -// A straight run in one direction. -struct TileLeg{ - Direction direction; - size_t tiles = 0; // tiles travelled; a ledge hop counts 2 - bool ends_at_wall = false; // the next tile in `direction` stops the player -}; -std::string to_string(const TileLeg& leg); - -struct TilePlanCosts{ - int per_tile = 1; - int per_grass_tile = 4; // extra for each tall-grass tile entered - int per_leg = 8; - int leg_not_at_wall = 50; // extra for a leg that stops in the open -}; - -// Cheapest legs from `from` to `to`, moving 4 ways, or nothing if `to` -// cannot be reached. Both tiles must be standable. -std::optional> plan_tile_route( - const TileGrid& grid, - const TilePos& from, const TilePos& to, - const TilePlanCosts& costs = TilePlanCosts() -); - -// A trainer sees the tiles in a straight line in front of them, up to -// `range` tiles or the first tile the player cannot stand on. -struct TrainerSight{ - std::string name; - TilePos pos; - Direction facing; - int range = 4; -}; -std::vector sight_tiles(const TileGrid& grid, const TrainerSight& trainer); - -// For each leg, the trainers whose sight line it enters. -std::vector> legs_crossing_sight( - const TileGrid& grid, - const TilePos& from, - const std::vector& legs, - const std::vector& trainers -); - -// The tiles a list of legs visits, starting with `from`. Throws -// InternalProgramError if a leg is stopped before its end. -std::vector trace_legs( - const TileGrid& grid, - const TilePos& from, - const std::vector& legs -); - - -// A leg of a plan that allows for open legs going a tile short or long. A -// leg to a wall is walked until the player stops; an open leg is walked for -// `leg.tiles` tiles' worth of time. `after` lists every tile the player may -// stand on once the leg is done. -struct PlannedLeg{ - TileLeg leg; - std::vector after; -}; -std::string to_string(const PlannedLeg& leg); - -struct RobustPlanCosts : TilePlanCosts{ - // An open leg of n tiles may end open_error + n / open_error_per tiles - // short or long: on the console 7 tiles went 9. - int open_error = 1; - int open_error_per = 5; - // Open legs this many tiles or shorter land exactly: a short hold moves - // whole tiles. 0 keeps every open leg uncertain. - int exact_open_tiles = 0; - // Extra per tile of an open leg: its timing error grows with its length, - // so a short step after a wall beats a long open leg. - int per_open_tile = 0; - int max_open_tiles = 12; // longest open leg to consider - size_t max_spread = 5; // most tiles the player may be on after a leg - // Most sets of possible tiles to search before giving up. The search is - // over sets, not tiles, so it grows far faster than the map: all of - // Jubilife City from six start tiles ran for minutes with no plan - // (r224a, 2026-10-31); 200000 sets took 31 s there, so this gives up - // after about 3. Use town costs in towns (a whole-Jubilife plan then - // takes 1 s) and crop the map to the part a leg needs rather than - // raising this. - size_t max_searched = 20000; -}; - -// Cheapest legs that take the player from any of the tiles in `from` to tiles -// that are all `goal`, even if every open leg ends up to `open_error` tiles -// off: the walls of later legs must bring the possible positions together. -// Legs that would leave the map or enter a door are not used. Nothing if no -// such plan exists, or none is found within `costs.max_searched` sets. -std::optional> plan_robust_route( - const TileGrid& grid, - const std::vector& from, const std::function& goal, - const RobustPlanCosts& costs = RobustPlanCosts() -); -// The same, from one tile to exactly `to`. -std::optional> plan_robust_route( - const TileGrid& grid, - const TilePos& from, const TilePos& to, - const RobustPlanCosts& costs = RobustPlanCosts() -); - - - -} -} -#endif +/* BDSP AutoStory - Route planner + * + * From: https://github.com/PokemonAutomation/ + * + * Turns a walk on the story world from one tile to another into straight + * legs. Timed stick holds drift by a tile; a leg that ends against a wall + * does not, because the player stops there however long the stick is held. + * The planner prefers such legs. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RoutePlanner_H +#define PokemonAutomation_PokemonBDSP_AutoStory_RoutePlanner_H + +#include +#include +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonBDSP_AutoStory_StoryWorld.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Where the player stops when walking in one direction until stopped. +struct WallHit{ + Pokemon::TilePos stop; + size_t tiles = 0; // tiles travelled; a ledge hop counts 2 + Pokemon::TilePos wall; // the first tile the player could not enter + bool anchored = false; // the player is held at `stop` (see StoryWorld::at_wall()) +}; +WallHit walk_to_wall(const StoryWorld& world, const Pokemon::TilePos& from, Pokemon::Direction direction); + + +// A straight run in one direction. +struct TileLeg{ + Pokemon::Direction direction = Pokemon::Direction::NORTH; + size_t tiles = 0; // tiles travelled; a ledge hop counts 2 + bool ends_at_wall = false; // the next tile in `direction` stops the player +}; +std::string to_string(const TileLeg& leg); + +struct TilePlanCosts{ + int per_tile = 1; + int per_grass_tile = 4; // extra for each tall-grass tile entered + int per_leg = 8; + int leg_not_at_wall = 50; // extra for a leg that stops in the open +}; + +// Cheapest legs from `from` to `to`, moving 4 ways, or nothing if `to` +// cannot be reached. Both tiles must be standable. +std::optional> plan_tile_route( + const StoryWorld& world, + const Pokemon::TilePos& from, const Pokemon::TilePos& to, + const TilePlanCosts& costs = TilePlanCosts() +); + +// A trainer sees the tiles in a straight line in front of them, up to +// `range` tiles or the first tile the player cannot stand on. The maps +// have no sight ranges, so story code lists them. +struct TrainerSight{ + std::string name; + Pokemon::TilePos pos; + Pokemon::Direction facing = Pokemon::Direction::NORTH; + int range = 4; +}; +std::vector sight_tiles(const StoryWorld& world, const TrainerSight& trainer); + +// For each leg, the trainers whose sight line it enters. +std::vector> legs_crossing_sight( + const StoryWorld& world, + const Pokemon::TilePos& from, + const std::vector& legs, + const std::vector& trainers +); + +// The tiles a list of legs visits, starting with `from`. Throws +// InternalProgramError if a leg is stopped before its end. +std::vector trace_legs( + const StoryWorld& world, + const Pokemon::TilePos& from, + const std::vector& legs +); + + +// A leg of a plan that allows for open legs going a tile short or long. A +// leg to a wall is walked until the player stops; an open leg is walked for +// `leg.tiles` tiles' worth of time. `after` lists every tile the player may +// stand on once the leg is done. +struct PlannedLeg{ + TileLeg leg; + std::vector after; +}; +std::string to_string(const PlannedLeg& leg); + +struct RobustPlanCosts : TilePlanCosts{ + // An open leg of n tiles may end open_error + n / open_error_per tiles + // short or long: on the console 7 tiles went 9. + int open_error = 1; + int open_error_per = 5; + // Open legs this many tiles or shorter land exactly: a short hold moves + // whole tiles. 0 keeps every open leg uncertain. + int exact_open_tiles = 0; + // Extra per tile of an open leg: its timing error grows with its length, + // so a short step after a wall beats a long open leg. + int per_open_tile = 0; + int max_open_tiles = 12; // longest open leg to consider + size_t max_spread = 5; // most tiles the player may be on after a leg + // Most sets of possible tiles to search before giving up. The search is + // over sets, not tiles, so it grows far faster than the map: all of + // Jubilife City from six start tiles ran for minutes with no plan + // (r224a, 2026-10-31); 200000 sets took 31 s there, so this gives up + // after about 3. Use town costs in towns (a whole-Jubilife plan then + // takes 1 s) and crop the map to the part a leg needs rather than + // raising this. + size_t max_searched = 20000; +}; + +// Cheapest legs that take the player from any of the tiles in `from` to tiles +// that are all `goal`, even if every open leg ends up to `open_error` tiles +// off: the walls of later legs must bring the possible positions together. +// Legs that would leave the maps or enter a door are not used. Nothing if no +// such plan exists, or none is found within `costs.max_searched` sets. +std::optional> plan_robust_route( + const StoryWorld& world, + const std::vector& from, const std::function& goal, + const RobustPlanCosts& costs = RobustPlanCosts() +); +// The same, from one tile to exactly `to`. +std::optional> plan_robust_route( + const StoryWorld& world, + const Pokemon::TilePos& from, const Pokemon::TilePos& to, + const RobustPlanCosts& costs = RobustPlanCosts() +); + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp deleted file mode 100644 index 84afae03f1..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* BDSP AutoStory - Sandgem Town tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_SandgemTown.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace SandgemTown{ - -using namespace Pokemon; - - -// Map source: the decomp (pret/pokediamond land_data narc_0007, 2026-10-31) -// with the signs and doors from its events file; Platinum's map_data_007 -// is the same. The rows from the doors down have been the decomp's since -// 2026-10-29; the four rows above the doors were the image's, and the -// grid now starts where the game's map does, four rows higher. -// Console checks: all three doors, five signs, the row below the doors east -// to the trees and north from it, the Lab's sign read facing west, the -// walk south from Route 202 stopping above the Mart (2026-10-29/30). -// Status: no checkpoint has run on this grid yet. 00.04, 00.05 and the -// Sandgem Center and Mart lady checkpoints passed with the image's rows -// above the doors; changed since: every tile is 4 rows lower (the grid -// begins at the map's edge), the road from Route 202 narrows on row 6 -// (the walk south from Route 202 stops at (29,5)), and the gap between -// the Lab's fence and the Center on the doors' row is four wide (11..14). -// Re-run them all. -// -// Decoded from Pokemon Diamond's collision table: cell (26,5) of the Sinnoh -// matrix, with the signs and doors from its events file. Local (x, y) = -// world (x - 160, z - 832); 34 x 32 tiles, the whole cell, so the grid's -// edges are where the game changes its location banner. Route 201 joins at -// column -64, row 7 (its row 4 is this grid's row 11); Route 202's road -// comes down onto row 0 at columns 24..29. -// -// Buildings are blocked; each door is the tile the player walks into, on -// the building's front row (row 10). Top left: Professor Rowan's lab, with a -// fence running west along row 10 to the map edge. Top middle: Pokemon -// Center. Top right: Poke Mart. Exits: west, rows 11..15 (Route 201); north, -// (24..29, 0) (Route 202: the road is 6 wide on rows 0..1, 10 wide on rows -// 2..5 and 6 wide again, columns 20..25, on rows 6..9); south, (20..25, 31) -// (the beach). -// -// The image squeezed the rows below the doors: it put both houses' doors -// three rows too high and the east house's wall where the game has open -// ground; r123a planned a west leg to that wall, ran on past it and entered -// the west house's door going north. The townspeople south of the Mart (a -// youngster and two breeders, who stand still in Diamond at (11,22) and -// (23,20)) wander on the console: not marked. Rowan, Barry and Dawn are -// hidden by story flags. -// -// Checked on the console: walking south from Route 202 along its column 30 -// stops above the Poke Mart, where the road narrows (counted as two rows -// above the signs' row on the image grid; the decomp has the wall at (29,6), -// so the stop is (29,5)), and walking west from there stops at (20,5). The -// lab's sign stands on row 11, in front of the fence: walking west along -// row 11 stops at it. -const TileGrid& grid(){ - return story_grid("SandgemTown"); -} - - -const TilePos ROUTE_202_ENTRY_STOP{29, 5}; -// The lab's door, between its two front windows. -const TilePos LAB_DOOR{8, 10}; -// The Pokemon Center's glass door. -const TilePos POKEMON_CENTER_DOOR{17, 10}; -// On the console, walking south along the road's west edge above it stops -// at (20,9), above it. -const TilePos POKEMON_CENTER_SIGN{20, 10}; -// The Poke Mart's door. -const TilePos POKE_MART_DOOR{27, 10}; -// Walking east along the doors' front row stops here, against the trees. -// Checked on the console (2026-10-30, CFR "walk"): east along row 12 (the -// path under the Lab's sign) from Route 201 stops at (29,12), and north from -// there stops here. From below the Center's sign (20,11), west stops at the -// Lab's sign, which reads facing west; south from there stops at the house -// 4 rows down, and north back at the sign's row; west of the house's north -// side is trees. A 200 ms hold south took one row; 300 ms took one or two. -const TilePos FRONT_ROW_EAST_END{29, 11}; - -std::vector below_sign_gap(){ - return {{21, 11}, {22, 11}, {23, 11}, {24, 11}}; -} - - - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.h deleted file mode 100644 index cb5d223828..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_SandgemTown.h +++ /dev/null @@ -1,49 +0,0 @@ -/* BDSP AutoStory - Sandgem Town tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Sandgem Town as a tile grid, from the Diamond decompilation's collision - * table; BDSP keeps DP's tile layout. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_SandgemTown_H -#define PokemonAutomation_PokemonBDSP_AutoStory_SandgemTown_H - -#include -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace SandgemTown{ - - -const Pokemon::TileGrid& grid(); - -// Where the walk south from Route 202 down the road's east side stops, -// above the Poke Mart where the road narrows. -extern const Pokemon::TilePos ROUTE_202_ENTRY_STOP; -extern const Pokemon::TilePos LAB_DOOR; -extern const Pokemon::TilePos POKEMON_CENTER_DOOR; -// The sign east of the Pokemon Center's door. Walking north from row 14 in -// its column stops on the tile below it. -extern const Pokemon::TilePos POKEMON_CENTER_SIGN; -extern const Pokemon::TilePos POKE_MART_DOOR; -// The east end of the row below the Center's and the Mart's doors, at the -// trees: one known tile to plan the way north to Route 202 from. From the -// Mart's door, a tile either side of its column, no plan north is robust. -extern const Pokemon::TilePos FRONT_ROW_EAST_END; -// The doors' front row below the gap between the Center's sign and the -// Mart's, columns 21..24: the only way north from that row that passes no -// door. Walking north from any of them leaves town for Route 202. Walking -// north from anywhere else on the row between columns 18 and 26 stops at a -// sign or a wall; the Center's door is at 17, the Mart's at 27. -std::vector below_sign_gap(); - - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp new file mode 100644 index 0000000000..20012b1bcd --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -0,0 +1,232 @@ +/* BDSP AutoStory - Story world + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "PokemonBDSP_AutoStory_StoryWorld.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using Pokemon::Direction; +using Pokemon::TileKind; +using Pokemon::TilePos; + + +namespace{ + +// The way a ledge is hopped, or nothing for any other tile. +std::optional ledge_direction(TileKind tile){ + switch (tile){ + case TileKind::LEDGE_NORTH: + return Direction::NORTH; + case TileKind::LEDGE_SOUTH: + return Direction::SOUTH; + case TileKind::LEDGE_WEST: + return Direction::WEST; + case TileKind::LEDGE_EAST: + return Direction::EAST; + case TileKind::WALL: + case TileKind::OPEN: + case TileKind::TALL_GRASS: + case TileKind::WATER: + case TileKind::DOOR: + case TileKind::SIGN: + return std::nullopt; + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown TileKind."); +} + +} + + +void StoryWorld::add(std::string name, const Pokemon::MapData& map, const TilePos& offset){ + for (const Placed& placed : m_maps){ + if (placed.name == name){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Map placed twice: " + name); + } + } + Placed placed{std::move(name), map.tiles, {}, offset}; + for (const Pokemon::MapObject& object : map.objects){ + if (!object.wander){ + placed.occupied.push_back({object.x, object.y}); + } + } + check_overlap(placed.name, placed); + m_maps.push_back(std::move(placed)); + rebuild(); +} + +// Map images show a border of trees past their edges, so two maps may +// share walls with nobody on them, but nothing else. +void StoryWorld::check_overlap(const std::string& name, const Placed& map) const{ + const auto free_wall = [](const Placed& placed, const TilePos& pos){ + return placed.tiles.at(pos) == TileKind::WALL && + std::find(placed.occupied.begin(), placed.occupied.end(), pos) == placed.occupied.end(); + }; + for (const Placed& placed : m_maps){ + for (int y = 0; y < map.tiles.height; y++){ + for (int x = 0; x < map.tiles.width; x++){ + const TilePos other{map.offset.x + x - placed.offset.x, map.offset.y + y - placed.offset.y}; + if (placed.tiles.contains(other) && (!free_wall(map, {x, y}) || !free_wall(placed, other))){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format( + "Map {} overlaps {} at its tile {}.", name, placed.name, Pokemon::to_string(TilePos{x, y}) + )); + } + } + } + } +} + +void StoryWorld::rebuild(){ + TilePos low = m_maps[0].offset; + TilePos high = low; + for (const Placed& placed : m_maps){ + low.x = std::min(low.x, placed.offset.x); + low.y = std::min(low.y, placed.offset.y); + high.x = std::max(high.x, placed.offset.x + placed.tiles.width); + high.y = std::max(high.y, placed.offset.y + placed.tiles.height); + } + // Block and uncover lists are in world tiles of the old origin. + const TilePos shift{m_origin.x - low.x, m_origin.y - low.y}; + for (std::vector* list : {&m_blocked, &m_uncovered}){ + for (TilePos& pos : *list){ + pos = {pos.x + shift.x, pos.y + shift.y}; + } + } + m_origin = low; + m_cells = Pokemon::Grid{high.x - low.x, high.y - low.y, {}}; + m_cells.cells.resize((size_t)m_cells.width * m_cells.height); + for (auto iter = m_maps.rbegin(); iter != m_maps.rend(); ++iter){ + const TilePos corner{iter->offset.x - low.x, iter->offset.y - low.y}; + for (int y = 0; y < iter->tiles.height; y++){ + for (int x = 0; x < iter->tiles.width; x++){ + m_cells.at({corner.x + x, corner.y + y}) = Cell{true, iter->tiles.at({x, y}), false}; + } + } + for (const TilePos& pos : iter->occupied){ + m_cells.at({corner.x + pos.x, corner.y + pos.y}).occupied = true; + } + } + for (const TilePos& pos : m_blocked){ + if (Cell* blocked = cell(pos)){ + blocked->occupied = true; + } + } + for (const TilePos& pos : m_uncovered){ + if (Cell* uncovered = cell(pos)){ + uncovered->covered = false; + } + } +} + +const StoryWorld::Cell* StoryWorld::cell(const TilePos& pos) const{ + if (!m_cells.contains(pos) || !m_cells.at(pos).covered){ + return nullptr; + } + return &m_cells.at(pos); +} +StoryWorld::Cell* StoryWorld::cell(const TilePos& pos){ + if (!m_cells.contains(pos) || !m_cells.at(pos).covered){ + return nullptr; + } + return &m_cells.at(pos); +} + + +bool StoryWorld::covered(const TilePos& pos) const{ + return cell(pos) != nullptr; +} + +std::optional StoryWorld::tile(const TilePos& pos) const{ + const Cell* found = cell(pos); + if (found == nullptr){ + return std::nullopt; + } + return found->tile; +} + +bool StoryWorld::occupied(const TilePos& pos) const{ + const Cell* found = cell(pos); + return found != nullptr && found->occupied; +} + +bool StoryWorld::standable(const TilePos& pos) const{ + const Cell* found = cell(pos); + return found != nullptr && !found->occupied && + (found->tile == TileKind::OPEN || found->tile == TileKind::TALL_GRASS); +} + +std::optional StoryWorld::step(const TilePos& from, Direction direction) const{ + const TilePos next = from.next(direction); + if (standable(next)){ + return next; + } + const Cell* found = cell(next); + if (found == nullptr || found->occupied || ledge_direction(found->tile) != direction){ + return std::nullopt; + } + const TilePos landing = next.next(direction); + if (standable(landing)){ + return landing; + } + return std::nullopt; +} + +bool StoryWorld::at_wall(const TilePos& pos, Direction direction) const{ + const std::optional next = tile(pos.next(direction)); + return next && *next != TileKind::DOOR && !step(pos, direction).has_value(); +} + +void StoryWorld::block(const TilePos& pos){ + if (Cell* found = cell(pos)){ + found->occupied = true; + m_blocked.push_back(pos); + } +} + +void StoryWorld::uncover(const TilePos& pos){ + if (Cell* found = cell(pos)){ + found->covered = false; + m_uncovered.push_back(pos); + } +} + + +TilePos StoryWorld::to_world(const std::string& map, const TilePos& local) const{ + for (const Placed& placed : m_maps){ + if (placed.name == map){ + return {placed.offset.x - m_origin.x + local.x, placed.offset.y - m_origin.y + local.y}; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown map: " + map); +} + +std::optional StoryWorld::to_local(const TilePos& world) const{ + for (const Placed& placed : m_maps){ + const TilePos local{world.x + m_origin.x - placed.offset.x, world.y + m_origin.y - placed.offset.y}; + if (placed.tiles.contains(local)){ + return MapTile{placed.name, local}; + } + } + return std::nullopt; +} + +std::string StoryWorld::describe(const TilePos& world) const{ + const std::optional local = to_local(world); + if (!local){ + return "world " + Pokemon::to_string(world); + } + return local->map + " " + Pokemon::to_string(local->pos); +} + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h new file mode 100644 index 0000000000..236e1972b2 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -0,0 +1,112 @@ +/* BDSP AutoStory - Story world + * + * From: https://github.com/PokemonAutomation/ + * + * Several story maps placed side by side on one world grid, so one plan can + * cross from a route into a town. What the tiles mean for walking in BDSP: + * open ground and tall grass are stood on; a ledge is hopped the arrow's + * way; walls, water and signs stop the player; a door is walked into. A + * person or an item standing still blocks their tile; a wanderer does not + * (the walker waits for them). Tiles no map covers are off the maps: a + * plan may not end there, but walking into one is not a wall, since it may + * be an exit. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryWorld_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryWorld_H + +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "Pokemon/Navigation/Pokemon_MapData.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// A tile of one of the maps, in that map's own coordinates. +struct MapTile{ + std::string map; + Pokemon::TilePos pos; +}; + + +class StoryWorld{ +public: + // Places `map` under `name` with its tile (0,0) at `offset`. Offsets are + // relative to each other and may be negative. Maps may overlap only + // where both are walls with nobody on them; the map placed first holds + // those tiles. Throws InternalProgramError if the name is taken or the + // maps conflict. World tile (0,0) is the top-left corner of all the + // maps together. + void add(std::string name, const Pokemon::MapData& map, const Pokemon::TilePos& offset); + + int width() const{ return m_cells.width; } + int height() const{ return m_cells.height; } + + // Whether a map holds this world tile. + bool covered(const Pokemon::TilePos& pos) const; + // The tile, or nothing off the maps. + std::optional tile(const Pokemon::TilePos& pos) const; + // Whether someone or something stands still on this tile, or it was + // blocked with block(). + bool occupied(const Pokemon::TilePos& pos) const; + + // Whether the player can stand on this tile. + bool standable(const Pokemon::TilePos& pos) const; + // Where one step from `from` lands, or nothing if the player is stopped. + // A step onto a ledge the arrow's way hops to the tile past it. + std::optional step(const Pokemon::TilePos& from, Pokemon::Direction direction) const; + // Whether a step from `pos` is refused by a tile that holds the player + // in place. Doors and tiles off the maps are not walls: walking into a + // door enters the building, and ground off the maps may be an exit. + bool at_wall(const Pokemon::TilePos& pos, Pokemon::Direction direction) const; + + // Blocks a tile found in the way on the console. Tiles off the maps + // are left alone. + void block(const Pokemon::TilePos& pos); + // Takes a tile off the maps: a tile a walk must not cross or stop on + // that the game lets us walk (a trainer's line of sight). + void uncover(const Pokemon::TilePos& pos); + + // Throws InternalProgramError for a map name it does not have. + Pokemon::TilePos to_world(const std::string& map, const Pokemon::TilePos& local) const; + // The map that holds a world tile, or nothing between maps. + std::optional to_local(const Pokemon::TilePos& world) const; + // "Route 201 (45, 3)", or "world (x, y)" if no map holds it. + std::string describe(const Pokemon::TilePos& world) const; + +private: + struct Placed{ + std::string name; + Pokemon::Grid tiles; + std::vector occupied; // local tiles + Pokemon::TilePos offset; + }; + struct Cell{ + bool covered = false; + Pokemon::TileKind tile = Pokemon::TileKind::WALL; + bool occupied = false; + }; + + void check_overlap(const std::string& name, const Placed& map) const; + void rebuild(); + const Cell* cell(const Pokemon::TilePos& pos) const; + Cell* cell(const Pokemon::TilePos& pos); + + std::vector m_maps; + Pokemon::TilePos m_origin; // offset of world tile (0,0) + Pokemon::Grid m_cells; + std::vector m_blocked; // world tiles, kept across add() + std::vector m_uncovered; +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp deleted file mode 100644 index b7d0f60bb6..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* BDSP AutoStory - Twinleaf Town tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_TwinleafTown.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace TwinleafTown{ - -using namespace Pokemon; - - -// Map source: the decomp (Diamond land_data 0000 = Platinum map_data_000, -// 2026-10-31) with the objects from its events file. -// Console checks: none yet. -// 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_0000: one cell of the -// Sinnoh matrix at column 3, row 27; map_data_000 in pret/pokeplatinum), -// with the objects from its events file (zone_event narc_0389, -// events_twinleaf_town.json in Platinum); BDSP keeps Diamond/Pearl's layout. -// Local (x, y) = world (x - 96, z - 864); 32 x 32 tiles. The pond at the -// bottom, (12..19, 27..31), is water, '#'. The pockets (7..10, 1..2) and -// (21..24, 1..2) are walkable in the data but closed in. -// Exit: Route 201 north through columns 12 to 19 at row 0 (the route's -// bottom rows open the same eight columns). The player's house is the -// south-east one, door (20, 21), and Barry's the north-west one, door (9, -// 11): behind (20, 21) the interior has Mom and the TV, behind (9, 11) only -// Barry's mother, and Platinum's scripts name the mailbox at (18, 21) the -// player's. pret/pokediamond's map constants call them the other way round -// (MAP_TWINLEAF_PLAYER_HOUSE_1F is the house behind (9, 11)); the interiors -// say otherwise. Objects, from the events file: -// door (20, 21), the player's house; its mailbox (18, 21), read like a -// sign, 'S'; -// door (9, 11), Barry's house; its mailbox (13, 11), 'S'; Barry himself -// stands on the door tile at the start (looks south, hidden by flag 402): -// the door keeps its 'D'; -// door (20, 11) to the north-east house; door (10, 21) to the south-west -// house; -// map signpost (16, 14); -// Guitarist (12, 5), looks north, west and east, not a trainer; -// Collector (12, 25), looks around, not a trainer; -// Pokemon Breeder F wanders around (23, 14), columns 22 to 24, row 14: off -// the grid. -// No trainers. Platinum decodes the same terrain and objects; its one extra, -// an arrow signpost at world (109, 856), stands in Route 201's cell. -const TileGrid& grid(){ - return story_grid("TwinleafTown"); -} - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h deleted file mode 100644 index 7e4de02893..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h +++ /dev/null @@ -1,27 +0,0 @@ -/* BDSP AutoStory - Twinleaf Town tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see - * the .cpp's header for the cells, the offset and the objects. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_TwinleafTown_H -#define PokemonAutomation_PokemonBDSP_AutoStory_TwinleafTown_H - -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace TwinleafTown{ - - -const Pokemon::TileGrid& grid(); - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp deleted file mode 100644 index a696281964..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* BDSP AutoStory - Verity Lakefront tiles - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_MapGrids.h" -#include "PokemonBDSP_AutoStory_VerityLakefront.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace VerityLakefront{ - -using namespace Pokemon; - - -// Map source: the decomp (Diamond land_data 0004 = Platinum map_data_004, -// 2026-10-31) with the objects from its events file. -// Console checks: none yet. -// 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_0004: one cell of the -// Sinnoh matrix at column 2, row 26; map_data_004 in pret/pokeplatinum), -// with the objects from its events file (zone_event narc_0319, -// events_verity_lakefront.json in Platinum); BDSP keeps Diamond/Pearl's -// layout. Local (x, y) = world (x - 64, z - 832); 32 x 32 tiles. The map -// header covers four cells (columns 1 and 2, rows 25 and 26); the other -// three are trees and an 8 x 8 patch of shallow water, so only this one is -// kept. The pocket (0..3, 0..3) is that water (puddle, behaviour 0x16), -// closed in. -// Route 201's west edge is this cell's column 31: open on rows 14 to 18 (the -// upper level) and 20 to 23 (the lower), with Route 201's x = 96 at our x = -// 32. From the upper level the way west is over the ledge at column 20 (rows -// 14 to 18, jumped west, shown as a wall), landing on columns 14 to 19; the -// lower level joins it at (16..19, 20). The ledges on row 19, 'v', drop -// south onto the lower level. The lake's entrance is the warp tiles (16, 11) -// and (17, 11), walked onto heading north, written as '.'; their destination -// is Lake Verity, or its Galactic version once that story state is set. -// Objects, from the events file: -// arrow signpost (15, 14), beside the path to the lake; -// Barry (16, 11), looks south, hidden by flag 435, standing on the warp -// tile: '.' wins; -// no one else, and no trainers. -// Platinum decodes the same terrain; it has no Barry object here and calls -// the sign a trainer-tips signpost. -const TileGrid& grid(){ - return story_grid("VerityLakefront"); -} - -} -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.h deleted file mode 100644 index 3ededdc534..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_VerityLakefront.h +++ /dev/null @@ -1,27 +0,0 @@ -/* BDSP AutoStory - Verity Lakefront tiles - * - * From: https://github.com/PokemonAutomation/ - * - * Decoded from the Pokemon Diamond decompilation (pret/pokediamond); see - * the .cpp's header for the cells, the offset and the objects. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_VerityLakefront_H -#define PokemonAutomation_PokemonBDSP_AutoStory_VerityLakefront_H - -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace VerityLakefront{ - - -const Pokemon::TileGrid& grid(); - - -} -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp deleted file mode 100644 index a42684c862..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp +++ /dev/null @@ -1,256 +0,0 @@ -/* BDSP AutoStory Map Grid Tests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/Json/JsonValue.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "CommonFramework/ImageTypes/ImageViewRGB32.h" -#include "Pokemon/Navigation/Pokemon_MapSet.h" -#include "Pokemon/Navigation/Pokemon_TileGrid.h" -#include "Data/PokemonBDSP_AutoStory_MapGrids.h" -#include "Data/PokemonBDSP_AutoStory_Route202.h" -#include "Data/PokemonBDSP_AutoStory_SandgemTown.h" -#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" -#include "Data/PokemonBDSP_AutoStory_PlanCosts.h" -#include "PokemonBDSP_AutoStory_MapGrid_Tests.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ - - -namespace{ - -using Pokemon::Direction; -using Pokemon::MapSet; -using Pokemon::TileGrid; -using Pokemon::TilePos; -using Pokemon::TileType; - -// 00.04's training walks up and down the catch patch, three grass rows -// between tree rows, and needs the walk there to end in its grass: r253 -// and r254 loaded the catch's save in the pocket behind the trees at -// (21, 29), planned from the catch spot instead, and walked up and down -// the lawn east of the grass for three minutes without a battle. -class Test_Route202CatchGrass : public UnitTest{ -public: - Test_Route202CatchGrass() - : UnitTest("PokemonBDSP::AutoStory - Route 202: the catch patch and the walk to it") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ - const TileGrid& route = Route202::grid(); - for (int x = 15; x <= 20; x++){ - const Pokemon::WallHit up = Pokemon::walk_to_wall(route, {x, 27}, Direction::NORTH); - const Pokemon::WallHit down = Pokemon::walk_to_wall(route, {x, 25}, Direction::SOUTH); - if (!(up.stop == TilePos{x, 25}) || !(down.stop == TilePos{x, 27})){ - return "Catch patch column " + std::to_string(x) + ": north from row 27 stops at " + - Pokemon::to_string(up.stop) + ", south from row 25 at " + Pokemon::to_string(down.stop) + - "; expected rows 25 and 27, between tree rows."; - } - } - const MapSet& maps = story_maps(); - const std::vector area = story_after_training_area(); - const auto in_grass = [&](const TilePos& pos){ - return maps.world().at(pos) == TileType::TALL_GRASS && std::find(area.begin(), area.end(), pos) != area.end(); - }; - // As walk_route() plans: the route costs, else the default costs. - // From the whole area the catch's save may stand in, and from the - // pocket behind the trees alone, where r252 saved. - const TilePos pocket = maps.to_world(MAP_ROUTE_202, {21, 29}); - const std::vector>> starts{ - {"the catch's save area", story_catch_save_area()}, - {"the pocket behind the trees", {pocket}}, - }; - std::optional> legs; - for (const auto& [name, from] : starts){ - legs = Pokemon::plan_robust_route(maps.world(), from, in_grass, route_plan_costs()); - if (!legs){ - legs = Pokemon::plan_robust_route(maps.world(), from, in_grass, Pokemon::RobustPlanCosts()); - } - if (!legs || legs->empty()){ - return "From " + name + " to the catch grass: no plan."; - } - for (const TilePos& pos : legs->back().after){ - if (!in_grass(pos)){ - return "From " + name + " to the catch grass: the walk may end on " + maps.describe(pos) + ", not in the grass."; - } - } - logger.log("From " + name + " to the catch grass: " + std::to_string(legs->size()) + " legs, ending in the grass."); - } - return true; - } -}; - -// 00.04's way to Sandgem's Pokemon Center ends below the Center's sign, -// walking north into it, then taps west along the doors' row to below the -// door: the row must be open there, the door straight north of where the -// taps end, and nothing else (a sign, the Mart's door) on the way. -class Test_SandgemCenterApproach : public UnitTest{ -public: - Test_SandgemCenterApproach() - : UnitTest("PokemonBDSP::AutoStory - Sandgem Town: below the Center's sign to below its door") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ - const TileGrid& town = SandgemTown::grid(); - const TilePos sign = SandgemTown::POKEMON_CENTER_SIGN; - const TilePos door = SandgemTown::POKEMON_CENTER_DOOR; - if (town.at(sign) != TileType::SIGN || town.at(door) != TileType::DOOR || door.y != sign.y || door.x >= sign.x){ - return "The Center's sign " + Pokemon::to_string(sign) + " and door " + Pokemon::to_string(door) + - " are not a sign and a door west of it on one row."; - } - TilePos pos = sign.next(Direction::SOUTH); - for (int tap = 0; tap < sign.x - door.x; tap++){ - const std::optional next = town.step(pos, Direction::WEST); - if (!next){ - return "West from " + Pokemon::to_string(pos) + " is blocked."; - } - if (town.at(next->next(Direction::NORTH)) != TileType::BLOCKED && *next != door.next(Direction::SOUTH)){ - return "Above " + Pokemon::to_string(*next) + " is not the Center's wall."; - } - pos = *next; - } - if (!(pos == door.next(Direction::SOUTH))){ - return "The taps end at " + Pokemon::to_string(pos) + ", not below the door " + Pokemon::to_string(door) + "."; - } - logger.log("Sandgem: below the sign " + Pokemon::to_string(sign.next(Direction::SOUTH)) + ", " + - std::to_string(sign.x - door.x) + " taps west to below the door " + Pokemon::to_string(door) + "."); - return true; - } -}; - -// After training, 00.04 walks from wherever the training left us into -// Sandgem, to where the road stops above the Mart, with the default costs -// (heal_at_sandgem_center()): from the whole area and from each of its -// tiles alone, a plan must exist and end there. -class Test_TrainingToSandgem : public UnitTest{ -public: - Test_TrainingToSandgem() - : UnitTest("PokemonBDSP::AutoStory - Route 202: from every tile of the training area into Sandgem") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ - const MapSet& maps = story_maps(); - const TilePos entry = maps.to_world(MAP_SANDGEM_TOWN, SandgemTown::ROUTE_202_ENTRY_STOP); - const std::vector area = story_after_training_area(); - std::vector> starts{area}; - for (const TilePos& pos : area){ - starts.push_back({pos}); - } - for (const std::vector& from : starts){ - const auto legs = Pokemon::plan_robust_route(maps.world(), from, - [&](const TilePos& pos){ return pos == entry; }, Pokemon::RobustPlanCosts()); - const std::string name = from.size() == 1 ? maps.describe(from[0]) : "the whole training area"; - if (!legs || legs->empty()){ - return "From " + name + " into Sandgem: no plan."; - } - if (legs->back().after.size() != 1 || !(legs->back().after[0] == entry)){ - return "From " + name + " into Sandgem: the plan does not end on " + maps.describe(entry) + "."; - } - logger.log("From " + name + " into Sandgem: " + std::to_string(legs->size()) + " legs."); - } - return true; - } -}; - -// The maps (the JSON files built in, bdsp_map_json()) all parse through -// the shared loader into tile grids, each named as its file. -class Test_BuiltInMaps : public UnitTest{ -public: - Test_BuiltInMaps() - : UnitTest("PokemonBDSP::AutoStory - Map grids: the built-in JSON maps load") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ - if (bdsp_map_json().empty()){ - return std::string("No built-in maps."); - } - for (const auto& [name, json] : bdsp_map_json()){ - try{ - const TileGrid& grid = story_grid(name); - logger.log(std::format("{}: {} x {}", name, grid.width(), grid.height())); - }catch (Exception& e){ - return std::format("{}: {}: {}", name, e.name(), e.message()); - } - } - return true; - } -}; - -// The JSON glyphs as BDSP tiles: every BDSP tile and a person standing; -// water and a wanderer have none. -struct GlyphCase{ - std::string name; - std::string json; - // The grid's rows, or empty when reading it must throw. - std::vector rows; -}; - -class Test_MapGlyphs : public UnitTest{ -public: - Test_MapGlyphs() - : UnitTest("PokemonBDSP::AutoStory - Map grids: JSON glyphs as tile grids") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const std::vector cases{ - { - .name = "every BDSP tile, and a person standing", - .json = R"({"name": "T", "source": {"decomp_file": "f", "revision": "r", "date": "d"}, - "tiles": ["#.~", "vDS"], - "objects": [{"name": "npc_1_0", "kind": "npc", "x": 1, "y": 0}]})", - .rows = {"#N\"", "vDS"}, - }, - { - .name = "water has no BDSP tile", - .json = R"({"name": "T", "source": {"decomp_file": "f", "revision": "r", "date": "d"}, "tiles": ["#w"]})", - .rows = {}, - }, - { - .name = "a wanderer has no BDSP tile", - .json = R"({"name": "T", "source": {"decomp_file": "f", "revision": "r", "date": "d"}, "tiles": ["#.."], - "objects": [{"name": "lass", "kind": "npc", "x": 1, "y": 0, "wander": {"x0": 1, "y0": 0, "x1": 2, "y1": 0}}]})", - .rows = {}, - }, - }; - for (const GlyphCase& item : cases){ - std::optional grid; - std::string error; - try{ - grid = tile_grid_from_map(Pokemon::parse_map(parse_json(item.json), item.name)); - }catch (ParseException& e){ - error = e.message(); - } - if (item.rows.empty() != !grid){ - return item.name + (grid ? ": read a grid, expected a ParseException." : ": expected a grid, read: " + error); - } - if (grid){ - if (const std::optional difference = grid_difference(*grid, TileGrid(item.rows))){ - return item.name + ": differs from the expected rows at " + *difference + "."; - } - } - } - return true; - } -}; - -} - - -void add_tests_AutoStory_MapGrids(UnitTestDatabase& database){ - database.add(); - database.add(); - database.add(); - database.add(); - database.add(); -} - - -} -} -} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h deleted file mode 100644 index a7f7250b2b..0000000000 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h +++ /dev/null @@ -1,28 +0,0 @@ -/* BDSP AutoStory Map Grid Tests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_MapGrid_Tests_H -#define PokemonAutomation_PokemonBDSP_AutoStory_MapGrid_Tests_H - -#include "Common/Cpp/TestRunners/UnitTest.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ - - - -// Offline checks of the decomp grids against what the console showed: -// Route 202's catch patch between tree rows and the walks in and out of -// it, and Sandgem's Pokemon Center door, its sign and the row below them. -void add_tests_AutoStory_MapGrids(UnitTestDatabase& database); - - - -} -} -} -#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp new file mode 100644 index 0000000000..ea74104879 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp @@ -0,0 +1,195 @@ +/* BDSP AutoStory Route Planner Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The route planner (Data/PokemonBDSP_AutoStory_RoutePlanner.h) on small + * synthetic maps: walks to a wall, plans that end on walls, robust plans + * that bring several possible tiles together, and trainers' sight lines. + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Data/PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP_AutoStory_RoutePlanner_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +using Pokemon::Direction; +using Pokemon::TilePos; + +StoryWorld make_world(const std::vector& rows){ + Pokemon::MapData map; + map.name = "Test"; + map.tiles = Pokemon::Grid{(int)rows[0].size(), (int)rows.size(), {}}; + for (const std::string& row : rows){ + for (char glyph : row){ + map.tiles.cells.push_back(*Pokemon::tile_from_glyph(glyph)); + } + } + StoryWorld world; + world.add("Test", map, {0, 0}); + return world; +} + +std::string describe(const std::vector& legs){ + std::string text; + for (const PlannedLeg& leg : legs){ + text += (text.empty() ? "" : "; ") + to_string(leg); + } + return text; +} + + +struct WallCase{ + std::string name; + std::vector rows; + TilePos from; + Direction direction = Direction::EAST; + TilePos stop; + size_t tiles = 0; + bool anchored = false; +}; + +class Test_WalkToWall : public UnitTest{ +public: + Test_WalkToWall() + : UnitTest("PokemonBDSP::AutoStory - Route planner: walking until stopped") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::vector cases{ + {.name = "to a wall", .rows = {"....#"}, .stop = {3, 0}, .tiles = 3, .anchored = true}, + {.name = "off the map", .rows = {"...."}, .stop = {3, 0}, .tiles = 3, .anchored = false}, + {.name = "into a door", .rows = {"..D"}, .stop = {1, 0}, .tiles = 1, .anchored = false}, + {.name = "over a ledge, which counts 2", .rows = {".", "v", ".", "#"}, .direction = Direction::SOUTH, + .stop = {0, 2}, .tiles = 2, .anchored = true}, + }; + for (const WallCase& item : cases){ + const WallHit hit = walk_to_wall(make_world(item.rows), item.from, item.direction); + if (!(hit.stop == item.stop) || hit.tiles != item.tiles || hit.anchored != item.anchored){ + return std::format("{}: stops at {} after {} tiles, anchored {}; expected {} after {}, anchored {}.", item.name, + Pokemon::to_string(hit.stop), hit.tiles, hit.anchored, Pokemon::to_string(item.stop), item.tiles, item.anchored); + } + } + return true; + } +}; + + +// plan_tile_route() around a pillar: two legs, both to a wall, that trace +// to the goal. +class Test_PlanTileRoute : public UnitTest{ +public: + Test_PlanTileRoute() + : UnitTest("PokemonBDSP::AutoStory - Route planner: legs to walls around a pillar") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const StoryWorld world = make_world({"#####", "#...#", "#.#.#", "#...#", "#####"}); + const std::optional> legs = plan_tile_route(world, {1, 1}, {3, 3}); + if (!legs || legs->size() != 2 || !(*legs)[0].ends_at_wall || !(*legs)[1].ends_at_wall){ + return std::string("Expected two legs, both to a wall."); + } + if (!(trace_legs(world, {1, 1}, *legs).back() == TilePos{3, 3})){ + return std::string("The legs do not end on (3, 3)."); + } + logger.log(std::format("{}, {}", to_string((*legs)[0]), to_string((*legs)[1]))); + const std::optional> none = plan_tile_route(world, {1, 1}, {1, 1}); + if (!none || !none->empty()){ + return std::string("A route to the start is not empty."); + } + return true; + } +}; + + +// plan_robust_route() from one or several tiles to a goal, with the open +// legs' error as the costs give it. +struct RobustCase{ + std::string name; + std::vector from; + TilePos goal; + RobustPlanCosts costs; + // The plan as to_string() writes it, or empty when there is none. + std::string legs; +}; + +class Test_PlanRobustRoute : public UnitTest{ +public: + Test_PlanRobustRoute() + : UnitTest("PokemonBDSP::AutoStory - Route planner: robust plans") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const StoryWorld world = make_world({"######", "#....#", "######"}); + RobustPlanCosts exact_step; + exact_step.exact_open_tiles = 1; + const std::vector cases{ + {.name = "two starts meet at the wall", .from = {{1, 1}, {2, 1}}, .goal = {4, 1}, .legs = "east 3 (to wall) to (4, 1)"}, + {.name = "an open stop is never sure", .from = {{1, 1}}, .goal = {3, 1}, .legs = ""}, + {.name = "unless a one-tile step is exact", .from = {{1, 1}}, .goal = {3, 1}, .costs = exact_step, + .legs = "east 3 (to wall) to (4, 1); west 1 (open) to (3, 1)"}, + }; + for (const RobustCase& item : cases){ + const auto legs = plan_robust_route(world, item.from, [&](const TilePos& pos){ return pos == item.goal; }, item.costs); + const std::string read = legs ? describe(*legs) : ""; + if (read != item.legs){ + return std::format("{}: planned \"{}\", expected \"{}\".", item.name, read, item.legs); + } + } + try{ + plan_robust_route(world, TilePos{0, 0}, TilePos{4, 1}); + return std::string("A start on a wall did not throw."); + }catch (InternalProgramError&){} + return true; + } +}; + + +// A trainer's sight stops at the first tile the player cannot stand on, +// and a leg through it is reported; a leg that is stopped throws. +class Test_TrainerSight : public UnitTest{ +public: + Test_TrainerSight() + : UnitTest("PokemonBDSP::AutoStory - Route planner: trainers' sight lines") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const StoryWorld world = make_world({".....", ".....", "..#.."}); + const TrainerSight trainer{.name = "lass", .pos = {2, 0}, .facing = Direction::SOUTH, .range = 4}; + if (sight_tiles(world, trainer) != std::vector{{2, 1}}){ + return std::string("The lass's sight is not the one tile above the rock."); + } + const std::vector legs{{Direction::EAST, 4, true}, {Direction::SOUTH, 1, false}}; + const auto crossings = legs_crossing_sight(world, {0, 1}, legs, {trainer}); + if (crossings != std::vector>{{"lass"}, {}}){ + return std::string("Only the first leg crosses the lass's sight."); + } + try{ + trace_legs(world, {0, 1}, {{Direction::SOUTH, 2, false}}); + return std::string("A leg off the map did not throw."); + }catch (InternalProgramError&){} + return true; + } +}; + +} + + +void add_tests_AutoStory_RoutePlanner(UnitTestDatabase& database){ + database.add(); + database.add(); + database.add(); + database.add(); +} + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h new file mode 100644 index 0000000000..526d0fe601 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h @@ -0,0 +1,24 @@ +/* BDSP AutoStory Route Planner Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RoutePlanner_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_RoutePlanner_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Offline checks of the route planner on synthetic maps. +void add_tests_AutoStory_RoutePlanner(UnitTestDatabase& database); + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp new file mode 100644 index 0000000000..66e345f140 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -0,0 +1,193 @@ +/* BDSP AutoStory Story World Tests + * + * From: https://github.com/PokemonAutomation/ + * + * StoryWorld on small synthetic maps: what each tile does to a step, maps + * joined at offsets, and tiles blocked or taken off the maps. + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Data/PokemonBDSP_AutoStory_StoryWorld.h" +#include "PokemonBDSP_AutoStory_StoryWorld_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +using Pokemon::Direction; +using Pokemon::MapData; +using Pokemon::TilePos; + +// A map of these rows, with a person standing still on each `standing` +// tile and one wandering on each `wandering` tile. +MapData make_map( + const std::vector& rows, + const std::vector& standing = {}, + const std::vector& wandering = {} +){ + MapData map; + map.name = "Test"; + map.tiles = Pokemon::Grid{(int)rows[0].size(), (int)rows.size(), {}}; + for (const std::string& row : rows){ + for (char glyph : row){ + map.tiles.cells.push_back(*Pokemon::tile_from_glyph(glyph)); + } + } + for (const TilePos& pos : standing){ + map.objects.push_back({.name = "standing", .x = pos.x, .y = pos.y}); + } + for (const TilePos& pos : wandering){ + map.objects.push_back({.name = "wandering", .x = pos.x, .y = pos.y, .wander = Pokemon::WanderBox{pos.x, pos.y, pos.x, pos.y}}); + } + return map; +} + +StoryWorld make_world(const MapData& map){ + StoryWorld world; + world.add("Test", map, {0, 0}); + return world; +} + + +// One step from (1, 1) of a 3 x 3 map whose middle tile (the step's +// target) is `target`, and whether the player is held at a wall there. +struct StepCase{ + std::string name; + std::vector rows; + std::vector standing; + std::vector wandering; + TilePos from; + Direction direction = Direction::NORTH; + std::optional lands; + bool at_wall = false; +}; + +class Test_StoryWorldSteps : public UnitTest{ +public: + Test_StoryWorldSteps() + : UnitTest("PokemonBDSP::AutoStory - Story world: what each tile does to a step") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::vector cases{ + {.name = "open ground", .rows = {".", "."}, .from = {0, 1}, .lands = TilePos{0, 0}}, + {.name = "tall grass", .rows = {"~", "."}, .from = {0, 1}, .lands = TilePos{0, 0}}, + {.name = "a wall", .rows = {"#", "."}, .from = {0, 1}, .at_wall = true}, + {.name = "water", .rows = {"w", "."}, .from = {0, 1}, .at_wall = true}, + {.name = "a sign", .rows = {"S", "."}, .from = {0, 1}, .at_wall = true}, + {.name = "a door is not a wall", .rows = {"D", "."}, .from = {0, 1}}, + {.name = "off the map is not a wall", .rows = {"."}, .from = {0, 0}}, + {.name = "a south ledge hops south", .rows = {".", "v", "."}, .direction = Direction::SOUTH, .lands = TilePos{0, 2}}, + {.name = "a south ledge stops north", .rows = {".", "v", "."}, .from = {0, 2}, .at_wall = true}, + {.name = "a west ledge hops west", .rows = {".<."}, .from = {2, 0}, .direction = Direction::WEST, .lands = TilePos{0, 0}}, + {.name = "a west ledge stops east", .rows = {".<."}, .direction = Direction::EAST, .at_wall = true}, + {.name = "a ledge onto a wall stops", .rows = {".", "v", "#"}, .direction = Direction::SOUTH, .at_wall = true}, + {.name = "a person standing still", .rows = {".", "."}, .standing = {{0, 0}}, .from = {0, 1}, .at_wall = true}, + {.name = "a wanderer does not block", .rows = {".", "."}, .wandering = {{0, 0}}, .from = {0, 1}, .lands = TilePos{0, 0}}, + }; + for (const StepCase& item : cases){ + const StoryWorld world = make_world(make_map(item.rows, item.standing, item.wandering)); + const std::optional lands = world.step(item.from, item.direction); + if (lands != item.lands){ + return std::format("{}: lands on {}, expected {}.", item.name, + lands ? Pokemon::to_string(*lands) : "nothing", item.lands ? Pokemon::to_string(*item.lands) : "nothing"); + } + if (world.at_wall(item.from, item.direction) != item.at_wall){ + return std::format("{}: at_wall() is {}, expected {}.", item.name, !item.at_wall, item.at_wall); + } + } + return true; + } +}; + + +// Two maps joined: tiles of each at their offsets, the gap between them +// off the maps, and a shared wall border allowed where nothing else is. +class Test_StoryWorldJoin : public UnitTest{ +public: + Test_StoryWorldJoin() + : UnitTest("PokemonBDSP::AutoStory - Story world: maps joined at offsets") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + StoryWorld world; + world.add("West", make_map({"##", ".#"}), {0, 0}); + world.add("East", make_map({"#.", "#~"}), {1, -1}); + const std::vector> described{ + {{0, 2}, "West (0, 1)"}, + {{2, 0}, "East (1, 0)"}, + {{1, 1}, "West (1, 0)"}, // the shared wall: the first map holds it + {{2, 2}, "world (2, 2)"}, + }; + for (const auto& [pos, text] : described){ + if (world.describe(pos) != text){ + return std::format("{}: described as \"{}\", expected \"{}\".", Pokemon::to_string(pos), world.describe(pos), text); + } + } + if (world.width() != 3 || world.height() != 3 || world.covered({2, 2}) || !world.standable({2, 1})){ + return std::string("The joined world is not 3 x 3 with East's grass at (2, 1) and nothing at (2, 2)."); + } + if (!(world.to_world("East", {0, 0}) == TilePos{1, 0})){ + return "East (0, 0) is world " + Pokemon::to_string(world.to_world("East", {0, 0})) + ", expected (1, 0)."; + } + try{ + world.add("Overlap", make_map({"."}), {0, 1}); + return std::string("Adding a map over open ground did not throw."); + }catch (InternalProgramError&){} + try{ + world.to_world("North", {0, 0}); + return std::string("to_world() of an unknown map did not throw."); + }catch (InternalProgramError&){} + return true; + } +}; + + +// block() and uncover() change what a tile does, and survive a map added +// later that moves the world's origin. +class Test_StoryWorldBlockUncover : public UnitTest{ +public: + Test_StoryWorldBlockUncover() + : UnitTest("PokemonBDSP::AutoStory - Story world: blocked and uncovered tiles") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + StoryWorld world; + world.add("Road", make_map({"...."}), {0, 0}); + world.block({1, 0}); + world.uncover({2, 0}); + if (world.step({0, 0}, Direction::EAST) || !world.at_wall({0, 0}, Direction::EAST)){ + return std::string("A blocked tile is not a wall."); + } + if (world.covered({2, 0}) || world.at_wall({3, 0}, Direction::WEST)){ + return std::string("An uncovered tile is still on the map, or a wall."); + } + world.add("North", make_map({"#"}), {0, -1}); + const TilePos blocked = world.to_world("Road", {1, 0}); + const TilePos uncovered = world.to_world("Road", {2, 0}); + if (!world.occupied(blocked) || world.covered(uncovered) || !world.standable(world.to_world("Road", {3, 0}))){ + return std::string("Adding a map lost the blocked or uncovered tile."); + } + return true; + } +}; + +} + + +void add_tests_AutoStory_StoryWorld(UnitTestDatabase& database){ + database.add(); + database.add(); + database.add(); +} + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h new file mode 100644 index 0000000000..0fee678878 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h @@ -0,0 +1,24 @@ +/* BDSP AutoStory Story World Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryWorld_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryWorld_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Offline checks of the story world: tile rules, joins, blocked and uncovered tiles. +void add_tests_AutoStory_StoryWorld(UnitTestDatabase& database); + + +} +} +} +#endif From dc74ccb247dc5e47260c5c31e8fc0ae0fd9c5862 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 13:37:44 -0800 Subject: [PATCH 04/18] BDSP navigation: the story code reads the JSON maps; the per-map grids go StoryMaps, RouteRecords, Segment00Lines and PlanCosts now place story_map()s in StoryWorlds and take their named tiles from map_point()/map_region(). The trainers' sight lists move from the per-map files into StoryMaps. Removed: the per-map Data files, MapGrids, MAPS.md (its rules are in devtools/maps/bdsp_maps.py), the old MapGrid tests, and the generic Pokemon_TileGrid and Pokemon_MapSet. The tests are split by topic: story world, route planner, story maps (with the route records traced on their maps) and Segment 00's lines. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Source/PokemonBDSP/PokemonBDSP_Tests.cpp | 8 +- .../Data/PokemonBDSP_AutoStory_PlanCosts.cpp | 1 - .../Data/PokemonBDSP_AutoStory_PlanCosts.h | 10 +- .../PokemonBDSP_AutoStory_RouteRecords.cpp | 376 ++++++------ .../Data/PokemonBDSP_AutoStory_RouteRecords.h | 134 ++--- .../PokemonBDSP_AutoStory_Segment00Lines.cpp | 301 +++++----- .../PokemonBDSP_AutoStory_Segment00Lines.h | 157 +++-- .../Data/PokemonBDSP_AutoStory_StoryMaps.cpp | 555 ++++++++++-------- .../Data/PokemonBDSP_AutoStory_StoryMaps.h | 238 ++++---- .../PokemonBDSP_AutoStory_Segment00_Tests.cpp | 481 +++++++-------- .../PokemonBDSP_AutoStory_Segment00_Tests.h | 4 +- .../PokemonBDSP_AutoStory_StoryMaps_Tests.cpp | 251 ++++++++ .../PokemonBDSP_AutoStory_StoryMaps_Tests.h | 24 + SerialPrograms/cmake/SourceFiles.cmake | 70 +-- 14 files changed, 1424 insertions(+), 1186 deletions(-) create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp index 6f2d10925a..847692b532 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp @@ -5,9 +5,11 @@ */ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h" #include "Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.h" +#include "Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h" #include "Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h" +#include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h" +#include "Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h" #include "PokemonBDSP_Tests.h" namespace PokemonAutomation{ @@ -18,7 +20,9 @@ namespace PokemonBDSP{ void add_tests(UnitTestDatabase& database){ add_tests_AutoStory_Maps(database); - add_tests_AutoStory_MapGrids(database); + add_tests_AutoStory_StoryWorld(database); + add_tests_AutoStory_RoutePlanner(database); + add_tests_AutoStory_StoryMaps(database); add_tests_AutoStory_Segment00(database); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp index 1593266d18..ce7b7bc124 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp @@ -10,7 +10,6 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonBDSP{ -using Pokemon::RobustPlanCosts; RobustPlanCosts route_plan_costs(){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h index 825ef24312..7608e59c9e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h @@ -3,7 +3,7 @@ * From: https://github.com/PokemonAutomation/ * * The costs the story's walks are planned with on the BDSP maps - * (Pokemon::plan_robust_route()), apart from the walker, so the map + * (plan_robust_route()), apart from the walker, so the map * tests plan each walk the way the program does. * */ @@ -11,7 +11,7 @@ #ifndef PokemonAutomation_PokemonBDSP_AutoStory_PlanCosts_H #define PokemonAutomation_PokemonBDSP_AutoStory_PlanCosts_H -#include "Pokemon/Navigation/Pokemon_TileGrid.h" +#include "PokemonBDSP_AutoStory_RoutePlanner.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -21,14 +21,14 @@ namespace PokemonBDSP{ // The default: open legs are whole tiles on the D-pad, so they land exactly // at any length; a wall at a leg's end is still worth a little, and each // open tile a little more. -Pokemon::RobustPlanCosts route_plan_costs(); +RobustPlanCosts route_plan_costs(); // Between two corners of a walked line: whole tiles on the D-pad land // exactly, so an open leg costs nothing extra and the straight leg to the // corner beats a run to a wall and a tap back (r244a: "west 10 to the // wall, east 1" through the wandering Youngster lost the count; "west 9" // in taps keeps it). -Pokemon::RobustPlanCosts waypoint_plan_costs(); +RobustPlanCosts waypoint_plan_costs(); // In town: a one-tile step lands exactly, a short open leg a tile either // way, and both cost little more than a leg to a wall, so a plan steps a @@ -36,7 +36,7 @@ Pokemon::RobustPlanCosts waypoint_plan_costs(); // town to end every leg on a wall (Sandgem: 13 legs, r127a and r128b // walked into the Lab and the Mart). Pair it with a check at the end (a // sign read) for the timed legs. -Pokemon::RobustPlanCosts town_plan_costs(); +RobustPlanCosts town_plan_costs(); 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 fc0c0b7b61..9736436658 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp @@ -1,199 +1,177 @@ -/* BDSP AutoStory - Route records - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_RouteRecords.h" -#include "PokemonBDSP_AutoStory_JubilifeCity.h" -#include "PokemonBDSP_AutoStory_Route201.h" -#include "PokemonBDSP_AutoStory_Route203.h" -#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{ -namespace PokemonBDSP{ -namespace RouteRecords{ - -using namespace Pokemon; - -namespace{ -const TileGrid* twinleaf(){ return &TwinleafTown::grid(); } -const TileGrid* route201(){ return &Route201::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(); } - -// 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, true, Segment00Lines::ROUTE_201_ARRIVAL, { - {Direction::NORTH, 6, LegEnd::COUNT, "up the exit path to (15, 18): Barry's warning fires on that row"}, - {Direction::WEST, 3, LegEnd::COUNT, "after the scene, along row 18 to column 12"}, - {Direction::NORTH, 2, LegEnd::COUNT, "to row 16, the lower level's row to the Lakefront"}, - {Direction::WEST, 12, LegEnd::COUNT, "to (0, 16), 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 Route201::grid(), the decomp's since #111"}, - {"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"}, - }; -} - -// 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, true, Segment00Lines::ROUTE_201_RETURN, { - {Direction::EAST, 5, LegEnd::COUNT, "to (5, 14): Rowan and Dawn's scene fires on that column"}, - {Direction::EAST, 12, LegEnd::COUNT, "after the scene, along row 14 to column 17"}, - {Direction::EAST, 12, LegEnd::COUNT, "through the tall grass to column 29; the Breeder wanders rows 14 to 16 there"}, - {Direction::EAST, 12, LegEnd::COUNT, "to column 41"}, - {Direction::NORTH, 7, LegEnd::COUNT, "up column 41 to row 7, beside the north-east grass"}, - {Direction::EAST, 1, LegEnd::COUNT, "into the grass"}, - {Direction::NORTH, 2, LegEnd::COUNT, "to row 5"}, - {Direction::EAST, 10, LegEnd::COUNT, "through the grass to (52, 5), its last tile"}, - {Direction::EAST, 11, LegEnd::COUNT, "to (63, 5), 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::grid()"}, - {"00.03", "Sandgem Town: Dawn at the entrance", "Sandgem Town", sandgem, true, Segment00Lines::SANDGEM_ARRIVAL, { - {Direction::EAST, 4, LegEnd::COUNT, "along row 12 to (4, 12): 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; on Sandgem'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, true, 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}, - {Direction::NORTH, 16, LegEnd::COUNT, "stick 3960 ms: up to the street east to Route 203", false}, - {Direction::SOUTH, 2, LegEnd::COUNT, "stick 600 ms: back onto the street", false}, - {Direction::EAST, 0, LegEnd::NPC, "along the street onto Route 203 until Barry stops us; rows retried 0, +1, +1, -3, -1 when a wall comes first"}, - }, "jubilife_to_barry(); stick holds from the console, 2026-10-29, counted in tiles on the image grid's 3/4 rows: recount in taps before giving this record a start tile (task #21)"}, - {"01.02", "Barry to Oreburgh City through the Oreburgh Gate", "Route 203", route203, true, std::nullopt, { - {Direction::EAST, 0, LegEnd::WALL, "along the row Barry stopped us on"}, - {Direction::NORTH, 0, LegEnd::WALL, "to the top wall, then a row south at a time until east goes on (up to ten)"}, - {Direction::EAST, 0, LegEnd::NPC, "to the Hiker"}, - {Direction::EAST, 0, LegEnd::TRANSITION, "into the Oreburgh Gate"}, - {Direction::EAST, 0, LegEnd::TRANSITION, "through the Gate into Oreburgh City"}, - }, "route203_to_oreburgh(); no start tile: Barry stops us on whichever row we came along"}, - {"01.04", "Oreburgh Pokemon Center doorstep to the Gym", "Oreburgh City", oreburgh_city, true, OreburghCity::POKEMON_CENTER_DOORSTEP, { - {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", "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"}, - {Direction::NORTH, 0, LegEnd::WALL, "along the cliff"}, - {Direction::EAST, 2, LegEnd::COUNT, "to the stairs' column"}, - {Direction::NORTH, 0, LegEnd::WALL, "up the stairs"}, - {Direction::WEST, 0, LegEnd::WALL, "along the platform"}, - {Direction::SOUTH, 1, LegEnd::COUNT, "onto the Gate's row"}, - {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, true, 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"}, - }, "jubilife_to_rowan(); by hand 2026-10-31 (18 presses), r230b; the stick hold's count was taken on the image grid's 3/4 rows, so no start tile yet"}, - {"01.08", "Jubilife's north street onto Route 204", "Jubilife City", jubilife, true, std::nullopt, { - {Direction::NORTH, 0, LegEnd::BANNER, "up the street until Route 204's banner; the planned walk to the Ravaged Path door follows"}, - }, "jubilife_to_ravaged_path() step 1"}, - {"01.09", "Ravaged Path's east end out onto Route 204 North", "Ravaged Path", ravaged_path, true, RavagedPath::EAST_END, { - {Direction::WEST, 1, LegEnd::COUNT, "onto the tile above the way out"}, - {Direction::SOUTH, 0, LegEnd::TRANSITION, "out of the cave"}, - }, "ravaged_path() exit; the planned legs before it are tested as plans"}, - {"01.10", "Route 204 North's path into Floaroma", "Route 204 North", route204_north, true, TilePos{11, 5}, { - {Direction::NORTH, 0, LegEnd::BANNER, "from (11, 5) until Floaroma Town's banner; the waypoint line before it is tested as plans"}, - }, "route204_to_floaroma(); r248a"}, - {"01.11", "Floaroma's old couple", "Floaroma Town", floaroma, true, FloaromaTown::ROUTE_204_ARRIVAL, { - {Direction::WEST, 8, LegEnd::COUNT, "D-pad taps along the flower field's bottom row"}, - {Direction::NORTH, 0, LegEnd::NPC, "until the old woman stops us (3 tiles on r251a)"}, - {Direction::WEST, 1, LegEnd::COUNT, "below the old man"}, - {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; -} - - -} -} -} -} +/* BDSP AutoStory - Route records + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP_AutoStory_RouteRecords.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace RouteRecords{ + +using namespace Pokemon; + +namespace{ + +// 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", "TwinleafTown", true, map_point("TwinleafTown", "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", "TwinleafTown", true, map_point("TwinleafTown", "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", true, map_point("Route201", "route_201_arrival"), { + {Direction::NORTH, 6, LegEnd::COUNT, "up the exit path to (15, 18): Barry's warning fires on that row"}, + {Direction::WEST, 3, LegEnd::COUNT, "after the scene, along row 18 to column 12"}, + {Direction::NORTH, 2, LegEnd::COUNT, "to row 16, the lower level's row to the Lakefront"}, + {Direction::WEST, 12, LegEnd::COUNT, "to (0, 16), 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 Route201 map, the decomp's since #111"}, + {"00.01", "Verity Lakefront: to below the lake's entrance", "Verity Lakefront", "VerityLakefront", true, map_point("VerityLakefront", "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"}, + }; +} + +// 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", "VerityLakefront", true, map_point("VerityLakefront", "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", "VerityLakefront", true, map_point("VerityLakefront", "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", true, map_point("Route201", "route_201_return"), { + {Direction::EAST, 5, LegEnd::COUNT, "to (5, 14): Rowan and Dawn's scene fires on that column"}, + {Direction::EAST, 12, LegEnd::COUNT, "after the scene, along row 14 to column 17"}, + {Direction::EAST, 12, LegEnd::COUNT, "through the tall grass to column 29; the Breeder wanders rows 14 to 16 there"}, + {Direction::EAST, 12, LegEnd::COUNT, "to column 41"}, + {Direction::NORTH, 7, LegEnd::COUNT, "up column 41 to row 7, beside the north-east grass"}, + {Direction::EAST, 1, LegEnd::COUNT, "into the grass"}, + {Direction::NORTH, 2, LegEnd::COUNT, "to row 5"}, + {Direction::EAST, 10, LegEnd::COUNT, "through the grass to (52, 5), its last tile"}, + {Direction::EAST, 11, LegEnd::COUNT, "to (63, 5), 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 the Route201 map"}, + {"00.03", "Sandgem Town: Dawn at the entrance", "Sandgem Town", "SandgemTown", true, map_point("SandgemTown", "sandgem_arrival"), { + {Direction::EAST, 4, LegEnd::COUNT, "along row 12 to (4, 12): 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; on Sandgem'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", "JubilifeCity", true, 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}, + {Direction::NORTH, 16, LegEnd::COUNT, "stick 3960 ms: up to the street east to Route 203", false}, + {Direction::SOUTH, 2, LegEnd::COUNT, "stick 600 ms: back onto the street", false}, + {Direction::EAST, 0, LegEnd::NPC, "along the street onto Route 203 until Barry stops us; rows retried 0, +1, +1, -3, -1 when a wall comes first"}, + }, "jubilife_to_barry(); stick holds from the console, 2026-10-29, counted in tiles on the image grid's 3/4 rows: recount in taps before giving this record a start tile (task #21)"}, + {"01.02", "Barry to Oreburgh City through the Oreburgh Gate", "Route 203", "Route203", true, std::nullopt, { + {Direction::EAST, 0, LegEnd::WALL, "along the row Barry stopped us on"}, + {Direction::NORTH, 0, LegEnd::WALL, "to the top wall, then a row south at a time until east goes on (up to ten)"}, + {Direction::EAST, 0, LegEnd::NPC, "to the Hiker"}, + {Direction::EAST, 0, LegEnd::TRANSITION, "into the Oreburgh Gate"}, + {Direction::EAST, 0, LegEnd::TRANSITION, "through the Gate into Oreburgh City"}, + }, "route203_to_oreburgh(); no start tile: Barry stops us on whichever row we came along"}, + {"01.04", "Oreburgh Pokemon Center doorstep to the Gym", "Oreburgh City", "OreburghCity", true, map_point("OreburghCity", "pokemon_center_doorstep"), { + {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", "Oreburgh Gym", "OreburghGym", true, map_point("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", "OreburghCity", true, map_point("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"}, + {Direction::NORTH, 0, LegEnd::WALL, "along the cliff"}, + {Direction::EAST, 2, LegEnd::COUNT, "to the stairs' column"}, + {Direction::NORTH, 0, LegEnd::WALL, "up the stairs"}, + {Direction::WEST, 0, LegEnd::WALL, "along the platform"}, + {Direction::SOUTH, 1, LegEnd::COUNT, "onto the Gate's row"}, + {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", "JubilifeCity", true, 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"}, + }, "jubilife_to_rowan(); by hand 2026-10-31 (18 presses), r230b; the stick hold's count was taken on the image grid's 3/4 rows, so no start tile yet"}, + {"01.08", "Jubilife's north street onto Route 204", "Jubilife City", "JubilifeCity", true, std::nullopt, { + {Direction::NORTH, 0, LegEnd::BANNER, "up the street until Route 204's banner; the planned walk to the Ravaged Path door follows"}, + }, "jubilife_to_ravaged_path() step 1"}, + {"01.09", "Ravaged Path's east end out onto Route 204 North", "Ravaged Path", "RavagedPath", true, map_point("RavagedPath", "east_end"), { + {Direction::WEST, 1, LegEnd::COUNT, "onto the tile above the way out"}, + {Direction::SOUTH, 0, LegEnd::TRANSITION, "out of the cave"}, + }, "ravaged_path() exit; the planned legs before it are tested as plans"}, + {"01.10", "Route 204 North's path into Floaroma", "Route 204 North", "Route204North", true, TilePos{11, 5}, { + {Direction::NORTH, 0, LegEnd::BANNER, "from (11, 5) until Floaroma Town's banner; the waypoint line before it is tested as plans"}, + }, "route204_to_floaroma(); r248a"}, + {"01.11", "Floaroma's old couple", "Floaroma Town", "FloaromaTown", true, map_point("FloaromaTown", "route_204_arrival"), { + {Direction::WEST, 8, LegEnd::COUNT, "D-pad taps along the flower field's bottom row"}, + {Direction::NORTH, 0, LegEnd::NPC, "until the old woman stops us (3 tiles on r251a)"}, + {Direction::WEST, 1, LegEnd::COUNT, "below the old man"}, + {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_RouteRecords.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h index 5fbcc8b09d..3097c7b65b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h @@ -1,67 +1,67 @@ -/* BDSP AutoStory - Route records - * - * From: https://github.com/PokemonAutomation/ - * - * Every walk a checkpoint makes that is not planned on a grid, written - * down as legs: the direction, the count or the thing that ends the leg - * (a wall, a person, a door, a location banner, a map transition, a - * scene). The checkpoints run their own code today; these records say - * what that code does, so a test can trace each leg on the map once the - * map is right, and so the next version can run the record instead. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RouteRecords_H -#define PokemonAutomation_PokemonBDSP_AutoStory_RouteRecords_H - -#include -#include -#include -#include "Pokemon/Navigation/Pokemon_TileGrid.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ -namespace RouteRecords{ - - -// What ends a leg. -enum class LegEnd{ - COUNT, // exactly `tiles` tiles (D-pad taps, or a stick hold timed for them) - WALL, // walks until the map stops the player; `tiles` is the expected count, 0 if unknown - NPC, // walks until a person stops the player - DOOR, // walks into a door or cave mouth (a fade) - BANNER, // walks until the next map's location banner shows - TRANSITION, // walks until a map transition (the screen goes dark) - SCENE, // walks until a cutscene takes over -}; - -struct RouteLeg{ - Pokemon::Direction direction; - size_t tiles; - LegEnd end; - std::string note; - // A counted leg walked by D-pad taps (or a leg the map ends) is exact; - // a count from a timed stick hold is an estimate, a tile or two either - // way, until someone counts it on the console in taps. - bool exact = true; -}; - -struct RouteRecord{ - std::string checkpoint; // "01.05" - std::string title; - std::string map; // the map the legs are on ("" when none exists yet) - const Pokemon::TileGrid* (*grid)(); // that map's grid, nullptr when none - bool traceable; // the grid's rows are the game's (decomp or console), so legs can be traced - std::optional start; // where the record starts on that grid - std::vector legs; - std::string source; // the code and the console runs behind it -}; - -const std::vector& all(); - - -} -} -} -} -#endif +/* BDSP AutoStory - Route records + * + * From: https://github.com/PokemonAutomation/ + * + * Every walk a checkpoint makes that is not planned on a grid, written + * down as legs: the direction, the count or the thing that ends the leg + * (a wall, a person, a door, a location banner, a map transition, a + * scene). The checkpoints run their own code today; these records say + * what that code does, so a test can trace each leg on the map once the + * map is right, and so the next version can run the record instead. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RouteRecords_H +#define PokemonAutomation_PokemonBDSP_AutoStory_RouteRecords_H + +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace RouteRecords{ + + +// What ends a leg. +enum class LegEnd{ + COUNT, // exactly `tiles` tiles (D-pad taps, or a stick hold timed for them) + WALL, // walks until the map stops the player; `tiles` is the expected count, 0 if unknown + NPC, // walks until a person stops the player + DOOR, // walks into a door or cave mouth (a fade) + BANNER, // walks until the next map's location banner shows + TRANSITION, // walks until a map transition (the screen goes dark) + SCENE, // walks until a cutscene takes over +}; + +struct RouteLeg{ + Pokemon::Direction direction; + size_t tiles; + LegEnd end; + std::string note; + // A counted leg walked by D-pad taps (or a leg the map ends) is exact; + // a count from a timed stick hold is an estimate, a tile or two either + // way, until someone counts it on the console in taps. + bool exact = true; +}; + +struct RouteRecord{ + std::string checkpoint; // "01.05" + std::string title; + std::string map; // the map the legs are on + std::string map_file; // that map's JSON map (story_map()) + bool traceable; // the map's tiles are the game's (decomp or console), so legs can be traced + std::optional start; // where the record starts on that map + std::vector legs; + std::string source; // the code and the console runs behind it +}; + +const std::vector& all(); + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp index fe4bed1a06..70b9d9bac1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp @@ -1,156 +1,145 @@ -/* BDSP AutoStory - Segment 00's walked lines - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include "PokemonBDSP_AutoStory_Route201.h" -#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). Route201::grid() leaves off the cell's seven wall rows -// at the top, so it starts 7 rows lower; SandgemTown::grid() is its whole -// cell. -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::grid(), {96, 839}); - maps.add(MAP_VERITY_LAKEFRONT, VerityLakefront::grid(), {64, 832}); - maps.add(MAP_SANDGEM_TOWN, SandgemTown::grid(), {160, 832}); - 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, 18}, 6, 1, - "the first time north of Twinleaf (var 0x4086 = 0)"}, - {"Route 201's row 19 after the warning", MAP_ROUTE_201, {14, 19}, 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, 14}, 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, 11}, 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, 24}; -const TilePos BARRY_WARNING{15, 18}; -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, 14}; -const TilePos ROWAN_STOP{5, 14}; -const TilePos ROUTE_201_EAST_END{63, 5}; -const TilePos SANDGEM_ARRIVAL{0, 12}; -const TilePos DAWN_STOP{4, 12}; - -// 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 13 to 16) is the way -// both to and from the lake: the upper level's ledges only drop onto it. -// Row 16 is used westward and row 14 eastward: on the way out Rowan and -// the counterpart are not yet on (8, 14..15) and Barry is gone from (16, -// 16), but 16 keeps the line one row off the Breeder's range; on the way -// back 14 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, 18}), route201({12, 16}), route201({0, 16}), - 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 19 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, 14}), route201({29, 14}), route201({41, 14}), - route201({41, 7}), route201({42, 7}), route201({42, 5}), route201({52, 5}), - route201(ROUTE_201_EAST_END), sandgem(DAWN_STOP), - }, "Dawn at Sandgem's entrance", {"Dawn at Sandgem's entrance"}), - }; - return lines; -} - -} -} -} -} +/* BDSP AutoStory - Segment 00's walked lines + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP_AutoStory_StoryMaps.h" +#include "PokemonBDSP_AutoStory_Segment00Lines.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace Segment00Lines{ + +using Pokemon::TilePos; + + +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). The Route201 map leaves off the cell's seven wall rows +// at the top, so it starts 7 rows lower; story_map("SandgemTown") is its whole +// cell. +const StoryWorld& segment00_maps(){ + static const StoryWorld maps = []{ + StoryWorld maps; + maps.add(MAP_TWINLEAF_TOWN, story_map("TwinleafTown"), {96, 864}); + maps.add(MAP_ROUTE_201, story_map("Route201"), {96, 839}); + maps.add(MAP_VERITY_LAKEFRONT, story_map("VerityLakefront"), {64, 832}); + maps.add(MAP_SANDGEM_TOWN, story_map("SandgemTown"), {160, 832}); + 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, 18}, 6, 1, + "the first time north of Twinleaf (var 0x4086 = 0)"}, + {"Route 201's row 19 after the warning", MAP_ROUTE_201, {14, 19}, 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, 14}, 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, 11}, 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; +} + + + +// 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 13 to 16) is the way +// both to and from the lake: the upper level's ledges only drop onto it. +// Row 16 is used westward and row 14 eastward: on the way out Rowan and +// the counterpart are not yet on (8, 14..15) and Barry is gone from (16, +// 16), but 16 keeps the line one row off the Breeder's range; on the way +// back 14 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}; } +// The same, at a named point of the map. +MapTile twinleaf_point(const char* point){ return twinleaf(map_point("TwinleafTown", point)); } +MapTile route201_point(const char* point){ return route201(map_point("Route201", point)); } +MapTile lakefront_point(const char* point){ return lakefront(map_point("VerityLakefront", point)); } +MapTile sandgem_point(const char* point){ return sandgem(map_point("SandgemTown", point)); } +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_point("house_doorstep"), twinleaf({13, 22}), twinleaf({13, 12}), twinleaf_point("barry_doorstep"), + }, "Barry's door", {"Barry's door"}), + walked("00.01", "Barry's doorstep to Route 201", { + twinleaf_point("barry_doorstep"), twinleaf({15, 12}), twinleaf_point("twinleaf_north_exit"), route201_point("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_point("barry_warning"), route201({12, 18}), route201({12, 16}), route201({0, 16}), + lakefront({20, 23}), lakefront({20, 21}), lakefront({17, 21}), lakefront_point("lake_entrance"), + }, "Barry at the lake's entrance", {"Barry at the lake's entrance", "Route 201's row 19 after the warning"}), + walked("00.03", "the lake's entrance back to Rowan", { + lakefront_point("lake_entrance"), lakefront({17, 21}), lakefront({29, 21}), route201_point("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_point("rowan_stop"), route201({17, 14}), route201({29, 14}), route201({41, 14}), + route201({41, 7}), route201({42, 7}), route201({42, 5}), route201({52, 5}), + route201_point("route_201_east_end"), sandgem_point("dawn_stop"), + }, "Dawn at Sandgem's entrance", {"Dawn at Sandgem's entrance"}), + }; + return lines; +} + +} +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h index 8269643c84..940ec31426 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h @@ -1,84 +1,73 @@ -/* 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; - -// 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 +/* 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 maps: 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_Grid.h" +#include "PokemonBDSP_AutoStory_StoryWorld.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; + +// 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 StoryWorld& 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 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(); + +// The route records start and end on named points of the maps (Twinleaf +// Town's house_doorstep, Route 201's barry_warning, ...), all on the lines. + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp index 25f7180d5f..6cdb9f95c2 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp @@ -1,246 +1,309 @@ -/* BDSP AutoStory - Story maps - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonBDSP_AutoStory_JubilifeCity.h" -#include "PokemonBDSP_AutoStory_OreburghMine.h" -#include "PokemonBDSP_AutoStory_RavagedPath.h" -#include "PokemonBDSP_AutoStory_Route203.h" -#include "PokemonBDSP_AutoStory_Route204.h" -#include "PokemonBDSP_AutoStory_Route204South.h" -#include "PokemonBDSP_AutoStory_OreburghCity.h" -#include "PokemonBDSP_AutoStory_FloaromaTown.h" -#include "PokemonBDSP_AutoStory_Route201.h" -#include "PokemonBDSP_AutoStory_Route202.h" -#include "PokemonBDSP_AutoStory_SandgemTown.h" -#include "PokemonBDSP_AutoStory_StoryMaps.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ - -using namespace Pokemon; - - -const char* const MAP_ROUTE_201 = "Route 201"; -const char* const MAP_SANDGEM_TOWN = "Sandgem Town"; -const char* const MAP_ROUTE_202 = "Route 202"; -const char* const MAP_JUBILIFE_CITY = "Jubilife City"; -const char* const MAP_OREBURGH_MINE = "Oreburgh Mine"; -const char* const MAP_RAVAGED_PATH = "Ravaged Path"; -const char* const MAP_ROUTE_204 = "Route 204"; -const char* const MAP_OREBURGH_CITY = "Oreburgh City"; -const char* const MAP_FLOAROMA_TOWN = "Floaroma Town"; -const char* const MAP_ROUTE_204_SOUTH = "Route 204 South"; -const char* const MAP_ROUTE_203 = "Route 203"; - - -// Offsets are the maps' places in the game's world grid (the decomp's -// cells): Route 201 at world (96,839), Sandgem Town at (160,832), Route 202 -// at (159,800). Route 201's row 4 is Sandgem's row 11, below the doors, and -// Route 202's road comes down off its row 31 onto Sandgem's row 0. -const MapSet& story_maps(){ - static const MapSet maps = []{ - MapSet maps; - maps.add(MAP_ROUTE_201, Route201::grid(), {0, 0}); - maps.add(MAP_SANDGEM_TOWN, SandgemTown::grid(), {64, -7}); - maps.add(MAP_ROUTE_202, Route202::grid(), {63, -39}); - return maps; - }(); - return maps; -} - -const MapSet& jubilife_maps(){ - static const MapSet maps = []{ - MapSet maps; - maps.add(MAP_JUBILIFE_CITY, JubilifeCity::grid(), {0, 0}); - return maps; - }(); - return maps; -} - -// Planned one map at a time: Route 203 and Jubilife joined ran for minutes -// without a plan (r224a, 2026-10-31). -const MapSet& route203_maps(){ - static const MapSet maps = []{ - MapSet maps; - maps.add(MAP_ROUTE_203, Route203::grid(), {0, 0}); - return maps; - }(); - return maps; -} - -bool on_route203_west_line(const TilePos& pos){ - return pos.y == 18 && pos.x >= 24 && pos.x <= 42; -} - -// Columns 42..63, rows 12..25 of the Jubilife grid (world x 170..191, -// z 748..761), as a map of its own: the cut is the map's edge, which no leg -// may cross or stop on, not a wall a plan could walk "to". -namespace{ -const TilePos JUBILIFE_EAST_CORNER{42, 12}; -const int JUBILIFE_EAST_BOTTOM = 25; -} -const MapSet& jubilife_east_maps(){ - static const MapSet maps = []{ - const TileGrid& city = JubilifeCity::grid(); - const TilePos corner = JUBILIFE_EAST_CORNER; - std::vector rows; - for (int y = corner.y; y <= JUBILIFE_EAST_BOTTOM; y++){ - std::string row; - for (int x = corner.x; x < city.width(); x++){ - row += tile_char(city.at({x, y})); - } - rows.push_back(row); - } - MapSet maps; - maps.add(MAP_JUBILIFE_CITY, TileGrid(rows), {0, 0}); - return maps; - }(); - return maps; -} - -// Route 203's road (rows 17..19 of its grid) meets Jubilife's east street, -// rows 21..24 of its grid, at its east edge; the banner shows a tile or two -// in. Both in the corner map's tiles, from the Jubilife grid's. -const std::vector& jubilife_east_entrance(){ - static const std::vector tiles = []{ - std::vector tiles; - for (int y = 21; y <= 24; y++){ - for (int x = 61; x <= 63; x++){ - tiles.push_back({x - JUBILIFE_EAST_CORNER.x, y - JUBILIFE_EAST_CORNER.y}); - } - } - return tiles; - }(); - return tiles; -} - -// The north road where it leaves the plaza, columns 44..48 of rows 16..20. -bool on_jubilife_north_road(const TilePos& pos){ - const int x = pos.x + JUBILIFE_EAST_CORNER.x; - const int y = pos.y + JUBILIFE_EAST_CORNER.y; - return x >= 44 && x <= 48 && y >= 16 && y <= 20; -} - -const MapSet& oreburgh_mine_maps(){ - static const MapSet maps = []{ - MapSet maps; - maps.add(MAP_OREBURGH_MINE, OreburghMine::grid(), {0, 0}); - return maps; - }(); - return maps; -} - -MapSet ravaged_path_maps(const std::vector& smashed){ - TileGrid grid = RavagedPath::grid(); - for (const TilePos& rock : smashed){ - grid.set(rock, TileType::WALKABLE); - } - MapSet maps; - maps.add(MAP_RAVAGED_PATH, grid, {0, 0}); - return maps; -} - -const MapSet& oreburgh_city_maps(){ - static const MapSet maps = []{ - MapSet maps; - maps.add(MAP_OREBURGH_CITY, OreburghCity::grid(), {0, 0}); - return maps; - }(); - return maps; -} - -const MapSet& floaroma_maps(){ - static const MapSet maps = []{ - MapSet maps; - maps.add(MAP_FLOAROMA_TOWN, FloaromaTown::grid(), {0, 0}); - return maps; - }(); - return maps; -} - -const MapSet& route204_north_maps(){ - static const MapSet maps = []{ - MapSet maps; - maps.add(MAP_ROUTE_204, Route204::north_grid(), {0, 0}); - return maps; - }(); - return maps; -} - -const MapSet& route204_south_maps(){ - static const MapSet maps = []{ - MapSet maps; - maps.add(MAP_ROUTE_204_SOUTH, Route204South::grid(), {0, 0}); - return maps; - }(); - return maps; -} - -bool story_map_plannable(const std::string& map){ - return map == MAP_ROUTE_201 || map == MAP_ROUTE_202; -} - -bool story_at_jubilife_exit(const TilePos& world){ - const std::optional tile = story_maps().to_local(world); - return tile && tile->map == MAP_ROUTE_202 && tile->pos.y <= 3; -} - -std::vector story_save_spots(){ - const MapSet& maps = story_maps(); - return { - maps.to_world(MAP_ROUTE_202, Route202::CATCH_SPOT), - maps.to_world(MAP_ROUTE_202, Route202::SAVE_SPOT), - }; -} - -std::vector story_door_front(const char* map, const TilePos& door){ - const TilePos below = story_maps().to_world(map, door.next(Direction::SOUTH)); - return {below.next(Direction::WEST), below, below.next(Direction::EAST)}; -} - -std::vector story_catch_save_area(){ - const MapSet& maps = story_maps(); - std::vector area; - for (int y = 25; y <= 29; y++){ - for (int x = 15; x <= 21; x++){ - const TilePos pos = maps.to_world(MAP_ROUTE_202, {x, y}); - if (maps.world().standable(pos)){ - area.push_back(pos); - } - } - } - return area; -} - -std::vector story_after_training_area(){ - const MapSet& maps = story_maps(); - const TilePos catch_spot = maps.to_world(MAP_ROUTE_202, Route202::CATCH_SPOT); - std::vector area; - for (int y = catch_spot.y - 2; y <= catch_spot.y + 2; y++){ - for (int x = catch_spot.x - 1; x <= catch_spot.x + 1; x++){ - // The rows below the catch spot are trees in BDSP. - if (maps.world().standable({x, y})){ - area.push_back({x, y}); - } - } - } - return area; -} - -std::vector story_trainer_sights(){ - std::vector sights = Route202::trainer_sights(); - for (TrainerSight& sight : sights){ - sight.pos = story_maps().to_world(MAP_ROUTE_202, sight.pos); - } - return sights; -} - - - -} -} -} +/* BDSP AutoStory - Story maps + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP_AutoStory_StoryMaps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using Pokemon::Direction; +using Pokemon::MapData; +using Pokemon::TilePos; + + +const char* const MAP_ROUTE_201 = "Route 201"; +const char* const MAP_SANDGEM_TOWN = "Sandgem Town"; +const char* const MAP_ROUTE_202 = "Route 202"; +const char* const MAP_JUBILIFE_CITY = "Jubilife City"; +const char* const MAP_OREBURGH_MINE = "Oreburgh Mine"; +const char* const MAP_RAVAGED_PATH = "Ravaged Path"; +const char* const MAP_ROUTE_204 = "Route 204"; +const char* const MAP_OREBURGH_CITY = "Oreburgh City"; +const char* const MAP_FLOAROMA_TOWN = "Floaroma Town"; +const char* const MAP_ROUTE_204_SOUTH = "Route 204 South"; +const char* const MAP_ROUTE_203 = "Route 203"; + + +namespace{ + +// One map on its own. +StoryWorld single(const char* name, const std::string& json_map){ + StoryWorld world; + world.add(name, story_map(json_map), {0, 0}); + return world; +} + +// The tiles of `map` from `corner`, `width` x `height`, and the objects on +// them, as a map of its own. Its points are left out. +MapData crop(const MapData& map, const TilePos& corner, int width, int height){ + MapData cropped; + cropped.name = map.name; + cropped.source = map.source; + cropped.tiles = Pokemon::Grid{width, height, {}}; + for (int y = 0; y < height; y++){ + for (int x = 0; x < width; x++){ + cropped.tiles.cells.push_back(map.tiles.at({corner.x + x, corner.y + y})); + } + } + for (Pokemon::MapObject object : map.objects){ + object.x -= corner.x; + object.y -= corner.y; + if (cropped.tiles.contains({object.x, object.y})){ + cropped.objects.push_back(std::move(object)); + } + } + return cropped; +} + +bool in_region(const std::string& map, const std::string& region, const TilePos& pos){ + const std::vector tiles = map_region(map, region); + return std::find(tiles.begin(), tiles.end(), pos) != tiles.end(); +} + +} + + +// Offsets are the maps' places in the game's world grid (the decomp's +// cells): Route 201 at world (96,839), Sandgem Town at (160,832), Route 202 +// at (159,800). Route 201's row 4 is Sandgem's row 11, below the doors, and +// Route 202's road comes down off its row 31 onto Sandgem's row 0. +const StoryWorld& story_maps(){ + static const StoryWorld maps = []{ + StoryWorld maps; + maps.add(MAP_ROUTE_201, story_map("Route201"), {0, 0}); + maps.add(MAP_SANDGEM_TOWN, story_map("SandgemTown"), {64, -7}); + maps.add(MAP_ROUTE_202, story_map("Route202"), {63, -39}); + return maps; + }(); + return maps; +} + +const StoryWorld& jubilife_maps(){ + static const StoryWorld maps = single(MAP_JUBILIFE_CITY, "JubilifeCity"); + return maps; +} + +// Planned one map at a time: Route 203 and Jubilife joined ran for minutes +// without a plan (r224a, 2026-10-31). +const StoryWorld& route203_maps(){ + static const StoryWorld maps = single(MAP_ROUTE_203, "Route203"); + return maps; +} + +bool on_route203_west_line(const TilePos& pos){ + return in_region("Route203", "west_line", pos); +} + +// Columns 42..63, rows 12..25 of Jubilife (world x 170..191, z 748..761), +// as a map of its own: the cut is the map's edge, which no leg may cross +// or stop on, not a wall a plan could walk "to". +namespace{ +const TilePos JUBILIFE_EAST_CORNER{42, 12}; +const int JUBILIFE_EAST_BOTTOM = 25; +} +const StoryWorld& jubilife_east_maps(){ + static const StoryWorld maps = []{ + const MapData& city = story_map("JubilifeCity"); + StoryWorld maps; + maps.add(MAP_JUBILIFE_CITY, crop( + city, JUBILIFE_EAST_CORNER, city.tiles.width - JUBILIFE_EAST_CORNER.x, JUBILIFE_EAST_BOTTOM - JUBILIFE_EAST_CORNER.y + 1 + ), {0, 0}); + return maps; + }(); + return maps; +} + +// Route 203's road (rows 17..19 of its map) meets Jubilife's east street, +// rows 21..24 of its map, at its east edge; the banner shows a tile or two +// in. In the corner map's tiles. +const std::vector& jubilife_east_entrance(){ + static const std::vector tiles = []{ + std::vector tiles; + for (const TilePos& pos : map_region("JubilifeCity", "east_entrance")){ + tiles.push_back({pos.x - JUBILIFE_EAST_CORNER.x, pos.y - JUBILIFE_EAST_CORNER.y}); + } + return tiles; + }(); + return tiles; +} + +bool on_jubilife_north_road(const TilePos& pos){ + return in_region("JubilifeCity", "north_road", {pos.x + JUBILIFE_EAST_CORNER.x, pos.y + JUBILIFE_EAST_CORNER.y}); +} + +const StoryWorld& oreburgh_mine_maps(){ + static const StoryWorld maps = single(MAP_OREBURGH_MINE, "OreburghMine"); + return maps; +} + +StoryWorld ravaged_path_maps(const std::vector& smashed){ + MapData map = story_map("RavagedPath"); + for (const TilePos& rock : smashed){ + if (map.tiles.contains(rock)){ + map.tiles.at(rock) = Pokemon::TileKind::OPEN; + } + } + StoryWorld maps; + maps.add(MAP_RAVAGED_PATH, map, {0, 0}); + return maps; +} + +const StoryWorld& oreburgh_city_maps(){ + static const StoryWorld maps = single(MAP_OREBURGH_CITY, "OreburghCity"); + return maps; +} + +const StoryWorld& floaroma_maps(){ + static const StoryWorld maps = single(MAP_FLOAROMA_TOWN, "FloaromaTown"); + return maps; +} + +const StoryWorld& route204_north_maps(){ + static const StoryWorld maps = single(MAP_ROUTE_204, "Route204North"); + return maps; +} + +bool in_floaroma_path(const TilePos& pos){ + return in_region("Route204North", "floaroma_path", pos); +} + +const StoryWorld& route204_south_maps(){ + static const StoryWorld maps = single(MAP_ROUTE_204_SOUTH, "Route204South"); + return maps; +} + +bool story_map_plannable(const std::string& map){ + return map == MAP_ROUTE_201 || map == MAP_ROUTE_202; +} + +bool story_at_jubilife_exit(const TilePos& world){ + const std::optional tile = story_maps().to_local(world); + return tile && tile->map == MAP_ROUTE_202 && tile->pos.y <= 3; +} + +std::vector story_save_spots(){ + const StoryWorld& maps = story_maps(); + return { + maps.to_world(MAP_ROUTE_202, map_point("Route202", "catch_spot")), + maps.to_world(MAP_ROUTE_202, map_point("Route202", "save_spot")), + }; +} + +std::vector story_door_front(const char* map, const TilePos& door){ + const TilePos below = story_maps().to_world(map, door.next(Direction::SOUTH)); + return {below.next(Direction::WEST), below, below.next(Direction::EAST)}; +} + +std::vector story_catch_save_area(){ + const StoryWorld& maps = story_maps(); + std::vector area; + for (int y = 25; y <= 29; y++){ + for (int x = 15; x <= 21; x++){ + const TilePos pos = maps.to_world(MAP_ROUTE_202, {x, y}); + if (maps.standable(pos)){ + area.push_back(pos); + } + } + } + return area; +} + +std::vector story_after_training_area(){ + const StoryWorld& maps = story_maps(); + const TilePos catch_spot = maps.to_world(MAP_ROUTE_202, map_point("Route202", "catch_spot")); + std::vector area; + for (int y = catch_spot.y - 2; y <= catch_spot.y + 2; y++){ + for (int x = catch_spot.x - 1; x <= catch_spot.x + 1; x++){ + // The rows below the catch spot are trees in BDSP. + if (maps.standable({x, y})){ + area.push_back({x, y}); + } + } + } + return area; +} + +std::vector story_trainer_sights(){ + std::vector sights = route202_trainer_sights(); + for (TrainerSight& sight : sights){ + sight.pos = story_maps().to_world(MAP_ROUTE_202, sight.pos); + } + return sights; +} + + +// From the events file: each trainer's tile, facing and sight range. +// Natalie challenged us at (22,22), walking east along the row above the +// ledge (r75), the fourth tile of her sight. +std::vector route202_trainer_sights(){ + return { + {.name = "tristan", .pos = map_point("Route202", "trainer_tristan"), .facing = Direction::SOUTH, .range = 5}, + {.name = "natalie", .pos = map_point("Route202", "trainer_natalie"), .facing = Direction::SOUTH, .range = 4}, + {.name = "logan", .pos = map_point("Route202", "trainer_logan"), .facing = Direction::SOUTH, .range = 5}, + }; +} + +std::vector route204_north_trainer_sights(){ + const auto at = [](const char* point){ return map_point("Route204North", point); }; + return { + {.name = "Twins (left)", .pos = at("trainer_twin_left"), .facing = Direction::SOUTH, .range = 3}, + {.name = "Twins (right)", .pos = at("trainer_twin_right"), .facing = Direction::SOUTH, .range = 4}, + {.name = "Aroma Lady Taylor", .pos = at("trainer_taylor"), .facing = Direction::SOUTH, .range = 4}, + {.name = "Aroma Lady Taylor", .pos = at("trainer_taylor"), .facing = Direction::EAST, .range = 4}, + // Bug Catcher Brandon paces east and west below the flower beds + // and stopped us on row 12 (r246a: "Say, what's your opinion on bug + // Pokemon?"); the DP map draws him at (20, 12), Platinum's data + // has him at (22, 13). The tile is a guess until a shot fixes it. + {.name = "Bug Catcher Brandon", .pos = at("trainer_brandon"), .facing = Direction::WEST, .range = 4}, + {.name = "Bug Catcher Brandon", .pos = at("trainer_brandon"), .facing = Direction::EAST, .range = 4}, + }; +} + +// Sarah turns between north and east; her east line crosses the street's +// columns, so a walk north meets it or not by luck (r233a passed, r234a +// fought). The planner cannot avoid it: she is listed so the route knows +// whom it may meet, with the range that fits. +std::vector route204_south_trainer_sights(){ + const auto at = [](const char* point){ return map_point("Route204South", point); }; + return { + {.name = "Lass Samantha", .pos = at("trainer_samantha"), .facing = Direction::SOUTH, .range = 4}, + {.name = "Lass Sarah", .pos = at("trainer_sarah"), .facing = Direction::NORTH, .range = 4}, + {.name = "Lass Sarah", .pos = at("trainer_sarah"), .facing = Direction::EAST, .range = 4}, + {.name = "Youngster Tyler", .pos = at("trainer_tyler"), .facing = Direction::EAST, .range = 4}, + {.name = "Youngster Tyler", .pos = at("trainer_tyler"), .facing = Direction::WEST, .range = 4}, + }; +} + +// Both see the middle column, so a walk north from the entrance is +// stopped twice before Roark (01.04's record). +std::vector oreburgh_gym_trainer_sights(){ + return { + {.name = "Youngster (first tier)", .pos = map_point("OreburghGym", "trainer_first_tier"), .facing = Direction::EAST, .range = 3}, + {.name = "Youngster (second tier)", .pos = map_point("OreburghGym", "trainer_second_tier"), .facing = Direction::WEST, .range = 4}, + }; +} + +std::vector route204_south_tiles_to_avoid(){ + std::vector tiles; + for (const TrainerSight& trainer : route204_south_trainer_sights()){ + if (trainer.name == "Lass Sarah" && trainer.facing == Direction::EAST){ + continue; + } + for (const TilePos& pos : sight_tiles(route204_south_maps(), trainer)){ + tiles.push_back(pos); + } + } + return tiles; +} + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h index 3e27b3dc7a..4e355d9eff 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h @@ -1,108 +1,130 @@ -/* BDSP AutoStory - Story maps - * - * From: https://github.com/PokemonAutomation/ - * - * The maps the story walks through, joined on one grid. - */ - -#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_H -#define PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_H - -#include "Pokemon/Navigation/Pokemon_MapSet.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonBDSP{ - - -extern const char* const MAP_ROUTE_201; -extern const char* const MAP_SANDGEM_TOWN; -extern const char* const MAP_ROUTE_202; -extern const char* const MAP_JUBILIFE_CITY; -extern const char* const MAP_OREBURGH_MINE; -extern const char* const MAP_RAVAGED_PATH; -extern const char* const MAP_ROUTE_204; -extern const char* const MAP_ROUTE_204_SOUTH; -extern const char* const MAP_ROUTE_203; - -// Route 201, Sandgem Town and Route 202. -const Pokemon::MapSet& story_maps(); - -// Jubilife City on its own: 00.05 starts there after Dawn's scene, so it is -// not joined to Route 202. -const Pokemon::MapSet& jubilife_maps(); -// Route 203 on its own (01.06), and whether a tile is on row 18 between the -// two cliffs: row 18 runs straight west from there under the west cliff -// into Jubilife, so the plan ends there (no leg may leave the map) and a -// walk west until Jubilife's banner shows goes on from there. -const Pokemon::MapSet& route203_maps(); -bool on_route203_west_line(const Pokemon::TilePos& pos); -// Jubilife City's north-east corner (01.06), at Jubilife's own tile -// coordinates: the rest of the city is walled off, so the plan searches only -// the part the walk needs. Where Route 203's road enters it, and whether a -// tile is on the north road below the plaza: walking north from there goes -// up the road to Route 204 (and Rowan's scene). -const Pokemon::MapSet& jubilife_east_maps(); -const std::vector& jubilife_east_entrance(); -bool on_jubilife_north_road(const Pokemon::TilePos& pos); -// The Oreburgh Mine's coal room on its own (01.03). -const Pokemon::MapSet& oreburgh_mine_maps(); - -// The Ravaged Path on its own (01.05), with the rocks in `smashed` open. -Pokemon::MapSet ravaged_path_maps(const std::vector& smashed = {}); - -// Route 204's north half on its own (01.05). -const Pokemon::MapSet& route204_north_maps(); - -// Route 204's south half on its own (01.08): it joins the north half only -// through the Ravaged Path, so the two are separate maps. -const Pokemon::MapSet& route204_south_maps(); - -// Oreburgh City alone (01.04, 01.05), and Floaroma Town alone (01.11). -extern const char* const MAP_OREBURGH_CITY; -extern const char* const MAP_FLOAROMA_TOWN; -const Pokemon::MapSet& oreburgh_city_maps(); -const Pokemon::MapSet& floaroma_maps(); - -// Whether a plan may cross this map. Routes are traced from the DP maps and -// their tree walls carried over to BDSP; towns changed more in the remake, so -// a town is crossed by screen-driven legs until the console has confirmed its -// grid. -bool story_map_plannable(const std::string& map); - -// The open rows at the top of Route 202, in world tiles: walking north from -// any of them enters Jubilife City. -bool story_at_jubilife_exit(const Pokemon::TilePos& world); - -// Where the post-catch half of 00.04 may start, in world tiles: the catch -// spot (00.03 saves there after the catch) and the save spot under the -// ledge (00.04 saves there once it has Potions, before Route 202's trainers). -std::vector story_save_spots(); - -// Where 00.04b's save after the catch may stand, in world tiles: wherever -// the catch's walks in the grass ended, the patch (15..20, 25..27) and the -// lawn column east of it, (21, 25..29), down to the pocket behind the tree -// row where r252's catch ended and saved (the save loads there: (21, 29) -// by the screen, the 202 sign 3 columns right and 4 rows up). -std::vector story_catch_save_area(); - -// Where a walk out of the door `door` of `map` may leave us, in world tiles: -// the tile below it and its neighbours either side, since the door opening -// is not lined up with one tile (Jubilife's Center, r85). -std::vector story_door_front(const char* map, const Pokemon::TilePos& door); - -// Where we may stand after training in the catch grass, in world tiles: the -// training walks up and down the catch spot's column, between the tree walls -// north and south of the grass, so a battle may stop us on any of its -// three rows. A column either side allows for where the catch left us. -std::vector story_after_training_area(); - -// Route 202's trainers, in world tiles of story_maps(). -std::vector story_trainer_sights(); - - - -} -} -} -#endif +/* BDSP AutoStory - Story maps + * + * From: https://github.com/PokemonAutomation/ + * + * The maps the story walks through, joined into story worlds, and the + * places and trainers on them that the story's walks need. The tiles and + * named points come from the JSON maps (PokemonBDSP_AutoStory_Maps.h); + * where the maps sit relative to each other, and the trainers' sight + * ranges, the maps do not say, so they are here. + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_H + +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP_AutoStory_StoryWorld.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Names of the maps in the story worlds below. Each is placed from the +// JSON map named without spaces ("Route 201" from Route201.json), except +// MAP_ROUTE_204, which is Route204North.json. +extern const char* const MAP_ROUTE_201; +extern const char* const MAP_SANDGEM_TOWN; +extern const char* const MAP_ROUTE_202; +extern const char* const MAP_JUBILIFE_CITY; +extern const char* const MAP_OREBURGH_MINE; +extern const char* const MAP_RAVAGED_PATH; +extern const char* const MAP_ROUTE_204; +extern const char* const MAP_ROUTE_204_SOUTH; +extern const char* const MAP_ROUTE_203; +extern const char* const MAP_OREBURGH_CITY; +extern const char* const MAP_FLOAROMA_TOWN; + +// Route 201, Sandgem Town and Route 202. +const StoryWorld& story_maps(); + +// Jubilife City on its own: 00.05 starts there after Dawn's scene, so it is +// not joined to Route 202. +const StoryWorld& jubilife_maps(); +// Route 203 on its own (01.06), and whether a tile is on row 18 between the +// two cliffs: row 18 runs straight west from there under the west cliff +// into Jubilife, so the plan ends there (no leg may leave the map) and a +// walk west until Jubilife's banner shows goes on from there. +const StoryWorld& route203_maps(); +bool on_route203_west_line(const Pokemon::TilePos& pos); +// Jubilife City's north-east corner (01.06), at its own tile coordinates: +// the rest of the city is walled off, so the plan searches only the part +// the walk needs. Where Route 203's road enters it, and whether a tile is +// on the north road below the plaza: walking north from there goes up the +// road to Route 204 (and Rowan's scene). +const StoryWorld& jubilife_east_maps(); +const std::vector& jubilife_east_entrance(); +bool on_jubilife_north_road(const Pokemon::TilePos& pos); +// The Oreburgh Mine's coal room on its own (01.03). +const StoryWorld& oreburgh_mine_maps(); + +// The Ravaged Path on its own (01.05), with the rocks in `smashed` open. +StoryWorld ravaged_path_maps(const std::vector& smashed = {}); + +// Route 204's north half on its own (01.05), and whether a tile is on the +// path north into Floaroma. +const StoryWorld& route204_north_maps(); +bool in_floaroma_path(const Pokemon::TilePos& pos); + +// Route 204's south half on its own (01.08): it joins the north half only +// through the Ravaged Path, so the two are separate maps. +const StoryWorld& route204_south_maps(); + +// Oreburgh City alone (01.04, 01.05), and Floaroma Town alone (01.11). +const StoryWorld& oreburgh_city_maps(); +const StoryWorld& floaroma_maps(); + +// Whether a plan may cross this map. Towns are crossed by screen-driven +// legs until the console has confirmed their maps. +bool story_map_plannable(const std::string& map); + +// The open rows at the top of Route 202, in world tiles: walking north from +// any of them enters Jubilife City. +bool story_at_jubilife_exit(const Pokemon::TilePos& world); + +// Where the post-catch half of 00.04 may start, in world tiles: the catch +// spot (00.03 saves there after the catch) and the save spot under the +// ledge (00.04 saves there once it has Potions, before Route 202's trainers). +std::vector story_save_spots(); + +// Where 00.04b's save after the catch may stand, in world tiles: wherever +// the catch's walks in the grass ended, the patch (15..20, 25..27) and the +// lawn column east of it, (21, 25..29), down to the pocket behind the tree +// row where r252's catch ended and saved (the save loads there: (21, 29) +// by the screen, the 202 sign 3 columns right and 4 rows up). +std::vector story_catch_save_area(); + +// Where a walk out of the door `door` of `map` may leave us, in world tiles: +// the tile below it and its neighbours either side, since the door opening +// is not lined up with one tile (Jubilife's Center, r85). +std::vector story_door_front(const char* map, const Pokemon::TilePos& door); + +// Where we may stand after training in the catch grass, in world tiles: the +// training walks up and down the catch spot's column, between the tree walls +// north and south of the grass, so a battle may stop us on any of its +// three rows. A column either side allows for where the catch left us. +std::vector story_after_training_area(); + +// Route 202's trainers, in world tiles of story_maps(). +std::vector story_trainer_sights(); + +// The trainers of a map, in its own tiles, with the sight ranges that fit +// the console. A trainer who looks two ways is listed once per way. +std::vector route202_trainer_sights(); +std::vector route204_north_trainer_sights(); +std::vector route204_south_trainer_sights(); +std::vector oreburgh_gym_trainer_sights(); + +// Route 204 South's tiles in the trainers' sight that a walk can avoid: +// all but Sarah's east line, which crosses the street (see the sights). +std::vector route204_south_tiles_to_avoid(); + + + +} +} +} +#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 index 4f85f52a85..479c1240c2 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp @@ -1,266 +1,215 @@ -/* 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 "Data/PokemonBDSP_AutoStory_PlanCosts.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(); -} - - -} -} -} +/* BDSP AutoStory Segment 00 Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Data/PokemonBDSP_AutoStory_Maps.h" +#include "Data/PokemonBDSP_AutoStory_Segment00Lines.h" +#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" +#include "Data/PokemonBDSP_AutoStory_PlanCosts.h" +#include "PokemonBDSP_AutoStory_Segment00_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +using Pokemon::TilePos; +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{ + TileLeg leg; + std::string error; +}; +Stretch plan_stretch(const StoryWorld& maps, const TilePos& from, const TilePos& to, const std::string& name){ + const auto plan = plan_robust_route(maps, 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 PlannedLeg& leg : *plan){ + text += " " + to_string(leg.leg); + } + return {{}, text}; + } + const 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 StoryWorld& 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 points the route records start and end on, each of which must lie +// on one of the lines. +struct NamedTile{ + const char* map; // in segment00_maps() + const char* json_map; + const char* point; +}; +std::vector named_tiles(){ + const char* twinleaf = Segment00Lines::MAP_TWINLEAF_TOWN; + const char* lakefront = Segment00Lines::MAP_VERITY_LAKEFRONT; + return { + {.map = twinleaf, .json_map = "TwinleafTown", .point = "house_doorstep"}, + {.map = twinleaf, .json_map = "TwinleafTown", .point = "barry_doorstep"}, + {.map = twinleaf, .json_map = "TwinleafTown", .point = "twinleaf_north_exit"}, + {.map = MAP_ROUTE_201, .json_map = "Route201", .point = "route_201_arrival"}, + {.map = MAP_ROUTE_201, .json_map = "Route201", .point = "barry_warning"}, + {.map = lakefront, .json_map = "VerityLakefront", .point = "lakefront_arrival"}, + {.map = lakefront, .json_map = "VerityLakefront", .point = "below_lake_entrance"}, + {.map = lakefront, .json_map = "VerityLakefront", .point = "lake_entrance"}, + {.map = MAP_ROUTE_201, .json_map = "Route201", .point = "route_201_return"}, + {.map = MAP_ROUTE_201, .json_map = "Route201", .point = "rowan_stop"}, + {.map = MAP_ROUTE_201, .json_map = "Route201", .point = "route_201_east_end"}, + {.map = MAP_SANDGEM_TOWN, .json_map = "SandgemTown", .point = "sandgem_arrival"}, + {.map = MAP_SANDGEM_TOWN, .json_map = "SandgemTown", .point = "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 maps, 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 StoryWorld& 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 MapTile named{tile.map, map_point(tile.json_map, tile.point)}; + const bool on_a_line = std::ranges::any_of(walked, [&](const MapTile& t){ + return t.map == named.map && t.pos == named.pos; + }); + if (!on_a_line){ + return std::string(tile.point) + " " + describe(named) + " is on none of the lines."; + } + } + return true; + } +}; + +} + + +void add_tests_AutoStory_Segment00(UnitTestDatabase& database){ + 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 index a956b4073c..7e501479e0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h @@ -15,8 +15,8 @@ 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. +// Offline checks of Segment 00's walked lines against the maps and the +// scenes' trigger rectangles. void add_tests_AutoStory_Segment00(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp new file mode 100644 index 0000000000..36c0bdb348 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp @@ -0,0 +1,251 @@ +/* BDSP AutoStory Story Maps Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The story's walks on its maps: Route 202's catch grass and the way into + * Sandgem, Sandgem's Center, the Oreburgh Gym's column, and the route + * records traced on their maps. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Data/PokemonBDSP_AutoStory_Maps.h" +#include "Data/PokemonBDSP_AutoStory_PlanCosts.h" +#include "Data/PokemonBDSP_AutoStory_RouteRecords.h" +#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" +#include "PokemonBDSP_AutoStory_StoryMaps_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +namespace{ + +using Pokemon::Direction; +using Pokemon::TileKind; +using Pokemon::TilePos; + +StoryWorld alone(const std::string& json_map){ + StoryWorld world; + world.add(json_map, story_map(json_map), {0, 0}); + return world; +} + +// 00.04's training walks up and down the catch patch, three grass rows +// between tree rows, and needs the walk there to end in its grass: r253 +// and r254 loaded the catch's save in the pocket behind the trees at +// (21, 29), planned from the catch spot instead, and walked up and down +// the lawn east of the grass for three minutes without a battle. +class Test_Route202CatchGrass : public UnitTest{ +public: + Test_Route202CatchGrass() + : UnitTest("PokemonBDSP::AutoStory - Route 202: the catch patch and the walk to it") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const StoryWorld route = alone("Route202"); + for (int x = 15; x <= 20; x++){ + const WallHit up = walk_to_wall(route, {x, 27}, Direction::NORTH); + const WallHit down = walk_to_wall(route, {x, 25}, Direction::SOUTH); + if (!(up.stop == TilePos{x, 25}) || !(down.stop == TilePos{x, 27})){ + return std::format("Catch patch column {}: north from row 27 stops at {}, south from row 25 at {}; expected rows 25 and 27, between tree rows.", + x, Pokemon::to_string(up.stop), Pokemon::to_string(down.stop)); + } + } + const StoryWorld& maps = story_maps(); + const std::vector area = story_after_training_area(); + const auto in_grass = [&](const TilePos& pos){ + return maps.tile(pos) == TileKind::TALL_GRASS && std::find(area.begin(), area.end(), pos) != area.end(); + }; + // As walk_route() plans: the route costs, else the default costs. + // From the whole area the catch's save may stand in, and from the + // pocket behind the trees alone, where r252 saved. + const std::vector>> starts{ + {"the catch's save area", story_catch_save_area()}, + {"the pocket behind the trees", {maps.to_world(MAP_ROUTE_202, {21, 29})}}, + }; + for (const auto& [name, from] : starts){ + std::optional> legs = plan_robust_route(maps, from, in_grass, route_plan_costs()); + if (!legs){ + legs = plan_robust_route(maps, from, in_grass, RobustPlanCosts()); + } + if (!legs || legs->empty()){ + return "From " + name + " to the catch grass: no plan."; + } + for (const TilePos& pos : legs->back().after){ + if (!in_grass(pos)){ + return "From " + name + " to the catch grass: the walk may end on " + maps.describe(pos) + ", not in the grass."; + } + } + logger.log(std::format("From {} to the catch grass: {} legs, ending in the grass.", name, legs->size())); + } + return true; + } +}; + +// 00.04's way to Sandgem's Pokemon Center ends below the Center's sign, +// walking north into it, then taps west along the doors' row to below the +// door: the row must be open there, the door straight north of where the +// taps end, and nothing else (a sign, the Mart's door) on the way. +class Test_SandgemCenterApproach : public UnitTest{ +public: + Test_SandgemCenterApproach() + : UnitTest("PokemonBDSP::AutoStory - Sandgem Town: below the Center's sign to below its door") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const StoryWorld town = alone("SandgemTown"); + const TilePos sign = map_point("SandgemTown", "pokemon_center_sign"); + const TilePos door = map_point("SandgemTown", "pokemon_center_door"); + if (town.tile(sign) != TileKind::SIGN || town.tile(door) != TileKind::DOOR || door.y != sign.y || door.x >= sign.x){ + return std::format("The Center's sign {} and door {} are not a sign and a door west of it on one row.", + Pokemon::to_string(sign), Pokemon::to_string(door)); + } + TilePos pos = sign.next(Direction::SOUTH); + for (int tap = 0; tap < sign.x - door.x; tap++){ + const std::optional next = town.step(pos, Direction::WEST); + if (!next){ + return "West from " + Pokemon::to_string(pos) + " is blocked."; + } + if (town.tile(next->next(Direction::NORTH)) != TileKind::WALL && *next != door.next(Direction::SOUTH)){ + return "Above " + Pokemon::to_string(*next) + " is not the Center's wall."; + } + pos = *next; + } + if (!(pos == door.next(Direction::SOUTH))){ + return std::format("The taps end at {}, not below the door {}.", Pokemon::to_string(pos), Pokemon::to_string(door)); + } + logger.log(std::format("Sandgem: below the sign {}, {} taps west to below the door {}.", + Pokemon::to_string(sign.next(Direction::SOUTH)), sign.x - door.x, Pokemon::to_string(door))); + return true; + } +}; + +// After training, 00.04 walks from wherever the training left us into +// Sandgem, to where the road stops above the Mart, with the default costs +// (heal_at_sandgem_center()): from the whole area and from each of its +// tiles alone, a plan must exist and end there. +class Test_TrainingToSandgem : public UnitTest{ +public: + Test_TrainingToSandgem() + : UnitTest("PokemonBDSP::AutoStory - Route 202: from every tile of the training area into Sandgem") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const StoryWorld& maps = story_maps(); + const TilePos entry = maps.to_world(MAP_SANDGEM_TOWN, map_point("SandgemTown", "route_202_entry_stop")); + const std::vector area = story_after_training_area(); + std::vector> starts{area}; + for (const TilePos& pos : area){ + starts.push_back({pos}); + } + for (const std::vector& from : starts){ + const auto legs = plan_robust_route(maps, from, [&](const TilePos& pos){ return pos == entry; }, RobustPlanCosts()); + const std::string name = from.size() == 1 ? maps.describe(from[0]) : "the whole training area"; + if (!legs || legs->empty()){ + return "From " + name + " into Sandgem: no plan."; + } + if (legs->back().after.size() != 1 || !(legs->back().after[0] == entry)){ + return "From " + name + " into Sandgem: the plan does not end on " + maps.describe(entry) + "."; + } + logger.log(std::format("From {} into Sandgem: {} legs.", name, legs->size())); + } + return true; + } +}; + +// The Oreburgh Gym's inside: 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_OreburghGymColumn : public UnitTest{ +public: + Test_OreburghGymColumn() + : UnitTest("PokemonBDSP::AutoStory - Oreburgh Gym: the column up to Roark") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + const StoryWorld gym = alone("OreburghGym"); + const TilePos entrance = map_point("OreburghGym", "entrance"); + const TilePos roark = map_point("OreburghGym", "roark"); + if (!gym.standable(entrance) || gym.tile(entrance.next(Direction::SOUTH)) != TileKind::DOOR){ + return std::string("The entrance tile is not standable above the door."); + } + if (!gym.occupied(roark)){ + return std::string("Nobody stands on Roark's tile."); + } + const WallHit up = walk_to_wall(gym, entrance, Direction::NORTH); + if (!(up.wall == roark)){ + return "North from the entrance stops at " + Pokemon::to_string(up.stop) + ", not in front of Roark."; + } + logger.log(std::format("Oreburgh Gym: north from the entrance walks {} tiles to Roark.", up.tiles)); + for (const TrainerSight& trainer : oreburgh_gym_trainer_sights()){ + if (!gym.occupied(trainer.pos)){ + return trainer.name + " does not stand on their tile."; + } + const std::vector seen = sight_tiles(gym, trainer); + const bool sees_column = std::ranges::any_of(seen, [&](const TilePos& pos){ + return pos.x == entrance.x && pos.y < entrance.y && pos.y > roark.y; + }); + if (!sees_column){ + return trainer.name + " does not see the column up to Roark."; + } + } + return true; + } +}; + +// Each traceable record with a start tile starts on ground, and its legs +// counted in whole tiles trace on its map up to the first leg that ends +// some other way. +class Test_RouteRecords : public UnitTest{ +public: + Test_RouteRecords() + : UnitTest("PokemonBDSP::AutoStory - Route records: counted legs trace on their maps") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + for (const RouteRecords::RouteRecord& record : RouteRecords::all()){ + const std::string name = record.checkpoint + " " + record.title; + const StoryWorld world = alone(record.map_file); + if (!record.traceable || !record.start){ + continue; + } + if (!world.standable(*record.start)){ + return name + ": starts on " + Pokemon::to_string(*record.start) + ", where nobody can stand."; + } + std::vector counted; + for (const RouteRecords::RouteLeg& leg : record.legs){ + if (leg.end != RouteRecords::LegEnd::COUNT || !leg.exact){ + break; + } + counted.push_back({leg.direction, leg.tiles, false}); + } + try{ + const TilePos end = trace_legs(world, *record.start, counted).back(); + logger.log(std::format("{}: {} counted legs to {}.", name, counted.size(), world.describe(end))); + }catch (InternalProgramError& e){ + return name + ": " + e.message(); + } + } + return true; + } +}; + +} + + +void add_tests_AutoStory_StoryMaps(UnitTestDatabase& database){ + database.add(); + database.add(); + database.add(); + database.add(); + database.add(); +} + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h new file mode 100644 index 0000000000..68fb96f3f3 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h @@ -0,0 +1,24 @@ +/* BDSP AutoStory Story Maps Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Offline checks of the story's walks on its maps: Route 202, Sandgem, the Oreburgh Gym and the route records. +void add_tests_AutoStory_StoryMaps(UnitTestDatabase& database); + + +} +} +} +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 5d63877935..8ed6d5c25d 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1461,8 +1461,6 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_MapData.cpp Source/Pokemon/Navigation/Pokemon_MapData.h Source/Pokemon/Navigation/Pokemon_MapData_Tests.cpp - Source/Pokemon/Navigation/Pokemon_MapSet.cpp - Source/Pokemon/Navigation/Pokemon_MapSet.h Source/Pokemon/Navigation/Pokemon_Navigation_Tests.h Source/Pokemon/Navigation/Pokemon_RouteLog.cpp Source/Pokemon/Navigation/Pokemon_RouteLog.h @@ -1470,8 +1468,6 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_StoryEvents.cpp Source/Pokemon/Navigation/Pokemon_StoryEvents.h Source/Pokemon/Navigation/Pokemon_StoryEvents_Tests.cpp - Source/Pokemon/Navigation/Pokemon_TileGrid.cpp - Source/Pokemon/Navigation/Pokemon_TileGrid.h Source/Pokemon/Navigation/Pokemon_StorySegments.cpp Source/Pokemon/Navigation/Pokemon_StorySegments.h Source/Pokemon/Navigation/Pokemon_StorySegments_Tests.cpp @@ -1546,52 +1542,6 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Resources/Pokemon_PokemonNames.h Source/Pokemon/Resources/Pokemon_PokemonSlugs.cpp Source/Pokemon/Resources/Pokemon_PokemonSlugs.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghMine.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RavagedPath.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route201.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route202.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route203.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Route204South.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghCity.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_OreburghGate.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TwinleafTown.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.h - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_MapGrids.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 - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp - Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h - Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.cpp - Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_MapGrid_Tests.h - Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp - Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleBallReader.cpp Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleBallReader.h Source/PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.cpp @@ -1672,8 +1622,28 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/PokemonBDSP_Tests.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.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_StoryMaps.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h Source/PokemonBDSP/Programs/Eggs/PokemonBDSP_EggAutonomous.cpp Source/PokemonBDSP/Programs/Eggs/PokemonBDSP_EggAutonomous.h Source/PokemonBDSP/Programs/Eggs/PokemonBDSP_EggAutonomousState.cpp From c83b4e4f663856d21626849c788a589fd7ae1784 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 13:51:05 -0800 Subject: [PATCH 05/18] BDSP navigation: slide_to_wall(), and Route 202's areas from the map's regions The planner's walk_to_wall() is now slide_to_wall(), so it no longer shares a name with the walker's walk_to_wall(), which walks on the console. story_catch_save_area() and story_after_training_area() read Route 202's regions instead of looping over its tiles. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonBDSP_AutoStory_RoutePlanner.cpp | 4 +-- .../Data/PokemonBDSP_AutoStory_RoutePlanner.h | 2 +- .../Data/PokemonBDSP_AutoStory_StoryMaps.cpp | 36 +++++++------------ ...kemonBDSP_AutoStory_RoutePlanner_Tests.cpp | 2 +- .../PokemonBDSP_AutoStory_StoryMaps_Tests.cpp | 6 ++-- 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp index 65111d657a..5952517e28 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp @@ -35,7 +35,7 @@ bool tall_grass(const StoryWorld& world, const TilePos& pos){ } -WallHit walk_to_wall(const StoryWorld& world, const TilePos& from, Direction direction){ +WallHit slide_to_wall(const StoryWorld& world, const TilePos& from, Direction direction){ WallHit hit; hit.stop = from; while (true){ @@ -269,7 +269,7 @@ std::optional to_wall_leg(const StoryWorld& world, const Spread& spre size_t longest = 0; int grass = 0; for (const TilePos& pos : spread){ - const WallHit hit = walk_to_wall(world, pos, direction); + const WallHit hit = slide_to_wall(world, pos, direction); if (!hit.anchored){ return std::nullopt; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h index f5b9d6d730..9b96713184 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h @@ -32,7 +32,7 @@ struct WallHit{ Pokemon::TilePos wall; // the first tile the player could not enter bool anchored = false; // the player is held at `stop` (see StoryWorld::at_wall()) }; -WallHit walk_to_wall(const StoryWorld& world, const Pokemon::TilePos& from, Pokemon::Direction direction); +WallHit slide_to_wall(const StoryWorld& world, const Pokemon::TilePos& from, Pokemon::Direction direction); // A straight run in one direction. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp index 6cdb9f95c2..c8dc372ab7 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp @@ -200,33 +200,23 @@ std::vector story_door_front(const char* map, const TilePos& door){ return {below.next(Direction::WEST), below, below.next(Direction::EAST)}; } -std::vector story_catch_save_area(){ - const StoryWorld& maps = story_maps(); - std::vector area; - for (int y = 25; y <= 29; y++){ - for (int x = 15; x <= 21; x++){ - const TilePos pos = maps.to_world(MAP_ROUTE_202, {x, y}); - if (maps.standable(pos)){ - area.push_back(pos); - } - } +namespace{ +// A region of Route 202, in world tiles of story_maps(). +std::vector route202_region(const char* region){ + std::vector tiles; + for (const TilePos& pos : map_region("Route202", region)){ + tiles.push_back(story_maps().to_world(MAP_ROUTE_202, pos)); } - return area; + return tiles; +} +} + +std::vector story_catch_save_area(){ + return route202_region("catch_save_area"); } std::vector story_after_training_area(){ - const StoryWorld& maps = story_maps(); - const TilePos catch_spot = maps.to_world(MAP_ROUTE_202, map_point("Route202", "catch_spot")); - std::vector area; - for (int y = catch_spot.y - 2; y <= catch_spot.y + 2; y++){ - for (int x = catch_spot.x - 1; x <= catch_spot.x + 1; x++){ - // The rows below the catch spot are trees in BDSP. - if (maps.standable({x, y})){ - area.push_back({x, y}); - } - } - } - return area; + return route202_region("after_training_area"); } std::vector story_trainer_sights(){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp index ea74104879..fd19365abe 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp @@ -74,7 +74,7 @@ class Test_WalkToWall : public UnitTest{ .stop = {0, 2}, .tiles = 2, .anchored = true}, }; for (const WallCase& item : cases){ - const WallHit hit = walk_to_wall(make_world(item.rows), item.from, item.direction); + const WallHit hit = slide_to_wall(make_world(item.rows), item.from, item.direction); if (!(hit.stop == item.stop) || hit.tiles != item.tiles || hit.anchored != item.anchored){ return std::format("{}: stops at {} after {} tiles, anchored {}; expected {} after {}, anchored {}.", item.name, Pokemon::to_string(hit.stop), hit.tiles, hit.anchored, Pokemon::to_string(item.stop), item.tiles, item.anchored); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp index 36c0bdb348..ec79f83bb0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp @@ -52,8 +52,8 @@ class Test_Route202CatchGrass : public UnitTest{ virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ const StoryWorld route = alone("Route202"); for (int x = 15; x <= 20; x++){ - const WallHit up = walk_to_wall(route, {x, 27}, Direction::NORTH); - const WallHit down = walk_to_wall(route, {x, 25}, Direction::SOUTH); + const WallHit up = slide_to_wall(route, {x, 27}, Direction::NORTH); + const WallHit down = slide_to_wall(route, {x, 25}, Direction::SOUTH); if (!(up.stop == TilePos{x, 25}) || !(down.stop == TilePos{x, 27})){ return std::format("Catch patch column {}: north from row 27 stops at {}, south from row 25 at {}; expected rows 25 and 27, between tree rows.", x, Pokemon::to_string(up.stop), Pokemon::to_string(down.stop)); @@ -177,7 +177,7 @@ class Test_OreburghGymColumn : public UnitTest{ if (!gym.occupied(roark)){ return std::string("Nobody stands on Roark's tile."); } - const WallHit up = walk_to_wall(gym, entrance, Direction::NORTH); + const WallHit up = slide_to_wall(gym, entrance, Direction::NORTH); if (!(up.wall == roark)){ return "North from the entrance stops at " + Pokemon::to_string(up.stop) + ", not in front of Roark."; } From fd2202ddd66369a7e2052dec4847662ac25f6c4b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 14:35:52 -0800 Subject: [PATCH 06/18] BDSP navigation tests: name every field, or give it a default Windows clang -Werror,-Wmissing-designated-field-initializers rejected test rows that left fields out. The rows' optional fields now have default member initializers, and the MapObjects built in the story world tests name all their fields. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- ...okemonBDSP_AutoStory_RoutePlanner_Tests.cpp | 6 +++--- .../PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp index fd19365abe..15a8111056 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp @@ -53,9 +53,9 @@ std::string describe(const std::vector& legs){ struct WallCase{ std::string name; std::vector rows; - TilePos from; + TilePos from = {}; Direction direction = Direction::EAST; - TilePos stop; + TilePos stop = {}; size_t tiles = 0; bool anchored = false; }; @@ -117,7 +117,7 @@ struct RobustCase{ std::string name; std::vector from; TilePos goal; - RobustPlanCosts costs; + RobustPlanCosts costs = {}; // The plan as to_string() writes it, or empty when there is none. std::string legs; }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index 66e345f140..e409fcceb3 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -43,10 +43,16 @@ MapData make_map( } } for (const TilePos& pos : standing){ - map.objects.push_back({.name = "standing", .x = pos.x, .y = pos.y}); + map.objects.push_back({ + .name = "standing", .kind = Pokemon::ObjectKind::NPC, .x = pos.x, .y = pos.y, + .facing = std::nullopt, .wander = std::nullopt, + }); } for (const TilePos& pos : wandering){ - map.objects.push_back({.name = "wandering", .x = pos.x, .y = pos.y, .wander = Pokemon::WanderBox{pos.x, pos.y, pos.x, pos.y}}); + map.objects.push_back({ + .name = "wandering", .kind = Pokemon::ObjectKind::NPC, .x = pos.x, .y = pos.y, + .facing = std::nullopt, .wander = Pokemon::WanderBox{pos.x, pos.y, pos.x, pos.y}, + }); } return map; } @@ -63,11 +69,11 @@ StoryWorld make_world(const MapData& map){ struct StepCase{ std::string name; std::vector rows; - std::vector standing; - std::vector wandering; - TilePos from; + std::vector standing = {}; + std::vector wandering = {}; + TilePos from = {}; Direction direction = Direction::NORTH; - std::optional lands; + std::optional lands = std::nullopt; bool at_wall = false; }; From 282212e5acf136d557493a5f631f671b1a846dab Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 14:37:47 -0800 Subject: [PATCH 07/18] BDSP navigation: change grid cells with Pokemon::cell_at() #122 made Grid's at() read-only and added cell_at() for writes; the story world and the Ravaged Path's smashed rocks follow. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp | 2 +- .../AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp index c8dc372ab7..02ab715514 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp @@ -146,7 +146,7 @@ StoryWorld ravaged_path_maps(const std::vector& smashed){ MapData map = story_map("RavagedPath"); for (const TilePos& rock : smashed){ if (map.tiles.contains(rock)){ - map.tiles.at(rock) = Pokemon::TileKind::OPEN; + Pokemon::cell_at(map.tiles, rock) = Pokemon::TileKind::OPEN; } } StoryWorld maps; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index 20012b1bcd..1786780d6c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -106,11 +106,11 @@ void StoryWorld::rebuild(){ const TilePos corner{iter->offset.x - low.x, iter->offset.y - low.y}; for (int y = 0; y < iter->tiles.height; y++){ for (int x = 0; x < iter->tiles.width; x++){ - m_cells.at({corner.x + x, corner.y + y}) = Cell{true, iter->tiles.at({x, y}), false}; + Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}) = Cell{true, iter->tiles.at({x, y}), false}; } } for (const TilePos& pos : iter->occupied){ - m_cells.at({corner.x + pos.x, corner.y + pos.y}).occupied = true; + Pokemon::cell_at(m_cells, {corner.x + pos.x, corner.y + pos.y}).occupied = true; } } for (const TilePos& pos : m_blocked){ @@ -135,7 +135,7 @@ StoryWorld::Cell* StoryWorld::cell(const TilePos& pos){ if (!m_cells.contains(pos) || !m_cells.at(pos).covered){ return nullptr; } - return &m_cells.at(pos); + return &Pokemon::cell_at(m_cells, pos); } From b798ef3ec1299055ae508abf5f8d596971b69623 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 14:40:14 -0800 Subject: [PATCH 08/18] BDSP navigation: StoryWorld keeps seven methods; walking rules are free functions Code health: StoryWorld had 14 public methods, and its overlap check and rebuild nested five deep. covered(), standable(), step(), at_wall() and describe() now take the world as their first argument and read it through tile() and occupied(); width() and height() are gone. The overlap check and the painting of a map are split out. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonBDSP_AutoStory_RoutePlanner.cpp | 20 +-- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 125 ++++++++++-------- .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 40 +++--- .../PokemonBDSP_AutoStory_StoryMaps_Tests.cpp | 14 +- ...PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 16 +-- 5 files changed, 115 insertions(+), 100 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp index 5952517e28..d836670c06 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp @@ -40,10 +40,10 @@ WallHit slide_to_wall(const StoryWorld& world, const TilePos& from, Direction di hit.stop = from; while (true){ const TilePos before = hit.stop; - const std::optional next = world.step(before, direction); + const std::optional next = step(world, before, direction); if (!next){ hit.wall = before.next(direction); - hit.anchored = world.at_wall(before, direction); + hit.anchored = at_wall(world, before, direction); return hit; } hit.tiles += distance(*next, before); @@ -72,7 +72,7 @@ class StoryWorldModel{ {} std::optional> press(const State& pos, Direction direction) const{ - const std::optional next = m_world.step(pos, direction); + const std::optional next = step(m_world, pos, direction); if (!next){ return std::nullopt; } @@ -86,7 +86,7 @@ class StoryWorldModel{ return step; } bool held_at(const State& pos, Direction direction) const{ - return m_world.at_wall(pos, direction); + return at_wall(m_world, pos, direction); } private: @@ -95,7 +95,7 @@ class StoryWorldModel{ }; void check_standable(const StoryWorld& world, const TilePos& from, const TilePos& to){ - if (!world.standable(from) || !world.standable(to)){ + if (!standable(world, from) || !standable(world, to)){ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format( "Route ends must be standable: {} -> {}.", Pokemon::to_string(from), Pokemon::to_string(to) )); @@ -137,7 +137,7 @@ std::vector sight_tiles(const StoryWorld& world, const TrainerSight& tr TilePos pos = trainer.pos; for (int i = 0; i < trainer.range; i++){ pos = pos.next(trainer.facing); - if (!world.standable(pos)){ + if (!standable(world, pos)){ break; } tiles.push_back(pos); @@ -184,7 +184,7 @@ std::vector trace_legs( size_t travelled = 0; while (travelled < leg.tiles){ const TilePos pos = tiles.back(); - const std::optional next = world.step(pos, leg.direction); + const std::optional next = step(world, pos, leg.direction); if (!next){ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format( "Leg {} is stopped at {}.", to_string(leg), Pokemon::to_string(pos) @@ -223,9 +223,9 @@ std::optional step_tiles(const StoryWorld& world, TilePos from, Directi Stepped stepped; int travelled = 0; while (travelled < tiles){ - const std::optional next = world.step(from, direction); + const std::optional next = step(world, from, direction); if (!next){ - if (!world.at_wall(from, direction)){ + if (!at_wall(world, from, direction)){ return std::nullopt; } break; @@ -420,7 +420,7 @@ std::optional> plan_robust_route( const RobustPlanCosts& costs ){ for (const TilePos& pos : from){ - if (!world.standable(pos)){ + if (!standable(world, pos)){ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Route starts must be standable: " + Pokemon::to_string(pos) + "."); } } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index 1786780d6c..656c684217 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -57,30 +57,37 @@ void StoryWorld::add(std::string name, const Pokemon::MapData& map, const TilePo placed.occupied.push_back({object.x, object.y}); } } - check_overlap(placed.name, placed); + check_overlap(placed); m_maps.push_back(std::move(placed)); rebuild(); } // Map images show a border of trees past their edges, so two maps may // share walls with nobody on them, but nothing else. -void StoryWorld::check_overlap(const std::string& name, const Placed& map) const{ - const auto free_wall = [](const Placed& placed, const TilePos& pos){ - return placed.tiles.at(pos) == TileKind::WALL && - std::find(placed.occupied.begin(), placed.occupied.end(), pos) == placed.occupied.end(); +std::optional StoryWorld::conflict(const Placed& map, const Placed& placed){ + const auto free_wall = [](const Placed& in, const TilePos& pos){ + return in.tiles.at(pos) == TileKind::WALL && + std::find(in.occupied.begin(), in.occupied.end(), pos) == in.occupied.end(); }; - for (const Placed& placed : m_maps){ - for (int y = 0; y < map.tiles.height; y++){ - for (int x = 0; x < map.tiles.width; x++){ - const TilePos other{map.offset.x + x - placed.offset.x, map.offset.y + y - placed.offset.y}; - if (placed.tiles.contains(other) && (!free_wall(map, {x, y}) || !free_wall(placed, other))){ - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format( - "Map {} overlaps {} at its tile {}.", name, placed.name, Pokemon::to_string(TilePos{x, y}) - )); - } + for (int y = 0; y < map.tiles.height; y++){ + for (int x = 0; x < map.tiles.width; x++){ + const TilePos other{map.offset.x + x - placed.offset.x, map.offset.y + y - placed.offset.y}; + if (placed.tiles.contains(other) && (!free_wall(map, {x, y}) || !free_wall(placed, other))){ + return TilePos{x, y}; } } } + return std::nullopt; +} + +void StoryWorld::check_overlap(const Placed& map) const{ + for (const Placed& placed : m_maps){ + if (const std::optional at = conflict(map, placed)){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format( + "Map {} overlaps {} at its tile {}.", map.name, placed.name, Pokemon::to_string(*at) + )); + } + } } void StoryWorld::rebuild(){ @@ -103,15 +110,7 @@ void StoryWorld::rebuild(){ m_cells = Pokemon::Grid{high.x - low.x, high.y - low.y, {}}; m_cells.cells.resize((size_t)m_cells.width * m_cells.height); for (auto iter = m_maps.rbegin(); iter != m_maps.rend(); ++iter){ - const TilePos corner{iter->offset.x - low.x, iter->offset.y - low.y}; - for (int y = 0; y < iter->tiles.height; y++){ - for (int x = 0; x < iter->tiles.width; x++){ - Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}) = Cell{true, iter->tiles.at({x, y}), false}; - } - } - for (const TilePos& pos : iter->occupied){ - Pokemon::cell_at(m_cells, {corner.x + pos.x, corner.y + pos.y}).occupied = true; - } + paint(*iter, {iter->offset.x - low.x, iter->offset.y - low.y}); } for (const TilePos& pos : m_blocked){ if (Cell* blocked = cell(pos)){ @@ -125,6 +124,17 @@ void StoryWorld::rebuild(){ } } +void StoryWorld::paint(const Placed& placed, const TilePos& corner){ + for (int y = 0; y < placed.tiles.height; y++){ + for (int x = 0; x < placed.tiles.width; x++){ + Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}) = Cell{true, placed.tiles.at({x, y}), false}; + } + } + for (const TilePos& pos : placed.occupied){ + Pokemon::cell_at(m_cells, {corner.x + pos.x, corner.y + pos.y}).occupied = true; + } +} + const StoryWorld::Cell* StoryWorld::cell(const TilePos& pos) const{ if (!m_cells.contains(pos) || !m_cells.at(pos).covered){ return nullptr; @@ -139,10 +149,6 @@ StoryWorld::Cell* StoryWorld::cell(const TilePos& pos){ } -bool StoryWorld::covered(const TilePos& pos) const{ - return cell(pos) != nullptr; -} - std::optional StoryWorld::tile(const TilePos& pos) const{ const Cell* found = cell(pos); if (found == nullptr){ @@ -156,33 +162,6 @@ bool StoryWorld::occupied(const TilePos& pos) const{ return found != nullptr && found->occupied; } -bool StoryWorld::standable(const TilePos& pos) const{ - const Cell* found = cell(pos); - return found != nullptr && !found->occupied && - (found->tile == TileKind::OPEN || found->tile == TileKind::TALL_GRASS); -} - -std::optional StoryWorld::step(const TilePos& from, Direction direction) const{ - const TilePos next = from.next(direction); - if (standable(next)){ - return next; - } - const Cell* found = cell(next); - if (found == nullptr || found->occupied || ledge_direction(found->tile) != direction){ - return std::nullopt; - } - const TilePos landing = next.next(direction); - if (standable(landing)){ - return landing; - } - return std::nullopt; -} - -bool StoryWorld::at_wall(const TilePos& pos, Direction direction) const{ - const std::optional next = tile(pos.next(direction)); - return next && *next != TileKind::DOOR && !step(pos, direction).has_value(); -} - void StoryWorld::block(const TilePos& pos){ if (Cell* found = cell(pos)){ found->occupied = true; @@ -217,10 +196,42 @@ std::optional StoryWorld::to_local(const TilePos& world) const{ return std::nullopt; } -std::string StoryWorld::describe(const TilePos& world) const{ - const std::optional local = to_local(world); + + +bool covered(const StoryWorld& world, const TilePos& pos){ + return world.tile(pos).has_value(); +} + +bool standable(const StoryWorld& world, const TilePos& pos){ + const std::optional tile = world.tile(pos); + return tile && (*tile == TileKind::OPEN || *tile == TileKind::TALL_GRASS) && !world.occupied(pos); +} + +std::optional step(const StoryWorld& world, const TilePos& from, Direction direction){ + const TilePos next = from.next(direction); + if (standable(world, next)){ + return next; + } + const std::optional tile = world.tile(next); + if (!tile || world.occupied(next) || ledge_direction(*tile) != direction){ + return std::nullopt; + } + const TilePos landing = next.next(direction); + if (standable(world, landing)){ + return landing; + } + return std::nullopt; +} + +bool at_wall(const StoryWorld& world, const TilePos& pos, Direction direction){ + const std::optional next = world.tile(pos.next(direction)); + return next && *next != TileKind::DOOR && !step(world, pos, direction).has_value(); +} + +std::string describe(const StoryWorld& world, const TilePos& pos){ + const std::optional local = world.to_local(pos); if (!local){ - return "world " + Pokemon::to_string(world); + return "world " + Pokemon::to_string(pos); } return local->map + " " + Pokemon::to_string(local->pos); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index 236e1972b2..1953009657 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -44,27 +44,12 @@ class StoryWorld{ // maps together. void add(std::string name, const Pokemon::MapData& map, const Pokemon::TilePos& offset); - int width() const{ return m_cells.width; } - int height() const{ return m_cells.height; } - - // Whether a map holds this world tile. - bool covered(const Pokemon::TilePos& pos) const; // The tile, or nothing off the maps. std::optional tile(const Pokemon::TilePos& pos) const; // Whether someone or something stands still on this tile, or it was // blocked with block(). bool occupied(const Pokemon::TilePos& pos) const; - // Whether the player can stand on this tile. - bool standable(const Pokemon::TilePos& pos) const; - // Where one step from `from` lands, or nothing if the player is stopped. - // A step onto a ledge the arrow's way hops to the tile past it. - std::optional step(const Pokemon::TilePos& from, Pokemon::Direction direction) const; - // Whether a step from `pos` is refused by a tile that holds the player - // in place. Doors and tiles off the maps are not walls: walking into a - // door enters the building, and ground off the maps may be an exit. - bool at_wall(const Pokemon::TilePos& pos, Pokemon::Direction direction) const; - // Blocks a tile found in the way on the console. Tiles off the maps // are left alone. void block(const Pokemon::TilePos& pos); @@ -76,8 +61,6 @@ class StoryWorld{ Pokemon::TilePos to_world(const std::string& map, const Pokemon::TilePos& local) const; // The map that holds a world tile, or nothing between maps. std::optional to_local(const Pokemon::TilePos& world) const; - // "Route 201 (45, 3)", or "world (x, y)" if no map holds it. - std::string describe(const Pokemon::TilePos& world) const; private: struct Placed{ @@ -92,8 +75,12 @@ class StoryWorld{ bool occupied = false; }; - void check_overlap(const std::string& name, const Placed& map) const; + void check_overlap(const Placed& map) const; + // The first tile of `map` that `placed` holds as anything but a wall + // with nobody on it, or nothing. + static std::optional conflict(const Placed& map, const Placed& placed); void rebuild(); + void paint(const Placed& placed, const Pokemon::TilePos& corner); const Cell* cell(const Pokemon::TilePos& pos) const; Cell* cell(const Pokemon::TilePos& pos); @@ -105,6 +92,23 @@ class StoryWorld{ }; +// The rules of walking on a story world, from its tiles. + +// Whether a map holds this world tile. +bool covered(const StoryWorld& world, const Pokemon::TilePos& pos); +// Whether the player can stand on this tile. +bool standable(const StoryWorld& world, const Pokemon::TilePos& pos); +// Where one step from `from` lands, or nothing if the player is stopped. +// A step onto a ledge the arrow's way hops to the tile past it. +std::optional step(const StoryWorld& world, const Pokemon::TilePos& from, Pokemon::Direction direction); +// Whether a step from `pos` is refused by a tile that holds the player +// in place. Doors and tiles off the maps are not walls: walking into a +// door enters the building, and ground off the maps may be an exit. +bool at_wall(const StoryWorld& world, const Pokemon::TilePos& pos, Pokemon::Direction direction); +// "Route 201 (45, 3)", or "world (x, y)" if no map holds it. +std::string describe(const StoryWorld& world, const Pokemon::TilePos& pos); + + } } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp index ec79f83bb0..3c6d8487cb 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp @@ -81,7 +81,7 @@ class Test_Route202CatchGrass : public UnitTest{ } for (const TilePos& pos : legs->back().after){ if (!in_grass(pos)){ - return "From " + name + " to the catch grass: the walk may end on " + maps.describe(pos) + ", not in the grass."; + return "From " + name + " to the catch grass: the walk may end on " + describe(maps, pos) + ", not in the grass."; } } logger.log(std::format("From {} to the catch grass: {} legs, ending in the grass.", name, legs->size())); @@ -109,7 +109,7 @@ class Test_SandgemCenterApproach : public UnitTest{ } TilePos pos = sign.next(Direction::SOUTH); for (int tap = 0; tap < sign.x - door.x; tap++){ - const std::optional next = town.step(pos, Direction::WEST); + const std::optional next = step(town, pos, Direction::WEST); if (!next){ return "West from " + Pokemon::to_string(pos) + " is blocked."; } @@ -146,12 +146,12 @@ class Test_TrainingToSandgem : public UnitTest{ } for (const std::vector& from : starts){ const auto legs = plan_robust_route(maps, from, [&](const TilePos& pos){ return pos == entry; }, RobustPlanCosts()); - const std::string name = from.size() == 1 ? maps.describe(from[0]) : "the whole training area"; + const std::string name = from.size() == 1 ? describe(maps, from[0]) : "the whole training area"; if (!legs || legs->empty()){ return "From " + name + " into Sandgem: no plan."; } if (legs->back().after.size() != 1 || !(legs->back().after[0] == entry)){ - return "From " + name + " into Sandgem: the plan does not end on " + maps.describe(entry) + "."; + return "From " + name + " into Sandgem: the plan does not end on " + describe(maps, entry) + "."; } logger.log(std::format("From {} into Sandgem: {} legs.", name, legs->size())); } @@ -171,7 +171,7 @@ class Test_OreburghGymColumn : public UnitTest{ const StoryWorld gym = alone("OreburghGym"); const TilePos entrance = map_point("OreburghGym", "entrance"); const TilePos roark = map_point("OreburghGym", "roark"); - if (!gym.standable(entrance) || gym.tile(entrance.next(Direction::SOUTH)) != TileKind::DOOR){ + if (!standable(gym, entrance) || gym.tile(entrance.next(Direction::SOUTH)) != TileKind::DOOR){ return std::string("The entrance tile is not standable above the door."); } if (!gym.occupied(roark)){ @@ -213,7 +213,7 @@ class Test_RouteRecords : public UnitTest{ if (!record.traceable || !record.start){ continue; } - if (!world.standable(*record.start)){ + if (!standable(world, *record.start)){ return name + ": starts on " + Pokemon::to_string(*record.start) + ", where nobody can stand."; } std::vector counted; @@ -225,7 +225,7 @@ class Test_RouteRecords : public UnitTest{ } try{ const TilePos end = trace_legs(world, *record.start, counted).back(); - logger.log(std::format("{}: {} counted legs to {}.", name, counted.size(), world.describe(end))); + logger.log(std::format("{}: {} counted legs to {}.", name, counted.size(), describe(world, end))); }catch (InternalProgramError& e){ return name + ": " + e.message(); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index e409fcceb3..3fd80e93b8 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -101,12 +101,12 @@ class Test_StoryWorldSteps : public UnitTest{ }; for (const StepCase& item : cases){ const StoryWorld world = make_world(make_map(item.rows, item.standing, item.wandering)); - const std::optional lands = world.step(item.from, item.direction); + const std::optional lands = step(world, item.from, item.direction); if (lands != item.lands){ return std::format("{}: lands on {}, expected {}.", item.name, lands ? Pokemon::to_string(*lands) : "nothing", item.lands ? Pokemon::to_string(*item.lands) : "nothing"); } - if (world.at_wall(item.from, item.direction) != item.at_wall){ + if (at_wall(world, item.from, item.direction) != item.at_wall){ return std::format("{}: at_wall() is {}, expected {}.", item.name, !item.at_wall, item.at_wall); } } @@ -133,11 +133,11 @@ class Test_StoryWorldJoin : public UnitTest{ {{2, 2}, "world (2, 2)"}, }; for (const auto& [pos, text] : described){ - if (world.describe(pos) != text){ - return std::format("{}: described as \"{}\", expected \"{}\".", Pokemon::to_string(pos), world.describe(pos), text); + if (describe(world, pos) != text){ + return std::format("{}: described as \"{}\", expected \"{}\".", Pokemon::to_string(pos), describe(world, pos), text); } } - if (world.width() != 3 || world.height() != 3 || world.covered({2, 2}) || !world.standable({2, 1})){ + if (!covered(world, {0, 2}) || covered(world, {3, 0}) || covered(world, {0, 3}) || covered(world, {2, 2}) || !standable(world, {2, 1})){ return std::string("The joined world is not 3 x 3 with East's grass at (2, 1) and nothing at (2, 2)."); } if (!(world.to_world("East", {0, 0}) == TilePos{1, 0})){ @@ -168,16 +168,16 @@ class Test_StoryWorldBlockUncover : public UnitTest{ world.add("Road", make_map({"...."}), {0, 0}); world.block({1, 0}); world.uncover({2, 0}); - if (world.step({0, 0}, Direction::EAST) || !world.at_wall({0, 0}, Direction::EAST)){ + if (step(world, {0, 0}, Direction::EAST) || !at_wall(world, {0, 0}, Direction::EAST)){ return std::string("A blocked tile is not a wall."); } - if (world.covered({2, 0}) || world.at_wall({3, 0}, Direction::WEST)){ + if (covered(world, {2, 0}) || at_wall(world, {3, 0}, Direction::WEST)){ return std::string("An uncovered tile is still on the map, or a wall."); } world.add("North", make_map({"#"}), {0, -1}); const TilePos blocked = world.to_world("Road", {1, 0}); const TilePos uncovered = world.to_world("Road", {2, 0}); - if (!world.occupied(blocked) || world.covered(uncovered) || !world.standable(world.to_world("Road", {3, 0}))){ + if (!world.occupied(blocked) || covered(world, uncovered) || !standable(world, world.to_world("Road", {3, 0}))){ return std::string("Adding a map lost the blocked or uncovered tile."); } return true; From b585b8c6eaed812df5acd36a55ac4d8cd09fdf6c Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 15:24:38 -0800 Subject: [PATCH 09/18] BDSP navigation: Segment 00 tests header in CRLF Like every other .h in the repo; line endings only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonBDSP_AutoStory_Segment00_Tests.h | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h index 7e501479e0..1471536bd4 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h @@ -1,27 +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 maps and the -// scenes' trigger rectangles. -void add_tests_AutoStory_Segment00(UnitTestDatabase& database); - - - -} -} -} -#endif +/* 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 maps and the +// scenes' trigger rectangles. +void add_tests_AutoStory_Segment00(UnitTestDatabase& database); + + + +} +} +} +#endif From 2daaa60dd271dce793ac3d49aa252478bd64ade6 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 19:58:44 -0800 Subject: [PATCH 10/18] BDSP navigation: people on the maps are no wall to stop against A leg to a wall that ends against someone standing still stops there, but they may turn and talk or walk off: r29 ran east into Mom, who talked. Tiles blocked on the console stay walls. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 16 +++++++++++++--- .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 3 +++ .../PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index 656c684217..fade601390 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -127,11 +127,13 @@ void StoryWorld::rebuild(){ void StoryWorld::paint(const Placed& placed, const TilePos& corner){ for (int y = 0; y < placed.tiles.height; y++){ for (int x = 0; x < placed.tiles.width; x++){ - Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}) = Cell{true, placed.tiles.at({x, y}), false}; + Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}) = Cell{true, placed.tiles.at({x, y}), false, false}; } } for (const TilePos& pos : placed.occupied){ - Pokemon::cell_at(m_cells, {corner.x + pos.x, corner.y + pos.y}).occupied = true; + Cell& standing = Pokemon::cell_at(m_cells, {corner.x + pos.x, corner.y + pos.y}); + standing.occupied = true; + standing.person = true; } } @@ -162,6 +164,11 @@ bool StoryWorld::occupied(const TilePos& pos) const{ return found != nullptr && found->occupied; } +bool StoryWorld::person(const TilePos& pos) const{ + const Cell* found = cell(pos); + return found != nullptr && found->person; +} + void StoryWorld::block(const TilePos& pos){ if (Cell* found = cell(pos)){ found->occupied = true; @@ -223,9 +230,12 @@ std::optional step(const StoryWorld& world, const TilePos& from, Direct return std::nullopt; } +// Someone standing in the way stops us too, but is no wall to stop against: +// they may turn and talk, or walk off (r29 ran east into Mom, who talked). bool at_wall(const StoryWorld& world, const TilePos& pos, Direction direction){ const std::optional next = world.tile(pos.next(direction)); - return next && *next != TileKind::DOOR && !step(world, pos, direction).has_value(); + return next && *next != TileKind::DOOR && !world.person(pos.next(direction)) && + !step(world, pos, direction).has_value(); } std::string describe(const StoryWorld& world, const TilePos& pos){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index 1953009657..3e660cfcfb 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -49,6 +49,8 @@ class StoryWorld{ // Whether someone or something stands still on this tile, or it was // blocked with block(). bool occupied(const Pokemon::TilePos& pos) const; + // Whether one of the maps' people stands on this tile (not a block()). + bool person(const Pokemon::TilePos& pos) const; // Blocks a tile found in the way on the console. Tiles off the maps // are left alone. @@ -73,6 +75,7 @@ class StoryWorld{ bool covered = false; Pokemon::TileKind tile = Pokemon::TileKind::WALL; bool occupied = false; + bool person = false; }; void check_overlap(const Placed& map) const; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index 3fd80e93b8..3531d72fd9 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -96,7 +96,7 @@ class Test_StoryWorldSteps : public UnitTest{ {.name = "a west ledge hops west", .rows = {".<."}, .from = {2, 0}, .direction = Direction::WEST, .lands = TilePos{0, 0}}, {.name = "a west ledge stops east", .rows = {".<."}, .direction = Direction::EAST, .at_wall = true}, {.name = "a ledge onto a wall stops", .rows = {".", "v", "#"}, .direction = Direction::SOUTH, .at_wall = true}, - {.name = "a person standing still", .rows = {".", "."}, .standing = {{0, 0}}, .from = {0, 1}, .at_wall = true}, + {.name = "a person standing still", .rows = {".", "."}, .standing = {{0, 0}}, .from = {0, 1}, .at_wall = false}, {.name = "a wanderer does not block", .rows = {".", "."}, .wandering = {{0, 0}}, .from = {0, 1}, .lands = TilePos{0, 0}}, }; for (const StepCase& item : cases){ From aade8837765d14625e9c6ddc7899e8fad260ec26 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 20:00:12 -0800 Subject: [PATCH 11/18] BDSP navigation: occupied() tells people from blocked tiles, in StoryWorld's seven methods Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 21 +++++++------------ .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 16 +++++++------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index fade601390..df99467c0f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -114,7 +114,7 @@ void StoryWorld::rebuild(){ } for (const TilePos& pos : m_blocked){ if (Cell* blocked = cell(pos)){ - blocked->occupied = true; + blocked->occupant = BLOCKED; } } for (const TilePos& pos : m_uncovered){ @@ -127,13 +127,11 @@ void StoryWorld::rebuild(){ void StoryWorld::paint(const Placed& placed, const TilePos& corner){ for (int y = 0; y < placed.tiles.height; y++){ for (int x = 0; x < placed.tiles.width; x++){ - Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}) = Cell{true, placed.tiles.at({x, y}), false, false}; + Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}) = Cell{true, placed.tiles.at({x, y}), NOBODY}; } } for (const TilePos& pos : placed.occupied){ - Cell& standing = Pokemon::cell_at(m_cells, {corner.x + pos.x, corner.y + pos.y}); - standing.occupied = true; - standing.person = true; + Pokemon::cell_at(m_cells, {corner.x + pos.x, corner.y + pos.y}).occupant = PERSON; } } @@ -159,19 +157,14 @@ std::optional StoryWorld::tile(const TilePos& pos) const{ return found->tile; } -bool StoryWorld::occupied(const TilePos& pos) const{ +StoryWorld::Occupant StoryWorld::occupied(const TilePos& pos) const{ const Cell* found = cell(pos); - return found != nullptr && found->occupied; -} - -bool StoryWorld::person(const TilePos& pos) const{ - const Cell* found = cell(pos); - return found != nullptr && found->person; + return found == nullptr ? NOBODY : found->occupant; } void StoryWorld::block(const TilePos& pos){ if (Cell* found = cell(pos)){ - found->occupied = true; + found->occupant = BLOCKED; m_blocked.push_back(pos); } } @@ -234,7 +227,7 @@ std::optional step(const StoryWorld& world, const TilePos& from, Direct // they may turn and talk, or walk off (r29 ran east into Mom, who talked). bool at_wall(const StoryWorld& world, const TilePos& pos, Direction direction){ const std::optional next = world.tile(pos.next(direction)); - return next && *next != TileKind::DOOR && !world.person(pos.next(direction)) && + return next && *next != TileKind::DOOR && world.occupied(pos.next(direction)) != StoryWorld::PERSON && !step(world, pos, direction).has_value(); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index 3e660cfcfb..e78a7ee5ee 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -46,11 +46,14 @@ class StoryWorld{ // The tile, or nothing off the maps. std::optional tile(const Pokemon::TilePos& pos) const; - // Whether someone or something stands still on this tile, or it was - // blocked with block(). - bool occupied(const Pokemon::TilePos& pos) const; - // Whether one of the maps' people stands on this tile (not a block()). - bool person(const Pokemon::TilePos& pos) const; + // Who or what stands still on a tile: one of the maps' people, or a + // tile blocked with block(). NOBODY is false, the others true. + enum Occupant{ + NOBODY = 0, + PERSON, + BLOCKED, + }; + Occupant occupied(const Pokemon::TilePos& pos) const; // Blocks a tile found in the way on the console. Tiles off the maps // are left alone. @@ -74,8 +77,7 @@ class StoryWorld{ struct Cell{ bool covered = false; Pokemon::TileKind tile = Pokemon::TileKind::WALL; - bool occupied = false; - bool person = false; + Occupant occupant = NOBODY; }; void check_overlap(const Placed& map) const; From 058c104c0943715108f47290a536ea3d44538e96 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 1 Nov 2026 21:29:34 -0800 Subject: [PATCH 12/18] BDSP maps: the lab's door mat in Sandgem, a row below its door A run west along row 11 went into the lab at (8, 11) (r41, r42). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonBDSP/Programs/AutoStory/Maps/SandgemTown.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/SandgemTown.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/SandgemTown.json index 4f7a4e61b4..61111248ec 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/SandgemTown.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Maps/SandgemTown.json @@ -1,6 +1,6 @@ { "name": "SandgemTown", - "source": {"decomp_file": "pret/pokediamond: files/fielddata/land_data/land_data_release/narc_0007.bin, files/fielddata/land_data/land_data_release/narc_0173.bin; zone_event narc_0396", "revision": "default branch", "date": "2026-10-31"}, + "source": {"decomp_file": "pret/pokediamond: files/fielddata/land_data/land_data_release/narc_0007.bin, files/fielddata/land_data/land_data_release/narc_0173.bin; zone_event narc_0396; console: the lab's door mat (8, 11) takes us in from the side (r41, r42)", "revision": "default branch", "date": "2026-10-31"}, "tiles": [ "########################......####", "########################......####", @@ -13,7 +13,7 @@ "####################......########", "####################......########", "########D##....##D##S....S#D######", - ".....S........................####", + ".....S..D.....................####", "..............................####", "..............................####", "..............................####", From d5c17a055158b4991fec5effb1a4b5962900248d Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 07:17:20 -0800 Subject: [PATCH 13/18] BDSP navigation: build against the new MapData tile kinds and fields nav/shared added the tile kinds OUTSIDE and CLOSED_*, renamed WanderBox to TileBox and gave MapObject trainer and hide_flag. None of the new kinds is a ledge; BDSP maps don't use their glyphs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 5 +++++ .../AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index df99467c0f..9ae90edb75 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -37,6 +37,11 @@ std::optional ledge_direction(TileKind tile){ case TileKind::WATER: case TileKind::DOOR: case TileKind::SIGN: + case TileKind::OUTSIDE: + case TileKind::CLOSED_NORTH: + case TileKind::CLOSED_SOUTH: + case TileKind::CLOSED_WEST: + case TileKind::CLOSED_EAST: return std::nullopt; } throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown TileKind."); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index 3531d72fd9..d297d2be99 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -46,12 +46,14 @@ MapData make_map( map.objects.push_back({ .name = "standing", .kind = Pokemon::ObjectKind::NPC, .x = pos.x, .y = pos.y, .facing = std::nullopt, .wander = std::nullopt, + .trainer = std::nullopt, .hide_flag = std::nullopt, }); } for (const TilePos& pos : wandering){ map.objects.push_back({ .name = "wandering", .kind = Pokemon::ObjectKind::NPC, .x = pos.x, .y = pos.y, - .facing = std::nullopt, .wander = Pokemon::WanderBox{pos.x, pos.y, pos.x, pos.y}, + .facing = std::nullopt, .wander = Pokemon::TileBox{pos.x, pos.y, pos.x, pos.y}, + .trainer = std::nullopt, .hide_flag = std::nullopt, }); } return map; From 990a0e021715df4a257b6175230fbd7d714c8fd0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 5 Nov 2026 22:10:48 -0800 Subject: [PATCH 14/18] BDSP AutoStory nav: align with PR #231 lint conventions --- .../Data/PokemonBDSP_AutoStory_PlanCosts.cpp | 6 +- .../Data/PokemonBDSP_AutoStory_PlanCosts.h | 6 +- .../PokemonBDSP_AutoStory_RoutePlanner.cpp | 12 +- .../Data/PokemonBDSP_AutoStory_RoutePlanner.h | 12 +- .../PokemonBDSP_AutoStory_RouteRecords.cpp | 10 +- .../Data/PokemonBDSP_AutoStory_RouteRecords.h | 11 +- .../PokemonBDSP_AutoStory_Segment00Lines.cpp | 11 +- .../PokemonBDSP_AutoStory_Segment00Lines.h | 12 +- .../Data/PokemonBDSP_AutoStory_StoryMaps.cpp | 12 +- .../Data/PokemonBDSP_AutoStory_StoryMaps.h | 24 +++- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 8 +- .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 8 +- ...kemonBDSP_AutoStory_RoutePlanner_Tests.cpp | 105 ++++++++++------ ...PokemonBDSP_AutoStory_RoutePlanner_Tests.h | 6 +- .../PokemonBDSP_AutoStory_Segment00_Tests.cpp | 59 +++++++-- .../PokemonBDSP_AutoStory_Segment00_Tests.h | 6 +- .../PokemonBDSP_AutoStory_StoryMaps_Tests.cpp | 118 +++++++++++------- .../PokemonBDSP_AutoStory_StoryMaps_Tests.h | 6 +- ...PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 90 ++++++++----- .../PokemonBDSP_AutoStory_StoryWorld_Tests.h | 6 +- 20 files changed, 339 insertions(+), 189 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp index ce7b7bc124..c59cfc09a3 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp @@ -41,6 +41,6 @@ RobustPlanCosts town_plan_costs(){ -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h index 7608e59c9e..62a7167cab 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h @@ -40,7 +40,7 @@ RobustPlanCosts town_plan_costs(); -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp index d836670c06..f867e407bc 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp @@ -32,7 +32,7 @@ bool tall_grass(const StoryWorld& world, const TilePos& pos){ return world.tile(pos) == TileKind::TALL_GRASS; } -} +} // namespace WallHit slide_to_wall(const StoryWorld& world, const TilePos& from, Direction direction){ @@ -102,7 +102,7 @@ void check_standable(const StoryWorld& world, const TilePos& from, const TilePos } } -} +} // namespace std::optional> plan_tile_route( const StoryWorld& world, @@ -403,7 +403,7 @@ class RobustSearch{ std::priority_queue, EntryGreater> m_queue; }; -} +} // namespace std::optional> plan_robust_route( const StoryWorld& world, @@ -429,6 +429,6 @@ std::optional> plan_robust_route( -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h index 9b96713184..a8660a078f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h @@ -32,6 +32,7 @@ struct WallHit{ Pokemon::TilePos wall; // the first tile the player could not enter bool anchored = false; // the player is held at `stop` (see StoryWorld::at_wall()) }; +// Computes straight-line sliding movement from tile position until hitting a wall. WallHit slide_to_wall(const StoryWorld& world, const Pokemon::TilePos& from, Pokemon::Direction direction); @@ -41,8 +42,10 @@ struct TileLeg{ size_t tiles = 0; // tiles travelled; a ledge hop counts 2 bool ends_at_wall = false; // the next tile in `direction` stops the player }; +// Formats tile movement leg into human-readable string representation. std::string to_string(const TileLeg& leg); +// Cost configuration parameters for tile route planning. struct TilePlanCosts{ int per_tile = 1; int per_grass_tile = 4; // extra for each tall-grass tile entered @@ -67,6 +70,7 @@ struct TrainerSight{ Pokemon::Direction facing = Pokemon::Direction::NORTH; int range = 4; }; +// Computes straight line-of-sight tiles for a trainer. std::vector sight_tiles(const StoryWorld& world, const TrainerSight& trainer); // For each leg, the trainers whose sight line it enters. @@ -94,8 +98,10 @@ struct PlannedLeg{ TileLeg leg; std::vector after; }; +// Formats planned route leg with uncertainties into human-readable representation. std::string to_string(const PlannedLeg& leg); +// Cost configuration parameters accounting for movement execution tolerances. struct RobustPlanCosts : TilePlanCosts{ // An open leg of n tiles may end open_error + n / open_error_per tiles // short or long: on the console 7 tiles went 9. @@ -138,7 +144,7 @@ std::optional> plan_robust_route( -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #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 9736436658..2522d854c3 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp @@ -141,7 +141,7 @@ std::vector segment01_records_from_jubilife(){ }; } -} +} // namespace // 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, @@ -171,7 +171,7 @@ const std::vector& all(){ } -} -} -} -} +} // namespace RouteRecords +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h index 3097c7b65b..37105c81d8 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.h @@ -35,6 +35,7 @@ enum class LegEnd{ SCENE, // walks until a cutscene takes over }; +// Single directional leg within a recorded route with its ending condition. struct RouteLeg{ Pokemon::Direction direction; size_t tiles; @@ -46,6 +47,7 @@ struct RouteLeg{ bool exact = true; }; +// Recorded sequence of route legs associated with a story checkpoint. struct RouteRecord{ std::string checkpoint; // "01.05" std::string title; @@ -57,11 +59,12 @@ struct RouteRecord{ std::string source; // the code and the console runs behind it }; +// Returns all defined story route records across checkpoints. const std::vector& all(); -} -} -} -} +} // namespace RouteRecords +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp index 70b9d9bac1..9d7d7311ce 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp @@ -113,7 +113,8 @@ WalkedLine walked( ){ return {std::move(checkpoint), std::move(name), std::move(corners), std::move(ends_in), std::move(live_triggers)}; } -} + +} // namespace const std::vector& lines(){ static const std::vector lines{ @@ -139,7 +140,7 @@ const std::vector& lines(){ return lines; } -} -} -} -} +} // namespace Segment00Lines +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h index 940ec31426..8d794257d3 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h @@ -30,6 +30,7 @@ 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; +// Verity Lakefront overworld map name. extern const char* const MAP_VERITY_LAKEFRONT; // Twinleaf Town, Route 201, the Verity Lakefront and Sandgem Town joined on @@ -48,7 +49,9 @@ struct SceneTrigger{ int height; std::string when; // the story state it fires in }; +// Returns all scene trigger zones for Segment 00. const std::vector& scene_triggers(); +// Returns whether given map tile falls within the scene trigger zone. bool trigger_covers(const SceneTrigger& trigger, const MapTile& tile); // A line walked corner to corner: every stretch between two corners is one @@ -60,14 +63,15 @@ struct WalkedLine{ 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 }; +// Returns all pre-defined walked route lines for Segment 00. const std::vector& lines(); // The route records start and end on named points of the maps (Twinleaf // Town's house_doorstep, Route 201's barry_warning, ...), all on the lines. -} -} -} -} +} // namespace Segment00Lines +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp index 02ab715514..7934c88438 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp @@ -66,7 +66,7 @@ bool in_region(const std::string& map, const std::string& region, const TilePos& return std::find(tiles.begin(), tiles.end(), pos) != tiles.end(); } -} +} // namespace // Offsets are the maps' places in the game's world grid (the decomp's @@ -106,7 +106,7 @@ bool on_route203_west_line(const TilePos& pos){ namespace{ const TilePos JUBILIFE_EAST_CORNER{42, 12}; const int JUBILIFE_EAST_BOTTOM = 25; -} +} // namespace const StoryWorld& jubilife_east_maps(){ static const StoryWorld maps = []{ const MapData& city = story_map("JubilifeCity"); @@ -209,7 +209,7 @@ std::vector route202_region(const char* region){ } return tiles; } -} +} // namespace std::vector story_catch_save_area(){ return route202_region("catch_save_area"); @@ -294,6 +294,6 @@ std::vector route204_south_tiles_to_avoid(){ -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h index 4e355d9eff..13e7fec7fc 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h @@ -27,15 +27,25 @@ namespace PokemonBDSP{ // JSON map named without spaces ("Route 201" from Route201.json), except // MAP_ROUTE_204, which is Route204North.json. extern const char* const MAP_ROUTE_201; +// Sandgem Town overworld map name. extern const char* const MAP_SANDGEM_TOWN; +// Route 202 overworld map name. extern const char* const MAP_ROUTE_202; +// Jubilife City overworld map name. extern const char* const MAP_JUBILIFE_CITY; +// Oreburgh Mine map name. extern const char* const MAP_OREBURGH_MINE; +// Ravaged Path map name. extern const char* const MAP_RAVAGED_PATH; +// Route 204 North map name. extern const char* const MAP_ROUTE_204; +// Route 204 South map name. extern const char* const MAP_ROUTE_204_SOUTH; +// Route 203 overworld map name. extern const char* const MAP_ROUTE_203; +// Oreburgh City overworld map name. extern const char* const MAP_OREBURGH_CITY; +// Floaroma Town overworld map name. extern const char* const MAP_FLOAROMA_TOWN; // Route 201, Sandgem Town and Route 202. @@ -49,6 +59,7 @@ const StoryWorld& jubilife_maps(); // into Jubilife, so the plan ends there (no leg may leave the map) and a // walk west until Jubilife's banner shows goes on from there. const StoryWorld& route203_maps(); +// Returns whether given tile lies on the west line towards Jubilife. bool on_route203_west_line(const Pokemon::TilePos& pos); // Jubilife City's north-east corner (01.06), at its own tile coordinates: // the rest of the city is walled off, so the plan searches only the part @@ -56,7 +67,9 @@ bool on_route203_west_line(const Pokemon::TilePos& pos); // on the north road below the plaza: walking north from there goes up the // road to Route 204 (and Rowan's scene). const StoryWorld& jubilife_east_maps(); +// Returns entrance coordinates for east entrance of Jubilife. const std::vector& jubilife_east_entrance(); +// Returns whether given tile lies on the north road towards Route 204. bool on_jubilife_north_road(const Pokemon::TilePos& pos); // The Oreburgh Mine's coal room on its own (01.03). const StoryWorld& oreburgh_mine_maps(); @@ -67,6 +80,7 @@ StoryWorld ravaged_path_maps(const std::vector& smashed = {}); // Route 204's north half on its own (01.05), and whether a tile is on the // path north into Floaroma. const StoryWorld& route204_north_maps(); +// Returns whether given tile lies within the Floaroma entrance path. bool in_floaroma_path(const Pokemon::TilePos& pos); // Route 204's south half on its own (01.08): it joins the north half only @@ -75,6 +89,7 @@ const StoryWorld& route204_south_maps(); // Oreburgh City alone (01.04, 01.05), and Floaroma Town alone (01.11). const StoryWorld& oreburgh_city_maps(); +// Returns StoryWorld instance containing Floaroma Town alone. const StoryWorld& floaroma_maps(); // Whether a plan may cross this map. Towns are crossed by screen-driven @@ -114,8 +129,11 @@ std::vector story_trainer_sights(); // The trainers of a map, in its own tiles, with the sight ranges that fit // the console. A trainer who looks two ways is listed once per way. std::vector route202_trainer_sights(); +// Returns trainer sights for Route 204 North. std::vector route204_north_trainer_sights(); +// Returns trainer sights for Route 204 South. std::vector route204_south_trainer_sights(); +// Returns trainer sights for Oreburgh Gym. std::vector oreburgh_gym_trainer_sights(); // Route 204 South's tiles in the trainers' sight that a walk can avoid: @@ -124,7 +142,7 @@ std::vector route204_south_tiles_to_avoid(); -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index 9ae90edb75..c245bf283e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -47,7 +47,7 @@ std::optional ledge_direction(TileKind tile){ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown TileKind."); } -} +} // namespace void StoryWorld::add(std::string name, const Pokemon::MapData& map, const TilePos& offset){ @@ -246,6 +246,6 @@ std::string describe(const StoryWorld& world, const TilePos& pos){ -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index e78a7ee5ee..dc5b76e3c5 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -34,6 +34,8 @@ struct MapTile{ }; +// Composite coordinate space combining multiple contiguous maps into one +// traversable overworld representation. class StoryWorld{ public: // Places `map` under `name` with its tile (0,0) at `offset`. Offsets are @@ -115,7 +117,7 @@ std::string describe(const StoryWorld& world, const Pokemon::TilePos& pos); -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp index 15a8111056..11f82e3cbd 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp @@ -60,12 +60,7 @@ struct WallCase{ bool anchored = false; }; -class Test_WalkToWall : public UnitTest{ -public: - Test_WalkToWall() - : UnitTest("PokemonBDSP::AutoStory - Route planner: walking until stopped") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ +UnitTestResult test_walk_to_wall(Logger&){ const std::vector cases{ {.name = "to a wall", .rows = {"....#"}, .stop = {3, 0}, .tiles = 3, .anchored = true}, {.name = "off the map", .rows = {"...."}, .stop = {3, 0}, .tiles = 3, .anchored = false}, @@ -81,18 +76,12 @@ class Test_WalkToWall : public UnitTest{ } } return true; - } -}; +} // plan_tile_route() around a pillar: two legs, both to a wall, that trace // to the goal. -class Test_PlanTileRoute : public UnitTest{ -public: - Test_PlanTileRoute() - : UnitTest("PokemonBDSP::AutoStory - Route planner: legs to walls around a pillar") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ +UnitTestResult test_plan_tile_route(Logger& logger){ const StoryWorld world = make_world({"#####", "#...#", "#.#.#", "#...#", "#####"}); const std::optional> legs = plan_tile_route(world, {1, 1}, {3, 3}); if (!legs || legs->size() != 2 || !(*legs)[0].ends_at_wall || !(*legs)[1].ends_at_wall){ @@ -107,8 +96,7 @@ class Test_PlanTileRoute : public UnitTest{ return std::string("A route to the start is not empty."); } return true; - } -}; +} // plan_robust_route() from one or several tiles to a goal, with the open @@ -122,12 +110,7 @@ struct RobustCase{ std::string legs; }; -class Test_PlanRobustRoute : public UnitTest{ -public: - Test_PlanRobustRoute() - : UnitTest("PokemonBDSP::AutoStory - Route planner: robust plans") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ +UnitTestResult test_plan_robust_route(Logger&){ const StoryWorld world = make_world({"######", "#....#", "######"}); RobustPlanCosts exact_step; exact_step.exact_open_tiles = 1; @@ -149,18 +132,12 @@ class Test_PlanRobustRoute : public UnitTest{ return std::string("A start on a wall did not throw."); }catch (InternalProgramError&){} return true; - } -}; +} // A trainer's sight stops at the first tile the player cannot stand on, // and a leg through it is reported; a leg that is stopped throws. -class Test_TrainerSight : public UnitTest{ -public: - Test_TrainerSight() - : UnitTest("PokemonBDSP::AutoStory - Route planner: trainers' sight lines") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ +UnitTestResult test_trainer_sight(Logger&){ const StoryWorld world = make_world({".....", ".....", "..#.."}); const TrainerSight trainer{.name = "lass", .pos = {2, 0}, .facing = Direction::SOUTH, .range = 4}; if (sight_tiles(world, trainer) != std::vector{{2, 1}}){ @@ -176,20 +153,70 @@ class Test_TrainerSight : public UnitTest{ return std::string("A leg off the map did not throw."); }catch (InternalProgramError&){} return true; - } +} + + +struct RoutePlannerInput{ + std::string name; + std::function body; }; -} +struct RoutePlannerExpectation{ +}; +struct RoutePlannerCase{ + RoutePlannerInput input; + RoutePlannerExpectation expectation; +}; + +class Test_RoutePlanner : public UnitTest{ +public: + explicit Test_RoutePlanner(RoutePlannerCase test_case) + : UnitTest("PokemonBDSP::AutoStory - Route planner: " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + RoutePlannerCase m_case; +}; + +} // namespace + + +const RoutePlannerCase ROUTE_PLANNER_CASES[] = { + { + .input = {"walking until stopped", test_walk_to_wall}, + .expectation = {}, + }, + { + .input = {"legs to walls around a pillar", test_plan_tile_route}, + .expectation = {}, + }, + { + .input = {"robust plans", test_plan_robust_route}, + .expectation = {}, + }, + { + .input = {"trainers' sight lines", test_trainer_sight}, + .expectation = {}, + }, +}; void add_tests_AutoStory_RoutePlanner(UnitTestDatabase& database){ - database.add(); - database.add(); - database.add(); - database.add(); + for (const auto& item : ROUTE_PLANNER_CASES){ + database.add(item); + } } -} -} -} + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h index 526d0fe601..1a75a9811f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.h @@ -18,7 +18,7 @@ namespace PokemonBDSP{ void add_tests_AutoStory_RoutePlanner(UnitTestDatabase& database); -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #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 index 479c1240c2..6c5ed6fd46 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp @@ -159,13 +159,7 @@ std::vector named_tiles(){ // every stretch plans as one straight leg on the decomp maps, 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{ +UnitTestResult test_segment00_lines(Logger& logger){ const StoryWorld& maps = Segment00Lines::segment00_maps(); for (const SceneTrigger& trigger : Segment00Lines::scene_triggers()){ if (trigger.width <= 0 || trigger.height <= 0){ @@ -199,17 +193,58 @@ class Test_Segment00Lines : public UnitTest{ } } return true; +} + + +struct Segment00Input{ + std::string name; + std::function body; +}; + +struct Segment00Expectation{ +}; + +struct Segment00Case{ + Segment00Input input; + Segment00Expectation expectation; +}; + +class Test_Segment00 : public UnitTest{ +public: + explicit Test_Segment00(Segment00Case test_case) + : UnitTest("PokemonBDSP::AutoStory - Segment 00: " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } } + +private: + Segment00Case m_case; }; -} +} // namespace +const Segment00Case SEGMENT00_CASES[] = { + { + .input = {"the lines into each scene", test_segment00_lines}, + .expectation = {}, + }, +}; + void add_tests_AutoStory_Segment00(UnitTestDatabase& database){ - database.add(); + for (const auto& item : SEGMENT00_CASES){ + database.add(item); + } } -} -} -} + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h index 1471536bd4..dfd010c7f4 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.h @@ -21,7 +21,7 @@ void add_tests_AutoStory_Segment00(UnitTestDatabase& database); -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp index 3c6d8487cb..62dec89465 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp @@ -44,12 +44,7 @@ StoryWorld alone(const std::string& json_map){ // and r254 loaded the catch's save in the pocket behind the trees at // (21, 29), planned from the catch spot instead, and walked up and down // the lawn east of the grass for three minutes without a battle. -class Test_Route202CatchGrass : public UnitTest{ -public: - Test_Route202CatchGrass() - : UnitTest("PokemonBDSP::AutoStory - Route 202: the catch patch and the walk to it") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ +UnitTestResult test_route202_catch_grass(Logger& logger){ const StoryWorld route = alone("Route202"); for (int x = 15; x <= 20; x++){ const WallHit up = slide_to_wall(route, {x, 27}, Direction::NORTH); @@ -87,19 +82,13 @@ class Test_Route202CatchGrass : public UnitTest{ logger.log(std::format("From {} to the catch grass: {} legs, ending in the grass.", name, legs->size())); } return true; - } -}; +} // 00.04's way to Sandgem's Pokemon Center ends below the Center's sign, // walking north into it, then taps west along the doors' row to below the // door: the row must be open there, the door straight north of where the // taps end, and nothing else (a sign, the Mart's door) on the way. -class Test_SandgemCenterApproach : public UnitTest{ -public: - Test_SandgemCenterApproach() - : UnitTest("PokemonBDSP::AutoStory - Sandgem Town: below the Center's sign to below its door") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ +UnitTestResult test_sandgem_center_approach(Logger& logger){ const StoryWorld town = alone("SandgemTown"); const TilePos sign = map_point("SandgemTown", "pokemon_center_sign"); const TilePos door = map_point("SandgemTown", "pokemon_center_door"); @@ -124,19 +113,13 @@ class Test_SandgemCenterApproach : public UnitTest{ logger.log(std::format("Sandgem: below the sign {}, {} taps west to below the door {}.", Pokemon::to_string(sign.next(Direction::SOUTH)), sign.x - door.x, Pokemon::to_string(door))); return true; - } -}; +} // After training, 00.04 walks from wherever the training left us into // Sandgem, to where the road stops above the Mart, with the default costs // (heal_at_sandgem_center()): from the whole area and from each of its // tiles alone, a plan must exist and end there. -class Test_TrainingToSandgem : public UnitTest{ -public: - Test_TrainingToSandgem() - : UnitTest("PokemonBDSP::AutoStory - Route 202: from every tile of the training area into Sandgem") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ +UnitTestResult test_training_to_sandgem(Logger& logger){ const StoryWorld& maps = story_maps(); const TilePos entry = maps.to_world(MAP_SANDGEM_TOWN, map_point("SandgemTown", "route_202_entry_stop")); const std::vector area = story_after_training_area(); @@ -156,18 +139,12 @@ class Test_TrainingToSandgem : public UnitTest{ logger.log(std::format("From {} into Sandgem: {} legs.", name, legs->size())); } return true; - } -}; +} // The Oreburgh Gym's inside: 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_OreburghGymColumn : public UnitTest{ -public: - Test_OreburghGymColumn() - : UnitTest("PokemonBDSP::AutoStory - Oreburgh Gym: the column up to Roark") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ +UnitTestResult test_oreburgh_gym_column(Logger& logger){ const StoryWorld gym = alone("OreburghGym"); const TilePos entrance = map_point("OreburghGym", "entrance"); const TilePos roark = map_point("OreburghGym", "roark"); @@ -195,18 +172,12 @@ class Test_OreburghGymColumn : public UnitTest{ } } return true; - } -}; +} // Each traceable record with a start tile starts on ground, and its legs // counted in whole tiles trace on its map up to the first leg that ends // some other way. -class Test_RouteRecords : public UnitTest{ -public: - Test_RouteRecords() - : UnitTest("PokemonBDSP::AutoStory - Route records: counted legs trace on their maps") - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ +UnitTestResult test_route_records(Logger& logger){ for (const RouteRecords::RouteRecord& record : RouteRecords::all()){ const std::string name = record.checkpoint + " " + record.title; const StoryWorld world = alone(record.map_file); @@ -231,21 +202,74 @@ class Test_RouteRecords : public UnitTest{ } } return true; +} + + +struct StoryMapsInput{ + std::string name; + std::function body; +}; + +struct StoryMapsExpectation{ +}; + +struct StoryMapsCase{ + StoryMapsInput input; + StoryMapsExpectation expectation; +}; + +class Test_StoryMaps : public UnitTest{ +public: + explicit Test_StoryMaps(StoryMapsCase test_case) + : UnitTest("PokemonBDSP::AutoStory - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } } + +private: + StoryMapsCase m_case; }; -} +} // namespace + +const StoryMapsCase STORY_MAPS_CASES[] = { + { + .input = {"Route 202: the catch patch and the walk to it", test_route202_catch_grass}, + .expectation = {}, + }, + { + .input = {"Sandgem Town: below the Center's sign to below its door", test_sandgem_center_approach}, + .expectation = {}, + }, + { + .input = {"Route 202: from every tile of the training area into Sandgem", test_training_to_sandgem}, + .expectation = {}, + }, + { + .input = {"Oreburgh Gym: the column up to Roark", test_oreburgh_gym_column}, + .expectation = {}, + }, + { + .input = {"Route records: counted legs trace on their maps", test_route_records}, + .expectation = {}, + }, +}; void add_tests_AutoStory_StoryMaps(UnitTestDatabase& database){ - database.add(); - database.add(); - database.add(); - database.add(); - database.add(); + for (const auto& item : STORY_MAPS_CASES){ + database.add(item); + } } -} -} -} + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h index 68fb96f3f3..c0ed36bd5b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.h @@ -18,7 +18,7 @@ namespace PokemonBDSP{ void add_tests_AutoStory_StoryMaps(UnitTestDatabase& database); -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index d297d2be99..e4cca12a13 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -79,12 +79,7 @@ struct StepCase{ bool at_wall = false; }; -class Test_StoryWorldSteps : public UnitTest{ -public: - Test_StoryWorldSteps() - : UnitTest("PokemonBDSP::AutoStory - Story world: what each tile does to a step") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ +UnitTestResult test_story_world_steps(Logger&){ const std::vector cases{ {.name = "open ground", .rows = {".", "."}, .from = {0, 1}, .lands = TilePos{0, 0}}, {.name = "tall grass", .rows = {"~", "."}, .from = {0, 1}, .lands = TilePos{0, 0}}, @@ -113,18 +108,12 @@ class Test_StoryWorldSteps : public UnitTest{ } } return true; - } -}; +} // Two maps joined: tiles of each at their offsets, the gap between them // off the maps, and a shared wall border allowed where nothing else is. -class Test_StoryWorldJoin : public UnitTest{ -public: - Test_StoryWorldJoin() - : UnitTest("PokemonBDSP::AutoStory - Story world: maps joined at offsets") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ +UnitTestResult test_story_world_join(Logger&){ StoryWorld world; world.add("West", make_map({"##", ".#"}), {0, 0}); world.add("East", make_map({"#.", "#~"}), {1, -1}); @@ -154,18 +143,12 @@ class Test_StoryWorldJoin : public UnitTest{ return std::string("to_world() of an unknown map did not throw."); }catch (InternalProgramError&){} return true; - } -}; +} // block() and uncover() change what a tile does, and survive a map added // later that moves the world's origin. -class Test_StoryWorldBlockUncover : public UnitTest{ -public: - Test_StoryWorldBlockUncover() - : UnitTest("PokemonBDSP::AutoStory - Story world: blocked and uncovered tiles") - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ +UnitTestResult test_story_world_block_uncover(Logger&){ StoryWorld world; world.add("Road", make_map({"...."}), {0, 0}); world.block({1, 0}); @@ -183,19 +166,66 @@ class Test_StoryWorldBlockUncover : public UnitTest{ return std::string("Adding a map lost the blocked or uncovered tile."); } return true; - } +} + + +struct StoryWorldInput{ + std::string name; + std::function body; }; -} +struct StoryWorldExpectation{ +}; +struct StoryWorldCase{ + StoryWorldInput input; + StoryWorldExpectation expectation; +}; + +class Test_StoryWorld : public UnitTest{ +public: + explicit Test_StoryWorld(StoryWorldCase test_case) + : UnitTest("PokemonBDSP::AutoStory - Story world: " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + StoryWorldCase m_case; +}; + +} // namespace + + +const StoryWorldCase STORY_WORLD_CASES[] = { + { + .input = {"what each tile does to a step", test_story_world_steps}, + .expectation = {}, + }, + { + .input = {"maps joined at offsets", test_story_world_join}, + .expectation = {}, + }, + { + .input = {"blocked and uncovered tiles", test_story_world_block_uncover}, + .expectation = {}, + }, +}; void add_tests_AutoStory_StoryWorld(UnitTestDatabase& database){ - database.add(); - database.add(); - database.add(); + for (const auto& item : STORY_WORLD_CASES){ + database.add(item); + } } -} -} -} + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h index 0fee678878..de4006d340 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.h @@ -18,7 +18,7 @@ namespace PokemonBDSP{ void add_tests_AutoStory_StoryWorld(UnitTestDatabase& database); -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif From 40cc6a75a5b1cd1673008110872666785b302555 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 7 Nov 2026 14:14:52 -0800 Subject: [PATCH 15/18] BDSP nav: fix C4456 local declaration shadowing in static lambdas --- .../Data/PokemonBDSP_AutoStory_RouteRecords.cpp | 4 ++-- .../PokemonBDSP_AutoStory_Segment00Lines.cpp | 12 ++++++------ .../Data/PokemonBDSP_AutoStory_StoryMaps.cpp | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) 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 2522d854c3..8c79df9f26 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp @@ -162,8 +162,8 @@ 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()); + const std::vector part_records = part(); + all.insert(all.end(), part_records.begin(), part_records.end()); } return all; }(); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp index 9d7d7311ce..6c546e89e7 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp @@ -29,12 +29,12 @@ const char* const MAP_VERITY_LAKEFRONT = "Verity Lakefront"; // cell. const StoryWorld& segment00_maps(){ static const StoryWorld maps = []{ - StoryWorld maps; - maps.add(MAP_TWINLEAF_TOWN, story_map("TwinleafTown"), {96, 864}); - maps.add(MAP_ROUTE_201, story_map("Route201"), {96, 839}); - maps.add(MAP_VERITY_LAKEFRONT, story_map("VerityLakefront"), {64, 832}); - maps.add(MAP_SANDGEM_TOWN, story_map("SandgemTown"), {160, 832}); - return maps; + StoryWorld world; + world.add(MAP_TWINLEAF_TOWN, story_map("TwinleafTown"), {96, 864}); + world.add(MAP_ROUTE_201, story_map("Route201"), {96, 839}); + world.add(MAP_VERITY_LAKEFRONT, story_map("VerityLakefront"), {64, 832}); + world.add(MAP_SANDGEM_TOWN, story_map("SandgemTown"), {160, 832}); + return world; }(); return maps; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp index 7934c88438..4e21902d76 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp @@ -75,11 +75,11 @@ bool in_region(const std::string& map, const std::string& region, const TilePos& // Route 202's road comes down off its row 31 onto Sandgem's row 0. const StoryWorld& story_maps(){ static const StoryWorld maps = []{ - StoryWorld maps; - maps.add(MAP_ROUTE_201, story_map("Route201"), {0, 0}); - maps.add(MAP_SANDGEM_TOWN, story_map("SandgemTown"), {64, -7}); - maps.add(MAP_ROUTE_202, story_map("Route202"), {63, -39}); - return maps; + StoryWorld world; + world.add(MAP_ROUTE_201, story_map("Route201"), {0, 0}); + world.add(MAP_SANDGEM_TOWN, story_map("SandgemTown"), {64, -7}); + world.add(MAP_ROUTE_202, story_map("Route202"), {63, -39}); + return world; }(); return maps; } @@ -110,11 +110,11 @@ const int JUBILIFE_EAST_BOTTOM = 25; const StoryWorld& jubilife_east_maps(){ static const StoryWorld maps = []{ const MapData& city = story_map("JubilifeCity"); - StoryWorld maps; - maps.add(MAP_JUBILIFE_CITY, crop( + StoryWorld world; + world.add(MAP_JUBILIFE_CITY, crop( city, JUBILIFE_EAST_CORNER, city.tiles.width - JUBILIFE_EAST_CORNER.x, JUBILIFE_EAST_BOTTOM - JUBILIFE_EAST_CORNER.y + 1 ), {0, 0}); - return maps; + return world; }(); return maps; } From d29fcef55f8c42e9c41184d53ed03124d63ccdc7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 7 Nov 2026 16:49:45 -0800 Subject: [PATCH 16/18] BDSP AutoStory nav: adopt wall recovery localization and hazard modeling --- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 24 ++- .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 7 +- .../PokemonBDSP_AutoStory_WallRecovery.cpp | 155 ++++++++++++++++++ .../Data/PokemonBDSP_AutoStory_WallRecovery.h | 44 +++++ ...kemonBDSP_AutoStory_RoutePlanner_Tests.cpp | 98 +++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 6 files changed, 327 insertions(+), 3 deletions(-) create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index c245bf283e..bf3fe46218 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -56,12 +56,17 @@ void StoryWorld::add(std::string name, const Pokemon::MapData& map, const TilePo throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Map placed twice: " + name); } } - Placed placed{std::move(name), map.tiles, {}, offset}; + Placed placed{.name = std::move(name), .tiles = map.tiles, .occupied = {}, .wander = {}, .warps = {}, .offset = offset}; for (const Pokemon::MapObject& object : map.objects){ if (!object.wander){ placed.occupied.push_back({object.x, object.y}); + }else{ + placed.wander.push_back(*object.wander); } } + for (const auto& warp : map.warps){ + placed.warps.push_back({warp.x, warp.y}); + } check_overlap(placed); m_maps.push_back(std::move(placed)); rebuild(); @@ -138,6 +143,18 @@ void StoryWorld::paint(const Placed& placed, const TilePos& corner){ for (const TilePos& pos : placed.occupied){ Pokemon::cell_at(m_cells, {corner.x + pos.x, corner.y + pos.y}).occupant = PERSON; } + for (const auto& box : placed.wander){ + for (int y = std::max(0, box.y0); y <= std::min(placed.tiles.height - 1, box.y1); y++){ + for (int x = std::max(0, box.x0); x <= std::min(placed.tiles.width - 1, box.x1); x++){ + Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}).recovery_hazard = true; + } + } + } + for (const auto& warp : placed.warps){ + if (placed.tiles.contains(warp)){ + Pokemon::cell_at(m_cells, {corner.x + warp.x, corner.y + warp.y}).recovery_hazard = true; + } + } } const StoryWorld::Cell* StoryWorld::cell(const TilePos& pos) const{ @@ -162,8 +179,11 @@ std::optional StoryWorld::tile(const TilePos& pos) const{ return found->tile; } -StoryWorld::Occupant StoryWorld::occupied(const TilePos& pos) const{ +StoryWorld::Occupant StoryWorld::occupied(const TilePos& pos, OccupancyUse use) const{ const Cell* found = cell(pos); + if (found && use == OccupancyUse::WALL_RECOVERY && found->recovery_hazard){ + return PERSON; + } return found == nullptr ? NOBODY : found->occupant; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index dc5b76e3c5..751d9cd7bb 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -55,7 +55,9 @@ class StoryWorld{ PERSON, BLOCKED, }; - Occupant occupied(const Pokemon::TilePos& pos) const; + // Recovery also excludes wandering areas and declared warps. + enum class OccupancyUse{ MOVEMENT, WALL_RECOVERY }; + Occupant occupied(const Pokemon::TilePos& pos, OccupancyUse use = OccupancyUse::MOVEMENT) const; // Blocks a tile found in the way on the console. Tiles off the maps // are left alone. @@ -74,12 +76,15 @@ class StoryWorld{ std::string name; Pokemon::Grid tiles; std::vector occupied; // local tiles + std::vector wander; // recovery hazards, not terrain + std::vector warps; Pokemon::TilePos offset; }; struct Cell{ bool covered = false; Pokemon::TileKind tile = Pokemon::TileKind::WALL; Occupant occupant = NOBODY; + bool recovery_hazard = false; }; void check_overlap(const Placed& map) const; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp new file mode 100644 index 0000000000..7ccc8549c5 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp @@ -0,0 +1,155 @@ +/* BDSP Wall Recovery + * + * From: https://github.com/PokemonAutomation/ + */ +#include +#include "PokemonBDSP_AutoStory_WallRecovery.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ +namespace{ + +using Pokemon::Direction; +using Pokemon::TilePos; + +// A wall ray must stay on the same map and walk one tile per step. A +// ledge may be legal travel but must not become a localization anchor. +std::optional safe_wall(const StoryWorld& world, TilePos from, Direction direction){ + const auto map = world.to_local(from); + if (!map || !standable(world, from) + || world.occupied(from, StoryWorld::OccupancyUse::WALL_RECOVERY) == StoryWorld::PERSON){ + return std::nullopt; + } + const WallHit wall = slide_to_wall(world, from, direction); + if (!wall.anchored + || world.occupied(wall.wall, StoryWorld::OccupancyUse::WALL_RECOVERY) == StoryWorld::PERSON){ + return std::nullopt; + } + while (from != wall.stop){ + const auto next = step(world, from, direction); + const auto local = next ? world.to_local(*next) : std::nullopt; + if (!next || *next != from.next(direction) || !local || local->map != map->map + || world.occupied(*next, StoryWorld::OccupancyUse::WALL_RECOVERY) == StoryWorld::PERSON){ + return std::nullopt; + } + from = *next; + } + return wall; +} + +class WallPolicy{ +public: + using Hypothesis = TilePos; + using Position = TilePos; + using Hold = TileLeg; + + static Position position(const Hypothesis& at){ return at; } + static int tiles(const Hold& hold){ return (int)hold.tiles; } + static std::optional> hold( + const StoryWorld& world, const std::vector& from, Direction direction + ){ + std::vector ends; + size_t longest = 0; + for (const auto& start : from){ + const auto wall = safe_wall(world, start, direction); + if (!wall){ + return std::nullopt; + } + longest = std::max(longest, wall->tiles); + if (std::find(ends.begin(), ends.end(), wall->stop) == ends.end()){ + ends.push_back(wall->stop); + } + } + return Pokemon::WallRecoveryStep{ + .positions = std::move(ends), + .hold = {.direction = direction, .tiles = longest, .ends_at_wall = true}, + }; + } + +}; + +} // namespace + +std::vector> wall_recovery_candidates( + const StoryWorld& world, const std::vector& from, + const Pokemon::WallRecoveryLimits& limits +){ + for (const auto& tile : from){ + if (!standable(world, tile)){ + return {}; + } + } + return Pokemon::find_wall_anchors(from, world, limits); +} + +std::vector interrupted_leg_positions( + const StoryWorld& world, const std::vector& from, Direction direction, size_t tiles +){ + std::vector positions; + for (TilePos at : from){ + for (size_t count = 0; count <= tiles; count++){ + if (std::find(positions.begin(), positions.end(), at) == positions.end()){ + positions.push_back(at); + } + const auto next = step(world, at, direction); + if (count == tiles || !next){ + break; + } + at = *next; + } + } + return positions; +} + +namespace{ +std::vector recovery_legs( + const StoryWorld& world, std::vector from, const std::vector& holds +){ + std::vector legs; + for (const auto& hold : holds){ + std::vector after; + for (const auto& at : from){ + const TilePos end = slide_to_wall(world, at, hold.direction).stop; + if (std::find(after.begin(), after.end(), end) == after.end()){ + after.push_back(end); + } + } + legs.push_back({.leg = hold, .after = after}); + from = std::move(after); + } + return legs; +} +} // namespace + +std::optional> plan_recovered_route( + const StoryWorld& world, const std::vector& from, + const std::function& goal, const RobustPlanCosts& costs +){ + if (from.empty()){ + return std::nullopt; + } + if (std::all_of(from.begin(), from.end(), goal)){ + return std::vector(); + } + if (from.size() == 1){ + return plan_robust_route(world, from, goal, costs); + } + auto anchors = wall_recovery_candidates(world, from); + std::stable_sort(anchors.begin(), anchors.end(), [&](const auto& a, const auto& b){ + return goal(a.at) && !goal(b.at); + }); + for (const auto& anchor : anchors){ + const auto back = plan_robust_route(world, std::vector{anchor.at}, goal, costs); + if (back){ + auto route = recovery_legs(world, from, anchor.holds); + route.insert(route.end(), back->begin(), back->end()); + return route; + } + } + return std::nullopt; +} + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h new file mode 100644 index 0000000000..862e2a2f14 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h @@ -0,0 +1,44 @@ +/* BDSP Wall Recovery + * + * From: https://github.com/PokemonAutomation/ + * + * BDSP's movement adapter for shared native wall convergence. Predictions + * do not confirm controller execution; the walker must establish arrival. + */ +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_WallRecovery_H +#define PokemonAutomation_PokemonBDSP_AutoStory_WallRecovery_H + +#include "Pokemon/Navigation/Pokemon_WallRecovery.h" +#include "PokemonBDSP_AutoStory_RoutePlanner.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +// Safe holds for every possible position, within one explicitly placed map. +// Never anchors against a person, crosses a door/map edge or hops a ledge. +// Caller must uncover trainer sight/scene hazards absent from StoryWorld. +std::vector> wall_recovery_candidates( + const StoryWorld& world, const std::vector& from, + const Pokemon::WallRecoveryLimits& limits = Pokemon::WallRecoveryLimits() +); + +// Every legal prefix, including zero movement, of an interrupted counted leg. +std::vector interrupted_leg_positions( + const StoryWorld& world, const std::vector& from, + Pokemon::Direction direction, size_t tiles +); + +// Establish a common wall anchor before continuing from an uncertain pose. +// Single positions retain the existing planner. Ambiguous positions without +// a safe anchor fail instead of choosing one. Goals already held need no walk. +std::optional> plan_recovered_route( + const StoryWorld& world, const std::vector& from, + const std::function& goal, + const RobustPlanCosts& costs +); + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp index 11f82e3cbd..5e0f972700 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp @@ -15,6 +15,8 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Data/PokemonBDSP_AutoStory_RoutePlanner.h" +#include "Data/PokemonBDSP_AutoStory_WallRecovery.h" +#include "Data/PokemonBDSP_AutoStory_Maps.h" #include "PokemonBDSP_AutoStory_RoutePlanner_Tests.h" namespace PokemonAutomation{ @@ -135,6 +137,85 @@ UnitTestResult test_plan_robust_route(Logger&){ } +// Empty map name selects a synthetic corridor: ####### / #.....# / #######. +// Both possible starts (1,1)/(5,1) must share a safe wall ray. NPCs and +// warps on that ray or its wall invalidate it; ordinary terrain is unchanged. +struct RecoveryGeometryInput{ + std::string name; + std::string map = {}; + std::vector from; + std::optional wander = {}; + std::vector warps = {}; +}; +struct RecoveryGeometryExpectation{ + std::optional anchor; + Direction direction = Direction::SOUTH; + size_t holds = 1; + std::optional free_tile = {}; +}; +struct RecoveryGeometryCase{ + RecoveryGeometryInput input; + RecoveryGeometryExpectation expectation; +}; + +Pokemon::MapData recovery_map(const RecoveryGeometryInput& input){ + Pokemon::MapData map; + if (!input.map.empty()){ + return story_map(input.map); + } + map.name = "RecoveryDiagnostic"; + map.tiles = Pokemon::Grid{7, 3, {}}; + for (const char* row : {"#######", "#.....#", "#######"}){ + for (char glyph : std::string(row)){ + map.tiles.cells.push_back(*Pokemon::tile_from_glyph(glyph)); + } + } + if (input.wander){ + map.objects.push_back({.name = "wanderer", .x = 3, .y = 1, .facing = std::nullopt, + .wander = input.wander, .trainer = std::nullopt, .hide_flag = std::nullopt}); + } + for (const auto& warp : input.warps){ + map.warps.push_back({.x = warp.x, .y = warp.y, .to = std::nullopt}); + } + return map; +} + +class Test_RecoveryGeometry : public UnitTest{ +public: + explicit Test_RecoveryGeometry(RecoveryGeometryCase scenario) + : UnitTest("PokemonBDSP::AutoStory - Recovery geometry: " + scenario.input.name), m_case(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const auto& expected = m_case.expectation; + const auto map = recovery_map(m_case.input); + StoryWorld world; + world.add(map.name, map, {0, 0}); + if (expected.free_tile && (!standable(world, *expected.free_tile) + || world.occupied(*expected.free_tile) != StoryWorld::NOBODY)){ + return "Expected ordinary movement to remain free at " + Pokemon::to_string(*expected.free_tile); + } + const auto anchors = wall_recovery_candidates(world, m_case.input.from); + const auto actual = anchors.empty() ? std::optional() : std::optional(anchors.front().at); + if (actual != expected.anchor){ + return std::format("Expected anchor {}, got {}.", + expected.anchor ? Pokemon::to_string(*expected.anchor) : "none", + actual ? Pokemon::to_string(*actual) : "none"); + } + if (anchors.empty()){ + return true; + } + const auto& holds = anchors.front().holds; + if (holds.size() != expected.holds || holds.empty() || holds.front().direction != expected.direction){ + return std::format("Expected {} holds beginning {}, got {} beginning {}.", + expected.holds, Pokemon::direction_name(expected.direction), holds.size(), + holds.empty() ? "none" : Pokemon::direction_name(holds.front().direction)); + } + return true; + } +private: + RecoveryGeometryCase m_case; +}; + // A trainer's sight stops at the first tile the player cannot stand on, // and a leg through it is reported; a leg that is stopped throws. UnitTestResult test_trainer_sight(Logger&){ @@ -209,10 +290,27 @@ const RoutePlannerCase ROUTE_PLANNER_CASES[] = { }, }; +const RecoveryGeometryCase GEOMETRY_CASES[] = { + {.input = {.name = "mine rows converge south", .map = "OreburghMine", .from = {{15, 15}, {15, 16}, {15, 17}}}, + .expectation = {.anchor = TilePos{.x = 15, .y = 17}}}, + {.input = {.name = "r55 tiles converge east", .map = "Route202", .from = {{27, 5}, {26, 5}}}, + .expectation = {.anchor = TilePos{.x = 30, .y = 5}, .direction = Direction::EAST}}, + {.input = {.name = "wandering area is unsafe", .from = {{1, 1}, {5, 1}}, + .wander = Pokemon::TileBox{.x0 = 2, .y0 = 1, .x1 = 4, .y1 = 1}}, + .expectation = {.anchor = std::nullopt, .free_tile = TilePos{.x = 3, .y = 1}}}, + {.input = {.name = "warp crossings are unsafe", .from = {{1, 1}, {5, 1}}, .warps = {{3, 1}}}, + .expectation = {.anchor = std::nullopt}}, + {.input = {.name = "warps on blocked glyphs are unsafe", .from = {{1, 1}, {5, 1}}, .warps = {{0, 1}, {6, 1}}}, + .expectation = {.anchor = std::nullopt}}, +}; + void add_tests_AutoStory_RoutePlanner(UnitTestDatabase& database){ for (const auto& item : ROUTE_PLANNER_CASES){ database.add(item); } + for (const auto& scenario : GEOMETRY_CASES){ + database.add(scenario); + } } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 13afab9941..2787af13fb 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1650,6 +1650,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp From ba18d4c6b69df3c1c058af1145488ed78f62cf9b Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 00:28:49 -0800 Subject: [PATCH 17/18] BDSP: fold #226 fixes into the story maps and route planner Moves #226's versions of these files into the PR that owns them. #226 commits: 0192d6bb5 BDSP AutoStory: a warp is a fade or a banner; walks report warps (#268 slices 1-3) (#284) 8eece7197 BDSP AutoStory: recovery picks the cheapest whole walk; 01.10 runs into Floaroma (#278) 5493a9eb8 BDSP AutoStory: routes never run along a wander zone; short wall legs walk every tile (#277) aa19dfa7f BDSP AutoStory 01.04: 21 taps from below the Center's door to the Gym's 5a1626885 BDSP AutoStory: soft cost penalty for wandering hazards and wall check safeguard 9a2eb0a11 BDSP AutoStory: avoid wandering NPC hazards and simulate wandering NPCs ac1ef0b49 BDSP AutoStory: align Oreburgh Mine maps, corridor legs, and Floaroma pathing Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_RoutePlanner.cpp | 82 ++++++++++++++++++- .../Data/PokemonBDSP_AutoStory_RoutePlanner.h | 20 ++++- .../PokemonBDSP_AutoStory_RouteRecords.cpp | 12 +-- .../PokemonBDSP_AutoStory_Segment00Lines.cpp | 6 +- .../Data/PokemonBDSP_AutoStory_StoryMaps.cpp | 17 +++- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 80 +++++++++++++++++- .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 18 ++++ .../PokemonBDSP_AutoStory_WallRecovery.cpp | 27 +++--- .../Data/PokemonBDSP_AutoStory_WallRecovery.h | 2 + .../PokemonBDSP_AutoStory_StoryMaps_Tests.cpp | 60 ++++++++++++++ 10 files changed, 298 insertions(+), 26 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp index f867e407bc..78e68ef048 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp @@ -83,6 +83,9 @@ class StoryWorldModel{ if (tall_grass(m_world, *next)){ step.extra_cost += m_costs.per_grass_tile; } + if (wandering_hazard(m_world, *next)){ + step.extra_cost += m_costs.per_wander_tile; + } return step; } bool held_at(const State& pos, Direction direction) const{ @@ -218,10 +221,15 @@ namespace{ struct Stepped{ TilePos end; int grass = 0; + int wander = 0; + // Two tiles in a row where someone wanders, the start among them: the + // walk runs along their zone, and plan_robust_route() does not use it. + bool along_wander = false; }; std::optional step_tiles(const StoryWorld& world, TilePos from, Direction direction, int tiles){ Stepped stepped; int travelled = 0; + bool in_wander = wandering_hazard(world, from); while (travelled < tiles){ const std::optional next = step(world, from, direction); if (!next){ @@ -234,6 +242,12 @@ std::optional step_tiles(const StoryWorld& world, TilePos from, Directi if (tall_grass(world, *next)){ stepped.grass++; } + const bool next_wander = wandering_hazard(world, *next); + if (next_wander){ + stepped.wander++; + stepped.along_wander |= in_wander; + } + in_wander = next_wander; from = *next; } stepped.end = from; @@ -268,13 +282,18 @@ std::optional to_wall_leg(const StoryWorld& world, const Spread& spre Expansion expansion; size_t longest = 0; int grass = 0; + int wander = 0; for (const TilePos& pos : spread){ const WallHit hit = slide_to_wall(world, pos, direction); if (!hit.anchored){ return std::nullopt; } if (const std::optional stepped = step_tiles(world, pos, direction, (int)hit.tiles)){ + if (stepped->along_wander){ + return std::nullopt; + } grass = std::max(grass, stepped->grass); + wander = std::max(wander, stepped->wander); } longest = std::max(longest, hit.tiles); expansion.next.push_back(hit.stop); @@ -282,7 +301,8 @@ std::optional to_wall_leg(const StoryWorld& world, const Spread& spre if (longest == 0){ return std::nullopt; } - expansion.cost = (long long)costs.per_leg + (long long)costs.per_tile * longest + (long long)costs.per_grass_tile * grass; + expansion.cost = (long long)costs.per_leg + (long long)costs.per_tile * longest + + (long long)costs.per_grass_tile * grass + (long long)costs.per_wander_tile * wander; expansion.leg = TileLeg{direction, longest, true}; return expansion; } @@ -292,19 +312,22 @@ std::optional to_wall_leg(const StoryWorld& world, const Spread& spre std::optional open_leg(const StoryWorld& world, const Spread& spread, Direction direction, int tiles, const RobustPlanCosts& costs){ Expansion expansion; int grass = 0; + int wander = 0; const int error = tiles <= costs.exact_open_tiles ? 0 : costs.open_error + tiles / costs.open_error_per; for (const TilePos& pos : spread){ for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ const std::optional stepped = step_tiles(world, pos, direction, n); - if (!stepped){ + if (!stepped || stepped->along_wander){ return std::nullopt; } grass = std::max(grass, stepped->grass); + wander = std::max(wander, stepped->wander); expansion.next.push_back(stepped->end); } } expansion.cost = (long long)costs.per_leg + costs.leg_not_at_wall + - (long long)(costs.per_tile + costs.per_open_tile) * tiles + (long long)costs.per_grass_tile * grass; + (long long)(costs.per_tile + costs.per_open_tile) * tiles + + (long long)costs.per_grass_tile * grass + (long long)costs.per_wander_tile * wander; expansion.leg = TileLeg{direction, (size_t)tiles, false}; return expansion; } @@ -376,6 +399,12 @@ class RobustSearch{ if (expansion.next.size() > m_costs.max_spread || expansion.next == spread){ return; } + if (spread != m_start){ + const TileLeg& prev = m_nodes.at(spread).leg.leg; + if (expansion.leg.direction == prev.direction && !prev.ends_at_wall){ + expansion.cost -= m_costs.per_leg; + } + } const long long total = cost + expansion.cost; auto iter = m_nodes.find(expansion.next); if (iter != m_nodes.end() && iter->second.cost <= total){ @@ -393,7 +422,20 @@ class RobustSearch{ at = step.parent; } std::reverse(legs.begin(), legs.end()); - return legs; + std::vector consolidated; + for (const PlannedLeg& planned : legs){ + if (!consolidated.empty() && + consolidated.back().leg.direction == planned.leg.direction && + !consolidated.back().leg.ends_at_wall + ){ + consolidated.back().leg.tiles += planned.leg.tiles; + consolidated.back().leg.ends_at_wall = planned.leg.ends_at_wall; + consolidated.back().after = planned.after; + }else{ + consolidated.push_back(planned); + } + } + return consolidated; } const StoryWorld& m_world; @@ -427,6 +469,38 @@ std::optional> plan_robust_route( return RobustSearch(world, costs).run(from, goal); } +long long robust_route_cost( + const StoryWorld& world, + const std::vector& from, const std::vector& legs, + const RobustPlanCosts& costs +){ + long long total = 0; + Spread spread = from; + normalize(spread); + const TileLeg* previous = nullptr; + for (const PlannedLeg& planned : legs){ + const TileLeg& leg = planned.leg; + const std::optional expansion = leg.ends_at_wall + ? to_wall_leg(world, spread, leg.direction, costs) + : open_leg(world, spread, leg.direction, (int)leg.tiles, costs); + long long cost = (long long)costs.per_leg + (long long)costs.per_tile * (long long)leg.tiles; + if (!leg.ends_at_wall){ + cost += costs.leg_not_at_wall + (long long)costs.per_open_tile * (long long)leg.tiles; + } + if (expansion){ + cost = expansion->cost; + } + if (previous != nullptr && previous->direction == leg.direction && !previous->ends_at_wall){ + cost -= costs.per_leg; + } + total += cost; + spread = planned.after; + normalize(spread); + previous = ⋚ + } + return total; +} + } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h index a8660a078f..718d4bf513 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h @@ -49,6 +49,7 @@ std::string to_string(const TileLeg& leg); struct TilePlanCosts{ int per_tile = 1; int per_grass_tile = 4; // extra for each tall-grass tile entered + int per_wander_tile = 3; // extra for each wander hazard tile entered int per_leg = 8; int leg_not_at_wall = 50; // extra for a leg that stops in the open }; @@ -128,8 +129,13 @@ struct RobustPlanCosts : TilePlanCosts{ // Cheapest legs that take the player from any of the tiles in `from` to tiles // that are all `goal`, even if every open leg ends up to `open_error` tiles // off: the walls of later legs must bring the possible positions together. -// Legs that would leave the maps or enter a door are not used. Nothing if no -// such plan exists, or none is found within `costs.max_searched` sets. +// Legs that would leave the maps or enter a door are not used, nor legs that +// run along a zone where someone wanders: two tiles of it in a row, the +// leg's start among them. Crossing a zone (one tile of it) costs +// `per_wander_tile`. On lab-B (2026-11-08, 01.08) Route 204's youngster, +// who wanders (12, 2) to (14, 2), stopped the leg "west 2 (to wall)" from +// (13, 2) twice. Nothing if no such plan exists, or none is found within +// `costs.max_searched` sets. std::optional> plan_robust_route( const StoryWorld& world, const std::vector& from, const std::function& goal, @@ -142,6 +148,16 @@ std::optional> plan_robust_route( const RobustPlanCosts& costs = RobustPlanCosts() ); +// What plan_robust_route() charges for walking `legs` from any of `from`, +// each leg from the tiles the one before may end on. A leg it would not +// plan (along a wander zone, or off the maps) costs its tiles and legs +// without grass or wander tiles. +long long robust_route_cost( + const StoryWorld& world, + const std::vector& from, const std::vector& legs, + const RobustPlanCosts& costs +); + } // namespace PokemonBDSP 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 8c79df9f26..9e72dad6ec 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp @@ -32,9 +32,9 @@ std::vector checkpoint_0001_records(){ }, "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", true, map_point("Route201", "route_201_arrival"), { {Direction::NORTH, 6, LegEnd::COUNT, "up the exit path to (15, 18): Barry's warning fires on that row"}, - {Direction::WEST, 3, LegEnd::COUNT, "after the scene, along row 18 to column 12"}, - {Direction::NORTH, 2, LegEnd::COUNT, "to row 16, the lower level's row to the Lakefront"}, - {Direction::WEST, 12, LegEnd::COUNT, "to (0, 16), the route's last tile"}, + {Direction::WEST, 1, LegEnd::COUNT, "after the scene, to (14, 18); west of it is trees (r16)"}, + {Direction::NORTH, 2, LegEnd::COUNT, "past the 201 sign at (13, 17) onto row 16, the lower level's row to the Lakefront (probe-r201-sign)"}, + {Direction::WEST, 14, LegEnd::COUNT, "to (0, 16), 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 Route201 map, the decomp's since #111"}, {"00.01", "Verity Lakefront: to below the lake's entrance", "Verity Lakefront", "VerityLakefront", true, map_point("VerityLakefront", "lakefront_arrival"), { @@ -94,10 +94,10 @@ std::vector segment01_records_to_oreburgh(){ {Direction::EAST, 0, LegEnd::TRANSITION, "into the Oreburgh Gate"}, {Direction::EAST, 0, LegEnd::TRANSITION, "through the Gate into Oreburgh City"}, }, "route203_to_oreburgh(); no start tile: Barry stops us on whichever row we came along"}, - {"01.04", "Oreburgh Pokemon Center doorstep to the Gym", "Oreburgh City", "OreburghCity", true, map_point("OreburghCity", "pokemon_center_doorstep"), { - {Direction::WEST, 20, LegEnd::COUNT, "D-pad taps along the Center's row to below the Gym's door"}, + {"01.04", "Oreburgh Pokemon Center doorstep to the Gym", "Oreburgh City", "OreburghCity", true, Pokemon::TilePos{47, 21}, { + {Direction::WEST, 21, 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"}, + }, "oreburgh_street_to_gym(); 21 taps; 20 were measured from (46, 21) on the console (r204 to r215, 3 runs on the same tile), and 01.03's heal leaves us below the Center's door (47, 21) (lab-B 2026-11-08 14:51: 20 taps from there ended a tile east of the Gym's door)"}, {"01.04", "Inside the Oreburgh Gym", "Oreburgh Gym", "OreburghGym", true, map_point("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)"}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp index 6c546e89e7..c32ae18be4 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp @@ -125,14 +125,16 @@ const std::vector& lines(){ twinleaf_point("barry_doorstep"), twinleaf({15, 12}), twinleaf_point("twinleaf_north_exit"), route201_point("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_point("barry_warning"), route201({12, 18}), route201({12, 16}), route201({0, 16}), + route201_point("barry_warning"), route201({14, 18}), route201({14, 16}), route201({0, 16}), lakefront({20, 23}), lakefront({20, 21}), lakefront({17, 21}), lakefront_point("lake_entrance"), }, "Barry at the lake's entrance", {"Barry at the lake's entrance", "Route 201's row 19 after the warning"}), walked("00.03", "the lake's entrance back to Rowan", { lakefront_point("lake_entrance"), lakefront({17, 21}), lakefront({29, 21}), route201_point("rowan_stop"), }, "Rowan and Dawn on the way back", {"Rowan and Dawn on the way back"}), + // Row 13, a row above the Breeder, who wanders (26..28, 14..16): no + // route runs along a wander zone (plan_robust_route()). walked("00.03", "Rowan to Dawn at Sandgem's entrance", { - route201_point("rowan_stop"), route201({17, 14}), route201({29, 14}), route201({41, 14}), + route201_point("rowan_stop"), route201({17, 14}), route201({17, 13}), route201({29, 13}), route201({41, 13}), route201({41, 7}), route201({42, 7}), route201({42, 5}), route201({52, 5}), route201_point("route_201_east_end"), sandgem_point("dawn_stop"), }, "Dawn at Sandgem's entrance", {"Dawn at Sandgem's entrance"}), diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp index 4e21902d76..c600154fc6 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp @@ -54,10 +54,25 @@ MapData crop(const MapData& map, const TilePos& corner, int width, int height){ for (Pokemon::MapObject object : map.objects){ object.x -= corner.x; object.y -= corner.y; - if (cropped.tiles.contains({object.x, object.y})){ + if (object.wander){ + object.wander->x0 -= corner.x; + object.wander->x1 -= corner.x; + object.wander->y0 -= corner.y; + object.wander->y1 -= corner.y; + } + if (cropped.tiles.contains({object.x, object.y}) || (object.wander + && object.wander->x1 >= 0 && object.wander->y1 >= 0 + && object.wander->x0 < width && object.wander->y0 < height)){ cropped.objects.push_back(std::move(object)); } } + for (auto warp : map.warps){ + warp.x -= corner.x; + warp.y -= corner.y; + if (cropped.tiles.contains({warp.x, warp.y})){ + cropped.warps.push_back(std::move(warp)); + } + } return cropped; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index bf3fe46218..ae35f4b51b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include "Common/Cpp/Exceptions.h" #include "PokemonBDSP_AutoStory_StoryWorld.h" @@ -146,7 +147,9 @@ void StoryWorld::paint(const Placed& placed, const TilePos& corner){ for (const auto& box : placed.wander){ for (int y = std::max(0, box.y0); y <= std::min(placed.tiles.height - 1, box.y1); y++){ for (int x = std::max(0, box.x0); x <= std::min(placed.tiles.width - 1, box.x1); x++){ - Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}).recovery_hazard = true; + Cell& c = Pokemon::cell_at(m_cells, {corner.x + x, corner.y + y}); + c.recovery_hazard = true; + c.wander_hazard = true; } } } @@ -187,6 +190,50 @@ StoryWorld::Occupant StoryWorld::occupied(const TilePos& pos, OccupancyUse use) return found == nullptr ? NOBODY : found->occupant; } +namespace{ + +void add_box_tiles(std::vector& out, const TilePos& corner, const Pokemon::TileBox& box, int max_w, int max_h){ + const int y0 = std::max(0, box.y0); + const int y1 = std::min(max_h - 1, box.y1); + const int x0 = std::max(0, box.x0); + const int x1 = std::min(max_w - 1, box.x1); + for (int y = y0; y <= y1; y++){ + for (int x = x0; x <= x1; x++){ + out.push_back({corner.x + x, corner.y + y}); + } + } +} + +} // namespace + +std::vector wandering_hazards(const StoryWorld& world){ + std::vector result; + for (const auto& placed : world.m_maps){ + const TilePos corner{placed.offset.x - world.m_origin.x, placed.offset.y - world.m_origin.y}; + for (const auto& box : placed.wander){ + add_box_tiles(result, corner, box, placed.tiles.width, placed.tiles.height); + } + } + std::sort(result.begin(), result.end(), [](const TilePos& a, const TilePos& b){ + if (a.y != b.y){ + return a.y < b.y; + } + return a.x < b.x; + }); + result.erase(std::unique(result.begin(), result.end()), result.end()); + return result; +} + +bool wandering_hazard(const StoryWorld& world, const TilePos& pos){ + const StoryWorld::Cell* found = world.cell(pos); + return found != nullptr && found->wander_hazard; +} + +bool recovery_hazard(const StoryWorld& world, const TilePos& pos){ + const StoryWorld::Cell* found = world.cell(pos); + return found != nullptr && found->recovery_hazard; +} + void StoryWorld::block(const TilePos& pos){ if (Cell* found = cell(pos)){ found->occupant = BLOCKED; @@ -248,6 +295,37 @@ std::optional step(const StoryWorld& world, const TilePos& from, Direct return std::nullopt; } +std::vector leg_path(const StoryWorld& grid, TilePos from, Direction direction, size_t tiles){ + std::vector path; + size_t travelled = 0; + while (travelled < tiles){ + const std::optional next = step(grid, from, direction); + if (!next){ + break; + } + travelled += std::abs(next->x - from.x) + std::abs(next->y - from.y); + from = *next; + path.push_back(from); + } + return path; +} + +bool warp_within(const StoryWorld& world, const std::vector& from, Direction direction, size_t reach){ + for (TilePos pos : from){ + for (size_t i = 0; i < reach; i++){ + if (world.tile(pos.next(direction)) == TileKind::DOOR){ + return true; + } + const std::optional next = step(world, pos, direction); + if (!next){ + break; + } + pos = *next; + } + } + return false; +} + // Someone standing in the way stops us too, but is no wall to stop against: // they may turn and talk, or walk off (r29 ran east into Mom, who talked). bool at_wall(const StoryWorld& world, const TilePos& pos, Direction direction){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index 751d9cd7bb..6940a5be4d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -71,6 +71,10 @@ class StoryWorld{ // The map that holds a world tile, or nothing between maps. std::optional to_local(const Pokemon::TilePos& world) const; + friend std::vector wandering_hazards(const StoryWorld& world); + friend bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); + friend bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); + private: struct Placed{ std::string name; @@ -85,6 +89,7 @@ class StoryWorld{ Pokemon::TileKind tile = Pokemon::TileKind::WALL; Occupant occupant = NOBODY; bool recovery_hazard = false; + bool wander_hazard = false; }; void check_overlap(const Placed& map) const; @@ -106,6 +111,12 @@ class StoryWorld{ // The rules of walking on a story world, from its tiles. +// All tiles where someone wanders on the maps, in world coordinates. +std::vector wandering_hazards(const StoryWorld& world); +// Whether a world tile is within a wandering hazard box. +bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); +// Whether a world tile is a recovery hazard (wander box or warp). +bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); // Whether a map holds this world tile. bool covered(const StoryWorld& world, const Pokemon::TilePos& pos); // Whether the player can stand on this tile. @@ -117,6 +128,13 @@ std::optional step(const StoryWorld& world, const Pokemon::Til // in place. Doors and tiles off the maps are not walls: walking into a // door enters the building, and ground off the maps may be an exit. bool at_wall(const StoryWorld& world, const Pokemon::TilePos& pos, Pokemon::Direction direction); +// The tiles the player passes when walking `tiles` tiles from `from`, the +// first one after `from` first. Stops early where the player is stopped. +std::vector leg_path(const StoryWorld& grid, Pokemon::TilePos from, Pokemon::Direction direction, size_t tiles); +// Whether a warp (a door's tile) lies within `reach` tiles `direction` of +// one of `from`, nothing stopping the player before it: where a walk that +// ran on past its leg's end may have gone through (#268 slice 2). +bool warp_within(const StoryWorld& world, const std::vector& from, Pokemon::Direction direction, size_t reach); // "Route 201 (45, 3)", or "world (x, y)" if no map holds it. std::string describe(const StoryWorld& world, const Pokemon::TilePos& pos); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp index 7ccc8549c5..3d73a54243 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp @@ -135,19 +135,26 @@ std::optional> plan_recovered_route( if (from.size() == 1){ return plan_robust_route(world, from, goal, costs); } - auto anchors = wall_recovery_candidates(world, from); - std::stable_sort(anchors.begin(), anchors.end(), [&](const auto& a, const auto& b){ - return goal(a.at) && !goal(b.at); - }); - for (const auto& anchor : anchors){ + // The cheapest whole walk, holds and the way on from the wall: the + // fewest held tiles alone chose "south 12 (to wall), north 12 (open)" + // over "north 13 (to wall), south 5 (open)" for 01.10's line 5 (lab-B + // 2026-11-08 18:15:47). Ties keep find_wall_anchors()' order. + std::optional> best; + long long best_cost = 0; + for (const auto& anchor : wall_recovery_candidates(world, from)){ const auto back = plan_robust_route(world, std::vector{anchor.at}, goal, costs); - if (back){ - auto route = recovery_legs(world, from, anchor.holds); - route.insert(route.end(), back->begin(), back->end()); - return route; + if (!back){ + continue; + } + auto route = recovery_legs(world, from, anchor.holds); + route.insert(route.end(), back->begin(), back->end()); + const long long cost = robust_route_cost(world, from, route, costs); + if (!best || cost < best_cost){ + best = std::move(route); + best_cost = cost; } } - return std::nullopt; + return best; } } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h index 862e2a2f14..954f02c4ae 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h @@ -32,6 +32,8 @@ std::vector interrupted_leg_positions( // Establish a common wall anchor before continuing from an uncertain pose. // Single positions retain the existing planner. Ambiguous positions without // a safe anchor fail instead of choosing one. Goals already held need no walk. +// Of the anchors, the one whose whole walk, holds and the way on to the +// goal, costs least (robust_route_cost()). std::optional> plan_recovered_route( const StoryWorld& world, const std::vector& from, const std::function& goal, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp index 62dec89465..48fe3d547e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp @@ -174,6 +174,58 @@ UnitTestResult test_oreburgh_gym_column(Logger& logger){ return true; } +// Oreburgh Mine B1F (the entrance hall): +// The hallway connects Oreburgh City above with the Coal Room below. +// Row 1 contains warp doors (11..13, 1) leading to the city. +// Row 21 contains warp doors (11..13, 21) leading to the coal room. +// Column 12 is unobstructed south from landing (12, 1) to warp door (12, 21). +// Column 11 is unobstructed north from landing (11, 21) to warp door (11, 1). +UnitTestResult test_oreburgh_mine_hall(Logger& logger){ + const StoryWorld hall = alone("OreburghMineB1F"); + for (int x = 11; x <= 13; x++){ + if (hall.tile({x, 1}) != TileKind::DOOR){ + return std::format("OreburghMineB1F ({}, 1) is not a DOOR tile (exit to city).", x); + } + if (hall.tile({x, 21}) != TileKind::DOOR){ + return std::format("OreburghMineB1F ({}, 21) is not a DOOR tile (entrance to coal room).", x); + } + } + for (int y = 2; y <= 20; y++){ + if (!standable(hall, {12, y})){ + return std::format("OreburghMineB1F column 12 row {} is blocked; expected clear path to coal room.", y); + } + if (!standable(hall, {11, y})){ + return std::format("OreburghMineB1F column 11 row {} is blocked; expected clear path to city exit.", y); + } + } + logger.log("OreburghMineB1F: columns 11 and 12 are clear between row 1 and row 21 warp doors."); + return true; +} + +// 01.04: the D-pad taps west from below Oreburgh's Center door end below +// the Gym's door, where the step north goes in. Red with 20 taps: they ended +// on (27, 21), a tile east of the door (lab-B, 2026-11-08 14:51). +UnitTestResult test_oreburgh_center_to_gym_taps(Logger& logger){ + const RouteRecords::RouteRecord* record = nullptr; + for (const RouteRecords::RouteRecord& item : RouteRecords::all()){ + if (item.checkpoint == "01.04" && item.map_file == "OreburghCity"){ + record = &item; + } + } + if (record == nullptr || !record->start || record->legs.empty()){ + return "No 01.04 record on Oreburgh City with a start tile and legs."; + } + const StoryWorld city = alone("OreburghCity"); + const RouteRecords::RouteLeg& west = record->legs.front(); + const TilePos end = trace_legs(city, *record->start, {{west.direction, west.tiles, false}}).back(); + const TilePos doorstep = map_point("OreburghCity", "gym_doorstep"); + if (end != doorstep){ + return std::format("{} taps west end on ({}, {}), not below the Gym's door ({}, {}).", west.tiles, end.x, end.y, doorstep.x, doorstep.y); + } + logger.log(std::format("Oreburgh: {} taps west from below the Center's door reach the Gym's doorstep.", west.tiles)); + return true; +} + // Each traceable record with a start tile starts on ground, and its legs // counted in whole tiles trace on its map up to the first leg that ends // some other way. @@ -256,6 +308,14 @@ const StoryMapsCase STORY_MAPS_CASES[] = { .input = {"Oreburgh Gym: the column up to Roark", test_oreburgh_gym_column}, .expectation = {}, }, + { + .input = {"Oreburgh Mine B1F: the entrance hall corridor and warps", test_oreburgh_mine_hall}, + .expectation = {}, + }, + { + .input = {"Oreburgh: 01.04's taps from the Center's door to the Gym's", test_oreburgh_center_to_gym_taps}, + .expectation = {}, + }, { .input = {"Route records: counted legs trace on their maps", test_route_records}, .expectation = {}, From 72eecf7747d643c02155f60cbe74a085bf264568 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 15:51:04 -0800 Subject: [PATCH 18/18] BDSP AutoStory: split the nav headers by concern; no char* in new code Moves only, no logic change. RoutePlanner.h keeps the tile planner; the trainer sight lines go to TrainerSight.h and the robust planner to RobustRoute.h. StoryWorld.h keeps the world; the walking rules go to WalkRules.h. StoryMaps.h keeps the worlds and the lines on them; the map names go to StoryMapNames.h, the segment 00 spots to StorySpots.h and the trainers to StoryTrainers.h. Map name constants are inline std::string; string parameters are std::string_view. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Data/PokemonBDSP_AutoStory_PlanCosts.cpp | 1 + .../Data/PokemonBDSP_AutoStory_PlanCosts.h | 1 + .../Data/PokemonBDSP_AutoStory_RobustRoute.h | 99 +++++++++++++++++++ .../PokemonBDSP_AutoStory_RoutePlanner.cpp | 3 + .../Data/PokemonBDSP_AutoStory_RoutePlanner.h | 88 ----------------- .../PokemonBDSP_AutoStory_Segment00Lines.cpp | 10 +- .../PokemonBDSP_AutoStory_Segment00Lines.h | 4 +- .../PokemonBDSP_AutoStory_StoryMapNames.h | 49 +++++++++ .../Data/PokemonBDSP_AutoStory_StoryMaps.cpp | 28 ++---- .../Data/PokemonBDSP_AutoStory_StoryMaps.h | 80 ++------------- .../Data/PokemonBDSP_AutoStory_StorySpots.h | 53 ++++++++++ .../PokemonBDSP_AutoStory_StoryTrainers.h | 43 ++++++++ .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 1 + .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 18 ---- .../Data/PokemonBDSP_AutoStory_TrainerSight.h | 47 +++++++++ .../Data/PokemonBDSP_AutoStory_WalkRules.h | 46 +++++++++ .../PokemonBDSP_AutoStory_WallRecovery.cpp | 3 + .../Data/PokemonBDSP_AutoStory_WallRecovery.h | 1 + ...kemonBDSP_AutoStory_RoutePlanner_Tests.cpp | 5 +- .../PokemonBDSP_AutoStory_Segment00_Tests.cpp | 12 ++- .../PokemonBDSP_AutoStory_StoryMaps_Tests.cpp | 6 ++ ...PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 1 + SerialPrograms/cmake/SourceFiles.cmake | 6 ++ 23 files changed, 393 insertions(+), 212 deletions(-) create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RobustRoute.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMapNames.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StorySpots.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryTrainers.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TrainerSight.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp index c59cfc09a3..eb982fef43 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp @@ -5,6 +5,7 @@ */ #include "PokemonBDSP_AutoStory_PlanCosts.h" +#include "PokemonBDSP_AutoStory_RobustRoute.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h index 62a7167cab..be2959df39 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h @@ -11,6 +11,7 @@ #ifndef PokemonAutomation_PokemonBDSP_AutoStory_PlanCosts_H #define PokemonAutomation_PokemonBDSP_AutoStory_PlanCosts_H +#include "PokemonBDSP_AutoStory_RobustRoute.h" #include "PokemonBDSP_AutoStory_RoutePlanner.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RobustRoute.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RobustRoute.h new file mode 100644 index 0000000000..a54bdc1610 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RobustRoute.h @@ -0,0 +1,99 @@ +/* BDSP AutoStory - Robust route planner + * + * From: https://github.com/PokemonAutomation/ + * + * Plans walks whose open legs may go a tile short or long: each leg + * lists every tile the player may end on, and later walls bring them + * back together. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RobustRoute_H +#define PokemonAutomation_PokemonBDSP_AutoStory_RobustRoute_H + +#include +#include +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP_AutoStory_StoryWorld.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// A leg of a plan that allows for open legs going a tile short or long. A +// leg to a wall is walked until the player stops; an open leg is walked for +// `leg.tiles` tiles' worth of time. `after` lists every tile the player may +// stand on once the leg is done. +struct PlannedLeg{ + TileLeg leg; + std::vector after; +}; +// Formats planned route leg with uncertainties into human-readable representation. +std::string to_string(const PlannedLeg& leg); + +// Cost configuration parameters accounting for movement execution tolerances. +struct RobustPlanCosts : TilePlanCosts{ + // An open leg of n tiles may end open_error + n / open_error_per tiles + // short or long: on the console 7 tiles went 9. + int open_error = 1; + int open_error_per = 5; + // Open legs this many tiles or shorter land exactly: a short hold moves + // whole tiles. 0 keeps every open leg uncertain. + int exact_open_tiles = 0; + // Extra per tile of an open leg: its timing error grows with its length, + // so a short step after a wall beats a long open leg. + int per_open_tile = 0; + int max_open_tiles = 12; // longest open leg to consider + size_t max_spread = 5; // most tiles the player may be on after a leg + // Most sets of possible tiles to search before giving up. The search is + // over sets, not tiles, so it grows far faster than the map: all of + // Jubilife City from six start tiles ran for minutes with no plan + // (r224a, 2026-10-31); 200000 sets took 31 s there, so this gives up + // after about 3. Use town costs in towns (a whole-Jubilife plan then + // takes 1 s) and crop the map to the part a leg needs rather than + // raising this. + size_t max_searched = 20000; +}; + +// Cheapest legs that take the player from any of the tiles in `from` to tiles +// that are all `goal`, even if every open leg ends up to `open_error` tiles +// off: the walls of later legs must bring the possible positions together. +// Legs that would leave the maps or enter a door are not used, nor legs that +// run along a zone where someone wanders: two tiles of it in a row, the +// leg's start among them. Crossing a zone (one tile of it) costs +// `per_wander_tile`. On lab-B (2026-11-08, 01.08) Route 204's youngster, +// who wanders (12, 2) to (14, 2), stopped the leg "west 2 (to wall)" from +// (13, 2) twice. Nothing if no such plan exists, or none is found within +// `costs.max_searched` sets. +std::optional> plan_robust_route( + const StoryWorld& world, + const std::vector& from, const std::function& goal, + const RobustPlanCosts& costs = RobustPlanCosts() +); +// The same, from one tile to exactly `to`. +std::optional> plan_robust_route( + const StoryWorld& world, + const Pokemon::TilePos& from, const Pokemon::TilePos& to, + const RobustPlanCosts& costs = RobustPlanCosts() +); + +// What plan_robust_route() charges for walking `legs` from any of `from`, +// each leg from the tiles the one before may end on. A leg it would not +// plan (along a wander zone, or off the maps) costs its tiles and legs +// without grass or wander tiles. +long long robust_route_cost( + const StoryWorld& world, + const std::vector& from, const std::vector& legs, + const RobustPlanCosts& costs +); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp index 78e68ef048..a89679cf16 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp @@ -11,7 +11,10 @@ #include #include "Common/Cpp/Exceptions.h" #include "Pokemon/Navigation/Pokemon_LegPlanner.h" +#include "PokemonBDSP_AutoStory_RobustRoute.h" #include "PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP_AutoStory_TrainerSight.h" +#include "PokemonBDSP_AutoStory_WalkRules.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h index 718d4bf513..5a09e8623c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h @@ -13,7 +13,6 @@ #define PokemonAutomation_PokemonBDSP_AutoStory_RoutePlanner_H #include -#include #include #include #include @@ -62,26 +61,6 @@ std::optional> plan_tile_route( const TilePlanCosts& costs = TilePlanCosts() ); -// A trainer sees the tiles in a straight line in front of them, up to -// `range` tiles or the first tile the player cannot stand on. The maps -// have no sight ranges, so story code lists them. -struct TrainerSight{ - std::string name; - Pokemon::TilePos pos; - Pokemon::Direction facing = Pokemon::Direction::NORTH; - int range = 4; -}; -// Computes straight line-of-sight tiles for a trainer. -std::vector sight_tiles(const StoryWorld& world, const TrainerSight& trainer); - -// For each leg, the trainers whose sight line it enters. -std::vector> legs_crossing_sight( - const StoryWorld& world, - const Pokemon::TilePos& from, - const std::vector& legs, - const std::vector& trainers -); - // The tiles a list of legs visits, starting with `from`. Throws // InternalProgramError if a leg is stopped before its end. std::vector trace_legs( @@ -91,73 +70,6 @@ std::vector trace_legs( ); -// A leg of a plan that allows for open legs going a tile short or long. A -// leg to a wall is walked until the player stops; an open leg is walked for -// `leg.tiles` tiles' worth of time. `after` lists every tile the player may -// stand on once the leg is done. -struct PlannedLeg{ - TileLeg leg; - std::vector after; -}; -// Formats planned route leg with uncertainties into human-readable representation. -std::string to_string(const PlannedLeg& leg); - -// Cost configuration parameters accounting for movement execution tolerances. -struct RobustPlanCosts : TilePlanCosts{ - // An open leg of n tiles may end open_error + n / open_error_per tiles - // short or long: on the console 7 tiles went 9. - int open_error = 1; - int open_error_per = 5; - // Open legs this many tiles or shorter land exactly: a short hold moves - // whole tiles. 0 keeps every open leg uncertain. - int exact_open_tiles = 0; - // Extra per tile of an open leg: its timing error grows with its length, - // so a short step after a wall beats a long open leg. - int per_open_tile = 0; - int max_open_tiles = 12; // longest open leg to consider - size_t max_spread = 5; // most tiles the player may be on after a leg - // Most sets of possible tiles to search before giving up. The search is - // over sets, not tiles, so it grows far faster than the map: all of - // Jubilife City from six start tiles ran for minutes with no plan - // (r224a, 2026-10-31); 200000 sets took 31 s there, so this gives up - // after about 3. Use town costs in towns (a whole-Jubilife plan then - // takes 1 s) and crop the map to the part a leg needs rather than - // raising this. - size_t max_searched = 20000; -}; - -// Cheapest legs that take the player from any of the tiles in `from` to tiles -// that are all `goal`, even if every open leg ends up to `open_error` tiles -// off: the walls of later legs must bring the possible positions together. -// Legs that would leave the maps or enter a door are not used, nor legs that -// run along a zone where someone wanders: two tiles of it in a row, the -// leg's start among them. Crossing a zone (one tile of it) costs -// `per_wander_tile`. On lab-B (2026-11-08, 01.08) Route 204's youngster, -// who wanders (12, 2) to (14, 2), stopped the leg "west 2 (to wall)" from -// (13, 2) twice. Nothing if no such plan exists, or none is found within -// `costs.max_searched` sets. -std::optional> plan_robust_route( - const StoryWorld& world, - const std::vector& from, const std::function& goal, - const RobustPlanCosts& costs = RobustPlanCosts() -); -// The same, from one tile to exactly `to`. -std::optional> plan_robust_route( - const StoryWorld& world, - const Pokemon::TilePos& from, const Pokemon::TilePos& to, - const RobustPlanCosts& costs = RobustPlanCosts() -); - -// What plan_robust_route() charges for walking `legs` from any of `from`, -// each leg from the tiles the one before may end on. A leg it would not -// plan (along a wander zone, or off the maps) costs its tiles and legs -// without grass or wander tiles. -long long robust_route_cost( - const StoryWorld& world, - const std::vector& from, const std::vector& legs, - const RobustPlanCosts& costs -); - } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp index c32ae18be4..4c8b844243 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.cpp @@ -17,8 +17,6 @@ namespace Segment00Lines{ using Pokemon::TilePos; -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): @@ -103,10 +101,10 @@ 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}; } // The same, at a named point of the map. -MapTile twinleaf_point(const char* point){ return twinleaf(map_point("TwinleafTown", point)); } -MapTile route201_point(const char* point){ return route201(map_point("Route201", point)); } -MapTile lakefront_point(const char* point){ return lakefront(map_point("VerityLakefront", point)); } -MapTile sandgem_point(const char* point){ return sandgem(map_point("SandgemTown", point)); } +MapTile twinleaf_point(std::string_view point){ return twinleaf(map_point("TwinleafTown", point)); } +MapTile route201_point(std::string_view point){ return route201(map_point("Route201", point)); } +MapTile lakefront_point(std::string_view point){ return lakefront(map_point("VerityLakefront", point)); } +MapTile sandgem_point(std::string_view point){ return sandgem(map_point("SandgemTown", point)); } WalkedLine walked( std::string checkpoint, std::string name, std::vector corners, std::string ends_in, std::vector live_triggers diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h index 8d794257d3..a814de841c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Segment00Lines.h @@ -29,9 +29,9 @@ 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; +inline const std::string MAP_TWINLEAF_TOWN = "Twinleaf Town"; // Verity Lakefront overworld map name. -extern const char* const MAP_VERITY_LAKEFRONT; +inline const std::string MAP_VERITY_LAKEFRONT = "Verity Lakefront"; // 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 diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMapNames.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMapNames.h new file mode 100644 index 0000000000..4cada07489 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMapNames.h @@ -0,0 +1,49 @@ +/* BDSP AutoStory - Story map names + * + * From: https://github.com/PokemonAutomation/ + * + * The names the story worlds give their maps. + * + */ +// code-health: allow header_symbols -- one list of every story map's name; splitting it hides which names are taken + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryMapNames_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryMapNames_H + +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Names of the maps in the story worlds (StoryMaps.h). Each is placed from the +// JSON map named without spaces ("Route 201" from Route201.json), except +// MAP_ROUTE_204, which is Route204North.json. +inline const std::string MAP_ROUTE_201 = "Route 201"; +// Sandgem Town overworld map name. +inline const std::string MAP_SANDGEM_TOWN = "Sandgem Town"; +// Route 202 overworld map name. +inline const std::string MAP_ROUTE_202 = "Route 202"; +// Jubilife City overworld map name. +inline const std::string MAP_JUBILIFE_CITY = "Jubilife City"; +// Oreburgh Mine map name. +inline const std::string MAP_OREBURGH_MINE = "Oreburgh Mine"; +// Ravaged Path map name. +inline const std::string MAP_RAVAGED_PATH = "Ravaged Path"; +// Route 204 North map name. +inline const std::string MAP_ROUTE_204 = "Route 204"; +// Route 204 South map name. +inline const std::string MAP_ROUTE_204_SOUTH = "Route 204 South"; +// Route 203 overworld map name. +inline const std::string MAP_ROUTE_203 = "Route 203"; +// Oreburgh City overworld map name. +inline const std::string MAP_OREBURGH_CITY = "Oreburgh City"; +// Floaroma Town overworld map name. +inline const std::string MAP_FLOAROMA_TOWN = "Floaroma Town"; + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp index f2c00f1cce..343ce03228 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp @@ -7,6 +7,9 @@ #include #include "PokemonBDSP_AutoStory_Maps.h" #include "PokemonBDSP_AutoStory_StoryMaps.h" +#include "PokemonBDSP_AutoStory_StorySpots.h" +#include "PokemonBDSP_AutoStory_StoryTrainers.h" +#include "PokemonBDSP_AutoStory_TrainerSight.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -17,25 +20,14 @@ using Pokemon::MapData; using Pokemon::TilePos; -const char* const MAP_ROUTE_201 = "Route 201"; -const char* const MAP_SANDGEM_TOWN = "Sandgem Town"; -const char* const MAP_ROUTE_202 = "Route 202"; -const char* const MAP_JUBILIFE_CITY = "Jubilife City"; -const char* const MAP_OREBURGH_MINE = "Oreburgh Mine"; -const char* const MAP_RAVAGED_PATH = "Ravaged Path"; -const char* const MAP_ROUTE_204 = "Route 204"; -const char* const MAP_OREBURGH_CITY = "Oreburgh City"; -const char* const MAP_FLOAROMA_TOWN = "Floaroma Town"; -const char* const MAP_ROUTE_204_SOUTH = "Route 204 South"; -const char* const MAP_ROUTE_203 = "Route 203"; namespace{ // One map on its own. -StoryWorld single(const char* name, const std::string& json_map){ +StoryWorld single(std::string_view name, const std::string& json_map){ StoryWorld world; - world.add(name, story_map(json_map), {0, 0}); + world.add(std::string(name), story_map(json_map), {0, 0}); return world; } @@ -210,14 +202,14 @@ std::vector story_save_spots(){ }; } -std::vector story_door_front(const char* map, const TilePos& door){ - const TilePos below = story_maps().to_world(map, door.next(Direction::SOUTH)); +std::vector story_door_front(std::string_view map, const TilePos& door){ + const TilePos below = story_maps().to_world(std::string(map), door.next(Direction::SOUTH)); return {below.next(Direction::WEST), below, below.next(Direction::EAST)}; } namespace{ // A region of Route 202, in world tiles of story_maps(). -std::vector route202_region(const char* region){ +std::vector route202_region(std::string_view region){ std::vector tiles; for (const TilePos& pos : map_region("Route202", region)){ tiles.push_back(story_maps().to_world(MAP_ROUTE_202, pos)); @@ -255,7 +247,7 @@ std::vector route202_trainer_sights(){ } std::vector route204_north_trainer_sights(){ - const auto at = [](const char* point){ return map_point("Route204North", point); }; + const auto at = [](std::string_view point){ return map_point("Route204North", point); }; return { {.name = "Twins (left)", .pos = at("trainer_twin_left"), .facing = Direction::SOUTH, .range = 3}, {.name = "Twins (right)", .pos = at("trainer_twin_right"), .facing = Direction::SOUTH, .range = 4}, @@ -275,7 +267,7 @@ std::vector route204_north_trainer_sights(){ // fought). The planner cannot avoid it: she is listed so the route knows // whom it may meet, with the range that fits. std::vector route204_south_trainer_sights(){ - const auto at = [](const char* point){ return map_point("Route204South", point); }; + const auto at = [](std::string_view point){ return map_point("Route204South", point); }; return { {.name = "Lass Samantha", .pos = at("trainer_samantha"), .facing = Direction::SOUTH, .range = 4}, {.name = "Lass Sarah", .pos = at("trainer_sarah"), .facing = Direction::NORTH, .range = 4}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h index 13e7fec7fc..7b5855cd4a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h @@ -3,11 +3,12 @@ * From: https://github.com/PokemonAutomation/ * * The maps the story walks through, joined into story worlds, and the - * places and trainers on them that the story's walks need. The tiles and - * named points come from the JSON maps (PokemonBDSP_AutoStory_Maps.h); - * where the maps sit relative to each other, and the trainers' sight - * ranges, the maps do not say, so they are here. + * lines and entrances on them that the story's plans end at. The tiles + * and named points come from the JSON maps (PokemonBDSP_AutoStory_Maps.h); + * where the maps sit relative to each other the maps do not say, so it is + * here. Spots and trainers on the maps: StorySpots.h, StoryTrainers.h. */ +// code-health: allow header_symbols -- each story map's world sits next to the lines and entrances on it that its plans end at #ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_H #define PokemonAutomation_PokemonBDSP_AutoStory_StoryMaps_H @@ -15,7 +16,7 @@ #include #include #include "Pokemon/Navigation/Pokemon_Grid.h" -#include "PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP_AutoStory_StoryMapNames.h" #include "PokemonBDSP_AutoStory_StoryWorld.h" namespace PokemonAutomation{ @@ -23,31 +24,6 @@ namespace NintendoSwitch{ namespace PokemonBDSP{ -// Names of the maps in the story worlds below. Each is placed from the -// JSON map named without spaces ("Route 201" from Route201.json), except -// MAP_ROUTE_204, which is Route204North.json. -extern const char* const MAP_ROUTE_201; -// Sandgem Town overworld map name. -extern const char* const MAP_SANDGEM_TOWN; -// Route 202 overworld map name. -extern const char* const MAP_ROUTE_202; -// Jubilife City overworld map name. -extern const char* const MAP_JUBILIFE_CITY; -// Oreburgh Mine map name. -extern const char* const MAP_OREBURGH_MINE; -// Ravaged Path map name. -extern const char* const MAP_RAVAGED_PATH; -// Route 204 North map name. -extern const char* const MAP_ROUTE_204; -// Route 204 South map name. -extern const char* const MAP_ROUTE_204_SOUTH; -// Route 203 overworld map name. -extern const char* const MAP_ROUTE_203; -// Oreburgh City overworld map name. -extern const char* const MAP_OREBURGH_CITY; -// Floaroma Town overworld map name. -extern const char* const MAP_FLOAROMA_TOWN; - // Route 201, Sandgem Town and Route 202. const StoryWorld& story_maps(); @@ -96,50 +72,6 @@ const StoryWorld& floaroma_maps(); // legs until the console has confirmed their maps. bool story_map_plannable(const std::string& map); -// The open rows at the top of Route 202, in world tiles: walking north from -// any of them enters Jubilife City. -bool story_at_jubilife_exit(const Pokemon::TilePos& world); - -// Where the post-catch half of 00.04 may start, in world tiles: the catch -// spot (00.03 saves there after the catch) and the save spot under the -// ledge (00.04 saves there once it has Potions, before Route 202's trainers). -std::vector story_save_spots(); - -// Where 00.04b's save after the catch may stand, in world tiles: wherever -// the catch's walks in the grass ended, the patch (15..20, 25..27) and the -// lawn column east of it, (21, 25..29), down to the pocket behind the tree -// row where r252's catch ended and saved (the save loads there: (21, 29) -// by the screen, the 202 sign 3 columns right and 4 rows up). -std::vector story_catch_save_area(); - -// Where a walk out of the door `door` of `map` may leave us, in world tiles: -// the tile below it and its neighbours either side, since the door opening -// is not lined up with one tile (Jubilife's Center, r85). -std::vector story_door_front(const char* map, const Pokemon::TilePos& door); - -// Where we may stand after training in the catch grass, in world tiles: the -// training walks up and down the catch spot's column, between the tree walls -// north and south of the grass, so a battle may stop us on any of its -// three rows. A column either side allows for where the catch left us. -std::vector story_after_training_area(); - -// Route 202's trainers, in world tiles of story_maps(). -std::vector story_trainer_sights(); - -// The trainers of a map, in its own tiles, with the sight ranges that fit -// the console. A trainer who looks two ways is listed once per way. -std::vector route202_trainer_sights(); -// Returns trainer sights for Route 204 North. -std::vector route204_north_trainer_sights(); -// Returns trainer sights for Route 204 South. -std::vector route204_south_trainer_sights(); -// Returns trainer sights for Oreburgh Gym. -std::vector oreburgh_gym_trainer_sights(); - -// Route 204 South's tiles in the trainers' sight that a walk can avoid: -// all but Sarah's east line, which crosses the street (see the sights). -std::vector route204_south_tiles_to_avoid(); - } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StorySpots.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StorySpots.h new file mode 100644 index 0000000000..8b68450d3a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StorySpots.h @@ -0,0 +1,53 @@ +/* BDSP AutoStory - Story spots + * + * From: https://github.com/PokemonAutomation/ + * + * Spots on the Route 201 to Route 202 world (story_maps()) where + * segment 00's walks start, save and end, in world tiles. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StorySpots_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StorySpots_H + +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// The open rows at the top of Route 202, in world tiles: walking north from +// any of them enters Jubilife City. +bool story_at_jubilife_exit(const Pokemon::TilePos& world); + +// Where the post-catch half of 00.04 may start, in world tiles: the catch +// spot (00.03 saves there after the catch) and the save spot under the +// ledge (00.04 saves there once it has Potions, before Route 202's trainers). +std::vector story_save_spots(); + +// Where 00.04b's save after the catch may stand, in world tiles: wherever +// the catch's walks in the grass ended, the patch (15..20, 25..27) and the +// lawn column east of it, (21, 25..29), down to the pocket behind the tree +// row where r252's catch ended and saved (the save loads there: (21, 29) +// by the screen, the 202 sign 3 columns right and 4 rows up). +std::vector story_catch_save_area(); + +// Where a walk out of the door `door` of `map` may leave us, in world tiles: +// the tile below it and its neighbours either side, since the door opening +// is not lined up with one tile (Jubilife's Center, r85). +std::vector story_door_front(std::string_view map, const Pokemon::TilePos& door); + +// Where we may stand after training in the catch grass, in world tiles: the +// training walks up and down the catch spot's column, between the tree walls +// north and south of the grass, so a battle may stop us on any of its +// three rows. A column either side allows for where the catch left us. +std::vector story_after_training_area(); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryTrainers.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryTrainers.h new file mode 100644 index 0000000000..f2a6becb64 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryTrainers.h @@ -0,0 +1,43 @@ +/* BDSP AutoStory - Story trainers + * + * From: https://github.com/PokemonAutomation/ + * + * The trainers on the story maps, with the sight ranges that fit the + * console: the maps do not say how far a trainer sees. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryTrainers_H +#define PokemonAutomation_PokemonBDSP_AutoStory_StoryTrainers_H + +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonBDSP_AutoStory_TrainerSight.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Route 202's trainers, in world tiles of story_maps(). +std::vector story_trainer_sights(); + +// The trainers of a map, in its own tiles, with the sight ranges that fit +// the console. A trainer who looks two ways is listed once per way. +std::vector route202_trainer_sights(); +// Returns trainer sights for Route 204 North. +std::vector route204_north_trainer_sights(); +// Returns trainer sights for Route 204 South. +std::vector route204_south_trainer_sights(); +// Returns trainer sights for Oreburgh Gym. +std::vector oreburgh_gym_trainer_sights(); + +// Route 204 South's tiles in the trainers' sight that a walk can avoid: +// all but Sarah's east line, which crosses the street (see the sights). +std::vector route204_south_tiles_to_avoid(); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index 2713d29025..d6f7a67b80 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -9,6 +9,7 @@ #include #include "Common/Cpp/Exceptions.h" #include "PokemonBDSP_AutoStory_StoryWorld.h" +#include "PokemonBDSP_AutoStory_WalkRules.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index 6940a5be4d..cf46b6f0c5 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -117,24 +117,6 @@ std::vector wandering_hazards(const StoryWorld& world); bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); // Whether a world tile is a recovery hazard (wander box or warp). bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); -// Whether a map holds this world tile. -bool covered(const StoryWorld& world, const Pokemon::TilePos& pos); -// Whether the player can stand on this tile. -bool standable(const StoryWorld& world, const Pokemon::TilePos& pos); -// Where one step from `from` lands, or nothing if the player is stopped. -// A step onto a ledge the arrow's way hops to the tile past it. -std::optional step(const StoryWorld& world, const Pokemon::TilePos& from, Pokemon::Direction direction); -// Whether a step from `pos` is refused by a tile that holds the player -// in place. Doors and tiles off the maps are not walls: walking into a -// door enters the building, and ground off the maps may be an exit. -bool at_wall(const StoryWorld& world, const Pokemon::TilePos& pos, Pokemon::Direction direction); -// The tiles the player passes when walking `tiles` tiles from `from`, the -// first one after `from` first. Stops early where the player is stopped. -std::vector leg_path(const StoryWorld& grid, Pokemon::TilePos from, Pokemon::Direction direction, size_t tiles); -// Whether a warp (a door's tile) lies within `reach` tiles `direction` of -// one of `from`, nothing stopping the player before it: where a walk that -// ran on past its leg's end may have gone through (#268 slice 2). -bool warp_within(const StoryWorld& world, const std::vector& from, Pokemon::Direction direction, size_t reach); // "Route 201 (45, 3)", or "world (x, y)" if no map holds it. std::string describe(const StoryWorld& world, const Pokemon::TilePos& pos); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TrainerSight.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TrainerSight.h new file mode 100644 index 0000000000..30f9130372 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TrainerSight.h @@ -0,0 +1,47 @@ +/* BDSP AutoStory - Trainer sight + * + * From: https://github.com/PokemonAutomation/ + * + * Which tiles a trainer sees, and which legs of a walk cross them. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_TrainerSight_H +#define PokemonAutomation_PokemonBDSP_AutoStory_TrainerSight_H + +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP_AutoStory_StoryWorld.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// A trainer sees the tiles in a straight line in front of them, up to +// `range` tiles or the first tile the player cannot stand on. The maps +// have no sight ranges, so story code lists them. +struct TrainerSight{ + std::string name; + Pokemon::TilePos pos; + Pokemon::Direction facing = Pokemon::Direction::NORTH; + int range = 4; +}; +// Computes straight line-of-sight tiles for a trainer. +std::vector sight_tiles(const StoryWorld& world, const TrainerSight& trainer); + +// For each leg, the trainers whose sight line it enters. +std::vector> legs_crossing_sight( + const StoryWorld& world, + const Pokemon::TilePos& from, + const std::vector& legs, + const std::vector& trainers +); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h new file mode 100644 index 0000000000..d6a5c6f90a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h @@ -0,0 +1,46 @@ +/* BDSP AutoStory - Walk rules + * + * From: https://github.com/PokemonAutomation/ + * + * Where the player can stand and step on a story world, from its tiles. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_WalkRules_H +#define PokemonAutomation_PokemonBDSP_AutoStory_WalkRules_H + +#include +#include +#include +#include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonBDSP_AutoStory_StoryWorld.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Whether a map holds this world tile. +bool covered(const StoryWorld& world, const Pokemon::TilePos& pos); +// Whether the player can stand on this tile. +bool standable(const StoryWorld& world, const Pokemon::TilePos& pos); +// Where one step from `from` lands, or nothing if the player is stopped. +// A step onto a ledge the arrow's way hops to the tile past it. +std::optional step(const StoryWorld& world, const Pokemon::TilePos& from, Pokemon::Direction direction); +// Whether a step from `pos` is refused by a tile that holds the player +// in place. Doors and tiles off the maps are not walls: walking into a +// door enters the building, and ground off the maps may be an exit. +bool at_wall(const StoryWorld& world, const Pokemon::TilePos& pos, Pokemon::Direction direction); +// The tiles the player passes when walking `tiles` tiles from `from`, the +// first one after `from` first. Stops early where the player is stopped. +std::vector leg_path(const StoryWorld& grid, Pokemon::TilePos from, Pokemon::Direction direction, size_t tiles); +// Whether a warp (a door's tile) lies within `reach` tiles `direction` of +// one of `from`, nothing stopping the player before it: where a walk that +// ran on past its leg's end may have gone through (#268 slice 2). +bool warp_within(const StoryWorld& world, const std::vector& from, Pokemon::Direction direction, size_t reach); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp index 3d73a54243..b26f8caf51 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp @@ -3,6 +3,9 @@ * From: https://github.com/PokemonAutomation/ */ #include +#include "PokemonBDSP_AutoStory_RobustRoute.h" +#include "PokemonBDSP_AutoStory_RoutePlanner.h" +#include "PokemonBDSP_AutoStory_WalkRules.h" #include "PokemonBDSP_AutoStory_WallRecovery.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h index 954f02c4ae..fbf95a6f2a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h @@ -9,6 +9,7 @@ #define PokemonAutomation_PokemonBDSP_AutoStory_WallRecovery_H #include "Pokemon/Navigation/Pokemon_WallRecovery.h" +#include "PokemonBDSP_AutoStory_RobustRoute.h" #include "PokemonBDSP_AutoStory_RoutePlanner.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp index 5e0f972700..6c055847d0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp @@ -14,7 +14,10 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Data/PokemonBDSP_AutoStory_RobustRoute.h" #include "Data/PokemonBDSP_AutoStory_RoutePlanner.h" +#include "Data/PokemonBDSP_AutoStory_TrainerSight.h" +#include "Data/PokemonBDSP_AutoStory_WalkRules.h" #include "Data/PokemonBDSP_AutoStory_WallRecovery.h" #include "Data/PokemonBDSP_AutoStory_Maps.h" #include "PokemonBDSP_AutoStory_RoutePlanner_Tests.h" @@ -165,7 +168,7 @@ Pokemon::MapData recovery_map(const RecoveryGeometryInput& input){ } map.name = "RecoveryDiagnostic"; map.tiles = Pokemon::Grid{7, 3, {}}; - for (const char* row : {"#######", "#.....#", "#######"}){ + for (std::string_view row : {"#######", "#.....#", "#######"}){ for (char glyph : std::string(row)){ map.tiles.cells.push_back(*Pokemon::tile_from_glyph(glyph)); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp index 6c5ed6fd46..d417b27ea2 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Segment00_Tests.cpp @@ -7,6 +7,8 @@ #include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Data/PokemonBDSP_AutoStory_Maps.h" +#include "Data/PokemonBDSP_AutoStory_RobustRoute.h" +#include "Data/PokemonBDSP_AutoStory_RoutePlanner.h" #include "Data/PokemonBDSP_AutoStory_Segment00Lines.h" #include "Data/PokemonBDSP_AutoStory_StoryMaps.h" #include "Data/PokemonBDSP_AutoStory_PlanCosts.h" @@ -131,13 +133,13 @@ std::string check_triggers(Logger& logger, const WalkedLine& line, const std::ve // The points the route records start and end on, each of which must lie // on one of the lines. struct NamedTile{ - const char* map; // in segment00_maps() - const char* json_map; - const char* point; + std::string map; // in segment00_maps() + std::string json_map; + std::string point; }; std::vector named_tiles(){ - const char* twinleaf = Segment00Lines::MAP_TWINLEAF_TOWN; - const char* lakefront = Segment00Lines::MAP_VERITY_LAKEFRONT; + const std::string& twinleaf = Segment00Lines::MAP_TWINLEAF_TOWN; + const std::string& lakefront = Segment00Lines::MAP_VERITY_LAKEFRONT; return { {.map = twinleaf, .json_map = "TwinleafTown", .point = "house_doorstep"}, {.map = twinleaf, .json_map = "TwinleafTown", .point = "barry_doorstep"}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp index 48fe3d547e..6d181824fc 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryMaps_Tests.cpp @@ -18,8 +18,14 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Data/PokemonBDSP_AutoStory_Maps.h" #include "Data/PokemonBDSP_AutoStory_PlanCosts.h" +#include "Data/PokemonBDSP_AutoStory_RobustRoute.h" +#include "Data/PokemonBDSP_AutoStory_RoutePlanner.h" #include "Data/PokemonBDSP_AutoStory_RouteRecords.h" #include "Data/PokemonBDSP_AutoStory_StoryMaps.h" +#include "Data/PokemonBDSP_AutoStory_StorySpots.h" +#include "Data/PokemonBDSP_AutoStory_StoryTrainers.h" +#include "Data/PokemonBDSP_AutoStory_TrainerSight.h" +#include "Data/PokemonBDSP_AutoStory_WalkRules.h" #include "PokemonBDSP_AutoStory_StoryMaps_Tests.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index e4cca12a13..99cb510515 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -14,6 +14,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Data/PokemonBDSP_AutoStory_StoryWorld.h" +#include "Data/PokemonBDSP_AutoStory_WalkRules.h" #include "PokemonBDSP_AutoStory_StoryWorld_Tests.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 117a0e2fee..d99619571f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1724,16 +1724,22 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RobustRoute.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RouteRecords.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_StoryMapNames.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StorySpots.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryTrainers.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_TrainerSight.h + Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.h Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp