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

@ -131,7 +131,12 @@ func _ready() -> void:
shed_stock.setup(campaign, shed_zone, player) # every pile prop in place for the navigation
nav.build(get_parent(), zones.playable.grow(5.0), config.nav_cell_size, config.enemy_radius + config.nav_inflate_margin)
shed_stock.refresh()
var field := zones.zone(FarmZone.Kind.CROP_FIELD)
# #13: three CROP_FIELD zones now (the original field, lettuce/cabbage, corn); field_rect is
# their bounding box (ThiefBehavior.area_for: "close enough, go straight" once inside it).
var crop_zones := zones.zones_of(FarmZone.Kind.CROP_FIELD)
var field_rect := crop_zones[0].rect()
for i in range(1, crop_zones.size()):
field_rect = field_rect.merge(crop_zones[i].rect())
# Goals are the crop rows themselves (not the whole zone), so a fence around the crops
# encloses every goal and thieves have to break in. Likewise the inside of the pen.
var crop_goals := PackedInt32Array()
@ -162,7 +167,7 @@ func _ready() -> void:
animals = AnimalSystem.new()
animals.name = "Animals"
add_child(animals)
behavior.setup(config, nav, loot, crop_field, escape_field, field.rect())
behavior.setup(config, nav, loot, crop_field, escape_field, field_rect)
behavior.pen_rect = pen_zone.rect()
behavior.shed_rect = shed_zone.rect()
behavior.farm_rect = zones.playable
@ -675,8 +680,9 @@ func _ground_takes_crops() -> bool:
func _breaker_goals() -> PackedInt32Array:
if structures == null:
return PackedInt32Array()
var areas: Array[Rect2] = [zones.zone(FarmZone.Kind.CROP_FIELD).rect(), zones.zone(FarmZone.Kind.ANIMAL_PEN).rect(),
zones.zone(FarmZone.Kind.SUPPLY_SHED).rect()]
var areas: Array[Rect2] = [zones.zone(FarmZone.Kind.ANIMAL_PEN).rect(), zones.zone(FarmZone.Kind.SUPPLY_SHED).rect()]
for z in zones.zones_of(FarmZone.Kind.CROP_FIELD): # #13: all three crop fields, not just one
areas.append(z.rect())
var guarding: Array[Dictionary] = []
var barriers: Array[Dictionary] = []
for e in campaign.state.structures:
@ -753,11 +759,15 @@ func _on_phase_changed(phase: CampaignController.Phase, _previous: CampaignContr
## End of the dawn grace: whoever is still on the farm leaves (carrying their loot off), and
## loot still lying on the ground goes home (crops to their plots, sacks to the shed, loose
## animals to the pen).
## animals to the pen). #13: grows crops_total for any field that just sprouted (state.night is
## the night that just finished; nights_survived isn't set to it until right after this signal),
## so the morning snapshot (retry, the save file) already has it right. The new field's units
## themselves flip from DORMANT to HOME in loot.sync_from_state(), at the morning that follows.
func _on_night_ending() -> void:
enemies.remove_all()
loot.return_dropped()
interactions.regen_overnight()
loot.grow_crops_total(campaign.state.night)
func _unhandled_input(event: InputEvent) -> void: