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

@ -446,8 +446,11 @@ static func _enemy_bytes(es: EnemySystem, d: int) -> PackedByteArray:
## A scarecrow in a snapshot: slot, position, facing, speed, alive and patching, health, its
## timers (invulnerable, fear, bomb recharge, patch, gather, repair), the weapon, the channel
## clip and what it is focused on and gathering (names), and the repair's target and progress.
## timers (invulnerable, fear, bomb recharge, patch, gather, repair, structure level-up), the
## weapon, the channel clip and what it is focused on and gathering (names), and the repair's and
## the level-up's target and progress (#10: a structure upgrade is driven the same way as a
## repair -- entirely host-side off the partner's held interact button, nothing in "req" -- so
## this is the only wire change it needs).
func _put_avatar(b: StreamPeerBuffer, a: Avatar) -> void:
var it := a.interactions
var k := a.kit
@ -457,7 +460,7 @@ func _put_avatar(b: StreamPeerBuffer, a: Avatar) -> void:
b.put_u8(clampi(roundi(a.body.move_strength() * 100.0), 0, 255))
b.put_u8((1 if k.alive else 0) | (2 if k.patching else 0))
b.put_u8(clampi(k.hp(), 0, 255))
for t: float in [k.invulnerable_left, k.fear_left, a.combat.bomb_left, k.patch_elapsed, it.gather_elapsed, it.repair_elapsed]:
for t: float in [k.invulnerable_left, k.fear_left, a.combat.bomb_left, k.patch_elapsed, it.gather_elapsed, it.repair_elapsed, it.upgrade_elapsed]:
CoopLink.put_time(b, t)
b.put_u8(int(a.combat.weapon))
CoopLink.put_text(b, String(a.body.channel_clip) if a.body.rooted else "")
@ -465,6 +468,8 @@ func _put_avatar(b: StreamPeerBuffer, a: Avatar) -> void:
CoopLink.put_text(b, String(it.gathering.name) if it.gathering != null else "")
b.put_32(it.repair_target)
b.put_32(it.repairing)
b.put_32(it.upgrade_target)
b.put_32(it.upgrading)
func _on_message(kind: String, data: Variant) -> void:
@ -730,7 +735,7 @@ func _read_avatar(b: StreamPeerBuffer) -> Dictionary:
var flags := b.get_u8()
rec["a"] = (flags & 1) != 0
rec["hp"] = b.get_u8()
for key: String in ["inv", "fl", "bl", "pt", "ge", "re"]:
for key: String in ["inv", "fl", "bl", "pt", "ge", "re", "ue"]:
rec[key] = CoopLink.get_time(b)
if (flags & 2) == 0:
rec["pt"] = -1.0 # not patching
@ -740,6 +745,8 @@ func _read_avatar(b: StreamPeerBuffer) -> Dictionary:
rec["ga"] = CoopLink.get_text(b)
rec["rt"] = b.get_32()
rec["rp"] = b.get_32()
rec["ut"] = b.get_32()
rec["up"] = b.get_32()
return rec
@ -783,6 +790,9 @@ func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
it.repair_target = int(rec["rt"])
it.repairing = int(rec["rp"])
it.repair_elapsed = float(rec["re"])
it.upgrade_target = int(rec["ut"])
it.upgrading = int(rec["up"])
it.upgrade_elapsed = float(rec["ue"])
func _gather_node(node_name: String) -> Node3D: