feat: add ResourceNode system with target selection and reservation
Phase 1-2 of the ResourceNode migration plan: - Create ResourceNode class (world/resource_nodes/) with extraction, reservation, nearest-available selection, and debug label - Place 4 resource instances in main.tscn (2 berry bushes, 2 trees) - Add target_id to SimNPC for tracking which node an NPC is using - Add set_npc_target_id and release_npc_reservation to SimulationManager with cleanup on task change, completion, and death - Update WorldViewManager to query available ResourceNodes first, falling back to zone markers with a logged warning
This commit is contained in:
@@ -59,13 +59,19 @@ func simulate_tick() -> void:
|
||||
|
||||
for npc in npcs:
|
||||
var old_task := npc.current_task
|
||||
var old_target := npc.target_id
|
||||
var old_state := npc.task_state
|
||||
var was_complete := npc.task_complete
|
||||
var was_dead := npc.is_dead
|
||||
|
||||
npc.simulate_tick(village)
|
||||
|
||||
if old_task != npc.current_task and old_target != &"":
|
||||
release_npc_reservation(npc.id)
|
||||
|
||||
if not was_dead and npc.is_dead:
|
||||
if old_target != &"":
|
||||
release_npc_reservation(npc.id)
|
||||
npc_died.emit(npc)
|
||||
npc_task_changed.emit(npc, old_task, npc.current_task)
|
||||
|
||||
@@ -79,6 +85,9 @@ func simulate_tick() -> void:
|
||||
var completed_task := npc.current_task
|
||||
var needs_immediate_food_after_gather := npc.should_eat_immediately_after_task()
|
||||
|
||||
if npc.target_id != &"":
|
||||
release_npc_reservation(npc.id)
|
||||
|
||||
village.apply_npc_task(npc)
|
||||
village_was_changed = true
|
||||
|
||||
@@ -129,6 +138,22 @@ func simulate_tick() -> void:
|
||||
if DEBUG_LOGS:
|
||||
print(village.get_summary())
|
||||
|
||||
func set_npc_target_id(npc_id: int, target_id: StringName) -> void:
|
||||
for npc in npcs:
|
||||
if npc.id == npc_id:
|
||||
npc.target_id = target_id
|
||||
return
|
||||
|
||||
func release_npc_reservation(npc_id: int) -> void:
|
||||
for npc in npcs:
|
||||
if npc.id == npc_id:
|
||||
if npc.target_id != &"":
|
||||
var node := ResourceNode.get_by_id(npc.target_id)
|
||||
if node != null:
|
||||
node.release(npc.id)
|
||||
npc.target_id = &""
|
||||
return
|
||||
|
||||
func notify_npc_arrived(npc_id: int) -> void:
|
||||
for npc in npcs:
|
||||
if npc.id == npc_id:
|
||||
|
||||
Reference in New Issue
Block a user