diff options
author | rubidium <rubidium@openttd.org> | 2009-06-16 13:52:18 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-06-16 13:52:18 +0000 |
commit | 512b021e261f042dccd9bdc254cd470a46e575f5 (patch) | |
tree | e78a9754bf6d326bf90b988cbe69ed74a6a763b4 | |
parent | 4b05617c42c89a323560a0bfd9225fcac9b69588 (diff) | |
download | openttd-512b021e261f042dccd9bdc254cd470a46e575f5.tar.xz |
(svn r16581) -Codechange: unify the access to Engine::lifelength.
-rw-r--r-- | src/ai/api/ai_engine.cpp | 2 | ||||
-rw-r--r-- | src/aircraft_cmd.cpp | 2 | ||||
-rw-r--r-- | src/build_vehicle_gui.cpp | 2 | ||||
-rw-r--r-- | src/engine.cpp | 10 | ||||
-rw-r--r-- | src/engine_base.h | 1 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 2 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 2 | ||||
-rw-r--r-- | src/train_cmd.cpp | 2 |
8 files changed, 17 insertions, 6 deletions
diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp index 64c85de04..b8be61069 100644 --- a/src/ai/api/ai_engine.cpp +++ b/src/ai/api/ai_engine.cpp @@ -117,7 +117,7 @@ if (!IsValidEngine(engine_id)) return -1; if (GetVehicleType(engine_id) == AIVehicle::VT_RAIL && IsWagon(engine_id)) return -1; - return ::Engine::Get(engine_id)->lifelength * DAYS_IN_LEAP_YEAR; + return ::Engine::Get(engine_id)->GetLifeLengthInDays(); } /* static */ Money AIEngine::GetRunningCost(EngineID engine_id) diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 511dbe02a..1ea69d5c6 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -334,7 +334,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin v->reliability = e->reliability; v->reliability_spd_dec = e->reliability_spd_dec; - v->max_age = e->lifelength * DAYS_IN_LEAP_YEAR; + v->max_age = e->GetLifeLengthInDays(); _new_vehicle_id = v->index; diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 72cfb0a29..eea5d5585 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -676,7 +676,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number) if (e->type != VEH_TRAIN || RailVehInfo(engine_number)->railveh_type != RAILVEH_WAGON) { /* Design date - Life length */ SetDParam(0, ymd.year); - SetDParam(1, e->lifelength); + SetDParam(1, e->GetLifeLengthInDays() / DAYS_IN_LEAP_YEAR); DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE); y += FONT_HEIGHT_NORMAL; diff --git a/src/engine.cpp b/src/engine.cpp index bc0fb8a52..a9ad89db5 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -316,6 +316,16 @@ uint Engine::GetDisplayMaxTractiveEffort() const } /** + * Returns the vehicle's life length in days. + * @return the life length + */ +Date Engine::GetLifeLengthInDays() const +{ + /* Assume leap years; this gives the player a bit more than the given amount of years, but never less. */ + return this->lifelength * DAYS_IN_LEAP_YEAR; +} + +/** * Initializes the EngineOverrideManager with the default engines. */ void EngineOverrideManager::ResetToDefaultMapping() diff --git a/src/engine_base.h b/src/engine_base.h index bbf25b9fa..e86dea168 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -59,6 +59,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { uint GetPower() const; uint GetDisplayWeight() const; uint GetDisplayMaxTractiveEffort() const; + Date GetLifeLengthInDays() const; }; struct EngineIDMapping { diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index f2704e1d0..894477e68 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -230,7 +230,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint v->reliability = e->reliability; v->reliability_spd_dec = e->reliability_spd_dec; - v->max_age = e->lifelength * DAYS_IN_LEAP_YEAR; + v->max_age = e->GetLifeLengthInDays(); _new_vehicle_id = v->index; v->name = NULL; diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 15c150be2..3c451c701 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -799,7 +799,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 v->reliability = e->reliability; v->reliability_spd_dec = e->reliability_spd_dec; - v->max_age = e->lifelength * DAYS_IN_LEAP_YEAR; + v->max_age = e->GetLifeLengthInDays(); _new_vehicle_id = v->index; v->name = NULL; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 253981a46..8769f3aab 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -869,7 +869,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, v->reliability = e->reliability; v->reliability_spd_dec = e->reliability_spd_dec; - v->max_age = e->lifelength * DAYS_IN_LEAP_YEAR; + v->max_age = e->GetLifeLengthInDays(); v->name = NULL; v->railtype = rvi->railtype; |