Loading

opf find depot

  1. FindDepotData OPFShipFindNearestDepot(const Ship *v, int max_distance) // todo
  2. {
  3.     Trackdir trackdir = v->GetVehicleTrackdir();
  4.     DiagDirection enterdir = TrackdirToExitdir(trackdir);  
  5.     TrackBits tracks = TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(enterdir));
  6.  
  7.     FindDepotData fdd;
  8.     Depot *depot;
  9.     uint best_dist = max_distance == 0 ? UINT_MAX : max_distance;
  10.     FOR_ALL_DEPOTS(depot) {
  11.         TileIndex depottile = depot->xy;
  12.         if (IsShipDepotTile(depottile) && IsTileOwner(depottile, v->owner)) {
  13.             uint dist = DistanceManhattan(v->tile, depottile);
  14.             if (dist <= best_dist) {
  15.                 bool path_found;
  16.                 Track track = OPFShipChooseTrack(v, v->tile, enterdir, tracks, path_found, depottile);
  17.                 if (track != INVALID_TRACK) {
  18.                     fdd.best_length = dist;
  19.                     fdd.tile = depottile;
  20.                     break;
  21.                 }
  22.             }
  23.         }
  24.     }
  25.  
  26.     return fdd;
  27. }

Comments