src/pathfind.cpp
branchNewGRF_ports
changeset 6719 4cc327ad39d5
parent 6678 6353b8865d42
child 6720 35756db7e577
equal deleted inserted replaced
6718:5a8b295aa345 6719:4cc327ad39d5
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "bridge_map.h"
     7 #include "bridge_map.h"
     8 #include "station_map.h"
     8 #include "station_map.h"
     9 #include "depot.h"
     9 #include "depot.h"
    10 #include "functions.h"
    10 #include "functions.h"
       
    11 #include "landscape.h"
    11 #include "map.h"
    12 #include "map.h"
    12 #include "tile.h"
    13 #include "tile.h"
    13 #include "pathfind.h"
    14 #include "pathfind.h"
    14 #include "rail.h"
    15 #include "rail.h"
    15 #include "debug.h"
    16 #include "debug.h"
   150 	tile = TILE_MASK(tile + TileOffsByDiagDir(direction));
   151 	tile = TILE_MASK(tile + TileOffsByDiagDir(direction));
   151 
   152 
   152 	if (++tpf->rd.cur_length > 50)
   153 	if (++tpf->rd.cur_length > 50)
   153 		return;
   154 		return;
   154 
   155 
   155 	bits = GetTileTrackStatus(tile, tpf->tracktype);
   156 	bits = GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type);
   156 	bits = (byte)((bits | (bits >> 8)) & _bits_mask[direction]);
   157 	bits = (byte)((bits | (bits >> 8)) & _bits_mask[direction]);
   157 	if (bits == 0)
   158 	if (bits == 0)
   158 		return;
   159 		return;
   159 
   160 
   160 	assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY());
   161 	assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY());
   319 		}
   320 		}
   320 	}
   321 	}
   321 
   322 
   322 	tpf->rd.cur_length++;
   323 	tpf->rd.cur_length++;
   323 
   324 
   324 	bits = GetTileTrackStatus(tile, tpf->tracktype);
   325 	bits = GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type);
   325 
   326 
   326 	if ((byte)bits != tpf->var2) {
   327 	if ((byte)bits != tpf->var2) {
   327 		bits &= _tpfmode1_and[direction];
   328 		bits &= _tpfmode1_and[direction];
   328 		bits = bits | (bits >> 8);
   329 		bits = bits | (bits >> 8);
   329 	}
   330 	}
   360 		return;
   361 		return;
   361 
   362 
   362 	direction = ReverseDiagDir(direction);
   363 	direction = ReverseDiagDir(direction);
   363 	tile += TileOffsByDiagDir(direction);
   364 	tile += TileOffsByDiagDir(direction);
   364 
   365 
   365 	bits = GetTileTrackStatus(tile, tpf->tracktype);
   366 	bits = GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type);
   366 	bits |= (bits >> 8);
   367 	bits |= (bits >> 8);
   367 
   368 
   368 	if ( (byte)bits != tpf->var2) {
   369 	if ( (byte)bits != tpf->var2) {
   369 		bits &= _bits_mask[direction];
   370 		bits &= _bits_mask[direction];
   370 	}
   371 	}
   385 		}
   386 		}
   386 		tpf->rd = rd;
   387 		tpf->rd = rd;
   387 	} while (bits != 0);
   388 	} while (bits != 0);
   388 }
   389 }
   389 
   390 
   390 void FollowTrack(TileIndex tile, uint16 flags, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
   391 void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
   391 {
   392 {
   392 	TrackPathFinder tpf;
   393 	TrackPathFinder tpf;
   393 
   394 
   394 	assert(direction < 4);
   395 	assert(direction < 4);
   395 
   396 
   408 	tpf.disable_tile_hash = HASBIT(flags, 12);  // 0x1000
   409 	tpf.disable_tile_hash = HASBIT(flags, 12);  // 0x1000
   409 	tpf.hasbit_13         = HASBIT(flags, 13);  // 0x2000
   410 	tpf.hasbit_13         = HASBIT(flags, 13);  // 0x2000
   410 
   411 
   411 
   412 
   412 	tpf.tracktype = (TransportType)(flags & 0xFF);
   413 	tpf.tracktype = (TransportType)(flags & 0xFF);
       
   414 	tpf.sub_type = sub_type;
   413 
   415 
   414 	if (HASBIT(flags, 11)) {
   416 	if (HASBIT(flags, 11)) {
   415 		tpf.rd.pft_var6 = 0xFF;
   417 		tpf.rd.pft_var6 = 0xFF;
   416 		tpf.enum_proc(tile, data, INVALID_TRACKDIR, 0, 0);
   418 		tpf.enum_proc(tile, data, INVALID_TRACKDIR, 0, 0);
   417 		TPFMode2(&tpf, tile, direction);
   419 		TPFMode2(&tpf, tile, direction);
   780 			/* Not a regular rail tile?
   782 			/* Not a regular rail tile?
   781 			 * Then we can't use the code below, but revert to more general code. */
   783 			 * Then we can't use the code below, but revert to more general code. */
   782 			if (!IsTileType(tile, MP_RAILWAY) || !IsPlainRailTile(tile)) {
   784 			if (!IsTileType(tile, MP_RAILWAY) || !IsPlainRailTile(tile)) {
   783 				/* We found a tile which is not a normal railway tile.
   785 				/* We found a tile which is not a normal railway tile.
   784 				 * Determine which tracks that exist on this tile. */
   786 				 * Determine which tracks that exist on this tile. */
   785 				uint32 ts = GetTileTrackStatus(tile, TRANSPORT_RAIL) & _tpfmode1_and[direction];
   787 				uint32 ts = GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & _tpfmode1_and[direction];
   786 				bits = TrackdirBitsToTrackBits((TrackdirBits)(ts & TRACKDIR_BIT_MASK));
   788 				bits = TrackdirBitsToTrackBits((TrackdirBits)(ts & TRACKDIR_BIT_MASK));
   787 
   789 
   788 				/* Check that the tile contains exactly one track */
   790 				/* Check that the tile contains exactly one track */
   789 				if (bits == 0 || KILL_FIRST_BIT(bits) != 0) break;
   791 				if (bits == 0 || KILL_FIRST_BIT(bits) != 0) break;
   790 
   792 
   818 				bits = TRACK_BIT_NONE;
   820 				bits = TRACK_BIT_NONE;
   819 				break;
   821 				break;
   820 			}
   822 			}
   821 
   823 
   822 			/* If we reach here, the tile has exactly one track, and this
   824 			/* If we reach here, the tile has exactly one track, and this
   823 			 track is reachable => Rail segment continues */
   825 			 track is reachable = > Rail segment continues */
   824 
   826 
   825 			track = _new_trackdir[FIND_FIRST_BIT(bits)][direction];
   827 			track = _new_trackdir[FIND_FIRST_BIT(bits)][direction];
   826 			assert(track != INVALID_TRACKDIR);
   828 			assert(track != INVALID_TRACKDIR);
   827 
   829 
   828 			si.cur_length += _length_of_track[track];
   830 			si.cur_length += _length_of_track[track];