summaryrefslogtreecommitdiff
path: root/src/engine.cpp
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2009-01-24 20:14:15 +0000
committerglx <glx@openttd.org>2009-01-24 20:14:15 +0000
commit9b73303b4d4c91cb0fcee44679e5443bc8c5fa0b (patch)
tree9ca7c83bbeeb0c45437a57aa25919d6493f228ac /src/engine.cpp
parentaf7b7867a7565dc3c18242d9cfad1912b6ef4e40 (diff)
downloadopenttd-9b73303b4d4c91cb0fcee44679e5443bc8c5fa0b.tar.xz
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index ef6d63438..32d591373 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -118,6 +118,25 @@ Engine::~Engine()
free(this->name);
}
+Money Engine::GetRunningCost() const
+{
+ switch (this->type) {
+ case VEH_ROAD:
+ return this->u.road.running_cost * GetPriceByIndex(this->u.road.running_cost_class) >> 8;
+
+ case VEH_TRAIN:
+ return GetEngineProperty(this->index, 0x0D, this->u.rail.running_cost) * GetPriceByIndex(this->u.rail.running_cost_class) >> 8;
+
+ case VEH_SHIP:
+ return GetEngineProperty(this->index, 0x0F, this->u.ship.running_cost) * _price.ship_running >> 8;
+
+ case VEH_AIRCRAFT:
+ return GetEngineProperty(this->index, 0x0E, this->u.air.running_cost) * _price.aircraft_running >> 8;
+
+ default: NOT_REACHED();
+ }
+}
+
/** Sets cached values in Company::num_vehicles and Group::num_vehicles
*/
void SetCachedEngineCounts()