harvest/game/tests/pen_ring.gd
Forrest eb89268b66 Task #11: Animal Pen boundary becomes player-built
Delete the 23 fence_024 scene props (and their unused ext_resource) from
Zones/AnimalPen in farm.tscn -- their StaticBody3D colliders permanently
walled the pen in FarmNavigation.build(), so today they're the only thing
enclosing it. FarmZone.Kind.ANIMAL_PEN and AnimalSystem.update_pen_open()
already drive the open/closed check; players now build ordinary fence/gate
structures around the existing pen rect to close it.

Remove the free starting gate from GameConfig.start_structures (now an
empty array): the pen is fully player-built, nothing stands at the start.

Add game/tests/pen_ring.gd, a shared helper with the pen rect's 24-piece
fence/gate layout (the same positions the deleted props and the old
starting gate used to occupy), built through StructureSystem's normal
validate/place path at normal cost.

Rework the pen tests that assumed a pre-built pen:
- test_structures.gd gets a new _pen_boundary check (open with nothing
  built, open with a gap, shut once the ring is complete -- the task's
  acceptance test) and builds the ring there for the rest of the suite;
  _breakout no longer assumes the gate specifically breaks (a retreating
  thief now follows a global escape-to-map-edge field across equally
  breakable ring pieces, not a single gap in a solid wall), checking
  whichever piece breaks and that patching it shuts the pen again.
- test_targets.gd builds the full ring in setup (gate first, so it keeps
  structure id 1) and spawns the animal thief near the gate so its
  "breaks the gate" narrative still holds.
- test_roster.gd's fence-breaker test places only the gate (not the full
  ring): FarmSim._breaker_goals() treats every structure near a zone as
  "guarding" it, so a full ring would turn its two-barriers-then-the-
  scarecrow narrative into twenty-five.
- test_farm_state.gd and test_cycle.gd's stale "the pen's gate" wording
  and assumptions are updated for the empty start_structures.

No new FAIL lines versus the pre-existing baseline (one known-flaky
test_roster check aside, confirmed to pass on isolated reruns).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-05 14:34:02 -04:00

77 lines
3.6 KiB
GDScript

class_name PenRing
extends RefCounted
## Positions for the Animal Pen's player-built fence/gate boundary (task #11): the same 24-piece
## layout the deleted fence_024 props and the removed GameConfig.start_structures starting gate
## used to occupy, around FarmZone.Kind.ANIMAL_PEN's rect (center (-3, -6), 14 x 10 m, world x
## -10..4, z -11..-1). Built through StructureSystem's normal validate/place path, at normal
## cost. Shared by test setups that need the pen closed the way it used to be out of the box
## (test_targets.gd, test_roster.gd); test_structures.gd's dedicated player-built-pen-boundary
## test builds the same layout by hand (with checks) instead of calling build_full().
## North and south runs: 7 fences each, 2 m apart, covering the full 14 m side.
const RUN_XS: Array[float] = [-9.0, -7.0, -5.0, -3.0, -1.0, 1.0, 3.0]
const NORTH_Z := -11.0
const SOUTH_Z := -1.0
## West and east runs: 5 slots each, 2 m apart, covering the full 10 m side. The east run's
## middle slot is the gate (where the old starting gate stood), so animals can be led in.
const SIDE_ZS: Array[float] = [-10.0, -8.0, -6.0, -4.0, -2.0]
const WEST_X := -10.0
const EAST_X := 4.0
const GATE_Z := -6.0
const GATE_ROT := 2
## Pen center: within StructureSystem.build_range (9 m) of every slot below, so one point works
## as the "scarecrow" distance check in validate() for the whole ring.
const NEAR := Vector2(-3.0, -6.0)
## The 23 fence slots (the east run's middle slot skipped: that one's the gate's), each a
## [x: float, z: float, rot: int] triple.
static func fence_slots() -> Array:
var out: Array = []
for x in RUN_XS:
out.append([x, NORTH_Z, 0])
out.append([x, SOUTH_Z, 0])
for z in SIDE_ZS:
out.append([WEST_X, z, GATE_ROT])
if z != GATE_Z:
out.append([EAST_X, z, GATE_ROT])
return out
## Builds the full ring (gate first, so it gets structure id 1, the way the old starting gate
## did) at normal cost, through the normal validate/place path. Grants and restores shed
## resources around it so callers don't need to pre-fund it. Returns the gate's id (-1 if the
## farm's layout ever drifts enough that validate() refuses a slot -- logged as a warning rather
## than failing outright, since this is setup, not the check itself).
static func build_full(sim: FarmSim) -> int:
var s := sim.campaign.state
var st := sim.structures
var keep: Dictionary = s.resources.shed.duplicate()
s.resources.shed = {"wood": 999, "scrap": 999, "straw": 999}
var gate_id := _place(st, "gate", EAST_X, GATE_Z, GATE_ROT)
for slot in fence_slots():
_place(st, "fence", slot[0], slot[1], slot[2])
s.resources.shed = keep
return gate_id
## Just the gate, at normal cost (granting and restoring shed resources around it): for tests that
## only need a single structure near the pen (matching nav.structure_at lookups at its old spot),
## not a closed pen -- e.g. test_roster.gd's fence-breaker test, where a full ring of equally-
## "guarding" structures (FarmSim._breaker_goals) would change its two-barriers-then-the-
## scarecrow narrative.
static func build_gate_only(sim: FarmSim) -> int:
var s := sim.campaign.state
var keep: Dictionary = s.resources.shed.duplicate()
s.resources.shed = {"wood": 999, "scrap": 999, "straw": 999}
var gate_id := _place(sim.structures, "gate", EAST_X, GATE_Z, GATE_ROT)
s.resources.shed = keep
return gate_id
static func _place(st: StructureSystem, type: String, x: float, z: float, rot: int) -> int:
var why := st.validate(type, x, z, rot, NEAR)
if why != "":
push_warning("PenRing: %s at (%s, %s) refused: %s" % [type, x, z, why])
return -1
return st.place(type, x, z, rot)