1625 * on in there. This 'workaround' can be removed once the maprewrite is done. |
1626 * on in there. This 'workaround' can be removed once the maprewrite is done. |
1626 */ |
1627 */ |
1627 if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) { |
1628 if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) { |
1628 // It is a tunnel we're checking, we need to do some special stuff |
1629 // It is a tunnel we're checking, we need to do some special stuff |
1629 // because VehicleFromPos will not find the vihicle otherwise |
1630 // because VehicleFromPos will not find the vihicle otherwise |
1630 byte direction = GB(_m[tile].m5, 0, 2); |
1631 TileIndex end = GetOtherTunnelEnd(tile); |
1631 FindLengthOfTunnelResult flotr; |
1632 DiagDirection direction = GetTunnelDirection(tile); |
1632 flotr = FindLengthOfTunnel(tile, direction); |
1633 |
1633 dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible) |
1634 dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible) |
1634 |
1635 |
1635 // check for a vehicle with that trackdir on the start tile of the tunnel |
1636 // check for a vehicle with that trackdir on the start tile of the tunnel |
1636 if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) return true; |
1637 if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) return true; |
1637 |
1638 |
1638 // check for a vehicle with that trackdir on the end tile of the tunnel |
1639 // check for a vehicle with that trackdir on the end tile of the tunnel |
1639 if (VehicleFromPos(flotr.tile, &dest, SignalVehicleCheckProc) != NULL) return true; |
1640 if (VehicleFromPos(end, &dest, SignalVehicleCheckProc) != NULL) return true; |
1640 |
1641 |
1641 // now check all tiles from start to end for a "hidden" vehicle |
1642 // now check all tiles from start to end for a "hidden" vehicle |
1642 // NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile? |
1643 // NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile? |
1643 dest.track = 0x40; // trackbit for vehicles "hidden" inside a tunnel |
1644 dest.track = 0x40; // trackbit for vehicles "hidden" inside a tunnel |
1644 for (; tile != flotr.tile; tile += TileOffsByDir(direction)) { |
1645 for (; tile != end; tile += TileOffsByDir(direction)) { |
1645 if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) |
1646 if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) |
1646 return true; |
1647 return true; |
1647 } |
1648 } |
1648 |
1649 |
1649 // no vehicle found |
1650 // no vehicle found |