src/elrail.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6877 889301acc299
--- a/src/elrail.cpp	Mon Dec 03 23:39:38 2007 +0000
+++ b/src/elrail.cpp	Tue Jan 22 21:00:30 2008 +0000
@@ -48,24 +48,25 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "station_map.h"
-#include "tile.h"
-#include "viewport.h"
-#include "functions.h" /* We should REALLY get rid of this goddamn file, as it is butt-ugly */
-#include "variables.h" /* ... same here */
+#include "viewport_func.h"
+#include "settings_type.h"
 #include "landscape.h"
-#include "rail.h"
+#include "rail_type.h"
 #include "debug.h"
 #include "tunnel_map.h"
 #include "road_map.h"
 #include "bridge_map.h"
 #include "bridge.h"
 #include "rail_map.h"
+#include "train.h"
+#include "rail_gui.h"
+#include "transparency.h"
+#include "tunnelbridge_map.h"
+#include "vehicle_func.h"
+#include "player_base.h"
+
 #include "table/sprites.h"
 #include "table/elrail_data.h"
-#include "vehicle.h"
-#include "train.h"
-#include "gui.h"
-#include "transparency.h"
 
 static inline TLG GetTLG(TileIndex t)
 {
@@ -91,17 +92,11 @@
 			break;
 
 		case MP_TUNNELBRIDGE:
-			if (IsTunnel(t)) {
-				if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
-				if (override != NULL) *override = 1 << GetTunnelDirection(t);
-				return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(t)));
-			} else {
-				if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
-				if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) {
-					*override = 1 << GetBridgeRampDirection(t);
-				}
-				return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(t)));
+			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
+			if (override != NULL && (IsTunnel(t) || DistanceMax(t, GetOtherBridgeEnd(t)) > 1)) {
+				*override = 1 << GetTunnelBridgeDirection(t);
 			}
+			return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
 
 		case MP_ROAD:
 			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE;
@@ -131,7 +126,7 @@
 		} else if (*tileh != SLOPE_FLAT) {
 			*tileh = SLOPE_FLAT;
 		} else {
-			switch (GetBridgeRampDirection(tile)) {
+			switch (GetTunnelBridgeDirection(tile)) {
 				case DIAGDIR_NE: *tileh = SLOPE_NE; break;
 				case DIAGDIR_SE: *tileh = SLOPE_SE; break;
 				case DIAGDIR_SW: *tileh = SLOPE_SW; break;
@@ -188,7 +183,7 @@
 
 	if ((GetRailType(ti->tile) != RAILTYPE_ELECTRIC) || _patches.disable_elrails) return;
 
-	DiagDirection dir = GetTunnelDirection(ti->tile);
+	DiagDirection dir = GetTunnelBridgeDirection(ti->tile);
 
 	const SortableSpriteStruct *sss = &CatenarySpriteData_Tunnel[dir];
 	const int *BB_data = _tunnel_wire_BB[dir];
@@ -247,7 +242,7 @@
 		 * existing foundataions, so we do have to do that manually later on.*/
 		tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL);
 		trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL);
-		if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
+		if (IsTunnelTile(neighbour) && i != GetTunnelBridgeDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
 
 		/* If the neighboured tile does not smoothly connect to the current tile (because of a foundation),
 		 * we have to draw all pillars on the current tile. */
@@ -264,7 +259,7 @@
 			/* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */
 			if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
 			    IsBridgeTile(neighbour) &&
-			    GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)) {
+			    GetTunnelBridgeDirection(neighbour) == ReverseDiagDir(i)) {
 				continue;
 			}
 
@@ -291,7 +286,7 @@
 		/* Read the foundataions if they are present, and adjust the tileh */
 		if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
 		if (IsBridgeTile(neighbour)) {
-			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour)));
+			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetTunnelBridgeDirection(neighbour)));
 		}
 
 		ApplyFoundationToSlope(foundation, &tileh[TS_NEIGHBOUR]);
@@ -443,7 +438,7 @@
 	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
 		TileIndex head = GetNorthernBridgeEnd(ti->tile);
 
-		if (GetBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
+		if (GetTunnelBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
 			DrawCatenaryOnBridge(ti);
 		}
 	}
@@ -502,7 +497,7 @@
 			if (v->type == VEH_TRAIN && v->u.rail.railtype == RAILTYPE_ELECTRIC) {
 				/* this railroad vehicle is now compatible only with elrail,
 				*  so add there also normal rail compatibility */
-				v->u.rail.compatible_railtypes |= (1 << RAILTYPE_RAIL);
+				v->u.rail.compatible_railtypes |= RAILTYPES_RAIL;
 				v->u.rail.railtype = RAILTYPE_RAIL;
 				SetBit(v->u.rail.flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL);
 			}