Randoloot/tests/levels/surface_poi_counts_test.gd
2026-10-19 22:58:37 +02:00

45 lines
2.3 KiB
GDScript

extends Node
const GENERATOR := preload("res://scripts/planets/surface_generator.gd")
const SCENERY := preload("res://scripts/planets/surface_scenery.gd")
func _ready() -> void:
var extra_ruins := 0
var observed_totals := {}
for index in 64:
var profile: Dictionary = preload("res://scripts/planets/planet_profiles.gd").generate(711,index,"Test")
var data: Dictionary = GENERATOR.generate(500+index,profile)
var counts := {"warehouse":0,"village":0,"cave":0,"ruins":0,"deposit":0}
for poi in data.pois: counts[poi.kind] = int(counts.get(poi.kind, 0)) + 1
for poi in data.pois:
if poi.kind != "cave": continue
assert(poi.has("mountain_position"))
assert(is_equal_approx(poi.position.distance_to(poi.mountain_position), 86.0))
assert(data.mountains.any(func(m): return m.get("cave_anchor",false) and m.position == poi.mountain_position))
for other in data.pois:
if other.id != poi.id: assert(other.position.distance_to(poi.position) >= 420)
assert(counts.warehouse == 1 and counts.village == 1 and counts.ruins in [1,2])
assert(counts.deposit >= 2 and counts.cave >= 2)
var natural_count: int = counts.deposit + counts.cave
assert(natural_count >= 5 and natural_count <= 10)
observed_totals[natural_count] = true
assert(data.events.size() == 1 and data.events[0].position.is_finite())
assert(data.events[0].position.length() > 300)
extra_ruins += int(counts.ruins == 2)
if index == 0:
var repeated: Dictionary = GENERATOR.generate(500,profile)
assert(repeated.pois == data.pois and repeated.events == data.events)
# Most maps have one of each, with some maps containing a second.
assert(extra_ruins > 4 and extra_ruins < 30)
assert(observed_totals.size() == 6)
# No flat ground can disable the guaranteed question-mark event.
var fallback := {"seed":987,"heights":PackedFloat32Array(),"trees":[],"rocks":[],"mountains":[],"pois":[]}
fallback.heights.resize(96*96)
fallback.heights.fill(0.0)
var rng := RandomNumberGenerator.new()
rng.seed = 987
SCENERY.generate(fallback,rng)
assert(fallback.events.size() == 1 and fallback.events[0].position.is_finite())
assert(fallback.events[0].position.length() > 400)
print("SURFACE POI COUNTS PASS: 64 maps, ruins 1..2, 5..10 caves/deposits combined, both kinds at least twice, warehouse/village once, one guaranteed event, deterministic layout; extra ruins=",extra_ruins)
get_tree().quit()