4604dc6d5a
Add ACTION_SLEEP with home-position targeting and energy restoration. Embed schedule periods (SLEEP/MEAL/WORK/DISCRETIONARY) in ActionSelectionSystem with TimeOfDay from SimulationClock. NPCs sleep at night when energy is low, eat during meal periods when hungry, and work/discretionary the rest of the cycle. Home position stored per NPC and serialized through NPCStateRecord with backward-compatible fallback. Cycle duration persisted through save/restore. Includes headless test for sleep period, work period, meal hunger, energy restoration, serialization round-trip, and home targeting without world adapter.
32 lines
681 B
GDScript
32 lines
681 B
GDScript
class_name SimulationClock
|
|
extends RefCounted
|
|
|
|
var tick_interval: float
|
|
var accumulator := 0.0
|
|
var elapsed_ticks := 0
|
|
var cycle_duration_seconds := 240.0
|
|
|
|
|
|
func _init(interval: float = 1.0) -> void:
|
|
tick_interval = maxf(interval, 0.0001)
|
|
|
|
|
|
func advance(delta: float) -> int:
|
|
accumulator += maxf(delta, 0.0)
|
|
var ticks_due := 0
|
|
while accumulator >= tick_interval:
|
|
accumulator -= tick_interval
|
|
elapsed_ticks += 1
|
|
ticks_due += 1
|
|
return ticks_due
|
|
|
|
|
|
func reset() -> void:
|
|
accumulator = 0.0
|
|
elapsed_ticks = 0
|
|
|
|
|
|
func time_of_day() -> float:
|
|
var total_seconds := elapsed_ticks * tick_interval + accumulator
|
|
return fmod(total_seconds / maxf(cycle_duration_seconds, 1.0), 1.0)
|