(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

This commit is contained in:
tron 2006-05-07 07:55:05 +00:00
parent 4f092c8de8
commit 5622ad4b5e
6 changed files with 26 additions and 20 deletions

View File

@ -535,15 +535,11 @@ static void AnimateTile_Industry(TileIndex tile)
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)

View File

@ -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);
}
}

17
tile.c
View File

@ -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;
}

1
tile.h
View File

@ -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)
{

View File

@ -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;

View File

@ -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 */