Files
lilygo-t-deck/src/netdeck/nd_demomap.h
T
Dejvino b38d5d4b56 Extract map-specific data into a generic MapSource interface
One interface (nd_mapsource.h) now owns everything map-specific: tiles,
rooms/doors/cameras, the network graph (nodes + edges with roles replacing
the hardcoded N_AIRLK/N_DOOR/N_HIVE indices) and the entity spawn list.
The scenario populates its structures once via selectMap() and never checks
which map is active.

- DemoMapSource: self-contained demo grid (moved out of the sketch), demo
  node/edge/spawn tables
- GenMapSource: adapts the random MapGenerator — now with L-corridors for
  guaranteed connectivity, doors that lead somewhere, airlock pad, terminal
  and crates (never on corridor tiles); network graph derived from the room
  chain, marine-first spawn list with droid patrols
- NetDeck.ino: all source branching removed; red trace follows the real
  active-link path (BFS HIVE->ROOT); reinforcement spawns near the blast door
- Tests: MapTest validates 50 generated runs + demo via the interface with
  an airlock flood-fill; new generated-map integration journey; test node
  handles resolve through the source (no hardcoded indices)
2026-11-15 18:21:35 +01:00

161 lines
6.8 KiB
C++

/**
* @file nd_demomap.h
* @brief NetDeck — Breach & Board: demo map source.
*
* The hardcoded 3-room demo floorplan (airlock bottom-left, main corridor
* L-shaped middle, server room right) with its network graph and entity
* spawn list, all behind the generic MapSource interface. The demo map
* remains available for automated tests while the random MapGenerator is
* the default play map.
*
* Header-only: include from sketch or test harness.
*/
#pragma once
#include <cstdint>
#include <vector>
#include <string>
#include "nd_layout.h"
#include "nd_mapsource.h"
// ---------------------------------------------------------------------------
// Demo map: 40x24 tile coordinate space
// ---------------------------------------------------------------------------
// # = wall, . = floor, o = cover crate, + = blast door, A = airlock, T = terminal
// Airlock room (bottom-left), main corridor (L-shaped middle),
// server room (right). The '+' door at (28,12) is the Room2/Room3 blast door.
namespace nd {
static const char* const DEMO_MAP[TILE_ROWS] = {
"########################################",
"#.........#.................#..........#",
"#.........#......#..........#..........#",
"#...#.....#......#..........#.....o....#",
"#....o....#......#..........#..........#",
"#...#.....#......#..........#..........#",
"#.........#.................#..........#",
"#.........#.................#.....T....#",
"#...........................#..........#",
"#...........................#..........#",
"#.........#...#.....o.......#..........#",
"#.........#...#.............#..........#",
"#.........#.................+..........#",
"###########.................#..........#",
"#.........#.................#..........#",
"#....#....#...........o.....#....#.....#",
"#.........#.................#..........#",
"#...........................#..........#",
"#...........................#..........#",
"#.........#.....#...........#..........#",
"#.........#.....#...........#.....o....#",
"#.A.......#.................#..........#",
"#.........#.................#..........#",
"########################################",
};
// ---------------------------------------------------------------------------
// Demo tables (namespace scope, internal linkage — one copy per TU)
// ---------------------------------------------------------------------------
// Network graph: 7 nodes pinned to demo tiles. Roles replace the old
// hardcoded N_AIRLK/N_DOOR/N_HIVE indices.
static const int DEMO_NODE_COUNT = 7;
static const int DEMO_EDGE_COUNT = 6;
static const NetNodeDef DEMO_NODES[DEMO_NODE_COUNT] = {
{ "AIRLK", 4, 20, C_AIRLOCK, 3, true, NR_ROOT },
{ "JUNC", 18, 6, C_NODE, 3, false, NR_NONE },
{ "DOOR", 28, 12, C_DOOR, 3, false, NR_DOOR },
{ "HIVE", 35, 4, C_HIVE, 3, false, NR_HIVE },
{ "CAM1", 14, 2, C_CAMERA, 6, false, NR_CAMERA },
{ "CAM2", 31, 3, C_CAMERA, 6, false, NR_CAMERA },
{ "CAM3", 22, 18, C_CAMERA, 6, false, NR_CAMERA },
};
static const NetEdgeDef DEMO_EDGES[DEMO_EDGE_COUNT] = {
{ 0, 1, "AIRLK-JUNC" },
{ 1, 2, "JUNC-DOOR" },
{ 1, 3, "JUNC-HIVE" },
{ 1, 4, "JUNC-CAM1" },
{ 2, 5, "DOOR-CAM2" },
{ 4, 6, "CAM1-CAM3" },
};
// Entity spawn list — mirrors the demo encounter layout:
// 0,1 marines | 2 patrol droid | 3 stationary droid | 4 heavy |
// 5,6 turrets | 8,9,10 patrol/guard droids | 11 turret on the door approach
// (marines first — slots 0/1 are the squad)
static const int DEMO_SPAWN_COUNT = 11;
static const UnitSpawn DEMO_SPAWNS[DEMO_SPAWN_COUNT] = {
{ 0, 2, 21, -1, -1 }, // marine (at the airlock)
{ 0, 3, 21, -1, -1 }, // marine
{ 1, 12, 2, 12 + 2 * TILE_COLS, 26 + 18 * TILE_COLS, }, // corridor patrol
{ 1, 20, 12, -1, -1 }, // stationary droid
{ 2, 32, 10, -1, -1 }, // heavy (server room)
{ 3, 33, 5, -1, -1 }, // turret (terminal guard)
{ 3, 35, 5, -1, -1 }, // turret (terminal guard)
{ 1, 2, 2, 2 + 2 * TILE_COLS, 8 + 6 * TILE_COLS, }, // top-left patrol
{ 1, 31, 16, -1, -1 }, // server-room guard
{ 1, 14, 18, 13 + 18 * TILE_COLS, 25 + 18 * TILE_COLS, }, // corridor patrol
{ 3, 26, 10, -1, -1 }, // turret (door approach)
};
// ---------------------------------------------------------------------------
// DemoMapSource: everything map-specific about the demo scenario, in one place
// ---------------------------------------------------------------------------
class DemoMapSource : public MapSource {
public:
DemoMapSource() {
buildMapVector();
buildStructures();
}
// --- tile grid ---
char tileAt(int tx, int ty) const override {
if (tx < 0 || ty < 0 || tx >= TILE_COLS || ty >= TILE_ROWS) return '#';
return DEMO_MAP[ty][tx];
}
const std::vector<std::string>& getMap() const override { return mapVec_; }
// --- structures ---
const std::vector<Room>& getRooms() const override { return rooms_; }
const std::vector<Door>& getDoors() const override { return doors_; }
const std::vector<Camera>& getCameras() const override { return cameras_; }
// --- network graph ---
int nodeCount() const override { return DEMO_NODE_COUNT; }
const NetNodeDef& node(int i) const override { return DEMO_NODES[i]; }
int edgeCount() const override { return DEMO_EDGE_COUNT; }
const NetEdgeDef& edge(int i) const override { return DEMO_EDGES[i]; }
// --- entity spawn list ---
int spawnCount() const override { return DEMO_SPAWN_COUNT; }
const UnitSpawn& spawn(int i) const override { return DEMO_SPAWNS[i]; }
private:
void buildMapVector() {
mapVec_.reserve(TILE_ROWS);
for (int y = 0; y < TILE_ROWS; y++) mapVec_.emplace_back(DEMO_MAP[y]);
}
void buildStructures() {
rooms_.clear();
doors_.clear();
cameras_.clear();
Room r;
r = { 1, 14, 9, 21, 5, 17, 72 }; rooms_.push_back(r); // airlock
r = { 11, 1, 27, 21, 19, 11, 357 }; rooms_.push_back(r); // corridor
r = { 29, 1, 38, 12, 33, 6, 120 }; rooms_.push_back(r); // server room
Door d = { 28, 12, false, false, true }; // blast door
doors_.push_back(d);
}
std::vector<std::string> mapVec_;
// Demo room regions (informational: airlock / corridor / server)
std::vector<Room> rooms_;
std::vector<Door> doors_; // the Room2/Room3 blast door
std::vector<Camera> cameras_; // demo cameras live on the net (CAM1-3)
};
} // namespace nd