Add station cargo history

This commit is contained in:
Andreas Schmitt
2021-06-23 08:21:29 +02:00
parent f3b39b12a8
commit 9b1783809d
13 changed files with 352 additions and 1 deletions

View File

@@ -404,6 +404,23 @@ void Station::GetTileArea(TileArea *ta, StationType type) const
}
}
/**
* Update the cargo history.
*/
void Station::UpdateCargoHistory()
{
const CargoSpec* cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
auto amount = this->goods[cs->Index()].cargo.AvailableCount();
std::rotate(std::begin(this->station_cargo_history) + cs->Index() * MAX_STATION_CARGO_HISTORY_DAYS,
std::begin(this->station_cargo_history) + cs->Index() * MAX_STATION_CARGO_HISTORY_DAYS + 1,
std::begin(this->station_cargo_history) + (cs->Index() + 1) * MAX_STATION_CARGO_HISTORY_DAYS);
this->station_cargo_history[(cs->Index() + 1) * MAX_STATION_CARGO_HISTORY_DAYS - 1] = std::clamp(amount / STATION_CARGO_HISTORY_FACTOR, (uint)0, (uint)UINT8_MAX);
}
}
/**
* Update the virtual coords needed to draw the station sign.
*/
@@ -4240,6 +4257,17 @@ void OnTick_Station()
}
}
/** Daily loop for stations. */
void StationDailyLoop()
{
// Only record cargo history every second day.
if (_date % 2 != 0) {
for (Station *st : Station::Iterate()) {
st->UpdateCargoHistory();
}
}
}
/** Monthly loop for stations. */
void StationMonthlyLoop()
{