diff options
author | yexo <yexo@openttd.org> | 2009-03-28 12:04:38 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2009-03-28 12:04:38 +0000 |
commit | 400208ee0afd84f1e9ddf1ab851e34a87b3e98c0 (patch) | |
tree | d96ab887f0146fd83a81a513c794f40959849e14 | |
parent | e02d31cd3abaf078131a82e7d0a0c46a5a759d24 (diff) | |
download | openttd-400208ee0afd84f1e9ddf1ab851e34a87b3e98c0.tar.xz |
(svn r15875) -Add: AIBridge::GetBridgeID() so AIs can get the type of bridge that are already build.
-rw-r--r-- | bin/ai/regression/regression.nut | 3 | ||||
-rw-r--r-- | bin/ai/regression/regression.txt | 3 | ||||
-rw-r--r-- | src/ai/api/ai_bridge.cpp | 6 | ||||
-rw-r--r-- | src/ai/api/ai_bridge.hpp | 8 | ||||
-rw-r--r-- | src/ai/api/ai_bridge.hpp.sq | 1 |
5 files changed, 21 insertions, 0 deletions
diff --git a/bin/ai/regression/regression.nut b/bin/ai/regression/regression.nut index 152ab6d51..827145e77 100644 --- a/bin/ai/regression/regression.nut +++ b/bin/ai/regression/regression.nut @@ -256,12 +256,15 @@ function Regression::Bridge() print(" Valid Bridges: " + j); print(" IsBridgeTile(): " + AIBridge.IsBridgeTile(33160)); + print(" GetBridgeID(): " + AIBridge.GetBridgeID(33160)); print(" RemoveBridge(): " + AIBridge.RemoveBridge(33155)); print(" GetLastErrorString(): " + AIError.GetLastErrorString()); print(" GetOtherBridgeEnd(): " + AIBridge.GetOtherBridgeEnd(33160)); print(" BuildBridge(): " + AIBridge.BuildBridge(AIVehicle.VT_ROAD, 5, 33160, 33155)); print(" IsBridgeTile(): " + AIBridge.IsBridgeTile(33160)); + print(" GetBridgeID(): " + AIBridge.GetBridgeID(33160)); print(" IsBridgeTile(): " + AIBridge.IsBridgeTile(33155)); + print(" GetBridgeID(): " + AIBridge.GetBridgeID(33155)); print(" GetOtherBridgeEnd(): " + AIBridge.GetOtherBridgeEnd(33160)); print(" BuildBridge(): " + AIBridge.BuildBridge(AIVehicle.VT_ROAD, 5, 33160, 33155)); print(" GetLastErrorString(): " + AIError.GetLastErrorString()); diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt index cf105624c..3eefdd3fb 100644 --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -743,12 +743,15 @@ GetMinLength(): -1 Valid Bridges: 10 IsBridgeTile(): false + GetBridgeID(): -1 RemoveBridge(): false GetLastErrorString(): ERR_PRECONDITION_FAILED GetOtherBridgeEnd(): -1 BuildBridge(): true IsBridgeTile(): true + GetBridgeID(): 5 IsBridgeTile(): true + GetBridgeID(): 5 GetOtherBridgeEnd(): 33155 BuildBridge(): false GetLastErrorString(): ERR_ALREADY_BUILT diff --git a/src/ai/api/ai_bridge.cpp b/src/ai/api/ai_bridge.cpp index 27f5c116e..4e7d51776 100644 --- a/src/ai/api/ai_bridge.cpp +++ b/src/ai/api/ai_bridge.cpp @@ -23,6 +23,12 @@ return ::IsBridgeTile(tile); } +/* static */ BridgeID AIBridge::GetBridgeID(TileIndex tile) +{ + if (!IsBridgeTile(tile)) return -1; + return (BridgeID)::GetBridgeType(tile); +} + static void _DoCommandReturnBuildBridge2(class AIInstance *instance) { if (!AIBridge::_BuildBridgeRoad2()) { diff --git a/src/ai/api/ai_bridge.hpp b/src/ai/api/ai_bridge.hpp index f53ee2339..58cc9d60b 100644 --- a/src/ai/api/ai_bridge.hpp +++ b/src/ai/api/ai_bridge.hpp @@ -52,6 +52,14 @@ public: static bool IsBridgeTile(TileIndex tile); /** + * Get the BridgeID of a bridge at a given tile. + * @param tile The tile to get the BridgeID from. + * @pre IsBridgeTile(tile). + * @return The BridgeID from the bridge at tile 'tile'. + */ + static BridgeID GetBridgeID(TileIndex tile); + + /** * Get the name of a bridge. * @param bridge_id The bridge to get the name of. * @pre IsValidBridge(bridge_id). diff --git a/src/ai/api/ai_bridge.hpp.sq b/src/ai/api/ai_bridge.hpp.sq index 1a4117457..eddd4f5da 100644 --- a/src/ai/api/ai_bridge.hpp.sq +++ b/src/ai/api/ai_bridge.hpp.sq @@ -36,6 +36,7 @@ void SQAIBridge_Register(Squirrel *engine) { SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsValidBridge, "IsValidBridge", 2, ".i"); SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsBridgeTile, "IsBridgeTile", 2, ".i"); + SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetBridgeID, "GetBridgeID", 2, ".i"); SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetName, "GetName", 2, ".i"); SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetMaxSpeed, "GetMaxSpeed", 2, ".i"); SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetPrice, "GetPrice", 3, ".ii"); |