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

@ -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: