(svn r3831) Add and use GetRailDepotDirection()
authortron
Sun, 12 Mar 2006 16:13:16 +0000
changeset 3185 c0ef161f700f
parent 3184 7405329343ce
child 3186 5798593c2d95
(svn r3831) Add and use GetRailDepotDirection()
ai/default/default.c
depot.h
rail_cmd.c
rail_map.h
train_cmd.c
vehicle.c
--- a/ai/default/default.c	Sun Mar 12 15:04:03 2006 +0000
+++ b/ai/default/default.c	Sun Mar 12 16:13:16 2006 +0000
@@ -4,6 +4,7 @@
 #include "../../openttd.h"
 #include "../../functions.h"
 #include "../../map.h"
+#include "../../rail_map.h"
 #include "../../road_map.h"
 #include "../../tile.h"
 #include "../../player.h"
@@ -3625,8 +3626,9 @@
 		} else {
 			static const byte _depot_bits[] = {0x19,0x16,0x25,0x2A};
 
-			m5 &= 3;
-			if (GetRailTrackStatus(tile + TileOffsByDir(m5)) & _depot_bits[m5])
+			DiagDirection dir = GetRailDepotDirection(tile);
+
+			if (GetRailTrackStatus(tile + TileOffsByDir(dir)) & _depot_bits[dir])
 				return;
 
 			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
--- a/depot.h	Sun Mar 12 15:04:03 2006 +0000
+++ b/depot.h	Sun Mar 12 16:13:16 2006 +0000
@@ -8,6 +8,7 @@
 
 #include "direction.h"
 #include "pool.h"
+#include "rail_map.h"
 #include "road_map.h"
 #include "tile.h"
 #include "variables.h"
@@ -103,7 +104,7 @@
 
 	switch (type)
 	{
-		case TRANSPORT_RAIL: return (DiagDirection)GB(_m[tile].m5, 0, 2);
+		case TRANSPORT_RAIL: return GetRailDepotDirection(tile);
 		case TRANSPORT_ROAD: return GetRoadDepotDirection(tile);
 		case TRANSPORT_WATER:
 			/* Water is stubborn, it stores the directions in a different order. */
--- a/rail_cmd.c	Sun Mar 12 15:04:03 2006 +0000
+++ b/rail_cmd.c	Sun Mar 12 16:13:16 2006 +0000
@@ -1027,7 +1027,7 @@
 		return CMD_ERROR;
 
 	if (flags & DC_EXEC) {
-		Track track = TrackdirToTrack(DiagdirToDiagTrackdir(GetDepotDirection(tile, TRANSPORT_RAIL)));
+		Track track = TrackdirToTrack(DiagdirToDiagTrackdir(GetRailDepotDirection(tile)));
 
 		DoDeleteDepot(tile);
 		SetSignalsOnBothDir(tile, track);
@@ -2085,7 +2085,7 @@
 	if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0;
 
 	/* depot direction */
-	dir = GetDepotDirection(tile, TRANSPORT_RAIL);
+	dir = GetRailDepotDirection(tile);
 
 	/* calculate the point where the following wagon should be activated */
 	/* this depends on the length of the current vehicle */
--- a/rail_map.h	Sun Mar 12 15:04:03 2006 +0000
+++ b/rail_map.h	Sun Mar 12 16:13:16 2006 +0000
@@ -8,6 +8,12 @@
 #include "waypoint.h"
 
 
+static inline DiagDirection GetRailDepotDirection(TileIndex t)
+{
+	return (DiagDirection)GB(_m[t].m5, 0, 2);
+}
+
+
 static inline TrackBits GetRailWaypointBits(TileIndex t)
 {
 	return _m[t].m5 & RAIL_WAYPOINT_TRACK_MASK ? TRACK_BIT_Y : TRACK_BIT_X;
--- a/train_cmd.c	Sun Mar 12 15:04:03 2006 +0000
+++ b/train_cmd.c	Sun Mar 12 16:13:16 2006 +0000
@@ -540,7 +540,7 @@
 
 			v->engine_type = engine;
 
-			dir = GB(_m[tile].m5, 0, 2);
+			dir = GetRailDepotDirection(tile);
 
 			v->direction = DiagDirToDir(dir);
 			v->tile = tile;
@@ -699,7 +699,7 @@
 
 			v->unitnumber = unit_num;
 
-			dir = GB(_m[tile].m5, 0, 2);
+			dir = GetRailDepotDirection(tile);
 
 			v->direction = DiagDirToDir(dir);
 			v->tile = tile;
@@ -3167,7 +3167,7 @@
 		if (x + 4 > 15 &&
 				(!CheckCompatibleRail(v, tile) ||
 				(IsTileDepotType(tile, TRANSPORT_RAIL) &&
-				GetDepotDirection(tile, TRANSPORT_RAIL) == dir))) {
+				GetRailDepotDirection(tile) == dir))) {
 			v->cur_speed = 0;
 			ReverseTrainDirection(v);
 			return false;
@@ -3287,7 +3287,7 @@
 
 void TrainEnterDepot(Vehicle *v, TileIndex tile)
 {
-	SetSignalsOnBothDir(tile, _depot_track_ind[GB(_m[tile].m5, 0, 2)]);
+	SetSignalsOnBothDir(tile, _depot_track_ind[GetRailDepotDirection(tile)]);
 
 	if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v);
 
--- a/vehicle.c	Sun Mar 12 15:04:03 2006 +0000
+++ b/vehicle.c	Sun Mar 12 16:13:16 2006 +0000
@@ -1960,7 +1960,7 @@
 	switch (v->type) {
 		case VEH_Train:
 			if (v->u.rail.track == 0x80) /* We'll assume the train is facing outwards */
-				return DiagdirToDiagTrackdir(GetDepotDirection(v->tile, TRANSPORT_RAIL)); /* Train in depot */
+				return DiagdirToDiagTrackdir(GetRailDepotDirection(v->tile)); /* Train in depot */
 
 			if (v->u.rail.track == 0x40) /* train in tunnel, so just use his direction and assume a diagonal track */
 				return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));