feat: add npc decision inspector

This commit is contained in:
2026-07-05 23:50:18 +02:00
parent 7edf9acd57
commit d883148132
16 changed files with 305 additions and 13 deletions
+10 -1
View File
@@ -3,8 +3,17 @@ extends RefCounted
var action_id: StringName
var duration_override := -1.0
var reason: String
var scores: Dictionary
func _init(selected_action_id: StringName, selected_duration_override: float = -1.0) -> void:
func _init(
selected_action_id: StringName,
selected_duration_override: float = -1.0,
decision_reason: String = "",
decision_scores: Dictionary = {}
) -> void:
action_id = selected_action_id
duration_override = selected_duration_override
reason = decision_reason
scores = decision_scores.duplicate(true)
+29 -11
View File
@@ -7,24 +7,40 @@ func select_action(npc: SimNPC, village: SimVillage) -> ActionSelectionResult:
return null
if npc.is_starving:
if npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD) >= 1.0:
return ActionSelectionResult.new(SimulationIds.ACTION_EAT, 1.0)
return ActionSelectionResult.new(
SimulationIds.ACTION_EAT, 1.0, "Starving and carrying food"
)
if village.food > 0:
return ActionSelectionResult.new(SimulationIds.ACTION_WITHDRAW_FOOD, 1.0)
return ActionSelectionResult.new(SimulationIds.ACTION_GATHER_FOOD, 4.0)
return ActionSelectionResult.new(
SimulationIds.ACTION_WITHDRAW_FOOD, 1.0, "Starving; pantry has food"
)
return ActionSelectionResult.new(
SimulationIds.ACTION_GATHER_FOOD, 4.0, "Starving; pantry is empty"
)
if npc.hunger > 75.0:
if npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD) >= 1.0:
return ActionSelectionResult.new(SimulationIds.ACTION_EAT)
return ActionSelectionResult.new(
SimulationIds.ACTION_EAT, -1.0, "Hungry and carrying food"
)
if village.food > 0:
return ActionSelectionResult.new(SimulationIds.ACTION_WITHDRAW_FOOD)
return ActionSelectionResult.new(SimulationIds.ACTION_GATHER_FOOD)
return ActionSelectionResult.new(
SimulationIds.ACTION_WITHDRAW_FOOD, -1.0, "Hungry; pantry has food"
)
return ActionSelectionResult.new(
SimulationIds.ACTION_GATHER_FOOD, -1.0, "Hungry; pantry is empty"
)
if npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD) > 0.0:
return ActionSelectionResult.new(SimulationIds.ACTION_DEPOSIT_FOOD)
return ActionSelectionResult.new(
SimulationIds.ACTION_DEPOSIT_FOOD, -1.0, "Carrying food for storage"
)
if npc.energy < 25.0:
return ActionSelectionResult.new(SimulationIds.ACTION_REST)
return ActionSelectionResult.new(_choose_best_work_action(npc, village))
return ActionSelectionResult.new(
SimulationIds.ACTION_REST, -1.0, "Energy is below the rest threshold"
)
return _choose_best_work_action(npc, village)
func _choose_best_work_action(npc: SimNPC, village: SimVillage) -> StringName:
func _choose_best_work_action(npc: SimNPC, village: SimVillage) -> ActionSelectionResult:
var scores := {
SimulationIds.ACTION_GATHER_FOOD:
_calculate_score(
@@ -80,7 +96,9 @@ func _choose_best_work_action(npc: SimNPC, village: SimVillage) -> StringName:
if score > best_score:
best_action = action_id
best_score = score
return best_action
return ActionSelectionResult.new(
best_action, -1.0, "Highest current work utility", scores
)
func _calculate_score(