(svn r13235) [NoAI] -Change [API CHANGE]: AITunnel.GetOtherTunnelEnd() now returns INVALID_TILE if no other end is found noai
authorglx
Sat, 24 May 2008 22:48:46 +0000
branchnoai
changeset 10691 a60393d87c0b
parent 10679 fcd493243794
child 10713 c5c9dc32c052
(svn r13235) [NoAI] -Change [API CHANGE]: AITunnel.GetOtherTunnelEnd() now returns INVALID_TILE if no other end is found
[NoAI] -Add [FS#2028]: added AIBridge.GetOtherBridgeEnd() which allows you to find the other end of a bridge
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
src/ai/api/ai_bridge.cpp
src/ai/api/ai_bridge.hpp
src/ai/api/ai_bridge.hpp.sq
src/ai/api/ai_tunnel.cpp
src/ai/api/ai_tunnel.hpp
--- a/bin/ai/regression/regression.nut	Fri May 23 16:19:13 2008 +0000
+++ b/bin/ai/regression/regression.nut	Sat May 24 22:48:46 2008 +0000
@@ -104,9 +104,11 @@
 	print("  IsBridgeTile():       " + AIBridge.IsBridgeTile(33160));
 	print("  RemoveBridge():       " + AIBridge.RemoveBridge(33155));
 	print("  GetLastErrorString(): " + AIError.GetLastErrorString());
+	print("  GetOtherBridgeEnd():  " + AIBridge.GetOtherBridgeEnd(33160));
 	print("  BuildBridge():        " + AIBridge.BuildBridge(AIVehicle.VEHICLE_ROAD, 5, 33160, 33155));
 	print("  IsBridgeTile():       " + AIBridge.IsBridgeTile(33160));
 	print("  IsBridgeTile():       " + AIBridge.IsBridgeTile(33155));
+	print("  GetOtherBridgeEnd():  " + AIBridge.GetOtherBridgeEnd(33160));
 	print("  BuildBridge():        " + AIBridge.BuildBridge(AIVehicle.VEHICLE_ROAD, 5, 33160, 33155));
 	print("  GetLastErrorString(): " + AIError.GetLastErrorString());
 	print("  RemoveBridge():       " + AIBridge.RemoveBridge(33155));
--- a/bin/ai/regression/regression.txt	Fri May 23 16:19:13 2008 +0000
+++ b/bin/ai/regression/regression.txt	Sat May 24 22:48:46 2008 +0000
@@ -572,9 +572,11 @@
   IsBridgeTile():       false
   RemoveBridge():       false
   GetLastErrorString(): ERR_PRECONDITION_FAILED
+  GetOtherBridgeEnd():  -1
   BuildBridge():        true
   IsBridgeTile():       true
   IsBridgeTile():       true
+  GetOtherBridgeEnd():  33155
   BuildBridge():        false
   GetLastErrorString(): ERR_ALREADY_BUILT
   RemoveBridge():       true
--- a/src/ai/api/ai_bridge.cpp	Fri May 23 16:19:13 2008 +0000
+++ b/src/ai/api/ai_bridge.cpp	Sat May 24 22:48:46 2008 +0000
@@ -94,3 +94,11 @@
 
 	return ::GetBridgeSpec(bridge_id)->avail_year;
 }
+
+/* static */ TileIndex AIBridge::GetOtherBridgeEnd(TileIndex tile)
+{
+	if (!::IsValidTile(tile)) return INVALID_TILE;
+	if (!IsBridgeTile(tile)) return INVALID_TILE;
+
+	return ::GetOtherBridgeEnd(tile);
+}
--- a/src/ai/api/ai_bridge.hpp	Fri May 23 16:19:13 2008 +0000
+++ b/src/ai/api/ai_bridge.hpp	Sat May 24 22:48:46 2008 +0000
@@ -132,6 +132,15 @@
 	 * @return Whether the bridge has been/can be removed or not.
 	 */
 	static bool RemoveBridge(TileIndex tile);
+
+	/**
+	 * Get the tile that is on the other end of a bridge starting at tile.
+	 * @param tile The tile that is an end of a bridge.
+	 * @pre AIMap::IsValidTile(tile).
+	 * @pre IsBridgeTile(tile).
+	 * @return The TileIndex that is the other end of the bridge.
+	 */
+	static TileIndex GetOtherBridgeEnd(TileIndex tile);
 };
 
 #endif /* AI_BRIDGE_HPP */
--- a/src/ai/api/ai_bridge.hpp.sq	Fri May 23 16:19:13 2008 +0000
+++ b/src/ai/api/ai_bridge.hpp.sq	Sat May 24 22:48:46 2008 +0000
@@ -34,17 +34,18 @@
 	AIError::RegisterErrorMapString(AIBridge::ERR_BRIDGE_CANNOT_END_IN_WATER,      "ERR_BRIDGE_CANNOT_END_IN_WATER");
 	AIError::RegisterErrorMapString(AIBridge::ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT, "ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT");
 
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetClassName,     "GetClassName",     1, "x");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsValidBridge,    "IsValidBridge",    2, "xi");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsBridgeTile,     "IsBridgeTile",     2, "xi");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetName,          "GetName",          2, "xi");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetMaxSpeed,      "GetMaxSpeed",      2, "xi");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetPrice,         "GetPrice",         3, "xii");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetMaxLength,     "GetMaxLength",     2, "xi");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetMinLength,     "GetMinLength",     2, "xi");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetYearAvailable, "GetYearAvailable", 2, "xi");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::BuildBridge,      "BuildBridge",      5, "xiiii");
-	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::RemoveBridge,     "RemoveBridge",     2, "xi");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetClassName,      "GetClassName",      1, "x");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsValidBridge,     "IsValidBridge",     2, "xi");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsBridgeTile,      "IsBridgeTile",      2, "xi");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetName,           "GetName",           2, "xi");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetMaxSpeed,       "GetMaxSpeed",       2, "xi");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetPrice,          "GetPrice",          3, "xii");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetMaxLength,      "GetMaxLength",      2, "xi");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetMinLength,      "GetMinLength",      2, "xi");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetYearAvailable,  "GetYearAvailable",  2, "xi");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::BuildBridge,       "BuildBridge",       5, "xiiii");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::RemoveBridge,      "RemoveBridge",      2, "xi");
+	SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetOtherBridgeEnd, "GetOtherBridgeEnd", 2, "xi");
 
 	SQAIBridge.PostRegister(engine);
 }
--- a/src/ai/api/ai_tunnel.cpp	Fri May 23 16:19:13 2008 +0000
+++ b/src/ai/api/ai_tunnel.cpp	Sat May 24 22:48:46 2008 +0000
@@ -25,7 +25,7 @@
 	if (IsTunnelTile(tile)) return ::GetOtherTunnelEnd(tile);
 
 	::DoCommand(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL);
-	return _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile;
+	return _build_tunnel_endtile == 0 ? INVALID_TILE : _build_tunnel_endtile;
 }
 
 /* static */ bool AITunnel::BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start)
--- a/src/ai/api/ai_tunnel.hpp	Fri May 23 16:19:13 2008 +0000
+++ b/src/ai/api/ai_tunnel.hpp	Sat May 24 22:48:46 2008 +0000
@@ -50,7 +50,7 @@
 	 * @param tile The tile that is an entrance to a tunnel or the tile where you may want to build a tunnel.
 	 * @pre AIMap::IsValidTile(tile).
 	 * @return The TileIndex that is the other end of the (would be) tunnel, or
-	 *  'tile' if no other end was found (crossing tunnels).
+	 *  INVALID_TILE if no other end was found (can't build tunnel).
 	 */
 	static TileIndex GetOtherTunnelEnd(TileIndex tile);