Scheduled dispatch: Add flag to re-use all dispatch slots

This commit is contained in:
Jonathan G Rennison
2024-01-21 18:09:24 +00:00
parent 423877374b
commit 5b7689a0aa
12 changed files with 113 additions and 23 deletions

View File

@@ -243,6 +243,39 @@ CommandCost CmdScheduledDispatchSetDelay(TileIndex tile, DoCommandFlag flags, ui
return CommandCost();
}
/**
* Set scheduled dispatch maximum allow delay
*
* @param tile Not used.
* @param flags Operation to perform.
* @param p1 Vehicle index
* @param p2 Whether to re-use slots
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdScheduledDispatchSetReuseSlots(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
{
VehicleID veh = GB(p1, 0, 20);
uint schedule_index = GB(p1, 20, 12);
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
if (v->orders == nullptr) return CMD_ERROR;
if (schedule_index >= v->orders->GetScheduledDispatchScheduleCount()) return CMD_ERROR;
if (flags & DC_EXEC) {
v->orders->GetDispatchScheduleByIndex(schedule_index).SetScheduledDispatchReuseSlots(p2 != 0);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
return CommandCost();
}
/**
* Reset scheduled dispatch last dispatch vehicle time
*