From 400208ee0afd84f1e9ddf1ab851e34a87b3e98c0 Mon Sep 17 00:00:00 2001 From: yexo Date: Sat, 28 Mar 2009 12:04:38 +0000 Subject: (svn r15875) -Add: AIBridge::GetBridgeID() so AIs can get the type of bridge that are already build. --- src/ai/api/ai_bridge.cpp | 6 ++++++ src/ai/api/ai_bridge.hpp | 8 ++++++++ src/ai/api/ai_bridge.hpp.sq | 1 + 3 files changed, 15 insertions(+) (limited to 'src/ai/api') 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 @@ -51,6 +51,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. 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"); -- cgit v1.2.3-54-g00ecf