vehicle.c
changeset 1752 cdbfb2f23e72
parent 1735 e38d9d16bc03
child 1757 b179d50241dc
--- a/vehicle.c	Mon May 02 22:13:20 2005 +0000
+++ b/vehicle.c	Mon May 02 23:59:11 2005 +0000
@@ -15,6 +15,8 @@
 #include "engine.h"
 #include "sound.h"
 #include "debug.h"
+#include "npf.h"
+#include "vehicle_gui.h"
 
 #define INVALID_COORD (-0x8000)
 #define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0)))
@@ -1707,6 +1709,35 @@
 	return (dir+((dirdiff&7)<5?1:-1)) & 7;
 }
 
+byte GetVehicleTrackdir(const Vehicle* v)
+{
+	switch(v->type)
+	{
+		case VEH_Train:
+			if (v->u.rail.track == 0x80)
+				return 0xFF; /* Train in depot */
+			else if (v->u.rail.track == 0x40)
+				/* train in tunnel, so just use his direction and assume a diagonal track */
+				return _dir_to_diag_trackdir[(v->direction>>1)&3];
+			else
+				return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.rail.track)][v->direction];
+		case VEH_Ship:
+			if (v->u.ship.state == 0x80)
+				return 0xFF; /* Ship in depot */
+			else
+				return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.ship.state)][v->direction];
+		case VEH_Road:
+			if (v->u.road.state == 254)
+				return 0xFF; /* Road vehicle in depot */
+			else
+				return _dir_to_diag_trackdir[(v->direction>>1)&3];
+		case VEH_Aircraft:
+		case VEH_Special:
+		case VEH_Disaster:
+		default:
+			return 0xFF;
+	}
+}
 /* Return value has bit 0x2 set, when the vehicle enters a station. Then,
  * result << 8 contains the id of the station entered. If the return value has
  * bit 0x8 set, the vehicle could not and did not enter the tile. Are there
@@ -2076,5 +2107,3 @@
 const ChunkHandler _veh_chunk_handlers[] = {
 	{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST},
 };
-
-