feat: add simple village simulation of resources

This commit is contained in:
Rijad Zuzo
2026-06-19 10:53:30 +02:00
parent d85fc5a7f9
commit d7022b3f27
3 changed files with 47 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
class_name SimVillage
extends RefCounted
var food := 20.0
var wood := 10.0
var safety := 50.0
var knowledge := 0.0
func apply_npc_task(npc: SimNPC) -> void:
match npc.current_task:
"gather_food":
food += 2.0
"gather_wood":
wood += 2.0
"patrol":
safety += 1.0
"study":
knowledge += 1.0
"eat":
food -= 1.0
"rest":
pass
"wander":
pass
food = max(food, 0.0)
wood = max(wood, 0.0)
safety = clamp(safety, 0.0, 100.0)
func get_summary() -> String:
return "Village | food: %s | wood: %s | safety: %s | knowledge: %s" % [
round(food),
round(wood),
round(safety),
round(knowledge)
]
+1
View File
@@ -0,0 +1 @@
uid://oqdf44lxs3dg
+10
View File
@@ -1,6 +1,10 @@
extends Node extends Node
signal npc_task_changed(npc: SimNPC, old_task: String, new_task: String) signal npc_task_changed(npc: SimNPC, old_task: String, new_task: String)
signal village_changed(village: SimVillage)
var village := SimVillage.new()
const DEBUG_LOGS := true const DEBUG_LOGS := true
var npcs: Array[SimNPC] = [] var npcs: Array[SimNPC] = []
@@ -68,3 +72,9 @@ func simulate_tick() -> void:
" | energy: ", " | energy: ",
round(npc.energy) round(npc.energy)
) )
for npc in npcs:
village.apply_npc_task(npc)
village_changed.emit(village)
if DEBUG_LOGS:
print(village.get_summary())