summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clear_cmd.c7
-rw-r--r--dummy_land.c2
-rw-r--r--industry_cmd.c4
-rw-r--r--landscape.c6
-rw-r--r--openttd.h2
-rw-r--r--rail_cmd.c12
-rw-r--r--road_cmd.c12
-rw-r--r--station_cmd.c4
-rw-r--r--town_cmd.c4
-rw-r--r--tree_cmd.c7
-rw-r--r--tunnelbridge_cmd.c12
-rw-r--r--unmovable_cmd.c11
-rw-r--r--viewport.c20
-rw-r--r--water_cmd.c7
14 files changed, 61 insertions, 49 deletions
diff --git a/clear_cmd.c b/clear_cmd.c
index 1f46a071d..6d1016daa 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 1052cde0a..88daa0752 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 fe7e79d45..dfc366c6f 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 753e24d48..e6608fa5e 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 d0062fd3f..c72cbc0a4 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 1dd401df6..338742b25 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 4328aa277..e4a725711 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 1e8a4ea12..305364df6 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 720918419..f87f1917c 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 9caf6b9d6..99b2de384 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 8380b0467..bddc02d2d 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 7da836041..0188900e6 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 eb0cbe51e..200098188 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 ca23cc84f..834cfd196 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)