MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / NetworkGetCompanyStats

Function NetworkGetCompanyStats

src/network/network_server.cpp:1491–1523  ·  view source on GitHub ↗

* Get the company stats. */

Source from the content-addressed store, hash-verified

1489 * Get the company stats.
1490 */
1491NetworkCompanyStatsArray NetworkGetCompanyStats()
1492{
1493 NetworkCompanyStatsArray stats = {};
1494
1495 /* Go through all vehicles and count the type of vehicles */
1496 for (const Vehicle *v : Vehicle::Iterate()) {
1497 if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
1498 uint8_t type = 0;
1499 switch (v->type) {
1500 case VEH_TRAIN: type = NETWORK_VEH_TRAIN; break;
1501 case VEH_ROAD: type = RoadVehicle::From(v)->IsBus() ? NETWORK_VEH_BUS : NETWORK_VEH_LORRY; break;
1502 case VEH_AIRCRAFT: type = NETWORK_VEH_PLANE; break;
1503 case VEH_SHIP: type = NETWORK_VEH_SHIP; break;
1504 default: continue;
1505 }
1506 stats[v->owner].num_vehicle[type]++;
1507 }
1508
1509 /* Go through all stations and count the types of stations */
1510 for (const Station *s : Station::Iterate()) {
1511 if (Company::IsValidID(s->owner)) {
1512 NetworkCompanyStats *npi = &stats[s->owner];
1513
1514 if (s->facilities.Test(StationFacility::Train)) npi->num_station[NETWORK_VEH_TRAIN]++;
1515 if (s->facilities.Test(StationFacility::TruckStop)) npi->num_station[NETWORK_VEH_LORRY]++;
1516 if (s->facilities.Test(StationFacility::BusStop)) npi->num_station[NETWORK_VEH_BUS]++;
1517 if (s->facilities.Test(StationFacility::Airport)) npi->num_station[NETWORK_VEH_PLANE]++;
1518 if (s->facilities.Test(StationFacility::Dock)) npi->num_station[NETWORK_VEH_SHIP]++;
1519 }
1520 }
1521
1522 return stats;
1523}
1524
1525/**
1526 * Send updated client info of a particular client.

Callers 1

SendCompanyStatsMethod · 0.85

Calls 3

IsBusMethod · 0.80
TestMethod · 0.80
IsPrimaryVehicleMethod · 0.45

Tested by

no test coverage detected