src/ai/api/ai_airport.cpp
author rubidium
Sun, 15 Jul 2007 16:39:11 +0000
branchnoai
changeset 9668 6fe3d2cb9655
parent 9654 b836eb5c521f
child 9670 820b77e19bb3
permissions -rw-r--r--
(svn r10582) [NoAI] -Codechange: allow getting the president and company names of other companies as well as their company value and bank balance.
/* $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;
}