diff --git a/pathfind.c b/pathfind.c index 9a71b2bdec..c6f88720ed 100644 --- a/pathfind.c +++ b/pathfind.c @@ -672,6 +672,13 @@ static const byte _length_of_track[16] = { 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 @@ start_at: // 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; + } } ///////////////////