diff options
author | Darkvater <darkvater@openttd.org> | 2005-04-14 22:59:49 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2005-04-14 22:59:49 +0000 |
commit | 174030a15f0b67bde1e62ad2d092197c8a722fa0 (patch) | |
tree | 7f3ee2c3f7281a19d08473fe35c6009927b7d7d9 | |
parent | 2e58ce2fd92102f608104ab5de687ec52a6d95d4 (diff) | |
download | openttd-174030a15f0b67bde1e62ad2d092197c8a722fa0.tar.xz |
(svn r2201) - Fix: Crash in scenario-editor with terraforming out-of-map bounds.
-rw-r--r-- | main_gui.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/main_gui.c b/main_gui.c index 818631556..65def85a8 100644 --- a/main_gui.c +++ b/main_gui.c @@ -1152,7 +1152,7 @@ static void AskResetLandscape(uint mode) */ static void CommonRaiseLowerBigLand(uint tile, int mode) { - int size; + int sizex, sizey; byte h; _error_message_2 = mode ? STR_0808_CAN_T_RAISE_LAND_HERE : STR_0809_CAN_T_LOWER_LAND_HERE; @@ -1164,27 +1164,32 @@ static void CommonRaiseLowerBigLand(uint tile, int mode) } else { SndPlayTileFx(SND_1F_SPLAT, tile); - size = _terraform_size; - assert(size != 0); + assert(_terraform_size != 0); + // check out for map overflows + sizex = min(MapSizeX() - TileX(tile) - 1, _terraform_size); + sizey = min(MapSizeY() - TileY(tile) - 1, _terraform_size); + + if (sizex == 0 || sizey == 0) return; + if (mode != 0) { /* Raise land */ h = 15; // XXX - max height - BEGIN_TILE_LOOP(tile2, size, size, tile) + BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) { h = min(h, TileHeight(tile2)); - END_TILE_LOOP(tile2, size, size, tile) + } END_TILE_LOOP(tile2, sizex, sizey, tile) } else { /* Lower land */ h = 0; - BEGIN_TILE_LOOP(tile2, size, size, tile) + BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) { h = max(h, TileHeight(tile2)); - END_TILE_LOOP(tile2, size, size, tile) + } END_TILE_LOOP(tile2, sizex, sizey, tile) } - BEGIN_TILE_LOOP(tile2, size, size, tile) + BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) { if (TileHeight(tile2) == h) { DoCommandP(tile2, 8, (uint32)mode, NULL, CMD_TERRAFORM_LAND | CMD_AUTO); } - END_TILE_LOOP(tile2, size, size, tile) + } END_TILE_LOOP(tile2, sizex, sizey, tile) } _generating_world = false; |