Merge branch 'master' into jgrpp
# Conflicts: # src/elrail.cpp # src/ground_vehicle.hpp # src/landscape.cpp # src/saveload/afterload.cpp # src/saveload/saveload.h # src/tile_cmd.h # src/town_cmd.cpp # src/tunnelbridge_cmd.cpp
This commit is contained in:
@@ -2563,7 +2563,7 @@ void DrawBridgeMiddle(const TileInfo *ti)
|
||||
}
|
||||
|
||||
|
||||
static int GetSlopePixelZ_TunnelBridge(TileIndex tile, uint x, uint y)
|
||||
static int GetSlopePixelZ_TunnelBridge(TileIndex tile, uint x, uint y, bool ground_vehicle)
|
||||
{
|
||||
int z;
|
||||
Slope tileh = GetTilePixelSlope(tile, &z);
|
||||
@@ -2572,34 +2572,27 @@ static int GetSlopePixelZ_TunnelBridge(TileIndex tile, uint x, uint y)
|
||||
y &= 0xF;
|
||||
|
||||
if (IsTunnel(tile)) {
|
||||
uint pos = (DiagDirToAxis(GetTunnelBridgeDirection(tile)) == AXIS_X ? y : x);
|
||||
|
||||
/* In the tunnel entrance? */
|
||||
if (5 <= pos && pos <= 10) return z;
|
||||
if (ground_vehicle) return z;
|
||||
} else { // IsBridge(tile)
|
||||
if (IsCustomBridgeHeadTile(tile)) {
|
||||
return z + TILE_HEIGHT + (IsSteepSlope(tileh) ? TILE_HEIGHT : 0);
|
||||
}
|
||||
|
||||
DiagDirection dir = GetTunnelBridgeDirection(tile);
|
||||
uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
|
||||
|
||||
z += ApplyPixelFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh);
|
||||
|
||||
/* On the bridge ramp? */
|
||||
if (5 <= pos && pos <= 10) {
|
||||
int delta;
|
||||
|
||||
if (ground_vehicle) {
|
||||
if (tileh != SLOPE_FLAT) return z + TILE_HEIGHT;
|
||||
|
||||
switch (dir) {
|
||||
default: NOT_REACHED();
|
||||
case DIAGDIR_NE: delta = (TILE_SIZE - 1 - x) / 2; break;
|
||||
case DIAGDIR_SE: delta = y / 2; break;
|
||||
case DIAGDIR_SW: delta = x / 2; break;
|
||||
case DIAGDIR_NW: delta = (TILE_SIZE - 1 - y) / 2; break;
|
||||
case DIAGDIR_NE: tileh = SLOPE_NE; break;
|
||||
case DIAGDIR_SE: tileh = SLOPE_SE; break;
|
||||
case DIAGDIR_SW: tileh = SLOPE_SW; break;
|
||||
case DIAGDIR_NW: tileh = SLOPE_NW; break;
|
||||
}
|
||||
return z + 1 + delta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3063,6 +3056,29 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to prepare the ground vehicle when entering a bridge. This get called
|
||||
* when entering the bridge, at the last frame of travel on the bridge head.
|
||||
* Our calling function gets called before UpdateInclination/UpdateZPosition,
|
||||
* which normally controls the Z-coordinate. However, in the wormhole of the
|
||||
* bridge the vehicle is in a strange state so UpdateInclination does not get
|
||||
* called for the wormhole of the bridge and as such the going up/down bits
|
||||
* would remain set. As such, this function clears those. In doing so, the call
|
||||
* to UpdateInclination will not update the Z-coordinate, so that has to be
|
||||
* done here as well.
|
||||
* @param gv The ground vehicle entering the bridge.
|
||||
*/
|
||||
template <typename T>
|
||||
static void PrepareToEnterBridge(T *gv)
|
||||
{
|
||||
if (HasBit(gv->gv_flags, GVF_GOINGUP_BIT)) {
|
||||
gv->z_pos++;
|
||||
ClrBit(gv->gv_flags, GVF_GOINGUP_BIT);
|
||||
} else {
|
||||
ClrBit(gv->gv_flags, GVF_GOINGDOWN_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frame when the 'enter tunnel' sound should be played. This is the second
|
||||
* frame on a tile, so the sound is played shortly after entering the tunnel
|
||||
@@ -3098,7 +3114,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||
y += offset.y;
|
||||
}
|
||||
|
||||
int z = GetSlopePixelZ(x, y) - v->z_pos;
|
||||
int z = GetSlopePixelZ(x, y, true) - v->z_pos;
|
||||
|
||||
if (abs(z) > 2) return VETSB_CANNOT_ENTER;
|
||||
|
||||
@@ -3188,8 +3204,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||
Train *t = Train::From(v);
|
||||
t->track = TRACK_BIT_WORMHOLE;
|
||||
SetBit(t->First()->flags, VRF_CONSIST_SPEED_REDUCTION);
|
||||
ClrBit(t->gv_flags, GVF_GOINGUP_BIT);
|
||||
ClrBit(t->gv_flags, GVF_GOINGDOWN_BIT);
|
||||
PrepareToEnterBridge(t);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3205,9 +3220,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
|
||||
}
|
||||
rv->InvalidateImageCache();
|
||||
rv->state = RVSB_WORMHOLE;
|
||||
/* There are no slopes inside bridges / tunnels. */
|
||||
ClrBit(rv->gv_flags, GVF_GOINGUP_BIT);
|
||||
ClrBit(rv->gv_flags, GVF_GOINGDOWN_BIT);
|
||||
PrepareToEnterBridge(rv);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user