rail_cmd.c
changeset 3154 a8fffb204d0e
parent 3153 301c1d71122b
child 3157 40de8616c04c
equal deleted inserted replaced
3153:301c1d71122b 3154:a8fffb204d0e
     8 #include "road_map.h"
     8 #include "road_map.h"
     9 #include "table/sprites.h"
     9 #include "table/sprites.h"
    10 #include "table/strings.h"
    10 #include "table/strings.h"
    11 #include "map.h"
    11 #include "map.h"
    12 #include "tile.h"
    12 #include "tile.h"
       
    13 #include "tunnel_map.h"
    13 #include "vehicle.h"
    14 #include "vehicle.h"
    14 #include "viewport.h"
    15 #include "viewport.h"
    15 #include "command.h"
    16 #include "command.h"
    16 #include "pathfind.h"
    17 #include "pathfind.h"
    17 #include "engine.h"
    18 #include "engine.h"
  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