summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/heightmap.cpp3
-rw-r--r--src/tgp.cpp3
-rw-r--r--src/tile_map.cpp6
-rw-r--r--src/tile_map.h19
4 files changed, 21 insertions, 10 deletions
diff --git a/src/heightmap.cpp b/src/heightmap.cpp
index 8f0fac6ad..2f6d14e56 100644
--- a/src/heightmap.cpp
+++ b/src/heightmap.cpp
@@ -364,8 +364,7 @@ static void GrayscaleToMapHeights(uint img_width, uint img_height, byte *map)
SetTileHeight(tile, map[img_row * img_width + img_col] / 16);
}
/* Only clear the tiles within the map area. */
- if (TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY() &&
- (!_settings_game.construction.freeform_edges || (TileX(tile) != 0 && TileY(tile) != 0))) {
+ if (IsInnerTile(tile)) {
MakeClear(tile, CLEAR_GRASS, 3);
}
}
diff --git a/src/tgp.cpp b/src/tgp.cpp
index 6d17fd853..4cbde2d82 100644
--- a/src/tgp.cpp
+++ b/src/tgp.cpp
@@ -950,8 +950,7 @@ static void TgenSetTileHeight(TileIndex tile, int height)
SetTileHeight(tile, height);
/* Only clear the tiles within the map area. */
- if (TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY() &&
- (!_settings_game.construction.freeform_edges || (TileX(tile) != 0 && TileY(tile) != 0))) {
+ if (IsInnerTile(tile)) {
MakeClear(tile, CLEAR_GRASS, 3);
}
}
diff --git a/src/tile_map.cpp b/src/tile_map.cpp
index 017bb5c56..86670c88a 100644
--- a/src/tile_map.cpp
+++ b/src/tile_map.cpp
@@ -22,11 +22,7 @@ Slope GetTileSlope(TileIndex tile, int *h)
{
assert(tile < MapSize());
- uint x = TileX(tile);
- uint y = TileY(tile);
-
- if (x == MapMaxX() || y == MapMaxY() ||
- ((x == 0 || y == 0) && _settings_game.construction.freeform_edges)) {
+ if (!IsInnerTile(tile)) {
if (h != NULL) *h = TileHeight(tile);
return SLOPE_FLAT;
}
diff --git a/src/tile_map.h b/src/tile_map.h
index 2c5cfffbf..f9c7a2ac9 100644
--- a/src/tile_map.h
+++ b/src/tile_map.h
@@ -78,6 +78,23 @@ static inline TileType GetTileType(TileIndex tile)
}
/**
+ * Check if a tile is within the map (not a border)
+ *
+ * @param tile The tile to check
+ * @return Whether the tile is in the interior of the map
+ * @pre tile < MapSize()
+ */
+static inline bool IsInnerTile(TileIndex tile)
+{
+ assert(tile < MapSize());
+
+ uint x = TileX(tile);
+ uint y = TileY(tile);
+
+ return x < MapMaxX() && y < MapMaxY() && ((x > 0 && y > 0) || !_settings_game.construction.freeform_edges);
+}
+
+/**
* Set the type of a tile
*
* This functions sets the type of a tile. If the type
@@ -95,7 +112,7 @@ static inline void SetTileType(TileIndex tile, TileType type)
/* VOID tiles (and no others) are exactly allowed at the lower left and right
* edges of the map. If _settings_game.construction.freeform_edges is true,
* the upper edges of the map are also VOID tiles. */
- assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() || (_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) == (type == MP_VOID));
+ assert(IsInnerTile(tile) == (type != MP_VOID));
SB(_m[tile].type_height, 4, 4, type);
}