Codechange: refactor FindClosestDepot to not use pointers, but return a struct

This commit is contained in:
Rubidium
2023-01-03 22:33:09 +01:00
committed by rubidium42
parent b3907b1359
commit 375a5b8e3f
12 changed files with 69 additions and 82 deletions

View File

@@ -220,6 +220,23 @@ struct RefitDesc {
cargo(cargo), capacity(capacity), remaining(remaining) {}
};
/**
* Structure to return information about the closest depot location,
* and whether it could be found.
*/
struct ClosestDepot {
TileIndex location;
DestinationID destination; ///< The DestinationID as used for orders.
bool reverse;
bool found;
ClosestDepot() :
location(INVALID_TILE), destination(0), reverse(false), found(false) {}
ClosestDepot(TileIndex location, DestinationID destination, bool reverse = false) :
location(location), destination(destination), reverse(reverse), found(true) {}
};
/** %Vehicle data structure. */
struct Vehicle : VehiclePool::PoolItem<&_vehicle_pool>, BaseVehicle, BaseConsist {
private:
@@ -771,12 +788,9 @@ public:
/**
* Find the closest depot for this vehicle and tell us the location,
* DestinationID and whether we should reverse.
* @param location where do we go to?
* @param destination what hangar do we go to?
* @param reverse should the vehicle be reversed?
* @return true if a depot could be found.
* @return A structure with information about the closest depot, if found.
*/
virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) { return false; }
virtual ClosestDepot FindClosestDepot() { return {}; }
virtual void SetDestTile(TileIndex tile) { this->dest_tile = tile; }