# HG changeset patch # User KUDr # Date 1167693513 0 # Node ID 6975ccb4a7bdf72b078185b1c0e2a0aa1aad1129 # Parent f5c656cf0a0e5bb1b706c93fa8ad5985c876d78e (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero. diff -r f5c656cf0a0e -r 6975ccb4a7bd bridge_cmd.c --- a/bridge_cmd.c Mon Jan 01 20:13:03 2007 +0000 +++ b/bridge_cmd.c Mon Jan 01 23:18:33 2007 +0000 @@ -1017,28 +1017,39 @@ /* Get the vehicle out of the wormhole, the track will be chosen later by the pathfinder */ v->tile = tile; - v->u.rail.track = 0; + v->u.rail.track = TrackToTrackBits(TrackdirToTrack(DiagdirToDiagTrackdir(dir))); return 4; } return 0; } else { + TileIndex other_bridge_end_tile; + uint32 bridge_length; /* We are on the bridge head itself, possibly entering the bridge */ /* Vehicle will enter the bridge wormhole when it reaches the tile edge in the * direction of the bridge. */ TileIndexDiffC diff = TileIndexDiffCByDiagDir(dir); /* If vehicle didn't reach the edge we can return and try it next time */ if (((diff.x != 0 ? x : y) & 0x0F) != (diff.x + diff.y > 0 ? TILE_SIZE - 1 : 0)) return 0; - /* We will enter the bridge wormhole. Adjust the other coordinate to the middle of tile - * to allow train controller to select proper vehicle image */ - if (diff.x != 0) v->y_pos = y; else v->x_pos = x; + /* We will enter the bridge wormhole. */ - /* We're about to enter the bridge body, clear all up/down flags just in case */ - v->u.rail.track = 0x40; - v->direction = DiagDirToDir(dir); - CLRBIT(v->u.rail.flags, VRF_GOINGUP); - CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); - return 4; + other_bridge_end_tile = GetOtherBridgeEnd(tile); + bridge_length = GetBridgeLength(tile, other_bridge_end_tile); + if (bridge_length > 0) { + /* Non-zero bridge length. Adjust the other coordinate to the middle of tile + * to allow train controller to select proper vehicle image */ + if (diff.x != 0) v->y_pos = y; else v->x_pos = x; + v->direction = DiagDirToDir(dir); + /* We're about to enter the bridge body, clear all up/down flags just in case */ + v->u.rail.track = 0x40; + v->direction = DiagDirToDir(dir); + CLRBIT(v->u.rail.flags, VRF_GOINGUP); + CLRBIT(v->u.rail.flags, VRF_GOINGDOWN); + return 4; + } else { + /* Zero bridge length. Pretend that nothing extra happened. Custom bridge heads should act as normal tracks. */ + ; + } } return 0; }