Loading

Paste #pagop3ur5

  1. /**
  2.  * Ensure there is no ship coming from or going to the given diagonal direction.
  3.  * @param tile Position to examine.
  4.  * @param diag_dir Diagonal direction
  5.  * @return Succeeded command (water is free) or failed command (a ship is found).
  6.  */
  7. CommandCost EnsureNoShipFromDiagDir(TileIndex tile, DiagDirection diag_dir)
  8. {
  9.     TrackBits tb = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));
  10.     if ((tb & TRACK_BIT_ALL) != TRACK_BIT_NONE && !IsShipDepotTile(tile) && !(IsTileType(tile, MP_WATER) && IsLock(tile)) &&
  11.             !(IsTileType(tile, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(tile) == TRANSPORT_WATER)) {
  12.         if ((diag_dir == DIAGDIR_NE && (tb & TRACK_BIT_3WAY_NE) != 0) ||
  13.                 (diag_dir == DIAGDIR_SE && (tb & TRACK_BIT_3WAY_SE) != 0) ||
  14.                 (diag_dir == DIAGDIR_NW && (tb & TRACK_BIT_3WAY_NW) != 0) ||
  15.                 (diag_dir == DIAGDIR_SW && (tb & TRACK_BIT_3WAY_SW) != 0)) {
  16.             CommandCost ret = EnsureNoShipOnWater(tile);
  17.             if (ret.Failed()) return ret;
  18.         }
  19.     }
  20.     return CommandCost();
  21. }

Comments