(svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole custombridgeheads
authorKUDr
Mon, 01 Jan 2007 18:26:10 +0000
branchcustombridgeheads
changeset 5624 7901de192beb
parent 5623 ef2a8a524a95
child 5625 ff6ea2cb5620
(svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
bridge_cmd.c
--- a/bridge_cmd.c	Mon Jan 01 16:31:13 2007 +0000
+++ b/bridge_cmd.c	Mon Jan 01 18:26:10 2007 +0000
@@ -1011,28 +1011,24 @@
 
 	dir = GetBridgeRampDirection(tile);
 
-	/* We are entering the bridge head from the bridge itself */
 	if (v->direction == DiagDirToDir(ReverseDiagDir(dir))) {
-		v->tile = tile;
+		/* We are entering the bridge head from the bridge itself */
 		if (v->u.rail.track == 0x40) {
 			/* Get the vehicle out of the wormhole, the track will be chosen later
 			   by the pathfinder */
+			v->tile = tile;
 			v->u.rail.track = 0;
 			return 4;
 		}
 		return 0;
 
-	/* We are on the bridge head itself */
 	} else {
-		switch (dir) {
-			default: NOT_REACHED();
-			/* Should any of these ifs be true, we're not near the edge which
-			   faces the bridge body. In that case, do nothing */
-			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;
-		}
+		/* We are on the bridge head itself, possibly entering the bridge */
+		/* Vehicle will enter the bridge wormhole when it reaches the tile edge in the
+		 * direction of the bridge. */
+		TileIndexDiffC diff = TileIndexDiffCByDiagDir(dir);
+		/* If vehicle didn't reach the edge we can return and try it next time */
+		if (((diff.x != 0 ? x : y) & 0x0F) != (diff.x + diff.y > 0 ? TILE_SIZE - 1 : 0)) return 0;
 
 		/* We're about to enter the bridge body, clear all up/down flags just in case */
 		v->u.rail.track = 0x40;