Index: src/terraform_gui.h =================================================================== --- src/terraform_gui.h (revision 15654) +++ src/terraform_gui.h (working copy) @@ -12,4 +12,7 @@ void ShowTerraformToolbar(Window *link = NULL); void ShowEditorTerraformToolbar(); +bool TerraformAddErrorTile(TileIndex tile); +void TerraformClearErrorTiles(); +bool IsTerraformErrorTile(TileIndex tile); #endif /* GUI_H */ Index: src/terraform_cmd.cpp =================================================================== --- src/terraform_cmd.cpp (revision 15654) +++ src/terraform_cmd.cpp (working copy) @@ -48,8 +48,63 @@ TerraformerHeightMod modheight[TERRAFORMER_MODHEIGHT_SIZE]; ///< Height modifications. }; -TileIndex _terraform_err_tile; ///< first tile we couldn't terraform +TileIndex _terraform_err_tiles[TERRAFORMER_TILE_TABLE_SIZE+1]; ///< the list of tiles that we couldn't terraform +TileIndex *_terraform_err_max = _terraform_err_tiles; +void PrintErrorTiles() +{ + TileIndex *ptr = _terraform_err_tiles; + while (ptr <= _terraform_err_max) + { + if (*ptr == INVALID_TILE) + printf("INVALID_TILE\n"); + else + printf("%d, ", *ptr); + ptr++; + } +} + +void TerraformAddErrorTile(TileIndex tile) +{ + if (_terraform_err_max - _terraform_err_tiles <= TERRAFORMER_TILE_TABLE_SIZE) + { + *_terraform_err_max = tile; + _terraform_err_max++; + *_terraform_err_max = INVALID_TILE; + MarkTileDirtyByTile(tile); + } + + PrintErrorTiles(); +} + +void TerraformClearErrorTiles() +{ + TileIndex *ptr = _terraform_err_tiles; + while (ptr < _terraform_err_max) + { + MarkTileDirtyByTile(*ptr); + ptr++; + } + + _terraform_err_max = _terraform_err_tiles; + *_terraform_err_max = INVALID_TILE; + PrintErrorTiles(); +} + +bool IsTerraformErrorTile(TileIndex tile) +{ + if (tile == INVALID_TILE) return false; + + TileIndex *ptr = _terraform_err_tiles; + while (ptr < _terraform_err_max) + { + if (*ptr == tile) return true; + ptr++; + } + + return false; +} + /** * Gets the TileHeight (height of north corner) of a tile as of current terraforming progress. * @@ -168,8 +223,8 @@ */ if (x == 1) x = 0; if (y == 1) y = 0; - _terraform_err_tile = TileXY(x, y); - return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); + TerraformAddErrorTile(TileXY(x, y)); + //return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP); } /* Mark incident tiles, that are involved in the terraforming */ @@ -212,7 +267,7 @@ /* Terraform the neighboured corner. The resulting height difference should be 1. */ height_diff += (height_diff < 0 ? 1 : -1); CommandCost cost = TerraformTileHeight(ts, tile, r + height_diff); - if (CmdFailed(cost)) return cost; + //if (CmdFailed(cost)) return cost; total_cost.AddCost(cost); } } @@ -230,7 +285,8 @@ */ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - _terraform_err_tile = INVALID_TILE; + //_terraform_err_tile = INVALID_TILE; + TerraformClearErrorTiles(); CommandCost total_cost(EXPENSES_CONSTRUCTION); int direction = (p2 != 0 ? 1 : -1); @@ -242,28 +298,28 @@ if ((p1 & SLOPE_W) != 0 && tile + TileDiffXY(1, 0) < MapSize()) { TileIndex t = tile + TileDiffXY(1, 0); CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); - if (CmdFailed(cost)) return cost; + //if (CmdFailed(cost)) return cost; total_cost.AddCost(cost); } if ((p1 & SLOPE_S) != 0 && tile + TileDiffXY(1, 1) < MapSize()) { TileIndex t = tile + TileDiffXY(1, 1); CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); - if (CmdFailed(cost)) return cost; + //if (CmdFailed(cost)) return cost; total_cost.AddCost(cost); } if ((p1 & SLOPE_E) != 0 && tile + TileDiffXY(0, 1) < MapSize()) { TileIndex t = tile + TileDiffXY(0, 1); CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); - if (CmdFailed(cost)) return cost; + //if (CmdFailed(cost)) return cost; total_cost.AddCost(cost); } if ((p1 & SLOPE_N) != 0) { TileIndex t = tile + TileDiffXY(0, 0); CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction); - if (CmdFailed(cost)) return cost; + //if (CmdFailed(cost)) return cost; total_cost.AddCost(cost); } @@ -299,12 +355,14 @@ /* Check if bridge would take damage */ if (direction == 1 && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && GetBridgeHeight(GetSouthernBridgeEnd(tile)) <= z_max * TILE_HEIGHT) { - _terraform_err_tile = tile; // highlight the tile under the bridge + //_terraform_err_tile = tile; // highlight the tile under the bridge + TerraformAddErrorTile(tile); return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); } /* Check if tunnel would take damage */ if (direction == -1 && IsTunnelInWay(tile, z_min * TILE_HEIGHT)) { - _terraform_err_tile = tile; // highlight the tile above the tunnel + //_terraform_err_tile = tile; // highlight the tile above the tunnel + TerraformAddErrorTile(tile); return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); } /* Check tiletype-specific things, and add extra-cost */ @@ -313,8 +371,9 @@ CommandCost cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, flags | DC_AUTO, z_min * TILE_HEIGHT, tileh); _generating_world = curr_gen; if (CmdFailed(cost)) { - _terraform_err_tile = tile; - return cost; + //_terraform_err_tile = tile; + TerraformAddErrorTile(tile); + //return cost; } total_cost.AddCost(cost); } @@ -358,7 +417,8 @@ { if (p1 >= MapSize()) return CMD_ERROR; - _terraform_err_tile = INVALID_TILE; + //_terraform_err_tile = INVALID_TILE; + TerraformClearErrorTiles(); /* remember level height */ uint oldh = TileHeight(p1); @@ -389,7 +449,7 @@ uint curh = TileHeight(tile2); while (curh != h) { CommandCost ret = DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); - if (CmdFailed(ret)) break; + //if (CmdFailed(ret)) break; if (flags & DC_EXEC) { money -= ret.GetCost(); Index: src/terraform_gui.cpp =================================================================== --- src/terraform_gui.cpp (revision 15654) +++ src/terraform_gui.cpp (working copy) @@ -33,9 +33,6 @@ { if (success) { SndPlayTileFx(SND_1F_SPLAT, tile); - } else { - extern TileIndex _terraform_err_tile; - SetRedErrorSquare(_terraform_err_tile); } } Index: src/viewport.cpp =================================================================== --- src/viewport.cpp (revision 15654) +++ src/viewport.cpp (working copy) @@ -39,6 +39,7 @@ #include "window_func.h" #include "tilehighlight_func.h" #include "window_gui.h" +#include "terraform_gui.h" #include "table/sprites.h" #include "table/strings.h" @@ -872,7 +873,7 @@ static void DrawTileSelection(const TileInfo *ti) { /* Draw a red error square? */ - bool is_redsq = _thd.redsq == ti->tile; + bool is_redsq = _thd.redsq == ti->tile || IsTerraformErrorTile(ti->tile); if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING); /* no selection active? */ @@ -2098,7 +2099,7 @@ if (tile != old) { if (tile != INVALID_TILE) MarkTileDirtyByTile(tile); - if (old != INVALID_TILE) MarkTileDirtyByTile(old); + if (old != INVALID_TILE) MarkTileDirtyByTile(old); } } Index: src/tilehighlight_type.h =================================================================== --- src/tilehighlight_type.h (revision 15654) +++ src/tilehighlight_type.h (working copy) @@ -71,7 +71,7 @@ ViewportPlaceMethod select_method; ViewportDragDropSelectionProcess select_proc; - TileIndex redsq; + TileIndex redsq; }; #endif /* TILEHIGHLIGHT_TYPE_H */