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

Method UpdateInfrastructureList

src/company_gui.cpp:1593–1684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1591 }
1592
1593 void UpdateInfrastructureList()
1594 {
1595 this->list.clear();
1596
1597 const Company *c = Company::GetIfValid(this->window_number);
1598 if (c == nullptr) return;
1599
1600 Money total_monthly_cost = 0;
1601
1602 if (uint32_t rail_total = c->infrastructure.GetRailTotal(); rail_total > 0) {
1603 /* Rail types and signals. */
1604 this->list.emplace_back(InfrastructureItemType::Header, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT);
1605
1606 for (const RailType &rt : _sorted_railtypes) {
1607 if (c->infrastructure.rail[rt] == 0) continue;
1608 Money monthly_cost = RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total);
1609 total_monthly_cost += monthly_cost;
1610 this->list.emplace_back(InfrastructureItemType::Value, GetRailTypeInfo(rt)->strings.name, c->infrastructure.rail[rt], monthly_cost);
1611 }
1612
1613 if (c->infrastructure.signal > 0) {
1614 Money monthly_cost = SignalMaintenanceCost(c->infrastructure.signal);
1615 total_monthly_cost += monthly_cost;
1616 this->list.emplace_back(InfrastructureItemType::Value, STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS, c->infrastructure.signal, monthly_cost);
1617 }
1618 }
1619
1620 if (uint32_t road_total = c->infrastructure.GetRoadTotal(); road_total > 0) {
1621 /* Road types. */
1622 if (!this->list.empty()) this->list.emplace_back(InfrastructureItemType::Spacer);
1623 this->list.emplace_back(InfrastructureItemType::Header, STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT);
1624
1625 for (const RoadType &rt : _sorted_roadtypes) {
1626 if (!RoadTypeIsRoad(rt)) continue;
1627 if (c->infrastructure.road[rt] == 0) continue;
1628 Money monthly_cost = RoadMaintenanceCost(rt, c->infrastructure.road[rt], road_total);
1629 total_monthly_cost += monthly_cost;
1630 this->list.emplace_back(InfrastructureItemType::Value, GetRoadTypeInfo(rt)->strings.name, c->infrastructure.road[rt], monthly_cost);
1631 }
1632 }
1633
1634 if (uint32_t tram_total = c->infrastructure.GetTramTotal(); tram_total > 0) {
1635 /* Tram types. */
1636 if (!this->list.empty()) this->list.emplace_back(InfrastructureItemType::Spacer);
1637 this->list.emplace_back(InfrastructureItemType::Header, STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT);
1638
1639 for (const RoadType &rt : _sorted_roadtypes) {
1640 if (!RoadTypeIsTram(rt)) continue;
1641 if (c->infrastructure.road[rt] == 0) continue;
1642 Money monthly_cost = RoadMaintenanceCost(rt, c->infrastructure.road[rt], tram_total);
1643 total_monthly_cost += monthly_cost;
1644 this->list.emplace_back(InfrastructureItemType::Value, GetRoadTypeInfo(rt)->strings.name, c->infrastructure.road[rt], monthly_cost);
1645 }
1646 }
1647
1648 if (c->infrastructure.water > 0) {
1649 /* Canals, locks, and ship depots (docks are counted as stations). */
1650 if (!this->list.empty()) this->list.emplace_back(InfrastructureItemType::Spacer);

Callers 2

OnInitMethod · 0.95

Calls 15

RailMaintenanceCostFunction · 0.85
GetRailTypeInfoFunction · 0.85
SignalMaintenanceCostFunction · 0.85
RoadTypeIsRoadFunction · 0.85
RoadMaintenanceCostFunction · 0.85
GetRoadTypeInfoFunction · 0.85
RoadTypeIsTramFunction · 0.85
CanalMaintenanceCostFunction · 0.85
AirportMaintenanceCostFunction · 0.85
StationMaintenanceCostFunction · 0.85
GetRailTotalMethod · 0.80
GetRoadTotalMethod · 0.80

Tested by

no test coverage detected