Loading

Paste #pol6ejtzl

  1. /**
  2.  * Check whether growing on a half-tile coast tile ends up blocking a water connection
  3.  *
  4.  * @param tile The target tile
  5.  * @return true if building here blocks a water connection
  6.  */
  7. static bool PeterNGrowingBlocksWaterConnection(TileIndex tile)
  8. {
  9.     if (!IsValidTile(tile)) return false;
  10.     if (!IsCoastTile(tile)) return false;
  11.  
  12.     Slope slope = GetTileSlope(tile);
  13.  
  14.     /* Is this a coast tile with one corner raised ? */
  15.     if (!IsSlopeWithOneCornerRaised(slope)) return false;
  16.  
  17.     Track track = TrackBitsToTrack(TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)));
  18.     Trackdir trackdir = TrackToTrackdir(track);
  19.  
  20.     DiagDirection dir_a = TrackdirToExitdir(trackdir);
  21.     DiagDirection dir_b = TrackdirToExitdir(ReverseTrackdir(trackdir));
  22.  
  23.     TileIndex tile_a = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir_a));
  24.     TileIndex tile_b = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir_b));
  25.  
  26.     Corner corner = GetHighestSlopeCorner(slope);
  27.     static const Direction corner_to_direction[] = { DIR_W, DIR_S, DIR_E, DIR_N };
  28.  
  29.     /* Test adjacent tiles are valid */
  30.     TileIndex tile_a = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir_a));
  31.     if (!IsValidTile(tile_a)) return false;
  32.     TileIndex tile_b = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir_b));
  33.     if (!IsValidTile(tile_b)) return false;
  34.     TileIndex tile_o = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(corner_to_direction[OppositeCorner(corner)]));
  35.     if (!IsValidTile(tile_o)) return false;
  36.  
  37.     /* Test adjacent tiles are traversible. */
  38.     if (TrackStatusToTrackBits(GetTileTrackStatus(tile_a, TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
  39.     if (TrackStatusToTrackBits(GetTileTrackStatus(tile_b, TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
  40.  
  41.     /* If they are, test opposite tile has connecting track. */
  42.     TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile_o, TRANSPORT_WATER, 0));
  43.     if (HasBit(trackbits, TrackToOppositeTrack(track))) return false;
  44.  
  45.     /* Over building would block a route, so deny it. */
  46.     return true;
  47. }

Comments