harvest/game/scripts/game_config.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

305 lines
17 KiB
GDScript

class_name GameConfig
extends Resource
## Every tunable campaign setting, kept in one resource (see game/RULES.md for the rules these
## values feed). The defaults live in res://game/resources/game_config.tres; every number is a
## starting value to tune during balancing.
@export_group("Campaign")
## Nights the scarecrow must survive before the farmers return.
@export_range(1, 60) var campaign_nights: int = 5
@export_group("Waves")
## Every night plan's groups are scaled when played: this many times the enemies, arriving this
## many times the plan's spacing apart (NightPlan.scaled_count / scaled_every). 5 and 0.4: five
## times the enemies, two and a half times as often. A plan can set its own instead
## (NightPlan.count_scale / spacing_scale; night 1 plays unscaled).
@export_range(0.1, 20.0) var wave_count_scale: float = 7.0
@export_range(0.05, 4.0) var wave_spacing_scale: float = 0.3
## Every enemy arrives at its own random point along the farm's edge (FarmZones.edge), on foot this
## many meters outside the playable map (also where carriers escape to), flyers this far out.
## Ground arrivals stay inside the navigation grid (5 m beyond the map).
@export_range(0.5, 4.5) var spawn_margin: float = 3.0
@export var flyer_spawn_margin: float = 8.0
@export_group("Phases")
## Seconds of game time per phase. The morning review is untimed: it waits for the player.
@export var day_length: float = 180.0
@export var dusk_length: float = 30.0
@export var night_length: float = 150.0
## After sunrise: enemies retreat and carriers can still be intercepted for this long.
@export var dawn_grace: float = 20.0
## D1: lets the player skip the rest of the day/dusk and start the night (off by default).
@export var allow_early_night: bool = false
@export_group("Scarecrow")
## HP carries over between nights (D7); 0 HP is an immediate Game Over.
@export_range(1, 100) var scarecrow_max_hp: int = 3
## After an accepted hit the scarecrow ignores further hits for this long.
@export var invulnerability_time: float = 1.0
## Fear: enemies within fear_radius flee for fear_duration; usable every fear_cooldown seconds.
@export var fear_radius: float = 6.0
@export var fear_cooldown: float = 12.0
@export var fear_duration: float = 2.0
## Patch up: hold for patch_time (rooted, no shooting) to restore patch_heal HP.
@export var patch_time: float = 2.0
@export_range(1, 100) var patch_heal: int = 3
## Sprint (the workbench's Sprint upgrade): hold sprint while moving to run sprint_speed_mult
## times as fast for up to sprint_time seconds; once it ends, sprint_cooldown seconds until the
## next one.
@export var sprint_speed_mult: float = 1.8
@export var sprint_time: float = 4.0
@export var sprint_cooldown: float = 10.0
@export_group("Farm assets")
## Crop units and animals on the farm when the vacation starts; they must match the farm scene
## (the crop field's CropUnits, the animals in the pen). Supplies are the shed's stock (the start
## materials below). A category with nothing in it at the start is not in play and is ignored by
## the "farm stripped" check (D2).
@export_range(0, 500) var start_crops: int = 30
@export_range(0, 100) var start_animals: int = 8
## Structures standing when the vacation starts ({"type", "x", "z", "rot"}). Empty: the animal
## pen is fully player-built (its fence/gate ring is no longer a scene prop or a free starter).
@export var start_structures: Array[Dictionary] = []
@export_group("Theft rules")
## D5: fear makes carriers drop their loot, not only killing them.
@export var fear_drops_loot: bool = true
## D6: dropped loot still on the ground when the dawn grace ends returns home automatically.
@export var loot_returns_at_dawn: bool = true
## D6: animals that can follow the scarecrow back to the pen at once.
@export_range(1, 10) var max_following_animals: int = 5
## Seconds an enemy needs to take a crop unit, catch an animal, or fill a sack at the shed (times
## its type's steal_time); damage during that time resets it.
@export var crop_steal_time: float = 2.5
@export var animal_capture_time: float = 2.0
@export var supply_steal_time: float = 1.0
## A supply thief takes this many units of the material the shed holds most of (never more than
## there is).
@export_range(1, 100) var supply_bundle: int = 5
## Loose animals (dropped, or wandered out of an open pen) walk toward the farm's nearest edge at
## this speed, stopping to graze now and then; one that gets off the farm is lost.
@export var stray_speed: float = 1.1
## At night, while the pen is open (its gate broken or removed), one animal wanders out every
## this many seconds. An animal brought back stays calm (won't wander out) for animal_calm_time.
@export var animal_wander_interval: float = 10.0
@export var animal_calm_time: float = 30.0
## Animals following the scarecrow walk its trail at up to this speed.
@export var follow_speed: float = 6.0
## What a thief with no set target goes for ("any" in a night plan), and where a thief whose target
## is gone goes next: relative weights per category.
@export var target_weights: Dictionary = {"crops": 2.0, "animals": 1.0, "supplies": 1.0}
## The scarecrow recovers dropped loot by walking within this distance of it.
@export var pickup_radius: float = 1.3
@export_group("Resources")
## Wood, scrap, and straw in the supply shed when the vacation starts.
@export_range(0, 999) var start_wood: int = 4
@export_range(0, 999) var start_scrap: int = 2
@export_range(0, 999) var start_straw: int = 4
## The scarecrow's pouch holds this many units in total; it empties into the shed on entry.
@export_range(1, 200) var pouch_capacity: int = 16
## Seconds of holding interact per gather (each takes one charge of the gather point).
@export var gather_time: float = 1.5
## What things cost: name -> {material: amount}: patching up, the buildables, and the upgrades.
@export var costs: Dictionary = {
"patch": {"straw": 2},
"straw_stuffing": {"straw": 12, "wood": 4},
"sprint": {"wood": 8, "straw": 6},
"corn_shooter": {"scrap": 10, "wood": 4},
"pumpkin_bomb": {"straw": 12, "scrap": 6},
"rapid_fire": {"scrap": 12, "wood": 8},
"heavy_seeds": {"scrap": 14, "straw": 10},
"wide_fear": {"straw": 20, "wood": 4},
"quick_fear": {"straw": 16, "scrap": 6},
"reinforced_fences": {"wood": 20, "scrap": 6},
"long_range": {"scrap": 14, "wood": 10},
"sticky_tar": {"straw": 14, "scrap": 6},
"fence": {"wood": 2},
"gate": {"wood": 4, "scrap": 1},
"slowing_trap": {"scrap": 3, "wood": 1},
"automated_defense": {"scrap": 6, "wood": 2, "straw": 2},
}
@export_group("Upgrades")
## Bought once each by day at the work area's workbench, for costs[id] (Upgrades). Each changes
## one stat: "mult" multiplies it, "add" adds to it. Stats are GameConfig settings, plus
## scarecrow_max_hp (the scarecrow's, in FarmState) and barrier_hp (fences' and gates' health).
## One without a stat unlocks something instead (sprint: PlayerCharacter; the corn shooter and
## pumpkin bombs: ScarecrowCombat). "requires": another upgrade that must be bought first.
@export var upgrades: Dictionary = {
"corn_shooter": {"name": "Corn shooter", "text": "A gun that fires corn kernels, from afar", "track": "Weapon"},
"rapid_fire": {"name": "Rapid fire", "text": "The corn shooter fires a third faster", "track": "Weapon", "stat": "fire_rate", "mult": 1.333, "requires": "corn_shooter"},
"heavy_seeds": {"name": "Heavy seeds", "text": "Each kernel does 2 damage", "track": "Weapon", "stat": "shot_damage", "add": 1, "requires": "corn_shooter"},
"pumpkin_bomb": {"name": "Pumpkin bombs", "text": "Throw a pumpkin that bursts, hurting everything within 3 m (one every 4 s)", "track": "Weapon"},
"wide_fear": {"name": "Wide fear", "text": "Fear reaches 30% farther", "track": "Fear", "stat": "fear_radius", "mult": 1.3},
"quick_fear": {"name": "Quick fear", "text": "Fear recharges 20% faster", "track": "Fear", "stat": "fear_cooldown", "mult": 0.8},
"straw_stuffing": {"name": "Straw stuffing", "text": "+2 max health", "track": "Scarecrow", "stat": "scarecrow_max_hp", "add": 2},
"sprint": {"name": "Sprint", "text": "Sprint 80% faster for 4 s at a time, every 10 s", "track": "Scarecrow"},
"reinforced_fences": {"name": "Reinforced fences", "text": "Fences and gates +50% health", "track": "Defenses", "stat": "barrier_hp", "mult": 1.5},
"long_range": {"name": "Long-range defenses", "text": "Turrets reach 30% farther", "track": "Defenses", "stat": "turret_range", "mult": 1.3},
"sticky_tar": {"name": "Sticky tar", "text": "Tar patches hold 50% longer", "track": "Defenses", "stat": "trap_slow_time", "mult": 1.5},
}
@export_group("Assessment")
## The final assessment's weight per category (Assessment): the score is the weighted share of
## each category kept, renormalized over the categories in play, as 0..100 points.
@export var assessment_weights: Dictionary = {"crops": 0.5, "animals": 0.3, "supplies": 0.2}
## Rating tiers, best first: the first one whose min the score reaches.
@export var rating_tiers: Array[Dictionary] = [
{"min": 95, "name": "Blue-ribbon harvest", "text": "The farmers can hardly tell they were gone."},
{"min": 80, "name": "Bumper crop", "text": "A few gaps in the rows, nothing a good week won't fix."},
{"min": 60, "name": "Fair season", "text": "The farm made it, a little thinner than they left it."},
{"min": 40, "name": "Lean season", "text": "The farmers will be counting what's missing for a while."},
{"min": 0, "name": "Hanging by a thread", "text": "There's a farm left, but only just."},
]
@export_group("Structures")
## Hit points of the built defenses; a slowing trap's "HP" is the enemies it can still slow.
@export_range(1, 500) var fence_hp: int = 20
@export_range(1, 500) var gate_hp: int = 30
@export_range(1, 500) var trap_triggers: int = 10
@export_range(1, 500) var turret_hp: int = 25
## A ground enemy crossing a slowing trap moves at this share of its speed for this long.
@export_range(0.05, 1.0) var trap_slow_factor: float = 0.5
@export var trap_slow_time: float = 2.0
## The automated defense shoots the nearest enemy in range with a clear line, every interval.
@export var turret_range: float = 7.0
@export var turret_fire_interval: float = 1.0
## The scarecrow builds within this distance of itself.
@export var build_range: float = 9.0
## Enemies treat each cell of a barrier as this many meters of extra path, so they walk around
## a short wall but break through a long one.
@export var barrier_detour: float = 18.0
## Holding interact for repair_time repairs a structure fully, for its build cost scaled by the
## share of HP (or triggers) it is missing, rounded up.
@export var repair_time: float = 1.5
## Dismantling gives back this share of the build cost (rounded down), into the shed.
@export_range(0.0, 1.0) var dismantle_refund: float = 0.5
## Cells finalized per tick while flow fields rebuild after a structure change.
@export_range(100, 100000) var flow_slice_cells: int = 2000
@export_group("Combat")
## Height of the gun muzzle, the bullets, and enemy hit proxies (shots fly horizontally). It
## clears the sunflowers (1.67 m) and the pen fence (1.69 m), so thieves in the field stay
## visible and shootable.
@export var combat_height: float = 1.8
## The pitchfork, every scarecrow's from the start (ScarecrowCombat): a stab every
## pitchfork_interval s hits the nearest pitchfork_targets enemies within pitchfork_reach m of the
## scarecrow's center (plus their hit radius) and pitchfork_arc degrees of the aim, with a clear
## line, for pitchfork_damage each.
@export var pitchfork_reach: float = 2.2
@export var pitchfork_arc: float = 100.0
@export_range(1, 20) var pitchfork_damage: int = 2
@export_range(1, 20) var pitchfork_targets: int = 3
@export var pitchfork_interval: float = 0.5
## Pumpkin bombs (the Pumpkin bombs upgrade): thrown at the aim point, bomb_min_range ..
## bomb_range m away, flying at bomb_speed m/s; on landing every enemy within bomb_radius m takes
## bomb_damage. One every bomb_cooldown s.
@export var bomb_range: float = 10.0
@export var bomb_min_range: float = 2.0
@export var bomb_speed: float = 12.0
@export var bomb_radius: float = 3.0
@export_range(1, 50) var bomb_damage: int = 3
@export var bomb_cooldown: float = 4.0
## The corn shooter (the Corn shooter upgrade) is the gun: kernels per second and their damage
## (rapid fire and heavy seeds raise them), and the projectiles below.
@export var fire_rate: float = 6.0
## Damage of one of the scarecrow's shots (automated defenses always do 1).
@export_range(1, 10) var shot_damage: int = 1
@export var projectile_speed: float = 24.0
@export var projectile_lifetime: float = 2.0
@export_range(1, 1024) var projectile_capacity: int = 64
## Horizontal distance from the scarecrow's center to the muzzle along the aim direction.
@export var muzzle_distance: float = 1.05
## Right-stick radial dead zone, and mouse travel (px) that switches aiming back to the mouse.
@export var aim_dead_zone: float = 0.3
@export var mouse_switch_threshold: float = 12.0
@export_group("Enemies")
@export_range(1, 1024) var enemy_capacity: int = 800
## The enemy roster (EnemySystem.TYPE_NAMES), one row per type:
## speed, acceleration m/s, m/s^2
## hp hits it takes
## flying ignores ground occupancy, structures, and traps; altitude is only
## visual (its hit proxy stays at combat height)
## targets what it goes for: loot categories ("crops", "animals", "supplies"), or
## "structures" (barriers guarding valuables)
## steal_time times the category's steal time
## carry_speed share of its speed while carrying loot
## structure_damage per hit on a barrier, every hit_interval
## damage, hit_interval per melee hit on the scarecrow, and the cooldown between hits
## aggression "none" (never fights), "contact" (hits the scarecrow when touching it
## while busy), "fight" (turns on a scarecrow within aggro_range, and
## hunts it when nothing is left to break)
## hit_radius projectile hit proxy
@export var enemy_types: Dictionary = {
"thief": {"speed": 3.0, "acceleration": 14.0, "hp": 3, "flying": false, "targets": ["animals", "supplies"],
"steal_time": 1.0, "carry_speed": 0.7, "structure_damage": 2, "damage": 1, "hit_interval": 1.2,
"aggression": "contact", "hit_radius": 0.4, "aggro_range": 0.0},
"crow": {"speed": 5.5, "acceleration": 18.0, "hp": 1, "flying": true, "targets": ["crops"],
"steal_time": 0.8, "carry_speed": 0.75, "structure_damage": 0, "damage": 0, "hit_interval": 1.0,
"aggression": "none", "hit_radius": 0.45, "aggro_range": 0.0},
"breaker": {"speed": 1.9, "acceleration": 8.0, "hp": 6, "flying": false, "targets": ["structures"],
"steal_time": 0.0, "carry_speed": 0.0, "structure_damage": 8, "damage": 2, "hit_interval": 1.5,
"aggression": "fight", "hit_radius": 0.55, "aggro_range": 4.0},
}
## Flyers cruise at this visual altitude and come down to land_altitude to take a crop.
@export var cruise_altitude: float = 3.2
@export var land_altitude: float = 1.55
## Barriers within this distance of the crop rows, the pen, or the shed guard them: fence
## breakers go for those first.
@export var guard_range: float = 6.0
## Body radius of ground enemies (navigation clearance is this plus nav_inflate_margin).
@export var enemy_radius: float = 0.3
@export var nav_cell_size: float = 0.5
@export var nav_inflate_margin: float = 0.05
@export var separation_radius: float = 0.8
@export var separation_weight: float = 1.4
## Bounded push per tick when enemies overlap each other or the scarecrow.
@export var max_correction_per_tick: float = 0.15
## Melee: an enemy touching the scarecrow (within this much of contact) and off cooldown hits
## it for its type's damage; the cooldown (hit_interval) starts on every attempt.
@export var enemy_attack_reach: float = 0.25
## Fleeing enemies (fear) run at this share of their normal speed.
@export var flee_speed_factor: float = 1.15
## Within this distance and with a clear line, enemies steer straight at their target.
@export var direct_seek_distance: float = 12.0
## Trickle mode, for tests and soaks: when above 0, the night's plan is ignored and this many
## enemies of trickle_type are kept on the farm, the next arriving thief_spawn_interval after one
## leaves (anywhere along the farm's edge). 0 plays the night's NightPlan (WaveDirector).
@export_range(0, 32) var night_thieves: int = 0
@export var thief_spawn_interval: float = 6.0
@export var trickle_type: String = "crow"
## What trickle enemies go for: "crops", "animals", "supplies", or "any" (of their type's targets).
@export var trickle_target: String = "any"
## A row of the enemy roster.
func enemy(type_name: String) -> Dictionary:
return enemy_types.get(type_name, {})
## Full hit points of a structure type (a slowing trap's are the enemies it can still slow).
func structure_hp(type: String) -> int:
match type:
"fence":
return fence_hp
"gate":
return gate_hp
"slowing_trap":
return trap_triggers
return turret_hp
## Length of a phase in seconds, or INF for the untimed morning review and terminal phases.
func phase_length(phase: CampaignController.Phase) -> float:
match phase:
CampaignController.Phase.DAY:
return day_length
CampaignController.Phase.DUSK:
return dusk_length
CampaignController.Phase.NIGHT:
return night_length
CampaignController.Phase.DAWN:
return dawn_grace
return INF