Changeset - r7488:e5f4cea230c4
[Not reviewed]
master
0 10 0
rubidium - 17 years ago 2007-08-29 21:27:16
rubidium@openttd.org
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
10 files changed with 46 insertions and 22 deletions:
0 comments (0 inline, 0 general)
src/aircraft.h
Show inline comments
 
@@ -7,6 +7,8 @@
 

	
 
#include "station_map.h"
 
#include "vehicle.h"
 
#include "engine.h"
 
#include "variables.h"
 

	
 
/** An aircraft can be one ot those types */
 
enum AircraftSubType {
 
@@ -130,6 +132,7 @@ struct Aircraft : public Vehicle {
 
	int GetImage(Direction direction) const;
 
	int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; }
 
	int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 16; }
 
	Money GetRunningCost() const { return AircraftVehInfo(this->engine_type)->running_cost * _price.aircraft_running; }
 
	void Tick();
 
};
 

	
src/aircraft_gui.cpp
Show inline comments
 
@@ -80,7 +80,7 @@ static void AircraftDetailsWndProc(Windo
 

	
 
			SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
 
			SetDParam(2, v->max_age / 366);
 
			SetDParam(3, _price.aircraft_running * AircraftVehInfo(v->engine_type)->running_cost >> 8);
 
			SetDParam(3, v->GetDisplayRunningCost());
 
			DrawString(2, 15, STR_A00D_AGE_RUNNING_COST_YR, 0);
 
		}
 

	
src/roadveh.h
Show inline comments
 
@@ -6,7 +6,8 @@
 
#define ROADVEH_H
 

	
 
#include "vehicle.h"
 

	
 
#include "engine.h"
 
#include "variables.h"
 

	
 
enum RoadVehicleSubType {
 
	RVST_FRONT,
 
@@ -83,6 +84,7 @@ struct RoadVehicle : public Vehicle {
 
	int GetImage(Direction direction) const;
 
	int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
 
	int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; }
 
	Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * _price.roadveh_running; }
 
	void Tick();
 
};
 

	
src/roadveh_gui.cpp
Show inline comments
 
@@ -91,7 +91,7 @@ static void RoadVehDetailsWndProc(Window
 

	
 
			SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
 
			SetDParam(2, v->max_age / 366);
 
			SetDParam(3, RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running >> 8);
 
			SetDParam(3, v->GetDisplayRunningCost());
 
			DrawString(2, 15, STR_900D_AGE_RUNNING_COST_YR, 0);
 
		}
 

	
src/ship.h
Show inline comments
 
@@ -6,6 +6,8 @@
 
#define SHIP_H
 

	
 
#include "vehicle.h"
 
#include "engine.h"
 
#include "variables.h"
 

	
 
void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
void RecalcShipStuff(Vehicle *v);
 
@@ -48,6 +50,7 @@ struct Ship: public Vehicle {
 
	int GetImage(Direction direction) const;
 
	int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
 
	int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; }
 
	Money GetRunningCost() const { return ShipVehInfo(this->engine_type)->running_cost * _price.ship_running; }
 
	void Tick();
 
};
 

	
src/ship_gui.cpp
Show inline comments
 
@@ -50,7 +50,7 @@ static void ShipDetailsWndProc(Window *w
 

	
 
			SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
 
			SetDParam(2, v->max_age / 366);
 
			SetDParam(3, ShipVehInfo(v->engine_type)->running_cost * _price.ship_running >> 8);
 
			SetDParam(3, v->GetDisplayRunningCost());
 
			DrawString(2, 15, STR_9812_AGE_RUNNING_COST_YR, 0);
 
		}
 

	
src/train.h
Show inline comments
 
@@ -274,6 +274,7 @@ struct Train : public Vehicle {
 
	int GetImage(Direction direction) const;
 
	int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; }
 
	int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed * 10 / 16; }
 
	Money GetRunningCost() const;
 
	void Tick();
 
};
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -3313,6 +3313,25 @@ static void TrainLocoHandler(Vehicle *v,
 
}
 

	
 

	
 

	
 
Money Train::GetRunningCost() const
 
{
 
	Money cost = 0;
 
	const Vehicle *v = this;
 

	
 
	do {
 
		const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
 

	
 
		byte cost_factor = GetVehicleProperty(v, 0x0D, rvi->running_cost_base);
 
		if (cost_factor == 0) continue;
 

	
 
		cost += cost_factor * _price.running_rail[rvi->running_cost_class];
 
	} while ((v = GetNextVehicle(v)) != NULL);
 

	
 
	return cost;
 
}
 

	
 

	
 
void Train::Tick()
 
{
 
	if (_age_cargo_skip_counter == 0) this->cargo.AgeCargo();
 
@@ -3384,22 +3403,6 @@ static void CheckIfTrainNeedsService(Veh
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 
}
 

	
 
Money GetTrainRunningCost(const Vehicle *v)
 
{
 
	Money cost = 0;
 

	
 
	do {
 
		const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
 

	
 
		byte cost_factor = GetVehicleProperty(v, 0x0D, rvi->running_cost_base);
 
		if (cost_factor == 0) continue;
 

	
 
		cost += cost_factor * _price.running_rail[rvi->running_cost_class];
 
	} while ((v = GetNextVehicle(v)) != NULL);
 

	
 
	return cost;
 
}
 

	
 
void OnNewDay_Train(Vehicle *v)
 
{
 
	if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
 
@@ -3420,7 +3423,7 @@ void OnNewDay_Train(Vehicle *v)
 

	
 
		if ((v->vehstatus & VS_STOPPED) == 0) {
 
			/* running costs */
 
			CommandCost cost(GetTrainRunningCost(v) / 364);
 
			CommandCost cost(v->GetRunningCost() / 364);
 

	
 
			v->profit_this_year -= cost.GetCost() >> 8;
 

	
src/train_gui.cpp
Show inline comments
 
@@ -209,7 +209,7 @@ static void DrawTrainDetailsWindow(Windo
 

	
 
	SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
 
	SetDParam(2, v->max_age / 366);
 
	SetDParam(3, GetTrainRunningCost(v) >> 8);
 
	SetDParam(3, v->GetDisplayRunningCost());
 
	DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0);
 

	
 
	SetDParam(2, v->GetDisplayMaxSpeed());
src/vehicle.h
Show inline comments
 
@@ -427,10 +427,22 @@ struct Vehicle : PoolItem<Vehicle, Vehic
 
	virtual int GetDisplayMaxSpeed() const { return 0; }
 

	
 
	/**
 
	 * Gets the running cost of a vehicle
 
	 * @return the vehicle's running cost
 
	 */
 
	virtual Money GetRunningCost() const { return 0; }
 

	
 
	/**
 
	 * Calls the tick handler of the vehicle
 
	 */
 
	virtual void Tick() {};
 

	
 
	/**
 
	 * Gets the running cost of a vehicle  that can be sent into SetDParam for string processing.
 
	 * @return the vehicle's running cost
 
	 */
 
	Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
 

	
 
	bool IsValid() const { return this->type != VEH_INVALID; }
 
};
 

	
0 comments (0 inline, 0 general)