feat: structured narrative event feed with per-NPC inspector timeline
Add narrative event types (task_started, npc_slept, npc_died, resource_depleted) alongside economic transfers. EconomicEventRecord gains create_narrative factory and human-readable description method. SimulationManager records task-start and sleep/death events, exposes get_npc_events() for per-NPC history queries. Inspector now shows a Recent timeline of the last 5 events for the selected NPC, plus displays carried wood count. Relax EconomicEventRecord validation to accept non-economic events. Update roadmap with completed milestones.
This commit is contained in:
@@ -126,6 +126,13 @@ func simulate_tick() -> void:
|
||||
latest_decisions[npc.id] = selection
|
||||
npc_decision_recorded.emit(npc, selection)
|
||||
npc.set_task(selection.action_id, selection.duration_override)
|
||||
var action_def := SimulationDefinitions.get_action(selection.action_id)
|
||||
var action_display := String(selection.action_id)
|
||||
if action_def != null:
|
||||
action_display = action_def.display_name
|
||||
record_narrative_event(
|
||||
SimulationIds.EVENT_TASK_STARTED, npc.id, &"", action_display
|
||||
)
|
||||
|
||||
if old_task != npc.current_task and old_target != &"":
|
||||
release_npc_reservation(npc.id)
|
||||
@@ -135,6 +142,7 @@ func simulate_tick() -> void:
|
||||
release_npc_reservation(npc.id)
|
||||
npc_died.emit(npc)
|
||||
npc_task_changed.emit(npc, old_task, npc.current_task)
|
||||
record_narrative_event(SimulationIds.EVENT_NPC_DIED, npc.id)
|
||||
|
||||
if debug_logs:
|
||||
print("[SimulationManager] NPC died: ", npc.npc_name)
|
||||
@@ -218,6 +226,7 @@ func simulate_tick() -> void:
|
||||
elif completed_task == SimulationIds.ACTION_SLEEP:
|
||||
npc.energy = minf(npc.energy + 40.0, 100.0)
|
||||
npc.position = npc.home_position
|
||||
record_narrative_event(SimulationIds.EVENT_NPC_SLEPT, npc.id)
|
||||
if debug_logs:
|
||||
print("[SimulationManager] ", npc.npc_name, " completed sleep at home")
|
||||
elif (
|
||||
@@ -460,6 +469,32 @@ func _record_economic_event(
|
||||
economic_event_recorded.emit(event)
|
||||
|
||||
|
||||
func record_narrative_event(
|
||||
event_type: StringName,
|
||||
actor_id: int,
|
||||
source_id: StringName = &"",
|
||||
action_display: String = ""
|
||||
) -> void:
|
||||
var event := EconomicEventRecord.create_narrative(
|
||||
next_event_id, event_type, tick_count, actor_id, source_id, action_display
|
||||
)
|
||||
next_event_id += 1
|
||||
economic_events.append(event)
|
||||
economic_event_recorded.emit(event)
|
||||
|
||||
|
||||
func get_npc_events(npc_id: int, max_count: int = 8) -> Array[EconomicEventRecord]:
|
||||
var results: Array[EconomicEventRecord] = []
|
||||
for i in range(economic_events.size() - 1, -1, -1):
|
||||
var event: EconomicEventRecord = economic_events[i]
|
||||
if event.data["actor_id"] == npc_id:
|
||||
results.append(event)
|
||||
if results.size() >= max_count:
|
||||
break
|
||||
results.reverse()
|
||||
return results
|
||||
|
||||
|
||||
func _initialize_storage() -> void:
|
||||
if not storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY):
|
||||
storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = (StorageStateRecord.create(
|
||||
|
||||
Reference in New Issue
Block a user