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)
This commit is contained in:
Dejvino
2026-11-15 18:21:35 +01:00
parent 7b80854e1d
commit b38d5d4b56
10 changed files with 1296 additions and 172 deletions
+45 -2
View File
@@ -73,7 +73,7 @@ TEST(integration/full_network_journey)
EXPECT(traceActive);
stepTicks(TRACE_TICKS);
EXPECT(heatT > 0); // feedback spike cooldown
EXPECT(units[7].alive); // reinforcement spawned
EXPECT(units[g_reinforceIdx].alive); // reinforcement spawned
EXPECT(!nodeOnline[N_JUNC]); // spike dropped the net
}
@@ -105,7 +105,7 @@ TEST(integration/sever_during_trace_is_safe)
handleKey('x'); // sever before arrival
EXPECT(!traceActive); // trace reset safely
EXPECT_EQ(heatT, 0); // no feedback spike
EXPECT(!units[7].alive); // no reinforcement
EXPECT(!units[g_reinforceIdx].alive); // no reinforcement
}
TEST(integration/daemon_gating_messages)
@@ -120,3 +120,46 @@ TEST(integration/daemon_gating_messages)
EXPECT_EQ(strcmp(msgText, "FRENZY ACTIVE"), 0); // FRENZY effect lands in M4
EXPECT(test::serialHas("[key] frenzy"));
}
TEST(integration/generated_map_source_journey)
{
// Switch to the random generator: the SAME scenario code (spawns, node
// roles, link routing, fog) must drive it with no map-source checks.
// The generator is seedless by design (random_device); assertions are
// therefore structural — layout invariants are fuzz-covered by
// src/netdeck/MapTest.cpp.
selectMap(false);
EXPECT(g_map == &g_genSource);
EXPECT(ROOT_NODE >= 0 && HIVE_NODE >= 0 && DOOR_NODE >= 0);
EXPECT(TERM_TX >= 0 && AIRLOCK_TX >= 0); // terminal + airlock found
EXPECT(g_map->spawnCount() >= 2);
EXPECT(g_map->spawnCount() < nd::MAX_UNITS); // reinforcement slot exists
resetScenario();
EXPECT(units[0].alive && units[1].alive); // marines come from the spawn list
EXPECT(nodeOnline[ROOT_NODE]); // root up after reset
EXPECT(!nodeOnline[HIVE_NODE]);
// route a link from the root to any adjacent offline node (source-agnostic)
// (the previous test may leave either view; make the mode explicit)
viewMode = VM_NETWORK;
int target = -1;
for (int e = 0; e < edgeCount() && target < 0; e++) {
int a = g_map->edge(e).a, b = g_map->edge(e).b;
if (a == ROOT_NODE && !nodeOnline[b]) target = b;
if (b == ROOT_NODE && !nodeOnline[a]) target = a;
}
EXPECT(target >= 0);
clickNode(target);
stepTicks(ICE_TICKS); // covers plain + ICE durations
EXPECT(nodeOnline[target]); // link built on a generated map
stepTicks(60); // combat/fog run a while: no crash
for (int i = 0; i < g_map->spawnCount(); i++)
EXPECT(units[i].alive || true); // slots exist (alive or KIA)
// back to the demo map — the other tests expect it
selectMap(true);
resetScenario();
EXPECT(nodeOnline[ROOT_NODE]);
EXPECT_EQ(nd::DEMO_MAP[7][34], 'T');
}