src/ai/api/ai_tunnel.cpp
author truebrain
Thu, 28 Feb 2008 01:11:23 +0000
branchnoai
changeset 9803 c86d5834fb11
parent 9794 5d866d7cb991
child 9807 5b3be41b3ce6
permissions -rw-r--r--
(svn r12309) [NoAI] -Codechange: optimize a little bit (a very small little bit, but every bit counts :) ) (glx)
/** @file ai_tunnel.cpp handles the query-related of the AITunnel class and can construct tunnels **/

#include "ai_tunnel.hpp"
#include "../../landscape.h"
#include "../../tunnel_map.h"
#include "../../road_type.h"

/* static */ bool AITunnel::IsTunnelTile(TileIndex tile)
{
	return ::IsTunnelTile(tile);
}

/* static */ TileIndex AITunnel::GetOtherTunnelEnd(TileIndex tile)
{
	if (!IsTunnelTile(tile)) return INVALID_TILE;

	return ::GetOtherTunnelEnd(tile);
}

/* static */ bool AITunnel::BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start)
{
	if (!::IsValidTile(start)) return false;
	if (vehicle_type != AIVehicle::VEHICLE_RAIL && vehicle_type != AIVehicle::VEHICLE_ROAD) return false;

	uint type = 0;
	if (vehicle_type == AIVehicle::VEHICLE_ROAD) {
		type |= (TRANSPORT_ROAD << 9);
		type |= ROADTYPES_ROAD;
	} else {
		type |= (TRANSPORT_RAIL << 9);
		type |= RAILTYPES_RAIL;
	}

	return AIObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL);
}

/* static */ bool AITunnel::RemoveTunnel(TileIndex tile)
{
	if (!IsTunnelTile(tile)) return false;

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