From 72cd855978bf45fd444eae72551a12e13a35b0c8 Mon Sep 17 00:00:00 2001 From: frosch Date: Tue, 1 Nov 2011 00:21:08 +0000 Subject: (svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code. --- src/vehicle.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/vehicle.cpp') 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; } @@ -631,6 +631,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 @@ -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; -- cgit v1.2.3-54-g00ecf