summaryrefslogtreecommitdiff
path: root/src/landscape.cpp
diff options
context:
space:
mode:
authorJohannes E. Krause <j.k@eclipso.de>2019-01-13 20:58:48 +0100
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-01-24 21:17:17 +0100
commitc33596fe4af59213a8a6119fee61a75ed91abdc4 (patch)
treea88ea65bb25e6a66aff19ac11d4039b7314e7a1b /src/landscape.cpp
parent05da5a177c7e976d5da0da541a842482ab23017d (diff)
downloadopenttd-c33596fe4af59213a8a6119fee61a75ed91abdc4.tar.xz
Codechange: Unify tile height model in all functions (Patch by adf88, #6583)
Diffstat (limited to 'src/landscape.cpp')
-rw-r--r--src/landscape.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/landscape.cpp b/src/landscape.cpp
index 79b24baf7..991a445ad 100644
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -131,9 +131,15 @@ Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
* (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely)
* So give it a z-malus of 4 in the first iterations. */
int z = 0;
- for (int i = 0; i < 5; i++) z = GetSlopePixelZ(Clamp(pt.x + max(z, 4) - 4, min_coord, max_x), Clamp(pt.y + max(z, 4) - 4, min_coord, max_y)) / 2;
- for (int m = 3; m > 0; m--) z = GetSlopePixelZ(Clamp(pt.x + max(z, m) - m, min_coord, max_x), Clamp(pt.y + max(z, m) - m, min_coord, max_y)) / 2;
- for (int i = 0; i < 5; i++) z = GetSlopePixelZ(Clamp(pt.x + z, min_coord, max_x), Clamp(pt.y + z, min_coord, max_y)) / 2;
+ if (clamp_to_map) {
+ for (int i = 0; i < 5; i++) z = GetSlopePixelZ(Clamp(pt.x + max(z, 4) - 4, min_coord, max_x), Clamp(pt.y + max(z, 4) - 4, min_coord, max_y)) / 2;
+ for (int m = 3; m > 0; m--) z = GetSlopePixelZ(Clamp(pt.x + max(z, m) - m, min_coord, max_x), Clamp(pt.y + max(z, m) - m, min_coord, max_y)) / 2;
+ for (int i = 0; i < 5; i++) z = GetSlopePixelZ(Clamp(pt.x + z, min_coord, max_x), Clamp(pt.y + z, min_coord, max_y)) / 2;
+ } else {
+ for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + max(z, 4) - 4, pt.y + max(z, 4) - 4) / 2;
+ for (int m = 3; m > 0; m--) z = GetSlopePixelZOutsideMap(pt.x + max(z, m) - m, pt.y + max(z, m) - m) / 2;
+ for (int i = 0; i < 5; i++) z = GetSlopePixelZOutsideMap(pt.x + z, pt.y + z ) / 2;
+ }
pt.x += z;
pt.y += z;
@@ -343,6 +349,23 @@ int GetSlopePixelZ(int x, int y)
}
/**
+ * Return world \c z coordinate of a given point of a tile,
+ * also for tiles outside the map (virtual "black" tiles).
+ *
+ * @param x World X coordinate in tile "units", may be ouside the map.
+ * @param y World Y coordinate in tile "units", may be ouside the map.
+ * @return World Z coordinate at tile ground level, including slopes and foundations.
+ */
+int GetSlopePixelZOutsideMap(int x, int y)
+{
+ if (IsInsideBS(x, 0, MapSizeX() * TILE_SIZE) && IsInsideBS(y, 0, MapSizeY() * TILE_SIZE)) {
+ return GetSlopePixelZ(x, y);
+ } else {
+ return _tile_type_procs[MP_VOID]->get_slope_z_proc(INVALID_TILE, x, y);
+ }
+}
+
+/**
* Determine the Z height of a corner relative to TileZ.
*
* @pre The slope must not be a halftile slope.