(svn r23931) -Change: Scale infrastructure cost of rail tracks by the total number of all tracks and not independently for each rail type.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
michi_cc 12 years ago
parent 1cf2f521ab
commit 0542e26460

@ -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;

@ -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);

@ -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++) {

@ -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.
}
/**

@ -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;
}

@ -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

Loading…
Cancel
Save