if (!IsTileFlat(tile_cur)) {
if (GetTileZ(tile) == 0 && GetTileZ(tile_cur) == 0) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
int z_tile = GetTileMaxZ(tile);
int z_tile_cur = GetTileMaxZ(tile_cur);
bool z = Delta(z_tile_cur, z_tile) == 0;
Slope slope = GetTileSlope(tile_cur);
/* Mark the tile as already cleared for the terraform command.
* Do this for all tiles (like trees), not only objects. */
ClearedObjectArea *coa = FindClearedObject(tile_cur);
if (coa == NULL) {
coa = _cleared_object_areas.Append();
coa->first_tile = tile_cur;
coa->area = TileArea(tile_cur, 1, 1);
}
/* Hide the tile from the terraforming command */
TileIndex tile_cur_before = coa->first_tile;
coa->first_tile = INVALID_TILE;
ret = DoCommand(tile_cur, z ? slope : ComplementSlope(slope), z ? 0 : 1, flags | DC_NO_WATER, CMD_TERRAFORM_LAND);
coa->first_tile = tile_cur_before;
if (ret.Failed()) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
cost.AddCost(ret);
}