summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-19 09:45:44 +0000
committerrubidium <rubidium@openttd.org>2009-02-19 09:45:44 +0000
commita5f30dd553edd6ea6cdd554ba1082d517e8e61df (patch)
treec9ee92ae7cbfe93892ebfded0c1f663c6a2f9e99
parent459a855e6074bca02a7aca174ab37778acc9f55d (diff)
downloadopenttd-a5f30dd553edd6ea6cdd554ba1082d517e8e61df.tar.xz
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
-rw-r--r--src/build_vehicle_gui.cpp5
-rw-r--r--src/engine.cpp16
-rw-r--r--src/engine_base.h1
3 files changed, 19 insertions, 3 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 9164d95b4..feb01a051 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -512,11 +512,10 @@ static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const
static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi)
{
const Engine *e = GetEngine(engine_number);
- uint weight = e->GetDisplayWeight();
/* Purchase Cost - Engine weight */
SetDParam(0, e->GetCost());
- SetDParam(1, weight);
+ SetDParam(1, e->GetDisplayWeight());
DrawString(x, y, STR_PURCHASE_INFO_COST_WEIGHT, TC_FROMSTRING);
y += 10;
@@ -528,7 +527,7 @@ static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, cons
/* Max tractive effort - not applicable if old acceleration or maglev */
if (_settings_game.vehicle.train_acceleration_model != TAM_ORIGINAL && rvi->railtype != RAILTYPE_MAGLEV) {
- SetDParam(0, (weight * 10 * GetEngineProperty(engine_number, 0x1F, rvi->tractive_effort)) / 256);
+ SetDParam(0, e->GetDisplayMaxTractiveEffort());
DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, TC_FROMSTRING);
y += 10;
}
diff --git a/src/engine.cpp b/src/engine.cpp
index 499ac399d..8373d9430 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -204,6 +204,22 @@ uint Engine::GetDisplayWeight() const
}
}
+/**
+ * Returns the tractive effort for display purposes.
+ * For dual-headed train-engines this is the tractive effort of both heads
+ * @return tractive effort in display units kN
+ */
+uint Engine::GetDisplayMaxTractiveEffort() const
+{
+ /* Currently only trains have 'tractive effort' */
+ switch (this->type) {
+ case VEH_TRAIN:
+ return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, 0x1F, this->u.rail.tractive_effort)) / 256;
+
+ default: NOT_REACHED();
+ }
+}
+
/** Sets cached values in Company::num_vehicles and Group::num_vehicles
*/
void SetCachedEngineCounts()
diff --git a/src/engine_base.h b/src/engine_base.h
index 787ae804b..dbbb2c308 100644
--- a/src/engine_base.h
+++ b/src/engine_base.h
@@ -55,6 +55,7 @@ struct Engine : PoolItem<Engine, EngineID, &_Engine_pool> {
uint GetDisplayMaxSpeed() const;
uint GetPower() const;
uint GetDisplayWeight() const;
+ uint GetDisplayMaxTractiveEffort() const;
};
static inline bool IsEngineIndex(uint index)