(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
authortron
Sun, 07 May 2006 07:55:05 +0000
changeset 3773 996897ffc8ea
parent 3772 4872d75f5172
child 3774 4a1efffc7cdc
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
industry_cmd.c
landscape.c
tile.c
tile.h
train_cmd.c
tunnelbridge_cmd.c
--- a/industry_cmd.c	Sun May 07 07:01:48 2006 +0000
+++ b/industry_cmd.c	Sun May 07 07:55:05 2006 +0000
@@ -535,15 +535,11 @@
 
 static void CreateIndustryEffectSmoke(TileIndex tile)
 {
-	Slope tileh;
-	uint x;
-	uint y;
-	uint z;
+	uint x = TileX(tile) * TILE_SIZE;
+	uint y = TileY(tile) * TILE_SIZE;
+	uint z = GetTileMaxZ(tile);
 
-	tileh = GetTileSlope(tile, &z);
-	x = TileX(tile) * TILE_SIZE;
-	y = TileY(tile) * TILE_SIZE;
-	CreateEffectVehicle(x + 15, y + 14, z + 59 + (tileh != SLOPE_FLAT ? TILE_HEIGHT : 0), EV_CHIMNEY_SMOKE);
+	CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE);
 }
 
 static void MakeIndustryTileBigger(TileIndex tile)
--- a/landscape.c	Sun May 07 07:01:48 2006 +0000
+++ b/landscape.c	Sun May 07 07:55:05 2006 +0000
@@ -396,10 +396,9 @@
 void ConvertGroundTilesIntoWaterTiles(void)
 {
 	TileIndex tile = 0;
-	uint h;
 
 	for (tile = 0; tile < MapSize(); ++tile) {
-		if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h == 0) {
+		if (IsTileType(tile, MP_CLEAR) && GetTileMaxZ(tile) == 0) {
 			MakeWater(tile);
 		}
 	}
--- a/tile.c	Sun May 07 07:01:48 2006 +0000
+++ b/tile.c	Sun May 07 07:55:05 2006 +0000
@@ -56,3 +56,20 @@
 	GetTileSlope(tile, &h);
 	return h;
 }
+
+
+uint GetTileMaxZ(TileIndex t)
+{
+	uint max;
+	uint h;
+
+	h = TileHeight(t);
+	max = h;
+	h = TileHeight(t + TileDiffXY(1, 0));
+	if (h > max) max = h;
+	h = TileHeight(t + TileDiffXY(0, 1));
+	if (h > max) max = h;
+	h = TileHeight(t + TileDiffXY(1, 1));
+	if (h > max) max = h;
+	return max * 8;
+}
--- a/tile.h	Sun May 07 07:01:48 2006 +0000
+++ b/tile.h	Sun May 07 07:55:05 2006 +0000
@@ -30,6 +30,7 @@
 Slope GetTileh(uint n, uint w, uint e, uint s, uint *h);
 Slope GetTileSlope(TileIndex tile, uint *h);
 uint GetTileZ(TileIndex tile);
+uint GetTileMaxZ(TileIndex tile);
 
 static inline bool CorrectZ(Slope tileh)
 {
--- a/train_cmd.c	Sun May 07 07:01:48 2006 +0000
+++ b/train_cmd.c	Sun May 07 07:55:05 2006 +0000
@@ -2623,13 +2623,8 @@
 
 		case MP_TUNNELBRIDGE:
 			if (IsBridge(tile) && IsBridgeMiddle(tile)) {
-				uint height;
-				Slope tileh = GetTileSlope(tile, &height);
-
-				// correct Z position of a train going under a bridge on slopes
-				if (tileh != SLOPE_FLAT) height += TILE_HEIGHT;
-
-				if (v->z_pos > height) return true; // train is going over bridge
+				// is train going over the bridge?
+				if (v->z_pos > GetTileMaxZ(tile)) return true;
 			}
 			break;
 
--- a/tunnelbridge_cmd.c	Sun May 07 07:01:48 2006 +0000
+++ b/tunnelbridge_cmd.c	Sun May 07 07:55:05 2006 +0000
@@ -1357,10 +1357,8 @@
 		}
 	} else if (IsBridge(tile)) { // XXX is this necessary?
 		if (v->type == VEH_Road || (v->type == VEH_Train && IsFrontEngine(v))) {
-			uint h;
+			uint h = GetTileMaxZ(tile);
 
-			// Compensate for possible foundation
-			if (GetTileSlope(tile, &h) != SLOPE_FLAT) h += TILE_HEIGHT;
 			if (IsBridgeRamp(tile) ||
 					myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge
 				/* modify speed of vehicle */