diff --git a/pathfind.c b/pathfind.c index 4e65c3d991..799e23d58c 100644 --- a/pathfind.c +++ b/pathfind.c @@ -699,6 +699,10 @@ start_at: // We are not driving into the tunnel, or it is an invalid tunnel continue; } + if (!HASBIT(tpf->railtypes, GetRailType(tile))) { + bits = 0; + break; + } flotr = FindLengthOfTunnel(tile, direction); si.cur_length += flotr.length * DIAG_FACTOR; tile = flotr.tile; @@ -730,6 +734,12 @@ 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, GetRailTypeCrossing(tile))) || + !HASBIT(tpf->railtypes, GetRailType(tile))) { + bits = 0; + break; + } + /////////////////// // If we reach here, the tile has exactly one track. // tile - index to a tile that is not rail tile, but still straight (with optional signals)