src/ai/api/ai_tunnel.cpp
branchnoai
changeset 9794 5d866d7cb991
child 9807 5b3be41b3ce6
equal deleted inserted replaced
9793:c5fb53240401 9794:5d866d7cb991
       
     1 /** @file ai_tunnel.cpp handles the query-related of the AITunnel class and can construct tunnels **/
       
     2 
       
     3 #include "ai_tunnel.hpp"
       
     4 #include "../../landscape.h"
       
     5 #include "../../tunnel_map.h"
       
     6 #include "../../road_type.h"
       
     7 
       
     8 /* static */ bool AITunnel::IsTunnelTile(TileIndex tile)
       
     9 {
       
    10 	return ::IsTunnelTile(tile);
       
    11 }
       
    12 
       
    13 /* static */ TileIndex AITunnel::GetOtherTunnelEnd(TileIndex tile)
       
    14 {
       
    15 	if (!IsTunnelTile(tile)) return INVALID_TILE;
       
    16 
       
    17 	return ::GetOtherTunnelEnd(tile);
       
    18 }
       
    19 
       
    20 /* static */ bool AITunnel::BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start)
       
    21 {
       
    22 	if (!::IsValidTile(start)) return false;
       
    23 	if (vehicle_type != AIVehicle::VEHICLE_RAIL && vehicle_type != AIVehicle::VEHICLE_ROAD) return false;
       
    24 
       
    25 	uint type = 0;
       
    26 	if (vehicle_type == AIVehicle::VEHICLE_ROAD) {
       
    27 		type |= (TRANSPORT_ROAD << 9);
       
    28 		type |= ROADTYPES_ROAD;
       
    29 	} else {
       
    30 		type |= (TRANSPORT_RAIL << 9);
       
    31 		type |= RAILTYPES_RAIL;
       
    32 	}
       
    33 
       
    34 	return AIObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL);
       
    35 }
       
    36 
       
    37 /* static */ bool AITunnel::RemoveTunnel(TileIndex tile)
       
    38 {
       
    39 	if (!IsTunnelTile(tile)) return false;
       
    40 
       
    41 	return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
       
    42 }