Add way to mass cancel vehicle go to depot/service

pull/59/head
Jonathan G Rennison 6 years ago
parent 2821599f6b
commit 53dd010f3b

@ -962,6 +962,9 @@ public:
DoCommandP(0, DEPOT_MASS_SEND | (index == ADI_SERVICE ? DEPOT_SERVICE : 0U), this->vli.Pack(), GetCmdSendToDepot(this->vli.vtype));
break;
}
case ADI_CANCEL_DEPOT:
DoCommandP(0, DEPOT_MASS_SEND | DEPOT_CANCEL, this->vli.Pack(), GetCmdSendToDepot(this->vli.vtype));
break;
case ADI_ADD_SHARED: // Add shared Vehicles
assert(Group::IsValidID(this->vli.index));

@ -3906,6 +3906,7 @@ STR_VEHICLE_LIST_MANAGE_LIST :{BLACK}Manage l
STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Send instructions to all vehicles in this list
STR_VEHICLE_LIST_REPLACE_VEHICLES :Replace vehicles
STR_VEHICLE_LIST_SEND_FOR_SERVICING :Send for Servicing
STR_VEHICLE_LIST_CANCEL_DEPOT_SERVICE :Cancel Servicing/Send to
STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Send to Depot
STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Send to Depot

@ -2950,23 +2950,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command, Tile
if (this->vehstatus & VS_CRASHED) return CMD_ERROR;
if (this->IsStoppedInDepot()) return CMD_ERROR;
if (this->current_order.IsType(OT_GOTO_DEPOT) && !(command & DEPOT_SPECIFIC)) {
bool halt_in_depot = (this->current_order.GetDepotActionType() & ODATFB_HALT) != 0;
if (!!(command & DEPOT_SERVICE) == halt_in_depot) {
/* We called with a different DEPOT_SERVICE setting.
* Now we change the setting to apply the new one and let the vehicle head for the same depot.
* Note: the if is (true for requesting service == true for ordered to stop in depot) */
if (flags & DC_EXEC) {
if (!(this->current_order.GetDepotOrderType() & ODTFB_BREAKDOWN)) this->current_order.SetDepotOrderType(ODTF_MANUAL);
this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT);
this->ClearSeparation();
if (HasBit(this->vehicle_flags, VF_TIMETABLE_SEPARATION)) ClrBit(this->vehicle_flags, VF_TIMETABLE_STARTED);
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
}
return CommandCost();
}
if (command & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders
auto cancel_order = [&]() {
if (flags & DC_EXEC) {
/* If the orders to 'goto depot' are in the orders list (forced servicing),
* then skip to the next order; effectively cancelling this forced service */
@ -2991,6 +2975,35 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command, Tile
/* prevent any attempt to update timetable for current order, as actual travel time will be incorrect due to depot command */
this->cur_timetable_order_index = INVALID_VEH_ORDER_ID;
}
};
if (command & DEPOT_CANCEL) {
if (this->current_order.IsType(OT_GOTO_DEPOT)) {
cancel_order();
return CommandCost();
} else {
return CMD_ERROR;
}
}
if (this->current_order.IsType(OT_GOTO_DEPOT) && !(command & DEPOT_SPECIFIC)) {
bool halt_in_depot = (this->current_order.GetDepotActionType() & ODATFB_HALT) != 0;
if (!!(command & DEPOT_SERVICE) == halt_in_depot) {
/* We called with a different DEPOT_SERVICE setting.
* Now we change the setting to apply the new one and let the vehicle head for the same depot.
* Note: the if is (true for requesting service == true for ordered to stop in depot) */
if (flags & DC_EXEC) {
if (!(this->current_order.GetDepotOrderType() & ODTFB_BREAKDOWN)) this->current_order.SetDepotOrderType(ODTF_MANUAL);
this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT);
this->ClearSeparation();
if (HasBit(this->vehicle_flags, VF_TIMETABLE_SEPARATION)) ClrBit(this->vehicle_flags, VF_TIMETABLE_STARTED);
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
}
return CommandCost();
}
if (command & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders
cancel_order();
return CommandCost();
}

@ -1496,11 +1496,11 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
/**
* Send all vehicles of type to depots
* @param flags the flags used for DoCommand()
* @param service should the vehicles only get service in the depots
* @param depot_flags depot command flags
* @param vli identifier of the vehicle list
* @return 0 for success and CMD_ERROR if no vehicle is able to go to depot
*/
static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, const VehicleListIdentifier &vli)
static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, DepotCommand depot_flags, const VehicleListIdentifier &vli)
{
VehicleList list;
@ -1510,7 +1510,7 @@ static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, con
bool had_success = false;
for (uint i = 0; i < list.Length(); i++) {
const Vehicle *v = list[i];
CommandCost ret = DoCommand(v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0, flags, GetCmdSendToDepot(vli.vtype));
CommandCost ret = DoCommand(v->tile, v->index | depot_flags, 0, flags, GetCmdSendToDepot(vli.vtype));
if (ret.Succeeded()) {
had_success = true;
@ -1543,7 +1543,9 @@ CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1
/* Mass goto depot requested */
VehicleListIdentifier vli;
if (!vli.UnpackIfValid(p2)) return CMD_ERROR;
return SendAllVehiclesToDepot(flags, (p1 & DEPOT_SERVICE) != 0, vli);
uint32 depot_flags = (p1 & (DEPOT_SERVICE | DEPOT_CANCEL));
if (!(p1 & DEPOT_CANCEL)) depot_flags |= DEPOT_DONT_CANCEL;
return SendAllVehiclesToDepot(flags, (DepotCommand) depot_flags, vli);
}
Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));

@ -322,6 +322,7 @@ DropDownList *BaseVehicleListWindow::BuildActionDropdownList(bool show_autorepla
}
*list->Append() = new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE, disable);
*list->Append() = new DropDownListStringItem(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT, disable);
*list->Append() = new DropDownListStringItem(STR_VEHICLE_LIST_CANCEL_DEPOT_SERVICE, ADI_CANCEL_DEPOT, disable);
if (show_group) {
*list->Append() = new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, disable);

@ -44,6 +44,7 @@ struct BaseVehicleListWindow : public Window {
ADI_REPLACE,
ADI_SERVICE,
ADI_DEPOT,
ADI_CANCEL_DEPOT,
ADI_ADD_SHARED,
ADI_REMOVE_ALL,
ADI_CHANGE_ORDER,

@ -65,12 +65,13 @@ enum VehiclePathFinders {
/** Flags to add to p1 for goto depot commands. */
enum DepotCommand {
DEPOT_CANCEL = (1U << 26), ///< Cancel depot/service order
DEPOT_SPECIFIC = (1U << 27), ///< Send vehicle to specific depot
DEPOT_SERVICE = (1U << 28), ///< The vehicle will leave the depot right after arrival (serivce only)
DEPOT_SERVICE = (1U << 28), ///< The vehicle will leave the depot right after arrival (service only)
DEPOT_MASS_SEND = (1U << 29), ///< Tells that it's a mass send to depot command (type in VLW flag)
DEPOT_DONT_CANCEL = (1U << 30), ///< Don't cancel current goto depot command if any
DEPOT_LOCATE_HANGAR = (1U << 31), ///< Find another airport if the target one lacks a hangar
DEPOT_COMMAND_MASK = 0x1FU << 27,
DEPOT_COMMAND_MASK = 0x3FU << 26,
};
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS = 128; ///< The maximum length of a vehicle name in characters including '\0'

Loading…
Cancel
Save