feat: add actions based on village resources and profession
This commit is contained in:
+34
-7
@@ -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:
|
||||
if village.food > 0:
|
||||
current_task = "eat"
|
||||
hunger -= 25.0
|
||||
elif energy < 30.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:
|
||||
return
|
||||
|
||||
match profession:
|
||||
"farmer":
|
||||
current_task = "gather_food"
|
||||
"woodcutter":
|
||||
current_task = "gather_wood"
|
||||
"guard":
|
||||
current_task = "patrol"
|
||||
"scholar":
|
||||
current_task = "study"
|
||||
_:
|
||||
current_task = "wander"
|
||||
|
||||
@@ -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" % [
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user