/**
* Ensure there is no ship coming from or going to the given diagonal direction.
* @param tile Position to examine.
* @param diag_dir Diagonal direction
* @return Succeeded command (water is free) or failed command (a ship is found).
*/
CommandCost EnsureNoShipFromDiagDir(TileIndex tile, DiagDirection diag_dir)
{
TrackBits tb = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));
if ((tb & TRACK_BIT_ALL) != TRACK_BIT_NONE && !IsShipDepotTile(tile) && !(IsTileType(tile, MP_WATER) && IsLock(tile)) &&
!(IsTileType(tile, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(tile) == TRANSPORT_WATER)) {
if ((diag_dir == DIAGDIR_NE && (tb & TRACK_BIT_3WAY_NE) != 0) ||
(diag_dir == DIAGDIR_SE && (tb & TRACK_BIT_3WAY_SE) != 0) ||
(diag_dir == DIAGDIR_NW && (tb & TRACK_BIT_3WAY_NW) != 0) ||
(diag_dir == DIAGDIR_SW && (tb & TRACK_BIT_3WAY_SW) != 0)) {
CommandCost ret = EnsureNoShipOnWater(tile);
if (ret.Failed()) return ret;
}
}
return CommandCost();
}