src/ai/api/ai_airport.cpp
author rubidium
Thu, 27 Mar 2008 05:15:06 +0000
branchnoai
changeset 9825 cc77111ebd85
parent 9820 8c116d4c6033
child 9833 89a64246458f
permissions -rw-r--r--
(svn r12437) [NoAI] -Add: functions to get the current date and to determine the year/month/day from that date.
/* $Id$ */

/** @file ai_airport.cpp handles the functions of the AIAirport class */

#include "ai_airport.hpp"
#include "../../variables.h"
#include "../../station_map.h"
#include "../../player_func.h"
#include "../../settings_type.h"

/* static */ bool AIAirport::IsHangarTile(TileIndex tile)
{
	if (!::IsValidTile(tile)) return false;

	return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile);
}

/* static */ bool AIAirport::IsAirportTile(TileIndex tile)
{
	if (!::IsValidTile(tile)) return false;

	return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile);
}

/* static */ bool AIAirport::AirportAvailable(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 : (uint)CA_UNMODIFIED;
}

/* static */ bool AIAirport::BuildAirport(TileIndex tile, AirportType type)
{
	if (!::IsValidTile(tile)) return false;
	if (type > AT_HELISTATION) return 0;

	return AIObject::DoCommand(tile, type, 0, CMD_BUILD_AIRPORT);
}

/* static */ bool AIAirport::RemoveAirport(TileIndex tile)
{
	if (!::IsValidTile(tile)) return false;
	if (!IsAirportTile(tile) && !IsHangarTile(tile)) return false;

	return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
}

/* static */ 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;
}