feat: add completition of work only after work is done
This commit is contained in:
@@ -56,6 +56,7 @@ func simulate_tick() -> void:
|
||||
|
||||
for npc in npcs:
|
||||
var old_task := npc.current_task
|
||||
var old_state := npc.task_state
|
||||
var was_complete := npc.task_complete
|
||||
|
||||
npc.simulate_tick(village)
|
||||
@@ -67,6 +68,10 @@ func simulate_tick() -> void:
|
||||
village.apply_npc_task(npc)
|
||||
village_was_changed = true
|
||||
|
||||
npc.task_complete = true
|
||||
npc.task_state = SimNPC.TASK_STATE_IDLE
|
||||
npc.current_task = "idle"
|
||||
|
||||
if DEBUG_LOGS:
|
||||
print(
|
||||
npc.npc_name,
|
||||
@@ -74,6 +79,8 @@ func simulate_tick() -> void:
|
||||
npc.profession,
|
||||
" | task: ",
|
||||
npc.current_task,
|
||||
" | state: ",
|
||||
npc.task_state,
|
||||
" | progress: ",
|
||||
npc.task_progress,
|
||||
"/",
|
||||
@@ -86,11 +93,24 @@ func simulate_tick() -> void:
|
||||
round(npc.energy)
|
||||
)
|
||||
|
||||
if old_state != npc.task_state:
|
||||
print("[SimulationManager] State changed: ", npc.npc_name, " ", old_state, " -> ", npc.task_state)
|
||||
|
||||
if village_was_changed:
|
||||
village_changed.emit(village)
|
||||
|
||||
if DEBUG_LOGS:
|
||||
print(village.get_summary())
|
||||
|
||||
func notify_npc_arrived(npc_id: int) -> void:
|
||||
for npc in npcs:
|
||||
if npc.id == npc_id:
|
||||
if npc.task_state == SimNPC.TASK_STATE_TRAVELING:
|
||||
npc.start_working()
|
||||
|
||||
if DEBUG_LOGS:
|
||||
print("[SimulationManager] ", npc.npc_name, " arrived and started working on: ", npc.current_task)
|
||||
return
|
||||
|
||||
func eat_food(amount: float) -> void:
|
||||
village.food -= amount
|
||||
|
||||
Reference in New Issue
Block a user