feat: add task duration and task commitment
This commit is contained in:
+47
-25
@@ -13,6 +13,10 @@ var position: Vector3
|
||||
|
||||
var is_starving := false
|
||||
|
||||
var task_duration := 0.0
|
||||
var task_progress := 0.0
|
||||
var task_complete := true
|
||||
|
||||
func _init(
|
||||
_id: int,
|
||||
_npc_name: String,
|
||||
@@ -37,51 +41,69 @@ func simulate_tick(village: SimVillage) -> void:
|
||||
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
|
||||
else:
|
||||
current_task = "gather_food"
|
||||
return
|
||||
|
||||
if energy < 30.0:
|
||||
current_task = "rest"
|
||||
energy += 20.0
|
||||
return
|
||||
|
||||
is_starving = hunger >= 90.0
|
||||
|
||||
if is_starving:
|
||||
|
||||
if is_starving:
|
||||
energy -= 8.0
|
||||
|
||||
hunger = clamp(hunger, 0.0, 100.0)
|
||||
energy = clamp(energy, 0.0, 100.0)
|
||||
|
||||
if not task_complete:
|
||||
task_progress += 1.0
|
||||
if task_progress >= task_duration:
|
||||
task_complete = true
|
||||
return
|
||||
|
||||
choose_new_task(village)
|
||||
|
||||
|
||||
func choose_new_task(village: SimVillage) -> void:
|
||||
task_progress = 0.0
|
||||
task_complete = false
|
||||
|
||||
if hunger > 75.0:
|
||||
if village.food > 0:
|
||||
set_task("eat", 2.0)
|
||||
hunger -= 25.0
|
||||
else:
|
||||
set_task("gather_food", 5.0)
|
||||
return
|
||||
|
||||
if energy < 30.0:
|
||||
set_task("rest", 4.0)
|
||||
energy += 20.0
|
||||
return
|
||||
|
||||
if village.food < 15.0:
|
||||
current_task = "gather_food"
|
||||
set_task("gather_food", 5.0)
|
||||
return
|
||||
|
||||
if village.wood < 10.0:
|
||||
current_task = "gather_wood"
|
||||
set_task("gather_wood", 5.0)
|
||||
return
|
||||
|
||||
if village.safety < 40.0 and profession == "guard":
|
||||
current_task = "patrol"
|
||||
set_task("patrol", 6.0)
|
||||
return
|
||||
|
||||
if village.knowledge < 10.0 and profession == "scholar":
|
||||
current_task = "study"
|
||||
set_task("study", 6.0)
|
||||
return
|
||||
|
||||
match profession:
|
||||
"farmer":
|
||||
current_task = "gather_food"
|
||||
set_task("gather_food", 5.0)
|
||||
"woodcutter":
|
||||
current_task = "gather_wood"
|
||||
set_task("gather_wood", 5.0)
|
||||
"guard":
|
||||
current_task = "patrol"
|
||||
set_task("patrol", 6.0)
|
||||
"scholar":
|
||||
current_task = "study"
|
||||
set_task("study", 6.0)
|
||||
_:
|
||||
current_task = "wander"
|
||||
set_task("wander", 4.0)
|
||||
|
||||
func set_task(task: String, duration: float) -> void:
|
||||
current_task = task
|
||||
task_duration = duration
|
||||
task_progress = 0.0
|
||||
task_complete = false
|
||||
|
||||
Reference in New Issue
Block a user