diff options
author | frosch <frosch@openttd.org> | 2011-11-01 00:21:08 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-11-01 00:21:08 +0000 |
commit | 72cd855978bf45fd444eae72551a12e13a35b0c8 (patch) | |
tree | b7f4b3cc07022ba32160f5e67f4cb5a527266d12 /src/vehicle.cpp | |
parent | c366e0d45f87f9ba625ed73cbf5bff61d8483c5c (diff) | |
download | openttd-72cd855978bf45fd444eae72551a12e13a35b0c8.tar.xz |
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r-- | src/vehicle.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index e5c239dc8..5827b46da 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -92,7 +92,7 @@ void VehicleServiceInDepot(Vehicle *v) { v->date_of_last_service = _date; v->breakdowns_since_last_service = 0; - v->reliability = Engine::Get(v->engine_type)->reliability; + v->reliability = v->GetEngine()->reliability; SetWindowDirty(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated } @@ -111,7 +111,7 @@ bool Vehicle::NeedsServicing() const /* Are we ready for the next service cycle? */ const Company *c = Company::Get(this->owner); if (c->settings.vehicle.servint_ispercent ? - (this->reliability >= Engine::Get(this->engine_type)->reliability * (100 - this->service_interval) / 100) : + (this->reliability >= this->GetEngine()->reliability * (100 - this->service_interval) / 100) : (this->date_of_last_service + this->service_interval >= _date)) { return false; } @@ -632,6 +632,16 @@ bool Vehicle::HasEngineType() const } /** + * Retrieves the engine of the vehicle. + * @return Engine of the vehicle. + * @pre HasEngineType() == true + */ +const Engine *Vehicle::GetEngine() const +{ + return Engine::Get(this->engine_type); +} + +/** * Handle the pathfinding result, especially the lost status. * If the vehicle is now lost and wasn't previously fire an * event to the AIs and a news message to the user. If the @@ -1158,7 +1168,7 @@ void AgeVehicle(Vehicle *v) if (v->Previous() != NULL || v->owner != _local_company || (v->vehstatus & VS_CRASHED) != 0) return; /* Don't warn if a renew is active */ - if (Company::Get(v->owner)->settings.engine_renew && Engine::Get(v->engine_type)->company_avail != 0) return; + if (Company::Get(v->owner)->settings.engine_renew && v->GetEngine()->company_avail != 0) return; StringID str; if (age == -DAYS_IN_LEAP_YEAR) { @@ -1756,7 +1766,7 @@ PaletteID GetVehiclePalette(const Vehicle *v) uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity) { if (mail_capacity != NULL) *mail_capacity = 0; - const Engine *e = Engine::Get(v->engine_type); + const Engine *e = v->GetEngine(); if (!e->CanCarryCargo()) return 0; @@ -2113,7 +2123,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) void Vehicle::UpdateVisualEffect(bool allow_power_change) { bool powered_before = HasBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER); - const Engine *e = Engine::Get(this->engine_type); + const Engine *e = this->GetEngine(); /* Evaluate properties */ byte visual_effect; |