337 } while (bits != 0); |
337 } while (bits != 0); |
338 } |
338 } |
339 |
339 |
340 void FollowTrack(uint tile, uint16 flags, byte direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) |
340 void FollowTrack(uint tile, uint16 flags, byte direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) |
341 { |
341 { |
342 TrackPathFinder *tpf = alloca(sizeof(TrackPathFinder)); |
342 TrackPathFinder tpf; |
343 |
343 |
344 assert(direction < 4); |
344 assert(direction < 4); |
345 |
345 |
346 /* initialize path finder variables */ |
346 /* initialize path finder variables */ |
347 tpf->userdata = data; |
347 tpf.userdata = data; |
348 tpf->enum_proc = enum_proc; |
348 tpf.enum_proc = enum_proc; |
349 tpf->new_link = tpf->links; |
349 tpf.new_link = tpf.links; |
350 tpf->num_links_left = 0x400; |
350 tpf.num_links_left = lengthof(tpf.links); |
351 |
351 |
352 tpf->rd.cur_length = 0; |
352 tpf.rd.cur_length = 0; |
353 tpf->rd.depth = 0; |
353 tpf.rd.depth = 0; |
354 tpf->rd.pft_var6 = 0; |
354 tpf.rd.pft_var6 = 0; |
355 |
355 |
356 tpf->var2 = HASBIT(flags, 15) ? 0x43 : 0xFF; /* 0x8000 */ |
356 tpf.var2 = HASBIT(flags, 15) ? 0x43 : 0xFF; /* 0x8000 */ |
357 |
357 |
358 tpf->disable_tile_hash = HASBIT(flags, 12) != 0; /* 0x1000 */ |
358 tpf.disable_tile_hash = HASBIT(flags, 12) != 0; /* 0x1000 */ |
359 tpf->hasbit_13 = HASBIT(flags, 13) != 0; /* 0x2000 */ |
359 tpf.hasbit_13 = HASBIT(flags, 13) != 0; /* 0x2000 */ |
360 |
360 |
361 |
361 |
362 tpf->tracktype = (byte)flags; |
362 tpf.tracktype = (byte)flags; |
363 |
363 |
364 if (HASBIT(flags, 11)) { |
364 if (HASBIT(flags, 11)) { |
365 tpf->rd.pft_var6 = 0xFF; |
365 tpf.rd.pft_var6 = 0xFF; |
366 tpf->enum_proc(tile, data, 0, 0, 0); |
366 tpf.enum_proc(tile, data, 0, 0, 0); |
367 TPFMode2(tpf, tile, direction); |
367 TPFMode2(&tpf, tile, direction); |
368 } else { |
368 } else { |
369 /* clear the hash_heads */ |
369 /* clear the hash_heads */ |
370 memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); |
370 memset(tpf.hash_head, 0, sizeof(tpf.hash_head)); |
371 TPFMode1(tpf, tile, direction); |
371 TPFMode1(&tpf, tile, direction); |
372 } |
372 } |
373 |
373 |
374 if (after_proc != NULL) |
374 if (after_proc != NULL) |
375 after_proc(tpf); |
375 after_proc(&tpf); |
376 } |
376 } |
377 |
377 |
378 typedef struct { |
378 typedef struct { |
379 TileIndex tile; |
379 TileIndex tile; |
380 uint16 cur_length; |
380 uint16 cur_length; |
711 void NewTrainPathfind(uint tile, byte direction, TPFEnumProc *enum_proc, void *data, byte *cache) |
711 void NewTrainPathfind(uint tile, byte direction, TPFEnumProc *enum_proc, void *data, byte *cache) |
712 { |
712 { |
713 if (!_patches.new_pathfinding) { |
713 if (!_patches.new_pathfinding) { |
714 FollowTrack(tile, 0x3000 | TRANSPORT_RAIL, direction, enum_proc, NULL, data); |
714 FollowTrack(tile, 0x3000 | TRANSPORT_RAIL, direction, enum_proc, NULL, data); |
715 } else { |
715 } else { |
716 NewTrackPathFinder *tpf; |
716 NewTrackPathFinder tpf; |
717 |
717 tpf.userdata = data; |
718 tpf = alloca(sizeof(NewTrackPathFinder)); |
718 tpf.enum_proc = enum_proc; |
719 tpf->userdata = data; |
719 tpf.tracktype = 0; |
720 tpf->enum_proc = enum_proc; |
720 tpf.maxlength = _patches.pf_maxlength; |
721 tpf->tracktype = 0; |
721 tpf.nstack = 0; |
722 tpf->maxlength = _patches.pf_maxlength; |
722 tpf.new_link = tpf.links; |
723 tpf->nstack = 0; |
723 tpf.num_links_left = lengthof(tpf.links); |
724 tpf->new_link = tpf->links; |
724 memset(tpf.hash_head, 0, sizeof(tpf.hash_head)); |
725 tpf->num_links_left = 0x400; |
725 |
726 memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); |
726 NTPEnum(&tpf, tile, direction); |
727 |
727 } |
728 NTPEnum(tpf, tile, direction); |
728 } |
729 } |
729 |
730 } |
|
731 |
|