diff options
author | michi_cc <michi_cc@openttd.org> | 2011-12-03 23:40:46 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2011-12-03 23:40:46 +0000 |
commit | d3b7b89493e025654d218fb77da095649b4f6ba2 (patch) | |
tree | 6667e4164c5c8bda4c1b7092376872b315c65610 /src/economy.cpp | |
parent | f98312eb77e12cfa45de40a1b4e8359160b0d9ff (diff) | |
download | openttd-d3b7b89493e025654d218fb77da095649b4f6ba2.tar.xz |
(svn r23415) -Feature: Infrastructure maintenance costs.
Diffstat (limited to 'src/economy.cpp')
-rw-r--r-- | src/economy.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index ada4fc227..9fa2e11de 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -46,6 +46,7 @@ #include "core/pool_func.hpp" #include "newgrf.h" #include "core/backup_type.hpp" +#include "water.h" #include "table/strings.h" #include "table/pricebase.h" @@ -584,17 +585,39 @@ static void CompaniesGenStatistics() Station *st; Backup<CompanyByte> cur_company(_current_company, FILE_LINE); - FOR_ALL_STATIONS(st) { - cur_company.Change(st->owner); - CommandCost cost(EXPENSES_PROPERTY, _price[PR_STATION_VALUE] >> 1); - SubtractMoneyFromCompany(cost); + Company *c; + + if (!_settings_game.economy.infrastructure_maintenance) { + FOR_ALL_STATIONS(st) { + cur_company.Change(st->owner); + CommandCost cost(EXPENSES_PROPERTY, _price[PR_STATION_VALUE] >> 1); + SubtractMoneyFromCompany(cost); + } + } else { + /* Improved monthly infrastructure costs. */ + FOR_ALL_COMPANIES(c) { + cur_company.Change(c->index); + + CommandCost cost(EXPENSES_PROPERTY); + for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) { + if (c->infrastructure.rail[rt] != 0) cost.AddCost(RailMaintenanceCost(rt, c->infrastructure.rail[rt])); + } + cost.AddCost(SignalMaintenanceCost(c->infrastructure.signal)); + for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) { + if (c->infrastructure.road[rt] != 0) cost.AddCost(RoadMaintenanceCost(rt, c->infrastructure.road[rt])); + } + cost.AddCost(CanalMaintenanceCost(c->infrastructure.water)); + cost.AddCost(StationMaintenanceCost(c->infrastructure.station)); + cost.AddCost(AirportMaintenanceCost(c->index)); + + SubtractMoneyFromCompany(cost); + } } cur_company.Restore(); /* Only run the economic statics and update company stats every 3rd month (1st of quarter). */ if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return; - Company *c; FOR_ALL_COMPANIES(c) { memmove(&c->old_economy[1], &c->old_economy[0], sizeof(c->old_economy) - sizeof(c->old_economy[0])); c->old_economy[0] = c->cur_economy; @@ -713,6 +736,7 @@ void RecomputePrices() SetWindowClassesDirty(WC_BUILD_VEHICLE); SetWindowClassesDirty(WC_REPLACE_VEHICLE); SetWindowClassesDirty(WC_VEHICLE_DETAILS); + SetWindowClassesDirty(WC_COMPANY_INFRASTRUCTURE); InvalidateWindowData(WC_PAYMENT_RATES, 0); } |