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