pathfind.c
changeset 3153 e83501906eae
parent 3132 4ecd7f40fc76
child 3154 6ab0cb6b7ab3
equal deleted inserted replaced
3152:00aa2d4cf39e 3153:e83501906eae
   125 	0,
   125 	0,
   126 	0x5,
   126 	0x5,
   127 	0x2A,
   127 	0x2A,
   128 };
   128 };
   129 
   129 
   130 static void TPFMode2(TrackPathFinder *tpf, TileIndex tile, int direction)
   130 static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
   131 {
   131 {
   132 	uint bits;
   132 	uint bits;
   133 	int i;
   133 	int i;
   134 	RememberData rd;
   134 	RememberData rd;
   135 	int owner = -1;
   135 	int owner = -1;
   273 32,40,40,42,40,44,44,46,
   273 32,40,40,42,40,44,44,46,
   274 32,48,48,50,48,52,52,54,
   274 32,48,48,50,48,52,52,54,
   275 48,56,56,58,56,60,60,62,
   275 48,56,56,58,56,60,60,62,
   276 };
   276 };
   277 
   277 
   278 static void TPFMode1(TrackPathFinder *tpf, TileIndex tile, uint direction)
   278 static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
   279 {
   279 {
   280 	uint bits;
   280 	uint bits;
   281 	int i;
   281 	int i;
   282 	RememberData rd;
   282 	RememberData rd;
   283 	TileIndex tile_org = tile;
   283 	TileIndex tile_org = tile;
   341 	 * not reach it (for example, when two lines merge */
   341 	 * not reach it (for example, when two lines merge */
   342 	if (tpf->hasbit_13)
   342 	if (tpf->hasbit_13)
   343 		return;
   343 		return;
   344 
   344 
   345 	tile = tile_org;
   345 	tile = tile_org;
   346 	direction ^= 2;
   346 	direction = ReverseDiagDir(direction);
   347 
   347 
   348 	bits = GetTileTrackStatus(tile, tpf->tracktype);
   348 	bits = GetTileTrackStatus(tile, tpf->tracktype);
   349 	bits |= (bits >> 8);
   349 	bits |= (bits >> 8);
   350 
   350 
   351 	if ( (byte)bits != tpf->var2) {
   351 	if ( (byte)bits != tpf->var2) {
   368 		}
   368 		}
   369 		tpf->rd = rd;
   369 		tpf->rd = rd;
   370 	} while (bits != 0);
   370 	} while (bits != 0);
   371 }
   371 }
   372 
   372 
   373 void FollowTrack(TileIndex tile, uint16 flags, byte direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
   373 void FollowTrack(TileIndex tile, uint16 flags, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
   374 {
   374 {
   375 	TrackPathFinder tpf;
   375 	TrackPathFinder tpf;
   376 
   376 
   377 	assert(direction < 4);
   377 	assert(direction < 4);
   378 
   378 
   504 }
   504 }
   505 
   505 
   506 // mark a tile as visited and store the length of the path.
   506 // mark a tile as visited and store the length of the path.
   507 // if we already had a better path to this tile, return false.
   507 // if we already had a better path to this tile, return false.
   508 // otherwise return true.
   508 // otherwise return true.
   509 static bool NtpVisit(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint length)
   509 static bool NtpVisit(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection dir, uint length)
   510 {
   510 {
   511 	uint hash,head;
   511 	uint hash,head;
   512 	HashLink *link, *new_link;
   512 	HashLink *link, *new_link;
   513 
   513 
   514 	assert(length < 16384-1);
   514 	assert(length < 16384-1);
   669 
   669 
   670 // new more optimized pathfinder for trains...
   670 // new more optimized pathfinder for trains...
   671 // Tile is the tile the train is at.
   671 // Tile is the tile the train is at.
   672 // direction is the tile the train is moving towards.
   672 // direction is the tile the train is moving towards.
   673 
   673 
   674 static void NTPEnum(NewTrackPathFinder *tpf, TileIndex tile, uint direction)
   674 static void NTPEnum(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
   675 {
   675 {
   676 	TrackBits bits, allbits;
   676 	TrackBits bits, allbits;
   677 	uint track;
   677 	uint track;
   678 	TileIndex tile_org;
   678 	TileIndex tile_org;
   679 	StackedItem si;
   679 	StackedItem si;
   910 	}
   910 	}
   911 }
   911 }
   912 
   912 
   913 
   913 
   914 // new pathfinder for trains. better and faster.
   914 // new pathfinder for trains. better and faster.
   915 void NewTrainPathfind(TileIndex tile, TileIndex dest, byte direction, NTPEnumProc *enum_proc, void *data)
   915 void NewTrainPathfind(TileIndex tile, TileIndex dest, DiagDirection direction, NTPEnumProc* enum_proc, void* data)
   916 {
   916 {
   917 	NewTrackPathFinder tpf;
   917 	NewTrackPathFinder tpf;
   918 
   918 
   919 	tpf.dest = dest;
   919 	tpf.dest = dest;
   920 	tpf.userdata = data;
   920 	tpf.userdata = data;