src/pathfind.cpp
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
equal deleted inserted replaced
10991:d8811e327d12 10994:cd9968b6f96b
   110 	return true;
   110 	return true;
   111 }
   111 }
   112 
   112 
   113 static void TPFModeShip(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
   113 static void TPFModeShip(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
   114 {
   114 {
   115 	RememberData rd;
       
   116 
       
   117 	assert(tpf->tracktype == TRANSPORT_WATER);
   115 	assert(tpf->tracktype == TRANSPORT_WATER);
       
   116 
       
   117 	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
       
   118 		/* wrong track type */
       
   119 		if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) return;
       
   120 
       
   121 		DiagDirection dir = GetTunnelBridgeDirection(tile);
       
   122 		/* entering tunnel / bridge? */
       
   123 		if (dir == direction) {
       
   124 			TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
       
   125 
       
   126 			tpf->rd.cur_length += GetTunnelBridgeLength(tile, endtile) + 1;
       
   127 
       
   128 			TPFSetTileBit(tpf, tile, 14);
       
   129 			TPFSetTileBit(tpf, endtile, 14);
       
   130 
       
   131 			tile = endtile;
       
   132 		} else {
       
   133 			/* leaving tunnel / bridge? */
       
   134 			if (ReverseDiagDir(dir) != direction) return;
       
   135 		}
       
   136 	}
   118 
   137 
   119 	/* This addition will sometimes overflow by a single tile.
   138 	/* This addition will sometimes overflow by a single tile.
   120 	 * The use of TILE_MASK here makes sure that we still point at a valid
   139 	 * The use of TILE_MASK here makes sure that we still point at a valid
   121 	 * tile, and then this tile will be in the sentinel row/col, so GetTileTrackStatus will fail. */
   140 	 * tile, and then this tile will be in the sentinel row/col, so GetTileTrackStatus will fail. */
   122 	tile = TILE_MASK(tile + TileOffsByDiagDir(direction));
   141 	tile = TILE_MASK(tile + TileOffsByDiagDir(direction));
   131 
   150 
   132 	bool only_one_track = true;
   151 	bool only_one_track = true;
   133 	do {
   152 	do {
   134 		Track track = RemoveFirstTrack(&bits);
   153 		Track track = RemoveFirstTrack(&bits);
   135 		if (bits != TRACK_BIT_NONE) only_one_track = false;
   154 		if (bits != TRACK_BIT_NONE) only_one_track = false;
   136 		rd = tpf->rd;
   155 		RememberData rd = tpf->rd;
   137 
   156 
   138 		/* Change direction 4 times only */
   157 		/* Change direction 4 times only */
   139 		if (!only_one_track && track != tpf->rd.last_choosen_track) {
   158 		if (!only_one_track && track != tpf->rd.last_choosen_track) {
   140 			if (++tpf->rd.depth > 4) {
   159 			if (++tpf->rd.depth > 4) {
   141 				tpf->rd = rd;
   160 				tpf->rd = rd;