src/ai/api/ai_tile.cpp
author truebrain
Sun, 24 Feb 2008 23:00:00 +0000
branchnoai
changeset 9756 7e637829cbd3
parent 9737 ee408edf3851
child 9769 015b6674c8ad
permissions -rw-r--r--
(svn r12241) [NoAI] -Fix r12236: global search/replace to the unreadable documentation! WHOHO! (tnx Progman)
/* $Id$ */

/** @file ai_tile.cpp handles the functions of the AITile class */

#include "ai_tile.hpp"
#include "../../tile_map.h"
#include "../../map_func.h"
#include "../../variables.h"
#include "../../station.h"
#include "../../command_type.h"
#include "../../settings_type.h"

/* static */ bool AITile::IsBuildable(TileIndex tile)
{
	/* Outside of the map */
	if (tile >= ::MapSize()) return false;

	switch (::GetTileType(tile)) {
		default: return true;
		case MP_VOID:
		case MP_HOUSE:
		case MP_STATION:
		case MP_INDUSTRY:
		case MP_UNMOVABLE:
		case MP_WATER: return false;
	}
}

/* static */ bool AITile::IsWater(TileIndex tile)
{
	/* Outside of the map */
	if (tile >= ::MapSize()) return false;

	return ::GetTileType(tile) == MP_WATER;
}

/* static */ int32 AITile::GetSlope(TileIndex tile)
{
	/* Outside of the map */
	if (tile >= ::MapSize()) return 0;

	return ::GetTileSlope(tile, NULL);
}

/* static */ int32 AITile::GetHeight(TileIndex tile)
{
	/* Outside of the map */
	if (tile >= ::MapSize()) return 0;

	return ::TileHeight(tile);
}

/* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius)
{
	/* Outside of the map */
	if (tile >= ::MapSize()) return 0;

	AcceptedCargo accepts;
	::GetAcceptanceAroundTiles(accepts, tile, width, height, _patches.modified_catchment ? radius : (uint)CA_UNMODIFIED);
	return accepts[cargo_type];
}

/* static */ int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius)
{
	/* Outside of the map */
	if (tile >= ::MapSize()) return 0;

	AcceptedCargo produced;
	::GetProductionAroundTiles(produced, tile, width, height, _patches.modified_catchment ? radius : (uint)CA_UNMODIFIED);
	return produced[cargo_type];
}

/* static */ bool AITile::RaiseTile(TileIndex tile, int32 slope)
{
	/* Outside of the map */
	if (tile >= ::MapSize()) return false;

	return AIObject::DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND);
}

/* static */ bool AITile::LowerTile(TileIndex tile, int32 slope)
{
	/* Outside of the map */
	if (tile >= ::MapSize()) return false;

	return AIObject::DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND);
}