summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-29 21:27:16 +0000
committerrubidium <rubidium@openttd.org>2007-08-29 21:27:16 +0000
commitdc8019575404425b52abc121c6bd9159596fee87 (patch)
treec750fba2dc3e7efcc74cbccf329c29e874b3102e
parentfff12fd22e6e526c7a8259606bb9235f1ed97e06 (diff)
downloadopenttd-dc8019575404425b52abc121c6bd9159596fee87.tar.xz
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
-rw-r--r--src/aircraft.h3
-rw-r--r--src/aircraft_gui.cpp2
-rw-r--r--src/roadveh.h4
-rw-r--r--src/roadveh_gui.cpp2
-rw-r--r--src/ship.h3
-rw-r--r--src/ship_gui.cpp2
-rw-r--r--src/train.h1
-rw-r--r--src/train_cmd.cpp37
-rw-r--r--src/train_gui.cpp2
-rw-r--r--src/vehicle.h12
10 files changed, 46 insertions, 22 deletions
diff --git a/src/aircraft.h b/src/aircraft.h
index 0a32703e2..15a5530e0 100644
--- a/src/aircraft.h
+++ b/src/aircraft.h
@@ -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();
};
diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp
index 77d1af685..28813eb12 100644
--- a/src/aircraft_gui.cpp
+++ b/src/aircraft_gui.cpp
@@ -80,7 +80,7 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
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);
}
diff --git a/src/roadveh.h b/src/roadveh.h
index 24b64424d..7644e3570 100644
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -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();
};
diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp
index 15d65057b..f67d81e02 100644
--- a/src/roadveh_gui.cpp
+++ b/src/roadveh_gui.cpp
@@ -91,7 +91,7 @@ static void RoadVehDetailsWndProc(Window *w, WindowEvent *e)
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);
}
diff --git a/src/ship.h b/src/ship.h
index ac86c907a..929eeccc6 100644
--- a/src/ship.h
+++ b/src/ship.h
@@ -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();
};
diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp
index 88010ced3..5f7bdd1fe 100644
--- a/src/ship_gui.cpp
+++ b/src/ship_gui.cpp
@@ -50,7 +50,7 @@ static void ShipDetailsWndProc(Window *w, WindowEvent *e)
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);
}
diff --git a/src/train.h b/src/train.h
index a64048fb8..5befad626 100644
--- a/src/train.h
+++ b/src/train.h
@@ -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();
};
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 59765bf40..f1c428ff5 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3313,6 +3313,25 @@ static void TrainLocoHandler(Vehicle *v, bool mode)
}
+
+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(Vehicle *v)
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;
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index bad613344..f88ab54ab 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -209,7 +209,7 @@ static void DrawTrainDetailsWindow(Window *w)
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());
diff --git a/src/vehicle.h b/src/vehicle.h
index 8b7e29796..b07aa44d4 100644
--- a/src/vehicle.h
+++ b/src/vehicle.h
@@ -427,10 +427,22 @@ struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
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; }
};