Skip to content

Commit ce701d4

Browse files
dayfineclaude
andcommitted
Merge bdsp/maps-rederive (#111: maps as JSON) into bdsp/segment00-planned-walks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
2 parents 778bea6 + 04b00fa commit ce701d4

24 files changed

Lines changed: 1645 additions & 635 deletions

‎SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_FloaromaTown.cpp‎

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "PokemonBDSP_AutoStory_MapGrids.h"
78
#include "PokemonBDSP_AutoStory_FloaromaTown.h"
89

910
namespace PokemonAutomation{
@@ -66,42 +67,7 @@ using namespace Pokemon;
6667
// has), and it has a Beauty at (10, 19) looking south instead of the man at
6768
// (11, 26).
6869
const TileGrid& grid(){
69-
static const TileGrid grid({
70-
// 0 1 2 3
71-
R"(######........................##)", // 0
72-
R"(##NN##........................##)", // 1
73-
R"(..............................##)", // 2
74-
R"(..............................##)", // 3
75-
R"(..............................##)", // 4
76-
R"(..............................##)", // 5
77-
R"(..............................##)", // 6
78-
R"(..................#####.......##)", // 7
79-
R"(..................#####.......##)", // 8
80-
R"(..................#####.......##)", // 9
81-
R"(......N...........#####.......##)", // 10
82-
R"(..........####...S##.##N......##)", // 11
83-
R"(..........####................##)", // 12
84-
R"(..........####................##)", // 13
85-
R"(..........#D##................##)", // 14
86-
R"(.......................####..S##)", // 15
87-
R"(.......................####...##)", // 16
88-
R"(.......................#D##...##)", // 17
89-
R"(..............................##)", // 18
90-
R"(.............S..................)", // 19
91-
R"(................................)", // 20
92-
R"(...................N............)", // 21
93-
R"(................................)", // 22
94-
R"(..NN..........#####....####...##)", // 23
95-
R"(..............#####....####...##)", // 24
96-
R"(..............#####....####...##)", // 25
97-
R"(...........N..##D##....#D##...##)", // 26
98-
R"(..............................##)", // 27
99-
R"(..............................##)", // 28
100-
R"(..............................##)", // 29
101-
R"(########.#...###################)", // 30
102-
R"(########.#...###################)", // 31
103-
});
104-
return grid;
70+
return story_grid("FloaromaTown");
10571
}
10672

10773
const TilePos ROUTE_204_ARRIVAL{11, 29};

‎SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_JubilifeCity.cpp‎

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <string>
88
#include <vector>
9+
#include "PokemonBDSP_AutoStory_MapGrids.h"
910
#include "PokemonBDSP_AutoStory_JubilifeCity.h"
1011

1112
namespace PokemonAutomation{
@@ -58,95 +59,8 @@ using namespace Pokemon;
5859
// one along row 21 (45..47), a Twin around (33,18), a School Kid on column
5960
// 51 (rows 33..35), a Pokefan around (41,30). Rowan and the grunts at the
6061
// north exit, the Collectors and Dawn are hidden by story flags.
61-
namespace{
62-
// Rows 0..31: the matrix's cell row 4 (world z 736..767), the north half.
63-
std::vector<std::string> north_half(){
64-
// 0 1 2 3 4 5 6
65-
// 0123456789012345678901234567890123456789012345678901234567890123
66-
return {
67-
R"(##########################################..............########)", // 0
68-
R"(##########################################..............########)", // 1
69-
R"(############################################.....###############)", // 2
70-
R"(############################################......##############)", // 3
71-
R"(############################################......##############)", // 4
72-
R"(############################################......##############)", // 5
73-
R"(############################################......##############)", // 6
74-
R"(#############################################....###############)", // 7
75-
R"(############################....#########.......S.##############)", // 8
76-
R"(############################....#########.........##############)", // 9
77-
R"(#########..#########..######....#########.........##############)", // 10
78-
R"(#########..#########..######....#########.........##############)", // 11
79-
R"(#########..#########..######....#########.........##############)", // 12
80-
R"(#########..#########..######....#########.........##############)", // 13
81-
R"(#########..#########..######....#########.........##############)", // 14
82-
R"(#########..##D###D##..######....####D####.........##############)", // 15
83-
R"(#########.............######........N......#.....#######....####)", // 16
84-
R"(#########.............######......................######....####)", // 17
85-
R"(..#######......N......######......................######....####)", // 18
86-
R"(..###########S......########...........S.........S##D###....####)", // 19
87-
R"(..#.S.#.......................#..........................#.S####)", // 20
88-
R"(................................................................)", // 21
89-
R"(D...............................................................)", // 22
90-
R"(D...............................................................)", // 23
91-
R"(................................................................)", // 24
92-
R"(..#...#.......................#.....N....................#..####)", // 25
93-
R"(..############.............####......####...................####)", // 26
94-
R"(..############.............####......####................#######)", // 27
95-
R"(##############.################...##.####..#.....######..#######)", // 28
96-
R"(##############.################...##.####.........#####..#######)", // 29
97-
R"(##############.################...................#D############)", // 30
98-
R"(################################.........................#######)", // 31
99-
};
100-
}
101-
// Rows 32..63: cell row 5 (world z 768..799), the south half.
102-
std::vector<std::string> south_half(){
103-
// 0 1 2 3 4 5 6
104-
// 0123456789012345678901234567890123456789012345678901234567890123
105-
return {
106-
R"(################################.........................##D####)", // 32
107-
R"(################################.......................N.#######)", // 33
108-
R"(################################.........................#######)", // 34
109-
R"(###############............#####..............N..........#######)", // 35
110-
R"(###############............#####......#####..............#######)", // 36
111-
R"(###############..#########.#####.##########.......######.#######)", // 37
112-
R"(###############..#########.#####.##########.......######.#######)", // 38
113-
R"(###############..#########.#####.###########.....#######.#######)", // 39
114-
R"(##################################..S.##D##.......##D###########)", // 40
115-
R"(###############..#########.#####.........................#######)", // 41
116-
R"(##############...####D####N.###..........................#######)", // 42
117-
R"(##############...........................................#######)", // 43
118-
R"(##############.....S........................N............#######)", // 44
119-
R"(##############...........................................#######)", // 45
120-
R"(##############.............#########................N.N..#######)", // 46
121-
R"(###############............#########.#####...............#######)", // 47
122-
R"(###############............#########.#####...............#######)", // 48
123-
R"(###############.####..####.###############...............#######)", // 49
124-
R"(###############.####..####.###############...............#######)", // 50
125-
R"(###############.####..####.###############...........###########)", // 51
126-
R"(############D##.####..####.############D##...........###########)", // 52
127-
R"(##########.................#########.......#.....#...########.##)", // 53
128-
R"(##########.................#########.................########.##)", // 54
129-
R"(##########.......N....#..#.#########......S..........########.##)", // 55
130-
R"(##########............#..#.#########.................########.##)", // 56
131-
R"(##########.................#########.................########.##)", // 57
132-
R"(###########################################.......##############)", // 58
133-
R"(###########################################.......##############)", // 59
134-
R"(########################################.##.......##############)", // 60
135-
R"(########################################.####...################)", // 61
136-
R"(########################################..........##############)", // 62
137-
R"(########################################..........##############)", // 63
138-
};
139-
}
140-
}
141-
14262
const TileGrid& grid(){
143-
static const TileGrid grid = []{
144-
std::vector<std::string> rows = north_half();
145-
const std::vector<std::string> south = south_half();
146-
rows.insert(rows.end(), south.begin(), south.end());
147-
return TileGrid(rows);
148-
}();
149-
return grid;
63+
return story_grid("JubilifeCity");
15064
}
15165

15266
// Checked on the console (2026-10-30, CFR "walk"): 00.05's save stands

‎SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_LakeVerity.cpp‎

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "PokemonBDSP_AutoStory_MapGrids.h"
78
#include "PokemonBDSP_AutoStory_LakeVerity.h"
89

910
namespace PokemonAutomation{
@@ -56,42 +57,7 @@ using namespace Pokemon;
5657
// separate map (MAP_LAKE_VERITY_GALACTIC), reached from the same Lakefront
5758
// warp tiles.
5859
const TileGrid& grid(){
59-
static const TileGrid grid({
60-
// 0 1 2 3
61-
R"(################################)", // 0
62-
R"(################################)", // 1
63-
R"(################################)", // 2
64-
R"(################################)", // 3
65-
R"(......############....##########)", // 4
66-
R"(......############....##########)", // 5
67-
R"(.......###########......########)", // 6
68-
R"(.......###########......########)", // 7
69-
R"(.......###########".....########)", // 8
70-
R"(.......###########""....########)", // 9
71-
R"(################""""....########)", // 10
72-
R"(################NN""....########)", // 11
73-
R"(##############."""""..##########)", // 12
74-
R"(##############.""""...##########)", // 13
75-
R"(############..."""..############)", // 14
76-
R"(############........############)", // 15
77-
R"(##########..........############)", // 16
78-
R"(##########..........############)", // 17
79-
R"(############......##############)", // 18
80-
R"(############....N.##############)", // 19
81-
R"(############......##############)", // 20
82-
R"(############......##############)", // 21
83-
R"(##############..################)", // 22
84-
R"(################################)", // 23
85-
R"(################################)", // 24
86-
R"(################################)", // 25
87-
R"(################################)", // 26
88-
R"(################################)", // 27
89-
R"(################################)", // 28
90-
R"(################################)", // 29
91-
R"(################################)", // 30
92-
R"(################################)", // 31
93-
});
94-
return grid;
60+
return story_grid("LakeVerity");
9561
}
9662

9763
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/* BDSP AutoStory - Map grids
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include <format>
8+
#include <map>
9+
#include "Common/Cpp/Exceptions.h"
10+
#include "Common/Cpp/Json/JsonValue.h"
11+
#include "PokemonBDSP_AutoStory_Maps_TestData.h"
12+
#include "PokemonBDSP_AutoStory_MapGrids.h"
13+
14+
namespace PokemonAutomation{
15+
namespace NintendoSwitch{
16+
namespace PokemonBDSP{
17+
18+
using Pokemon::MapData;
19+
using Pokemon::TileGrid;
20+
using Pokemon::TileKind;
21+
using Pokemon::TilePos;
22+
using Pokemon::TileType;
23+
24+
25+
namespace{
26+
27+
std::optional<TileType> tile_type_of(TileKind kind){
28+
switch (kind){
29+
case TileKind::WALL: return TileType::BLOCKED;
30+
case TileKind::OPEN: return TileType::WALKABLE;
31+
case TileKind::TALL_GRASS: return TileType::TALL_GRASS;
32+
case TileKind::LEDGE_SOUTH: return TileType::LEDGE;
33+
case TileKind::DOOR: return TileType::DOOR;
34+
case TileKind::SIGN: return TileType::SIGN;
35+
default: return std::nullopt;
36+
}
37+
}
38+
39+
}
40+
41+
TileGrid tile_grid_from_map(const MapData& map){
42+
std::vector<std::string> rows;
43+
for (int y = 0; y < map.tiles.height; y++){
44+
std::string row;
45+
for (int x = 0; x < map.tiles.width; x++){
46+
const TileKind kind = map.tiles.at(TilePos{x, y});
47+
const std::optional<TileType> type = tile_type_of(kind);
48+
if (!type){
49+
throw ParseException(std::format(
50+
"{}: glyph '{}' at {} has no BDSP tile.", map.name, Pokemon::glyph_of(kind), Pokemon::to_string(TilePos{x, y})
51+
));
52+
}
53+
row += Pokemon::tile_char(*type);
54+
}
55+
rows.push_back(std::move(row));
56+
}
57+
for (const Pokemon::MapObject& object : map.objects){
58+
if (object.kind != Pokemon::ObjectKind::NPC || object.wander){
59+
throw ParseException(std::format("{}: object {} is not a person standing still.", map.name, object.name));
60+
}
61+
rows[object.y][object.x] = Pokemon::tile_char(TileType::NPC);
62+
}
63+
return TileGrid(rows);
64+
}
65+
66+
std::optional<std::string> grid_difference(const TileGrid& here, const TileGrid& there){
67+
if (here.width() != there.width() || here.height() != there.height()){
68+
return std::format("{} x {} here, {} x {} there", here.width(), here.height(), there.width(), there.height());
69+
}
70+
for (int y = 0; y < here.height(); y++){
71+
for (int x = 0; x < here.width(); x++){
72+
const TilePos pos{x, y};
73+
if (here.at(pos) != there.at(pos)){
74+
return std::format(
75+
"{}: '{}' here, '{}' there",
76+
Pokemon::to_string(pos), Pokemon::tile_char(here.at(pos)), Pokemon::tile_char(there.at(pos))
77+
);
78+
}
79+
}
80+
}
81+
return std::nullopt;
82+
}
83+
84+
85+
namespace{
86+
87+
std::map<std::string, TileGrid>& installed_grids(){
88+
static std::map<std::string, TileGrid> grids;
89+
return grids;
90+
}
91+
92+
const std::map<std::string, TileGrid>& built_in_grids(){
93+
static const std::map<std::string, TileGrid> grids = []{
94+
std::map<std::string, TileGrid> parsed;
95+
for (const auto& [name, json] : test_map_json()){
96+
const MapData map = Pokemon::parse_map(parse_json(json), name + ".json (built in)");
97+
if (map.name != name){
98+
throw ParseException(std::format("{}.json (built in): name is \"{}\".", name, map.name));
99+
}
100+
parsed.emplace(name, tile_grid_from_map(map));
101+
}
102+
return parsed;
103+
}();
104+
return grids;
105+
}
106+
107+
}
108+
109+
const TileGrid& built_in_grid(const std::string& name){
110+
const std::map<std::string, TileGrid>& grids = built_in_grids();
111+
if (auto iter = grids.find(name); iter != grids.end()){
112+
return iter->second;
113+
}
114+
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No BDSP story map named \"" + name + "\".");
115+
}
116+
117+
const TileGrid& story_grid(const std::string& name){
118+
const std::map<std::string, TileGrid>& grids = installed_grids();
119+
if (auto iter = grids.find(name); iter != grids.end()){
120+
return iter->second;
121+
}
122+
return built_in_grid(name);
123+
}
124+
125+
void install_story_grids(std::map<std::string, TileGrid> grids){
126+
if (installed_grids().empty()){
127+
installed_grids() = std::move(grids);
128+
}
129+
}
130+
131+
132+
133+
}
134+
}
135+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* BDSP AutoStory - Map grids
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
* The story's maps are JSON files in the shared map schema
6+
* (Pokemon_MapData.h), read with the shared loader and turned into the tile
7+
* grids the planner walks. Each map's X::grid() returns story_grid("X").
8+
*
9+
*/
10+
11+
#ifndef PokemonAutomation_PokemonBDSP_AutoStory_MapGrids_H
12+
#define PokemonAutomation_PokemonBDSP_AutoStory_MapGrids_H
13+
14+
#include <map>
15+
#include <optional>
16+
#include <string>
17+
#include "Pokemon/Navigation/Pokemon_MapData.h"
18+
#include "Pokemon/Navigation/Pokemon_TileGrid.h"
19+
20+
namespace PokemonAutomation{
21+
namespace NintendoSwitch{
22+
namespace PokemonBDSP{
23+
24+
25+
// A map's tiles as a tile grid: walls, open ground, tall grass, south
26+
// ledges, doors and signs; a standing person ("npc" object) is an NPC tile.
27+
// Throws ParseException, naming the map, for what BDSP's grids have no
28+
// tile for (water, ledges other than south, items, wanderers).
29+
Pokemon::TileGrid tile_grid_from_map(const Pokemon::MapData& map);
30+
31+
// "(x, y): 'N' here, '.' there", or nothing when the grids are the same
32+
// size and equal cell for cell.
33+
std::optional<std::string> grid_difference(const Pokemon::TileGrid& here, const Pokemon::TileGrid& there);
34+
35+
// The built-in copy of the map `name` (test_map_json()), parsed once.
36+
// Throws InternalProgramError for a name it does not have.
37+
const Pokemon::TileGrid& built_in_grid(const std::string& name);
38+
39+
// The grid of the map `name`: the one installed from Packages' files by
40+
// install_story_grids(), which the program does when it starts, else the
41+
// built-in copy (the unit tests, which have no Packages).
42+
const Pokemon::TileGrid& story_grid(const std::string& name);
43+
44+
// Makes story_grid() hand out `grids` from then on. Once only: callers keep
45+
// copies of what they were handed first.
46+
void install_story_grids(std::map<std::string, Pokemon::TileGrid> grids);
47+
48+
49+
50+
}
51+
}
52+
}
53+
#endif

0 commit comments

Comments
 (0)