diff --git a/clear_cmd.c b/clear_cmd.c index 1f46a071df..6d1016daa0 100644 --- a/clear_cmd.c +++ b/clear_cmd.c @@ -534,9 +534,12 @@ static void DrawTile_Clear(TileInfo *ti) DrawClearLandFence(ti); } -static uint GetSlopeZ_Clear(const TileInfo* ti) +static uint GetSlopeZ_Clear(TileIndex tile, uint x, uint y) { - return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; + uint z; + uint tileh = GetTileSlope(tile, &z); + + return z + GetPartialZ(x & 0xF, y & 0xF, tileh); } static Slope GetSlopeTileh_Clear(TileIndex tile, Slope tileh) diff --git a/dummy_land.c b/dummy_land.c index 1052cde0a7..88daa07525 100644 --- a/dummy_land.c +++ b/dummy_land.c @@ -14,7 +14,7 @@ static void DrawTile_Dummy(TileInfo *ti) } -static uint GetSlopeZ_Dummy(const TileInfo* ti) +static uint GetSlopeZ_Dummy(TileIndex tile, uint x, uint y) { return 0; } diff --git a/industry_cmd.c b/industry_cmd.c index fe7e79d458..dfc366c6f9 100644 --- a/industry_cmd.c +++ b/industry_cmd.c @@ -267,9 +267,9 @@ static void DrawTile_Industry(TileInfo *ti) } } -static uint GetSlopeZ_Industry(const TileInfo *ti) +static uint GetSlopeZ_Industry(TileIndex tile, uint x, uint y) { - return ti->z + (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT); + return GetTileMaxZ(tile); } static Slope GetSlopeTileh_Industry(TileIndex tile, Slope tileh) diff --git a/landscape.c b/landscape.c index 753e24d487..e6608fa5e1 100644 --- a/landscape.c +++ b/landscape.c @@ -174,11 +174,9 @@ uint GetPartialZ(int x, int y, Slope corners) uint GetSlopeZ(int x, int y) { - TileInfo ti; + TileIndex tile = TileVirtXY(x, y); - FindLandscapeHeight(&ti, x, y); - - return _tile_type_procs[ti.type]->get_slope_z_proc(&ti); + return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y); } diff --git a/openttd.h b/openttd.h index d0062fd3f6..c72cbc0a4a 100644 --- a/openttd.h +++ b/openttd.h @@ -298,7 +298,7 @@ typedef struct { typedef void DrawTileProc(TileInfo *ti); -typedef uint GetSlopeZProc(const TileInfo* ti); +typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y); typedef int32 ClearTileProc(TileIndex tile, byte flags); typedef void GetAcceptedCargoProc(TileIndex tile, AcceptedCargo res); typedef void GetTileDescProc(TileIndex tile, TileDesc *td); diff --git a/rail_cmd.c b/rail_cmd.c index 1dd401df6a..338742b251 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -1692,20 +1692,20 @@ void SetSignalsOnBothDir(TileIndex tile, byte track) UpdateSignalsOnSegment(tile, _search_dir_2[track]); } -static uint GetSlopeZ_Track(const TileInfo* ti) +static uint GetSlopeZ_Track(TileIndex tile, uint x, uint y) { - Slope tileh = ti->tileh; - uint z = ti->z; + uint z; + Slope tileh = GetTileSlope(tile, &z); if (tileh == SLOPE_FLAT) return z; - if (IsPlainRailTile(ti->tile)) { - uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile)); + if (IsPlainRailTile(tile)) { + uint f = GetRailFoundation(tileh, GetTrackBits(tile)); if (f != 0) { if (f < 15) return z + TILE_HEIGHT; // leveled foundation tileh = _inclined_tileh[f - 15]; // inclined foundation } - return z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh); + return z + GetPartialZ(x & 0xF, y & 0xF, tileh); } else { return z + TILE_HEIGHT; } diff --git a/road_cmd.c b/road_cmd.c index 4328aa277b..e4a725711b 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -833,20 +833,20 @@ void DrawRoadDepotSprite(int x, int y, DiagDirection dir) } } -static uint GetSlopeZ_Road(const TileInfo* ti) +static uint GetSlopeZ_Road(TileIndex tile, uint x, uint y) { - Slope tileh = ti->tileh; - uint z = ti->z; + uint z; + Slope tileh = GetTileSlope(tile, &z); if (tileh == SLOPE_FLAT) return z; - if (GetRoadTileType(ti->tile) == ROAD_TILE_NORMAL) { - uint f = GetRoadFoundation(tileh, GetRoadBits(ti->tile)); + if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) { + uint f = GetRoadFoundation(tileh, GetRoadBits(tile)); if (f != 0) { if (f < 15) return z + TILE_HEIGHT; // leveled foundation tileh = _inclined_tileh[f - 15]; // inclined foundation } - return z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh); + return z + GetPartialZ(x & 0xF, y & 0xF, tileh); } else { return z + TILE_HEIGHT; } diff --git a/station_cmd.c b/station_cmd.c index 1e8a4ea12b..305364df6a 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -2152,9 +2152,9 @@ void StationPickerDrawSprite(int x, int y, RailType railtype, int image) } } -static uint GetSlopeZ_Station(const TileInfo* ti) +static uint GetSlopeZ_Station(TileIndex tile, uint x, uint y) { - return ti->z + (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT); + return GetTileMaxZ(tile); } static Slope GetSlopeTileh_Station(TileIndex tile, Slope tileh) diff --git a/town_cmd.c b/town_cmd.c index 720918419c..f87f1917cf 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -110,9 +110,9 @@ static void DrawTile_Town(TileInfo *ti) } } -static uint GetSlopeZ_Town(const TileInfo* ti) +static uint GetSlopeZ_Town(TileIndex tile, uint x, uint y) { - return ti->z + (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT); + return GetTileMaxZ(tile); } static Slope GetSlopeTileh_Town(TileIndex tile, Slope tileh) diff --git a/tree_cmd.c b/tree_cmd.c index 9caf6b9d65..99b2de384d 100644 --- a/tree_cmd.c +++ b/tree_cmd.c @@ -323,9 +323,12 @@ static void DrawTile_Trees(TileInfo *ti) } -static uint GetSlopeZ_Trees(const TileInfo* ti) +static uint GetSlopeZ_Trees(TileIndex tile, uint x, uint y) { - return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; + uint z; + uint tileh = GetTileSlope(tile, &z); + + return z + GetPartialZ(x & 0xF, y & 0xF, tileh); } static Slope GetSlopeTileh_Trees(TileIndex tile, Slope tileh) diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index 8380b04672..bddc02d2d6 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -1089,13 +1089,13 @@ static void DrawTile_TunnelBridge(TileInfo *ti) } } -static uint GetSlopeZ_TunnelBridge(const TileInfo* ti) +static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y) { - TileIndex tile = ti->tile; - uint z = ti->z; - uint x = ti->x & 0xF; - uint y = ti->y & 0xF; - Slope tileh = ti->tileh; + uint z; + Slope tileh = GetTileSlope(tile, &z); + + x &= 0xF; + y &= 0xF; if (IsTunnel(tile)) { uint pos = (DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? y : x); diff --git a/unmovable_cmd.c b/unmovable_cmd.c index 7da8360418..0188900e65 100644 --- a/unmovable_cmd.c +++ b/unmovable_cmd.c @@ -176,12 +176,15 @@ static void DrawTile_Unmovable(TileInfo *ti) } } -static uint GetSlopeZ_Unmovable(const TileInfo* ti) +static uint GetSlopeZ_Unmovable(TileIndex tile, uint x, uint y) { - if (IsOwnedLand(ti->tile)) { - return ti->z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh); + if (IsOwnedLand(tile)) { + uint z; + uint tileh = GetTileSlope(tile, &z); + + return z + GetPartialZ(x & 0xF, y & 0xF, tileh); } else { - return ti->z + (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT); + return GetTileMaxZ(tile); } } diff --git a/viewport.c b/viewport.c index eb0cbe51e4..200098188b 100644 --- a/viewport.c +++ b/viewport.c @@ -294,7 +294,6 @@ ViewPort *IsPtInWindowViewport(const Window *w, int x, int y) static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y) { - int z; Point pt; int a,b; @@ -314,16 +313,19 @@ static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y) a = x+y; b = x-y; #endif - z = GetSlopeZ(a, b) >> 1; - z = GetSlopeZ(a+z, b+z) >> 1; - z = GetSlopeZ(a+z, b+z) >> 1; - z = GetSlopeZ(a+z, b+z) >> 1; - z = GetSlopeZ(a+z, b+z) >> 1; - pt.x = a+z; - pt.y = b+z; + if ((uint)a < MapMaxX() * TILE_SIZE && (uint)b < MapMaxY() * TILE_SIZE) { + uint z; - if ((uint)pt.x >= MapMaxX() * TILE_SIZE || (uint)pt.y >= MapMaxY() * TILE_SIZE) { + z = GetSlopeZ(a, b ) / 2; + z = GetSlopeZ(a + z, b + z) / 2; + z = GetSlopeZ(a + z, b + z) / 2; + z = GetSlopeZ(a + z, b + z) / 2; + z = GetSlopeZ(a + z, b + z) / 2; + + pt.x = a + z; + pt.y = b + z; + } else { pt.x = pt.y = -1; } diff --git a/water_cmd.c b/water_cmd.c index ca23cc84fb..834cfd1964 100644 --- a/water_cmd.c +++ b/water_cmd.c @@ -479,9 +479,12 @@ void DrawShipDepotSprite(int x, int y, int image) } -static uint GetSlopeZ_Water(const TileInfo *ti) +static uint GetSlopeZ_Water(TileIndex tile, uint x, uint y) { - return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; + uint z; + uint tileh = GetTileSlope(tile, &z); + + return z + GetPartialZ(x & 0xF, y & 0xF, tileh); } static Slope GetSlopeTileh_Water(TileIndex tile, Slope tileh)