mirror of https://github.com/OpenTTD/OpenTTD
(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
parent
4f092c8de8
commit
5622ad4b5e
|
@ -535,15 +535,11 @@ static void AnimateTile_Industry(TileIndex tile)
|
||||||
|
|
||||||
static void CreateIndustryEffectSmoke(TileIndex tile)
|
static void CreateIndustryEffectSmoke(TileIndex tile)
|
||||||
{
|
{
|
||||||
Slope tileh;
|
uint x = TileX(tile) * TILE_SIZE;
|
||||||
uint x;
|
uint y = TileY(tile) * TILE_SIZE;
|
||||||
uint y;
|
uint z = GetTileMaxZ(tile);
|
||||||
uint z;
|
|
||||||
|
|
||||||
tileh = GetTileSlope(tile, &z);
|
CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MakeIndustryTileBigger(TileIndex tile)
|
static void MakeIndustryTileBigger(TileIndex tile)
|
||||||
|
|
|
@ -396,10 +396,9 @@ void InitializeLandscape(void)
|
||||||
void ConvertGroundTilesIntoWaterTiles(void)
|
void ConvertGroundTilesIntoWaterTiles(void)
|
||||||
{
|
{
|
||||||
TileIndex tile = 0;
|
TileIndex tile = 0;
|
||||||
uint h;
|
|
||||||
|
|
||||||
for (tile = 0; tile < MapSize(); ++tile) {
|
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);
|
MakeWater(tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
tile.c
17
tile.c
|
@ -56,3 +56,20 @@ uint GetTileZ(TileIndex tile)
|
||||||
GetTileSlope(tile, &h);
|
GetTileSlope(tile, &h);
|
||||||
return 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
1
tile.h
|
@ -30,6 +30,7 @@ typedef enum TropicZones {
|
||||||
Slope GetTileh(uint n, uint w, uint e, uint s, uint *h);
|
Slope GetTileh(uint n, uint w, uint e, uint s, uint *h);
|
||||||
Slope GetTileSlope(TileIndex tile, uint *h);
|
Slope GetTileSlope(TileIndex tile, uint *h);
|
||||||
uint GetTileZ(TileIndex tile);
|
uint GetTileZ(TileIndex tile);
|
||||||
|
uint GetTileMaxZ(TileIndex tile);
|
||||||
|
|
||||||
static inline bool CorrectZ(Slope tileh)
|
static inline bool CorrectZ(Slope tileh)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2623,13 +2623,8 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
|
||||||
|
|
||||||
case MP_TUNNELBRIDGE:
|
case MP_TUNNELBRIDGE:
|
||||||
if (IsBridge(tile) && IsBridgeMiddle(tile)) {
|
if (IsBridge(tile) && IsBridgeMiddle(tile)) {
|
||||||
uint height;
|
// is train going over the bridge?
|
||||||
Slope tileh = GetTileSlope(tile, &height);
|
if (v->z_pos > GetTileMaxZ(tile)) return true;
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1357,10 +1357,8 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
|
||||||
}
|
}
|
||||||
} else if (IsBridge(tile)) { // XXX is this necessary?
|
} else if (IsBridge(tile)) { // XXX is this necessary?
|
||||||
if (v->type == VEH_Road || (v->type == VEH_Train && IsFrontEngine(v))) {
|
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) ||
|
if (IsBridgeRamp(tile) ||
|
||||||
myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge
|
myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge
|
||||||
/* modify speed of vehicle */
|
/* modify speed of vehicle */
|
||||||
|
|
Loading…
Reference in New Issue