2026-09-15 23:05:05 +03:00
extends SceneTree
2026-09-30 08:08:27 +03:00
const E = preload ( "res://world/owniverse/math/exact.gd" )
2026-09-15 23:05:05 +03:00
const Clock = preload ( "res://world/owniverse/simulation_time.gd" )
var checks : int = 0
var failures : int = 0
func _initialize () -> void :
call_deferred ( "run" )
func check ( condition : bool , message : String ) -> void :
2026-09-30 08:08:27 +03:00
checks = E . add ( checks , 1 )
if ( not condition ):
failures = E . add ( failures , 1 )
2026-09-15 23:05:05 +03:00
push_error ( message )
func fixture ():
var world = load ( "res://world/owniverse/owniverse.gd" ) . new ()
var global : Node = root . get_node ( "Global" )
for id in global . OwniverseEntities :
var entity = load ( "res://world/owniverse/owniverse_entity.gd" ) . new ( global . OwniverseEntities [ id ])
2026-09-29 20:23:20 +03:00
world . catalog . entities [ id ] = entity
2026-09-30 08:08:27 +03:00
world . state . amount [ id ] = 0
world . state . stats . total_amount [ id ] = 0
if E . ne ( entity . group_as , "" ):
world . state . amount [ entity . group_as ] = 0
world . state . stats . total_amount [ entity . group_as ] = 0
2026-09-29 20:23:20 +03:00
world . catalog . entities [ "N" ] . life_product = {}
world . catalog . entities [ "N" ] . product_per_year_type = "H"
2026-09-30 08:08:27 +03:00
world . catalog . entities [ "N" ] . product_per_year_amount = 10
world . catalog . entities [ "N" ] . auto = 0
world . state . amount . N = 1
2026-09-15 23:05:05 +03:00
return world
func dispose ( world ) -> void :
2026-09-29 20:23:20 +03:00
for entity in world . catalog . entities . values ():
2026-09-15 23:05:05 +03:00
entity . free ()
world . free ()
func run () -> void :
var world = fixture ()
var global : Node = root . get_node ( "Global" )
2026-09-30 08:08:27 +03:00
check ( E . eq ( global . CivilizationRules . size (), 44 ), "Load all ethical civilization stages" )
for row : Dictionary in global . CivilizationRules . values ():
check (( E . eq ( row . ethics . size (), 6 ) or E . eq ( row . span , 0 )), "Every ethical stage has six rules" )
world . state . amount . RD = 12
world . state . amount [ "C0.2" ] = 8
world . state . binds . RD = { "C2.0" : 12 , "C1.9" : 3 }
2026-09-29 20:23:20 +03:00
world . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
check (( E . eq ( world . state . amount [ "C2.0" ], 12 ) and E . eq ( world . state . binds . RD [ "C2.0" ], 0 )), "Old space civilizations detach without loss" )
check ( E . eq ( world . state . binds . RD [ "C1.9" ], 3 ), "Planetary civilizations retain their host" )
check ( E . eq ( world . state . ethics [ "C0.2" ], { "m" : 2 , "l" : 2 , "w" : 1 , "d" : 1 , "c" : 1 , "b" : 1 }), "Migration uses equal ethics and deterministic remainder" )
check ( world . state . ethics [ "C2.0" ] . values () . all ( func ( n ) : return E . eq ( n , 2 )), "Bound civilization ethics count physical population" )
2026-09-15 23:05:05 +03:00
var before : Dictionary = world . state . duplicate ( true )
2026-09-29 20:23:20 +03:00
world . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
check ( E . eq ( world . state , before ), "Repeated initialization preserves ethics" )
world . state . ethics [ "C0.2" ] = { "m" : 8 , "l" : 0 , "w" : 0 , "d" : 0 , "c" : 0 , "b" : 0 }
2026-09-29 20:23:20 +03:00
world . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
check ( E . eq ( world . state . ethics [ "C0.2" ] . m , 8 ), "Existing unequal distribution is retained" )
world . state . amount [ "C0.2" ] = 3
2026-09-29 20:23:20 +03:00
world . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
check ( E . eq ( world . state . ethics [ "C0.2" ] . m , 3 ), "Losses reduce ethics without inventing population" )
2026-10-01 23:43:34 +03:00
check ( E . eq ( root . get_node ( "SaveManager" ) . validate_data ({ "format_version" : 5 , "app_version" : "" , "ui" : { "current_page" : 0 }, "state" : world . state }), "" ), "Ethics state validates" )
2026-09-15 23:05:05 +03:00
var restored = fixture ()
2026-09-30 08:08:27 +03:00
restored . state = E . decode ( bytes_to_var ( var_to_bytes ( E . encode ( world . state ))))
2026-09-29 20:23:20 +03:00
restored . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
check ( E . eq ( restored . state , world . state ), "Save roundtrip preserves ethics and ownership" )
2026-09-15 23:05:05 +03:00
dispose ( restored )
dispose ( world )
world = fixture ()
2026-09-30 08:08:27 +03:00
world . state . amount . RD = 10
for row : Dictionary in global . CivilizationRules [ "C1.9" ] . ethics . values ():
2026-09-16 19:54:47 +03:00
row . progress = "1"
row . degradation = "0"
row . colonization = "0"
2026-09-30 08:08:27 +03:00
world . state . binds . RD = { "C1.9" : 10 }
world . state . batches [ "C1.9" ] = [{ "amount" : 10 , "start_year" : 1 , "end_year" : 1 }]
world . evolution . evolve_batches ( world . state , 1 )
check (( E . eq ( world . state . amount [ "C2.0" ], 10 ) and E . eq ( world . state . binds . RD . get ( "C2.0" , 0 ), 0 )), "Space successor does not inherit planetary binding" )
2026-09-15 23:05:05 +03:00
dispose ( world )
2026-09-16 07:58:19 +03:00
var capacity = load ( "res://world/owniverse/civilization_state.gd" )
world = fixture ()
2026-09-30 08:08:27 +03:00
world . state . amount . RD = 10
world . state . amount [ "C2.0" ] = 8
2026-09-16 07:58:19 +03:00
var budget : Dictionary = capacity . stellar_budget ( world , world . state , global . CivilizationRules )
2026-09-30 08:08:27 +03:00
check ( E . eq ( capacity . admit_transition ( budget , global . CivilizationRules , "C1.9" , "C2.0" , 5 ), 2 ), "Growth consumes only remaining stellar capacity" )
check ( E . eq ( capacity . admit_transition ( budget , global . CivilizationRules , "C1.9" , "C2.0" , 5 ), 0 ), "A reservation cannot be spent twice" )
world . state . amount [ "C2.0" ] = 1
2026-09-16 07:58:19 +03:00
budget = capacity . stellar_budget ( world , world . state , global . CivilizationRules )
2026-09-30 08:08:27 +03:00
check ( E . eq ( capacity . admit_transition ( budget , global . CivilizationRules , "C2.0" , "C2.1" , 1 ), 1 ), "A transition reuses the source reservation" )
check ( E . eq ( budget . free . DwStar , 0 ), "C2.1 reserves ten dwarf stars" )
world . state . amount [ "C2.0" ] = 0
world . state . binds . SC = { "RD" : 10 }
2026-09-16 07:58:19 +03:00
budget = capacity . stellar_budget ( world , world . state , global . CivilizationRules )
2026-09-30 08:08:27 +03:00
check ( E . eq ( budget . capacity . DwStar , 20 ), "Stars inside structures are counted once" )
2026-09-16 07:58:19 +03:00
dispose ( world )
world = fixture ()
2026-09-30 08:08:27 +03:00
world . state . amount . RD = 12
world . state . amount [ "C2.1" ] = 2
world . state . amount [ "C2.0" ] = 5
2026-09-29 20:23:20 +03:00
world . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
check (( E . eq ( world . state . amount [ "C2.1" ], 1 ) and E . eq ( world . state . amount [ "C2.0" ], 2 )), "Shared budget supports advanced civilizations first" )
check ( E . eq ( world . state . binds . RD [ "C1.9" ], 4 ), "Excess cascades to supported planetary stage" )
2026-09-16 07:58:19 +03:00
var snapshot : Dictionary = world . state . duplicate ( true )
2026-09-29 20:23:20 +03:00
world . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
check ( E . eq ( world . state , snapshot ), "Capacity enforcement is idempotent" )
world . state . amount . RD = 0
2026-09-29 20:23:20 +03:00
world . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
check (( E . eq ( world . state . amount [ "C2.1" ], 0 ) and E . eq ( world . state . amount [ "C2.0" ], 0 )), "Vanished stars force all unsupported space civilizations down" )
check ( E . eq ( world . ledger . physical_amounts ( world . state )[ "C1.9" ], 7 ), "Forced degradation conserves civilizations" )
2026-09-16 07:58:19 +03:00
dispose ( world )
world = fixture ()
2026-09-30 08:08:27 +03:00
world . state . amount . LGW = 20
world . state . amount . SMBH = E . of ( "2.0e22" )
world . state . amount [ "C4.2" ] = 3
2026-09-29 20:23:20 +03:00
world . evolution . initialize_life_batches ()
2026-09-30 08:08:27 +03:00
check ( E . eq ( world . state . amount [ "C4.2" ], 2 ), "SMBH capacity uses stellar mass equivalent" )
check ( E . eq ( world . ledger . physical_amounts ( world . state )[ "C1.9" ], 1 ), "Unsupported civilization degrades through missing habitat families" )
2026-10-01 23:43:34 +03:00
check ( E . eq ( root . get_node ( "SaveManager" ) . validate_data ({ "format_version" : 5 , "app_version" : "" , "ui" : { "current_page" : 0 }, "state" : world . state }), "" ), "Capacity-limited state validates" )
2026-09-16 07:58:19 +03:00
dispose ( world )
world = fixture ()
2026-09-30 08:08:27 +03:00
world . state . amount . RD = 2
for row : Dictionary in global . CivilizationRules [ "C1.9" ] . ethics . values ():
2026-09-16 19:54:47 +03:00
row . progress = "1"
row . degradation = "0"
row . colonization = "0"
2026-09-30 08:08:27 +03:00
world . state . binds . RD = { "C1.9" : 5 }
world . state . batches [ "C1.9" ] = [{ "amount" : 5 , "start_year" : 1 , "end_year" : 1 }]
world . evolution . evolve_batches ( world . state , 1 )
check (( E . eq ( world . state . amount [ "C2.0" ], 2 ) and E . eq ( world . state . binds . RD [ "C1.9" ], 3 )), "Unfunded transition retains the original planetary civilization" )
2026-09-16 07:58:19 +03:00
dispose ( world )
2026-09-30 08:08:27 +03:00
print (( "Civilization state: %d checks, %d failures" % [ checks , failures ]))
quit (( 0 if E . eq ( failures , 0 ) else 1 ))