src/ai/api/ai_airport.cpp
author truebrain
Sat, 23 Feb 2008 16:21:10 +0000
branchnoai
changeset 9746 e4ab7ea8d897
parent 9737 ee408edf3851
child 9773 d2c20cd38f18
permissions -rw-r--r--
(svn r12226) [NoAI] -Fix: remove the dep for AIStationList_Vehicle on AIStationList, as Squirrel doesn't like it
/* $Id$ */

#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)
{
	/* 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 : (uint)CA_UNMODIFIED;
}

/* static */ bool AIAirport::BuildAirport(TileIndex tile, AirportType type)
{
	/* Outside of the map */
	if (tile >= ::MapSize()) return false;
	if (type > AT_HELISTATION) return 0;

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

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