1
0
Fork 0

Codechange: Iterate group vehicle lists for GroupStatistics::UpdateProfits

pull/10548/head
SamuXarick 2023-12-30 16:20:08 +00:00
parent 89c69f991c
commit 4ee690b911
1 changed files with 11 additions and 13 deletions

View File

@ -204,26 +204,24 @@ void GroupStatistics::Clear()
*/
/* static */ void GroupStatistics::UpdateProfits()
{
/* Set up the engine count for all companies */
for (Company *c : Company::Iterate()) {
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
c->group_all[type].ClearProfits();
c->group_default[type].ClearProfits();
}
}
/* Recalculate */
for (Group *g : Group::Iterate()) {
g->statistics.ClearProfits();
}
for (const Vehicle *v : Vehicle::Iterate()) {
if (v->IsPrimaryVehicle()) {
for (Company *c : Company::Iterate()) {
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
c->group_all[type].ClearProfits();
c->group_default[type].ClearProfits();
/* Recalculate */
const VehicleList &vehicle_list = c->group_all[type].vehicle_list;
for (const Vehicle *v : vehicle_list) {
GroupStatistics::AddProfitLastYear(v);
if (v->age > VEHICLE_PROFIT_MIN_AGE) GroupStatistics::VehicleReachedMinAge(v);
}
}
}
}
/**
* Update autoreplace_defined and autoreplace_finished of all statistics of a company.