diff options
author | glx <glx@openttd.org> | 2009-01-25 00:57:03 +0000 |
---|---|---|
committer | glx <glx@openttd.org> | 2009-01-25 00:57:03 +0000 |
commit | 470da22ac3dd297766a3064b8e72aa8c601c74c7 (patch) | |
tree | a8b3e55a2f1168021a45917b6fbf5777c3476634 /src/ai/api | |
parent | 512cc98b35891a491b4e24a0a5f440f8b9e548d7 (diff) | |
download | openttd-470da22ac3dd297766a3064b8e72aa8c601c74c7.tar.xz |
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
Diffstat (limited to 'src/ai/api')
-rw-r--r-- | src/ai/api/ai_engine.cpp | 24 | ||||
-rw-r--r-- | src/ai/api/ai_event_types.cpp | 24 |
2 files changed, 2 insertions, 46 deletions
diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp index 545305f3f..5d301f47c 100644 --- a/src/ai/api/ai_engine.cpp +++ b/src/ai/api/ai_engine.cpp @@ -157,29 +157,7 @@ { if (!IsValidEngine(engine_id)) return -1; - switch (::GetEngine(engine_id)->type) { - case VEH_ROAD: { - const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id); - return (_price.roadveh_base >> 3) * vi->cost_factor >> 5; - } break; - - case VEH_TRAIN: { - const RailVehicleInfo *vi = ::RailVehInfo(engine_id); - return (_price.build_railvehicle >> 3) * vi->cost_factor >> 5; - } break; - - case VEH_SHIP: { - const ShipVehicleInfo *vi = ::ShipVehInfo(engine_id); - return (_price.ship_base >> 3) * vi->cost_factor >> 5; - } break; - - case VEH_AIRCRAFT: { - const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine_id); - return (_price.aircraft_base >> 3) * vi->cost_factor >> 5; - } break; - - default: NOT_REACHED(); - } + return ::GetEngine(engine_id)->GetCost(); } /* static */ int32 AIEngine::GetMaxAge(EngineID engine_id) diff --git a/src/ai/api/ai_event_types.cpp b/src/ai/api/ai_event_types.cpp index 9792f92f9..6230caad6 100644 --- a/src/ai/api/ai_event_types.cpp +++ b/src/ai/api/ai_event_types.cpp @@ -113,29 +113,7 @@ int32 AIEventEnginePreview::GetMaxSpeed() Money AIEventEnginePreview::GetPrice() { - switch (::GetEngine(engine)->type) { - case VEH_ROAD: { - const RoadVehicleInfo *vi = ::RoadVehInfo(engine); - return (_price.roadveh_base >> 3) * vi->cost_factor >> 5; - } break; - - case VEH_TRAIN: { - const RailVehicleInfo *vi = ::RailVehInfo(engine); - return (_price.build_railvehicle >> 3) * vi->cost_factor >> 5; - } break; - - case VEH_SHIP: { - const ShipVehicleInfo *vi = ::ShipVehInfo(engine); - return (_price.ship_base >> 3) * vi->cost_factor >> 5; - } break; - - case VEH_AIRCRAFT: { - const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine); - return (_price.aircraft_base >> 3) * vi->cost_factor >> 5; - } break; - - default: NOT_REACHED(); - } + return ::GetEngine(engine)->GetCost(); } Money AIEventEnginePreview::GetRunningCost() |