Changeset - r19063:6deb502206fb
[Not reviewed]
master
0 6 0
michi_cc - 12 years ago 2012-02-11 22:43:39
michi_cc@openttd.org
(svn r23931) -Change: Scale infrastructure cost of rail tracks by the total number of all tracks and not independently for each rail type.
6 files changed with 27 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/company_base.h
Show inline comments
 
@@ -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;
src/company_gui.cpp
Show inline comments
 
@@ -1588,8 +1588,9 @@ struct CompanyInfrastructureWindow : Win
 
		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 : Win
 
				/* 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 : Win
 

	
 
				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 : Win
 
					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);
src/economy.cpp
Show inline comments
 
@@ -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++) {
src/rail.h
Show inline comments
 
@@ -379,13 +379,14 @@ static inline Money RailConvertCost(Rail
 
/**
 
 * 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.
 
}
 

	
 
/**
src/script/api/script_infrastructure.cpp
Show inline comments
 
@@ -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;
 
		}
src/table/pricebase.h
Show inline comments
 
@@ -76,7 +76,7 @@ extern const PriceBaseSpec _price_base_s
 
	{   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
0 comments (0 inline, 0 general)