Files
Cinderwild/tests/test_terrain_edges.gd
Paul Bailey 4640f5e577 M1a: survival core, pause menu, title screen and save/load
Design: docs/SURVIVAL_DESIGN.md (core loop, systems, architecture, phases).

Survival core (M1a):
- Items/recipes as data (data/*.json) in the addon SDK's define_item /
  define_recipe shape; procedural item meshes and offscreen-rendered icons
- Inventory class (40 slots, hotbar = row 1) shared by player and chests;
  click / right-click split / shift-click quick-move
- Actions autoload: the intent layer (craft, pickup, harvest_hit, place,
  transfer) that validates every change; becomes the RPC surface in M2
- Gathering: ground pickups (sticks, stones, flint); trees chopped with an
  axe fall and leave stumps; boulders mined with a pickaxe shrink per hit
- Crafting screen with station checks (workbench); placement mode with
  green/red ghost, rotation and overlap/slope validation
- Pieces: campfire (light, flames, embers), workbench, chest (16 slots)
- HUD: hotbar, held tool view model with swing, prompts, toasts

Menus and saving:
- ESC pause menu: resume, controls, fullscreen, mouse sensitivity, quit
- Title screen over a flyover of the island: Continue / New World (name +
  seed) / Load World (with delete) / Quit
- Saves autoload: one folder per world under user://worlds, atomic writes
  with a .bak; stores only player changes (player, pieces, chest contents,
  harvested resources, taken pickups) and regenerates the rest from the seed
- Autosave every 2 min, Save & Quit to title/desktop, save on window close

Fixes: UI screens now fill the viewport (were pinned top-left); title
backdrop no longer captures the mouse.

Tests: test_survival_core (31 checks), test_save_load (round trip + slots),
test_terrain_edges now checks 8 seeds for deep pits / unbanked water.
2026-11-04 00:34:46 +00:00

67 lines
2.6 KiB
GDScript

extends SceneTree
## Terrain edge check, for several seeds: in the band just inside the boundary
## wall there must be (1) no water deeper than you can wade out of, and (2) no
## water without a bank, i.e. ground that drops away outward. The inland water
## surface stops at the wall, so unbanked water hangs in the air over the drop.
## This is the bug where the player fell into floating water by the sea cliff.
## Shallow ponds at the foot of the mountains are fine: the slope holds them.
##
## Run: godot --headless --path . --script res://tests/test_terrain_edges.gd
const BAND := 10.0 # metres inside the wall to check
const MAX_EDGE_DEPTH := 1.0 # deepest allowed water near the edge (wadeable)
const BANK_CHECK := 12.0 # how far outward the bank must rise above water
## The original island plus a spread of other seeds: new worlds get random
## seeds, so the edge rule has to hold for any of them.
const SEEDS := [1337, 1, 42, 777, 4242, 9001, 31337, 123456]
func _initialize() -> void:
_all.call_deferred()
func _all() -> void:
var failed := 0
for s in SEEDS:
var terrain: Node3D = load("res://scripts/world/terrain.gd").new()
terrain.noise_seed = s
root.add_child(terrain) # builds in _ready
var bad := _check(terrain)
print("seed %6d: %s" % [s, "ok" if bad == 0 else "%d bad samples" % bad])
if bad > 0:
failed += 1
terrain.free()
print("RESULT: %s (%d/%d seeds clean)" % ["PASS" if failed == 0 else "FAIL", SEEDS.size() - failed, SEEDS.size()])
quit(1 if failed > 0 else 0)
func _check(terrain: Node3D) -> int:
var bad := 0
var worst := INF
var worst_at := Vector2.ZERO
var half: float = terrain.size * 0.5
var x := -half
while x < half:
var z := -half
while z < half:
if terrain.inside_boundary(x, z, 0.0) and not terrain.inside_boundary(x, z, BAND):
var h: float = terrain.sample_height(x, z)
# Hazard 1: a pit too deep to wade out of near the edge.
var too_deep: bool = h < terrain.water_level - MAX_EDGE_DEPTH
# Hazard 2: water that isn't held in by a bank. The inland water
# surface stops at the wall, so wet ground must rise again just
# outward, or the water edge hangs over a drop.
var unbanked := false
if h < terrain.water_level:
var out := Vector2(x, z).normalized() * BANK_CHECK
unbanked = terrain.sample_height(x + out.x, z + out.y) < terrain.water_level
if too_deep or unbanked:
bad += 1
if h < worst:
worst = h
worst_at = Vector2(x, z)
z += 1.0
x += 1.0
if bad > 0:
print(" lowest %.1f m at (%.0f, %.0f), sea weight %.2f" % [
worst, worst_at.x, worst_at.y, terrain.sea_weight(worst_at.x, worst_at.y)])
return bad