mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-24 06:59:10 +00:00
(svn r3777) Add some functions to handle tunnels
This commit is contained in:
11
rail_cmd.c
11
rail_cmd.c
@@ -10,6 +10,7 @@
|
||||
#include "table/strings.h"
|
||||
#include "map.h"
|
||||
#include "tile.h"
|
||||
#include "tunnel_map.h"
|
||||
#include "vehicle.h"
|
||||
#include "viewport.h"
|
||||
#include "command.h"
|
||||
@@ -1627,21 +1628,21 @@ static bool SignalVehicleCheck(TileIndex tile, uint track)
|
||||
if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 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 = GB(_m[tile].m5, 0, 2);
|
||||
FindLengthOfTunnelResult flotr;
|
||||
flotr = FindLengthOfTunnel(tile, direction);
|
||||
TileIndex end = GetOtherTunnelEnd(tile);
|
||||
DiagDirection direction = GetTunnelDirection(tile);
|
||||
|
||||
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;
|
||||
if (VehicleFromPos(end, &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)) {
|
||||
for (; tile != end; tile += TileOffsByDir(direction)) {
|
||||
if (VehicleFromPos(tile, &dest, SignalVehicleCheckProc) != NULL)
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user