fix: empty-path re-entrancy, retry_count reset, := to = for Variant
This commit is contained in:
@@ -28,6 +28,8 @@ var task_duration := 0.0
|
||||
var task_progress := 0.0
|
||||
var task_complete := true
|
||||
var target_id: StringName = &""
|
||||
var retry_count := 0
|
||||
var last_task := ""
|
||||
|
||||
func _init(
|
||||
_id: int,
|
||||
@@ -227,6 +229,9 @@ func calculate_task_score(
|
||||
if profession == preferred_profession:
|
||||
score += 2.0
|
||||
|
||||
if task_name == last_task:
|
||||
score -= 1.5
|
||||
|
||||
score += randf_range(0.0, 0.5)
|
||||
|
||||
if DEBUG_LOGS:
|
||||
@@ -242,6 +247,7 @@ func calculate_task_score(
|
||||
return score
|
||||
|
||||
func set_task(task: String, duration: float) -> void:
|
||||
last_task = current_task
|
||||
current_task = task
|
||||
task_duration = duration
|
||||
task_progress = 0.0
|
||||
|
||||
@@ -98,6 +98,7 @@ func simulate_tick() -> void:
|
||||
village.apply_npc_task(npc)
|
||||
|
||||
village_was_changed = true
|
||||
npc.retry_count = 0
|
||||
|
||||
npc.task_complete = true
|
||||
npc.task_state = SimNPC.TASK_STATE_IDLE
|
||||
@@ -110,6 +111,15 @@ func simulate_tick() -> void:
|
||||
if DEBUG_LOGS:
|
||||
print("[SimulationManager] ", npc.npc_name, " gathered food while starving and is going to eat immediately.")
|
||||
|
||||
if npc.task_state == SimNPC.TASK_STATE_TRAVELING and npc.target_id == &"":
|
||||
npc.retry_count += 1
|
||||
if npc.retry_count >= 5:
|
||||
if DEBUG_LOGS:
|
||||
print("[SimulationManager] ", npc.npc_name, " stuck traveling without target for ", npc.retry_count, " attempts, replanning")
|
||||
npc.task_state = SimNPC.TASK_STATE_IDLE
|
||||
npc.current_task = ""
|
||||
npc.retry_count = 0
|
||||
|
||||
if DEBUG_LOGS:
|
||||
print(
|
||||
npc.npc_name,
|
||||
@@ -176,6 +186,8 @@ func notify_npc_arrived(npc_id: int) -> void:
|
||||
print("[SimulationManager] ", npc.npc_name, " arrived but target ", npc.target_id, " is unavailable, replanning")
|
||||
release_npc_reservation(npc.id)
|
||||
npc.task_state = SimNPC.TASK_STATE_IDLE
|
||||
npc.current_task = ""
|
||||
npc.retry_count += 1
|
||||
return
|
||||
|
||||
npc.start_working()
|
||||
|
||||
Reference in New Issue
Block a user