(svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this custombridgeheads
authorcelestar
Sat, 30 Dec 2006 17:35:08 +0000
branchcustombridgeheads
changeset 5608 a0768f524071
parent 5607 5169e3e15ce9
child 5609 ec38986d2c8e
(svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
bridge_cmd.c
--- a/bridge_cmd.c	Sat Dec 30 17:16:07 2006 +0000
+++ b/bridge_cmd.c	Sat Dec 30 17:35:08 2006 +0000
@@ -944,7 +944,45 @@
 }
 
 
-static uint32 VehicleEnter_Bridge(Vehicle *v, TileIndex tile, int x, int y)
+static uint32 VehicleEnter_Street_Bridge(Vehicle *v, TileIndex tile, int x, int y)
+{
+	int z = GetSlopeZ(x, y) - v->z_pos;
+
+	DiagDirection dir;
+
+	if (myabs(z) > 2) return 8;
+
+	if (v->type == VEH_Road) {
+		/* modify speed of vehicle */
+		uint16 spd = _bridge[GetBridgeType(tile)].speed * 2;
+		if (v->cur_speed > spd) v->cur_speed = spd;
+	}
+
+	dir = GetBridgeRampDirection(tile);
+	if (DirToDiagDir(v->direction) == dir) {
+		switch (dir) {
+			default: NOT_REACHED();
+			case DIAGDIR_NE: if ((x & 0xF) != 0)             return 0; break;
+			case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break;
+			case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
+			case DIAGDIR_NW: if ((y & 0xF) != 0)             return 0; break;
+		}
+		v->u.road.state = 0xFF;
+		return 4;
+	} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
+		v->tile = tile;
+		if (v->u.road.state == 0xFF) {
+			static const byte road_exit_bridge_state[4] = {8, 9, 0, 1};
+			v->u.road.state = road_exit_bridge_state[dir];
+			v->u.road.frame = 0;
+			return 4;
+		}
+		return 0;
+	}
+	return 0;
+}
+
+static uint32 VehicleEnter_Railway_Bridge(Vehicle *v, TileIndex tile, int x, int y)
 {
 	int z = GetSlopeZ(x, y) - v->z_pos;
 
@@ -959,11 +997,9 @@
 
 	if (myabs(z) > 2) return 8;
 
-	if (v->type == VEH_Road || (v->type == VEH_Train && IsFrontEngine(v))) {
+	if (IsFrontEngine(v)) {
 		/* modify speed of vehicle */
 		uint16 spd = _bridge[GetBridgeType(tile)].speed;
-
-		if (v->type == VEH_Road) spd *= 2;
 		if (v->cur_speed > spd) v->cur_speed = spd;
 	}
 
@@ -977,34 +1013,30 @@
 			case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
 			case DIAGDIR_NW: if ((y & 0xF) != 0)             return 0; break;
 		}
-		if (v->type == VEH_Train) {
-			v->u.rail.track = 0x40;
-			CLRBIT(v->u.rail.flags, VRF_GOINGUP);
-			CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
-		} else {
-			v->u.road.state = 0xFF;
-		}
+		v->u.rail.track = 0x40;
+		CLRBIT(v->u.rail.flags, VRF_GOINGUP);
+		CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
 		return 4;
 	} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
 		v->tile = tile;
-		if (v->type == VEH_Train) {
-			if (v->u.rail.track == 0x40) {
-				v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2);
-				return 4;
-			}
-		} else {
-			if (v->u.road.state == 0xFF) {
-				static const byte road_exit_bridge_state[4] = {8, 9, 0, 1};
-				v->u.road.state = road_exit_bridge_state[dir];
-				v->u.road.frame = 0;
-				return 4;
-			}
+		if (v->u.rail.track == 0x40) {
+			v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2);
+			return 4;
 		}
 		return 0;
 	}
 	return 0;
 }
 
+static uint32 VehicleEnter_Bridge(Vehicle *v, TileIndex tile, int x, int y)
+{
+	if (v->type == VEH_Train) return VehicleEnter_Railway_Bridge(v, tile, x, y);
+
+	if (v->type == VEH_Road) return VehicleEnter_Street_Bridge(v, tile, x, y);
+
+	NOT_REACHED();
+}
+
 const TileTypeProcs _tile_type_bridge_procs = {
 	DrawTile_Bridge,           /* draw_tile_proc */
 	GetSlopeZ_Bridge,          /* get_slope_z_proc */