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:
@@ -243,9 +243,20 @@ func simulate_tick() -> void:
|
|||||||
print("[SimulationManager] ", npc.npc_name, " completed sleep at home")
|
print("[SimulationManager] ", npc.npc_name, " completed sleep at home")
|
||||||
elif (
|
elif (
|
||||||
completed_task
|
completed_task
|
||||||
not in [SimulationIds.ACTION_GATHER_FOOD, SimulationIds.ACTION_GATHER_WOOD]
|
not in [
|
||||||
|
SimulationIds.ACTION_GATHER_FOOD,
|
||||||
|
SimulationIds.ACTION_GATHER_WOOD,
|
||||||
|
SimulationIds.ACTION_PATROL,
|
||||||
|
SimulationIds.ACTION_STUDY
|
||||||
|
]
|
||||||
):
|
):
|
||||||
village.apply_npc_task(npc)
|
village.apply_npc_task(npc)
|
||||||
|
elif completed_task == SimulationIds.ACTION_PATROL:
|
||||||
|
_consume_wood_for_work(npc, completed_task)
|
||||||
|
village.apply_npc_task(npc)
|
||||||
|
elif completed_task == SimulationIds.ACTION_STUDY:
|
||||||
|
_consume_wood_for_work(npc, completed_task)
|
||||||
|
village.apply_npc_task(npc)
|
||||||
elif debug_logs:
|
elif debug_logs:
|
||||||
print(
|
print(
|
||||||
"[SimulationManager] ",
|
"[SimulationManager] ",
|
||||||
@@ -631,6 +642,25 @@ func deposit_npc_wood(npc: SimNPC) -> float:
|
|||||||
return deposited
|
return deposited
|
||||||
|
|
||||||
|
|
||||||
|
func _consume_wood_for_work(npc: SimNPC, action_id: StringName) -> void:
|
||||||
|
var woodpile := get_woodpile()
|
||||||
|
if woodpile == null:
|
||||||
|
return
|
||||||
|
var consumed := woodpile.withdraw(SimulationIds.RESOURCE_WOOD, 1.0)
|
||||||
|
_sync_village_wood()
|
||||||
|
if consumed >= 1.0:
|
||||||
|
_record_economic_event(
|
||||||
|
SimulationIds.EVENT_ITEM_CONSUMED,
|
||||||
|
npc.id,
|
||||||
|
SimulationIds.STORAGE_VILLAGE_WOODPILE,
|
||||||
|
&"consumed",
|
||||||
|
SimulationIds.RESOURCE_WOOD,
|
||||||
|
consumed
|
||||||
|
)
|
||||||
|
if debug_logs:
|
||||||
|
print("[SimulationManager] %s consumed wood for %s" % [npc.npc_name, action_id])
|
||||||
|
|
||||||
|
|
||||||
func withdraw_to_npc(npc: SimNPC, item_id: StringName, amount: float) -> float:
|
func withdraw_to_npc(npc: SimNPC, item_id: StringName, amount: float) -> float:
|
||||||
var withdrawn := get_pantry().withdraw(item_id, amount)
|
var withdrawn := get_pantry().withdraw(item_id, amount)
|
||||||
npc.add_inventory(item_id, withdrawn)
|
npc.add_inventory(item_id, withdrawn)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ static func capture(npc: SimNPC) -> NPCStateRecord:
|
|||||||
"last_task": String(npc.last_task),
|
"last_task": String(npc.last_task),
|
||||||
"random_seed": str(npc.random_source.seed),
|
"random_seed": str(npc.random_source.seed),
|
||||||
"random_state": str(npc.random_source.state),
|
"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.random_source.state = String(data["random_state"]).to_int()
|
||||||
npc.debug_logs = debug_logs
|
npc.debug_logs = debug_logs
|
||||||
var saved_familiarity = data.get("familiarity", {})
|
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)
|
npc.familiarity = saved_familiarity.duplicate(true)
|
||||||
return npc
|
return npc
|
||||||
|
|
||||||
|
|
||||||
func to_dictionary() -> Dictionary:
|
func to_dictionary() -> Dictionary:
|
||||||
return data.duplicate(true)
|
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