* Update the finances of all companies. * Pay for the stations, update the history graph, update ratings and company values, and deal with bankruptcy. */
| 639 | * Pay for the stations, update the history graph, update ratings and company values, and deal with bankruptcy. |
| 640 | */ |
| 641 | static void CompaniesGenStatistics() |
| 642 | { |
| 643 | /* Check for bankruptcy each month */ |
| 644 | for (Company *c : Company::Iterate()) { |
| 645 | CompanyCheckBankrupt(c); |
| 646 | } |
| 647 | |
| 648 | Backup<CompanyID> cur_company(_current_company); |
| 649 | |
| 650 | /* Pay Infrastructure Maintenance, if enabled */ |
| 651 | if (_settings_game.economy.infrastructure_maintenance) { |
| 652 | /* Improved monthly infrastructure costs. */ |
| 653 | for (const Company *c : Company::Iterate()) { |
| 654 | cur_company.Change(c->index); |
| 655 | |
| 656 | CommandCost cost(EXPENSES_PROPERTY); |
| 657 | uint32_t rail_total = c->infrastructure.GetRailTotal(); |
| 658 | for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) { |
| 659 | if (c->infrastructure.rail[rt] != 0) cost.AddCost(RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total)); |
| 660 | } |
| 661 | cost.AddCost(SignalMaintenanceCost(c->infrastructure.signal)); |
| 662 | uint32_t road_total = c->infrastructure.GetRoadTotal(); |
| 663 | uint32_t tram_total = c->infrastructure.GetTramTotal(); |
| 664 | for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) { |
| 665 | if (c->infrastructure.road[rt] != 0) cost.AddCost(RoadMaintenanceCost(rt, c->infrastructure.road[rt], RoadTypeIsRoad(rt) ? road_total : tram_total)); |
| 666 | } |
| 667 | cost.AddCost(CanalMaintenanceCost(c->infrastructure.water)); |
| 668 | cost.AddCost(StationMaintenanceCost(c->infrastructure.station)); |
| 669 | cost.AddCost(AirportMaintenanceCost(c->index)); |
| 670 | |
| 671 | SubtractMoneyFromCompany(cost); |
| 672 | } |
| 673 | } |
| 674 | cur_company.Restore(); |
| 675 | |
| 676 | /* Only run the economic statistics and update company stats every 3rd economy month (1st of quarter). */ |
| 677 | if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, TimerGameEconomy::month)) return; |
| 678 | |
| 679 | for (Company *c : Company::Iterate()) { |
| 680 | /* Drop the oldest history off the end */ |
| 681 | std::copy_backward(c->old_economy.data(), c->old_economy.data() + MAX_HISTORY_QUARTERS - 1, c->old_economy.data() + MAX_HISTORY_QUARTERS); |
| 682 | c->old_economy[0] = c->cur_economy; |
| 683 | c->cur_economy = {}; |
| 684 | |
| 685 | if (c->num_valid_stat_ent != MAX_HISTORY_QUARTERS) c->num_valid_stat_ent++; |
| 686 | |
| 687 | UpdateCompanyRatingAndValue(c, true); |
| 688 | if (c->block_preview != 0) c->block_preview--; |
| 689 | } |
| 690 | |
| 691 | SetWindowDirty(WC_INCOME_GRAPH, 0); |
| 692 | SetWindowDirty(WC_OPERATING_PROFIT, 0); |
| 693 | SetWindowDirty(WC_DELIVERED_CARGO, 0); |
| 694 | SetWindowDirty(WC_PERFORMANCE_HISTORY, 0); |
| 695 | SetWindowDirty(WC_COMPANY_VALUE, 0); |
| 696 | SetWindowDirty(WC_COMPANY_LEAGUE, 0); |
| 697 | } |
| 698 |
no test coverage detected