1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 17:02:37 +01:00

(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company

This commit is contained in:
glx
2009-01-24 20:14:15 +00:00
parent 7e7fab1b18
commit e8b5f49861
6 changed files with 43 additions and 81 deletions

View File

@@ -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()