feat: add npc decision inspector
This commit is contained in:
@@ -8,6 +8,7 @@ signal npc_travel_requested(npc: SimNPC, target_position: Vector3)
|
||||
signal npc_inventory_changed(npc: SimNPC, item_id: StringName, amount: float)
|
||||
signal economic_event_recorded(event: EconomicEventRecord)
|
||||
signal state_restored
|
||||
signal npc_decision_recorded(npc: SimNPC, decision: ActionSelectionResult)
|
||||
|
||||
var village := SimVillage.new()
|
||||
|
||||
@@ -24,6 +25,7 @@ var resource_states: Dictionary = {}
|
||||
var storage_states: Dictionary = {}
|
||||
var economic_events: Array[EconomicEventRecord] = []
|
||||
var next_event_id := 0
|
||||
var latest_decisions: Dictionary = {}
|
||||
var action_selector := ActionSelectionSystem.new()
|
||||
var action_executor := ActionExecutionSystem.new()
|
||||
var target_resolver := ActionTargetResolver.new()
|
||||
@@ -111,6 +113,8 @@ func simulate_tick() -> void:
|
||||
):
|
||||
var selection := action_selector.select_action(npc, village)
|
||||
if selection != null:
|
||||
latest_decisions[npc.id] = selection
|
||||
npc_decision_recorded.emit(npc, selection)
|
||||
npc.set_task(selection.action_id, selection.duration_override)
|
||||
|
||||
if old_task != npc.current_task and old_target != &"":
|
||||
@@ -679,6 +683,10 @@ func get_state_checksum() -> String:
|
||||
return create_state_record().to_json().sha256_text()
|
||||
|
||||
|
||||
func get_latest_decision(npc_id: int) -> ActionSelectionResult:
|
||||
return latest_decisions.get(npc_id)
|
||||
|
||||
|
||||
func create_state_record() -> SimulationStateRecord:
|
||||
var record := SimulationStateRecord.new()
|
||||
var wander_streams: Array[Dictionary] = []
|
||||
@@ -747,6 +755,7 @@ func restore_state(record: SimulationStateRecord) -> bool:
|
||||
storage_states[storage_record.get_storage_id()] = storage_record
|
||||
_sync_village_food()
|
||||
economic_events = record.economic_events.duplicate()
|
||||
latest_decisions.clear()
|
||||
|
||||
npcs.clear()
|
||||
for npc_record in record.npcs:
|
||||
|
||||
Reference in New Issue
Block a user