src/ai/api/ai_marine.cpp
branchnoai
changeset 9691 1231d4e5f5aa
child 9695 708f1e3cc4c4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_marine.cpp	Tue Jul 24 21:09:39 2007 +0000
@@ -0,0 +1,143 @@
+/* $Id$ */
+
+#include "ai_marine.hpp"
+#include "../../command.h"
+#include "../../variables.h"
+#include "../../station_map.h"
+#include "../../water_map.h"
+
+
+/* static */ bool AIMarine::IsWaterDepotTile(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return ::IsTileType(tile, MP_WATER) && ::GetWaterTileType(tile) == WATER_TILE_DEPOT;
+}
+
+/* static */ bool AIMarine::IsDockTile(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return ::IsTileType(tile, MP_STATION) && ::IsDock(tile);
+}
+
+/* static */ bool AIMarine::IsBuoyTile(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return ::IsTileType(tile, MP_STATION) && ::IsBuoy(tile);
+}
+
+/* static */ bool AIMarine::IsLockTile(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return ::IsTileType(tile, MP_WATER) && ::GetWaterTileType(tile) == WATER_TILE_LOCK;
+}
+
+/* static */ bool AIMarine::IsCanalTile(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return ::IsTileType(tile, MP_WATER) && ::IsCanal(tile);
+}
+
+bool AIMarine::BuildWaterDepot(TileIndex tile, bool vertical)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return this->DoCommand(tile, vertical, 0, CMD_BUILD_SHIP_DEPOT);
+}
+
+bool AIMarine::BuildDock(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return this->DoCommand(tile, 1, 0, CMD_BUILD_DOCK);
+}
+
+bool AIMarine::BuildBuoy(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return this->DoCommand(tile, 0, 0, CMD_BUILD_BUOY);
+}
+
+bool AIMarine::BuildLock(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return this->DoCommand(tile, 0, 0, CMD_BUILD_LOCK);
+}
+
+bool AIMarine::BuildCanal(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	return this->DoCommand(tile, tile, 0, CMD_BUILD_CANAL);
+}
+
+bool AIMarine::RemoveWaterDepot(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	/* Not a water depot tile */
+	if (!IsWaterDepotTile(tile)) return false;
+
+	return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+}
+
+bool AIMarine::RemoveDock(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	/* Not a dock tile */
+	if (!IsDockTile(tile)) return false;
+
+	return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+}
+
+bool AIMarine::RemoveBuoy(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	/* Not a buoy tile */
+	if (!IsBuoyTile(tile)) return false;
+
+	return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+}
+
+bool AIMarine::RemoveLock(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	/* Not a lock tile */
+	if (!IsLockTile(tile)) return false;
+
+	return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+}
+
+bool AIMarine::RemoveCanal(TileIndex tile)
+{
+	/* Outside of the map */
+	if (tile >= ::MapSize()) return false;
+
+	/* Not a canal tile */
+	if (!IsCanalTile(tile)) return false;
+
+	return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+}