if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
// int z_upper_corner_n = TileHeight(tile);
// int z_upper_corner_s = TileHeight(TileAddByDiagDir(tile, AxisToDiagDir(axis == AXIS_X ? AXIS_Y : AXIS_X)));
int z_slope1;
Slope slope1 = GetTileSlope(tile, &z_slope1);
int z_middle_corner_n = TileHeight(tile2);
int z_middle_corner_s = TileHeight(TileAddByDiagDir(tile2, AxisToDiagDir(axis == AXIS_X ? AXIS_Y : AXIS_X)));
int z_slope2;
Slope slope2 = GetTileSlope(tile2, &z_slope2);
// int z_lower_corner_n = TileHeight(tile2 + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)));
// 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)));
/* Forbid these combinations. */
if (IsSteepSlope(slope1) || IsSteepSlope(slope2)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
if (slope1 == SLOPE_NS && slope2 == SLOPE_EW || slope1 == SLOPE_EW && slope2 == SLOPE_NS) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
if (z_middle_corner_n != z_middle_corner_s && (IsSlopeWithThreeCornersRaised(slope1) && IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithOneCornerRaised(slope1) && IsSlopeWithThreeCornersRaised(slope2))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
if ((slope1 == slope2 || slope1 == ComplementSlope(slope2)) && IsInclinedSlope(slope1)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
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);
// int corners_tile1 = IsSlopeWithOneCornerRaised(slope1) ? 1 : IsSlopeWithThreeCornersRaised(slope1) ? 3 : 2;
// int tee = TileHeight(tile);
// int z_tile1_min = GetTileZ(tile);
// int z_tile1_max = GetTileMaxZ(tile);
// int z_tile2_min = GetTileZ(tile2);
// int z_tile2_max = GetTileMaxZ(tile2);
// bool z = Delta(z_tile_lower, z_tile) == 0;
if (slope1 == SLOPE_FLAT || slope2 == SLOPE_FLAT) {
/* Mark the tile as already cleared for the terraform command.
* Do this for all tiles (like trees), not only objects. */
ClearedObjectArea *coa = FindClearedObject(slope1 == SLOPE_FLAT ? tile2 : tile);
if (coa == NULL) {
coa = _cleared_object_areas.Append();
coa->first_tile = slope1 == SLOPE_FLAT ? tile2 : tile;
coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
}
/* Hide the tile from the terraforming command */
TileIndex tile_flat_before = coa->first_tile;
coa->first_tile = INVALID_TILE;
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);
coa->first_tile = tile_flat_before;
if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
cost.AddCost(ret);
} else {
if ((IsSlopeWithThreeCornersRaised(slope1) || IsSlopeWithOneCornerRaised(slope1)) && (IsSlopeWithThreeCornersRaised(slope2) || IsSlopeWithOneCornerRaised(slope2))) {
// int z_middle_corner1 = TileHeight(tile2);
// int z_middle_corner2 = TileHeight(TileAddByDiagDir(tile2, AxisToDiagDir(axis == AXIS_X ? AXIS_Y : AXIS_X)));
/* Mark the tile as already cleared for the terraform command.
* Do this for all tiles (like trees), not only objects. */
ClearedObjectArea *coa = FindClearedObject(tile);
if (coa == NULL) {
coa = _cleared_object_areas.Append();
coa->first_tile = tile;
coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
}
/* Hide the tile from the terraforming command */
TileIndex tile_3corner1_before = coa->first_tile;
coa->first_tile = INVALID_TILE;
ret = DoCommand(tile, IsSlopeWithThreeCornersRaised(slope1) ? ComplementSlope(slope1) : slope1, IsSlopeWithThreeCornersRaised(slope1) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
coa->first_tile = tile_3corner1_before;
if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
cost.AddCost(ret);
if (z_middle_corner_n == z_middle_corner_s) {
/* Mark the tile as already cleared for the terraform command.
* Do this for all tiles (like trees), not only objects. */
ClearedObjectArea *coa = FindClearedObject(tile2);
if (coa == NULL) {
coa = _cleared_object_areas.Append();
coa->first_tile = tile2;
coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
}
/* Hide the tile from the terraforming command */
TileIndex tile_3corner2_before = coa->first_tile;
coa->first_tile = INVALID_TILE;
ret = DoCommand(tile2, IsSlopeWithThreeCornersRaised(slope2) ? ComplementSlope(slope2) : slope2, IsSlopeWithThreeCornersRaised(slope2) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
coa->first_tile = tile_3corner2_before;
if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
cost.AddCost(ret);
}
} else {
if (IsInclinedSlope(slope1) && (IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2)) || IsInclinedSlope(slope2) && (IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1))) {
if ((IsInclinedSlope(slope1) && DiagDirToAxis(GetInclinedSlopeDirection(slope1)) == OtherAxis(axis)) || (IsInclinedSlope(slope2) && DiagDirToAxis(GetInclinedSlopeDirection(slope2)) == OtherAxis(axis))) {
if (IsInclinedSlope(slope1)) {
/* Mark the tile as already cleared for the terraform command.
* Do this for all tiles (like trees), not only objects. */
ClearedObjectArea *coa = FindClearedObject(tile);
if (coa == NULL) {
coa = _cleared_object_areas.Append();
coa->first_tile = tile;
coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
}
/* Hide the tile from the terraforming command */
TileIndex tile_inclined1_before = coa->first_tile;
coa->first_tile = INVALID_TILE;
ret = DoCommand(tile, IsSlopeWithThreeCornersRaised(slope2) ? ComplementSlope(slope1) : slope1, IsSlopeWithThreeCornersRaised(slope2) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
coa->first_tile = tile_inclined1_before;
if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
cost.AddCost(ret);
} else {
/* Mark the tile as already cleared for the terraform command.
* Do this for all tiles (like trees), not only objects. */
ClearedObjectArea *coa = FindClearedObject(tile2);
if (coa == NULL) {
coa = _cleared_object_areas.Append();
coa->first_tile = tile2;
coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
}
/* Hide the tile from the terraforming command */
TileIndex tile_inclined2_before = coa->first_tile;
coa->first_tile = INVALID_TILE;
ret = DoCommand(tile2, IsSlopeWithThreeCornersRaised(slope1) ? ComplementSlope(slope2) : slope2, IsSlopeWithThreeCornersRaised(slope1) ? 1 : 0, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
coa->first_tile = tile_inclined2_before;
if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
cost.AddCost(ret);
}
}
} else {
if ((slope1 == SLOPE_EW || slope1 == SLOPE_NS) && (IsSlopeWithOneCornerRaised(slope2) || IsSlopeWithThreeCornersRaised(slope2)) || (slope2 == SLOPE_NS || slope2 == SLOPE_EW) && (IsSlopeWithOneCornerRaised(slope1) || IsSlopeWithThreeCornersRaised(slope1))) {
/* Mark the tile as already cleared for the terraform command.
* Do this for all tiles (like trees), not only objects. */
ClearedObjectArea *coa = FindClearedObject((slope1 == SLOPE_EW || slope1 == SLOPE_NS) ? tile : tile2);
if (coa == NULL) {
coa = _cleared_object_areas.Append();
coa->first_tile = (slope1 == SLOPE_EW || slope1 == SLOPE_NS) ? tile : tile2;
coa->area = TileArea(tile, axis == AXIS_X ? 2 : 1, axis == AXIS_Y ? 2 : 1);
}
/* Hide the tile from the terraforming command */
TileIndex tile_oppositecorners_before = coa->first_tile;
coa->first_tile = INVALID_TILE;
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);
coa->first_tile = tile_oppositecorners_before;
if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
cost.AddCost(ret);
} else {
/* Shouldn't reach here. */
assert(false);
}
}
}
}
}