src/ai/api/ai_tunnel.cpp
author rubidium
Thu, 27 Mar 2008 05:15:06 +0000
branchnoai
changeset 9825 cc77111ebd85
parent 9807 5b3be41b3ce6
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.
/** @file ai_tunnel.cpp handles the query-related of the AITunnel class and can construct tunnels **/

#include "ai_tunnel.hpp"
#include "ai_map.hpp"
#include "../../landscape.h"
#include "../../tunnel_map.h"
#include "../../road_type.h"
#include "../../command_func.h"
#include "../../variables.h"

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

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

	/* If it's a tunnel alread, take the easy way out! */
	if (IsTunnelTile(tile)) return ::GetOtherTunnelEnd(tile);

	::DoCommand(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL);
	return _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile;
}

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