Task #20: lettuce and corn fields on the south soil, map grows to 60 x 80

- farm.tscn: LettuceField moves to (-1, 0.44, 25) on the SW soil tile
  (ground_008_004) and CornField to (29, 0.31, 25) on the SE tile
  (ground_011_003), both still 10 x 10 m. Their units keep ids 31-40 /
  41-50, plots 7-10 and sprout nights 2 / 4. The sunflower children are
  replaced: lettuce rows get 8 cabbage heads each (plant_004/005), corn
  rows 10 stalks each (plant_001, scaled ~0.8). Every plant's height
  follows the soil under it (raycast), so none floats.
- South Fields (outside zone) moves to (9.5, 41), 66 x 10, between the
  new south edge (z 35) and the old south fence; its four hay points
  move there too and rest on the soil.
- FarmZones.playable: Rect2(-13, -45, 60, 80), i.e. z -45..35.
- ThiefBehavior: one rect per crop field (field_rects) instead of their
  bounding box; area_for() takes the target's position.
- LootSystem: carried/dropped crop tokens show the crop's own plant
  (CROP_TOKENS), each scene loaded once.
- Tests: test_farm_layout checks the 60 x 80 map, outside zones off the
  map, the later fields on the soil tiles with their own plants standing
  on the soil, side names for both fields, the open east side south of
  the fence, and splits the travel bound (12 s core rule, 16 s for the
  south fields). test_theft: new south edge cell, crop tokens.
  run_tests EDGE/SKY south points follow the edge. test_targets: the
  dropped animal is watched from outside the gate (the carrier now dies
  ~4 m from the west edge).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-06 13:10:08 -04:00
parent 26b735d3e6
commit fc7c74fa32
10 changed files with 593 additions and 475 deletions

View file

@ -8,8 +8,10 @@ extends Node3D
@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.
## "sunflower" (the original field), "lettuce", or "corn" (#13). Cosmetic only: it picks the
## token a carried or dropped unit shows (#20, LootSystem.CROP_TOKENS), while theft rules go by
## category, not by this. The plants under the unit are the scene's (sunflowers plant_007/008,
## cabbage heads plant_004/005, corn stalks plant_001).
@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.

View file

@ -131,12 +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()
# #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())
# #13: three CROP_FIELD zones (the original field, lettuce/cabbage, corn). #20: each keeps its
# own rectangle (ThiefBehavior.area_for: "close enough, go straight" once inside the target's
# field); their bounding box would span most of the map now that the later fields lie south.
var field_rects: Array[Rect2] = []
for z in zones.zones_of(FarmZone.Kind.CROP_FIELD):
field_rects.append(z.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()
@ -167,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_rects)
behavior.pen_rect = pen_zone.rect()
behavior.shed_rect = shed_zone.rect()
behavior.farm_rect = zones.playable

View file

@ -8,7 +8,9 @@ extends Node3D
## (WaveDirector). Beyond the map the scarecrow can roam out to the old farm's outer fences
## (Perimeter/PlayerBounds), where outside zones hold more to gather.
@export var playable := Rect2(-13.0, -45.0, 60.0, 60.0)
## 60 x 80 m, x -13..47, z -45..35. #20: it reaches 20 m further south than the original 60 x 60 m
## map, over the old plowed soil where the lettuce/cabbage and corn fields now grow.
@export var playable := Rect2(-13.0, -45.0, 60.0, 80.0)
## Where the scarecrow can go: out to the old farm's outer fences.
@export var roam := Rect2(-27.6, -59.6, 82.4, 106.6)

View file

@ -57,7 +57,14 @@ const BADGE_FILL := {
Category.ANIMAL: [Color(1.0, 0.62, 0.78), Color(1.0, 0.92, 0.95)],
Category.SUPPLY: [Color(0.78, 0.62, 0.4), Color(0.35, 0.8, 1.0)],
}
const TOKEN_SCENE := "res://assets/farm/ithappy/farm/prefabs/assets/plant/plant_007.tscn"
## The token a carried or dropped crop shows, by CropUnit.crop (#20): the plant that grows in its
## field (a sunflower, a cabbage head, a corn stalk), scaled to about a meter at its largest. Any
## other crop shows a sunflower.
const CROP_TOKENS := {
"sunflower": ["res://assets/farm/ithappy/farm/prefabs/assets/plant/plant_007.tscn", 0.6],
"lettuce": ["res://assets/farm/ithappy/farm/prefabs/assets/plant/plant_004.tscn", 1.2],
"corn": ["res://assets/farm/ithappy/farm/prefabs/assets/plant/plant_001.tscn", 0.4],
}
const SACK_SCENE := "res://assets/farm/ithappy/farm/prefabs/assets/prop/bag_002.tscn"
const THREAT_COLORS := {
Threat.TARGETED: Color(1.0, 0.6, 0.1),
@ -140,7 +147,10 @@ func setup(p_campaign: CampaignController, units: Array[CropUnit], p_enemies: En
_outline[c] = outline_material(CATEGORY_COLORS[c])
var ring_shader := load("res://game/resources/steal_ring.gdshader") as Shader
var icon_shader := load("res://game/resources/loot_icon.gdshader") as Shader
var token_scene := load(TOKEN_SCENE) as PackedScene
var crop_of := {} # unit id -> a CROP_TOKENS key
for u in units:
crop_of[u.unit_id] = u.crop if CROP_TOKENS.has(u.crop) else "sunflower"
var token_scenes := {} # loaded once per crop: an instance doesn't keep its PackedScene alive
var sack_scene := load(SACK_SCENE) as PackedScene
for id in range(1, n):
category[id] = _category_of(id)
@ -157,8 +167,11 @@ func setup(p_campaign: CampaignController, units: Array[CropUnit], p_enemies: En
var token: Node3D = null
match category[id]:
Category.CROP:
token = token_scene.instantiate() as Node3D
token.scale = Vector3.ONE * 0.6
var crop: String = crop_of.get(id, "sunflower")
if not token_scenes.has(crop):
token_scenes[crop] = load(CROP_TOKENS[crop][0])
token = (token_scenes[crop] as PackedScene).instantiate() as Node3D
token.scale = Vector3.ONE * float(CROP_TOKENS[crop][1])
Category.SUPPLY:
token = sack_scene.instantiate() as Node3D
token.scale = Vector3.ONE * 0.85

View file

@ -60,7 +60,9 @@ var loot: LootSystem
var nav: FarmNavigation
var crop_field: PackedInt32Array
var escape_field: PackedInt32Array
var field_rect: Rect2
## Every crop field's rectangle (#20: one per field, not their bounding box, now that the fields
## lie far apart). A crop thief inside the field its target grows in goes straight at it.
var field_rects: Array[Rect2] = []
## Set by FarmSim: the flow fields toward the pen, each shed pile (material -> field), and the
## barriers guarding valuables; those areas; the farm (flyers leave over its edge); and, every
## tick, where the scarecrow is.
@ -83,13 +85,13 @@ var _dir := PackedFloat32Array([0.0, 0.0])
func setup(p_cfg: GameConfig, p_nav: FarmNavigation, p_loot: LootSystem, p_crop_field: PackedInt32Array,
p_escape_field: PackedInt32Array, p_field_rect: Rect2) -> void:
p_escape_field: PackedInt32Array, p_field_rects: Array[Rect2]) -> void:
cfg = p_cfg
nav = p_nav
loot = p_loot
crop_field = p_crop_field
escape_field = p_escape_field
field_rect = p_field_rect
field_rects = p_field_rects
func update(es: EnemySystem, dt: float) -> void:
@ -236,7 +238,7 @@ func _seek(es: EnemySystem, i: int, dt: float) -> void:
return
es.pace[i] = 1.0
var field := field_for(unit)
if (area_for(loot.category[unit]).has_point(p) or d < cfg.direct_seek_distance) and nav.line_clear(p.x, p.y, goal.x, goal.y):
if (area_for(loot.category[unit], goal).has_point(p) or d < cfg.direct_seek_distance) and nav.line_clear(p.x, p.y, goal.x, goal.y):
es.desire_x[i] = to.x / d
es.desire_z[i] = to.y / d
es.timer[i] = 0.0
@ -437,13 +439,19 @@ func field_for(id: int) -> PackedInt32Array:
return crop_field
func area_for(c: int) -> Rect2:
## The area around an item's home where a thief stops following the flow field and goes straight
## (given a clear line): the pen, the shed, or the crop field holding goal (none for a crop lying
## outside every field).
func area_for(c: int, goal: Vector2) -> Rect2:
match c:
LootSystem.Category.ANIMAL:
return pen_rect
LootSystem.Category.SUPPLY:
return shed_rect
return field_rect
for r in field_rects:
if r.has_point(goal):
return r
return Rect2()
func _steal(es: EnemySystem, i: int, dt: float) -> void: