Randoloot/tests/mining_network_checks.gd
2026-10-20 19:53:03 +02:00

62 lines
3.6 KiB
GDScript

@tool
extends Node
const NETWORK = preload("res://scripts/planets/mining_network.gd")
func run_checks() -> Dictionary:
var failures: Array[String] = []
var previous := Vector2i.ZERO
for level in range(1, 121):
var bounds := NETWORK.richness_bounds(level)
if bounds.x < previous.x or bounds.y < previous.y: failures.append("Non-monotonic bands")
previous = bounds
for seed_value in 100:
var profile := {"id":"%d:planet:0" % seed_value, "seed":seed_value, "name":"Test", "difficulty":0.5}
var richness := NETWORK.deposit_richness(profile, level)
if richness < bounds.x or richness > bounds.y: failures.append("Out of band")
if NETWORK.build_cost(profile, level) != richness * 10: failures.append("Wrong scaled price")
if richness != NETWORK.deposit_richness(profile, level): failures.append("Rerolled")
var progress = preload("res://scripts/planets/planet_progress.gd").new()
var captain = preload("res://scripts/captain/captain_progress.gd").new()
var profile := {}
for seed_value in 1000:
var candidate := {"id":"%d:planet:0" % seed_value,"seed":seed_value,"name":"Test","difficulty":0.5}
if NETWORK.has_recruit(candidate) and NETWORK.has_deep_deposit(candidate):
profile = candidate
break
if profile.is_empty(): return {"failures":["No fixture planet"]}
var hire_cost := NETWORK.recruitment_cost(NETWORK.recruit(profile))
captain.credits = hire_cost
if NETWORK.hire(progress, captain, profile): failures.append("Hired without cabin")
if captain.credits != hire_cost: failures.append("Charged failed hire")
progress.freighter_rooms["cabin_1"] = "crew_cabin"
captain.credits = hire_cost - 1
if NETWORK.hire(progress, captain, profile): failures.append("Hired without credits")
captain.credits = hire_cost
if not NETWORK.hire(progress, captain, profile): failures.append("Hire failed")
if captain.credits != 0: failures.append("Wrong hire charge")
if NETWORK.hire(progress, captain, profile): failures.append("Duplicate hire")
var station_cost := NETWORK.build_cost(profile, 1)
captain.parts = station_cost - 1
if NETWORK.build(progress, captain, profile, 1): failures.append("Built without parts")
if captain.parts != station_cost-1: failures.append("Charged failed build")
captain.parts = station_cost
if not NETWORK.build(progress, captain, profile, 1): failures.append("Build failed")
if captain.parts != 0: failures.append("Wrong build charge")
if NETWORK.build(progress, captain, profile, 1): failures.append("Duplicate build")
var station: Dictionary = progress.mining_stations[str(profile.id)]
if NETWORK.station_rate(progress, station) != 0: failures.append("Unstaffed production")
var member_id := str(NETWORK.recruit(profile).id)
NETWORK.assign(progress, str(profile.id), member_id)
station.richness = 50
progress.crew[member_id].management = 50
if not is_equal_approx(NETWORK.station_rate(progress, station), 75): failures.append("Rate formula")
var before: float = progress.deuter
NETWORK.advance(progress, 60)
if not is_equal_approx(progress.deuter-before, 75): failures.append("Production")
if int(station.richness) != 50: failures.append("Deposit depleted")
NETWORK.dismiss(progress, member_id)
if NETWORK.station_rate(progress, station) != 0: failures.append("Dismiss production")
var old_profile = preload("res://scripts/planets/planet_profiles.gd").generate(1234, 0, "Legacy")
var old_station := {"id":old_profile.id,"planet_name":"Legacy","system":40}
if NETWORK.station_richness(old_station) != NETWORK.deposit_richness(old_profile,40): failures.append("Legacy migration")
return {"failures":failures,"sample_rolls":12000,"production_example":75,"level_1":NETWORK.richness_bounds(1),"level_120":NETWORK.richness_bounds(120)}