(svn r12315) [NoAI] -Fix: AITunnel::GetOtherTunnelEnd() now also works to estimate where a non-existing tunnel would end (Morloth / glx) noai
authortruebrain
Fri, 29 Feb 2008 00:17:59 +0000
branchnoai
changeset 9807 5b3be41b3ce6
parent 9806 d65cc2bcb0de
child 9808 0b40f556e051
(svn r12315) [NoAI] -Fix: AITunnel::GetOtherTunnelEnd() now also works to estimate where a non-existing tunnel would end (Morloth / glx)
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
src/ai/api/ai_tunnel.cpp
src/ai/api/ai_tunnel.hpp
--- a/bin/ai/regression/regression.nut	Thu Feb 28 14:28:44 2008 +0000
+++ b/bin/ai/regression/regression.nut	Fri Feb 29 00:17:59 2008 +0000
@@ -946,8 +946,11 @@
 {
 	print("  IsTunnelTile():       " + AITunnel.IsTunnelTile(29050));
 	print("  RemoveTunnel():       " + AITunnel.RemoveTunnel(29050));
+	print("  GetOtherTunnelEnd():  " + AITunnel.GetOtherTunnelEnd(29050));
 	print("  BuildTunnel():        " + AITunnel.BuildTunnel(AIVehicle.VEHICLE_ROAD, 29050));
+	print("  GetOtherTunnelEnd():  " + AITunnel.GetOtherTunnelEnd(29050));
 	print("  IsTunnelTile():       " + AITunnel.IsTunnelTile(29050));
+	print("  IsTunnelTile():       " + AITunnel.IsTunnelTile(28026));
 	print("  RemoveTunnel():       " + AITunnel.RemoveTunnel(29050));
 	print("  IsTunnelTile():       " + AITunnel.IsTunnelTile(29050));
 }
--- a/bin/ai/regression/regression.txt	Thu Feb 28 14:28:44 2008 +0000
+++ b/bin/ai/regression/regression.txt	Fri Feb 29 00:17:59 2008 +0000
@@ -5675,7 +5675,10 @@
     0 => 538
   IsTunnelTile():       false
   RemoveTunnel():       false
+  GetOtherTunnelEnd():  28026
   BuildTunnel():        true
+  GetOtherTunnelEnd():  28026
+  IsTunnelTile():       true
   IsTunnelTile():       true
   RemoveTunnel():       true
   IsTunnelTile():       false
--- a/src/ai/api/ai_tunnel.cpp	Thu Feb 28 14:28:44 2008 +0000
+++ b/src/ai/api/ai_tunnel.cpp	Fri Feb 29 00:17:59 2008 +0000
@@ -1,9 +1,12 @@
 /** @file ai_tunnel.cpp handles the query-related of the AITunnel class and can construct tunnels **/
 
 #include "ai_tunnel.hpp"
+#include "ai_map.hpp"
 #include "../../landscape.h"
 #include "../../tunnel_map.h"
 #include "../../road_type.h"
+#include "../../command_func.h"
+#include "../../variables.h"
 
 /* static */ bool AITunnel::IsTunnelTile(TileIndex tile)
 {
@@ -12,9 +15,13 @@
 
 /* static */ TileIndex AITunnel::GetOtherTunnelEnd(TileIndex tile)
 {
-	if (!IsTunnelTile(tile)) return INVALID_TILE;
+	if (!::IsValidTile(tile)) return INVALID_TILE;
 
-	return ::GetOtherTunnelEnd(tile);
+	/* If it's a tunnel alread, take the easy way out! */
+	if (IsTunnelTile(tile)) return ::GetOtherTunnelEnd(tile);
+
+	::DoCommand(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL);
+	return _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile;
 }
 
 /* static */ bool AITunnel::BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start)
--- a/src/ai/api/ai_tunnel.hpp	Thu Feb 28 14:28:44 2008 +0000
+++ b/src/ai/api/ai_tunnel.hpp	Fri Feb 29 00:17:59 2008 +0000
@@ -17,7 +17,7 @@
 	static const char *GetClassName() { return "AITunnel"; }
 
 	/**
-	 * Check wether the tile is an entrance to a tunnel.
+	 * Check whether the tile is an entrance to a tunnel.
 	 * @pre AIMap::IsValidTile(tile).
 	 * @param tile The tile to check.
 	 * @note true if and only if the tile is the beginning or end of a tunnel.
@@ -25,10 +25,10 @@
 	static bool IsTunnelTile(TileIndex tile);
 
 	/**
-	 * Get the tile that exits on the other end of a tunnel starting at tunnelTile.
-	 * @pre AIMap::IsValidTile(tile) && IsTunnelTile(tile).
-	 * @param tile A tile that is an entrance to a tunnel.
-	 * @return The TileIndex that is the other end of the tunnel.
+	 * Get the tile that exits on the other end of a (would be) tunnel starting at tile.
+	 * @pre AIMap::IsValidTile(tile).
+	 * @param tile A tile that is an entrance to a tunnel or a tile where you may want to build a tunnel.
+	 * @return The TileIndex that is the other end of the (would be) tunnel, or 'tile' if no other end was found (crossing tunnels).
 	 */
 	static TileIndex GetOtherTunnelEnd(TileIndex tile);