--- a/pathfind.c Sun Jun 04 17:25:00 2006 +0000
+++ b/pathfind.c Sun Jun 04 21:40:21 2006 +0000
@@ -672,6 +672,13 @@
DIAG_FACTOR,DIAG_FACTOR,STR_FACTOR,STR_FACTOR,STR_FACTOR,STR_FACTOR,0,0
};
+static inline bool IsBridgeMiddle(TileIndex t) {return HASBIT(_m[t].m5, 6);}
+static inline uint GetBridgeAxis(TileIndex t) {return GB(_m[t].m5, 0, 1);}
+static inline uint DiagDirToAxis(DiagDirection d) {return (d & 1);}
+static inline bool IsBridge(TileIndex t) {return HASBIT(_m[t].m5, 7);}
+static inline bool IsBridgeTile(TileIndex t) {return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);}
+static inline RailType GetRailTypeCrossing(TileIndex t) {return (RailType)GB(_m[t].m4, 0, 4);}
+
// new more optimized pathfinder for trains...
// Tile is the tile the train is at.
// direction is the tile the train is moving towards.
@@ -766,9 +773,13 @@
// Check that the tile contains exactly one track
if (bits == 0 || KILL_FIRST_BIT(bits) != 0) break;
- if (IsTileType(tile, MP_STREET) ? !HASBIT(tpf->railtypes, GB(_m[tile].m4, 0, 4)) : !HASBIT(tpf->railtypes, GetRailType(tile))) {
- bits = 0;
- break;
+ /* Check the rail type only if the train is *NOT* on top of
+ * a bridge. */
+ if (!(IsBridgeTile(tile) && IsBridgeMiddle(tile) && GetBridgeAxis(tile) == DiagDirToAxis(direction))) {
+ if (IsTileType(tile, MP_STREET) ? !HASBIT(tpf->railtypes, GetRailTypeCrossing(tile)) : !HASBIT(tpf->railtypes, GetRailType(tile))) {
+ bits = 0;
+ break;
+ }
}
///////////////////