From 8094975094eee7c1701fb642b47826c147f5e2f2 Mon Sep 17 00:00:00 2001 From: Rijad Zuzo Date: Wed, 8 Jul 2026 21:22:43 +0200 Subject: [PATCH] feat: resource depletion events and village event feed Record resource_depleted narrative events when NPC or player extraction exhausts a ResourceNode. Add get_recent_events() for cross-NPC event queries. Village panel now shows the last 3 village-wide events as a readable feed below the resource counters, making shortages and depletion visible without opening the inspector. --- simulation/SimulationManager.gd | 18 ++++++++++++++++++ world/ui/ui.gd | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/simulation/SimulationManager.gd b/simulation/SimulationManager.gd index c254779..1416c7f 100644 --- a/simulation/SimulationManager.gd +++ b/simulation/SimulationManager.gd @@ -195,6 +195,12 @@ func simulate_tick() -> void: resource_state.get_resource_id(), extracted ) + if resource_state.get_amount_remaining() <= 0.0: + record_narrative_event( + SimulationIds.EVENT_RESOURCE_DEPLETED, + npc.id, + resource_state.get_node_id() + ) if debug_logs: print( "[SimulationManager] ", @@ -495,6 +501,14 @@ func get_npc_events(npc_id: int, max_count: int = 8) -> Array[EconomicEventRecor return results +func get_recent_events(max_count: int = 5) -> Array[EconomicEventRecord]: + var results: Array[EconomicEventRecord] = [] + var start := maxi(economic_events.size() - max_count, 0) + for i in range(start, economic_events.size()): + results.append(economic_events[i]) + return results + + func _initialize_storage() -> void: if not storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY): storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = (StorageStateRecord.create( @@ -727,6 +741,10 @@ func harvest_resource_node(node: ResourceNode) -> float: resource_state.get_resource_id(), extracted ) + if resource_state.get_amount_remaining() <= 0.0: + record_narrative_event( + SimulationIds.EVENT_RESOURCE_DEPLETED, -1, resource_state.get_node_id() + ) village_changed.emit(village) if debug_logs: diff --git a/world/ui/ui.gd b/world/ui/ui.gd index 0109713..515281e 100644 --- a/world/ui/ui.gd +++ b/world/ui/ui.gd @@ -52,6 +52,17 @@ func _unhandled_key_input(event: InputEvent) -> void: func _on_village_changed(village: SimVillage) -> void: + var name_map := {} + for npc in simulation_manager.npcs: + name_map[npc.id] = npc.npc_name + var event_lines: Array[String] = [] + for event in simulation_manager.get_recent_events(3): + event_lines.append(event.description(name_map)) + var event_text := "\n".join(event_lines) + if event_text.is_empty(): + event_text = "" + else: + event_text = "\n" + event_text village_stats_label.text = ( """ Village @@ -65,6 +76,7 @@ func _on_village_changed(village: SimVillage) -> void: Food Mod: %.2f Safety Mod: %.2f Knowledge Mod: %.2f + %s """ % [ round(village.food), @@ -74,7 +86,8 @@ func _on_village_changed(village: SimVillage) -> void: simulation_manager.get_starving_count(), village.food_modifier, village.safety_modifier, - village.knowledge_modifier + village.knowledge_modifier, + event_text ] )