# HG changeset patch # User rubidium # Date 2014-09-22 15:04:18 # Node ID 3432f0c0d85c1ba5dab33c4badf69fe3ee2acf13 # Parent 59c428b78abee84cbbf7279b822c206145c5e4f3 (svn r26908) -Codechange: replace a magic number by a more logical calculation diff --git a/src/viewport.cpp b/src/viewport.cpp --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -419,11 +419,13 @@ static Point TranslateXYToTileCoord(cons a = y - x; b = y + x; - /* we need to move variables in to the valid range, as the - * GetTileZoomCenterWindow() function can call here with invalid x and/or y, - * when the user tries to zoom out along the sides of the map */ - a = Clamp(a, -4 * (int)TILE_SIZE, (int)(MapMaxX() * TILE_SIZE) - 1); - b = Clamp(b, -4 * (int)TILE_SIZE, (int)(MapMaxY() * TILE_SIZE) - 1); + /* Bring the coordinates near to a valid range. This is mostly due to the + * tiles on the north side of the map possibly being drawn too high due to + * the extra height levels. So at the top we allow a number of extra tiles. + * This number is based on the tile height and pixels. */ + int extra_tiles = CeilDiv(_settings_game.construction.max_heightlevel * TILE_HEIGHT, TILE_PIXELS); + a = Clamp(a, -extra_tiles * TILE_SIZE, MapMaxX() * TILE_SIZE - 1); + b = Clamp(b, -extra_tiles * TILE_SIZE, MapMaxY() * TILE_SIZE - 1); /* (a, b) is the X/Y-world coordinate that belongs to (x,y) if the landscape would be completely flat on height 0. * Now find the Z-world coordinate by fix point iteration.