Loading

Paste #p807efevu

  1. struct { TrackBits next_track_1, next_track_2; } table[] = {
  2.     /*         t1x,t1y,t2x,t2y,              next_track_1          ,        next_track_2             opposite_tile */
  3.     /* CORNER_W  0,  1, -1,  0,  */ { TRACK_BIT_X | TRACK_BIT_RIGHT, TRACK_BIT_Y | TRACK_BIT_RIGHT }, /* -1,  1 */
  4.     /* CORNER_S  1,  0,  0,  1,  */ { TRACK_BIT_Y | TRACK_BIT_UPPER, TRACK_BIT_X | TRACK_BIT_UPPER }, /*  1,  1 */
  5.     /* CORNER_E  0, -1,  1,  0,  */ { TRACK_BIT_X | TRACK_BIT_LEFT , TRACK_BIT_Y | TRACK_BIT_LEFT  }, /*  1, -1 */
  6.     /* CORNER_N -1,  0,  0, -1,  */ { TRACK_BIT_Y | TRACK_BIT_LOWER, TRACK_BIT_X | TRACK_BIT_LOWER }, /* -1, -1 */
  7. };
  8.  
  9. static bool GrowingOnWateredTile(TileIndex tile)
  10. {
  11.     Slope slope = GetTileSlope(tile);
  12.     if (IsSlopeWithOneCornerRaised(slope) && IsCoastTile(tile)) {
  13.         Corner corner = GetHighestSlopeCorner(slope);
  14.         Corner opposite_corner = OppositeCorner(corner);
  15.  
  16.         extern const TileIndexDiffC _tileoffs_by_dir[DIR_END];
  17.         TileIndexDiffC diffc = _tileoffs_by_dir[GetCornerDirection(opposite_corner)];
  18.  
  19.         TileIndex opposite_tile = TileAddWrap(tile, diffc.x, diffc.y);
  20.         if (IsValidTile(opposite_tile)) {
  21.             TrackBits opposite_track = CornerToTrackBits(corner);
  22.             TileIndex tile_1 = TileAddWrap(tile, opposite_corner & 1 ? diffc.x : 0, opposite_corner & 1 ? 0 : diffc.y);
  23.             TileIndex tile_2 = TileAddWrap(tile, opposite_corner & 1 ? 0 : diffc.x, opposite_corner & 1 ? diffc.x : 0);
  24.             TrackBits next_track_1 = table[corner].next_track_1 & TrackStatusToTrackBits(GetTileTrackStatus(tile_1, TRANSPORT_WATER, 0));
  25.             TrackBits next_track_2 = table[corner].next_track_2 & TrackStatusToTrackBits(GetTileTrackStatus(tile_2, TRANSPORT_WATER, 0));
  26.             TrackBits main_track_1 = table[opposite_corner].next_track_2 & TrackStatusToTrackBits(GetTileTrackStatus(tile_1, TRANSPORT_WATER, 0));
  27.             TrackBits main_track_2 = table[opposite_corner].next_track_1 & TrackStatusToTrackBits(GetTileTrackStatus(tile_2, TRANSPORT_WATER, 0));
  28.             TrackBits mirror = TRACK_BIT_CROSS | (corner & 1 ? TRACK_BIT_HORZ : TRACK_BIT_VERT);
  29.             if (main_track_1 && main_track_2) { // Is there a connection between 'tile_1' and 'tile_2' via 'tile'?
  30.                 if (opposite_track & TrackStatusToTrackBits(GetTileTrackStatus(opposite_tile, TRANSPORT_WATER, 0))) { // Is there an 'opposite_track' that can be used to try an alternative connection?
  31.                     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'?
  32.                         return false; // There is an alternative connection. Town than grow on 'tile'.
  33.                     }
  34.                 }
  35.                 return true; // There is either no 'opposite_track', or an incomplete connection via 'opposite_tile'.
  36.             }
  37.         }
  38.     }
  39.     return false; // There was no connection via 'tile', or it was incomplete, or the 'opposite_tile' is outside the map.
  40. }

Comments