summaryrefslogtreecommitdiff
path: root/src/engine.cpp
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2009-01-25 00:57:03 +0000
committerglx <glx@openttd.org>2009-01-25 00:57:03 +0000
commitc1cf3934fa5bd523dd1df01cf505c9f06927701d (patch)
treea8b3e55a2f1168021a45917b6fbf5777c3476634 /src/engine.cpp
parent80ee3d3440233b50bbe818b2f74f6aac8841edfa (diff)
downloadopenttd-c1cf3934fa5bd523dd1df01cf505c9f06927701d.tar.xz
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 32d591373..37886699d 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -137,6 +137,28 @@ Money Engine::GetRunningCost() const
}
}
+Money Engine::GetCost() const
+{
+ switch (this->type) {
+ case VEH_ROAD:
+ return GetEngineProperty(this->index, 0x11, this->u.road.cost_factor) * (_price.roadveh_base >> 3) >> 5;
+
+ case VEH_TRAIN:
+ if (this->u.rail.railveh_type == RAILVEH_WAGON) {
+ return (GetEngineProperty(this->index, 0x17, this->u.rail.cost_factor) * _price.build_railwagon) >> 8;
+ } else {
+ return GetEngineProperty(this->index, 0x17, this->u.rail.cost_factor) * (_price.build_railvehicle >> 3) >> 5;
+ }
+ case VEH_SHIP:
+ return GetEngineProperty(this->index, 0x0A, this->u.ship.cost_factor) * (_price.ship_base >> 3) >> 5;
+
+ case VEH_AIRCRAFT:
+ return GetEngineProperty(this->index, 0x0B, this->u.air.cost_factor) * (_price.aircraft_base >> 3) >> 5;
+
+ default: NOT_REACHED();
+ }
+}
+
/** Sets cached values in Company::num_vehicles and Group::num_vehicles
*/
void SetCachedEngineCounts()