1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-21 05:29:11 +00:00

(svn r10373) [0.5] -Backport from trunk (r10306, r10311, r10317, r10339, r10344):

- Fix: Acceleration for trains on slopes is not calculated properly [FS#786] (r10317, r10344)
- Fix: Rail could be destroyed when building tunnels (r10306)
This commit is contained in:
rubidium
2007-06-28 14:11:00 +00:00
parent a6c7987a43
commit cd32a5f18c
3 changed files with 27 additions and 16 deletions

View File

@@ -2748,26 +2748,28 @@ static void TrainEnterStation(Vehicle *v, StationID station)
static byte AfterSetTrainPos(Vehicle *v, bool new_tile)
{
byte new_z, old_z;
// need this hint so it returns the right z coordinate on bridges.
_get_z_hint = v->z_pos;
new_z = GetSlopeZ(v->x_pos, v->y_pos);
_get_z_hint = 0;
old_z = v->z_pos;
v->z_pos = new_z;
byte old_z = v->z_pos;
v->z_pos = GetSlopeZ(v->x_pos, v->y_pos);
if (new_tile) {
CLRBIT(v->u.rail.flags, VRF_GOINGUP);
CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
if (new_z != old_z) {
TileIndex tile = TileVirtXY(v->x_pos, v->y_pos);
if (v->u.rail.track == TRACK_BIT_X || v->u.rail.track == TRACK_BIT_Y) {
/* Any track that isn't TRACK_BIT_X or TRACK_BIT_Y cannot be sloped.
* To check whether the current tile is sloped, and in which
* direction it is sloped, we get the 'z' at the center of
* the tile (middle_z) and the edge of the tile (old_z),
* which we then can compare. */
static const int HALF_TILE_SIZE = TILE_SIZE / 2;
static const int INV_TILE_SIZE_MASK = ~(TILE_SIZE - 1);
// XXX workaround, whole UP/DOWN detection needs overhaul
if (!IsTunnelTile(tile)) {
SETBIT(v->u.rail.flags, (new_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN);
byte middle_z = GetSlopeZ((v->x_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE, (v->y_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE);
/* For some reason tunnel tiles are always given as sloped :(
* But they are not sloped... */
if (middle_z != v->z_pos && !IsTunnelTile(TileVirtXY(v->x_pos, v->y_pos))) {
SETBIT(v->u.rail.flags, (middle_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN);
}
}
}