--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_airport.cpp Fri Jul 13 23:18:12 2007 +0000
@@ -0,0 +1,59 @@
+/* $Id$ */
+
+#include "ai_airport.hpp"
+#include "../../command.h"
+#include "../../station_map.h"
+
+
+bool AIAirport::IsHangarTile(TileIndex tile)
+{
+ /* Outside of the map */
+ if (tile >= ::MapSize()) return false;
+
+ return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile);
+}
+
+bool AIAirport::IsAirportTile(TileIndex tile)
+{
+ /* Outside of the map */
+ if (tile >= ::MapSize()) return false;
+
+ return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile);
+}
+
+bool AIAirport::AiportAvailable(AirportType type)
+{
+ /* Small airport is always available */
+ if (type == AT_SMALL) return true;
+ /* The rest has to be looked up */
+ return HASBIT(::GetValidAirports(), type);
+}
+
+bool AIAirport::BuildAirport(TileIndex tile, AirportType type)
+{
+ /* Outside of the map */
+ if (tile >= ::MapSize()) return false;
+
+ return this->DoCommand(tile, type, 0, CMD_BUILD_AIRPORT);
+}
+
+bool AIAirport::RemoveAirport(TileIndex tile)
+{
+ /* Outside of the map */
+ if (tile >= ::MapSize()) return false;
+
+ /* Not a airport tile */
+ if (!IsAirportTile(tile) && !IsHangarTile(tile)) return false;
+
+ return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+}
+
+TileIndex AIAirport::GetHangarOfAirport(TileIndex tile)
+{
+ if (!IsTileType(tile, MP_STATION)) return INVALID_TILE;
+
+ const Station *st = GetStationByTile(tile);
+ if (st->owner != _current_player) return INVALID_TILE;
+
+ return ToTileIndexDiff(st->Airport()->airport_depots[0]) + st->xy;
+}