Task #9 follow-up: make the Workbench genuinely targetable (Decision 3)

FarmSim._breaker_goals() now treats an unbroken Workbench as guarding its
own work area unconditionally (not just when within guard_range of the
pen/shed/crop-field rects, which it normally isn't), alongside whatever
else actually guards something -- so it joins a non-empty guarding set
instead of only ever being a last-resort fallback. A broken Workbench (0
HP) drops out entirely: nothing left to gain by sending a breaker at it.

That alone wasn't enough in practice: the Workbench's footprint sits on
its own scene prop's real collision, which FarmNavigation.build() already
rasterized into blocked[] before any structure ever gets placed there --
unlike every player-placed structure, which validate()'s world-blocked
check keeps off already-blocked terrain. _rasterize_into() skipped tagging
structure_at[] on an already-blocked cell, so the Workbench was invisible
to ThiefBehavior._adjacent_structure() and FarmNavigation.barrier_ahead():
a fence breaker would walk right up to it and then just stand there,
forever stuck in SEEK, never transitioning to BREAK. Fixed by tagging
structure_at[] for a structure id even over a blocked cell; a terrain
block (id < 0) still skips already-blocked cells exactly as before, and
no existing (validate()-placed) structure's footprint was ever on blocked
terrain to begin with, so this changes nothing for fences, gates, traps,
or turrets.

test_structures.gd's Workbench check now proves targeting, not just
damage: with a real guarding structure also present (PenRing.build_gate_
only, the same single-barrier setup test_roster.gd's own fence-breaker
test uses) and the scarecrow kept well clear, a fence breaker spawned
with no hand-set state or barrier walks to and smashes the Workbench on
its own, and a broken Workbench is confirmed absent from the breaker
goals. Found by running the actual AI end to end (not by poking es.state/
es.barrier by hand, which only proves damage()).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-05 16:46:04 -04:00
parent df10a1967c
commit acf4e2f4c1
3 changed files with 51 additions and 13 deletions

View file

@ -289,7 +289,11 @@ func _rasterize(hull: PackedVector2Array, inflate: float) -> void:
## Marks the cells within inflate of a convex outline: as blocked (id < 0) or, for free cells,
## as belonging to structure id.
## as belonging to structure id. A structure (id >= 0) is tagged even over an already-blocked
## cell (#9: the Workbench, granted onto its own scene prop's real collision, bypassing the
## build-on-free-ground check every player-placed structure goes through in validate() -- without
## this, it would be invisible to _adjacent_structure()/barrier_ahead(), undetectable and
## unbreakable); this never changes anything for a structure that is on free ground to begin with.
func _rasterize_into(hull: PackedVector2Array, inflate: float, id: int) -> void:
var lo := hull[0]
var hi := hull[0]
@ -304,7 +308,7 @@ func _rasterize_into(hull: PackedVector2Array, inflate: float, id: int) -> void:
for cz in range(c0 / width, c1 / width + 1):
for cx in range(c0 % width, c1 % width + 1):
var i := cz * width + cx
if blocked[i] == 1:
if blocked[i] == 1 and id < 0:
continue
var p := cell_center(i)
if (solid and Geometry2D.is_point_in_polygon(p, hull)) or _dist2_to_outline(p, hull) <= r2:

View file

@ -688,7 +688,12 @@ func _breaker_goals() -> PackedInt32Array:
for e in campaign.state.structures:
if not structures.blocks(e["type"]):
continue
if e["type"] == "workbench" and int(e["hp"]) <= 0:
continue # broken: nothing left to gain by sending a breaker at it
barriers.append(e)
if e["type"] == "workbench":
guarding.append(e) # #9 Decision 3: it guards its own work area, unconditionally
continue
var at := Vector2(e["x"], e["z"])
for a in areas:
if a.grow(config.guard_range).has_point(at):