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
 
@@ -32,12 +32,20 @@ struct CompanyInfrastructure {
 
	uint32 road[ROADTYPE_END]; ///< Count of company owned track bits for each road type.
 
	uint32 signal;             ///< Count of company owned signals.
 
	uint32 rail[RAILTYPE_END]; ///< Count of company owned track bits for each rail type.
 
	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;
 
extern CompanyPool _company_pool;
 

	
 

	
src/company_gui.cpp
Show inline comments
 
@@ -1585,14 +1585,15 @@ struct CompanyInfrastructureWindow : Win
 
	/** Get total infrastructure maintenance cost. */
 
	Money GetTotalMaintenanceCost() const
 
	{
 
		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);
 

	
 
		if (HasBit(this->roadtypes, ROADTYPE_ROAD)) total += RoadMaintenanceCost(ROADTYPE_ROAD, c->infrastructure.road[ROADTYPE_ROAD]);
 
		if (HasBit(this->roadtypes, ROADTYPE_TRAM)) total += RoadMaintenanceCost(ROADTYPE_TRAM, c->infrastructure.road[ROADTYPE_TRAM]);
 

	
 
@@ -1672,15 +1673,16 @@ struct CompanyInfrastructureWindow : Win
 
			case WID_CI_WATER_COUNT:
 
			case WID_CI_STATION_COUNT:
 
			case WID_CI_TOTAL: {
 
				/* 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));
 
				for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
 
					max_val = max(max_val, c->infrastructure.road[rt]);
 
					max_cost = max(max_cost, RoadMaintenanceCost(rt, c->infrastructure.road[rt]));
 
@@ -1736,27 +1738,29 @@ struct CompanyInfrastructureWindow : Win
 
					/* No valid railtype. */
 
					DrawString(r.left + offs_left, r.right - offs_right, y += FONT_HEIGHT_NORMAL, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
 
				}
 

	
 
				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);
 
					}
 
				}
 
				if (this->railtypes != RAILTYPES_NONE) {
 
					SetDParam(0, c->infrastructure.signal);
 
					SetDParam(1, SignalMaintenanceCost(c->infrastructure.signal) * 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);
 
				}
 
				break;
 
			}
 

	
 
			case WID_CI_ROAD_DESC:
 
				DrawString(r.left, r.right, y, STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT);
 

	
 
				if (this->roadtypes != ROADTYPES_NONE) {
 
					if (HasBit(this->roadtypes, ROADTYPE_ROAD)) DrawString(r.left + offs_left, r.right - offs_right, y += FONT_HEIGHT_NORMAL, STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD);
src/economy.cpp
Show inline comments
 
@@ -594,14 +594,15 @@ static void CompaniesGenStatistics()
 
	} else {
 
		/* Improved monthly infrastructure costs. */
 
		FOR_ALL_COMPANIES(c) {
 
			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++) {
 
				if (c->infrastructure.road[rt] != 0) cost.AddCost(RoadMaintenanceCost(rt, c->infrastructure.road[rt]));
 
			}
 
			cost.AddCost(CanalMaintenanceCost(c->infrastructure.water));
src/rail.h
Show inline comments
 
@@ -376,19 +376,20 @@ static inline Money RailConvertCost(Rail
 
	return rebuildcost;
 
}
 

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

	
 
/**
 
 * Calculates the maintenance cost of a number of signals.
 
 * @param num Number of signals.
 
 * @return Total cost.
src/script/api/script_infrastructure.cpp
Show inline comments
 
@@ -76,13 +76,14 @@
 

	
 
/* static */ Money ScriptInfrastructure::GetMonthlyRailCosts(ScriptCompany::CompanyID company, ScriptRail::RailType railtype)
 
{
 
	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)
 
{
 
	company = ScriptCompany::ResolveCompanyID(company);
 
	if (company == ScriptCompany::COMPANY_INVALID || (::RoadType)roadtype >= ROADTYPE_END || !_settings_game.economy.infrastructure_maintenance) return 0;
 
@@ -96,14 +97,15 @@
 
	if (company == ScriptCompany::COMPANY_INVALID || !_settings_game.economy.infrastructure_maintenance) return 0;
 

	
 
	::Company *c = ::Company::Get((::CompanyID)company);
 
	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;
 
		}
 

	
 
		case INFRASTRUCTURE_SIGNALS:
 
			return SignalMaintenanceCost(c->infrastructure.signal);
src/table/pricebase.h
Show inline comments
 
@@ -73,13 +73,13 @@ extern const PriceBaseSpec _price_base_s
 
	{   5000, PCAT_CONSTRUCTION, GSF_END,          PR_CLEAR_WATER        }, ///< PR_BUILD_CANAL
 
	{   5000, PCAT_CONSTRUCTION, GSF_END,          PR_CLEAR_WATER        }, ///< PR_CLEAR_CANAL
 
	{  10000, PCAT_CONSTRUCTION, GSF_END,          PR_CLEAR_WATER        }, ///< PR_BUILD_AQUEDUCT
 
	{   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
 
	{   5000, PCAT_RUNNING,      GSF_END,          PR_BUILD_STATION_AIRPORT}, ///< PR_INFRASTRUCTURE_AIRPORT
 
};
 
assert_compile(lengthof(_price_base_specs) == PR_END);
0 comments (0 inline, 0 general)