From e8b5f4986147fa7036653abd82052f29ad27b85a Mon Sep 17 00:00:00 2001 From: glx Date: Sat, 24 Jan 2009 20:14:15 +0000 Subject: (svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company --- src/engine.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/engine.cpp') diff --git a/src/engine.cpp b/src/engine.cpp index ef6d63438..32d591373 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -118,6 +118,25 @@ Engine::~Engine() free(this->name); } +Money Engine::GetRunningCost() const +{ + switch (this->type) { + case VEH_ROAD: + return this->u.road.running_cost * GetPriceByIndex(this->u.road.running_cost_class) >> 8; + + case VEH_TRAIN: + return GetEngineProperty(this->index, 0x0D, this->u.rail.running_cost) * GetPriceByIndex(this->u.rail.running_cost_class) >> 8; + + case VEH_SHIP: + return GetEngineProperty(this->index, 0x0F, this->u.ship.running_cost) * _price.ship_running >> 8; + + case VEH_AIRCRAFT: + return GetEngineProperty(this->index, 0x0E, this->u.air.running_cost) * _price.aircraft_running >> 8; + + default: NOT_REACHED(); + } +} + /** Sets cached values in Company::num_vehicles and Group::num_vehicles */ void SetCachedEngineCounts() -- cgit v1.2.3-54-g00ecf