From 01bbb17cb182047705d61707fe636af3fc0657f0 Mon Sep 17 00:00:00 2001 From: yexo Date: Fri, 9 Apr 2010 12:02:50 +0000 Subject: [PATCH] (svn r19591) -Add: [NoAI] AIRail::GetMaxSpeed(RailType) to get the speed limit of railtypes --- bin/ai/regression/regression.nut | 1 + bin/ai/regression/regression.txt | 1 + src/ai/api/ai_rail.cpp | 7 +++++++ src/ai/api/ai_rail.hpp | 12 ++++++++++++ src/ai/api/ai_rail.hpp.sq | 1 + 5 files changed, 22 insertions(+) diff --git a/bin/ai/regression/regression.nut b/bin/ai/regression/regression.nut index eb9b9667f1..5f835c528f 100644 --- a/bin/ai/regression/regression.nut +++ b/bin/ai/regression/regression.nut @@ -1027,6 +1027,7 @@ function Regression::RailTypeList() for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { print(" RailType: " + i); print(" IsRailTypeAvailable(): " + AIRail.IsRailTypeAvailable(i)); + print(" GetMaxSpeed(): " + AIRail.GetMaxSpeed(i)); } } diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt index 35d4ed272b..611450f469 100644 --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -7208,6 +7208,7 @@ ERROR: IsEnd() is invalid as Begin() is never called ListDump: RailType: 0 IsRailTypeAvailable(): true + GetMaxSpeed(): 0 --Road-- Road diff --git a/src/ai/api/ai_rail.cpp b/src/ai/api/ai_rail.cpp index ae349ccde0..1db02e274f 100644 --- a/src/ai/api/ai_rail.cpp +++ b/src/ai/api/ai_rail.cpp @@ -469,3 +469,10 @@ static bool IsValidSignalType(int signal_type) default: return -1; } } + +/* static */ int32 AIRail::GetMaxSpeed(RailType railtype) +{ + if (!AIRail::IsRailTypeAvailable(railtype)) return -1; + + return ::GetRailTypeInfo((::RailType)railtype)->max_speed; +} diff --git a/src/ai/api/ai_rail.hpp b/src/ai/api/ai_rail.hpp index e82d01ae9f..5a8a3d111a 100644 --- a/src/ai/api/ai_rail.hpp +++ b/src/ai/api/ai_rail.hpp @@ -440,6 +440,18 @@ public: * @return The baseprice of building the given object. */ static Money GetBuildCost(RailType railtype, BuildType build_type); + + /** + * Get the maximum speed of trains running on this railtype. + * @param railtype The railtype to get the maximum speed of. + * @pre IsRailTypeAvailable(railtype) + * @return The maximum speed trains can run on this railtype + * or 0 if there is no limit. + * @note The speed is in OpenTTD's internal speed unit. + * This is mph / 1.6, which is roughly km/h. + * To get km/h multiply this number by 1.00584. + */ + static int32 GetMaxSpeed(RailType railtype); }; #endif /* AI_RAIL_HPP */ diff --git a/src/ai/api/ai_rail.hpp.sq b/src/ai/api/ai_rail.hpp.sq index 9f9365e0df..30c875c4ea 100644 --- a/src/ai/api/ai_rail.hpp.sq +++ b/src/ai/api/ai_rail.hpp.sq @@ -106,6 +106,7 @@ void SQAIRail_Register(Squirrel *engine) SQAIRail.DefSQStaticMethod(engine, &AIRail::BuildSignal, "BuildSignal", 4, ".iii"); SQAIRail.DefSQStaticMethod(engine, &AIRail::RemoveSignal, "RemoveSignal", 3, ".ii"); SQAIRail.DefSQStaticMethod(engine, &AIRail::GetBuildCost, "GetBuildCost", 3, ".ii"); + SQAIRail.DefSQStaticMethod(engine, &AIRail::GetMaxSpeed, "GetMaxSpeed", 2, ".i"); SQAIRail.PostRegister(engine); }