7 | FindDepotData fdd;
| 12 | /* Argument values for FindShipTrack below, for the reversed ship direction */
|
---|
| | 13 | DiagDirection enterdir_rev = ReverseDiagDir(enterdir);
|
---|
| | 14 | TileIndex tile_rev = v->tile;
|
---|
| | 15 | TrackBits tracks_rev = TrackStatusToTrackBits(GetTileTrackStatus(tile_rev, TRANSPORT_WATER, 0)) & DiagdirReachesTracks(enterdir_rev) & TrackdirBitsToTrackBits(TrackdirToTrackdirBits(trackdir));
|
---|
| | 16 |
|
---|
| | 17 | Track track; // initialized, but unused
|
---|
| | 18 |
|
---|
| | 19 | if (max_distance == 0) max_distance = INT_MAX;
|
---|
| | 20 | uint best_length = UINT_MAX;
|
---|
| | 21 |
|
---|
13 | uint dist = DistanceManhattan(v->tile, depottile);
| 26 | uint distdepot = DistanceManhattan(v->tile, depottile);
|
---|
14 | if (dist <= best_dist) {
| 27 | if (distdepot <= (uint)max_distance && distdepot < best_length) {
|
---|
15 | bool path_found;
| 28 |
|
---|
16 | Track track = OPFShipChooseTrack(v, v->tile, enterdir, tracks, path_found, depottile);
| 29 | /* Let's find the length it would be if we would reverse first */
|
---|
17 | if (track != INVALID_TRACK) {
| 30 | uint length_rev = UINT_MAX;
|
---|
18 | fdd.best_length = dist;
| 31 | if (tracks_rev != 0) {
|
---|
19 | fdd.tile = depottile;
| 32 | length_rev = FindShipTrack(v, tile_rev, enterdir_rev, tracks_rev, tile, &track, depottile); //
|
---|
20 | break;
| 33 | if (length_rev != UINT_MAX) length_rev++; // penalty for reversing
|
---|
| | 34 | }
|
---|
| | 35 |
|
---|
| | 36 | /* And if we would not reverse? */
|
---|
| | 37 | uint length = FindShipTrack(v, tile, enterdir, tracks, 0, &track, depottile);
|
---|
| | 38 |
|
---|
| | 39 | /* Get the shortest length */
|
---|
| | 40 | uint min_length = minu(length_rev, length);
|
---|
| | 41 |
|
---|
| | 42 | if (min_length < best_length) {
|
---|
| | 43 | best_length = min_length;
|
---|
| | 44 |
|
---|
| | 45 | fdd.tile = depottile; // tile location of ship depot
|
---|
| | 46 | fdd.best_length = distdepot; // distance manhattan from ship to depot
|
---|
| | 47 | fdd.reverse = !(length <= length_rev);
|
---|