1
0
Fork 0

(svn r16581) -Codechange: unify the access to Engine::lifelength.

release/1.0
rubidium 2009-06-16 13:52:18 +00:00
parent 4b05617c42
commit 512b021e26
8 changed files with 17 additions and 6 deletions

View File

@ -117,7 +117,7 @@
if (!IsValidEngine(engine_id)) return -1; if (!IsValidEngine(engine_id)) return -1;
if (GetVehicleType(engine_id) == AIVehicle::VT_RAIL && IsWagon(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) /* static */ Money AIEngine::GetRunningCost(EngineID engine_id)

View File

@ -334,7 +334,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->reliability = e->reliability; v->reliability = e->reliability;
v->reliability_spd_dec = e->reliability_spd_dec; 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; _new_vehicle_id = v->index;

View File

@ -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) { if (e->type != VEH_TRAIN || RailVehInfo(engine_number)->railveh_type != RAILVEH_WAGON) {
/* Design date - Life length */ /* Design date - Life length */
SetDParam(0, ymd.year); 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); DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;

View File

@ -315,6 +315,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. * Initializes the EngineOverrideManager with the default engines.
*/ */

View File

@ -59,6 +59,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
uint GetPower() const; uint GetPower() const;
uint GetDisplayWeight() const; uint GetDisplayWeight() const;
uint GetDisplayMaxTractiveEffort() const; uint GetDisplayMaxTractiveEffort() const;
Date GetLifeLengthInDays() const;
}; };
struct EngineIDMapping { struct EngineIDMapping {

View File

@ -230,7 +230,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
v->reliability = e->reliability; v->reliability = e->reliability;
v->reliability_spd_dec = e->reliability_spd_dec; 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; _new_vehicle_id = v->index;
v->name = NULL; v->name = NULL;

View File

@ -799,7 +799,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
v->reliability = e->reliability; v->reliability = e->reliability;
v->reliability_spd_dec = e->reliability_spd_dec; 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; _new_vehicle_id = v->index;
v->name = NULL; v->name = NULL;

View File

@ -869,7 +869,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
v->reliability = e->reliability; v->reliability = e->reliability;
v->reliability_spd_dec = e->reliability_spd_dec; 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->name = NULL;
v->railtype = rvi->railtype; v->railtype = rvi->railtype;