feat: add actions based on village resources and profession

This commit is contained in:
Rijad Zuzo
2026-06-19 16:16:47 +02:00
parent f251423f62
commit fbe3487b56
3 changed files with 40 additions and 12 deletions
+34 -7
View File
@@ -28,23 +28,50 @@ func _init(
position = Vector3(randf_range(-8.0, 8.0), 0.0, randf_range(-8.0, 8.0)) 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 hunger += 5.0
energy -= 2.0 energy -= 2.0
hunger = clamp(hunger, 0.0, 100.0)
energy = clamp(energy, 0.0, 100.0)
if hunger > 75.0: if hunger > 75.0:
if village.food > 0:
current_task = "eat" current_task = "eat"
hunger -= 25.0 hunger -= 25.0
elif energy < 30.0: else:
current_task = "gather_food"
return
if energy < 30.0:
current_task = "rest" current_task = "rest"
energy += 20.0 energy += 20.0
elif profession == "farmer": return
if village.food < 15.0:
current_task = "gather_food" current_task = "gather_food"
elif profession == "woodcutter": return
if village.wood < 10.0:
current_task = "gather_wood" current_task = "gather_wood"
elif profession == "guard": return
if village.safety < 40.0 and profession == "guard":
current_task = "patrol" current_task = "patrol"
elif profession == "scholar": return
if village.knowledge < 10.0 and profession == "scholar":
current_task = "study" current_task = "study"
else: return
match profession:
"farmer":
current_task = "gather_food"
"woodcutter":
current_task = "gather_wood"
"guard":
current_task = "patrol"
"scholar":
current_task = "study"
_:
current_task = "wander" current_task = "wander"
+2 -1
View File
@@ -21,11 +21,12 @@ func apply_npc_task(npc: SimNPC) -> void:
"rest": "rest":
pass pass
"wander": "wander":
pass safety -= 0.2
food = max(food, 0.0) food = max(food, 0.0)
wood = max(wood, 0.0) wood = max(wood, 0.0)
safety = clamp(safety, 0.0, 100.0) safety = clamp(safety, 0.0, 100.0)
knowledge = max(knowledge, 0.0)
func get_summary() -> String: func get_summary() -> String:
return "Village | food: %s | wood: %s | safety: %s | knowledge: %s" % [ return "Village | food: %s | wood: %s | safety: %s | knowledge: %s" % [
+1 -1
View File
@@ -55,7 +55,7 @@ func simulate_tick() -> void:
for npc in npcs: for npc in npcs:
var old_task := npc.current_task var old_task := npc.current_task
npc.simulate_tick() npc.simulate_tick(village)
if old_task != npc.current_task: if old_task != npc.current_task:
npc_task_changed.emit(npc, old_task, npc.current_task) npc_task_changed.emit(npc, old_task, npc.current_task)