summaryrefslogtreecommitdiff
path: root/src/ai/api
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-02-01 16:10:06 +0000
committerfrosch <frosch@openttd.org>2009-02-01 16:10:06 +0000
commitc28c4c1986a9a25cbf67ed84c6ba3d51447bbb6f (patch)
treedb4e289e273064a04dbb517c6f5ff509c4fa81f7 /src/ai/api
parent6d5cd47c74be39ce6ffd92addcab417f178cbaad (diff)
downloadopenttd-c28c4c1986a9a25cbf67ed84c6ba3d51447bbb6f.tar.xz
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
Diffstat (limited to 'src/ai/api')
-rw-r--r--src/ai/api/ai_engine.cpp29
-rw-r--r--src/ai/api/ai_event_types.cpp29
2 files changed, 8 insertions, 50 deletions
diff --git a/src/ai/api/ai_engine.cpp b/src/ai/api/ai_engine.cpp
index 564dbc018..762da14b1 100644
--- a/src/ai/api/ai_engine.cpp
+++ b/src/ai/api/ai_engine.cpp
@@ -118,31 +118,10 @@
{
if (!IsValidEngine(engine_id)) return -1;
- switch (::GetEngine(engine_id)->type) {
- case VEH_ROAD: {
- const RoadVehicleInfo *vi = ::RoadVehInfo(engine_id);
- /* Internal speeds are km/h * 2 */
- return vi->max_speed / 2;
- } break;
-
- case VEH_TRAIN: {
- const RailVehicleInfo *vi = ::RailVehInfo(engine_id);
- return vi->max_speed;
- } break;
-
- case VEH_SHIP: {
- const ShipVehicleInfo *vi = ::ShipVehInfo(engine_id);
- /* Internal speeds are km/h * 2 */
- return vi->max_speed / 2;
- } break;
-
- case VEH_AIRCRAFT: {
- const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine_id);
- return vi->max_speed / _settings_game.vehicle.plane_speed;
- } break;
-
- default: NOT_REACHED();
- }
+ const Engine *e = ::GetEngine(engine_id);
+ int32 max_speed = e->GetDisplayMaxSpeed() * 16 / 10; // convert mph to km-ish/h
+ if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
+ return max_speed;
}
/* static */ Money AIEngine::GetPrice(EngineID engine_id)
diff --git a/src/ai/api/ai_event_types.cpp b/src/ai/api/ai_event_types.cpp
index 1cf14f32d..c495e082e 100644
--- a/src/ai/api/ai_event_types.cpp
+++ b/src/ai/api/ai_event_types.cpp
@@ -79,31 +79,10 @@ int32 AIEventEnginePreview::GetCapacity()
int32 AIEventEnginePreview::GetMaxSpeed()
{
- switch (::GetEngine(engine)->type) {
- case VEH_ROAD: {
- const RoadVehicleInfo *vi = ::RoadVehInfo(engine);
- /* Internal speeds are km/h * 2 */
- return vi->max_speed / 2;
- } break;
-
- case VEH_TRAIN: {
- const RailVehicleInfo *vi = ::RailVehInfo(engine);
- return vi->max_speed;
- } break;
-
- case VEH_SHIP: {
- const ShipVehicleInfo *vi = ::ShipVehInfo(engine);
- /* Internal speeds are km/h * 2 */
- return vi->max_speed / 2;
- } break;
-
- case VEH_AIRCRAFT: {
- const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine);
- return vi->max_speed / _settings_game.vehicle.plane_speed;
- } break;
-
- default: NOT_REACHED();
- }
+ const Engine *e = ::GetEngine(engine);
+ int32 max_speed = e->GetDisplayMaxSpeed() * 16 / 10; // convert mph to km-ish/h
+ if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
+ return max_speed;
}
Money AIEventEnginePreview::GetPrice()