1
0
Fork 0

Codechange: Iterate group vehicle lists for NetworkPopulateCompanyStats and NetworkAutoCleanCompanies

pull/10548/head
SamuXarick 2023-12-30 23:46:19 +00:00
parent becb273ed4
commit 17c6259f5c
1 changed files with 18 additions and 13 deletions

View File

@ -1442,17 +1442,21 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
memset(stats, 0, sizeof(*stats) * MAX_COMPANIES); memset(stats, 0, sizeof(*stats) * MAX_COMPANIES);
/* Go through all vehicles and count the type of vehicles */ /* Go through all vehicles and count the type of vehicles */
for (const Vehicle *v : Vehicle::Iterate()) { for (const Company *c : Company::Iterate()) {
if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue; for (VehicleType vtype = VEH_BEGIN; vtype < VEH_COMPANY_END; vtype++) {
byte type = 0; const VehicleList &vehicle_list = c->group_all[vtype].vehicle_list;
switch (v->type) { for (const Vehicle *v : vehicle_list) {
case VEH_TRAIN: type = NETWORK_VEH_TRAIN; break; byte type = 0;
case VEH_ROAD: type = RoadVehicle::From(v)->IsBus() ? NETWORK_VEH_BUS : NETWORK_VEH_LORRY; break; switch (vtype) {
case VEH_AIRCRAFT: type = NETWORK_VEH_PLANE; break; case VEH_TRAIN: type = NETWORK_VEH_TRAIN; break;
case VEH_SHIP: type = NETWORK_VEH_SHIP; break; case VEH_ROAD: type = RoadVehicle::From(v)->IsBus() ? NETWORK_VEH_BUS : NETWORK_VEH_LORRY; break;
default: continue; case VEH_AIRCRAFT: type = NETWORK_VEH_PLANE; break;
case VEH_SHIP: type = NETWORK_VEH_SHIP; break;
default: continue;
}
stats[c->index].num_vehicle[type]++;
}
} }
stats[v->owner].num_vehicle[type]++;
} }
/* Go through all stations and count the types of stations */ /* Go through all stations and count the types of stations */
@ -1542,9 +1546,10 @@ static void NetworkAutoCleanCompanies()
if (_settings_client.network.autoclean_novehicles != 0) { if (_settings_client.network.autoclean_novehicles != 0) {
memset(vehicles_in_company, 0, sizeof(vehicles_in_company)); memset(vehicles_in_company, 0, sizeof(vehicles_in_company));
for (const Vehicle *v : Vehicle::Iterate()) { for (const Company *c : Company::Iterate()) {
if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue; for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
vehicles_in_company[v->owner]++; vehicles_in_company[c->index] += (int)c->group_all[type].vehicle_list.size();
}
} }
} }