Loading

Paste #pfvyzywvd

  1.     if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
  2. //      int z_upper_corner_n = TileHeight(tile);
  3. //      int z_upper_corner_s = TileHeight(TileAddByDiagDir(tile, AxisToDiagDir(axis == AXIS_X ? AXIS_Y : AXIS_X)));
  4.         int z_slope1;
  5.         Slope slope1 = GetTileSlope(tile, &z_slope1);
  6.         int z_middle_corner_n = TileHeight(tile2);
  7.         int z_middle_corner_s = TileHeight(TileAddByDiagDir(tile2, AxisToDiagDir(axis == AXIS_X ? AXIS_Y : AXIS_X)));
  8.         int z_slope2;
  9.         Slope slope2 = GetTileSlope(tile2, &z_slope2);
  10. //      int z_lower_corner_n = TileHeight(tile2 + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)));
  11. //      int z_lower_corner_s = TileHeight(TileAddByDiagDir(tile2 + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)), AxisToDiagDir(axis == AXIS_X ? AXIS_Y : AXIS_X)));
  12.  
  13.         /* Forbid these combinations. */
  14.         if (IsSteepSlope(slope1) || IsSteepSlope(slope2)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  15.         if (slope1 == SLOPE_NS && slope2 == SLOPE_EW || slope1 == SLOPE_EW && slope2 == SLOPE_NS) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  16.         if (z_middle_corner_n != z_middle_corner_s && (IsSlopeWithThreeCornersRaised(slope1) && IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithOneCornerRaised(slope1) && IsSlopeWithThreeCornersRaised(slope2))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  17.         if ((slope1 == slope2 || slope1 == ComplementSlope(slope2)) && IsInclinedSlope(slope1)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  18.         if (((IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2) || slope2 == SLOPE_EW || slope2 == SLOPE_NS) && IsInclinedSlope(slope1) && DiagDirToAxis(GetInclinedSlopeDirection(slope1)) == axis) || ((IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1) || slope1 == SLOPE_EW || slope1 == SLOPE_NS) && IsInclinedSlope(slope2) && DiagDirToAxis(GetInclinedSlopeDirection(slope2)) == axis)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  19.  
  20. //      int corners_tile1 = IsSlopeWithOneCornerRaised(slope1) ? 1 : IsSlopeWithThreeCornersRaised(slope1) ? 3 : 2;
  21. //      int tee = TileHeight(tile);
  22. //      int z_tile1_min = GetTileZ(tile);
  23. //      int z_tile1_max = GetTileMaxZ(tile);
  24. //      int z_tile2_min = GetTileZ(tile2);
  25. //      int z_tile2_max = GetTileMaxZ(tile2);
  26. //      bool z = Delta(z_tile_lower, z_tile) == 0;
  27.         if (slope1 == SLOPE_FLAT || slope2 == SLOPE_FLAT) {
  28.             /* Mark the tile as already cleared for the terraform command.
  29.              * Do this for all tiles (like trees), not only objects. */
  30.             ClearedObjectArea *coa = FindClearedObject(slope1 == SLOPE_FLAT ? tile2 : tile);
  31.             if (coa == NULL) {
  32.                 coa = _cleared_object_areas.Append();
  33.                 coa->first_tile = slope1 == SLOPE_FLAT ? tile2 : tile;
  34.                 coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  35.             }
  36.             /* Hide the tile from the terraforming command */
  37.             TileIndex tile_flat_before = coa->first_tile;
  38.             coa->first_tile = INVALID_TILE;
  39.             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);
  40.             coa->first_tile = tile_flat_before;
  41.             if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  42.             cost.AddCost(ret);
  43.         } else {
  44.             if ((IsSlopeWithThreeCornersRaised(slope1) || IsSlopeWithOneCornerRaised(slope1)) && (IsSlopeWithThreeCornersRaised(slope2) || IsSlopeWithOneCornerRaised(slope2))) {
  45. //              int z_middle_corner1 = TileHeight(tile2);
  46. //              int z_middle_corner2 = TileHeight(TileAddByDiagDir(tile2, AxisToDiagDir(axis == AXIS_X ? AXIS_Y : AXIS_X)));
  47.                
  48.                 /* Mark the tile as already cleared for the terraform command.
  49.                  * Do this for all tiles (like trees), not only objects. */
  50.                 ClearedObjectArea *coa = FindClearedObject(tile);
  51.                 if (coa == NULL) {
  52.                     coa = _cleared_object_areas.Append();
  53.                     coa->first_tile = tile;
  54.                     coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  55.                 }
  56.                 /* Hide the tile from the terraforming command */
  57.                 TileIndex tile_3corner1_before = coa->first_tile;
  58.                 coa->first_tile = INVALID_TILE;
  59.                 ret = DoCommand(tile, IsSlopeWithThreeCornersRaised(slope1) ? ComplementSlope(slope1) : slope1, IsSlopeWithThreeCornersRaised(slope1) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  60.                 coa->first_tile = tile_3corner1_before;
  61.                 if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  62.                 cost.AddCost(ret);
  63.  
  64.                 if (z_middle_corner_n == z_middle_corner_s) {
  65.                     /* Mark the tile as already cleared for the terraform command.
  66.                      * Do this for all tiles (like trees), not only objects. */
  67.                     ClearedObjectArea *coa = FindClearedObject(tile2);
  68.                     if (coa == NULL) {
  69.                         coa = _cleared_object_areas.Append();
  70.                         coa->first_tile = tile2;
  71.                         coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  72.                     }
  73.                     /* Hide the tile from the terraforming command */
  74.                     TileIndex tile_3corner2_before = coa->first_tile;
  75.                     coa->first_tile = INVALID_TILE;
  76.                     ret = DoCommand(tile2, IsSlopeWithThreeCornersRaised(slope2) ? ComplementSlope(slope2) : slope2, IsSlopeWithThreeCornersRaised(slope2) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  77.                     coa->first_tile = tile_3corner2_before;
  78.                     if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  79.                     cost.AddCost(ret);
  80.                 }
  81.             } else {
  82.                 if (IsInclinedSlope(slope1) && (IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2)) || IsInclinedSlope(slope2) && (IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1))) {
  83.                     if ((IsInclinedSlope(slope1) && DiagDirToAxis(GetInclinedSlopeDirection(slope1)) == OtherAxis(axis)) || (IsInclinedSlope(slope2) && DiagDirToAxis(GetInclinedSlopeDirection(slope2)) == OtherAxis(axis))) {
  84.                         if (IsInclinedSlope(slope1)) {
  85.                             /* Mark the tile as already cleared for the terraform command.
  86.                              * Do this for all tiles (like trees), not only objects. */
  87.                             ClearedObjectArea *coa = FindClearedObject(tile);
  88.                             if (coa == NULL) {
  89.                                 coa = _cleared_object_areas.Append();
  90.                                 coa->first_tile = tile;
  91.                                 coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  92.                             }
  93.                             /* Hide the tile from the terraforming command */
  94.                             TileIndex tile_inclined1_before = coa->first_tile;
  95.                             coa->first_tile = INVALID_TILE;
  96.                             ret = DoCommand(tile, IsSlopeWithThreeCornersRaised(slope2) ? ComplementSlope(slope1) : slope1, IsSlopeWithThreeCornersRaised(slope2) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  97.                             coa->first_tile = tile_inclined1_before;
  98.                             if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  99.                             cost.AddCost(ret);
  100.                         } else {
  101.                             /* Mark the tile as already cleared for the terraform command.
  102.                              * Do this for all tiles (like trees), not only objects. */
  103.                             ClearedObjectArea *coa = FindClearedObject(tile2);
  104.                             if (coa == NULL) {
  105.                                 coa = _cleared_object_areas.Append();
  106.                                 coa->first_tile = tile2;
  107.                                 coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  108.                             }
  109.                             /* Hide the tile from the terraforming command */
  110.                             TileIndex tile_inclined2_before = coa->first_tile;
  111.                             coa->first_tile = INVALID_TILE;
  112.                             ret = DoCommand(tile2, IsSlopeWithThreeCornersRaised(slope1) ? ComplementSlope(slope2) : slope2, IsSlopeWithThreeCornersRaised(slope1) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
  113.                             coa->first_tile = tile_inclined2_before;
  114.                             if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  115.                             cost.AddCost(ret);
  116.                         }
  117.                     }
  118.                 } else {
  119.                     if ((slope1 == SLOPE_EW || slope1 == SLOPE_NS) && (IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2)) || (slope2 == SLOPE_NS || slope2 == SLOPE_EW) && (IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1))) {
  120.                         /* Mark the tile as already cleared for the terraform command.
  121.                          * Do this for all tiles (like trees), not only objects. */
  122.                         ClearedObjectArea *coa = FindClearedObject((slope1 == SLOPE_EW || slope1 == SLOPE_NS) ? tile : tile2);
  123.                         if (coa == NULL) {
  124.                             coa = _cleared_object_areas.Append();
  125.                             coa->first_tile = (slope1 == SLOPE_EW || slope1 == SLOPE_NS) ? tile : tile2;
  126.                             coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
  127.                         }
  128.                         /* Hide the tile from the terraforming command */
  129.                         TileIndex tile_oppositecorners_before = coa->first_tile;
  130.                         coa->first_tile = INVALID_TILE;
  131.                         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);
  132.                         coa->first_tile = tile_oppositecorners_before;
  133.                         if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
  134.                         cost.AddCost(ret);
  135.                     } else {
  136.                         /* Shouldn't reach here. */
  137.                         assert(false);
  138.                     }
  139.                 }
  140.             }
  141.         }
  142.     }

Comments