extends SceneTree var checks := 0 var failures := 0 var runtime: Variant var clock: Variant var state: Variant func _initialize() -> void: call_deferred("run") func expect(ok: bool, text: String) -> void: checks += 1 if not ok: failures += 1; push_error(text) else: print("PASS: ",text) func command(type: StringName, payload: Dictionary) -> bool: var r: CommandResult = runtime.submit_command(type,payload,&"player") expect(r.is_success(), "%s: %s" % [type,r.message]);return r.is_success() func run() -> void: clock = load("res://autoload/game_clock.gd").new();state = load("res://autoload/game_state.gd").new();runtime = load("res://autoload/simulation_runtime.gd").new() clock.reset(1,6,0);state.reset();runtime.initialize(clock,state,714);clock.set_paused(true) expect(runtime.enable_production_operations()[&"ok"], "normal operations enable staff rest") command(&"register_staff",{&"staff_id":&"resting",&"role_id":&"porter",&"options":{&"health":20,&"fatigue":20,&"current_cell":Vector3i(5,0,0),&"state":StaffRuntime.State.OFF_DUTY}}) clock.advance_minutes(30) var worker: StaffRuntime = runtime.staff_service.get_staff(&"resting") expect(worker.health == 20 and worker.current_cell == Vector3i(5,0,0), "off-duty worker cannot heal in the public corridor without a rest room") expect(runtime.get_staff_rest_report(&"resting")[&"label"].contains("休憩先なし"), "missing rest room has an actionable status") runtime.path_service.set_connector_enabled(&"starter.staff_door",false) command(&"build_facility",{&"definition_id":&"staff_waiting_room",&"origin":Vector3i(-6,0,1)}) clock.advance_minutes(120) expect(worker.current_cell == Vector3i(5,0,0) and worker.health == 20, "rest room behind a blocked door cannot teleport or heal the worker") command(&"build_facility",{&"definition_id":&"staff_door",&"origin":Vector3i(0,0,1)}) clock.advance_minutes(30) var midpoint: Dictionary = runtime.create_snapshot() clock.advance_minutes(60) expect(runtime.get_staff_rest_report(&"resting").get(&"resting",false) and worker.current_cell.z == 1, "off-duty worker physically reaches the back-layer rest room") expect(worker.health > 20 and worker.fatigue < 20, "health and fatigue recover only after arrival") var final_state: Dictionary = runtime.create_snapshot() expect(runtime.restore_snapshot(midpoint), "rest movement snapshot restores") clock.advance_minutes(60) expect(runtime.create_snapshot() == final_state, "rest movement and recovery replay identically") worker = runtime.staff_service.get_staff(&"resting") var room_id: StringName = runtime.get_staff_rest_report(&"resting")[&"facility_id"] runtime.facility_service.set_operational_status(room_id,{&"operator_open":false},clock.absolute_minute) var health := worker.health clock.advance_minutes(30) expect(worker.health == health and not runtime.get_staff_rest_report(&"resting").get(&"resting",false), "closed waiting room cannot recover health") runtime.facility_service.set_operational_status(room_id,{&"operator_open":true},clock.absolute_minute) worker.health = 0 clock.advance_minutes(30) expect(worker.health == 0 and worker.state == StaffRuntime.State.INCAPACITATED, "rest cannot replace rescue for an incapacitated worker") expect(runtime.restore_snapshot(runtime.create_snapshot()), "closed-room and collapse state remain saveable") runtime.free();clock.free();state.free() print("Staff rest: %d checks, %d failures" % [checks,failures]);quit(failures)