summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2009-01-25 00:57:03 +0000
committerglx <glx@openttd.org>2009-01-25 00:57:03 +0000
commitc1cf3934fa5bd523dd1df01cf505c9f06927701d (patch)
treea8b3e55a2f1168021a45917b6fbf5777c3476634 /src/ai
parent80ee3d3440233b50bbe818b2f74f6aac8841edfa (diff)
downloadopenttd-c1cf3934fa5bd523dd1df01cf505c9f06927701d.tar.xz
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/api/ai_engine.cpp24
-rw-r--r--src/ai/api/ai_event_types.cpp24
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()