summaryrefslogtreecommitdiff
path: root/src/engine.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-02-01 16:10:06 +0000
committerfrosch <frosch@openttd.org>2009-02-01 16:10:06 +0000
commit9c2ba4f96ad445c948480c2b1a564214274d87b6 (patch)
treedb4e289e273064a04dbb517c6f5ff509c4fa81f7 /src/engine.cpp
parentecb685411ad0a553ba0b7070ae2598bd6c6e637c (diff)
downloadopenttd-9c2ba4f96ad445c948480c2b1a564214274d87b6.tar.xz
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 1e388a3e1..20be6ebd8 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -154,6 +154,56 @@ Money Engine::GetCost() const
}
}
+/**
+ * Returns max speed for display purposes
+ * @return max speed in mph
+ */
+uint Engine::GetDisplayMaxSpeed() const
+{
+ switch (this->type) {
+ case VEH_TRAIN:
+ return GetEngineProperty(this->index, 0x09, this->u.rail.max_speed) * 10 / 16;
+
+ case VEH_ROAD:
+ return this->u.road.max_speed * 10 / 32;
+
+ case VEH_SHIP:
+ return GetEngineProperty(this->index, 0x0B, this->u.ship.max_speed) * 10 / 32;
+
+ case VEH_AIRCRAFT:
+ return this->u.air.max_speed * 10 / 16;
+
+ default: NOT_REACHED();
+ }
+}
+
+uint Engine::GetPower() const
+{
+ /* Currently only trains have 'power' */
+ switch (this->type) {
+ case VEH_TRAIN:
+ return GetEngineProperty(this->index, 0x0B, this->u.rail.power);
+
+ default: NOT_REACHED();
+ }
+}
+
+/**
+ * Returns the weight for display purposes.
+ * For dual-headed train-engines this is the weight of both heads
+ * @return weight in display units metric tons
+ */
+uint Engine::GetDisplayWeight() const
+{
+ /* Currently only trains have 'weight' */
+ switch (this->type) {
+ case VEH_TRAIN:
+ return GetEngineProperty(this->index, 0x16, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
+
+ default: NOT_REACHED();
+ }
+}
+
/** Sets cached values in Company::num_vehicles and Group::num_vehicles
*/
void SetCachedEngineCounts()