diff --git a/simulation/SimVillage.gd b/simulation/SimVillage.gd new file mode 100644 index 0000000..18e68e0 --- /dev/null +++ b/simulation/SimVillage.gd @@ -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) + ] diff --git a/simulation/SimVillage.gd.uid b/simulation/SimVillage.gd.uid new file mode 100644 index 0000000..a976eb2 --- /dev/null +++ b/simulation/SimVillage.gd.uid @@ -0,0 +1 @@ +uid://oqdf44lxs3dg diff --git a/simulation/SimulationManager.gd b/simulation/SimulationManager.gd index 8e097ff..57565a2 100644 --- a/simulation/SimulationManager.gd +++ b/simulation/SimulationManager.gd @@ -1,6 +1,10 @@ extends Node 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 var npcs: Array[SimNPC] = [] @@ -68,3 +72,9 @@ func simulate_tick() -> void: " | energy: ", round(npc.energy) ) + + for npc in npcs: + village.apply_npc_task(npc) + village_changed.emit(village) + if DEBUG_LOGS: + print(village.get_summary())