src/ai/api/ai_airport.cpp
branchnoai
changeset 9654 b836eb5c521f
child 9670 820b77e19bb3
equal deleted inserted replaced
9653:50e2eb4abf46 9654:b836eb5c521f
       
     1 /* $Id$ */
       
     2 
       
     3 #include "ai_airport.hpp"
       
     4 #include "../../command.h"
       
     5 #include "../../station_map.h"
       
     6 
       
     7 
       
     8 bool AIAirport::IsHangarTile(TileIndex tile)
       
     9 {
       
    10 	/* Outside of the map */
       
    11 	if (tile >= ::MapSize()) return false;
       
    12 
       
    13 	return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile);
       
    14 }
       
    15 
       
    16 bool AIAirport::IsAirportTile(TileIndex tile)
       
    17 {
       
    18 	/* Outside of the map */
       
    19 	if (tile >= ::MapSize()) return false;
       
    20 
       
    21 	return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile);
       
    22 }
       
    23 
       
    24 bool AIAirport::AiportAvailable(AirportType type)
       
    25 {
       
    26 	/* Small airport is always available */
       
    27 	if (type == AT_SMALL) return true;
       
    28 	/* The rest has to be looked up */
       
    29 	return HASBIT(::GetValidAirports(), type);
       
    30 }
       
    31 
       
    32 bool AIAirport::BuildAirport(TileIndex tile, AirportType type)
       
    33 {
       
    34 	/* Outside of the map */
       
    35 	if (tile >= ::MapSize()) return false;
       
    36 
       
    37 	return this->DoCommand(tile, type, 0, CMD_BUILD_AIRPORT);
       
    38 }
       
    39 
       
    40 bool AIAirport::RemoveAirport(TileIndex tile)
       
    41 {
       
    42 	/* Outside of the map */
       
    43 	if (tile >= ::MapSize()) return false;
       
    44 
       
    45 	/* Not a airport tile */
       
    46 	if (!IsAirportTile(tile) && !IsHangarTile(tile)) return false;
       
    47 
       
    48 	return this->DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
       
    49 }
       
    50 
       
    51 TileIndex AIAirport::GetHangarOfAirport(TileIndex tile)
       
    52 {
       
    53 	if (!IsTileType(tile, MP_STATION)) return INVALID_TILE;
       
    54 
       
    55 	const Station *st = GetStationByTile(tile);
       
    56 	if (st->owner != _current_player) return INVALID_TILE;
       
    57 
       
    58 	return ToTileIndexDiff(st->Airport()->airport_depots[0]) + st->xy;
       
    59 }