From c1cf3934fa5bd523dd1df01cf505c9f06927701d Mon Sep 17 00:00:00 2001 From: glx Date: Sun, 25 Jan 2009 00:57:03 +0000 Subject: (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication. --- src/ai/api/ai_engine.cpp | 24 +----------------------- src/ai/api/ai_event_types.cpp | 24 +----------------------- 2 files changed, 2 insertions(+), 46 deletions(-) (limited to 'src/ai/api') 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() -- cgit v1.2.3-70-g09d2