src/elrail.cpp
branchNewGRF_ports
changeset 6877 889301acc299
parent 6872 1c4a4a609f85
child 6878 7d1ff2f621c7
--- a/src/elrail.cpp	Sun Feb 03 01:34:21 2008 +0000
+++ b/src/elrail.cpp	Sun Feb 03 20:34:26 2008 +0000
@@ -64,6 +64,7 @@
 #include "tunnelbridge_map.h"
 #include "vehicle_func.h"
 #include "player_base.h"
+#include "tunnelbridge.h"
 
 #include "table/sprites.h"
 #include "table/elrail_data.h"
@@ -73,8 +74,11 @@
 	return (TLG)((HasBit(TileX(t), 0) << 1) + HasBit(TileY(t), 0));
 }
 
-/** Finds which Rail Bits are present on a given tile. For bridge tiles,
- * returns track bits under the bridge
+/**
+ * Finds which Electrified Rail Bits are present on a given tile.
+ * @param t tile to check
+ * @param override pointer to PCP override, can be NULL
+ * @return trackbits of tile if it is electrified
  */
 static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
 {
@@ -93,7 +97,7 @@
 
 		case MP_TUNNELBRIDGE:
 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
-			if (override != NULL && (IsTunnel(t) || DistanceMax(t, GetOtherBridgeEnd(t)) > 1)) {
+			if (override != NULL && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) {
 				*override = 1 << GetTunnelBridgeDirection(t);
 			}
 			return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
@@ -126,13 +130,7 @@
 		} else if (*tileh != SLOPE_FLAT) {
 			*tileh = SLOPE_FLAT;
 		} else {
-			switch (GetTunnelBridgeDirection(tile)) {
-				case DIAGDIR_NE: *tileh = SLOPE_NE; break;
-				case DIAGDIR_SE: *tileh = SLOPE_SE; break;
-				case DIAGDIR_SW: *tileh = SLOPE_SW; break;
-				case DIAGDIR_NW: *tileh = SLOPE_NW; break;
-				default: NOT_REACHED();
-			}
+			*tileh = InclinedSlope(GetTunnelBridgeDirection(tile));
 		}
 	}
 }
@@ -383,8 +381,8 @@
 	TileIndex end = GetSouthernBridgeEnd(ti->tile);
 	TileIndex start = GetOtherBridgeEnd(end);
 
-	uint length = GetBridgeLength(start, end);
-	uint num = DistanceMax(ti->tile, start);
+	uint length = GetTunnelBridgeLength(start, end);
+	uint num = GetTunnelBridgeLength(ti->tile, start) + 1;
 	uint height;
 
 	const SortableSpriteStruct *sss;
@@ -421,7 +419,7 @@
 	}
 
 	/* need a pylon on the southern end of the bridge */
-	if (DistanceMax(ti->tile, start) == length) {
+	if (GetTunnelBridgeLength(ti->tile, start) + 1 == length) {
 		DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE);
 		Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
 		if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
@@ -471,7 +469,6 @@
 
 int32 SettingsDisableElrail(int32 p1)
 {
-	EngineID e_id;
 	Vehicle *v;
 	Player *p;
 	bool disable = (p1 != 0);
@@ -481,8 +478,9 @@
 	const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC;
 
 	/* walk through all train engines */
-	for (e_id = 0; e_id < NUM_TRAIN_ENGINES; e_id++) {
-		RailVehicleInfo *rv_info = &_rail_vehicle_info[e_id];
+	EngineID eid;
+	FOR_ALL_ENGINEIDS_OF_TYPE(eid, VEH_TRAIN) {
+		RailVehicleInfo *rv_info = &_rail_vehicle_info[eid];
 		/* if it is an electric rail engine and its railtype is the wrong one */
 		if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) {
 			/* change it to the proper one */