Merge task #13: lettuce/cabbage and corn fields sprout after nights 2 and 4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
930647cccd
8 changed files with 974 additions and 28 deletions
|
|
@ -1,7 +1,16 @@
|
|||
class_name CropUnit
|
||||
extends Node3D
|
||||
## One stealable crop unit: a cluster of plants (this node's children) with one ID in FarmState.
|
||||
## The crop field holds 6 plots of 5 units; each unit is one row segment of its plot.
|
||||
## The original crop field holds 6 plots of 5 units; each unit is one row segment of its plot.
|
||||
## #13: two more fields (lettuce/cabbage, corn), each 2 plots of 5 units, sprout later in the
|
||||
## campaign: dormant (hidden, unclaimable) until FarmState.nights_survived reaches sprout_night,
|
||||
## then home like any other crop (LootSystem.sync_from_state derives this every morning).
|
||||
|
||||
@export var unit_id: int = 0
|
||||
@export var plot: int = 0
|
||||
## "sunflower" (the original field), "lettuce", or "corn" (#13). Cosmetic only; LootSystem
|
||||
## groups theft rules by category, not by this.
|
||||
@export var crop: String = "sunflower"
|
||||
## The night that must be survived (FarmState.nights_survived) before this unit sprouts and
|
||||
## becomes stealable. 0 = already grown, in play from the first morning.
|
||||
@export var sprout_night: int = 0
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ func zone_at(point: Vector3) -> FarmZone:
|
|||
return null
|
||||
|
||||
|
||||
## The farm's own zone of a kind (never an outside one).
|
||||
## The farm's own zone of a kind (never an outside one). When a kind has more than one zone
|
||||
## (#13: three CROP_FIELD zones), this is just the first found: use zones_of() for all of them.
|
||||
func zone(kind: FarmZone.Kind) -> FarmZone:
|
||||
for z in zones():
|
||||
if z.kind == kind:
|
||||
|
|
@ -39,6 +40,15 @@ func zone(kind: FarmZone.Kind) -> FarmZone:
|
|||
return null
|
||||
|
||||
|
||||
## Every one of the farm's own zones of a kind, in scene order.
|
||||
func zones_of(kind: FarmZone.Kind) -> Array[FarmZone]:
|
||||
var out: Array[FarmZone] = []
|
||||
for z in zones():
|
||||
if z.kind == kind:
|
||||
out.append(z)
|
||||
return out
|
||||
|
||||
|
||||
## The gathering areas beyond the fence.
|
||||
func outside_zones() -> Array[FarmZone]:
|
||||
var out: Array[FarmZone] = []
|
||||
|
|
@ -109,12 +119,11 @@ func side_of(p: Vector2) -> String:
|
|||
return ns + "-" + we if ns != "" and we != "" else ns + we
|
||||
|
||||
|
||||
## Every CropUnit in every CROP_FIELD zone (#13: the original field plus the two later ones).
|
||||
func crop_units() -> Array[CropUnit]:
|
||||
var out: Array[CropUnit] = []
|
||||
var field := zone(FarmZone.Kind.CROP_FIELD)
|
||||
if field == null:
|
||||
return out
|
||||
for node in field.find_children("*", "Node3D", true, false):
|
||||
if node is CropUnit:
|
||||
out.append(node)
|
||||
for field in zones_of(FarmZone.Kind.CROP_FIELD):
|
||||
for node in field.find_children("*", "Node3D", true, false):
|
||||
if node is CropUnit:
|
||||
out.append(node)
|
||||
return out
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue