From 5622ad4b5efdba60db4bcfaf03ba358c569064f6 Mon Sep 17 00:00:00 2001 From: tron Date: Sun, 7 May 2006 07:55:05 +0000 Subject: (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 | 14 +++++--------- landscape.c | 3 +-- tile.c | 17 +++++++++++++++++ tile.h | 1 + train_cmd.c | 9 ++------- tunnelbridge_cmd.c | 4 +--- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/industry_cmd.c b/industry_cmd.c index 1a4c96209..bad47ae6d 100644 --- a/industry_cmd.c +++ b/industry_cmd.c @@ -535,15 +535,11 @@ static void AnimateTile_Industry(TileIndex tile) static void CreateIndustryEffectSmoke(TileIndex tile) { - Slope tileh; - uint x; - uint y; - uint z; - - 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); + uint x = TileX(tile) * TILE_SIZE; + uint y = TileY(tile) * TILE_SIZE; + uint z = GetTileMaxZ(tile); + + CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE); } static void MakeIndustryTileBigger(TileIndex tile) diff --git a/landscape.c b/landscape.c index 53c72dfaf..cc044eab2 100644 --- a/landscape.c +++ b/landscape.c @@ -396,10 +396,9 @@ void InitializeLandscape(void) 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); } } diff --git a/tile.c b/tile.c index 36df4c542..98fb5f0bd 100644 --- a/tile.c +++ b/tile.c @@ -56,3 +56,20 @@ uint GetTileZ(TileIndex tile) 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; +} diff --git a/tile.h b/tile.h index cb51208e3..ebb1bb89a 100644 --- a/tile.h +++ b/tile.h @@ -30,6 +30,7 @@ typedef enum TropicZones { 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) { diff --git a/train_cmd.c b/train_cmd.c index a4ae5d61e..a9d5950b1 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -2623,13 +2623,8 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile) 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; diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index 503616e67..aca77e9e1 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -1357,10 +1357,8 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y } } 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 */ -- cgit v1.2.3-70-g09d2