struct { TrackBits next_track_1, next_track_2; } table[] = {
/* t1x,t1y,t2x,t2y, next_track_1 , next_track_2 opposite_tile */
/* CORNER_W 0, 1, -1, 0, */ { TRACK_BIT_X | TRACK_BIT_RIGHT, TRACK_BIT_Y | TRACK_BIT_RIGHT }, /* -1, 1 */
/* CORNER_S 1, 0, 0, 1, */ { TRACK_BIT_Y | TRACK_BIT_UPPER, TRACK_BIT_X | TRACK_BIT_UPPER }, /* 1, 1 */
/* CORNER_E 0, -1, 1, 0, */ { TRACK_BIT_X | TRACK_BIT_LEFT , TRACK_BIT_Y | TRACK_BIT_LEFT }, /* 1, -1 */
/* CORNER_N -1, 0, 0, -1, */ { TRACK_BIT_Y | TRACK_BIT_LOWER, TRACK_BIT_X | TRACK_BIT_LOWER }, /* -1, -1 */
};
static bool GrowingOnWateredTile(TileIndex tile)
{
Slope slope = GetTileSlope(tile);
if (IsSlopeWithOneCornerRaised(slope) && IsCoastTile(tile)) {
Corner corner = GetHighestSlopeCorner(slope);
Corner opposite_corner = OppositeCorner(corner);
extern const TileIndexDiffC _tileoffs_by_dir[DIR_END];
TileIndexDiffC diffc = _tileoffs_by_dir[GetCornerDirection(opposite_corner)];
TileIndex opposite_tile = TileAddWrap(tile, diffc.x, diffc.y);
if (IsValidTile(opposite_tile)) {
TrackBits opposite_track = CornerToTrackBits(corner);
TileIndex tile_1 = TileAddWrap(tile, opposite_corner & 1 ? diffc.x : 0, opposite_corner & 1 ? 0 : diffc.y);
TileIndex tile_2 = TileAddWrap(tile, opposite_corner & 1 ? 0 : diffc.x, opposite_corner & 1 ? diffc.x : 0);
TrackBits next_track_1 = table[corner].next_track_1 & TrackStatusToTrackBits(GetTileTrackStatus(tile_1, TRANSPORT_WATER, 0));
TrackBits next_track_2 = table[corner].next_track_2 & TrackStatusToTrackBits(GetTileTrackStatus(tile_2, TRANSPORT_WATER, 0));
TrackBits main_track_1 = table[opposite_corner].next_track_2 & TrackStatusToTrackBits(GetTileTrackStatus(tile_1, TRANSPORT_WATER, 0));
TrackBits main_track_2 = table[opposite_corner].next_track_1 & TrackStatusToTrackBits(GetTileTrackStatus(tile_2, TRANSPORT_WATER, 0));
TrackBits mirror = TRACK_BIT_CROSS | (corner & 1 ? TRACK_BIT_HORZ : TRACK_BIT_VERT);
if (main_track_1 && main_track_2) { // Is there a connection between 'tile_1' and 'tile_2' via 'tile'?
if (opposite_track & TrackStatusToTrackBits(GetTileTrackStatus(opposite_tile, TRANSPORT_WATER, 0))) { // Is there an 'opposite_track' that can be used to try an alternative connection?
if (next_track_1 & (main_track_1 ^ mirror) && next_track_2 & (main_track_2 ^ mirror)) { // Is there a connection between 'tile_1' and 'tile_2' via 'opposite_tile'?
return false; // There is an alternative connection. Town than grow on 'tile'.
}
}
return true; // There is either no 'opposite_track', or an incomplete connection via 'opposite_tile'.
}
}
}
return false; // There was no connection via 'tile', or it was incomplete, or the 'opposite_tile' is outside the map.
}