extends SceneTree ## Terrain edge check: there must be no ground below the inland waterline in the ## band just inside the boundary wall. Ground like that shows up as inland water ## hanging over a drop (the lake water surface stops at the wall) and makes pits ## the player can fall into and not climb out of. ## ## Run: godot --headless --path . --script res://tests/test_terrain_edges.gd const BAND := 10.0 # metres inside the wall to check func _initialize() -> void: var terrain: Node3D = load("res://scripts/world/terrain.gd").new() root.add_child(terrain) # builds in _ready _run.call_deferred(terrain) func _run(terrain: Node3D) -> void: 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) if h < terrain.water_level + 0.2: bad += 1 if h < worst: worst = h worst_at = Vector2(x, z) z += 1.0 x += 1.0 if bad > 0: print("FAIL: %d samples near the wall are below the waterline; lowest %.1f m at (%.0f, %.0f), sea weight %.2f" % [ bad, worst, worst_at.x, worst_at.y, terrain.sea_weight(worst_at.x, worst_at.y)]) else: print("PASS: ground near the wall stays above the waterline") quit(1 if bad > 0 else 0)