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:
commit
11d19d874a
10 changed files with 676 additions and 508 deletions
|
|
@ -26,14 +26,15 @@ const SUITES := [
|
|||
]
|
||||
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:
|
||||
## 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 := {
|
||||
"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.
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,16 +1,27 @@
|
|||
extends RefCounted
|
||||
## The playable farm: every zone exists once inside the 60 x 60 m map without overlapping,
|
||||
## lookups by position, the crop units, the farm's edge (where enemies arrive) and the gaps in
|
||||
## what's left of the perimeter fence (the north and east sides, without holes except their gaps;
|
||||
## the south and west are open), 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.
|
||||
## The playable farm: every zone exists once inside the 60 x 80 m map without overlapping (the
|
||||
## outside zones stay off it), lookups by position, the crop units, the later crop fields on the
|
||||
## plowed soil south of the original map with their own plants, the farm's edge (where enemies
|
||||
## arrive) and the gaps in what's left of the perimeter fence (the north and east sides, without
|
||||
## holes except their gaps; the south, the west, and the east side south of the fence are open),
|
||||
## 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
|
||||
## #13: the two new south-west crop fields are a legitimate corner of the map (user-decided
|
||||
## placement), and the farthest pair (a new field to the Scrap Heap, clear across the map) is a
|
||||
## little past the old 12 s bar; raised to fit it with a little room.
|
||||
const MAX_TRAVEL := 13.0
|
||||
## The layout rule: no key area more than 12 s from another. It holds for the farm's original
|
||||
## zones.
|
||||
const MAX_TRAVEL := 12.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 SCARECROW_RADIUS := 0.4
|
||||
const CELL := 0.5
|
||||
|
|
@ -26,10 +37,12 @@ func run(r: GameTestRunner) -> void:
|
|||
if zones == null:
|
||||
return
|
||||
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)
|
||||
_crops(r, zones)
|
||||
_south_fields(r, farm, zones)
|
||||
_markers(r, zones)
|
||||
var nav := FarmNavigation.new()
|
||||
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()):
|
||||
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")
|
||||
# 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
|
||||
|
|
@ -93,6 +115,106 @@ func _crops(r: GameTestRunner, zones: FarmZones) -> void:
|
|||
"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:
|
||||
var map := zones.playable
|
||||
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
|
||||
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)
|
||||
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)),
|
||||
zones.side_of(Vector2(31.0, 18.0)), 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])
|
||||
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", "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
|
||||
## every gap is open; the south and west sides are open ground.
|
||||
## What's left of the perimeter fence (the north side, and the east side down to the original map's
|
||||
## 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:
|
||||
var map := zones.playable
|
||||
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 holes: Array[Vector2] = []
|
||||
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
|
||||
var a: Vector2 = corners[side]
|
||||
var b: Vector2 = corners[(side + 1) % 4]
|
||||
|
|
@ -128,15 +257,22 @@ func _fence(r: GameTestRunner, zones: FarmZones, nav: FarmNavigation) -> void:
|
|||
var free := 0
|
||||
for k in steps + 1:
|
||||
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)):
|
||||
continue
|
||||
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):
|
||||
holes.append(p)
|
||||
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(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:
|
||||
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))
|
||||
|
|
@ -218,8 +354,9 @@ func _travel_times(r: GameTestRunner, farm: Node3D, zones: FarmZones) -> void:
|
|||
rule += "---|"
|
||||
r.info(header)
|
||||
r.info(rule)
|
||||
var worst := 0.0
|
||||
var worst_pair := ""
|
||||
var later := all.map(func(z: FarmZone) -> bool: return _crop_of(z) in FIELD_PLANTS)
|
||||
var worst := [0.0, 0.0] # among the original zones; pairs with a later field
|
||||
var worst_pair := ["", ""]
|
||||
for i in all.size():
|
||||
var field := nav.distance_field(PackedInt32Array([anchors[i]]))
|
||||
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])
|
||||
var seconds := nav.meters(cost) / RUN_SPEED
|
||||
row += " — |" if i == j else " %.1f s |" % seconds
|
||||
if seconds > worst:
|
||||
worst = seconds
|
||||
worst_pair = "%s -> %s" % [all[i].display_name, all[j].display_name]
|
||||
var k := 1 if later[i] or later[j] else 0
|
||||
if seconds > worst[k]:
|
||||
worst[k] = seconds
|
||||
worst_pair[k] = "%s -> %s" % [all[i].display_name, all[j].display_name]
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
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)")
|
||||
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)
|
||||
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)
|
||||
_escape(r, sim)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue