src/ai/api/ai_bridge.cpp
branchnoai
changeset 9868 3998f2e73dda
parent 9867 b7d9ffe24f81
child 10194 c9fdeb7450da
equal deleted inserted replaced
9867:b7d9ffe24f81 9868:3998f2e73dda
    22 	return ::IsBridgeTile(tile);
    22 	return ::IsBridgeTile(tile);
    23 }
    23 }
    24 
    24 
    25 /* static */ bool AIBridge::BuildBridge(AIVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end)
    25 /* static */ bool AIBridge::BuildBridge(AIVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end)
    26 {
    26 {
    27 	if (start == end ||
    27 	EnforcePrecondition(false, start != end);
    28 			!::IsValidTile(start) ||
    28 	EnforcePrecondition(false, ::IsValidTile(start) && ::IsValidTile(end));
    29 			!::IsValidTile(end) ||
    29 	EnforcePrecondition(false, TileX(start) == TileX(end) || TileY(start) == TileY(end));
    30 			/* Not on one line */
    30 	EnforcePrecondition(false, vehicle_type == AIVehicle::VEHICLE_ROAD || vehicle_type == AIVehicle::VEHICLE_RAIL);
    31 			(TileX(start) != TileX(end) && TileY(start) != TileY(end)) ||
       
    32 			(vehicle_type != AIVehicle::VEHICLE_ROAD && vehicle_type != AIVehicle::VEHICLE_RAIL)) {
       
    33 		AIObject::SetLastError(AIError::ERR_PRECONDITION_FAILED);
       
    34 		return false;
       
    35 	}
       
    36 
    31 
    37 	uint type = 0;
    32 	uint type = 0;
    38 	if (vehicle_type == AIVehicle::VEHICLE_ROAD) {
    33 	if (vehicle_type == AIVehicle::VEHICLE_ROAD) {
    39 		type |= (TRANSPORT_ROAD << 15);
    34 		type |= (TRANSPORT_ROAD << 15);
    40 		type |= (ROADTYPES_ROAD << 8);
    35 		type |= (ROADTYPES_ROAD << 8);
    46 	return AIObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE);
    41 	return AIObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE);
    47 }
    42 }
    48 
    43 
    49 /* static */ bool AIBridge::RemoveBridge(TileIndex tile)
    44 /* static */ bool AIBridge::RemoveBridge(TileIndex tile)
    50 {
    45 {
    51 	if (!IsBridgeTile(tile)) {
    46 	EnforcePrecondition(false, IsBridgeTile(tile));
    52 		AIObject::SetLastError(AIError::ERR_PRECONDITION_FAILED);
       
    53 		return false;
       
    54 	}
       
    55 
       
    56 	return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
    47 	return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
    57 }
    48 }
    58 
    49 
    59 /* static */ char *AIBridge::GetName(BridgeID bridge_id)
    50 /* static */ char *AIBridge::GetName(BridgeID bridge_id)
    60 {
    51 {