/**
* Check whether growing on a half-tile coast tile ends up blocking a water connection
*
* @param tile The target tile
* @return true if building here blocks a water connection
*/
static bool PeterNGrowingBlocksWaterConnection(TileIndex tile)
{
if (!IsValidTile(tile) || !IsCoastTile(tile)) return false;
Slope slope = GetTileSlope(tile);
/* Is this a coast tile with one corner raised ? */
if (!IsSlopeWithOneCornerRaised(slope)) return false;
Track track = TrackBitsToTrack(TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)));
Trackdir trackdir = TrackToTrackdir(track);
/* Test opposite tile is valid */
static const Direction corner_to_direction[] = { DIR_W, DIR_S, DIR_E, DIR_N };
TileIndex tile_o = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(corner_to_direction[OppositeCorner(GetHighestSlopeCorner(slope))]));
if (!IsValidTile(tile_o)) return false;
/* Test adjacent tiles are traversible. */
if (TrackStatusToTrackBits(GetTileTrackStatus(AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(TrackdirToExitdir(trackdir))), TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
if (TrackStatusToTrackBits(GetTileTrackStatus(AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(TrackdirToExitdir(ReverseTrackdir(trackdir)))), TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
/* If they are, test opposite tile has connecting track. */
if (HasBit(TrackStatusToTrackBits(GetTileTrackStatus(tile_o, TRANSPORT_WATER, 0)), TrackToOppositeTrack(track))) return false;
/* Over building would block a route, so deny it. */
return true;
}