updates
This commit is contained in:
parent
276d43613d
commit
4298caf5cb
552 changed files with 42990 additions and 776 deletions
|
|
@ -1,8 +1,10 @@
|
|||
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 perimeter markers, a perimeter fence without holes
|
||||
## except its gaps, ground navigation from every gap to every zone, scarecrow-only bounds,
|
||||
## zone-to-zone travel times (printed as the table kept in game/LAYOUT.md), and the zone banner.
|
||||
## 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.
|
||||
|
||||
const RUN_SPEED := 5.0 # PlayerCharacter.run_speed
|
||||
const MAX_TRAVEL := 12.0
|
||||
|
|
@ -73,52 +75,84 @@ func _crops(r: GameTestRunner, zones: FarmZones) -> void:
|
|||
|
||||
func _markers(r: GameTestRunner, zones: FarmZones) -> void:
|
||||
var map := zones.playable
|
||||
var gaps := zones.markers(FarmMarker.Kind.GAP)
|
||||
r.check(gaps.size() == 6, "6 perimeter gaps (got %d)" % gaps.size())
|
||||
var gaps := zones.gaps()
|
||||
r.check(gaps.size() == 3, "3 gaps in what's left of the perimeter fence (got %d)" % gaps.size())
|
||||
for m in gaps:
|
||||
var p := Vector2(m.global_position.x, m.global_position.z)
|
||||
r.check(not map.has_point(p) and map.grow(4.0).has_point(p), "%s sits just outside the perimeter" % m.name)
|
||||
var crows := zones.markers(FarmMarker.Kind.CROW)
|
||||
r.check(crows.size() == 4, "4 crow approach directions (got %d)" % crows.size())
|
||||
for m in crows:
|
||||
r.check(not map.grow(4.0).has_point(Vector2(m.global_position.x, m.global_position.z)), "%s is well outside the fence" % m.name)
|
||||
var cfg := load("res://game/resources/game_config.tres") as GameConfig
|
||||
var edge := zones.edge(cfg.spawn_margin)
|
||||
var on_edge := true
|
||||
for k in 40:
|
||||
var p := zones.edge_point(k / 40.0 + 0.01, cfg.spawn_margin)
|
||||
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 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])
|
||||
|
||||
|
||||
## Every free cell on the fence line is part of a gap (near a gap marker), and every gap is open.
|
||||
## 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.
|
||||
func _fence(r: GameTestRunner, zones: FarmZones, nav: FarmNavigation) -> void:
|
||||
var map := zones.playable
|
||||
var gaps := zones.markers(FarmMarker.Kind.GAP)
|
||||
var gaps := zones.gaps()
|
||||
var corners := [map.position, Vector2(map.end.x, map.position.y), map.end, Vector2(map.position.x, map.end.y)]
|
||||
var holes: Array[Vector2] = []
|
||||
for side in 4:
|
||||
var free_share: Array[float] = []
|
||||
for side in 4: # north, east, south, west
|
||||
var a: Vector2 = corners[side]
|
||||
var b: Vector2 = corners[(side + 1) % 4]
|
||||
var steps := ceili(a.distance_to(b) / (CELL * 0.5))
|
||||
var free := 0
|
||||
for k in steps + 1:
|
||||
var p := a.lerp(b, k / float(steps))
|
||||
if nav.is_free(nav.cell_of(p.x, p.y)) and not gaps.any(func(m: FarmMarker) -> bool:
|
||||
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:
|
||||
return Vector2(m.global_position.x, m.global_position.z).distance_to(p) < 4.5):
|
||||
holes.append(p)
|
||||
r.check(holes.is_empty(), "the perimeter fence has no holes outside its gaps %s" % [holes.slice(0, 5)])
|
||||
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])
|
||||
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))
|
||||
r.check(nav.is_free(nav.cell_of(edge.x, edge.y)), "%s is open for ground enemies" % m.name)
|
||||
|
||||
|
||||
## Ground enemies arrive anywhere on the edge with a route in (as FarmSim picks them: a route to
|
||||
## the pen) and can walk from there to every zone; the lengths printed are from the middle of each
|
||||
## side (the table in game/LAYOUT.md).
|
||||
func _enemy_routes(r: GameTestRunner, zones: FarmZones, nav: FarmNavigation) -> void:
|
||||
var gaps := zones.markers(FarmMarker.Kind.GAP)
|
||||
var cfg := load("res://game/resources/game_config.tres") as GameConfig
|
||||
var edge := zones.edge(cfg.spawn_margin)
|
||||
var ring := nav.free_cells_on_outline(edge, CELL * 0.75)
|
||||
var pen := nav.distance_field(nav.free_cells_in(zones.zone(FarmZone.Kind.ANIMAL_PEN).rect().grow(-1.0)))
|
||||
var spawns := PackedInt32Array()
|
||||
for c in ring:
|
||||
if pen[c] < FarmNavigation.UNREACHABLE:
|
||||
spawns.append(c)
|
||||
r.check(spawns.size() > ring.size() * 0.9, "enemies can arrive on nearly all of the farm's edge (%d of %d free cells)" % [spawns.size(), ring.size()])
|
||||
var mid := edge.get_center()
|
||||
var middles := {"north": Vector2(mid.x, edge.position.y), "east": Vector2(edge.end.x, mid.y), "south": Vector2(mid.x, edge.end.y), "west": Vector2(edge.position.x, mid.y)}
|
||||
for zone in zones.zones():
|
||||
var goal := nav.free_cells_in(zone.rect())
|
||||
r.check(goal.size() > 0, "%s has walkable ground (%d cells)" % [zone.display_name, goal.size()])
|
||||
var field := nav.distance_field(goal)
|
||||
var cut_off := 0
|
||||
for s in spawns:
|
||||
if field[s] >= FarmNavigation.UNREACHABLE:
|
||||
cut_off += 1
|
||||
r.check(cut_off == 0, "ground enemies can walk from anywhere on the edge to the %s and back (%d cells can't)" % [zone.display_name, cut_off])
|
||||
var lengths: Array[String] = []
|
||||
for m in gaps:
|
||||
var c := nav.nearest_free(nav.cell_of(m.global_position.x, m.global_position.z))
|
||||
var reachable := c >= 0 and field[c] < FarmNavigation.UNREACHABLE
|
||||
r.check(reachable, "ground enemies can walk from %s to the %s and back" % [m.name, zone.display_name])
|
||||
lengths.append("%.0f" % nav.meters(field[c]) if reachable else "-")
|
||||
r.info("%-12s from gaps (m): %s" % [zone.display_name, ", ".join(lengths)])
|
||||
for side: String in middles:
|
||||
var at: Vector2 = middles[side]
|
||||
var m := nav.nearest_free(nav.cell_of(at.x, at.y))
|
||||
lengths.append("%s %.0f" % [side, nav.meters(field[m])] if m >= 0 and field[m] < FarmNavigation.UNREACHABLE else "%s -" % side)
|
||||
r.info("%-12s from the edge (m): %s" % [zone.display_name, ", ".join(lengths)])
|
||||
|
||||
|
||||
func _scarecrow(r: GameTestRunner, farm: Node3D, zones: FarmZones) -> void:
|
||||
|
|
@ -127,16 +161,26 @@ func _scarecrow(r: GameTestRunner, farm: Node3D, zones: FarmZones) -> void:
|
|||
r.check(zones.playable.has_point(Vector2(player.global_position.x, player.global_position.z)), "the scarecrow starts inside the map")
|
||||
r.check(bounds.collision_layer == 4 and (player.collision_mask & 4) != 0 and (player.collision_mask & 1) != 0,
|
||||
"PlayerBounds is on the player_bounds layer, which only the scarecrow collides with")
|
||||
# Stand in each gap and try to walk out: the invisible wall stops the scarecrow.
|
||||
# Stand in each gap and walk out: nothing stops the scarecrow (the gathering areas outside).
|
||||
var start := player.global_transform
|
||||
for m in zones.markers(FarmMarker.Kind.GAP):
|
||||
for m in zones.gaps():
|
||||
var g := Vector2(m.global_position.x, m.global_position.z)
|
||||
var map := zones.playable
|
||||
var edge := Vector2(clampf(g.x, map.position.x, map.end.x), clampf(g.y, map.position.y, map.end.y))
|
||||
var out := (g - edge).normalized()
|
||||
player.global_position = Vector3(edge.x - out.x * 1.0, 0.3, edge.y - out.y * 1.0)
|
||||
player.global_position = Vector3(edge.x - out.x * 1.0, 0.6, edge.y - out.y * 1.0) # above the driveway's road
|
||||
var hit := player.move_and_collide(Vector3(out.x, 0.0, out.y) * 3.0, true)
|
||||
r.check(hit != null, "the scarecrow can't walk out through %s" % m.name)
|
||||
r.check(hit == null, "the scarecrow can walk out through %s" % m.name)
|
||||
# ...but not past the old farm's outer fences: the invisible walls are there now.
|
||||
var roam := zones.roam
|
||||
var sides := {"north": [Vector2(-20.0, roam.position.y + 1.0), Vector2(0, -1)], "south": [Vector2(5.0, roam.end.y - 1.0), Vector2(0, 1)],
|
||||
"west": [Vector2(roam.position.x + 1.0, 0.0), Vector2(-1, 0)], "east": [Vector2(roam.end.x - 1.0, -30.0), Vector2(1, 0)]}
|
||||
for side: String in sides:
|
||||
var at: Vector2 = sides[side][0]
|
||||
var dir: Vector2 = sides[side][1]
|
||||
player.global_position = Vector3(at.x, 0.3, at.y)
|
||||
var hit := player.move_and_collide(Vector3(dir.x, 0.0, dir.y) * 3.0, true)
|
||||
r.check(hit != null, "the scarecrow can't go past the %s edge of the roaming area" % side)
|
||||
player.global_transform = start
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue