src/town_cmd.cpp
changeset 8343 471bee030391
parent 8341 a7fef35fe38b
child 8345 6caa3fdb972c
equal deleted inserted replaced
8342:e34ebde612e0 8343:471bee030391
   905 	const Slope slope = GetTileSlope(tile, NULL);
   905 	const Slope slope = GetTileSlope(tile, NULL);
   906 	if (slope == SLOPE_FLAT) return false; // no slope, no bridge
   906 	if (slope == SLOPE_FLAT) return false; // no slope, no bridge
   907 
   907 
   908 	/* Make sure the direction is compatible with the slope.
   908 	/* Make sure the direction is compatible with the slope.
   909 	 * If any of the following bits match, the slope is forbidden for
   909 	 * If any of the following bits match, the slope is forbidden for
   910 	 * that diagdir. Total of 5 slopes per direction.
   910 	 *  that diagdir. This means 5 non-steep slopes, and 3 steep-slopes
       
   911 	 *  per diagdir.
   911 	 * 0 -> 0b1100
   912 	 * 0 -> 0b1100
   912 	 * 1 -> 0b0110
   913 	 * 1 -> 0b0110
   913 	 * 2 -> 0b0011
   914 	 * 2 -> 0b0011
   914 	 * 3 -> 0b1001
   915 	 * 3 -> 0b1001
   915 	 * 0xCC is 0b11001100, so we just shift it right with
   916 	 * 0xCC is 0b11001100, so we just shift it right with
   916 	 * the direction to get the forbidden slope mask. */
   917 	 * the direction to get the forbidden slope mask. */
   917 	if (HASBITS(slope & 0x0F, 0xCC >> bridge_dir)) return false;
   918 	if (HASBITS(slope & 0x0F, 0xCC >> bridge_dir)) return false;
   918 
   919 
       
   920 	/* Assure that the bridge is connectable to the start side */
       
   921 	if (!(GetTownRoadBits(TileAddByDiagDir(tile, ReverseDiagDir(bridge_dir))) & DiagDirToRoadBits(bridge_dir))) return false;
       
   922 
   919 	/* We are in the right direction */
   923 	/* We are in the right direction */
   920 	uint32 bridge_length = 0;     // This value stores the length of the possible bridge
   924 	uint8 bridge_length = 0;     // This value stores the length of the possible bridge
   921 	TileIndex bridge_tile = tile; // Used to store the other waterside
   925 	TileIndex bridge_tile = tile; // Used to store the other waterside
   922 
   926 
   923 	do {
   927 	do {
   924 		if (bridge_length++ >= 11) {
   928 		if (bridge_length++ >= 11) {
   925 			/* Max 11 tile long bridges */
   929 			/* Max 11 tile long bridges */
   926 			return false;
   930 			return false;
   927 		}
   931 		}
   928 		bridge_tile = TILE_MASK(bridge_tile + TileOffsByDiagDir(bridge_dir));
   932 		bridge_tile = TileAddByDiagDir(bridge_tile, bridge_dir);
   929 	} while (IsWaterTile(bridge_tile));
   933 	} while (IsWaterTile(bridge_tile));
   930 
   934 
   931 	/* no water tiles in between? */
   935 	/* no water tiles in between? */
   932 	if (bridge_length == 1) return false;
   936 	if (bridge_length == 1) return false;
   933 
   937