summaryrefslogtreecommitdiff
path: root/src/ai/api/ai_tunnel.hpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2009-01-12 17:11:45 +0000
committertruebrain <truebrain@openttd.org>2009-01-12 17:11:45 +0000
commita3dd7506d377b1434f913bd65c019eed52b64b6e (patch)
treeced1a262eb143ad6e64ec02f4a4c89835c0c32fd /src/ai/api/ai_tunnel.hpp
parent9294f9616866b9778c22076c19b5a32b4f85f788 (diff)
downloadopenttd-a3dd7506d377b1434f913bd65c019eed52b64b6e.tar.xz
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
NoAI is an API (a framework) to build your own AIs in. See: http://wiki.openttd.org/wiki/index.php/AI:Main_Page With many thanks to: - glx and Rubidium for their syncing, feedback and hard work - Yexo for his feedback, patches, and AIs which tested the system very deep - Morloth for his feedback and patches - TJIP for hosting a challenge which kept NoAI on track - All AI authors for testing our AI API, and all other people who helped in one way or another -Remove: all old AIs and their cheats/hacks
Diffstat (limited to 'src/ai/api/ai_tunnel.hpp')
-rw-r--r--src/ai/api/ai_tunnel.hpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/ai/api/ai_tunnel.hpp b/src/ai/api/ai_tunnel.hpp
new file mode 100644
index 000000000..625237905
--- /dev/null
+++ b/src/ai/api/ai_tunnel.hpp
@@ -0,0 +1,103 @@
+/* $Id$ */
+
+/** @file ai_tunnel.hpp Everything to query and build tunnels. */
+
+#ifndef AI_TUNNEL_HPP
+#define AI_TUNNEL_HPP
+
+#include "ai_object.hpp"
+#include "ai_vehicle.hpp"
+
+/**
+ * Class that handles all tunnel related functions.
+ */
+class AITunnel : public AIObject {
+public:
+ static const char *GetClassName() { return "AITunnel"; }
+
+ /**
+ * All tunnel related errors.
+ */
+ enum ErrorMessages {
+
+ /** Base for bridge related errors */
+ ERR_TUNNEL_BASE = AIError::ERR_CAT_TUNNEL << AIError::ERR_CAT_BIT_SIZE,
+
+ /** Can't build tunnels on water */
+ ERR_TUNNEL_CANNOT_BUILD_ON_WATER, // [STR_3807_CAN_T_BUILD_ON_WATER]
+
+ /** The start tile must slope either North, South, West or East */
+ ERR_TUNNEL_START_SITE_UNSUITABLE, // [STR_500B_SITE_UNSUITABLE_FOR_TUNNEL]
+
+ /** An other tunnel is in the way */
+ ERR_TUNNEL_ANOTHER_TUNNEL_IN_THE_WAY, // [STR_5003_ANOTHER_TUNNEL_IN_THE_WAY]
+
+ /** Unable to excavate land at the end to create the tunnel's exit */
+ ERR_TUNNEL_END_SITE_UNSUITABLE, // [STR_5005_UNABLE_TO_EXCAVATE_LAND]
+ };
+
+ /**
+ * Check whether the tile is an entrance to a tunnel.
+ * @param tile The tile to check.
+ * @pre AIMap::IsValidTile(tile).
+ * @return True if and only if the tile is the beginning or end of a tunnel.
+ */
+ static bool IsTunnelTile(TileIndex tile);
+
+ /**
+ * Get the tile that exits on the other end of a (would be) tunnel starting
+ * at tile.
+ * @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
+ * INVALID_TILE if no other end was found (can't build tunnel).
+ */
+ static TileIndex GetOtherTunnelEnd(TileIndex tile);
+
+#ifndef DOXYGEN_SKIP
+ /**
+ * Internal function to help BuildTunnel in case of road.
+ */
+ static bool _BuildTunnelRoad1();
+
+ /**
+ * Internal function to help BuildTunnel in case of road.
+ */
+ static bool _BuildTunnelRoad2();
+#endif
+
+ /**
+ * Builds a tunnel starting at start. The direction of the tunnel depends
+ * on the slope of the start tile. Tunnels can be created for either
+ * rails or roads; use the appropriate AIVehicle::VehicleType.
+ * As an extra for road, this functions builds two half-pieces of road on
+ * each end of the tunnel, making it easier for you to connect it to your
+ * network.
+ * @param start Where to start the tunnel.
+ * @param vehicle_type The vehicle-type of tunnel to build.
+ * @pre AIMap::IsValidTile(start).
+ * @pre vehicle_type == AIVehicle::VEHICLE_ROAD || (vehicle_type == AIVehicle::VEHICLE_RAIL &&
+ * AIRail::IsRailTypeAvailable(AIRail::GetCurrentRailType())).
+ * @exception AIError::ERR_AREA_NOT_CLEAR
+ * @exception AITunnel::ERR_TUNNEL_CANNOT_BUILD_ON_WATER
+ * @exception AITunnel::ERR_TUNNEL_START_SITE_UNSUITABLE
+ * @exception AITunnel::ERR_TUNNEL_ANOTHER_TUNNEL_IN_THE_WAY
+ * @exception AITunnel::ERR_TUNNEL_END_SITE_UNSUITABLE
+ * @return Whether the tunnel has been/can be build or not.
+ * @note The slope of a tile can be determined by AITile::GetSlope(TileIndex).
+ * @note No matter if the road pieces were build or not, if building the
+ * tunnel succeeded, this function returns true.
+ */
+ static bool BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start);
+
+ /**
+ * Remove the tunnel whose entrance is located at tile.
+ * @param tile The tile that is an entrance to a tunnel.
+ * @pre AIMap::IsValidTile(tile) && IsTunnelTile(tile).
+ * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
+ * @return Whether the tunnel has been/can be removed or not.
+ */
+ static bool RemoveTunnel(TileIndex tile);
+};
+
+#endif /* AI_TUNNEL_HPP */