feat: add location-based food storage loop

This commit is contained in:
2026-07-05 17:57:24 +02:00
parent 3ea8f02d55
commit 6dbb395bd6
22 changed files with 469 additions and 72 deletions
+20 -10
View File
@@ -1,8 +1,9 @@
class_name NPCStateRecord
extends RefCounted
const SCHEMA_VERSION := 2
const SCHEMA_VERSION := 3
const LEGACY_SCHEMA_VERSION := 1
const PREVIOUS_SCHEMA_VERSION := 2
var data: Dictionary
@@ -36,6 +37,7 @@ static func capture(npc: SimNPC) -> NPCStateRecord:
npc.travel_target_position.z
],
"has_travel_target": npc.has_travel_target,
"inventory": npc.inventory.duplicate(true),
"last_task": String(npc.last_task),
"random_seed": str(npc.random_source.seed),
"random_state": str(npc.random_source.state)
@@ -43,8 +45,8 @@ static func capture(npc: SimNPC) -> NPCStateRecord:
static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
var version := int(record_data.get("schema_version", -1))
if version == LEGACY_SCHEMA_VERSION:
record_data = _migrate_v1(record_data)
if version in [LEGACY_SCHEMA_VERSION, PREVIOUS_SCHEMA_VERSION]:
record_data = _migrate_legacy(record_data, version)
elif version != SCHEMA_VERSION:
return null
if not record_data.has_all([
@@ -52,7 +54,7 @@ static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
"intelligence", "current_task", "task_state", "position",
"is_starving", "starvation_ticks", "starvation_death_threshold",
"is_dead", "task_duration", "task_progress", "task_complete",
"target_id", "travel_target_position", "has_travel_target",
"target_id", "travel_target_position", "has_travel_target", "inventory",
"last_task", "random_seed", "random_state"
]):
return null
@@ -65,6 +67,8 @@ static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
or saved_target_position.size() != 3
):
return null
if not record_data["inventory"] is Dictionary:
return null
var profession_id := StringName(record_data["profession"])
if SimulationDefinitions.get_profession(profession_id) == null:
return null
@@ -85,14 +89,19 @@ static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
return null
return NPCStateRecord.new(record_data)
static func _migrate_v1(legacy_data: Dictionary) -> Dictionary:
static func _migrate_legacy(
legacy_data: Dictionary,
version: int
) -> Dictionary:
var migrated := legacy_data.duplicate(true)
migrated["schema_version"] = SCHEMA_VERSION
migrated["travel_target_position"] = legacy_data.get(
"position",
[0.0, 0.0, 0.0]
)
migrated["has_travel_target"] = false
if version == LEGACY_SCHEMA_VERSION:
migrated["travel_target_position"] = legacy_data.get(
"position",
[0.0, 0.0, 0.0]
)
migrated["has_travel_target"] = false
migrated["inventory"] = {}
return migrated
func restore(debug_logs: bool) -> SimNPC:
@@ -131,6 +140,7 @@ func restore(debug_logs: bool) -> SimNPC:
float(saved_target_position[2])
)
npc.has_travel_target = bool(data["has_travel_target"])
npc.inventory = data["inventory"].duplicate(true)
npc.last_task = StringName(data["last_task"])
npc.random_source.state = String(data["random_state"]).to_int()
npc.debug_logs = debug_logs