Merge task #20: lettuce and corn fields on the south soil, map 60 x 80

Lettuce (x -6..4) and corn (x 24..34, both z 20..30) sit on the bare
SW/SE soil with cabbage and corn-stalk prefabs and matching crop
tokens; playable map extends south to z 35; SouthFields moved off the
map; per-field thief rects. test_targets conflict resolved in favour of
#21 (dropped animals no longer run for the edge).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-06 13:19:10 -04:00
commit 11d19d874a
10 changed files with 676 additions and 508 deletions

View file

@ -5,11 +5,14 @@ The playable farm built in Step 2 of `first-game-plan.md`. All numbers here are
## The map ## The map
- **Playable area: 60 × 60 m**, x −13…47 and z −45…15 (`FarmZones.playable`). The rest of the - **Playable area: 60 × 80 m**, x −13…47 and z −45…35 (`FarmZones.playable`). It was 60 × 60 m
old farm is out-of-bounds scenery. (to z 15) until #20 extended it 20 m south over the old plowed soil, where the lettuce/cabbage
and corn fields grow. The rest of the old farm is out-of-bounds scenery.
- **Perimeter:** what's left of the wooden fence (`fence_005`, 52 segments): the north side and - **Perimeter:** what's left of the wooden fence (`fence_005`, 52 segments): the north side and
the east side, with **3 gaps**. The south side and most of the west side were taken out, so the the east side down to z 15 (the original map's south-east corner), with **3 gaps**. The south
farm is open ground there. side and most of the west side were taken out, and the east side's southern 20 m (z 15…35) has
none, so the farm is open ground there. Just beyond that stretch, about 1 m outside the map,
the old farm's outer fence runs north to south (x ≈ 48.2, z 18…46).
- **The farm's edge** is where enemies come from and go: every enemy arrives at its own random - **The farm's edge** is where enemies come from and go: every enemy arrives at its own random
point along it, and carriers escape across it (see "The farm's edge" below). point along it, and carriers escape across it (see "The farm's edge" below).
- **Scarecrow bounds:** invisible walls on the old farm's outer fences (`Zones/Perimeter/PlayerBounds`, - **Scarecrow bounds:** invisible walls on the old farm's outer fences (`Zones/Perimeter/PlayerBounds`,
@ -21,7 +24,7 @@ The playable farm built in Step 2 of `first-game-plan.md`. All numbers here are
Top-down picture with zone outlines: Top-down picture with zone outlines:
```sh ```sh
godot --path . --script res://game/tools/render_overview.gd -- --out=/tmp/farm.png --center=17,-15 --size=66 --zones godot --path . --script res://game/tools/render_overview.gd -- --out=/tmp/farm.png --center=17,-5 --size=86 --zones
``` ```
## Zones ## Zones
@ -34,8 +37,10 @@ name when the scarecrow walks in.
| Zone | Rectangle (x, z) | What's there | Purpose | | Zone | Rectangle (x, z) | What's there | Purpose |
|---|---|---|---| |---|---|---|---|
| Crop Field | 14…46, −18.6…11.4 | The sunflower field: 6 plots, 30 crop units, two 2 m walkways between the plot bands | Exposed asset; crows' target | | Crop Field | 14…46, −18.6…11.4 | The sunflower field: 6 plots, 30 crop units, two 2 m walkways between the plot bands | Exposed asset; crows' target |
| Lettuce Field | −6…4, 20…30 | Cabbage heads on the south-west plowed soil: 2 plots, 10 crop units. Sprouts after night 2 | A later crop field (see "The later fields" below) |
| Corn Field | 24…34, 20…30 | Corn stalks on the south-east plowed soil: 2 plots, 10 crop units. Sprouts after night 4 | A later crop field |
| Supply Shed | −6…8, −24…−14 | The red barn's south doors and the apron in front of them, with stock piles that grow and shrink with the stock (`ShedStock`): crates for scrap (west of the doors), logs for wood and hay bales for straw (east of the doors); also sacks and barrels | Stored materials; supply thieves' target | | Supply Shed | −6…8, −24…−14 | The red barn's south doors and the apron in front of them, with stock piles that grow and shrink with the stock (`ShedStock`): crates for scrap (west of the doors), logs for wood and hay bales for straw (east of the doors); also sacks and barrels | Stored materials; supply thieves' target |
| Work Area | 8…14, −24…−15 | Tool table, workbench, chair, bucket, between the barn and the house | Crafting, repairs, and upgrades | | Work Area | 25.6…31.6, −29.8…−20.8 | Tool table, workbench, chair, bucket, between the barn and the house | Crafting, repairs, and upgrades |
| Animal Pen | −10…4, −11…−1 | Brown paddock fence, a gate in the opening on the east side (a gate structure, standing from the start), henhouse, 4 chickens, 2 pigs, 2 sheep | Livestock; animal thieves' target. Enemies can only reach the inside by breaking the gate | | Animal Pen | −10…4, −11…−1 | Brown paddock fence, a gate in the opening on the east side (a gate structure, standing from the start), henhouse, 4 chickens, 2 pigs, 2 sheep | Livestock; animal thieves' target. Enemies can only reach the inside by breaking the gate |
| Woodlot | 37.5…46.5, −35…−21 | The fir tree line, dead trees and branches, log piles | Wood | | Woodlot | 37.5…46.5, −35…−21 | The fir tree line, dead trees and branches, log piles | Wood |
| Scrap Heap | 25.5…36.5, −44…−33 | Old pickup, wagon, wheelbarrow, lawn mower, barrels, crate, on the farmyard dirt | Scrap | | Scrap Heap | 25.5…36.5, −44…−33 | Old pickup, wagon, wheelbarrow, lawn mower, barrels, crate, on the farmyard dirt | Scrap |
@ -78,7 +83,7 @@ Each point is a `GatherNode` under its zone, holding the props it is made of.
workbench. workbench.
The middle and south-west of the map (x −13…14, z −1…15) are deliberately open ground for The middle and south-west of the map (x −13…14, z −1…15) are deliberately open ground for
building defenses. building defenses, and so is the south end around the later fields (z 15…35).
### Crop units ### Crop units
@ -94,6 +99,29 @@ visible.
| Middle band (z −6.5…0.4) | Plot 3: units 11–15 | Plot 4: units 16–20 | | Middle band (z −6.5…0.4) | Plot 3: units 11–15 | Plot 4: units 16–20 |
| South band (z 2.4…9.4) | Plot 5: units 21–25 | Plot 6: units 26–30 | | South band (z 2.4…9.4) | Plot 5: units 21–25 | Plot 6: units 26–30 |
### The later fields (#13, #20)
Two more crop fields sprout during the campaign. Until then their units are dormant: hidden, and
not stealable (`CropUnit.sprout_night`, `LootSystem`). #20 moved them onto the bare plowed soil
south of the original map: the ithappy `ground_008_004` tile (south-west, x −25.3…7.5,
z 14.6…45.3) and `ground_011_003` (south-east, x 13.4…46.1, z 14.2…44.8).
| Field | Zone (x, z) | Units | Plants per unit | Sprouts after |
|---|---|---|---|---|
| Lettuce Field | −6…4, 20…30 | Plot 7: 31–35, Plot 8: 36–40 | 8 cabbage heads (`plant_004` / `plant_005`, ≈0.45 m) | Night 2 |
| Corn Field | 24…34, 20…30 | Plot 9: 41–45, Plot 10: 46–50 | 10 corn stalks (`plant_001`, scaled to ≈2.1 m) | Night 4 |
- Each unit is one north–south row, about 6.6 m long (z ≈ 21.7…28.4). The rows are 0.95 m apart.
- **Height:** the soil's surface is 0.2–0.65 m above the grass. Each field's zone sits at the
soil's median height under its plants (y 0.44 and 0.31), and every plant follows the soil
beneath it.
- A cabbage rests on the lowest soil under its leaves.
- A corn stalk's base is 6 cm into the soil.
- `test_farm_layout` checks that no plant floats.
- **Tokens:** a carried or dropped crop shows its own field's plant (`LootSystem.CROP_TOKENS`).
- **Thieves:** a crop thief goes straight at its target once inside that target's field, given a
clear line (`ThiefBehavior.field_rects`, one rectangle per field).
## The farm's edge and the fence's gaps ## The farm's edge and the fence's gaps
**Arrivals.** Every enemy arrives at its own random point along the farm's edge **Arrivals.** Every enemy arrives at its own random point along the farm's edge
@ -116,7 +144,8 @@ always walk out to the gathering areas.
| GapEast | east, z −20…−17 | Woodlot and the crop field's north-east corner | | GapEast | east, z −20…−17 | Woodlot and the crop field's north-east corner |
The signposts of the three gaps that were in the removed south and west fence (SignSouthEast, The signposts of the three gaps that were in the removed south and west fence (SignSouthEast,
SignSouthWest, SignWest) still stand. SignSouthWest, SignWest) still stand. Since #20, SignSouthEast and SignSouthWest stand inside the
map, near the old south edge (z ≈ 13.8).
## Travel times ## Travel times
@ -124,20 +153,27 @@ Scarecrow at run speed (5 m/s). Path lengths come from the navigation grid with
radius (0.4 m), from zone center to zone center. The Animal Pen's center is inside the pen, so radius (0.4 m), from zone center to zone center. The Animal Pen's center is inside the pen, so
routes to it go through the gate. routes to it go through the gate.
| From \ to | Crop Field | Supply Shed | Work Area | Animal Pen | Woodlot | Scrap Heap | Haystacks | | From \ to | Crop Field | Lettuce Field | Corn Field | Supply Shed | Work Area | Animal Pen | Woodlot | Scrap Heap | Haystacks |
|---|---|---|---|---|---|---|---| |---|---|---|---|---|---|---|---|---|---|
| **Crop Field** | — | 7.2 s | 5.4 s | 6.8 s | 5.9 s | 7.3 s | 8.0 s | | **Crop Field** | — | 8.5 s | 5.9 s | 7.2 s | 4.4 s | 6.8 s | 5.9 s | 7.1 s | 8.0 s |
| **Supply Shed** | 7.2 s | — | 2.8 s | 4.3 s | 9.7 s | 9.1 s | 8.3 s | | **Lettuce Field** | 8.5 s | — | 6.0 s | 9.0 s | 12.5 s | 6.4 s | 14.2 s | 15.4 s | 15.5 s |
| **Work Area** | 5.4 s | 2.8 s | — | 4.7 s | 7.1 s | 6.6 s | 5.7 s | | **Corn Field** | 5.9 s | 6.0 s | — | 11.0 s | 10.1 s | 8.9 s | 11.8 s | 13.0 s | 13.7 s |
| **Animal Pen** | 6.8 s | 4.3 s | 4.7 s | — | 10.8 s | 11.0 s | 10.3 s | | **Supply Shed** | 7.2 s | 9.0 s | 11.0 s | — | 6.9 s | 2.9 s | 9.7 s | 9.1 s | 8.3 s |
| **Woodlot** | 5.9 s | 9.7 s | 7.1 s | 10.8 s | — | 3.5 s | 5.3 s | | **Work Area** | 4.4 s | 12.5 s | 10.1 s | 6.9 s | — | 8.0 s | 3.0 s | 3.2 s | 3.7 s |
| **Scrap Heap** | 7.3 s | 9.1 s | 6.6 s | 11.0 s | 3.5 s | — | 2.3 s | | **Animal Pen** | 6.8 s | 6.4 s | 8.9 s | 2.9 s | 8.0 s | — | 10.8 s | 10.3 s | 9.4 s |
| **Haystacks** | 8.0 s | 8.3 s | 5.7 s | 10.3 s | 5.3 s | 2.3 s | — | | **Woodlot** | 5.9 s | 14.2 s | 11.8 s | 9.7 s | 3.0 s | 10.8 s | — | 3.5 s | 5.3 s |
| **Scrap Heap** | 7.1 s | 15.4 s | 13.0 s | 9.1 s | 3.2 s | 10.3 s | 3.5 s | — | 2.3 s |
| **Haystacks** | 8.0 s | 15.5 s | 13.7 s | 8.3 s | 3.7 s | 9.4 s | 5.3 s | 2.3 s | — |
The longest trip is 11.0 s (Animal Pen ↔ Scrap Heap). The rule is no key area more than 12 s from - **The rule:** no key area more than 12 s from another. Among the original zones the longest
another. The two defended fronts sit 6–7 s apart: the crop field in the south-east, and the pen trip is 10.8 s (Animal Pen ↔ Woodlot).
and shed in the west. Holding one leaves the other exposed. The gathering spots are in the north, - **The later fields** at the map's south end are farther out: up to 15.5 s (Lettuce Field ↔
so a day of gathering pulls the scarecrow away from both fronts. Haystacks). `test_farm_layout` bounds them at 16 s.
- **The defended fronts:** the sunflower field in the east, and the pen and shed in the west, sit
6–7 s apart. Holding one leaves the other exposed. From night 2 the lettuce field joins them at
the south-west end (6.4 s from the pen), and from night 4 the corn field at the south-east end
(5.9 s from the sunflower field, 6.0 s from the lettuce).
- **Gathering** is in the north, so a day of gathering pulls the scarecrow away from every front.
Ground-enemy path from the middle of each side of the farm's edge (3 m out) to the nearest edge of Ground-enemy path from the middle of each side of the farm's edge (3 m out) to the nearest edge of
each zone, in meters (enemy radius 0.35 m). Enemies arrive anywhere along the edge, so these are each zone, in meters (enemy radius 0.35 m). Enemies arrive anywhere along the edge, so these are
@ -145,13 +181,20 @@ samples, not routes everyone takes; arriving behind the north fence means walkin
| Zone | North | East | South | West | | Zone | North | East | South | West |
|---|---|---|---|---| |---|---|---|---|---|
| Crop Field | 35 | 6 | 7 | 30 | | Crop Field | 35 | 16 | 27 | 30 |
| Supply Shed | 31 | 45 | 36 | 10 | | Lettuce Field | 76 | 67 | 17 | 29 |
| Work Area | 29 | 39 | 35 | 24 | | Corn Field | 78 | 37 | 11 | 50 |
| Animal Pen (inside) | 51 | 53 | 30 | 28 | | Supply Shed | 31 | 54 | 56 | 14 |
| Woodlot | 44 | 9 | 48 | 56 | | Work Area | 33 | 32 | 63 | 48 |
| Scrap Heap | 30 | 26 | 55 | 50 | | Animal Pen (inside) | 46 | 61 | 45 | 6 |
| Haystacks | 11 | 37 | 55 | 43 | | Woodlot | 44 | 19 | 68 | 60 |
| Scrap Heap | 30 | 36 | 76 | 54 |
| Haystacks | 11 | 47 | 75 | 47 |
Since #20 the side middles are further south: the east and west ones at z −5 (they were at
z −15), the south one at z 38. The east one is behind the east fence, so enemies arriving there
walk round to a gap or the fence's south end first. Further south on the east side (z 18…38),
arrivals stand behind the old farm's outer fence and walk round its north end (z ≈ 18).
## Navigation ## Navigation
@ -162,10 +205,14 @@ samples, not routes everyone takes; arriving behind the north fence means walkin
- Obstacles are inflated by the mover's radius. - Obstacles are inflated by the mover's radius.
- Distance fields use octile Dijkstra with no corner cutting. - Distance fields use octile Dijkstra with no corner cutting.
For enemies: the playable area plus a 5 m margin is 20,164 cells. 390 shapes are rasterized, and For enemies: the playable area plus a 5 m margin is 25,844 cells (20,164 before #20 extended the
the grid builds in about 25 ms (headless, editor binary). Because the grid comes from the same map). 367 shapes are rasterized, and the grid builds in about 27 ms (headless, editor binary).
collision the player walks against, physics and navigation can't drift apart. Step 3 adds flow Because the grid comes from the same collision the player walks against, physics and navigation
fields toward the crop plots and the farm's edge on top of it. can't drift apart. Step 3 adds flow fields toward the crop plots and the farm's edge on top of it.
A flow-field rebuild after placing a fence (escape, pen, 3 shed piles, fence breakers; 2,000 cells
per tick) takes about 200 ms of work over 85 ticks. Before #20 it was about 150 ms over 64 ticks.
Its largest slice stays about 3 ms.
## What changed from the old farm ## What changed from the old farm
@ -175,6 +222,9 @@ fields toward the crop plots and the farm's edge on top of it.
- the north-west field's soil tile - the north-west field's soil tile
- 29 segments of the old inner east fence that would have doubled the new perimeter - 29 segments of the old inner east fence that would have doubled the new perimeter
- **Moved:** the hay stack from beyond the north fence into the farmyard (Haystacks). - **Moved:** the hay stack from beyond the north fence into the farmyard (Haystacks).
- **#20:** the map grew 20 m south to take in the bare plowed soil there. The lettuce/cabbage and
corn fields (from #13, first placed on the grass at z 2…12) moved onto that soil, with their own
plants instead of sunflowers. The South Fields' hay moved south of the new edge.
- **Collision:** - **Collision:**
- `build_prop_collision.gd` generated collision for the newly placed prop types. - `build_prop_collision.gd` generated collision for the newly placed prop types.
- Animals get none: they are moving entities (`AnimalSystem`). - Animals get none: they are moving entities (`AnimalSystem`).
@ -228,12 +278,16 @@ Four outside zones (`FarmZone.outside`) hold more to gather. Every point there y
| North Grove (wood) | (12, −52), 16 × 12 | GroveDeadTree, GroveSnag, GroveDeadfall (dead trees, 3 charges), GroveLogs (log pile, 3) | GapNorth | | North Grove (wood) | (12, −52), 16 × 12 | GroveDeadTree, GroveSnag, GroveDeadfall (dead trees, 3 charges), GroveLogs (log pile, 3) | GapNorth |
| Old Hangar (scrap) | (38, −53), 18 × 13 | HangarWreck (old SUV, 4), HangarBarrels (3), HangarCart (3) | GapNorth, GapDriveway | | Old Hangar (scrap) | (38, −53), 18 × 13 | HangarWreck (old SUV, 4), HangarBarrels (3), HangarCart (3) | GapNorth, GapDriveway |
| East Road (scrap) | (51.5, −15), 6 × 14 | RoadsideCar (the abandoned red car, moved in from `Level/`, 4), RoadsideBarrels (3) | GapEast | | East Road (scrap) | (51.5, −15), 6 × 14 | RoadsideCar (the abandoned red car, moved in from `Level/`, 4), RoadsideBarrels (3) | GapEast |
| South Fields (straw) | (9.5, 31), 66 × 30 | FieldStackWest, FieldStackEast (4-bale stacks, 4), FieldBaleWest, FieldBaleEast (round bales, 3) | none: the south side is open | | South Fields (straw) | (9.5, 41), 66 × 10 | FieldStackWest (−14, 41.5), FieldStackEast (36, 41.5) (4-bale stacks, 4), FieldBaleWest (−3, 42), FieldBaleEast (21, 41) (round bales, 3) | none: the south side is open |
`FarmZones.zone(kind)` only ever returns the farm's own zone, and `zones()` lists only the farm's. `FarmZones.zone(kind)` only ever returns the farm's own zone, and `zones()` lists only the farm's.
`outside_zones()` lists these, and `zone_at()` finds both (the zone banner says "North Grove `outside_zones()` lists these, and `zone_at()` finds both (the zone banner says "North Grove
(outside the fence)"). (outside the fence)").
**The South Fields** (#20) are the strip of plowed soil between the map's south edge (z 35) and the
old farm's south fence (z ≈ 46.4). Their hay rests on the soil there, south of the later crop
fields and clear of the enemies' arrival line (z 38).
**Placing outside points:** the North Grove sits east of the tall barn on purpose. Behind the barn **Placing outside points:** the North Grove sits east of the tall barn on purpose. Behind the barn
(x < 9), the game camera can't see the scarecrow. The semi-trucks west of the farm are beyond the (x < 9), the game camera can't see the scarecrow. The semi-trucks west of the farm are beyond the
old west fence (x ≈ −28.5), so they're out of reach. old west fence (x ≈ −28.5), so they're out of reach.

File diff suppressed because it is too large Load diff

View file

@ -8,8 +8,10 @@ extends Node3D
@export var unit_id: int = 0 @export var unit_id: int = 0
@export var plot: int = 0 @export var plot: int = 0
## "sunflower" (the original field), "lettuce", or "corn" (#13). Cosmetic only; LootSystem ## "sunflower" (the original field), "lettuce", or "corn" (#13). Cosmetic only: it picks the
## groups theft rules by category, not by this. ## 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" @export var crop: String = "sunflower"
## The night that must be survived (FarmState.nights_survived) before this unit sprouts and ## 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. ## 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 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) nav.build(get_parent(), zones.playable.grow(5.0), config.nav_cell_size, config.enemy_radius + config.nav_inflate_margin)
shed_stock.refresh() shed_stock.refresh()
# #13: three CROP_FIELD zones now (the original field, lettuce/cabbage, corn); field_rect is # #13: three CROP_FIELD zones (the original field, lettuce/cabbage, corn). #20: each keeps its
# their bounding box (ThiefBehavior.area_for: "close enough, go straight" once inside it). # own rectangle (ThiefBehavior.area_for: "close enough, go straight" once inside the target's
var crop_zones := zones.zones_of(FarmZone.Kind.CROP_FIELD) # field); their bounding box would span most of the map now that the later fields lie south.
var field_rect := crop_zones[0].rect() var field_rects: Array[Rect2] = []
for i in range(1, crop_zones.size()): for z in zones.zones_of(FarmZone.Kind.CROP_FIELD):
field_rect = field_rect.merge(crop_zones[i].rect()) field_rects.append(z.rect())
# Goals are the crop rows themselves (not the whole zone), so a fence around the crops # 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. # encloses every goal and thieves have to break in. Likewise the inside of the pen.
var crop_goals := PackedInt32Array() var crop_goals := PackedInt32Array()
@ -167,7 +167,7 @@ func _ready() -> void:
animals = AnimalSystem.new() animals = AnimalSystem.new()
animals.name = "Animals" animals.name = "Animals"
add_child(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.pen_rect = pen_zone.rect()
behavior.shed_rect = shed_zone.rect() behavior.shed_rect = shed_zone.rect()
behavior.farm_rect = zones.playable 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 ## (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. ## (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. ## 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) @export var roam := Rect2(-27.6, -59.6, 82.4, 106.6)

View file

@ -59,7 +59,14 @@ const BADGE_FILL := {
Category.ANIMAL: [Color(1.0, 0.62, 0.78), Color(1.0, 0.92, 0.95)], 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)], 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 SACK_SCENE := "res://assets/farm/ithappy/farm/prefabs/assets/prop/bag_002.tscn"
const THREAT_COLORS := { const THREAT_COLORS := {
Threat.TARGETED: Color(1.0, 0.6, 0.1), Threat.TARGETED: Color(1.0, 0.6, 0.1),
@ -142,7 +149,10 @@ func setup(p_campaign: CampaignController, units: Array[CropUnit], p_enemies: En
_outline[c] = outline_material(CATEGORY_COLORS[c]) _outline[c] = outline_material(CATEGORY_COLORS[c])
var ring_shader := load("res://game/resources/steal_ring.gdshader") as Shader 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 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 var sack_scene := load(SACK_SCENE) as PackedScene
for id in range(1, n): for id in range(1, n):
category[id] = _category_of(id) category[id] = _category_of(id)
@ -159,8 +169,11 @@ func setup(p_campaign: CampaignController, units: Array[CropUnit], p_enemies: En
var token: Node3D = null var token: Node3D = null
match category[id]: match category[id]:
Category.CROP: Category.CROP:
token = token_scene.instantiate() as Node3D var crop: String = crop_of.get(id, "sunflower")
token.scale = Vector3.ONE * 0.6 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: Category.SUPPLY:
token = sack_scene.instantiate() as Node3D token = sack_scene.instantiate() as Node3D
token.scale = Vector3.ONE * 0.85 token.scale = Vector3.ONE * 0.85

View file

@ -60,7 +60,9 @@ var loot: LootSystem
var nav: FarmNavigation var nav: FarmNavigation
var crop_field: PackedInt32Array var crop_field: PackedInt32Array
var escape_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 ## 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 ## barriers guarding valuables; those areas; the farm (flyers leave over its edge); and, every
## tick, where the scarecrow is. ## 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, 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 cfg = p_cfg
nav = p_nav nav = p_nav
loot = p_loot loot = p_loot
crop_field = p_crop_field crop_field = p_crop_field
escape_field = p_escape_field escape_field = p_escape_field
field_rect = p_field_rect field_rects = p_field_rects
func update(es: EnemySystem, dt: float) -> void: func update(es: EnemySystem, dt: float) -> void:
@ -236,7 +238,7 @@ func _seek(es: EnemySystem, i: int, dt: float) -> void:
return return
es.pace[i] = 1.0 es.pace[i] = 1.0
var field := field_for(unit) 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_x[i] = to.x / d
es.desire_z[i] = to.y / d es.desire_z[i] = to.y / d
es.timer[i] = 0.0 es.timer[i] = 0.0
@ -437,13 +439,19 @@ func field_for(id: int) -> PackedInt32Array:
return crop_field 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: match c:
LootSystem.Category.ANIMAL: LootSystem.Category.ANIMAL:
return pen_rect return pen_rect
LootSystem.Category.SUPPLY: LootSystem.Category.SUPPLY:
return shed_rect 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: func _steal(es: EnemySystem, i: int, dt: float) -> void:

View file

@ -26,14 +26,15 @@ const SUITES := [
] ]
const TICK := 1.0 / 60.0 const TICK := 1.0 / 60.0
## Points on the farm's edge (FarmZones.edge) for tests that send an enemy in from a known side: ## Points on the farm's edge (FarmZones.edge) for tests that send an enemy in from a known side:
## on foot GameConfig.spawn_margin (3 m) outside the map, where the perimeter gaps used to be... ## on foot GameConfig.spawn_margin (3 m) outside the map, where the perimeter gaps used to be (#20:
## the south ones moved with the map's south edge, now z 35)...
const EDGE := { const EDGE := {
"north": Vector2(12.0, -48.0), "driveway": Vector2(50.0, -39.5), "east": Vector2(50.0, -18.5), "north": Vector2(12.0, -48.0), "driveway": Vector2(50.0, -39.5), "east": Vector2(50.0, -18.5),
"south-east": Vector2(31.0, 18.0), "south-west": Vector2(-4.0, 18.0), "west": Vector2(-16.0, -6.0), "south-east": Vector2(31.0, 38.0), "south-west": Vector2(-4.0, 38.0), "west": Vector2(-16.0, -6.0),
} }
## ...and flying flyer_spawn_margin (8 m) out, where the crow approaches were. ## ...and flying flyer_spawn_margin (8 m) out, where the crow approaches were.
const SKY := { const SKY := {
"north": Vector2(17.0, -53.0), "east": Vector2(55.0, -5.0), "south": Vector2(17.0, 23.0), "west": Vector2(-21.0, -15.0), "north": Vector2(17.0, -53.0), "east": Vector2(55.0, -5.0), "south": Vector2(17.0, 43.0), "west": Vector2(-21.0, -15.0),
} }
var passes: int = 0 var passes: int = 0

View file

@ -1,16 +1,27 @@
extends RefCounted extends RefCounted
## The playable farm: every zone exists once inside the 60 x 60 m map without overlapping, ## The playable farm: every zone exists once inside the 60 x 80 m map without overlapping (the
## lookups by position, the crop units, the farm's edge (where enemies arrive) and the gaps in ## outside zones stay off it), lookups by position, the crop units, the later crop fields on the
## what's left of the perimeter fence (the north and east sides, without holes except their gaps; ## plowed soil south of the original map with their own plants, the farm's edge (where enemies
## the south and west are open), ground navigation from anywhere on the edge to every zone, ## arrive) and the gaps in what's left of the perimeter fence (the north and east sides, without
## scarecrow-only bounds, zone-to-zone travel times (printed as the table kept in ## holes except their gaps; the south, the west, and the east side south of the fence are open),
## game/LAYOUT.md), and the zone banner. ## ground navigation from anywhere on the edge to every zone, scarecrow-only bounds, zone-to-zone
## travel times (printed as the table kept in game/LAYOUT.md), and the zone banner.
const RUN_SPEED := 5.0 # PlayerCharacter.run_speed const RUN_SPEED := 5.0 # PlayerCharacter.run_speed
## #13: the two new south-west crop fields are a legitimate corner of the map (user-decided ## The layout rule: no key area more than 12 s from another. It holds for the farm's original
## placement), and the farthest pair (a new field to the Scrap Heap, clear across the map) is a ## zones.
## little past the old 12 s bar; raised to fit it with a little room. const MAX_TRAVEL := 12.0
const MAX_TRAVEL := 13.0 ## #20: the lettuce/cabbage and corn fields sprout later, on the plowed soil at the map's south
## end (user-decided placement), so trips to them run longer: the farthest, the lettuce field to
## the Haystacks clear across the map, is 15.5 s. They get their own bound with a little room.
const MAX_TRAVEL_SOUTH_FIELDS := 16.0
## #20: the later fields' plants: cabbage heads and corn stalks, never the original field's
## sunflowers.
const PLANTS := "res://assets/farm/ithappy/farm/prefabs/assets/plant/plant_%s.tscn"
const FIELD_PLANTS := {"lettuce": ["004", "005"], "corn": ["001"]}
const SUNFLOWER_PLANTS := ["007", "008"]
## How deep a later field's plant may sit in the soil (its base below the surface).
const SUNK := 0.2
const ENEMY_RADIUS := 0.35 const ENEMY_RADIUS := 0.35
const SCARECROW_RADIUS := 0.4 const SCARECROW_RADIUS := 0.4
const CELL := 0.5 const CELL := 0.5
@ -26,10 +37,12 @@ func run(r: GameTestRunner) -> void:
if zones == null: if zones == null:
return return
var map := zones.playable var map := zones.playable
r.check(is_equal_approx(map.size.x, 60.0) and is_equal_approx(map.size.y, 60.0), "the playable map is 60 x 60 m") r.check(map.position.is_equal_approx(Vector2(-13.0, -45.0)) and map.size.is_equal_approx(Vector2(60.0, 80.0)),
"the playable map is 60 x 80 m, x -13..47 and z -45..35 (%s)" % map)
_zones(r, zones) _zones(r, zones)
_crops(r, zones) _crops(r, zones)
_south_fields(r, farm, zones)
_markers(r, zones) _markers(r, zones)
var nav := FarmNavigation.new() var nav := FarmNavigation.new()
nav.build(farm, map.grow(5.0), CELL, ENEMY_RADIUS) nav.build(farm, map.grow(5.0), CELL, ENEMY_RADIUS)
@ -58,6 +71,15 @@ func _zones(r: GameTestRunner, zones: FarmZones) -> void:
for j in range(i + 1, all.size()): for j in range(i + 1, all.size()):
r.check(not a.rect().intersects(all[j].rect()), "%s and %s don't overlap" % [a.display_name, all[j].display_name]) r.check(not a.rect().intersects(all[j].rect()), "%s and %s don't overlap" % [a.display_name, all[j].display_name])
r.check(zones.zone_at(Vector3(8.0, 0.0, -10.0)) == null, "open ground between zones belongs to no zone") r.check(zones.zone_at(Vector3(8.0, 0.0, -10.0)) == null, "open ground between zones belongs to no zone")
# The gathering areas beyond the fence stay off the map (#20: the South Fields moved south of
# the map's new south edge) and clear of every other zone.
var outside := zones.outside_zones()
for i in outside.size():
var o := outside[i]
r.check(not zones.playable.intersects(o.rect()), "%s lies outside the playable map" % o.display_name)
r.check(zones.zone_at(o.global_position) == o, "zone_at(center of %s) finds it" % o.display_name)
for z in all + outside.slice(i + 1):
r.check(not o.rect().intersects(z.rect()), "%s and %s don't overlap" % [o.display_name, z.display_name])
## #13: 20 more crop units in two later-sprouting fields (lettuce/cabbage, corn), 10 each, ids ## #13: 20 more crop units in two later-sprouting fields (lettuce/cabbage, corn), 10 each, ids
@ -93,6 +115,106 @@ func _crops(r: GameTestRunner, zones: FarmZones) -> void:
"10 corn units sprout after night 4") "10 corn units sprout after night 4")
## #20: the lettuce/cabbage and corn fields grow on the bare plowed soil south of the original map
## (the ithappy ground_008 / ground_011 tiles under Level/): each lies on one tile's footprint, with
## a meter to spare for its sloped rim, and is inside the playable map. Their plants are cabbage
## heads and corn stalks, not the original field's sunflowers, and stand on the soil: none floats
## above it, none is sunk deeper than SUNK.
func _south_fields(r: GameTestRunner, farm: Node3D, zones: FarmZones) -> void:
var soil: Array[Rect2] = []
var soil_bodies: Array[RID] = []
for tile in farm.get_node("Level").get_children():
var tile_name := String(tile.name)
if not (tile_name.begins_with("ground_008") or tile_name.begins_with("ground_011")):
continue
var a := _footprint(tile as Node3D)
soil.append(Rect2(a.position.x, a.position.z, a.size.x, a.size.z))
for body in tile.find_children("*", "StaticBody3D", true, false):
soil_bodies.append((body as StaticBody3D).get_rid())
var space := farm.get_world_3d().direct_space_state
for crop: String in FIELD_PLANTS:
var field := _field_of(zones, crop)
r.check(field != null, "there is a %s field" % crop)
if field == null:
continue
var rect := field.rect()
r.check(soil.any(func(s: Rect2) -> bool: return s.grow(-1.0).encloses(rect)) and zones.playable.encloses(rect),
"the %s (%s) lies on the plowed soil, inside the playable map" % [field.display_name, rect])
var want: Array = FIELD_PLANTS[crop].map(func(n: String) -> String: return PLANTS % n)
var wrong: Array[String] = []
var sunflowers := 0
var plants := 0
var lowest := INF
var highest := -INF
for u in _units_of(field):
for plant in u.get_children():
plants += 1
var path := (plant as Node).scene_file_path
if path not in want:
wrong.append("%s/%s" % [u.unit_id, plant.name])
if SUNFLOWER_PLANTS.any(func(n: String) -> bool: return path == PLANTS % n):
sunflowers += 1
var at := (plant as Node3D).global_position
var ground := _soil_height(space, soil_bodies, at)
lowest = minf(lowest, at.y - ground)
highest = maxf(highest, at.y - ground)
r.check(plants > 0 and wrong.is_empty() and sunflowers == 0, "the %s's %d plants are %s, none a sunflower (%s)"
% [field.display_name, plants, " / ".join(want.map(func(p: String) -> String: return p.get_file().get_basename())), wrong.slice(0, 4)])
r.check(lowest >= -SUNK and highest <= 0.01, "the %s's plants stand on the soil (base %.2f..%.2f m from it)" % [field.display_name, lowest, highest])
## The soil's height under a point (a ray down that skips everything but the soil tiles), or INF.
func _soil_height(space: PhysicsDirectSpaceState3D, soil_bodies: Array[RID], at: Vector3) -> float:
var skip: Array[RID] = []
for attempt in 8:
var q := PhysicsRayQueryParameters3D.create(Vector3(at.x, 6.0, at.z), Vector3(at.x, -3.0, at.z))
q.exclude = skip
var hit := space.intersect_ray(q)
if hit.is_empty():
break
if hit["rid"] in soil_bodies:
return (hit["position"] as Vector3).y
skip.append(hit["rid"])
return INF
## The world-space box around every mesh under a node.
static func _footprint(node: Node3D) -> AABB:
var box := AABB()
var first := true
for mi in node.find_children("*", "MeshInstance3D", true, false):
var m := mi as MeshInstance3D
if m.mesh == null:
continue
var a := m.global_transform * m.mesh.get_aabb()
box = a if first else box.merge(a)
first = false
return box
## The crop growing in a crop field ("sunflower", "lettuce", "corn"), or "" for other zones.
static func _crop_of(zone: FarmZone) -> String:
if zone.kind != FarmZone.Kind.CROP_FIELD:
return ""
var units := _units_of(zone)
return units[0].crop if units.size() > 0 else ""
static func _units_of(zone: FarmZone) -> Array[CropUnit]:
var out: Array[CropUnit] = []
for node in zone.find_children("*", "Node3D", true, false):
if node is CropUnit:
out.append(node)
return out
static func _field_of(zones: FarmZones, crop: String) -> FarmZone:
for z in zones.zones_of(FarmZone.Kind.CROP_FIELD):
if _crop_of(z) == crop:
return z
return null
func _markers(r: GameTestRunner, zones: FarmZones) -> void: func _markers(r: GameTestRunner, zones: FarmZones) -> void:
var map := zones.playable var map := zones.playable
var gaps := zones.gaps() var gaps := zones.gaps()
@ -108,19 +230,26 @@ func _markers(r: GameTestRunner, zones: FarmZones) -> void:
on_edge = on_edge and FarmZones.nearest_on_outline(edge, p).distance_to(p) < 1e-3 on_edge = on_edge and FarmZones.nearest_on_outline(edge, p).distance_to(p) < 1e-3
r.check(on_edge and zones.edge_point(0.0, cfg.spawn_margin).is_equal_approx(edge.position) r.check(on_edge and zones.edge_point(0.0, cfg.spawn_margin).is_equal_approx(edge.position)
and zones.edge_point(0.5, cfg.spawn_margin).is_equal_approx(edge.end), "edge_point walks the farm's edge, %.0f m out" % cfg.spawn_margin) and zones.edge_point(0.5, cfg.spawn_margin).is_equal_approx(edge.end), "edge_point walks the farm's edge, %.0f m out" % cfg.spawn_margin)
var lettuce := _field_of(zones, "lettuce").global_position
var corn := _field_of(zones, "corn").global_position
var names := [zones.side_of(Vector2(17.0, -48.0)), zones.side_of(Vector2(50.0, -40.0)), zones.side_of(Vector2(-16.0, -15.0)), var names := [zones.side_of(Vector2(17.0, -48.0)), zones.side_of(Vector2(50.0, -40.0)), zones.side_of(Vector2(-16.0, -15.0)),
zones.side_of(Vector2(31.0, 18.0)), zones.side_of(map.get_center())] zones.side_of(Vector2(corn.x, corn.z)), zones.side_of(Vector2(lettuce.x, lettuce.z)), zones.side_of(map.get_center())]
r.check(names == ["north", "north-east", "west", "south-east", ""], "the farm's sides are named by thirds: %s" % [names]) r.check(names == ["north", "north-east", "west", "south-east", "south-west", ""],
"the farm's sides are named by thirds (the corn field south-east, the lettuce field south-west): %s" % [names])
## What's left of the perimeter fence (the north and east sides) has no holes except its gaps, and ## What's left of the perimeter fence (the north side, and the east side down to the original map's
## every gap is open; the south and west sides are open ground. ## south-east corner) has no holes except its gaps, and every gap is open; the south and west
## sides are open ground, and so is the east side south of the fence (#20: the map reaches 20 m
## further south there, with no fence).
func _fence(r: GameTestRunner, zones: FarmZones, nav: FarmNavigation) -> void: func _fence(r: GameTestRunner, zones: FarmZones, nav: FarmNavigation) -> void:
var map := zones.playable var map := zones.playable
var gaps := zones.gaps() var gaps := zones.gaps()
var fence_end := _footprint(zones.get_node("Perimeter/Fence") as Node3D).end.z
var corners := [map.position, Vector2(map.end.x, map.position.y), map.end, Vector2(map.position.x, map.end.y)] var corners := [map.position, Vector2(map.end.x, map.position.y), map.end, Vector2(map.position.x, map.end.y)]
var holes: Array[Vector2] = [] var holes: Array[Vector2] = []
var free_share: Array[float] = [] var free_share: Array[float] = []
var east_open := Vector2i.ZERO # free, all: the east side south of the fence
for side in 4: # north, east, south, west for side in 4: # north, east, south, west
var a: Vector2 = corners[side] var a: Vector2 = corners[side]
var b: Vector2 = corners[(side + 1) % 4] var b: Vector2 = corners[(side + 1) % 4]
@ -128,15 +257,22 @@ func _fence(r: GameTestRunner, zones: FarmZones, nav: FarmNavigation) -> void:
var free := 0 var free := 0
for k in steps + 1: for k in steps + 1:
var p := a.lerp(b, k / float(steps)) var p := a.lerp(b, k / float(steps))
var past_fence := side == 1 and p.y > fence_end + CELL
east_open.y += 1 if past_fence else 0
if not nav.is_free(nav.cell_of(p.x, p.y)): if not nav.is_free(nav.cell_of(p.x, p.y)):
continue continue
free += 1 free += 1
if side < 2 and not gaps.any(func(m: FarmMarker) -> bool: if past_fence:
east_open.x += 1
elif side < 2 and not gaps.any(func(m: FarmMarker) -> bool:
return Vector2(m.global_position.x, m.global_position.z).distance_to(p) < 4.5): return Vector2(m.global_position.x, m.global_position.z).distance_to(p) < 4.5):
holes.append(p) holes.append(p)
free_share.append(free / float(steps + 1)) free_share.append(free / float(steps + 1))
r.check(holes.is_empty(), "the north and east fence has no holes outside its gaps %s" % [holes.slice(0, 5)]) r.check(holes.is_empty(), "the north and east fence has no holes outside its gaps %s" % [holes.slice(0, 5)])
r.check(free_share[2] > 0.9 and free_share[3] > 0.5, "the south and west sides are open (%.0f%% and %.0f%% free)" % [free_share[2] * 100.0, free_share[3] * 100.0]) var east_share := east_open.x / float(maxi(east_open.y, 1))
r.check(free_share[2] > 0.9 and free_share[3] > 0.5 and east_open.y > 0 and east_share > 0.9,
"the south and west sides are open (%.0f%% and %.0f%% free), and the east side south of the fence (z %.0f..%.0f, %.0f%% free)"
% [free_share[2] * 100.0, free_share[3] * 100.0, fence_end, map.end.y, east_share * 100.0])
for m in gaps: for m in gaps:
var g := Vector2(m.global_position.x, m.global_position.z) var g := Vector2(m.global_position.x, m.global_position.z)
var edge := Vector2(clampf(g.x, map.position.x, map.end.x), clampf(g.y, map.position.y, map.end.y)) var edge := Vector2(clampf(g.x, map.position.x, map.end.x), clampf(g.y, map.position.y, map.end.y))
@ -218,8 +354,9 @@ func _travel_times(r: GameTestRunner, farm: Node3D, zones: FarmZones) -> void:
rule += "---|" rule += "---|"
r.info(header) r.info(header)
r.info(rule) r.info(rule)
var worst := 0.0 var later := all.map(func(z: FarmZone) -> bool: return _crop_of(z) in FIELD_PLANTS)
var worst_pair := "" var worst := [0.0, 0.0] # among the original zones; pairs with a later field
var worst_pair := ["", ""]
for i in all.size(): for i in all.size():
var field := nav.distance_field(PackedInt32Array([anchors[i]])) var field := nav.distance_field(PackedInt32Array([anchors[i]]))
var row := "| **%s** |" % all[i].display_name var row := "| **%s** |" % all[i].display_name
@ -228,11 +365,14 @@ func _travel_times(r: GameTestRunner, farm: Node3D, zones: FarmZones) -> void:
r.check(cost < FarmNavigation.UNREACHABLE, "the scarecrow can walk from %s to %s" % [all[i].display_name, all[j].display_name]) r.check(cost < FarmNavigation.UNREACHABLE, "the scarecrow can walk from %s to %s" % [all[i].display_name, all[j].display_name])
var seconds := nav.meters(cost) / RUN_SPEED var seconds := nav.meters(cost) / RUN_SPEED
row += " — |" if i == j else " %.1f s |" % seconds row += " — |" if i == j else " %.1f s |" % seconds
if seconds > worst: var k := 1 if later[i] or later[j] else 0
worst = seconds if seconds > worst[k]:
worst_pair = "%s -> %s" % [all[i].display_name, all[j].display_name] worst[k] = seconds
worst_pair[k] = "%s -> %s" % [all[i].display_name, all[j].display_name]
r.info(row) r.info(row)
r.check(worst <= MAX_TRAVEL, "no key area is more than %.0f s from another (worst %.1f s: %s)" % [MAX_TRAVEL, worst, worst_pair]) r.check(worst[0] <= MAX_TRAVEL, "no key area is more than %.0f s from another (worst %.1f s: %s)" % [MAX_TRAVEL, worst[0], worst_pair[0]])
r.check(worst[1] <= MAX_TRAVEL_SOUTH_FIELDS, "the later crop fields, at the map's south end, are at most %.0f s from any key area (worst %.1f s: %s)"
% [MAX_TRAVEL_SOUTH_FIELDS, worst[1], worst_pair[1]])
func _banner(r: GameTestRunner, farm: Node3D, zones: FarmZones) -> void: func _banner(r: GameTestRunner, farm: Node3D, zones: FarmZones) -> void:

View file

@ -32,9 +32,14 @@ func run(r: GameTestRunner) -> void:
r.check(sim.loot.unit_count == 50 and sim.loot.count(S.HOME, LootSystem.Category.CROP) == 30 and sim.campaign.state.crops == 30 r.check(sim.loot.unit_count == 50 and sim.loot.count(S.HOME, LootSystem.Category.CROP) == 30 and sim.campaign.state.crops == 30
and sim.loot.count(S.DORMANT, LootSystem.Category.CROP) == 20, and sim.loot.count(S.DORMANT, LootSystem.Category.CROP) == 20,
"30 crop units start at home, 20 more dormant in the two later fields (#13)") "30 crop units start at home, 20 more dormant in the two later fields (#13)")
var edge_cells := [Vector2(-16.0, -6.0), Vector2(20.0, 18.0), Vector2(50.0, 0.0), Vector2(-16.0, 10.0)].filter(func(p: Vector2) -> bool: # #20: the map reaches z 35 now, so its south edge (3 m out) is at z 38; z 18 is inside the map.
var edge_cells := [Vector2(-16.0, -6.0), Vector2(20.0, 38.0), Vector2(50.0, 0.0), Vector2(-16.0, 10.0)].filter(func(p: Vector2) -> bool:
return sim.escape_field[sim.nav.cell_of(p.x, p.y)] == 0) return sim.escape_field[sim.nav.cell_of(p.x, p.y)] == 0)
r.check(edge_cells.size() == 4 and sim.escape_field[sim.nav.cell_of(10.0, -8.0)] > 0, "the farm's edge, all around, is where carriers escape") r.check(edge_cells.size() == 4 and sim.escape_field[sim.nav.cell_of(10.0, -8.0)] > 0, "the farm's edge, all around, is where carriers escape")
r.check(sim.escape_field[sim.nav.cell_of(20.0, 18.0)] > 0, "(20, 18), where the south edge used to be, is inside the map now")
# #20: a carried or dropped crop shows the plant of its own field.
var tokens := [1, 31, 41].map(func(id: int) -> String: return sim.loot._tokens[id].scene_file_path.get_file().get_basename())
r.check(tokens == ["plant_007", "plant_004", "plant_001"], "crop tokens match their crop: sunflower, cabbage, corn (%s)" % [tokens])
_steal_and_drop(r, sim, player) _steal_and_drop(r, sim, player)
_escape(r, sim) _escape(r, sim)