* Window with detailed information about the company's infrastructure. */
| 1559 | * Window with detailed information about the company's infrastructure. |
| 1560 | */ |
| 1561 | struct CompanyInfrastructureWindow : Window |
| 1562 | { |
| 1563 | enum class InfrastructureItemType : uint8_t { |
| 1564 | Header, ///< Section header. |
| 1565 | Spacer, ///< Spacer |
| 1566 | Value, ///< Label with values. |
| 1567 | Total, ///< Total cost. |
| 1568 | }; |
| 1569 | |
| 1570 | struct InfrastructureItem { |
| 1571 | InfrastructureItemType type; |
| 1572 | StringID label; |
| 1573 | uint count; |
| 1574 | Money cost; |
| 1575 | }; |
| 1576 | |
| 1577 | uint count_width = 0; |
| 1578 | uint cost_width = 0; |
| 1579 | |
| 1580 | mutable std::vector<InfrastructureItem> list; |
| 1581 | |
| 1582 | CompanyInfrastructureWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc) |
| 1583 | { |
| 1584 | this->InitNested(window_number); |
| 1585 | this->owner = this->window_number; |
| 1586 | } |
| 1587 | |
| 1588 | void OnInit() override |
| 1589 | { |
| 1590 | this->UpdateInfrastructureList(); |
| 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 | } |
nothing calls this directly
no test coverage detected