Loading

Paste #p3brhxe74

  1. static bool IsPossibleLockLocation(TileIndex tile)
  2. {
  3.     DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
  4.     if (!IsValidDiagDirection(dir)) return false;
  5.  
  6.     TileIndexDiff delta_mid = TileOffsByDiagDir(dir);
  7.     if (!IsTileFlat(tile + delta_mid)) return false;
  8.     if (!IsTileFlat(tile - delta_mid)) return false;
  9.  
  10.     return true;
  11. }
  12.  
  13. /**
  14.  * Tests whether a tile is suitable for a lock for the provided diagonal direction (axis).
  15.  * @param tile The middle tile of a lock
  16.  * @param dir Any diagonal direction belonging to the same axis
  17.  * @param check_tile_flat If set to true, check whether the tile is flat
  18.  * @return true if a lock can be placed in the given direction
  19.  */
  20. bool IsPossibleLockLocationOnDiagDir(TileIndex tile, DiagDirection dir, bool check_tile_flat) {
  21.     if (check_tile_flat && IsTileFlat(tile)) return false;
  22.     DiagDirection tdir = GetInclinedSlopeDirection(GetTileSlope(tile));
  23.     return (tdir == dir || tdir == ReverseDiagDir(dir)) && IsPossibleLockLocation(tile);
  24. }
  25.  
  26. /**
  27.  * Determine if a player could possibly build a ship lock that would cover this tile.
  28.  *
  29.  * @param bridge_tile The tile to possibly outrule a bridge position
  30.  * @param bridge_dir The bridge direction
  31.  * @return true if a player could possibly build a ship lock on this tile.
  32.  * @see GrowTownWithBridge
  33.  */
  34. static bool IsPossibleLockLocationOnTownBridgeTile(const TileIndex bridge_tile, const DiagDirection bridge_dir)
  35. {
  36.     const DiagDirection dir_side = ChangeDiagDir(bridge_dir, DIAGDIRDIFF_90LEFT);
  37.     const TileIndexDiff delta_side = TileOffsByDiagDir(dir_side);
  38.  
  39.     if (IsValidTile(bridge_tile) && IsPossibleLockLocationOnDiagDir(bridge_tile, bridge_dir, true) && IsWaterTile(bridge_tile) ||
  40.             IsValidTile(bridge_tile + delta_side) && IsPossibleLockLocationOnDiagDir(bridge_tile + delta_side, dir_side, true) && IsWaterTile(bridge_tile + delta_side) ||
  41.             IsValidTile(bridge_tile - delta_side) && IsPossibleLockLocationOnDiagDir(bridge_tile - delta_side, ReverseDiagDir(dir_side), true) && IsWaterTile(bridge_tile - delta_side)) {
  42.         return true;
  43.     }
  44.  
  45.     return false;
  46. }

Comments