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)
138 lines
5.1 KiB
C++
138 lines
5.1 KiB
C++
/**
|
|
* @file nd_mapsource.h
|
|
* @brief NetDeck — Breach & Board: generic map source interface.
|
|
*
|
|
* One interface for everything that is map-specific: the tile grid, the
|
|
* structural elements (rooms, doors, cameras), the network graph (nodes +
|
|
* edges) and the entity spawn list. A scenario populates its runtime
|
|
* structures from a MapSource exactly once and afterwards never needs to
|
|
* know (or check) where the map came from — the hardcoded demo floorplan
|
|
* and the random MapGenerator are interchangeable behind the interface.
|
|
*
|
|
* Header-only: include from sketch or test harness.
|
|
*/
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
#include <string>
|
|
#include "nd_layout.h"
|
|
|
|
namespace nd {
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Pool bounds for source-driven structures (sized for the worst generated map)
|
|
// ---------------------------------------------------------------------------
|
|
constexpr int MAX_NODES = 12; // network nodes across any map source
|
|
constexpr int MAX_EDGES = 16; // network edges across any map source
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Special node roles (replace the old hardcoded N_AIRLK/N_DOOR/N_HIVE indices)
|
|
// ---------------------------------------------------------------------------
|
|
enum NodeRole : uint8_t {
|
|
NR_NONE = 0, // plain junction node
|
|
NR_ROOT, // airlock uplink: always online, trace endpoint
|
|
NR_DOOR, // click toggles the blast door(s)
|
|
NR_HIVE, // ICE-protected hive: cracking spawns the red trace
|
|
NR_CAMERA, // camera: larger fog-of-war reveal radius while online
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Shared data structures (one shape for every map source)
|
|
// ---------------------------------------------------------------------------
|
|
struct Room {
|
|
int x0, y0; // top-left corner (inclusive)
|
|
int x1, y1; // bottom-right corner (inclusive)
|
|
int centerX; // center tile coordinate
|
|
int centerY;
|
|
int area; // number of floor tiles
|
|
};
|
|
|
|
struct Door {
|
|
int tx, ty; // tile coordinate ('+' on the map)
|
|
bool open; // whether the door starts open
|
|
bool isAirlock; // true if this is the airlock door
|
|
bool isHive; // true if this door leads to the hive room
|
|
};
|
|
|
|
struct Camera {
|
|
int tx, ty; // tile coordinate
|
|
int id; // camera ID
|
|
uint16_t color; // render color (C_CAMERA)
|
|
};
|
|
|
|
// A network node as the scenario consumes it (static definition — the
|
|
// runtime online state lives in the scenario, not here)
|
|
struct NetNodeDef {
|
|
const char* label;
|
|
int tx, ty; // tile position
|
|
uint16_t color; // render color
|
|
uint8_t sight; // fog reveal radius (tiles) while online
|
|
bool online; // initial online state (root = true)
|
|
uint8_t role; // NodeRole
|
|
};
|
|
|
|
struct NetEdgeDef {
|
|
uint8_t a, b; // node indices
|
|
const char* label; // "AIRLK-JUNC" style, for logs
|
|
};
|
|
|
|
// One entity spawn: applied by the scenario layer once at setup/reset.
|
|
// kind uses the shared unit taxonomy: 0=marine, 1=droid, 2=heavy, 3=turret.
|
|
struct UnitSpawn {
|
|
uint8_t kind;
|
|
int tx, ty;
|
|
int patA, patB; // patrol endpoints as tile indices (-1 = stationary)
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// MapSource abstract interface
|
|
// ---------------------------------------------------------------------------
|
|
class MapSource {
|
|
public:
|
|
virtual ~MapSource() = default;
|
|
|
|
// --- tile grid ---
|
|
virtual char tileAt(int tx, int ty) const = 0;
|
|
virtual const std::vector<std::string>& getMap() const = 0;
|
|
|
|
// --- structures ---
|
|
virtual const std::vector<Room>& getRooms() const = 0;
|
|
virtual const std::vector<Door>& getDoors() const = 0;
|
|
virtual const std::vector<Camera>& getCameras() const = 0;
|
|
|
|
// --- network graph ---
|
|
virtual int nodeCount() const = 0;
|
|
virtual const NetNodeDef& node(int i) const = 0;
|
|
virtual int edgeCount() const = 0;
|
|
virtual const NetEdgeDef& edge(int i) const = 0;
|
|
|
|
// --- entity spawn list ---
|
|
virtual int spawnCount() const = 0;
|
|
virtual const UnitSpawn& spawn(int i) const = 0;
|
|
|
|
// --- role lookups (shared implementation; -1 if the map has no such node)
|
|
int nodeByRole(uint8_t role) const {
|
|
for (int i = 0; i < nodeCount(); i++)
|
|
if (node(i).role == role) return i;
|
|
return -1;
|
|
}
|
|
int rootNode() const { return nodeByRole(NR_ROOT); }
|
|
int hiveNode() const { return nodeByRole(NR_HIVE); }
|
|
int doorNode() const { return nodeByRole(NR_DOOR); }
|
|
|
|
// First tile carrying `ch` (e.g. 'T' terminal, 'A' airlock); -1 if absent.
|
|
// Scans the tile grid, so it works for every source without branching.
|
|
bool findTile(char ch, int& tx, int& ty) const {
|
|
const std::vector<std::string>& m = getMap();
|
|
for (int y = 0; y < TILE_ROWS && y < (int)m.size(); y++) {
|
|
for (int x = 0; x < TILE_COLS && x < (int)m[y].size(); x++) {
|
|
if (m[y][x] == ch) { tx = x; ty = y; return true; }
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
|
|
} // namespace nd
|