diff options
author | Yexo <yexo@openttd.org> | 2009-01-21 02:31:55 +0000 |
---|---|---|
committer | Yexo <yexo@openttd.org> | 2009-01-21 02:31:55 +0000 |
commit | db3ee34b4468aa3448b64e339258760885c5d716 (patch) | |
tree | 272533ac91b7bc3ab16c3ee1a997e142f3170a2a /src/terraform_cmd.cpp | |
parent | 5e7669b539002cb9ec9e608f4601a827b5e9da57 (diff) | |
download | openttd-db3ee34b4468aa3448b64e339258760885c5d716.tar.xz |
(svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Diffstat (limited to 'src/terraform_cmd.cpp')
-rw-r--r-- | src/terraform_cmd.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/terraform_cmd.cpp b/src/terraform_cmd.cpp index 25c193299..337eca2fd 100644 --- a/src/terraform_cmd.cpp +++ b/src/terraform_cmd.cpp @@ -130,9 +130,10 @@ static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) */ static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile) { - TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); - TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); - TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); + /* Make sure all tiles passed to TerraformAddDirtyTile are within [0, MapSize()] */ + if (TileY(tile) >= 1) TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1)); + if (TileY(tile) >= 1 && TileX(tile) >= 1) TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1)); + if (TileX(tile) >= 1) TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0)); TerraformAddDirtyTile(ts, tile); } @@ -159,10 +160,10 @@ static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int */ if (height == TerraformGetHeightOfTile(ts, tile)) return CMD_ERROR; - /* Check "too close to edge of map" */ + /* Check "too close to edge of map". Only possible when freeform-edges is off. */ uint x = TileX(tile); uint y = TileY(tile); - if ((x <= 1) || (y <= 1) || (x >= MapMaxX() - 1) || (y >= MapMaxY() - 1)) { + if (!_settings_game.construction.freeform_edges && ((x <= 1) || (y <= 1) || (x >= MapMaxX() - 1) || (y >= MapMaxY() - 1))) { /* * Determine a sensible error tile */ @@ -187,6 +188,7 @@ static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int { const TileIndexDiffC *ttm; + TileIndex orig_tile = tile; static const TileIndexDiffC _terraform_tilepos[] = { { 1, 0}, // move to tile in SE {-2, 0}, // undo last move, and move to tile in NW @@ -197,6 +199,11 @@ static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { tile += ToTileIndexDiff(*ttm); + if (tile >= MapSize()) continue; + /* Make sure we don't wrap around the map */ + if (Delta(TileX(orig_tile), TileX(tile)) == MapSizeX() - 1) continue; + if (Delta(TileY(orig_tile), TileY(tile)) == MapSizeY() - 1) continue; + /* Get TileHeight of neighboured tile as of current terraform progress */ int r = TerraformGetHeightOfTile(ts, tile); int height_diff = height - r; @@ -224,9 +231,6 @@ static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int */ CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text) { - /* Make an extra check for map-bounds cause we add tiles to the originating tile */ - if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR; - _terraform_err_tile = INVALID_TILE; CommandCost total_cost(EXPENSES_CONSTRUCTION); @@ -271,6 +275,11 @@ CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, for (int count = ts.tile_table_count; count != 0; count--, ti++) { TileIndex tile = *ti; + assert(tile < MapSize()); + /* MP_VOID tiles can be terraformed but as tunnels and bridges + * cannot go under / over these tiles they don't need checking. */ + if (IsTileType(tile, MP_VOID)) continue; + /* Find new heights of tile corners */ uint z_N = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0)); uint z_W = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0)); |