Task #10: per-instance Turret/Tar Patch leveling (L1-L3)

Adds a per-placed-structure "level" (1-3) to automated_defense and
slowing_trap, upgraded independently (not account-wide) by holding
interact at that specific structure, by day, once it's undamaged
(repair still takes priority while it isn't), for a config-tunable
per-level cost.

Turret L2 fires turret_level_fire_mult (3x, matching the live Rapid
Fire multiplier) as often; L3 keeps that rate and fires
turret_l3_projectiles shots at once in a fan. A tar patch's trigger
footprint and visual grow by trap_level_size_mult per level (L2
double, L3 triple its L1 size); a bigger footprint that would overlap
a neighbor or the world refuses the upgrade with a reason.

FarmState.VERSION bumps 5->6 (STRUCTURE_KEYS gains "level"; migrate()
backfills level 1 on older saves, following the v2->v3 precedent for
night_log). Co-op: an upgrade is driven the same way repair already
is -- entirely host-side, off the partner's held interact button, no
new "req" case -- so the only wire change is forwarding the upgrade
channel's target/progress in the avatar snapshot, same as repair's.

New test_structures.gd coverage: fire interval and projectile count
per turret level, tar patch footprint per level, each proven
independently for two separately-placed structures of the same type,
plus the upgrade rules (repair-first, room, afford) and that level
survives a save/retry round trip.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-05 15:48:19 -04:00
parent 0613cca408
commit 62324ff4b1
8 changed files with 468 additions and 33 deletions

View file

@ -43,9 +43,9 @@ static func busy_state(cfg: GameConfig) -> FarmState:
s.resources.pouch = {"wood": 0, "scrap": 3, "straw": 1}
s.gather_charges = {"DeadTree": 1, "Haystack": 0}
s.upgrades = {"rapid_fire": 1, "sticky_tar": 1}
s.structures.append({"id": s.next_structure_id, "type": "fence", "x": 30.5, "z": -18.5, "rot": 3, "hp": 11})
s.structures.append({"id": s.next_structure_id, "type": "fence", "x": 30.5, "z": -18.5, "rot": 3, "hp": 11, "level": 1})
s.next_structure_id += 1
s.structures.append({"id": s.next_structure_id, "type": "slowing_trap", "x": 12.0, "z": -7.25, "rot": 0, "hp": 2})
s.structures.append({"id": s.next_structure_id, "type": "slowing_trap", "x": 12.0, "z": -7.25, "rot": 0, "hp": 2, "level": 2})
s.next_structure_id += 1
for n in [1, 2]:
var e := {"night": n, "crops_lost": n, "animals_lost": n - 1}