Allow naming scheduled dispatch schedules

This commit is contained in:
Jonathan G Rennison
2023-04-29 12:19:28 +01:00
parent 6445d688ed
commit 211c1ba61d
10 changed files with 132 additions and 20 deletions

View File

@@ -411,6 +411,49 @@ CommandCost CmdScheduledDispatchRemoveSchedule(TileIndex tile, DoCommandFlag fla
return CommandCost();
}
/**
* Rename scheduled dispatch schedule
*
* @param tile Not used.
* @param flags Operation to perform.
* @param p1 Vehicle index
* @param p2 Not used
* @param text name
* @return the cost of this operation or an error
*/
CommandCost CmdScheduledDispatchRenameSchedule(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 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;
bool reset = StrEmpty(text);
if (!reset) {
if (Utf8StringLength(text) >= MAX_LENGTH_VEHICLE_NAME_CHARS) return CMD_ERROR;
}
if (flags & DC_EXEC) {
if (reset) {
v->orders->GetDispatchScheduleByIndex(schedule_index).ScheduleName().clear();
} else {
v->orders->GetDispatchScheduleByIndex(schedule_index).ScheduleName() = text;
}
SetTimetableWindowsDirty(v, true);
}
return CommandCost();
}
/**
* Set scheduled dispatch slot list.
* @param dispatch_list The offset time list, must be correctly sorted.