feat: authoritative extraction from ResourceNode on task completion

Phase 3 of ResourceNode migration:
- Add apply_resource_delta to SimVillage for clean resource changes
- Extract from reserved ResourceNode on task completion instead of
  hard-coded apply_npc_task for gather_food/gather_wood
- Detect depleted/unavailable targets on arrival and replan
This commit is contained in:
2026-07-03 18:32:34 +02:00
parent 0dfaa06f9c
commit c6033b63fb
2 changed files with 37 additions and 1 deletions
+18 -1
View File
@@ -86,9 +86,17 @@ func simulate_tick() -> void:
var needs_immediate_food_after_gather := npc.should_eat_immediately_after_task()
if npc.target_id != &"":
var node := ResourceNode.get_by_id(npc.target_id)
if node != null:
var extracted := node.extract()
if extracted > 0:
village.apply_resource_delta(node.resource_id, extracted)
if DEBUG_LOGS:
print("[SimulationManager] ", npc.npc_name, " extracted ", extracted, " ", node.resource_id, " from ", node.node_id)
release_npc_reservation(npc.id)
else:
village.apply_npc_task(npc)
village.apply_npc_task(npc)
village_was_changed = true
npc.task_complete = true
@@ -161,6 +169,15 @@ func notify_npc_arrived(npc_id: int) -> void:
return
if npc.task_state == SimNPC.TASK_STATE_TRAVELING:
if npc.target_id != &"":
var node := ResourceNode.get_by_id(npc.target_id)
if node == null or not node.can_extract():
if DEBUG_LOGS:
print("[SimulationManager] ", npc.npc_name, " arrived but target ", npc.target_id, " is unavailable, replanning")
release_npc_reservation(npc.id)
npc.task_state = SimNPC.TASK_STATE_IDLE
return
npc.start_working()
if DEBUG_LOGS: