Loading

Paste #pae1wjqpy

  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 NewGrowingBlocksWaterConnection(TileIndex tile)
  8. {
  9.     if (!IsValidTile(tile) || !IsCoastTile(tile)) return false;
  10.  
  11.     Slope slope = GetTileSlope(tile);
  12.  
  13.     /* Is this a coast tile with one corner raised ? */
  14.     if (!IsSlopeWithOneCornerRaised(slope)) return false;
  15.  
  16.     Corner corner = GetHighestSlopeCorner(slope);
  17.  
  18.     /* Test opposite tile is valid */
  19.     static const Direction corner_to_direction[] = { DIR_W, DIR_S, DIR_E, DIR_N };
  20.     TileIndex opposite_tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(corner_to_direction[OppositeCorner(corner)]));
  21.     if (!IsValidTile(opposite_tile)) return false;
  22.  
  23.     /* Test adjacent tiles are traversible. */
  24.     Track track = TrackBitsToTrack(GetTileShipTrackStatus(tile));
  25.     Trackdir main_trackdir = TrackToTrackdir(track);
  26.  
  27.     DiagDirection main_dir_1 = TrackdirToExitdir(main_trackdir);
  28.     DiagDirection main_dir_2 = TrackdirToExitdir(ReverseTrackdir(main_trackdir));
  29.  
  30.     TrackBits trackbits_1 = GetTileShipTrackStatus(AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(main_dir_1)));
  31.     TrackBits trackbits_2 = GetTileShipTrackStatus(AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(main_dir_2)));
  32.  
  33.     TrackBits main_track_1 = trackbits_1 & DiagdirReachesTracks(main_dir_1);
  34.     TrackBits main_track_2 = trackbits_2 & DiagdirReachesTracks(main_dir_2);
  35.  
  36.     /* Is main tile connected to adjacent tiles? */
  37.     if (!main_track_1 || !main_track_2) return false;
  38.  
  39.     Track opposite_track = TrackToOppositeTrack(track);
  40.     Trackdir oppo_trackdir = TrackToTrackdir(opposite_track);
  41.  
  42.     TrackBits oppo_track_1 = trackbits_1 & DiagdirReachesTracks(TrackdirToExitdir(oppo_trackdir));
  43.     TrackBits oppo_track_2 = trackbits_2 & DiagdirReachesTracks(TrackdirToExitdir(ReverseTrackdir(oppo_trackdir)));
  44.  
  45.     TrackBits mirror = TRACK_BIT_CROSS | (corner & 1 ? TRACK_BIT_HORZ : TRACK_BIT_VERT);
  46.  
  47.     /* Is opposite tile connected to adjacent tiles? */
  48.     if (HasTrack(GetTileShipTrackStatus(opposite_tile), opposite_track) &&
  49.             oppo_track_1 & (main_track_1 ^ mirror) && oppo_track_2 & (main_track_2 ^ mirror)) return false;
  50.  
  51.     /* There is either no track or an incomplete connection via opposite tile. */
  52.     return true;
  53. }

Version history

Revision # Author Created at
pbfwpiqdi Anonymous 25 Feb 2019, 19:08:46 UTC Diff

Comments