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>
This commit is contained in:
Forrest 2026-10-05 14:34:02 -04:00
parent aa50e97311
commit eb89268b66
9 changed files with 163 additions and 96 deletions

View file

@ -1,7 +1,8 @@
extends RefCounted
## Construction on the real farm, with FarmSim stepped by hand: placement rules (each reason),
## build mode driven by gamepad input (build, dismantle, leave), paying and recording, the sliced
## flow-field rebuild, gates (the scarecrow passes, enemies can't), a walled-in thief breaking
## the player-built Animal Pen boundary (open with nothing built, open with a gap, shut once the
## ring is complete), build mode driven by gamepad input (build, dismantle, leave), paying and
## recording, the sliced flow-field rebuild, gates (the scarecrow passes, enemies can't), a walled-in thief breaking
## out through a fence (barrier routing), slowing traps (speed, triggers), the automated
## defense (range), damage and breaking (breach), repair (cost, any phase), dismantling (refund),
## persistence and retry, and an A/B night: the same attack on an open and on a fenced crop field.
@ -25,10 +26,11 @@ func run(r: GameTestRunner) -> void:
c.begin_day()
_rich(c)
_validation(r, sim)
_pen_boundary(r, sim)
_place_and_rebuild(r, sim)
_build_mode(r, sim, player)
await _gate(r, sim, player)
_breakout(r, sim, player)
await _breakout(r, sim, player)
_trap(r, sim)
_turret(r, sim)
_repair_and_dismantle(r, sim, player)
@ -52,7 +54,7 @@ func _validation(r: GameTestRunner, sim: FarmSim) -> void:
["at the barn doors", "fence", Vector2(1.0, -19.5), 0, "Keep the barn doors clear"],
["on a crop row", "fence", sim.loot.home[1], 2, "Not on the crops"],
["in the house", "automated_defense", Vector2(20.5, -26.0), 0, "Blocked"],
["on the pen fence", "fence", Vector2(-3.0, -11.0), 0, "Blocked"],
["on the pen's edge (no more fence_024 colliders)", "fence", Vector2(-3.0, -11.0), 0, ""],
]
for case in cases:
var why := st.validate(case[1], case[2].x, case[2].y, case[3], case[2] + Vector2(2.0, 2.0))
@ -76,6 +78,40 @@ func _validation(r: GameTestRunner, sim: FarmSim) -> void:
_to_day(sim)
## Task #11: the Animal Pen's boundary is no longer a scene prop (fence_024) or a free starting
## gate -- it's built the same way as any other fence/gate, at normal cost, through the normal
## validate/place path. With nothing built the pen is open; closing all but its gate slot still
## leaves that one gap open; filling it with a gate shuts the pen. This also leaves the ring
## standing (gate included) for the rest of the suite, the way the deleted props and the removed
## starting gate used to.
func _pen_boundary(r: GameTestRunner, sim: FarmSim) -> void:
var st := sim.structures
var s := sim.campaign.state
r.check(sim.animals.pen_open, "with no fence_024 props and no starting gate, the pen starts open")
var slots := PenRing.fence_slots()
var wood0 := int(s.resources.shed["wood"])
var refused := []
for slot in slots:
var why := st.validate("fence", slot[0], slot[1], slot[2], PenRing.NEAR)
if why == "":
st.place("fence", slot[0], slot[1], slot[2])
else:
refused.append("(%s, %s): %s" % [slot[0], slot[1], why])
r.check(refused.is_empty(), "every fence around the pen rect validates and places (%s)" % [refused])
r.check(int(s.resources.shed["wood"]) == wood0 - slots.size() * 2, "%d fences cost 2 wood each" % slots.size())
_settle(sim)
r.check(sim.animals.pen_open, "the ring minus its gate slot still leaves a gap: the pen is open")
var why := st.validate("gate", PenRing.EAST_X, PenRing.GATE_Z, PenRing.GATE_ROT, PenRing.NEAR)
r.check(why == "", "a gate validates in the last gap (got '%s')" % why)
var wood1 := int(s.resources.shed["wood"])
var scrap1 := int(s.resources.shed["scrap"])
var gate_id := st.place("gate", PenRing.EAST_X, PenRing.GATE_Z, PenRing.GATE_ROT)
r.check(gate_id >= 1 and int(s.resources.shed["wood"]) == wood1 - 4 and int(s.resources.shed["scrap"]) == scrap1 - 1,
"the gate costs 4 wood and 1 scrap")
_settle(sim)
r.check(not sim.animals.pen_open, "a player-built gate in the last gap shuts the pen")
func _place_and_rebuild(r: GameTestRunner, sim: FarmSim) -> void:
var st := sim.structures
var s := sim.campaign.state
@ -155,15 +191,19 @@ func _gate(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
player.global_position = AWAY
## A thief inside the pen, whose only opening is shut by the pen's gate, breaks the gate to get
## out; a new gate can go back in the opening.
## A thief inside the pen, walled in by its player-built ring, breaks a way out; a replacement
## piece can go back in the breach.
## Task #11: escape_field is a global distance-to-the-farm's-outer-edge field, not a "nearest pen
## exit" one, and every ring piece costs the same to cross -- so (unlike the old fence_024 wall
## with its one gap) the thief isn't guaranteed to break the gate specifically; it breaks whatever
## ring piece sits nearest its route to the edge. This checks the general mechanic (a walled-in
## thief breaks out, the breach opens the pen, patching it shuts the pen again) against whichever
## piece that turns out to be, rather than assuming it's the gate.
func _breakout(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
var st := sim.structures
var es := sim.enemies
player.global_position = AWAY
var id := sim.nav.structure_at[sim.nav.cell_of(4.0, -6.0)]
r.check(id >= 1 and sim.campaign.state.structure(id)["type"] == "gate" and not sim.animals.pen_open,
"the vacation starts with a gate shutting the pen")
r.check(not sim.animals.pen_open, "the player-built ring (_pen_boundary) is shutting the pen")
var inside := sim.nav.cell_of(-4.0, -6.0)
r.check(sim.escape_field[inside] < FarmNavigation.UNREACHABLE, "the walled-in pen still has a route out (through the barrier)")
var broken: Array[int] = []
@ -171,18 +211,25 @@ func _breakout(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void
var h := es.spawn(EnemySystem.TYPE_THIEF, -2.0, -6.0, Vector2.RIGHT)
es.state[es.resolve_handle(h)] = T.RETREAT
var reached := _until(sim, func() -> bool: return es.resolve_handle(h) >= 0 and es.state[es.resolve_handle(h)] == T.BREAK, 20.0)
r.check(reached < 20.0 and es.barrier[es.resolve_handle(h)] == id, "the thief walks to the fence and starts breaking it (%.1f s)" % reached)
var id := es.barrier[es.resolve_handle(h)] if reached < 20.0 else -1
r.check(reached < 20.0 and id >= 1, "the thief walks to the pen's boundary and starts breaking a way out (%.1f s)" % reached)
var piece: Dictionary = sim.campaign.state.structure(id)
var type: String = piece.get("type", "fence")
var at := Vector2(float(piece.get("x", 0.0)), float(piece.get("z", 0.0)))
var rot: int = int(piece.get("rot", 0))
var took := _until(sim, func() -> bool: return broken.has(id), 30.0)
var expect := ceilf(float(sim.config.gate_hp) / es.t_structure_damage[EnemySystem.TYPE_THIEF]) * es.t_hit_interval[EnemySystem.TYPE_THIEF]
var expect := ceilf(float(st.max_hp(type)) / es.t_structure_damage[EnemySystem.TYPE_THIEF]) * es.t_hit_interval[EnemySystem.TYPE_THIEF]
r.check(took < 30.0 and absf(took - expect) < es.t_hit_interval[EnemySystem.TYPE_THIEF] + 0.5,
"it breaks the gate in about %.0f s (took %.1f s)" % [expect, took])
r.check(sim.nav.structure_at[sim.nav.cell_of(4.0, -6.0)] < 0 and sim.animals.pen_open, "the broken gate is gone from navigation: the pen is open")
"it breaks the %s in about %.0f s (took %.1f s)" % [type, expect, took])
r.check(sim.nav.structure_at[sim.nav.cell_of(at.x, at.y)] < 0 and sim.animals.pen_open, "the broken piece is gone from navigation: the pen is open")
var out := _until(sim, func() -> bool: return es.resolve_handle(h) == -1, 40.0)
r.check(out < 40.0, "then it leaves the farm through the breach (%.1f s)" % out)
r.check(st.validate("gate", 4.0, -6.0, 2, Vector2(6.0, -6.0)) == "", "a new gate can go in the pen opening")
st.place("gate", 4.0, -6.0, 2)
await r.process_frame # the broken piece's view (fences keep real collision) is queue_free()'d, not freed outright
var replace_why := st.validate(type, at.x, at.y, rot, PenRing.NEAR)
r.check(replace_why == "", "a replacement %s can go back in the breach (got '%s')" % [type, replace_why])
st.place(type, at.x, at.y, rot)
_settle(sim)
r.check(not sim.animals.pen_open, "and shuts the pen again")
r.check(not sim.animals.pen_open, "patching the breach shuts the pen again")
func _trap(r: GameTestRunner, sim: FarmSim) -> void:
@ -269,7 +316,7 @@ func _repair_and_dismantle(r: GameTestRunner, sim: FarmSim, player: PlayerCharac
func _persistence(r: GameTestRunner, sim: FarmSim) -> void:
var c := sim.campaign
var st := sim.structures
var n0 := st.count() # the pen's gate
var n0 := st.count() # the player-built pen ring (fences and its gate)
st.place("fence", 8.0, -8.0, 0)
st.place("slowing_trap", 10.0, -12.0, 0)
var d := c.state.to_dict()