(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
/* $Id$ */
#include "ai_airport.hpp"
#include "../../variables.h"
#include "../../station_map.h"
/* static */ bool AIAirport::IsHangarTile(TileIndex tile)
{
/* Outside of the map */
if (tile >= ::MapSize()) return false;
return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile);
}
/* static */ bool AIAirport::IsAirportTile(TileIndex tile)
{
/* Outside of the map */
if (tile >= ::MapSize()) return false;
return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile);
}
/* static */ bool AIAirport::AiportAvailable(AirportType type)
{
if (type > AT_HELISTATION) return 0;
return HasBit(::GetValidAirports(), type);
}
/* static */ int32 AIAirport::GetAirportWidth(AirportType type)
{
if (type > AT_HELISTATION) return 0;
return GetAirport(type)->size_x;
}
/* static */ int32 AIAirport::GetAirportHeight(AirportType type)
{
if (type > AT_HELISTATION) return 0;
return GetAirport(type)->size_y;
}
/* static */ int32 AIAirport::GetAirportCoverageRadius(AirportType type)
{
if (type > AT_HELISTATION) return 0;
return _patches.modified_catchment ? GetAirport(type)->catchment : 4;
}
bool AIAirport::BuildAirport(TileIndex tile, AirportType type)
{
/* Outside of the map */
if (tile >= ::MapSize()) return false;
if (type > AT_HELISTATION) return 0;
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;
}