Task #13: two new crop fields with staged growth (Night 2 / Night 4)

Adds a Lettuce/Cabbage field (ids 31-40, x -11..-1 z 2..12) and a Corn field
(ids 41-50, x 2..12 z 2..12), each 2 plots of 5 units, placeholder plants
reusing plant_007/plant_008. CropUnit gains crop (cosmetic) and sprout_night
(0/2/4) fields. LootSystem gains a DORMANT status: a unit whose field hasn't
sprouted (FarmState.nights_survived < sprout_night) is hidden and never
claimable/recoverable, and is excluded from crops_total so it can't affect
scoring or the "farm stripped" check. sync_from_state() derives DORMANT vs.
HOME from nights_survived every morning (and after a retry/load), and
self-heals crops_total to the sprouted count; FarmSim.grow_crops_total() also
grows it right at night_ending so the morning snapshot (retry, the save file)
already has it right. FarmZones.crop_units() now gathers CropUnits from every
CROP_FIELD zone (there are three now), not just the first found; the same fix
applies to FarmSim's crop-area rect and the fence breakers' guarded areas.

Reworks test_farm_layout's zone-count and crop checks for the extra fields,
and test_theft's start-of-run and FarmState-consistency checks, which assumed
every crop unit was always in play; adds test_theft cases for both fields
sprouting on schedule, dormant units being unclaimable, and a sprouted unit
being stealable and scored, including a save/JSON round trip. Nudges
test_coop's co-op build spot into the 3 m walkway between the two new fields,
since its old spot now sits on the corn field's rows.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-05 15:52:38 -04:00
parent 0613cca408
commit 62edb8e04c
8 changed files with 974 additions and 28 deletions

View file

@ -26,13 +26,18 @@ extends Node3D
## LOST carried (or, for an animal, wandered) off the farm. Crops and animals are recorded
## in FarmState and gone for the rest of the run; a sack's contents are gone and the
## sack is free for the next theft.
## DORMANT crops only (#13): a unit of one of the later fields (lettuce/cabbage, corn) that
## hasn't sprouted yet (FarmState.nights_survived < CropUnit.sprout_night). Hidden,
## never claimable or recoverable, not counted in FarmState.crops_total, and ignored
## by alerts. sync_from_state() derives this every morning (and after a retry/load);
## it never shows up mid-night, since a unit only sprouts between mornings.
## Supplies in a carried or dropped sack still count as on the farm (FarmState.supplies_in_transit).
## Claims and carriers are enemy handles (id + generation), so a stale handle from a reused enemy
## slot can never move an item. Every change emits loot_event (toasts now, sounds later); steals,
## recoveries, strays, and supply losses count toward the night's record.
enum Category { CROP, ANIMAL, SUPPLY }
enum Status { HOME, CARRIED, DROPPED, LOST, FOLLOWING, LOOSE }
enum Status { HOME, CARRIED, DROPPED, LOST, FOLLOWING, LOOSE, DORMANT }
enum Threat { NONE, TARGETED, CARRIED, DROPPED }
## EnemySystem.want for a thief with no set target (it goes by GameConfig.target_weights).
@ -171,13 +176,20 @@ func setup(p_campaign: CampaignController, units: Array[CropUnit], p_enemies: En
## Every item back home, or gone if the farm state records it as lost (new vacation, retry,
## load). Clears all claims and empties every sack.
## load). Clears all claims and empties every sack. Crops (#13): a unit whose field hasn't
## sprouted yet (FarmState.nights_survived < CropUnit.sprout_night) goes DORMANT instead of HOME;
## crops_total is repaired to match the sprouted count here too, so a stale save (or one from
## before this field existed) can't disagree with what's actually shown.
func sync_from_state() -> void:
var s := campaign.state
var sprouted_count := 0
for id in range(1, item_count + 1):
match category[id]:
Category.CROP:
status[id] = Status.LOST if s.is_crop_lost(id) else Status.HOME
var sprouted: bool = s.nights_survived >= _units[id].sprout_night
if sprouted:
sprouted_count += 1
status[id] = Status.LOST if s.is_crop_lost(id) else (Status.HOME if sprouted else Status.DORMANT)
_units[id].visible = status[id] == Status.HOME
Category.ANIMAL:
var aid := animal_index(id)
@ -193,10 +205,27 @@ func sync_from_state() -> void:
holder[id] = -1
progress[id] = 0.0
_warned[id] = 0
if sprouted_count > s.crops_total:
s.crops_total = sprouted_count
s.supplies_in_transit = 0
update_visuals()
## Grows crops_total to include a field the moment it sprouts (called from FarmSim at
## night_ending, with the night that just finished: FarmState.nights_survived isn't set to it
## until right after, so this can't use nights_survived yet). A plain FarmState var, so once
## grown it's part of the morning snapshot (retry and the save file) and sync_from_state() never
## has to repair it down again. Never shrinks crops_total.
func grow_crops_total(night_survived: int) -> void:
var s := campaign.state
var sprouted_count := 0
for id in range(1, unit_count + 1):
if night_survived >= _units[id].sprout_night:
sprouted_count += 1
if sprouted_count > s.crops_total:
s.crops_total = sprouted_count
## Co-op host: every item's status, holder (enemy handle), steal progress, ground spot, and sack.
func replica_record() -> Dictionary:
var shown := PackedByteArray()