From ce668a8005ebb04c952a60b9d7f4970a28631cfe Mon Sep 17 00:00:00 2001 From: Dejvino Date: Sun, 15 Nov 2026 09:30:37 +0100 Subject: [PATCH] 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. --- AGENTS.md | 8 ++++++++ emulator/tests/integration_tests.h | 2 +- emulator/tests/unit_tests.h | 2 +- src/netdeck/NetDeck.ino | 17 +++++++++-------- src/netdeck/nd_layout.h | 1 + 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 298efc3..31e027b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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 diff --git a/emulator/tests/integration_tests.h b/emulator/tests/integration_tests.h index 694e0fc..e028534 100644 --- a/emulator/tests/integration_tests.h +++ b/emulator/tests/integration_tests.h @@ -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) diff --git a/emulator/tests/unit_tests.h b/emulator/tests/unit_tests.h index a70cca5..95626da 100644 --- a/emulator/tests/unit_tests.h +++ b/emulator/tests/unit_tests.h @@ -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); diff --git a/src/netdeck/NetDeck.ino b/src/netdeck/NetDeck.ino index d152a19..f6d3319 100644 --- a/src/netdeck/NetDeck.ino +++ b/src/netdeck/NetDeck.ino @@ -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 diff --git a/src/netdeck/nd_layout.h b/src/netdeck/nd_layout.h index 3693ea6..42af671 100644 --- a/src/netdeck/nd_layout.h +++ b/src/netdeck/nd_layout.h @@ -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;