diff options
author | michi_cc <michi_cc@openttd.org> | 2012-02-11 22:43:39 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2012-02-11 22:43:39 +0000 |
commit | 0542e26460cf5da6fb4a3486ed9b515721bdb0bd (patch) | |
tree | 901640a66314b34ff1bc6a72b67dc288683a79c9 | |
parent | 1cf2f521ab32279b6770a79e7fb50ef5bbcd4011 (diff) | |
download | openttd-0542e26460cf5da6fb4a3486ed9b515721bdb0bd.tar.xz |
(svn r23931) -Change: Scale infrastructure cost of rail tracks by the total number of all tracks and not independently for each rail type.
-rw-r--r-- | src/company_base.h | 8 | ||||
-rw-r--r-- | src/company_gui.cpp | 12 | ||||
-rw-r--r-- | src/economy.cpp | 3 | ||||
-rw-r--r-- | src/rail.h | 7 | ||||
-rw-r--r-- | src/script/api/script_infrastructure.cpp | 6 | ||||
-rw-r--r-- | src/table/pricebase.h | 2 |
6 files changed, 27 insertions, 11 deletions
diff --git a/src/company_base.h b/src/company_base.h index 58c0a0ce0..0f9e8ae10 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -35,6 +35,14 @@ struct CompanyInfrastructure { uint32 water; ///< Count of company owned track bits for canals. uint32 station; ///< Count of company owned station tiles. uint32 airport; ///< Count of company owned airports. + + /** Get total sum of all owned track bits. */ + uint32 GetRailTotal() const + { + uint32 total = 0; + for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) total += this->rail[rt]; + return total; + } }; typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool; diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 6e24afa98..6804e98d1 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1588,8 +1588,9 @@ struct CompanyInfrastructureWindow : Window const Company *c = Company::Get((CompanyID)this->window_number); Money total; + uint32 rail_total = c->infrastructure.GetRailTotal(); for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) { - if (HasBit(this->railtypes, rt)) total += RailMaintenanceCost(rt, c->infrastructure.rail[rt]); + if (HasBit(this->railtypes, rt)) total += RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total); } total += SignalMaintenanceCost(c->infrastructure.signal); @@ -1675,9 +1676,10 @@ struct CompanyInfrastructureWindow : Window /* Find the maximum count that is displayed. */ uint32 max_val = 1000; // Some random number to reserve enough space. Money max_cost = 10000; // Some random number to reserve enough space. + uint32 rail_total = c->infrastructure.GetRailTotal(); for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) { max_val = max(max_val, c->infrastructure.rail[rt]); - max_cost = max(max_cost, RailMaintenanceCost(rt, c->infrastructure.rail[rt])); + max_cost = max(max_cost, RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total)); } max_val = max(max_val, c->infrastructure.signal); max_cost = max(max_cost, SignalMaintenanceCost(c->infrastructure.signal)); @@ -1739,12 +1741,13 @@ struct CompanyInfrastructureWindow : Window break; - case WID_CI_RAIL_COUNT: + case WID_CI_RAIL_COUNT: { /* Draw infrastructure count for each valid railtype. */ + uint32 rail_total = c->infrastructure.GetRailTotal(); for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) { if (HasBit(this->railtypes, rt)) { SetDParam(0, c->infrastructure.rail[rt]); - SetDParam(1, RailMaintenanceCost(rt, c->infrastructure.rail[rt]) * 12); // Convert to per year + SetDParam(1, RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total) * 12); // Convert to per year DrawString(r.left, r.right, y += FONT_HEIGHT_NORMAL, _settings_game.economy.infrastructure_maintenance ? STR_COMPANY_INFRASTRUCTURE_VIEW_COST : STR_WHITE_COMMA); } } @@ -1754,6 +1757,7 @@ struct CompanyInfrastructureWindow : Window DrawString(r.left, r.right, y += FONT_HEIGHT_NORMAL, _settings_game.economy.infrastructure_maintenance ? STR_COMPANY_INFRASTRUCTURE_VIEW_COST : STR_WHITE_COMMA); } break; + } case WID_CI_ROAD_DESC: DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT); diff --git a/src/economy.cpp b/src/economy.cpp index 6e08b8638..e449465f8 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -597,8 +597,9 @@ static void CompaniesGenStatistics() cur_company.Change(c->index); CommandCost cost(EXPENSES_PROPERTY); + uint32 rail_total = c->infrastructure.GetRailTotal(); for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) { - if (c->infrastructure.rail[rt] != 0) cost.AddCost(RailMaintenanceCost(rt, c->infrastructure.rail[rt])); + if (c->infrastructure.rail[rt] != 0) cost.AddCost(RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total)); } cost.AddCost(SignalMaintenanceCost(c->infrastructure.signal)); for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) { diff --git a/src/rail.h b/src/rail.h index b8ef0cb12..03bc69364 100644 --- a/src/rail.h +++ b/src/rail.h @@ -379,13 +379,14 @@ static inline Money RailConvertCost(RailType from, RailType to) /** * Calculates the maintenance cost of a number of track bits. * @param railtype The railtype to get the cost of. - * @param num Number of track bits. + * @param num Number of track bits of this railtype. + * @param total_num Total number of track bits of all railtypes. * @return Total cost. */ -static inline Money RailMaintenanceCost(RailType railtype, uint32 num) +static inline Money RailMaintenanceCost(RailType railtype, uint32 num, uint32 total_num) { assert(railtype < RAILTYPE_END); - return (_price[PR_INFRASTRUCTURE_RAIL] * GetRailTypeInfo(railtype)->maintenance_multiplier * num * (1 + IntSqrt(num))) >> 11; // 4 bits fraction for the multiplier and 7 bits scaling. + return (_price[PR_INFRASTRUCTURE_RAIL] * GetRailTypeInfo(railtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 11; // 4 bits fraction for the multiplier and 7 bits scaling. } /** diff --git a/src/script/api/script_infrastructure.cpp b/src/script/api/script_infrastructure.cpp index 2b1e203c8..1ce051bba 100644 --- a/src/script/api/script_infrastructure.cpp +++ b/src/script/api/script_infrastructure.cpp @@ -79,7 +79,8 @@ company = ScriptCompany::ResolveCompanyID(company); if (company == ScriptCompany::COMPANY_INVALID || (::RailType)railtype >= RAILTYPE_END || !_settings_game.economy.infrastructure_maintenance) return 0; - return ::RailMaintenanceCost((::RailType)railtype, ::Company::Get((::CompanyID)company)->infrastructure.rail[railtype]); + const ::Company *c = ::Company::Get((::CompanyID)company); + return ::RailMaintenanceCost((::RailType)railtype, c->infrastructure.rail[railtype], c->infrastructure.GetRailTotal()); } /* static */ Money ScriptInfrastructure::GetMonthlyRoadCosts(ScriptCompany::CompanyID company, ScriptRoad::RoadType roadtype) @@ -99,8 +100,9 @@ switch (infra_type) { case INFRASTRUCTURE_RAIL: { Money cost; + uint32 rail_total = c->infrastructure.GetRailTotal(); for (::RailType rt = ::RAILTYPE_BEGIN; rt != ::RAILTYPE_END; rt++) { - cost += RailMaintenanceCost(rt, c->infrastructure.rail[rt]); + cost += RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total); } return cost; } diff --git a/src/table/pricebase.h b/src/table/pricebase.h index ee62e9faf..9dc2ee2ba 100644 --- a/src/table/pricebase.h +++ b/src/table/pricebase.h @@ -76,7 +76,7 @@ extern const PriceBaseSpec _price_base_specs[] = { { 2000, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_BRIDGE }, ///< PR_CLEAR_AQUEDUCT { 7500, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_WATER }, ///< PR_BUILD_LOCK { 2000, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_WATER }, ///< PR_CLEAR_LOCK - { 12, PCAT_RUNNING, GSF_END, PR_BUILD_RAIL }, ///< PR_INFRASTRUCTURE_RAIL + { 10, PCAT_RUNNING, GSF_END, PR_BUILD_RAIL }, ///< PR_INFRASTRUCTURE_RAIL { 10, PCAT_RUNNING, GSF_END, PR_BUILD_ROAD }, ///< PR_INFRASTRUCTURE_ROAD { 8, PCAT_RUNNING, GSF_END, PR_BUILD_CANAL }, ///< PR_INFRASTRUCTURE_WATER { 100, PCAT_RUNNING, GSF_END, PR_STATION_VALUE }, ///< PR_INFRASTRUCTURE_STATION |