summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2011-01-16 18:18:45 +0000
committersmatz <smatz@openttd.org>2011-01-16 18:18:45 +0000
commit92b90d877e5fcf1438d54cadcaf6ef0dfd43689f (patch)
tree1435e0933a3286ad14d357ac84836c6c84d8cb63
parent82346d4608929752e23ca87f79c80aba60ec8f9a (diff)
downloadopenttd-92b90d877e5fcf1438d54cadcaf6ef0dfd43689f.tar.xz
(svn r21824) -Codechange: don't call GetSlopeZ() when the ground vehicle is on a flat tile
-rw-r--r--src/ground_vehicle.hpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp
index 2922fff1d..ccb3ae81e 100644
--- a/src/ground_vehicle.hpp
+++ b/src/ground_vehicle.hpp
@@ -112,9 +112,9 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
FORCEINLINE byte UpdateInclination(bool new_tile, bool turned)
{
byte old_z = this->z_pos;
- this->z_pos = GetSlopeZ(this->x_pos, this->y_pos);
if (new_tile) {
+ this->z_pos = GetSlopeZ(this->x_pos, this->y_pos);
ClrBit(this->gv_flags, GVF_GOINGUP_BIT);
ClrBit(this->gv_flags, GVF_GOINGDOWN_BIT);
@@ -132,6 +132,18 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
SetBit(this->gv_flags, (middle_z > old_z) ? GVF_GOINGUP_BIT : GVF_GOINGDOWN_BIT);
}
}
+ } else {
+ /* Flat tile, tile with two opposing corners raised and tile with 3 corners
+ * raised can never have sloped track ... */
+ static const uint32 never_sloped = 1 << SLOPE_FLAT | 1 << SLOPE_EW | 1 << SLOPE_NS | 1 << SLOPE_NWS | 1 << SLOPE_WSE | 1 << SLOPE_SEN | 1 << SLOPE_ENW;
+ /* ... unless it's a bridge head. */
+ if (IsTileType(this->tile, MP_TUNNELBRIDGE) || // the following check would be true for tunnels anyway
+ (T::From(this)->TileMayHaveSlopedTrack() && !HasBit(never_sloped, GetTileSlope(this->tile, NULL)))) {
+ this->z_pos = GetSlopeZ(this->x_pos, this->y_pos);
+ } else {
+ /* Verify that assumption. */
+ assert(this->z_pos == GetSlopeZ(this->x_pos, this->y_pos));
+ }
}
this->UpdateViewport(true, turned);