mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-20 04:59:11 +00:00
Codechange: refactor FindClosestDepot to not use pointers, but return a struct
This commit is contained in:
@@ -1982,23 +1982,21 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
|
||||
|
||||
if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
|
||||
/* We need to search for the nearest depot (hangar). */
|
||||
TileIndex location;
|
||||
DestinationID destination;
|
||||
bool reverse;
|
||||
ClosestDepot closestDepot = v->FindClosestDepot();
|
||||
|
||||
if (v->FindClosestDepot(&location, &destination, &reverse)) {
|
||||
if (closestDepot.found) {
|
||||
/* PBS reservations cannot reverse */
|
||||
if (pbs_look_ahead && reverse) return false;
|
||||
if (pbs_look_ahead && closestDepot.reverse) return false;
|
||||
|
||||
v->SetDestTile(location);
|
||||
v->current_order.SetDestination(destination);
|
||||
v->SetDestTile(closestDepot.location);
|
||||
v->current_order.SetDestination(closestDepot.destination);
|
||||
|
||||
/* If there is no depot in front, reverse automatically (trains only) */
|
||||
if (v->type == VEH_TRAIN && reverse) Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DC_EXEC, v->index, false);
|
||||
if (v->type == VEH_TRAIN && closestDepot.reverse) Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DC_EXEC, v->index, false);
|
||||
|
||||
if (v->type == VEH_AIRCRAFT) {
|
||||
Aircraft *a = Aircraft::From(v);
|
||||
if (a->state == FLYING && a->targetairport != destination) {
|
||||
if (a->state == FLYING && a->targetairport != closestDepot.destination) {
|
||||
/* The aircraft is now heading for a different hangar than the next in the orders */
|
||||
extern void AircraftNextAirportPos_and_Order(Aircraft *a);
|
||||
AircraftNextAirportPos_and_Order(a);
|
||||
|
Reference in New Issue
Block a user