TileIndex tile = whatever tile the ship is;
DiagDirection direction = whatever direction the ship is headed;
TrackBits bits = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)) & DiagdirReachesTracks(direction);
Track track = RemoveFirstTrack(&bits);
TrackdirBits trackdirbits = TrackStatusToTrackdirBits(TrackToTrackBits(track) & DiagdirReachesTracks(direction));
Trackdir trackdir = RemoveFirstTrackdir(&trackdirbits);