Loading

Paste #pktd4qic5

  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.     Corner corner = GetHighestSlopeCorner(slope);
  21.     static const Direction corner_to_direction[] = { DIR_W, DIR_S, DIR_E, DIR_N };
  22.  
  23.     /* Test adjacent tiles are valid */
  24.     TileIndex tile_a = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(TrackdirToExitdir(trackdir)));
  25.     if (!IsValidTile(tile_a)) return false;
  26.     TileIndex tile_b = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(TrackdirToExitdir(ReverseTrackdir(trackdir))));
  27.     if (!IsValidTile(tile_b)) return false;
  28.     TileIndex tile_o = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(corner_to_direction[OppositeCorner(corner)]));
  29.     if (!IsValidTile(tile_o)) return false;
  30.  
  31.     /* Test adjacent tiles are traversible. */
  32.     if (TrackStatusToTrackBits(GetTileTrackStatus(tile_a, TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
  33.     if (TrackStatusToTrackBits(GetTileTrackStatus(tile_b, TRANSPORT_WATER, 0)) == TRACK_BIT_NONE) return false;
  34.  
  35.     /* If they are, test opposite tile has connecting track. */
  36.     TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile_o, TRANSPORT_WATER, 0));
  37.     if (HasBit(trackbits, TrackToOppositeTrack(track))) return false;
  38.  
  39.     /* Over building would block a route, so deny it. */
  40.     return true;
  41. }

Version history

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

Comments