diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/aircraft.h | 1 | ||||
-rw-r--r-- | src/aircraft_cmd.cpp | 19 | ||||
-rw-r--r-- | src/roadveh.h | 9 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 12 | ||||
-rw-r--r-- | src/ship.h | 1 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 12 | ||||
-rw-r--r-- | src/train.h | 1 | ||||
-rw-r--r-- | src/train_cmd.cpp | 12 | ||||
-rw-r--r-- | src/vehicle_base.h | 10 |
9 files changed, 73 insertions, 4 deletions
diff --git a/src/aircraft.h b/src/aircraft.h index 8662f947b..50611803c 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -127,6 +127,7 @@ struct Aircraft : public Vehicle { void Tick(); void OnNewDay(); TileIndex GetOrderStationLocation(StationID station); + bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); }; #endif /* AIRCRAFT_H */ diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 83d452b12..0fc9b3a3a 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -546,6 +546,25 @@ CommandCost CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 return CommandCost(); } +bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) +{ + const Station *st = GetStation(this->u.air.targetairport); + /* If the station is not a valid airport or if it has no hangars */ + if (!st->IsValid() || st->airport_tile == 0 || st->Airport()->nof_depots == 0) { + /* the aircraft has to search for a hangar on its own */ + StationID station = FindNearestHangar(this); + + if (station == INVALID_STATION) return false; + + st = GetStation(station); + } + + if (location != NULL) *location = st->xy; + if (destination != NULL) *destination = st->index; + + return true; +} + /** Send an aircraft to the hangar. * @param tile unused * @param flags for command type diff --git a/src/roadveh.h b/src/roadveh.h index ac121d042..9159a8784 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -47,6 +47,10 @@ static inline bool RoadVehHasArticPart(const Vehicle *v) void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2); +byte GetRoadVehLength(const Vehicle *v); + +void RoadVehUpdateCache(Vehicle *v); + /** * This class 'wraps' Vehicle; you do not actually instantiate this class. @@ -77,10 +81,7 @@ struct RoadVehicle : public Vehicle { void Tick(); void OnNewDay(); TileIndex GetOrderStationLocation(StationID station); + bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); }; -byte GetRoadVehLength(const Vehicle *v); - -void RoadVehUpdateCache(Vehicle *v); - #endif /* ROADVEH_H */ diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index a26180837..3c90018be 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -446,6 +446,18 @@ static const Depot* FindClosestRoadDepot(const Vehicle* v) return NULL; /* Target not found */ } +bool RoadVehicle::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) +{ + const Depot *depot = FindClosestRoadDepot(this); + + if (depot == NULL) return false; + + if (location != NULL) *location = depot->xy; + if (destination != NULL) *destination = depot->index; + + return true; +} + /** Send a road vehicle to the depot. * @param tile unused * @param flags operation to perform diff --git a/src/ship.h b/src/ship.h index 50f42611b..b0a0400ba 100644 --- a/src/ship.h +++ b/src/ship.h @@ -43,6 +43,7 @@ struct Ship: public Vehicle { void Tick(); void OnNewDay(); TileIndex GetOrderStationLocation(StationID station); + bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); }; #endif /* SHIP_H */ diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 4f5b956d9..bcd04025f 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -912,6 +912,18 @@ CommandCost CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) return CommandCost(); } +bool Ship::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) +{ + const Depot *depot = FindClosestShipDepot(this); + + if (depot == NULL) return false; + + if (location != NULL) *location = depot->xy; + if (destination != NULL) *destination = depot->index; + + return true; +} + /** Send a ship to the depot. * @param tile unused * @param flags type of operation diff --git a/src/train.h b/src/train.h index c6023ab37..6aa2ad763 100644 --- a/src/train.h +++ b/src/train.h @@ -305,6 +305,7 @@ struct Train : public Vehicle { void Tick(); void OnNewDay(); TileIndex GetOrderStationLocation(StationID station); + bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse); }; #endif /* TRAIN_H */ diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 72a0e1784..3813178d5 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2084,6 +2084,18 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v, int max_distance) return tfdd; } +bool Train::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) +{ + TrainFindDepotData tfdd = FindClosestTrainDepot(this, 0); + if (tfdd.best_length == (uint)-1) return false; + + if (location != NULL) *location = tfdd.tile; + if (destination != NULL) *destination = GetDepotByTile(tfdd.tile)->index; + if (reverse != NULL) *reverse = tfdd.reverse; + + return true; +} + /** Send a train to a depot * @param tile unused * @param flags type of operation diff --git a/src/vehicle_base.h b/src/vehicle_base.h index bd57e99c1..ac415fa64 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -512,6 +512,16 @@ public: * @return the location (tile) to aim for. */ virtual TileIndex GetOrderStationLocation(StationID station) { return INVALID_TILE; } + + /** + * 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. + */ + virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) { return false; } }; /** |