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.
This commit is contained in:
@@ -195,6 +195,12 @@ func simulate_tick() -> void:
|
|||||||
resource_state.get_resource_id(),
|
resource_state.get_resource_id(),
|
||||||
extracted
|
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:
|
if debug_logs:
|
||||||
print(
|
print(
|
||||||
"[SimulationManager] ",
|
"[SimulationManager] ",
|
||||||
@@ -495,6 +501,14 @@ func get_npc_events(npc_id: int, max_count: int = 8) -> Array[EconomicEventRecor
|
|||||||
return results
|
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:
|
func _initialize_storage() -> void:
|
||||||
if not storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY):
|
if not storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY):
|
||||||
storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = (StorageStateRecord.create(
|
storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = (StorageStateRecord.create(
|
||||||
@@ -727,6 +741,10 @@ func harvest_resource_node(node: ResourceNode) -> float:
|
|||||||
resource_state.get_resource_id(),
|
resource_state.get_resource_id(),
|
||||||
extracted
|
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)
|
village_changed.emit(village)
|
||||||
|
|
||||||
if debug_logs:
|
if debug_logs:
|
||||||
|
|||||||
+14
-1
@@ -52,6 +52,17 @@ func _unhandled_key_input(event: InputEvent) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_village_changed(village: SimVillage) -> 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_stats_label.text = (
|
||||||
"""
|
"""
|
||||||
Village
|
Village
|
||||||
@@ -65,6 +76,7 @@ func _on_village_changed(village: SimVillage) -> void:
|
|||||||
Food Mod: %.2f
|
Food Mod: %.2f
|
||||||
Safety Mod: %.2f
|
Safety Mod: %.2f
|
||||||
Knowledge Mod: %.2f
|
Knowledge Mod: %.2f
|
||||||
|
%s
|
||||||
"""
|
"""
|
||||||
% [
|
% [
|
||||||
round(village.food),
|
round(village.food),
|
||||||
@@ -74,7 +86,8 @@ func _on_village_changed(village: SimVillage) -> void:
|
|||||||
simulation_manager.get_starving_count(),
|
simulation_manager.get_starving_count(),
|
||||||
village.food_modifier,
|
village.food_modifier,
|
||||||
village.safety_modifier,
|
village.safety_modifier,
|
||||||
village.knowledge_modifier
|
village.knowledge_modifier,
|
||||||
|
event_text
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user