feat: wood consumption for patrol and study
Patrol and study now consume 1 wood from the village woodpile on completion, recording an item_consumed economic event. This gives wood a purpose and creates resource pressure between gathering and work-support activities. Familiarity serialization switched from raw Dictionary to sorted Array of {id, score} pairs for deterministic JSON checksum output across save/load.
This commit is contained in:
@@ -46,7 +46,7 @@ static func capture(npc: SimNPC) -> NPCStateRecord:
|
||||
"last_task": String(npc.last_task),
|
||||
"random_seed": str(npc.random_source.seed),
|
||||
"random_state": str(npc.random_source.state),
|
||||
"familiarity": npc.familiarity.duplicate(true)
|
||||
"familiarity": _sorted_familiarity(npc.familiarity)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -162,10 +162,26 @@ func restore(debug_logs: bool) -> SimNPC:
|
||||
npc.random_source.state = String(data["random_state"]).to_int()
|
||||
npc.debug_logs = debug_logs
|
||||
var saved_familiarity = data.get("familiarity", {})
|
||||
if saved_familiarity is Dictionary:
|
||||
if saved_familiarity is Array:
|
||||
for pair in saved_familiarity:
|
||||
var pair_dict: Dictionary = pair
|
||||
npc.familiarity[int(pair_dict["id"])] = float(pair_dict["score"])
|
||||
elif saved_familiarity is Dictionary:
|
||||
npc.familiarity = saved_familiarity.duplicate(true)
|
||||
return npc
|
||||
|
||||
|
||||
func to_dictionary() -> Dictionary:
|
||||
return data.duplicate(true)
|
||||
|
||||
|
||||
static func _sorted_familiarity(familiarity: Dictionary) -> Array:
|
||||
var pairs: Array[Dictionary] = []
|
||||
for key in familiarity:
|
||||
pairs.append({"id": int(key), "score": float(familiarity[key])})
|
||||
pairs.sort_custom(_familiarity_sort)
|
||||
return pairs
|
||||
|
||||
|
||||
static func _familiarity_sort(a: Dictionary, b: Dictionary) -> bool:
|
||||
return int(a["id"]) < int(b["id"])
|
||||
|
||||
Reference in New Issue
Block a user