diff options
author | matthijs <matthijs@openttd.org> | 2005-05-15 13:48:23 +0000 |
---|---|---|
committer | matthijs <matthijs@openttd.org> | 2005-05-15 13:48:23 +0000 |
commit | 2151550631fc489c3cceb4437b7d42dace5fa15d (patch) | |
tree | af3b40f114be5be9fbdc4aa0ddb3bfa613cf9ec3 | |
parent | 14996be3ef4815c4f3caf7ff5d5cf69ecd83ae58 (diff) | |
download | openttd-2151550631fc489c3cceb4437b7d42dace5fa15d.tar.xz |
(svn r2320) - Fix: [ 1185176 ] Train in tunnel is not properly detected by signal code (Hackykid)
-rw-r--r-- | rail_cmd.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/rail_cmd.c b/rail_cmd.c index 2cbc7e148..28c5e5a4d 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -1619,7 +1619,35 @@ bool SignalVehicleCheck(TileIndex tile, uint track) dest.tile = tile; dest.track = track; - return VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL; + if (GetTileType(tile)==MP_TUNNELBRIDGE && ((_map5[tile] & 0xF0)==0)) { + // It is a tunnel we're checking, we need to do some special stuff + // because VehicleFromPos will not find the vihicle otherwise + byte direction = _map5[tile] & 3; + FindLengthOfTunnelResult flotr; + flotr = FindLengthOfTunnel(tile, direction); + dest.track = 1 << (direction & 1); // get the trackbit the vehicle would have if it has not entered the tunnel yet (ie is still visible) + + // check for a vehicle with that trackdir on the start tile of the tunnel + if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) + return true; + + // check for a vehicle with that trackdir on the end tile of the tunnel + if (VehicleFromPos(flotr.tile, &dest, SignalVehicleCheckProc) != NULL) + return true; + + // now check all tiles from start to end for a "hidden" vehicle + // NOTE: the hashes for tiles may overlap, so this could maybe be optimised a bit by not checking every tile? + dest.track = 0x40; // trackbit for vehicles "hidden" inside a tunnel + for (; tile != flotr.tile; tile += TileOffsByDir(direction)) { + if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL) + return true; + } + + // no vehicle found + return false; + } else { + return VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL; + }; } static void SetSignalsAfterProc(TrackPathFinder *tpf) |