Loading

Paste #ptbisgux9

  1. /**
  2.  * Build a ship depot.
  3.  * @param tile tile where ship depot is built
  4.  * @param flags type of operation
  5.  * @param p1 bit 0 depot orientation (Axis)
  6.  * @param p2 unused
  7.  * @param text unused
  8.  * @return the cost of this operation or an error
  9.  */
  10. CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
  11. {
  12.     Axis axis = Extract<Axis, 0, 1>(p1);
  13.  
  14.     TileIndexDiff diff = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
  15.     TileIndex tile2 = tile + diff;
  16.  
  17.     if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
  18.  
  19.     if (!Depot::CanAllocateItem()) return CMD_ERROR;
  20.  
  21.     CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]);
  22.     CommandCost ret;
  23.  
  24.     WaterClass wc1 = IsWaterTile(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL;
  25.     Owner oc1 = HasTileWaterGround(tile) && GetWaterClass(tile) == WATER_CLASS_CANAL ? GetCanalOwner(tile) : _current_company;
  26.     bool add_cost1 = !IsWaterTile(tile);
  27.  
  28.     /* At this point we got a tile with no bridge over it. Check for ownership */
  29.     if (IsWaterTile(tile) && IsCanal(tile)) {
  30.         ret = EnsureNoVehicleOnGround(tile);
  31.         if (ret.Failed()) return ret;
  32.         if (oc1 != OWNER_NONE) {
  33.             ret = CheckTileOwnership(tile);
  34.             if (ret.Failed() && !_settings_game.construction.build_on_competitor_canal) return ret;
  35.         }
  36.     } else {
  37.         ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
  38.         if (ret.Failed()) return ret;
  39.         if (add_cost1) {
  40.             cost.AddCost(ret);
  41.             if (wc1 == WATER_CLASS_CANAL) cost.AddCost(_price[PR_BUILD_CANAL]);
  42.         }
  43.     }
  44.  
  45.     WaterClass wc2 = IsWaterTile(tile2) ? GetWaterClass(tile2) : WATER_CLASS_CANAL;
  46.     Owner oc2 = HasTileWaterGround(tile2) && GetWaterClass(tile2) == WATER_CLASS_CANAL ? GetCanalOwner(tile2) : _current_company;
  47.     bool add_cost2 = !IsWaterTile(tile2);
  48.  
  49.     /* At this point we got a tile2 with no bridge over it. Check for ownership */
  50.     if (IsWaterTile(tile2) && IsCanal(tile2)) {
  51.         ret = EnsureNoVehicleOnGround(tile2);
  52.         if (ret.Failed()) return ret;
  53.         if (oc2 != OWNER_NONE) {
  54.             ret = CheckTileOwnership(tile2);
  55.             if (ret.Failed() && !_settings_game.construction.build_on_competitor_canal) return ret;
  56.         }
  57.     } else {
  58.         ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
  59.         if (ret.Failed()) return ret;
  60.         if (add_cost2) {
  61.             cost.AddCost(ret);
  62.             if (wc2 == WATER_CLASS_CANAL) cost.AddCost(_price[PR_BUILD_CANAL]);
  63.         }
  64.     }
  65.  
  66.     if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
  67.         Slope slope1 = GetTileSlope(tile);
  68.         Slope slope2 = GetTileSlope(tile2);
  69.  
  70.         if (IsSteepSlope(slope1) || IsSteepSlope(slope2)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  71.  
  72.         int h_north_corner_n = TileHeight(tile);
  73.         int h_north_corner_s = TileHeight(TileAddByDiagDir(tile, AxisToDiagDir(OtherAxis(axis))));
  74.         int h_middle_corner_n = TileHeight(tile2);
  75.         int h_middle_corner_s = TileHeight(TileAddByDiagDir(tile2, AxisToDiagDir(OtherAxis(axis))));
  76.         int h_south_corner_n = TileHeight(tile2 + diff);
  77.         int h_south_corner_s = TileHeight(TileAddByDiagDir(tile2 + diff, AxisToDiagDir(OtherAxis(axis))));
  78.  
  79.         int corners[] = { h_north_corner_n, h_north_corner_s, h_middle_corner_n, h_middle_corner_s, h_south_corner_n, h_south_corner_s };
  80.  
  81.         int min_h = MAX_TILE_HEIGHT;
  82.         int max_h = 0;
  83.         for (int i = 0; i < lengthof(corners); i++) {
  84.             min_h = min(min_h, corners[i]);
  85.             max_h = max(max_h, corners[i]);
  86.         }
  87.  
  88.         int best_h = INT_MAX;
  89.         int second_best_h = INT_MAX;
  90.         int best_sum = INT_MAX;
  91.         int second_best_sum = INT_MAX;
  92.         for (int h = min_h; h <= max_h; h++) {
  93.             int sum = 0;
  94.             for (int c = 0; c < lengthof(corners); c++) {
  95.                 sum += abs(h - corners[c]);
  96.             }
  97.             if (sum <= best_sum) {
  98.                 second_best_sum = best_sum;
  99.                 best_sum = sum;
  100.                 second_best_h = best_h;
  101.                 best_h = h;
  102.             }
  103.         }
  104.         if (best_sum != second_best_sum) {
  105.             int command1p2 = -1;
  106.             Slope tileh1 = SLOPE_FLAT;
  107.             if (h_north_corner_n > best_h) {
  108.                 command1p2 = 0;
  109.                 tileh1 |= SLOPE_N;
  110.             } else if (h_north_corner_n < best_h) {
  111.                 command1p2 = 1;
  112.                 tileh1 |= SLOPE_N;
  113.             }
  114.             if (h_north_corner_s > best_h) {
  115.                 command1p2 = 0;
  116.                 tileh1 |= axis == AXIS_X ? SLOPE_E : SLOPE_W;
  117.             } else if (h_north_corner_s < best_h) {
  118.                 command1p2 = 1;
  119.                 tileh1 |= axis == AXIS_X ? SLOPE_E : SLOPE_W;
  120.             }
  121.  
  122.             int command2p2 = -1;
  123.             Slope tileh2 = SLOPE_FLAT;
  124.             if (h_south_corner_n > best_h) {
  125.                 command2p2 = 0;
  126.                 tileh2 |= axis == AXIS_X ? SLOPE_W : SLOPE_E;
  127.             } else if (h_south_corner_n < best_h) {
  128.                 command2p2 = 1;
  129.                 tileh2 |= axis == AXIS_X ? SLOPE_W : SLOPE_E;
  130.             }
  131.             if (h_south_corner_s > best_h) {
  132.                 command2p2 = 0;
  133.                 tileh2 |= SLOPE_S;
  134.             } else if (h_south_corner_s < best_h) {
  135.                 command2p2 = 1;
  136.                 tileh2 |= SLOPE_S;
  137.             }
  138.  
  139.             if (h_middle_corner_n > best_h) {
  140.                 if (tileh1 != SLOPE_FLAT) {
  141.                     command1p2 = 0;
  142.                     tileh1 |= axis == AXIS_X ? SLOPE_W : SLOPE_E;
  143.                 } else {
  144.                     command2p2 = 0;
  145.                     tileh2 |= SLOPE_N;
  146.                 }
  147.             } else if (h_middle_corner_n < best_h) {
  148.                 if (tileh1 != SLOPE_FLAT) {
  149.                     command1p2 = 1;
  150.                     tileh1 |= axis == AXIS_X ? SLOPE_W : SLOPE_E;
  151.                 } else {
  152.                     command2p2 = 1;
  153.                     tileh2 |= SLOPE_N;
  154.                 }
  155.             }
  156.  
  157.             if (h_middle_corner_s > best_h) {
  158.                 if (tileh1 != SLOPE_FLAT) {
  159.                     command1p2 = 0;
  160.                     tileh1 |= SLOPE_S;
  161.                 } else {
  162.                     command2p2 = 0;
  163.                     tileh2 |= axis == AXIS_X ? SLOPE_E : SLOPE_W;
  164.                 }
  165.             } else if (h_middle_corner_s < best_h) {
  166.                 if (tileh1 != SLOPE_FLAT) {
  167.                     command1p2 = 1;
  168.                     tileh1 |= SLOPE_S;
  169.                 } else {
  170.                     command2p2 = 1;
  171.                     tileh2 |= axis == AXIS_X ? SLOPE_E : SLOPE_W;
  172.                 }
  173.             }
  174.            
  175.             if (tileh1 != SLOPE_FLAT && command1p2 != -1) {
  176.                 /* Mark the tile as already cleared for the terraform command. */
  177.                 ClearedObjectArea *coa = MakeClearedObjectArea(tile, tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  178.                 /* Hide the tile from the terraforming command. */
  179.                 TileIndex tile1_before = coa->first_tile;
  180.                 coa->first_tile = INVALID_TILE;
  181.                 ret = DoCommand(tile, tileh1, command1p2, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  182.                 coa->first_tile = tile1_before;
  183.                 if (ret.Failed()) return ret;
  184.                 cost.AddCost(ret);
  185.  
  186.             }
  187.  
  188.             if (tileh2 != SLOPE_FLAT && command2p2 != -1) {
  189.                 /* Mark the tile as already cleared for the terraform command. */
  190.                 ClearedObjectArea *coa = MakeClearedObjectArea(tile2, tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  191.                 /* Hide the tile from the terraforming command. */
  192.                 TileIndex tile2_before = coa->first_tile;
  193.                 coa->first_tile = INVALID_TILE;
  194.                 ret = DoCommand(tile2, tileh2, command2p2, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  195.                 coa->first_tile = tile2_before;
  196.                 if (ret.Failed()) return ret;
  197.                 cost.AddCost(ret);
  198.             }
  199.         } else {
  200.             return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  201.         }
  202.     }
  203.  
  204. //  int best_h;
  205. //  int max_delta = MAX_TILE_HEIGHT;
  206. //  for (int h = min_h; h <= max_h; h++) {
  207. //      int delta = 0;
  208. //      for (int c = 0; c < lengthof(corners); c++) {
  209. //          delta = max(delta, Delta(h, corners[c]));
  210. //      }
  211. //      if (delta <= max_delta) {
  212. //          max_delta = delta;
  213. //          int c_count = 0;
  214. //          for (int c = 0; c < lengthof(corners); c++) {
  215. //              if (corners[c] == h) {
  216. //                  c_count++;
  217. //              }
  218. //          }
  219. //          best_h = h;
  220. //      }
  221. //  }
  222.  
  223. //  if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
  224. //      int z_slope1;
  225. //      Slope slope1 = GetTileSlope(tile, &z_slope1);
  226. //      int z_middle_corner_n = TileHeight(tile2);
  227. //      int z_middle_corner_s = TileHeight(TileAddByDiagDir(tile2, AxisToDiagDir(OtherAxis(axis))));
  228. //      int z_slope2;
  229. //      Slope slope2 = GetTileSlope(tile2, &z_slope2);
  230.  
  231. //      /* Forbid these combinations. */
  232.         /**
  233.          *       3
  234.          *      / \
  235.          *     2   2
  236.          *    / \ /
  237.          *   1   1
  238.          *    \ /
  239.          *     0
  240.          */
  241. //      if (IsSteepSlope(slope1) || IsSteepSlope(slope2)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  242.  
  243.         /**
  244.          *       1         0
  245.          *      / \       / \
  246.          *     0   0     1   1
  247.          *    / \ /     / \ /
  248.          *   1   1     0   0
  249.          *    \ /       \ /
  250.          *     0         1
  251.          */
  252. //      if (slope1 == SLOPE_NS && slope2 == SLOPE_EW || slope1 == SLOPE_EW && slope2 == SLOPE_NS) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  253.  
  254.         /**
  255.          *       1
  256.          *      / \
  257.          *     0   1
  258.          *    / \ /
  259.          *   0   1
  260.          *    \ /
  261.          *     0
  262.          */
  263. //      if (z_middle_corner_n != z_middle_corner_s && (IsSlopeWithThreeCornersRaised(slope1) && IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithOneCornerRaised(slope1) && IsSlopeWithThreeCornersRaised(slope2))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  264.  
  265.         /**
  266.          *       2         1
  267.          *      / \       / \
  268.          *     1   2     1   0
  269.          *    / \ /     / \ /
  270.          *   0   1     1   0
  271.          *    \ /       \ /
  272.          *     0         0
  273.          */
  274. //      if (slope1 == slope2 && IsInclinedSlope(slope1)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  275.  
  276.         /**
  277.          *       1         2         0
  278.          *      / \       / \       / \
  279.          *     0   1     1   2     1   0
  280.          *    / \ /     / \ /     / \ /
  281.          *   0   0     1   1     1   1
  282.          *    \ /       \ /       \ /
  283.          *     1         0         2
  284.          */
  285. //      if (((IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2)) && IsInclinedSlope(slope1) && DiagDirToAxis(GetInclinedSlopeDirection(slope1)) == axis) || ((IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1)) && IsInclinedSlope(slope2) && DiagDirToAxis(GetInclinedSlopeDirection(slope2)) == axis)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  286.  
  287.         /**
  288.          *       0
  289.          *      / \
  290.          *     0   1
  291.          *    / \ /
  292.          *   1   1
  293.          *    \ /
  294.          *     0
  295.          */
  296. //      if (((slope2 == SLOPE_EW || slope2 == SLOPE_NS) && IsInclinedSlope(slope1) && DiagDirToAxis(GetInclinedSlopeDirection(slope1)) == OtherAxis(axis)) || ((slope1 == SLOPE_EW || slope1 == SLOPE_NS) && IsInclinedSlope(slope2) && DiagDirToAxis(GetInclinedSlopeDirection(slope2)) == OtherAxis(axis))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  297.  
  298. //      /* Terraform these combinations. */
  299. //      if (slope1 == SLOPE_FLAT || slope2 == SLOPE_FLAT) {
  300. //          /* Mark the tile as already cleared for the terraform command. */
  301. //          ClearedObjectArea *coa = MakeClearedObjectArea(slope1 == SLOPE_FLAT ? tile2 : tile, tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  302. //          /* Hide the tile from the terraforming command. */
  303. //          TileIndex tile_flat_before = coa->first_tile;
  304. //          coa->first_tile = INVALID_TILE;
  305. //          ret = DoCommand(slope1 == SLOPE_FLAT ? tile2 : tile, slope1 == SLOPE_FLAT ? z_slope1 == z_slope2 ? slope2: ComplementSlope(slope2) : z_slope1 == z_slope2 ? slope1 : ComplementSlope(slope1), z_slope1 == z_slope2 ? 0 : 1, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  306. //          coa->first_tile = tile_flat_before;
  307. //          if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  308. //          cost.AddCost(ret);
  309. //      } else {
  310. //          if ((IsSlopeWithThreeCornersRaised(slope1) || IsSlopeWithOneCornerRaised(slope1)) && (IsSlopeWithThreeCornersRaised(slope2) || IsSlopeWithOneCornerRaised(slope2))) {
  311. //              /* Mark the tile as already cleared for the terraform command. */
  312. //              ClearedObjectArea *coa = MakeClearedObjectArea(tile, tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  313. //              /* Hide the tile from the terraforming command. */
  314. //              TileIndex tile_3corner1_before = coa->first_tile;
  315. //              coa->first_tile = INVALID_TILE;
  316. //              ret = DoCommand(tile, IsSlopeWithThreeCornersRaised(slope1) ? ComplementSlope(slope1) : slope1, IsSlopeWithThreeCornersRaised(slope1) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  317. //              coa->first_tile = tile_3corner1_before;
  318. //              if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  319. //              cost.AddCost(ret);
  320. //              if (z_middle_corner_n == z_middle_corner_s) {
  321. //                  /* Mark the tile as already cleared for the terraform command. */
  322. //                  ClearedObjectArea *coa = MakeClearedObjectArea(tile2, tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  323. //                  /* Hide the tile from the terraforming command. */
  324. //                  TileIndex tile_3corner2_before = coa->first_tile;
  325. //                  coa->first_tile = INVALID_TILE;
  326. //                  ret = DoCommand(tile2, IsSlopeWithThreeCornersRaised(slope2) ? ComplementSlope(slope2) : slope2, IsSlopeWithThreeCornersRaised(slope2) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  327. //                  coa->first_tile = tile_3corner2_before;
  328. //                  if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  329. //                  cost.AddCost(ret);
  330. //              }
  331. //          } else {
  332. //              if ((IsInclinedSlope(slope1) && DiagDirToAxis(GetInclinedSlopeDirection(slope1)) == OtherAxis(axis) && (IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2))) || (IsInclinedSlope(slope2) && DiagDirToAxis(GetInclinedSlopeDirection(slope2)) == OtherAxis(axis) && (IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1)))) {
  333. //                  /* Mark the tile as already cleared for the terraform command. */
  334. //                  ClearedObjectArea *coa = MakeClearedObjectArea(IsInclinedSlope(slope1) ? tile : tile2, tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  335. //                  /* Hide the tile from the terraforming command. */
  336. //                  TileIndex tile_inclined1_before = coa->first_tile;
  337. //                  coa->first_tile = INVALID_TILE;
  338. //                  ret = DoCommand(IsInclinedSlope(slope1) ? tile : tile2, IsInclinedSlope(slope1) ? IsSlopeWithThreeCornersRaised(slope2) ? ComplementSlope(slope1) : slope1 : IsSlopeWithThreeCornersRaised(slope1) ? ComplementSlope(slope2) : slope2, IsInclinedSlope(slope1) ? IsSlopeWithThreeCornersRaised(slope2) ? 1 : 0 : IsSlopeWithThreeCornersRaised(slope1) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  339. //                  coa->first_tile = tile_inclined1_before;
  340. //                  if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  341. //                  cost.AddCost(ret);
  342. //              } else {
  343. //                  if ((slope1 == SLOPE_EW || slope1 == SLOPE_NS) && (IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2)) || (slope2 == SLOPE_NS || slope2 == SLOPE_EW) && (IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1))) {
  344. //                      /* Mark the tile as already cleared for the terraform command. */
  345. //                      ClearedObjectArea *coa = MakeClearedObjectArea((slope1 == SLOPE_EW || slope1 == SLOPE_NS) ? tile : tile2, tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  346. //                      /* Hide the tile from the terraforming command. */
  347. //                      TileIndex tile_oppositecorners_before = coa->first_tile;
  348. //                      coa->first_tile = INVALID_TILE;
  349. //                      ret = DoCommand((slope1 == SLOPE_EW || slope1 == SLOPE_NS) ? tile : tile2, (slope1 == SLOPE_EW || slope1 == SLOPE_NS) ? IsSlopeWithOneCornerRaised(slope2) ? slope1 : ComplementSlope(slope1) : IsSlopeWithOneCornerRaised(slope1) ? slope2 : ComplementSlope(slope2), (slope1 == SLOPE_EW || slope1 == SLOPE_NS) ? IsSlopeWithOneCornerRaised(slope2) ? 0 : 1 : IsSlopeWithOneCornerRaised(slope1) ? 0 : 1, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  350. //                      coa->first_tile = tile_oppositecorners_before;
  351. //                      if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  352. //                      cost.AddCost(ret);
  353. //                  } else {
  354. //                      if (slope1 == ComplementSlope(slope2) && IsInclinedSlope(slope1)) {
  355. //                          /* Mark the tile as already cleared for the terraform command. */
  356. //                          ClearedObjectArea *coa = MakeClearedObjectArea(tile2, tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  357. //                          /* Hide the tile from the terraforming command. */
  358. //                          TileIndex tile_complement_before = coa->first_tile;
  359. //                          coa->first_tile = INVALID_TILE;
  360. //                          ret = DoCommand(tile2, z_middle_corner_n > z_slope1 ? slope2 : slope1, z_middle_corner_n > z_slope1 ? 0 : 1, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  361. //                          coa->first_tile = tile_complement_before;
  362. //                          if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  363. //                          cost.AddCost(ret);
  364. //                      } else {
  365. //                          /* Shouldn't reach here. */
  366. //                          assert(false);
  367. //                      }
  368. //                  }
  369. //              }
  370. //          }
  371. //      }
  372. //  }
  373.  
  374. //      if (!IsTileFlat(tile) || !IsTileFlat(tile2)) return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
  375.  
  376.     DiagDirection dir_rotate = axis == AXIS_X ? DIAGDIR_SE : DIAGDIR_NE;
  377.     TileIndex tc = tile + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));
  378.     ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
  379.     if (ret.Failed()) return ret;
  380.  
  381.     tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));
  382.     ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
  383.     if (ret.Failed()) return ret;
  384.  
  385.     dir_rotate = ReverseDiagDir(dir_rotate);
  386.     tc = tile + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));
  387.     ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
  388.     if (ret.Failed()) return ret;
  389.  
  390.     tc = tile2 + (axis == AXIS_X ? TileDiffXY(0, 1) : TileDiffXY(-1, 0));
  391.     ret = EnsureNoShipFromDiagDir(tc, dir_rotate);
  392.     if (ret.Failed()) return ret;
  393.  
  394.     if (flags & DC_EXEC) {
  395.         Depot *depot = new Depot(tile);
  396.         depot->build_date = _date;
  397.  
  398.         if (add_cost1 && wc1 == WATER_CLASS_CANAL) Company::Get(_current_company)->infrastructure.water++;
  399.         if (add_cost2 && wc2 == WATER_CLASS_CANAL) Company::Get(_current_company)->infrastructure.water++;
  400.         Company::Get(_current_company)->infrastructure.water += 2 * LOCK_DEPOT_TILE_FACTOR;
  401.         DirtyCompanyInfrastructureWindows(_current_company);
  402.  
  403.         MakeShipDepot(tile, _current_company, oc1, depot->index, DEPOT_PART_NORTH, axis, wc1);
  404.         MakeShipDepot(tile2, _current_company, oc2, depot->index, DEPOT_PART_SOUTH, axis, wc2);
  405.         MarkTileDirtyByTile(tile);
  406.         MarkTileDirtyByTile(tile2);
  407.         MakeDefaultName(depot);
  408.     }
  409.  
  410.     return cost;
  411. }

Comments