diff options
author | glx <glx@openttd.org> | 2009-01-24 20:14:15 +0000 |
---|---|---|
committer | glx <glx@openttd.org> | 2009-01-24 20:14:15 +0000 |
commit | e8b5f4986147fa7036653abd82052f29ad27b85a (patch) | |
tree | 9ca7c83bbeeb0c45437a57aa25919d6493f228ac /src/ai | |
parent | 7e7fab1b184f8d62af7e1fb55e7ba15c99281edc (diff) | |
download | openttd-e8b5f4986147fa7036653abd82052f29ad27b85a.tar.xz |
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/api/ai_engine.cpp | 29 | ||||
-rw-r--r-- | src/ai/api/ai_event_types.cpp | 29 |
2 files changed, 2 insertions, 56 deletions
diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp index 06ed3d728..545305f3f 100644 --- a/src/ai/api/ai_engine.cpp +++ b/src/ai/api/ai_engine.cpp @@ -193,34 +193,7 @@ { if (!IsValidEngine(engine_id)) return -1; - /* We need to create an instance in order to obtain GetRunningCost. - * This means we temporary allocate a vehicle in the pool, but - * there is no other way.. */ - Vehicle *vehicle; - switch (::GetEngine(engine_id)->type) { - case VEH_ROAD: { - vehicle = new RoadVehicle(); - } break; - - case VEH_TRAIN: { - vehicle = new Train(); - } break; - - case VEH_SHIP: { - vehicle = new Ship(); - } break; - - case VEH_AIRCRAFT: { - vehicle = new Aircraft(); - } break; - - default: NOT_REACHED(); - } - - vehicle->engine_type = engine_id; - Money runningCost = vehicle->GetRunningCost(); - delete vehicle; - return runningCost >> 8; + return ::GetEngine(engine_id)->GetRunningCost(); } /* static */ AIVehicle::VehicleType AIEngine::GetVehicleType(EngineID engine_id) diff --git a/src/ai/api/ai_event_types.cpp b/src/ai/api/ai_event_types.cpp index 09d801e70..9792f92f9 100644 --- a/src/ai/api/ai_event_types.cpp +++ b/src/ai/api/ai_event_types.cpp @@ -140,34 +140,7 @@ Money AIEventEnginePreview::GetPrice() Money AIEventEnginePreview::GetRunningCost() { - /* We need to create an instance in order to obtain GetRunningCost. - * This means we temporary allocate a vehicle in the pool, but - * there is no other way.. */ - Vehicle *vehicle; - switch (::GetEngine(engine)->type) { - case VEH_ROAD: { - vehicle = new RoadVehicle(); - } break; - - case VEH_TRAIN: { - vehicle = new Train(); - } break; - - case VEH_SHIP: { - vehicle = new Ship(); - } break; - - case VEH_AIRCRAFT: { - vehicle = new Aircraft(); - } break; - - default: NOT_REACHED(); - } - - vehicle->engine_type = engine; - Money runningCost = vehicle->GetRunningCost(); - delete vehicle; - return runningCost >> 8; + return ::GetEngine(engine)->GetRunningCost(); } AIVehicle::VehicleType AIEventEnginePreview::GetVehicleType() |