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)