feat: resource consumption rate display in village panel

Village panel now shows daily consumption rates alongside stockpiles (e.g. Food: 15 (-2/d), Wood: 7 (-1/d)). Rates are computed over a rolling 200-tick (~1 day) window by summing item_consumed economic events. The rate display only appears when non-zero, keeping the panel clean until actual consumption occurs. Closes the feedback loop: events show individual transfers, rates show aggregate trends.
This commit is contained in:
2026-07-09 01:18:33 +02:00
parent 6981c7e9bc
commit d6520c426a
2 changed files with 33 additions and 2 deletions
+22
View File
@@ -590,6 +590,28 @@ func get_current_speed() -> String:
return "%.2fx" % SPEED_LEVELS[speed_index]
func get_resource_rates() -> Dictionary:
var food_consumed := 0.0
var wood_consumed := 0.0
var recent_ticks := maxi(tick_count - 200, 0)
for event in economic_events:
if int(event.data["tick"]) < recent_ticks:
continue
if String(event.data["event_type"]) != "item_consumed":
continue
if float(event.data["amount"]) <= 0.0:
continue
if String(event.data["item_id"]) == "food":
food_consumed += float(event.data["amount"])
elif String(event.data["item_id"]) == "wood":
wood_consumed += float(event.data["amount"])
var elapsed := maxi(tick_count - recent_ticks, 1)
return {
"food_per_day": food_consumed / elapsed * 200.0,
"wood_per_day": wood_consumed / elapsed * 200.0
}
func _initialize_storage() -> void:
if not storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY):
storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = (StorageStateRecord.create(
+11 -2
View File
@@ -68,12 +68,19 @@ func _on_village_changed(village: SimVillage) -> void:
var speed_text := ""
if simulation_manager.has_method("get_current_speed"):
speed_text = simulation_manager.get_current_speed()
var rates: Dictionary = simulation_manager.get_resource_rates()
var food_rate := ""
if rates["food_per_day"] > 0.01:
food_rate = " (%.0f/d)" % rates["food_per_day"]
var wood_rate := ""
if rates["wood_per_day"] > 0.01:
wood_rate = " (%.0f/d)" % rates["wood_per_day"]
village_stats_label.text = (
"""
Village [%s]
Food: %s
Wood: %s
Food: %s%s
Wood: %s%s
Safety: %s
Knowledge: %s
Starving: %s
@@ -86,7 +93,9 @@ func _on_village_changed(village: SimVillage) -> void:
% [
speed_text,
round(village.food),
food_rate,
round(village.wood),
wood_rate,
round(village.safety),
round(village.knowledge),
simulation_manager.get_starving_count(),