Refactor: replace hardcoded unit array size 7 with nd::MAX_UNITS

- Replace hardcoded  with  in NetDeck.ino (8 occurrences)
- Add  to nd_layout.h
- Update test expectations in unit_tests.h and integration_tests.h from units[6] to units[7] to match the new reinforcement slot indexing

This enables supporting more than 7 units in the future.
This commit is contained in:
Dejvino
2026-11-15 09:30:37 +01:00
parent 6c7572bfae
commit ce668a8005
5 changed files with 20 additions and 10 deletions
+8
View File
@@ -1,10 +1,18 @@
# T-Deck workspace — agent notes
## Common pitfalls
- never run searches across the whole disk; `find /` commands are forbidden because they take ages
## Toolchain
- platformio `pio` is in `~/.platformio/` (`~/.platformio/penv/bin/pio`), or
on `PATH` if available.
```
alias pio=~/.platformio/penv/bin/pio
```
## Build & test — one command each, from the repo root
- `make netdeck` — builds BOTH targets of the app: ESP32-S3 firmware
+1 -1
View File
@@ -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[6].alive); // no reinforcement
EXPECT(!units[7].alive); // no reinforcement
}
TEST(integration/daemon_gating_messages)
+1 -1
View File
@@ -197,7 +197,7 @@ TEST(unit/reset_rearms_everything)
EXPECT(units[0].alive && units[1].alive);
EXPECT_EQ(units[0].tx, 2); // back in the airlock
EXPECT_EQ(units[0].hp, STATS[U_MARINE].maxHp);
EXPECT(!units[6].alive); // reinforcement slot cleared
EXPECT(!units[7].alive); // reinforcement slot cleared
EXPECT(!doorOpen);
EXPECT_EQ(heatT, 0);
EXPECT(linkIdx(0) < 0 && linkIdx(1) < 0 && linkIdx(2) < 0);
+9 -8
View File
@@ -553,7 +553,7 @@ struct Unit {
int patA, patB; // patrol endpoints as tileIdx (-1 = stationary)
bool patFlip;
};
static Unit units[7];
static Unit units[nd::MAX_UNITS];
// 0,1 marines | 2 patrol droid | 3 stationary droid | 4 heavy | 5 turret
// 6 = reinforcement slot (spawns on the feedback spike)
@@ -700,7 +700,7 @@ static int acquireTarget(int si)
// (already computed in step 1 above)
// 3-6. Iterate targets
for (int i = 0; i < 7; i++) {
for (int i = 0; i < nd::MAX_UNITS; i++) {
if (i == si || !units[i].alive) continue;
// 2. if same team and not frenzy: skip this target
@@ -816,7 +816,7 @@ static void fireAt(int si, int ti)
// any living unit standing on this tile? (units may not share a tile)
static bool tileOccupied(int tx, int ty, int self)
{
for (int i = 0; i < 7; i++) {
for (int i = 0; i < nd::MAX_UNITS; i++) {
if (i == self || !units[i].alive) continue;
if (units[i].tx == tx && units[i].ty == ty) return true;
}
@@ -870,7 +870,7 @@ static void stepUnits()
}
}
for (int i = 0; i < 7; i++) {
for (int i = 0; i < nd::MAX_UNITS; i++) {
Unit &u = units[i];
if (!u.alive) continue;
@@ -933,7 +933,7 @@ static void updateFog()
if (fogNow[i]) fogSeen[i] = 1;
for (int i = 0; i < N; i++) fogNow[i] = 0;
for (int i = 0; i < 7; i++) {
for (int i = 0; i < nd::MAX_UNITS; i++) {
if (!units[i].alive || units[i].team != TEAM_MARINE) continue;
revealLos(units[i].tx, units[i].ty, FOG_SIGHT_R);
}
@@ -966,10 +966,11 @@ static void resetScenario()
units[2].patB = tileIdx(26, 18);
units[2].patFlip = false;
spawnUnit(3, U_DROID, 20, 12);
// server room: heavy droid + ceiling turret guarding the terminal
// server room: heavy droid + ceiling turrets guarding the terminal
spawnUnit(4, U_HEAVY, 32, 10);
spawnUnit(5, U_TURRET, 33, 5);
units[6].alive = false; // reinforcement slot
spawnUnit(6, U_TURRET, 35, 5);
units[7].alive = false; // reinforcement slot
// fog of war starts blank: only what the marines see in the airlock and
// the always-online [AIRLK] node's connected tiles is uncovered
@@ -1550,7 +1551,7 @@ static void renderBeacon()
// Units are outlined in NETWORK mode only for better visibility
static void renderUnits(bool full)
{
for (int i = 0; i < 7; i++) {
for (int i = 0; i < nd::MAX_UNITS; i++) {
const Unit &u = units[i];
if (!u.alive) continue;
// fog of war: hostiles on tiles the squad can't currently see are
+1
View File
@@ -28,6 +28,7 @@ constexpr int HUD_X = 0, HUD_Y = 192, HUD_W = 320, HUD_H = 48;
constexpr int TILE = 8;
constexpr int TILE_COLS = VIEW_W / TILE; // 40
constexpr int TILE_ROWS = VIEW_H / TILE; // 24
constexpr int MAX_UNITS = 20;
// Sub-net node icons are 12x12.
constexpr int NODE_ICON = 12;