Loading

Paste #pmf3ej2io

  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) || !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.     Track track = TrackBitsToTrack(TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)));
  17.     Trackdir trackdir = TrackToTrackdir(track);
  18.  
  19.     /* Test opposite tile is valid */
  20.     static const Direction corner_to_direction[] = { DIR_W, DIR_S, DIR_E, DIR_N };
  21.     TileIndex tile_o = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(corner_to_direction[OppositeCorner(GetHighestSlopeCorner(slope))]));
  22.     if (!IsValidTile(tile_o)) return false;
  23.  
  24.     /* Test adjacent tiles are traversible. */
  25.     if (TrackStatusToTrackBits(GetTileTrackStatus(AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(TrackdirToExitdir(trackdir))), TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
  26.     if (TrackStatusToTrackBits(GetTileTrackStatus(AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(TrackdirToExitdir(ReverseTrackdir(trackdir)))), TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
  27.  
  28.     /* If they are, test opposite tile has connecting track. */
  29.     if (HasBit(TrackStatusToTrackBits(GetTileTrackStatus(tile_o, TRANSPORT_WATER, 0)), TrackToOppositeTrack(track))) return false;
  30.  
  31.     /* Over building would block a route, so deny it. */
  32.     return true;
  33. }

Version history

Revision # Author Created at
pktd4qic5 Anonymous 25 Feb 2019, 02:39:53 UTC Diff
pol6ejtzl Anonymous 25 Feb 2019, 02:38:03 UTC Diff

Comments