Codechange: refactor FindClosestDepot to not use pointers, but return a struct
This commit is contained in:
@@ -2423,11 +2423,9 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
TileIndex location;
|
||||
DestinationID destination;
|
||||
bool reverse;
|
||||
ClosestDepot closestDepot = this->FindClosestDepot();
|
||||
static const StringID no_depot[] = {STR_ERROR_UNABLE_TO_FIND_ROUTE_TO, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR};
|
||||
if (!this->FindClosestDepot(&location, &destination, &reverse)) return_cmd_error(no_depot[this->type]);
|
||||
if (!closestDepot.found) return_cmd_error(no_depot[this->type]);
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (this->current_order.IsType(OT_LOADING)) this->LeaveStation();
|
||||
@@ -2437,19 +2435,19 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
|
||||
SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
|
||||
}
|
||||
|
||||
this->SetDestTile(location);
|
||||
this->current_order.MakeGoToDepot(destination, ODTF_MANUAL);
|
||||
this->SetDestTile(closestDepot.location);
|
||||
this->current_order.MakeGoToDepot(closestDepot.destination, ODTF_MANUAL);
|
||||
if ((command & DepotCommand::Service) == DepotCommand::None) this->current_order.SetDepotActionType(ODATFB_HALT);
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
|
||||
|
||||
/* If there is no depot in front and the train is not already reversing, reverse automatically (trains only) */
|
||||
if (this->type == VEH_TRAIN && (reverse ^ HasBit(Train::From(this)->flags, VRF_REVERSING))) {
|
||||
if (this->type == VEH_TRAIN && (closestDepot.reverse ^ HasBit(Train::From(this)->flags, VRF_REVERSING))) {
|
||||
Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DC_EXEC, this->index, false);
|
||||
}
|
||||
|
||||
if (this->type == VEH_AIRCRAFT) {
|
||||
Aircraft *a = Aircraft::From(this);
|
||||
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