summaryrefslogtreecommitdiff
path: root/main_gui.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2005-04-14 22:59:49 +0000
committerDarkvater <Darkvater@openttd.org>2005-04-14 22:59:49 +0000
commit1e13bf3d272a37dba078259bfd07481abbb5de8b (patch)
tree7f3ee2c3f7281a19d08473fe35c6009927b7d7d9 /main_gui.c
parent371d8f83862df80d6352cc06aedcf9913db72b2a (diff)
downloadopenttd-1e13bf3d272a37dba078259bfd07481abbb5de8b.tar.xz
(svn r2201) - Fix: Crash in scenario-editor with terraforming out-of-map bounds.
Diffstat (limited to 'main_gui.c')
-rw-r--r--main_gui.c23
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;