feat: add simulation action definitions

This commit is contained in:
2026-07-05 13:35:33 +02:00
parent 12f9ba616f
commit f816f3976a
32 changed files with 608 additions and 113 deletions
+26 -8
View File
@@ -13,13 +13,13 @@ static func capture(npc: SimNPC) -> NPCStateRecord:
"schema_version": SCHEMA_VERSION,
"id": npc.id,
"name": npc.npc_name,
"profession": npc.profession,
"profession": String(npc.profession),
"hunger": npc.hunger,
"energy": npc.energy,
"strength": npc.strength,
"intelligence": npc.intelligence,
"current_task": npc.current_task,
"task_state": npc.task_state,
"current_task": String(npc.current_task),
"task_state": String(npc.task_state),
"position": [npc.position.x, npc.position.y, npc.position.z],
"is_starving": npc.is_starving,
"starvation_ticks": npc.starvation_ticks,
@@ -29,7 +29,7 @@ static func capture(npc: SimNPC) -> NPCStateRecord:
"task_progress": npc.task_progress,
"task_complete": npc.task_complete,
"target_id": String(npc.target_id),
"last_task": npc.last_task,
"last_task": String(npc.last_task),
"random_seed": str(npc.random_source.seed),
"random_state": str(npc.random_source.state)
})
@@ -48,6 +48,24 @@ static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
var saved_position = record_data["position"]
if not saved_position is Array or saved_position.size() != 3:
return null
var profession_id := StringName(record_data["profession"])
if SimulationDefinitions.get_profession(profession_id) == null:
return null
var action_id := StringName(record_data["current_task"])
if (
action_id not in [
SimulationIds.ACTION_IDLE,
SimulationIds.ACTION_DEAD
]
and SimulationDefinitions.get_action(action_id) == null
):
return null
var last_action_id := StringName(record_data["last_task"])
if (
not last_action_id.is_empty()
and SimulationDefinitions.get_action(last_action_id) == null
):
return null
return NPCStateRecord.new(record_data)
func restore(debug_logs: bool) -> SimNPC:
@@ -56,7 +74,7 @@ func restore(debug_logs: bool) -> SimNPC:
var npc := SimNPC.new(
int(data["id"]),
String(data["name"]),
String(data["profession"]),
StringName(data["profession"]),
float(data["strength"]),
float(data["intelligence"]),
random_source
@@ -64,8 +82,8 @@ func restore(debug_logs: bool) -> SimNPC:
var saved_position: Array = data["position"]
npc.hunger = float(data["hunger"])
npc.energy = float(data["energy"])
npc.current_task = String(data["current_task"])
npc.task_state = String(data["task_state"])
npc.current_task = StringName(data["current_task"])
npc.task_state = StringName(data["task_state"])
npc.position = Vector3(
float(saved_position[0]),
float(saved_position[1]),
@@ -79,7 +97,7 @@ func restore(debug_logs: bool) -> SimNPC:
npc.task_progress = float(data["task_progress"])
npc.task_complete = bool(data["task_complete"])
npc.target_id = StringName(data["target_id"])
npc.last_task = String(data["last_task"])
npc.last_task = StringName(data["last_task"])
npc.random_source.state = String(data["random_state"]).to_int()
npc.debug_logs = debug_logs
return npc