110 lines
5.0 KiB
GDScript
110 lines
5.0 KiB
GDScript
extends Node
|
|
const PROFILES := preload("res://scripts/planets/planet_profiles.gd")
|
|
const GEAR := preload("res://scripts/planets/captain_equipment.gd")
|
|
const EVENTS := preload("res://scripts/planets/surface_events.gd")
|
|
const REWARDS := preload("res://scripts/planets/planet_rewards.gd")
|
|
var captain: Resource
|
|
|
|
func set_gear(levels: Array) -> void:
|
|
for index in 3:
|
|
captain.gear_items[index].level = int(levels[index])
|
|
captain.gear_slots[GEAR.KINDS[index]] = index+1
|
|
|
|
func profile_for(total: float) -> Dictionary:
|
|
var fraction := total/300.0
|
|
return {"id":"threat-test","name":"Test zagrożeń","easy":total == 0.0,"seed":1234,"oxygen":80.0*(1.0-fraction),"temperature":40.0+60.0*fraction,"flora":50.0*fraction,"difficulty":fraction,"landing_damage":5}
|
|
|
|
func expect_chances(profile: Dictionary, expected: Array) -> void:
|
|
for stage in 3:
|
|
assert(is_equal_approx(PROFILES.success_chance(profile,captain,stage),float(expected[stage])/100.0))
|
|
|
|
func _ready() -> void:
|
|
captain = preload("res://scripts/captain/captain_progress.gd").new()
|
|
set_gear([0,0,0])
|
|
var safe := profile_for(0)
|
|
safe.temperature = 30
|
|
safe.oxygen = 98
|
|
assert(PROFILES.global_threat(safe,captain) == 0)
|
|
expect_chances(safe,[90,70,40])
|
|
assert(is_equal_approx(PROFILES.average_success_chance(safe,captain),2.0/3.0))
|
|
var extreme := profile_for(300)
|
|
assert(PROFILES.global_threat(extreme,captain) == 300)
|
|
expect_chances(extreme,[15,5,0])
|
|
expect_chances(profile_for(75),[52.5,37.5,20])
|
|
expect_chances(profile_for(150),[15,5,0])
|
|
expect_chances(profile_for(151),[15,5,0])
|
|
var cold := extreme.duplicate()
|
|
cold.temperature = -50
|
|
assert(PROFILES.global_threat(cold,captain) == 300)
|
|
for temperature in [-10,0,30,40]:
|
|
var normal := safe.duplicate()
|
|
normal.temperature = temperature
|
|
assert(PROFILES.global_threat(normal,captain) == 0)
|
|
var previous := 1.0
|
|
for index in 301:
|
|
var at := profile_for(float(index))
|
|
var raw := PROFILES.threat_report(at,captain)
|
|
assert(raw.raw_total >= 0 and raw.raw_total <= 300.0001)
|
|
var chance := PROFILES.success_chance(at,captain,0)
|
|
assert(chance <= previous+0.000001)
|
|
previous = chance
|
|
set_gear([1,1,1])
|
|
assert(PROFILES.global_threat(extreme,captain) == 294)
|
|
set_gear([25,25,25])
|
|
assert(PROFILES.global_threat(extreme,captain) == 150)
|
|
set_gear([26,26,26])
|
|
assert(PROFILES.global_threat(extreme,captain) == 144)
|
|
expect_chances(extreme,[18,7.6,1.6])
|
|
set_gear([50,0,0])
|
|
var report := PROFILES.threat_report(extreme,captain)
|
|
assert(report.effective.oxygen == 0 and report.effective.temperature == 100 and report.effective.biology == 100)
|
|
assert(report.total == 200)
|
|
set_gear([0,50,0])
|
|
report = PROFILES.threat_report(extreme,captain)
|
|
assert(report.effective.temperature == 0 and report.total == 200)
|
|
set_gear([0,0,50])
|
|
report = PROFILES.threat_report(extreme,captain)
|
|
assert(report.effective.biology == 0 and report.total == 200)
|
|
set_gear([50,50,50])
|
|
assert(PROFILES.global_threat(extreme,captain) == 0)
|
|
expect_chances(extreme,[90,70,40])
|
|
set_gear([100,100,100])
|
|
expect_chances(extreme,[90,70,40])
|
|
assert(PROFILES.threat_report(extreme,captain).raw_total == 300)
|
|
assert(REWARDS.material_multiplier(extreme) == 3)
|
|
assert(REWARDS.module_bonus_range(extreme) == Vector2i(2,10))
|
|
# Equipment changes effective odds, never the underlying planet rewards.
|
|
set_gear([0,0,0])
|
|
var state: Resource = captain.expedition
|
|
assert(state.begin_visit(extreme))
|
|
state.lander_hp = 100
|
|
captain.parts = 100
|
|
var rng := RandomNumberGenerator.new()
|
|
rng.seed = 45
|
|
var rng_before := rng.state
|
|
var poi := {"kind":"ruins","stage":2,"complete":false}
|
|
var result: Dictionary = state.resolve_poi(captain,poi,rng)
|
|
assert(result.blocked and result.chance == 0 and not poi.complete)
|
|
assert(state.lander_hp == 100 and rng.state == rng_before)
|
|
var evacuation := {"kind":"evacuation","seed":1234,"complete":false}
|
|
EVENTS.prepare(evacuation,captain,state)
|
|
evacuation.stage = 2
|
|
assert(EVENTS.chance(evacuation,captain,state) == 0)
|
|
var balance: float = captain.parts
|
|
result = EVENTS.resolve(evacuation,"help",captain,state)
|
|
assert(result.blocked and captain.parts == balance and not evacuation.complete)
|
|
assert(is_equal_approx(EVENTS.chance({"kind":"rescue"},captain,state),0.15))
|
|
assert(is_equal_approx(EVENTS.chance({"kind":"prototype"},captain,state),0.05))
|
|
set_gear([50,50,50])
|
|
assert(is_equal_approx(EVENTS.chance(evacuation,captain,state),0.40))
|
|
assert(is_equal_approx(EVENTS.chance({"kind":"rescue"},captain,state),0.90))
|
|
var scan := PROFILES.scan_description(extreme,captain)
|
|
assert(scan.contains("ŚREDNIA SZANSA POI: 66.7%") and scan.contains("90.0% / 70.0% / 40.0%"))
|
|
assert(scan.contains("Bez sprzętu: 300.0%"))
|
|
for index in 1000:
|
|
var generated := PROFILES.generate(99,index,"Biom")
|
|
var raw := PROFILES.raw_threats(generated)
|
|
assert(is_equal_approx(float(generated.difficulty),(float(raw.oxygen)+float(raw.temperature)+float(raw.biology))/300.0))
|
|
print("PLANET THREATS PASS: 0..300 total, three independent protections, 2 pp/level, L50 immunity, exact POI curves, 150 threshold, zero-chance guards, event risk, scan average, raw reward difficulty")
|
|
get_tree().quit()
|