12 #include "../../stdafx.h"
13 #include "../../tunnelbridge_map.h"
14 #include "../../tunnelbridge.h"
15 #include "../../ship.h"
16 #include "../../core/random_func.hpp"
18 #include "../../safeguards.h"
23 Track last_choosen_track;
38 if (tile == pfs->dest_coords) {
39 pfs->best_bird_dist = 0;
41 pfs->best_length =
minu(pfs->best_length, length);
46 if (tile != pfs->skiptile) {
61 if (dir == direction) {
78 if (++tpf->rd.cur_length > 50)
return;
85 bool only_one_track =
true;
92 if (!only_one_track && track != tpf->rd.last_choosen_track) {
93 if (++tpf->rd.depth > 4) {
97 tpf->rd.last_choosen_track = track;
102 if (!ShipTrackFollower(tile, tpf, tpf->rd.cur_length)) {
115 tpf->rd.cur_length = 0;
119 ShipTrackFollower(tile, tpf, 0);
120 TPFModeShip(tpf, tile, direction);
139 uint best_bird_dist = 0;
140 uint best_length = 0;
144 pfs.skiptile = skiptile;
151 pfs.best_bird_dist = UINT_MAX;
152 pfs.best_length = UINT_MAX;
154 OPFShipFollowTrack(tile, _ship_search_directions[i][dir], &pfs);
157 if (pfs.best_bird_dist != 0) {
159 if (pfs.best_bird_dist > best_bird_dist)
goto bad;
160 if (pfs.best_bird_dist < best_bird_dist)
goto good;
162 if (pfs.best_length > best_length)
goto bad;
163 if (pfs.best_length < best_length)
goto good;
168 uint r =
GB(Random(), 0, 8);
169 if (_pick_shiptrack_table[i] == ship_dir) r += 80;
170 if (_pick_shiptrack_table[best_track] == ship_dir) r -= 80;
171 if (r <= 127)
goto bad;
175 best_bird_dist = pfs.best_bird_dist;
176 best_length = pfs.best_length;
182 return best_bird_dist;
201 uint distr = UINT_MAX;
203 distr = FindShipTrack(v, tile2,
ReverseDiagDir(enterdir), b, tile, &track);
204 if (distr != UINT_MAX) distr++;
208 uint dist = FindShipTrack(v, tile, enterdir, tracks, 0, &track);
212 if (dist <= distr)
return track;