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

@ -199,6 +199,28 @@ extends Resource
## Cells finalized per tick while flow fields rebuild after a structure change.
@export_range(100, 100000) var flow_slice_cells: int = 2000
## Per-instance leveling (StructureSystem.LEVELABLE: automated_defense, slowing_trap; L1-L3), not
## account-wide like the workbench upgrades above. Holding interact at a specific placed structure
## (by day; it must be undamaged first) pays structure_level_costs[type][level - 1] to take it from
## level to level + 1 (index 0: L1->L2, index 1: L2->L3).
@export var structure_level_costs: Dictionary = {
"automated_defense": [{"scrap": 10, "wood": 4, "straw": 2}, {"scrap": 16, "wood": 6, "straw": 4}],
"slowing_trap": [{"scrap": 5, "wood": 2}, {"scrap": 8, "wood": 4}],
}
## Turret L2 fires this many times as often (mirrors the Rapid Fire upgrade's live multiplier,
## 3.0 in game_config.tres); L3 keeps the same rate.
@export var turret_level_fire_mult: float = 3.0
## Turret L3 fires this many shots at once in a fan around the aim direction, turret_l3_spread_deg
## apart (a triangle spread: the outer two off by the full spread from the center shot).
@export_range(1, 8) var turret_l3_projectiles: int = 3
@export var turret_l3_spread_deg: float = 10.0
## A tar patch's footprint (trigger area) and visual grow by this multiple of its L1 size, per
## level (index 0 = L1, so always 1.0).
@export var trap_level_size_mult: Array[float] = [1.0, 2.0, 3.0]
## Holding interact for structure_upgrade_time levels up a structure, paying structure_level_costs
## at the end (by day only; see Interactions).
@export var structure_upgrade_time: float = 2.0
@export_group("Combat")
## Height of the gun muzzle, the bullets, and enemy hit proxies (shots fly horizontally). It
## clears the sunflowers (1.67 m) and the pen fence (1.69 m), so thieves in the field stay