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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user