Loading

Paste #pw0td0crh

  1. Index: src/station_cmd.cpp
  2. ===================================================================
  3. --- src/station_cmd.cpp (revision 27655)
  4. +++ src/station_cmd.cpp (working copy)
  5. @@ -2443,6 +2443,48 @@
  6.     return false;
  7.  }
  8.  
  9. +/**
  10. + * Ensure this tile is not a target for ships to get to a nearby dock.
  11. + * @note Also takes into account Oil Rigs, even those under construction.
  12. + * @param tile Tile to query
  13. + * @param diagdir Optional diagonal direction to look for axis compatibility.
  14. + * @return Succeeded if the tile is not a ship docking area of a nearby dock,
  15. + *         or an error message if the tile is a ship docking area of a nearby
  16. +           dock.
  17. + * @note If the axis of a provided diagdir is equal to the axis of a nearby
  18. + *       docking area, it returns Succeeded. If diagdir is not provided, only
  19. + *       the docking area location is ensured.
  20. + */
  21. +static CommandCost EnsureNoDockingTile(TileIndex tile, DiagDirection diagdir = INVALID_DIAGDIR)
  22. +{
  23. +   Axis axis = diagdir == INVALID_DIAGDIR ? INVALID_AXIS : DiagDirToAxis(diagdir);
  24. +
  25. +   for (DiagDirection rot = DIAGDIR_BEGIN; rot < DIAGDIR_END; rot++) {
  26. +       TileIndex tc = TileAddByDiagDir(tile, rot);
  27. +       if (IsTileType(tc, MP_STATION) && (IsDock(tc) || IsOilRig(tc))) {
  28. +           Station *dock = Station::GetByTile(tc);
  29. +           TileIndex docking_location = TILE_ADD(dock->dock_tile, ToTileIndexDiff(GetDockOffset(dock->dock_tile)));
  30. +           if (axis == INVALID_AXIS) {
  31. +               return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_DOCK);
  32. +           } else {
  33. +               if (tile == docking_location) {
  34. +                   Axis axis_tc = DiagDirToAxis(rot);
  35. +                   if (axis != axis_tc) {
  36. +                       return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_DOCK);
  37. +                   }
  38. +               }
  39. +           }
  40. +       }
  41. +       if (axis != AXIS_X && DiagDirToAxis(rot) == AXIS_X) {
  42. +           if (IsTileType(tc + TileDiffXY(-1, 0), MP_INDUSTRY) && GetIndustryGfx(tc + TileDiffXY(-1, 0)) == GFX_OILRIG_1) {
  43. +               return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  44. +           }
  45. +       }
  46. +   }
  47. +
  48. +   return CommandCost();
  49. +}
  50. +
  51.  static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
  52.     {-1,  0},
  53.     { 0,  0},
  54. @@ -2493,6 +2535,10 @@
  55.  
  56.     if (IsBridgeAbove(tile_cur)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
  57.  
  58. +   /* Make sure there are no adjacent or incompatible ship docking areas */
  59. +   ret = EnsureNoDockingTile(tile_cur, direction);
  60. +   if (ret.Failed()) return ret;
  61. +
  62.     /* Get the water class of the water tile before it is cleared.*/
  63.     WaterClass wc = GetWaterClass(tile_cur);

Comments