Files
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

63 lines
2.0 KiB
C++

/**
* @file sim_helpers.h
* @brief Test helpers that touch sketch internals — include AFTER the
* sketch (single-TU inclusion gives the tests access to the
* sketch's statics, exactly like main.cpp gets them).
*/
#pragma once
#include "harness.h"
// advance the deterministic 20 Hz simulation by n ticks (no wall time)
inline void stepTicks(int n)
{
for (int i = 0; i < n; i++) stepSim();
}
// click exactly on a network node (Network view) — cursor + primary action
inline void clickNode(int node)
{
curX = nodePx(node);
curY = nodePy(node);
registerClick();
}
// click the center of a map tile (Cameras view) — places the beacon
inline void clickTile(int tx, int ty)
{
curX = tx * nd::TILE + nd::TILE / 2;
curY = ty * nd::TILE + nd::TILE / 2;
registerClick();
}
// find the active link on an edge, or -1
inline int linkIdx(int edge) { return linkOnEdge(edge); }
// ---------------------------------------------------------------------------
// Node handles resolved from the ACTIVE MAP SOURCE. The old tests hardcoded
// demo node indices (N_AIRLK/N_JUNC/...); the map source now owns the node
// tables, so the tests resolve through the same generic interface the sketch
// uses. (The fast suites run the demo map, where these are the classic nodes.)
// ---------------------------------------------------------------------------
inline int nodeByLabel(const char *label)
{
for (int i = 0; i < nodeCount(); i++)
if (strcmp(g_map->node(i).label, label) == 0) return i;
return -1;
}
#define N_AIRLK ROOT_NODE
#define N_DOOR DOOR_NODE
#define N_HIVE HIVE_NODE
#define N_JUNC nodeByLabel("JUNC")
#define N_CAM1 nodeByLabel("CAM1")
#define N_CAM2 nodeByLabel("CAM2")
#define N_CAM3 nodeByLabel("CAM3")
// fresh deterministic scenario state for a test
inline void freshScenario(unsigned seed = 0xC0FFEE)
{
std::srand((unsigned)seed);
resetScenario();
viewMode = VM_CAMERAS; // resetScenario deliberately keeps the view
test::serialClear();
}