mirror of https://github.com/OpenTTD/OpenTTD
(svn r5368) -Backport: 5351, 5352
-Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitchesrelease/0.4
parent
339160760b
commit
a2fc417d86
58
landscape.c
58
landscape.c
|
@ -184,34 +184,54 @@ uint GetSlopeZ(int x, int y)
|
||||||
return _tile_type_procs[ti.type]->get_slope_z_proc(&ti);
|
return _tile_type_procs[ti.type]->get_slope_z_proc(&ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
// direction=true: check for foundation in east and south corner
|
|
||||||
// direction=false: check for foundation in west and south corner
|
static Slope GetFoundationSlope(TileIndex tile, uint* z)
|
||||||
static bool hasFoundation(const TileInfo* ti, bool direction)
|
|
||||||
{
|
{
|
||||||
bool south, other; // southern corner and east/west corner
|
TileInfo ti;
|
||||||
uint slope = _tile_type_procs[ti->type]->get_slope_tileh_proc(ti);
|
Slope tileh;
|
||||||
uint tileh = ti->tileh;
|
Slope slope;
|
||||||
|
|
||||||
if (slope == 0 && slope != tileh) tileh = 15;
|
FindLandscapeHeightByTile(&ti, tile);
|
||||||
south = (tileh & 2) != (slope & 2);
|
tileh = ti.tileh;
|
||||||
|
slope = _tile_type_procs[GetTileType(tile)]->get_slope_tileh_proc(&ti);
|
||||||
|
|
||||||
if (direction) {
|
// Flatter slope -> higher base height
|
||||||
other = (tileh & 4) != (slope & 4);
|
if (slope < tileh) *z += TILE_HEIGHT;
|
||||||
} else {
|
return slope;
|
||||||
other = (tileh & 1) != (slope & 1);
|
|
||||||
}
|
|
||||||
return south || other;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
|
||||||
|
{
|
||||||
|
uint z;
|
||||||
|
Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z);
|
||||||
|
|
||||||
|
return
|
||||||
|
(z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) > z + (slope & SLOPE_E ? TILE_HEIGHT : 0)) ||
|
||||||
|
(z_here + (slope_here & SLOPE_W ? TILE_HEIGHT : 0) > z + (slope & SLOPE_S ? TILE_HEIGHT : 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
|
||||||
|
{
|
||||||
|
uint z;
|
||||||
|
Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z);
|
||||||
|
|
||||||
|
return
|
||||||
|
(z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) > z + (slope & SLOPE_W ? TILE_HEIGHT : 0)) ||
|
||||||
|
(z_here + (slope_here & SLOPE_E ? TILE_HEIGHT : 0) > z + (slope & SLOPE_S ? TILE_HEIGHT : 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DrawFoundation(TileInfo *ti, uint f)
|
void DrawFoundation(TileInfo *ti, uint f)
|
||||||
{
|
{
|
||||||
uint32 sprite_base = SPR_SLOPES_BASE-14;
|
uint32 sprite_base = SPR_SLOPES_BASE-14;
|
||||||
|
Slope slope;
|
||||||
|
uint z;
|
||||||
|
|
||||||
TileInfo ti2;
|
slope = GetFoundationSlope(ti->tile, &z);
|
||||||
FindLandscapeHeight(&ti2, ti->x, ti->y - 1);
|
if (!HasFoundationNW(ti->tile, slope, z)) sprite_base += 22;
|
||||||
if (hasFoundation(&ti2, true)) sprite_base += 22; // foundation in NW direction
|
if (!HasFoundationNE(ti->tile, slope, z)) sprite_base += 44;
|
||||||
FindLandscapeHeight(&ti2, ti->x - 1, ti->y);
|
|
||||||
if (hasFoundation(&ti2, false)) sprite_base += 22 * 2; // foundation in NE direction
|
|
||||||
|
|
||||||
if (f < 15) {
|
if (f < 15) {
|
||||||
// leveled foundation
|
// leveled foundation
|
||||||
|
|
|
@ -1277,8 +1277,31 @@ static uint GetSlopeZ_TunnelBridge(const TileInfo* ti)
|
||||||
|
|
||||||
static uint GetSlopeTileh_TunnelBridge(const TileInfo* ti)
|
static uint GetSlopeTileh_TunnelBridge(const TileInfo* ti)
|
||||||
{
|
{
|
||||||
// not accurate, but good enough for slope graphics drawing
|
TileIndex tile = ti->tile;
|
||||||
return 0;
|
Slope tileh = ti->tileh;
|
||||||
|
uint f;
|
||||||
|
|
||||||
|
if (IsTunnel(tile)) {
|
||||||
|
return tileh;
|
||||||
|
} else {
|
||||||
|
if (IsBridgeRamp(tile)) {
|
||||||
|
if (HASBIT(BRIDGE_NO_FOUNDATION, tileh)) {
|
||||||
|
return tileh;
|
||||||
|
} else {
|
||||||
|
f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (IsTransportUnderBridge(tile)) {
|
||||||
|
f = _bridge_foundations[GetBridgeAxis(tile)][tileh];
|
||||||
|
} else {
|
||||||
|
return tileh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f == 0) return tileh;
|
||||||
|
if (f < 15) return SLOPE_FLAT;
|
||||||
|
return _inclined_tileh[f - 15];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue