feat: add proper death from starvation and survival tasks urgency

This commit is contained in:
Rijad Zuzo
2026-06-21 23:37:58 +02:00
parent eef2068747
commit b5e2493c2a
6 changed files with 165 additions and 20 deletions
+34 -4
View File
@@ -2,6 +2,7 @@ extends Node
signal npc_task_changed(npc: SimNPC, old_task: String, new_task: String)
signal village_changed(village: SimVillage)
signal npc_died(npc: SimNPC)
var village := SimVillage.new()
@@ -26,9 +27,11 @@ var professions := [
func _ready() -> void:
randomize()
village.update_modifiers()
village.update_priorities()
generate_npcs()
print("--- Simulation started ---")
func _process(delta: float) -> void:
tick_timer += delta
@@ -58,13 +61,24 @@ func simulate_tick() -> void:
var old_task := npc.current_task
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:
if not was_dead and npc.is_dead:
npc_died.emit(npc)
npc_task_changed.emit(npc, old_task, npc.current_task)
if not was_complete and npc.task_complete:
if DEBUG_LOGS:
print("[SimulationManager] NPC died: ", npc.npc_name)
if old_task != npc.current_task and not npc.is_dead:
npc_task_changed.emit(npc, old_task, npc.current_task)
if not was_complete and npc.task_complete and not npc.is_dead:
var completed_task := npc.current_task
var needs_immediate_food_after_gather := npc.should_eat_immediately_after_task()
village.apply_npc_task(npc)
village_was_changed = true
@@ -72,6 +86,13 @@ func simulate_tick() -> void:
npc.task_state = SimNPC.TASK_STATE_IDLE
npc.current_task = "idle"
if needs_immediate_food_after_gather and village.food > 0:
npc.set_task("eat", 1.0)
npc_task_changed.emit(npc, completed_task, npc.current_task)
if DEBUG_LOGS:
print("[SimulationManager] ", npc.npc_name, " gathered food while starving and is going to eat immediately.")
if DEBUG_LOGS:
print(
npc.npc_name,
@@ -90,7 +111,13 @@ func simulate_tick() -> void:
" | hunger: ",
round(npc.hunger),
" | energy: ",
round(npc.energy)
round(npc.energy),
" | starving: ",
npc.is_starving,
" | starvation_ticks: ",
npc.starvation_ticks,
" | dead: ",
npc.is_dead
)
if old_state != npc.task_state:
@@ -105,6 +132,9 @@ func simulate_tick() -> void:
func notify_npc_arrived(npc_id: int) -> void:
for npc in npcs:
if npc.id == npc_id:
if npc.is_dead:
return
if npc.task_state == SimNPC.TASK_STATE_TRAVELING:
npc.start_working()