Loading

Paste #psmpbbtt2

  1. static const Depot *FindClosestShipDepot(const Vehicle *v, uint max_distance)
  2. {
  3.     /* Find the closest depot */
  4.     const Depot *depot;
  5.     const Depot *best_depot = NULL;
  6.     /* If we don't have a maximum distance, i.e. distance = 0,
  7.      * we want to find any depot so the best distance of no
  8.      * depot must be more than any correct distance. On the
  9.      * other hand if we have set a maximum distance, any depot
  10.      * further away than max_distance can safely be ignored. */
  11.     uint best_dist = max_distance == 0 ? UINT_MAX : max_distance + 1;
  12.  
  13.     FOR_ALL_DEPOTS(depot) {
  14.         TileIndex tile = depot->xy;
  15.         if (IsShipDepotTile(tile) && IsTileOwner(tile, v->owner)) {
  16.             uint dist = DistanceManhattan(tile, v->tile);
  17.             if (dist < best_dist) {
  18.                 best_dist = dist;
  19.                 best_depot = depot;
  20.             }
  21.         }
  22.     }
  23.  
  24.     return best_depot;
  25. }

Comments