From fbe3487b56b76532afe3af33cbfc57e7c66678b8 Mon Sep 17 00:00:00 2001 From: Rijad Zuzo Date: Fri, 19 Jun 2026 16:16:47 +0200 Subject: [PATCH] feat: add actions based on village resources and profession --- simulation/SimNPC.gd | 47 ++++++++++++++++++++++++++------- simulation/SimVillage.gd | 3 ++- simulation/SimulationManager.gd | 2 +- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/simulation/SimNPC.gd b/simulation/SimNPC.gd index abbb929..35c054d 100644 --- a/simulation/SimNPC.gd +++ b/simulation/SimNPC.gd @@ -28,23 +28,50 @@ func _init( position = Vector3(randf_range(-8.0, 8.0), 0.0, randf_range(-8.0, 8.0)) -func simulate_tick() -> void: +func simulate_tick(village: SimVillage) -> void: hunger += 5.0 energy -= 2.0 + hunger = clamp(hunger, 0.0, 100.0) + energy = clamp(energy, 0.0, 100.0) + if hunger > 75.0: - current_task = "eat" - hunger -= 25.0 - elif energy < 30.0: + if village.food > 0: + current_task = "eat" + hunger -= 25.0 + else: + current_task = "gather_food" + return + + if energy < 30.0: current_task = "rest" energy += 20.0 - elif profession == "farmer": + return + + if village.food < 15.0: current_task = "gather_food" - elif profession == "woodcutter": + return + + if village.wood < 10.0: current_task = "gather_wood" - elif profession == "guard": + return + + if village.safety < 40.0 and profession == "guard": current_task = "patrol" - elif profession == "scholar": + return + + if village.knowledge < 10.0 and profession == "scholar": current_task = "study" - else: - current_task = "wander" + return + + match profession: + "farmer": + current_task = "gather_food" + "woodcutter": + current_task = "gather_wood" + "guard": + current_task = "patrol" + "scholar": + current_task = "study" + _: + current_task = "wander" diff --git a/simulation/SimVillage.gd b/simulation/SimVillage.gd index 18e68e0..c9115d8 100644 --- a/simulation/SimVillage.gd +++ b/simulation/SimVillage.gd @@ -21,11 +21,12 @@ func apply_npc_task(npc: SimNPC) -> void: "rest": pass "wander": - pass + safety -= 0.2 food = max(food, 0.0) wood = max(wood, 0.0) safety = clamp(safety, 0.0, 100.0) + knowledge = max(knowledge, 0.0) func get_summary() -> String: return "Village | food: %s | wood: %s | safety: %s | knowledge: %s" % [ diff --git a/simulation/SimulationManager.gd b/simulation/SimulationManager.gd index 57565a2..11e9f72 100644 --- a/simulation/SimulationManager.gd +++ b/simulation/SimulationManager.gd @@ -55,7 +55,7 @@ func simulate_tick() -> void: for npc in npcs: var old_task := npc.current_task - npc.simulate_tick() + npc.simulate_tick(village) if old_task != npc.current_task: npc_task_changed.emit(npc, old_task, npc.current_task)