43 lines
1.4 KiB
GDScript
43 lines
1.4 KiB
GDScript
extends SceneTree
|
|
## Every island gets a wolf den: across many seeds the site search finds a
|
|
## spot away from the spawn and the sea.
|
|
## Run: godot --headless --path . --script res://tests/test_den_sites.gd
|
|
|
|
const SEEDS := [777, 4, 1337, 1, 2, 3, 5, 6, 7, 8, 9, 10, 42, 99, 123, 2024, 4242, 9001, 31337, 65535]
|
|
|
|
var _fails := 0
|
|
|
|
func check(cond: bool, what: String) -> void:
|
|
print((" ok " if cond else " FAIL ") + what)
|
|
if not cond:
|
|
_fails += 1
|
|
|
|
func _initialize() -> void:
|
|
_run.call_deferred()
|
|
|
|
func _run() -> void:
|
|
var S: Node = root.get_node("Saves")
|
|
S.root_dir = "user://test_den_sites"
|
|
for seed in SEEDS:
|
|
for w in S.list_worlds():
|
|
S.delete_world(w.id)
|
|
S.current_id = S.create_world("Den %d" % seed, seed)
|
|
var world: Node3D = load("res://scenes/world.tscn").instantiate()
|
|
root.add_child(world)
|
|
for _i in range(3):
|
|
await physics_frame
|
|
var den: Node3D = world.den
|
|
var t: Node3D = world.terrain
|
|
var p: Vector3 = den.position
|
|
var ok: bool = den.found
|
|
if ok:
|
|
ok = Vector2(p.x, p.z).length() >= 50.0 and t.sea_weight(p.x, p.z) <= 0.02
|
|
check(ok, "seed %d has a den (%.0f m from the centre)" % [seed, Vector2(p.x, p.z).length()])
|
|
world.queue_free()
|
|
await physics_frame
|
|
for w in S.list_worlds():
|
|
S.delete_world(w.id)
|
|
DirAccess.remove_absolute(S.root_dir)
|
|
print("RESULT: %s (%d failures)" % ["PASS" if _fails == 0 else "FAIL", _fails])
|
|
quit(1 if _fails > 0 else 0)
|