From 9670d858c828102387be0d86a6890de50a8f0fca Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 5 Nov 2018 11:12:09 +0100 Subject: src/landscape.cpp, src/tile_map.h: fix bug which makes assert fail --- src/landscape.cpp | 25 ++++++++++++++++--------- src/tile_map.h | 7 ++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/landscape.cpp b/src/landscape.cpp index b921deef2..ac9040e16 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -35,6 +35,7 @@ #include #include #include +#include "layer_func.h" #include "table/strings.h" #include "table/sprites.h" @@ -835,17 +836,23 @@ void RunTileLoop() void InitializeLandscape() { - for (uint y = _settings_game.construction.freeform_edges ? 1 : 0; y < MapMaxY(); y++) { - for (uint x = _settings_game.construction.freeform_edges ? 1 : 0; x < MapMaxX(); x++) { - MakeClear(TileXY(x, y), CLEAR_GRASS, 3); - SetTileHeight(TileXY(x, y), 0); - SetTropicZone(TileXY(x, y), TROPICZONE_NORMAL); - ClearBridgeMiddle(TileXY(x, y)); + uint maxx = LayerMaxX(); + uint maxy = LayerMaxY(); + uint sizex = MapSizeX(); + uint layersize = LayerSize(); + + FOR_ALL_LAYERS(layer) { + for (uint y = _settings_game.construction.freeform_edges ? 1 : 0; y < LayerMaxY(); y++) { + for (uint x = _settings_game.construction.freeform_edges ? 1 : 0; x < LayerMaxX(); x++) { + MakeClear(layer * layersize + TileXY(x, y), CLEAR_GRASS, 3); + SetTileHeight(layer * layersize + TileXY(x, y), 0); + SetTropicZone(layer * layersize + TileXY(x, y), TROPICZONE_NORMAL); + ClearBridgeMiddle(layer * layersize + TileXY(x, y)); + } + MakeVoid(layer * layersize + TileXY(LayerMaxX(), y)); } + for (uint x = 0; x < LayerSizeX(); x++) MakeVoid(TileXY(x, LayerMaxY())); } - - for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, MapMaxY())); - for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(MapMaxX(), y)); } static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 }; diff --git a/src/tile_map.h b/src/tile_map.h index 4bd584539..c191ab904 100644 --- a/src/tile_map.h +++ b/src/tile_map.h @@ -14,6 +14,7 @@ #include "map_func.h" #include "core/bitmath_func.hpp" #include "settings_type.h" +#include "layer_func.h" /** * Returns the height of a tile @@ -110,10 +111,10 @@ static inline bool IsInnerTile(TileIndex tile) { assert(tile < MapSize()); - uint x = TileX(tile); - uint y = TileY(tile); + uint x = LayerX(tile); + uint y = LayerY(tile); - return x < MapMaxX() && y < MapMaxY() && ((x > 0 && y > 0) || !_settings_game.construction.freeform_edges); + return x < LayerMaxX() && y < LayerMaxY() && ((x > 0 && y > 0) || !_settings_game.construction.freeform_edges); } /** -- cgit v1.2.3-70-g09d2