* Send this vehicle to the depot using the given command(s). * @param flags the command flags (like execute and such). * @param command the command to execute. * @return the cost of the depot action. */
| 2553 | * @return the cost of the depot action. |
| 2554 | */ |
| 2555 | CommandCost Vehicle::SendToDepot(DoCommandFlags flags, DepotCommandFlags command) |
| 2556 | { |
| 2557 | CommandCost ret = CheckOwnership(this->owner); |
| 2558 | if (ret.Failed()) return ret; |
| 2559 | |
| 2560 | if (this->vehstatus.Test(VehState::Crashed)) return CMD_ERROR; |
| 2561 | if (this->IsStoppedInDepot()) return CMD_ERROR; |
| 2562 | |
| 2563 | /* No matter why we're headed to the depot, unbunching data is no longer valid. */ |
| 2564 | if (flags.Test(DoCommandFlag::Execute)) this->ResetDepotUnbunching(); |
| 2565 | |
| 2566 | if (this->current_order.IsType(OT_GOTO_DEPOT)) { |
| 2567 | bool halt_in_depot = this->current_order.GetDepotActionType().Test(OrderDepotActionFlag::Halt); |
| 2568 | if (command.Test(DepotCommandFlag::Service) == halt_in_depot) { |
| 2569 | /* We called with a different DEPOT_SERVICE setting. |
| 2570 | * Now we change the setting to apply the new one and let the vehicle head for the same depot. |
| 2571 | * Note: the if is (true for requesting service == true for ordered to stop in depot) */ |
| 2572 | if (flags.Test(DoCommandFlag::Execute)) { |
| 2573 | this->current_order.SetDepotOrderType({}); |
| 2574 | this->current_order.SetDepotActionType(halt_in_depot ? OrderDepotActionFlags{} : OrderDepotActionFlag::Halt); |
| 2575 | SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); |
| 2576 | } |
| 2577 | return CommandCost(); |
| 2578 | } |
| 2579 | |
| 2580 | if (command.Test(DepotCommandFlag::DontCancel)) return CMD_ERROR; // Requested no cancellation of depot orders |
| 2581 | if (flags.Test(DoCommandFlag::Execute)) { |
| 2582 | /* If the orders to 'goto depot' are in the orders list (forced servicing), |
| 2583 | * then skip to the next order; effectively cancelling this forced service */ |
| 2584 | if (this->current_order.GetDepotOrderType().Test(OrderDepotTypeFlag::PartOfOrders)) this->IncrementRealOrderIndex(); |
| 2585 | |
| 2586 | if (this->IsGroundVehicle()) { |
| 2587 | uint16_t &gv_flags = this->GetGroundVehicleFlags(); |
| 2588 | SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); |
| 2589 | } |
| 2590 | |
| 2591 | this->current_order.MakeDummy(); |
| 2592 | SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); |
| 2593 | } |
| 2594 | return CommandCost(); |
| 2595 | } |
| 2596 | |
| 2597 | ClosestDepot closest_depot = this->FindClosestDepot(); |
| 2598 | 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}; |
| 2599 | if (!closest_depot.found) return CommandCost(no_depot[this->type]); |
| 2600 | |
| 2601 | if (flags.Test(DoCommandFlag::Execute)) { |
| 2602 | if (this->current_order.IsType(OT_LOADING)) this->LeaveStation(); |
| 2603 | |
| 2604 | if (this->IsGroundVehicle() && this->GetNumManualOrders() > 0) { |
| 2605 | uint16_t &gv_flags = this->GetGroundVehicleFlags(); |
| 2606 | SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); |
| 2607 | } |
| 2608 | |
| 2609 | this->SetDestTile(closest_depot.location); |
| 2610 | this->current_order.MakeGoToDepot(closest_depot.destination.ToDepotID(), {}); |
| 2611 | if (!command.Test(DepotCommandFlag::Service)) this->current_order.SetDepotActionType(OrderDepotActionFlag::Halt); |
| 2612 | SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); |
no test coverage detected