src/ai/api/ai_airport.cpp
author truebrain
Mon, 16 Jun 2008 00:07:49 +0000
branchnoai
changeset 10977 6c1a6657c7db
parent 10776 07203fc29812
permissions -rw-r--r--
(svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
-Note: if the road pieces failed to build, but building the bridge/tunnel succeeded, the function still returns true (for the obvious reasons)
/* $Id$ */

/** @file ai_airport.cpp Implementation of AIAirport. */

#include "ai_airport.hpp"
#include "ai_error.hpp"
#include "../../openttd.h"
#include "../../variables.h"
#include "../../station_map.h"
#include "../../player_func.h"
#include "../../settings_type.h"
#include "../../command_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 false;
	return HasBit(::GetValidAirports(), type);
}

/* static */ int32 AIAirport::GetAirportWidth(AirportType type)
{
	if (type > AT_HELISTATION) return -1;
	return ::GetAirport(type)->size_x;
}

/* static */ int32 AIAirport::GetAirportHeight(AirportType type)
{
	if (type > AT_HELISTATION) return -1;
	return ::GetAirport(type)->size_y;
}

/* static */ int32 AIAirport::GetAirportCoverageRadius(AirportType type)
{
	if (type > AT_HELISTATION) return -1;
	return _settings_game.station.modified_catchment ? ::GetAirport(type)->catchment : (uint)CA_UNMODIFIED;
}

/* static */ bool AIAirport::BuildAirport(TileIndex tile, AirportType type)
{
	EnforcePrecondition(false, ::IsValidTile(tile));
	EnforcePrecondition(false, type <= AT_HELISTATION);
	return AIObject::DoCommand(tile, type, 0, CMD_BUILD_AIRPORT);
}

/* static */ bool AIAirport::RemoveAirport(TileIndex tile)
{
	EnforcePrecondition(false, ::IsValidTile(tile))
	EnforcePrecondition(false, IsAirportTile(tile) || IsHangarTile(tile));
	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;
}