Randoloot/tests/levels/surface_poi_counts_test.gd
2026-10-18 14:46:34 +02:00

36 lines
1.7 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_mines := 0
var extra_ruins := 0
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 := {"mine":0,"ruins":0,"deposit":0}
for poi in data.pois: counts[poi.kind] += 1
assert(counts.mine in [1,2] and counts.ruins in [1,2])
assert(counts.deposit == 2)
assert(data.events.size() == 1 and data.events[0].position.is_finite())
assert(data.events[0].position.length() > 300)
extra_mines += int(counts.mine == 2)
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_mines > 4 and extra_mines < 30)
assert(extra_ruins > 4 and extra_ruins < 30)
# 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, mines/ruins 1..2, two deposits, one guaranteed event, deterministic layout, no-flat-ground fallback; extra mines/ruins=",extra_mines,"/",extra_ruins)
get_tree().quit()