summaryrefslogtreecommitdiff
path: root/src/terraform_cmd.cpp
diff options
context:
space:
mode:
authorYexo <Yexo@openttd.org>2009-01-21 02:31:55 +0000
committerYexo <Yexo@openttd.org>2009-01-21 02:31:55 +0000
commite3c69b7c4ebebba0aa85ef41ff6627705acb1db5 (patch)
tree272533ac91b7bc3ab16c3ee1a997e142f3170a2a /src/terraform_cmd.cpp
parent470437df70d63b2c44ce34d408b6820cfa446aed (diff)
downloadopenttd-e3c69b7c4ebebba0aa85ef41ff6627705acb1db5.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.cpp25
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));