@@ -25,192 +25,193 @@
* @param order_number The index of the timetable in the order list.
* @param val The new data of the timetable entry.
* @param mtf Which part of the timetable entry to change.
*/
static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val, ModifyTimetableFlags mtf)
{
Order *order = v->GetOrder(order_number);
int delta = 0;
switch (mtf) {
case MTF_WAIT_TIME:
delta = val - order->wait_time;
order->wait_time = val;
break;
case MTF_TRAVEL_TIME:
delta = val - order->travel_time;
order->travel_time = val;
case MTF_TRAVEL_SPEED:
order->max_speed = val;
default:
NOT_REACHED();
}
v->orders.list->UpdateOrderTimetable(delta);
for (v = v->FirstShared(); v != NULL; v = v->NextShared()) {
if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) {
v->current_order.wait_time = val;
v->current_order.travel_time = val;
v->current_order.max_speed = val;
SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
/**
* Change timetable data of an order.
* @param tile Not used.
* @param flags Operation to perform.
* @param p1 Various bitstuffed elements
* - p1 = (bit 0-19) - Vehicle with the orders to change.
* - p1 = (bit 20-27) - Order index to modify.
* - p1 = (bit 28-29) - Timetable data to change (@see ModifyTimetableFlags)
* @param p2 The amount of time to wait.
* - p2 = (bit 0-15) - The data to modify as specified by p1 bits 28-29.
* @param text unused
* @return the cost of this operation or an error
CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
VehicleID veh = GB(p1, 0, 20);
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
VehicleOrderID order_number = GB(p1, 20, 8);
if (order == NULL || order->IsType(OT_IMPLICIT)) return CMD_ERROR;
ModifyTimetableFlags mtf = Extract<ModifyTimetableFlags, 28, 2>(p1);
if (mtf >= MTF_END) return CMD_ERROR;
int wait_time = order->wait_time;
int travel_time = order->travel_time;
int max_speed = order->max_speed;
wait_time = GB(p2, 0, 16);
travel_time = GB(p2, 0, 16);
max_speed = GB(p2, 0, 16);
if (max_speed == 0) max_speed = UINT16_MAX; // Disable speed limit.
if (wait_time != order->wait_time) {
switch (order->GetType()) {
case OT_GOTO_STATION:
if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return_cmd_error(STR_ERROR_TIMETABLE_NOT_STOPPING_HERE);
case OT_CONDITIONAL:
default: return_cmd_error(STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
if (travel_time != order->travel_time && order->IsType(OT_CONDITIONAL)) return CMD_ERROR;
if (max_speed != order->max_speed && (order->IsType(OT_CONDITIONAL) || v->type == VEH_AIRCRAFT)) return CMD_ERROR;
if (flags & DC_EXEC) {
if (wait_time != order->wait_time) ChangeTimetable(v, order_number, wait_time, MTF_WAIT_TIME);
if (travel_time != order->travel_time) ChangeTimetable(v, order_number, travel_time, MTF_TRAVEL_TIME);
if (max_speed != order->max_speed) ChangeTimetable(v, order_number, max_speed, MTF_TRAVEL_SPEED);
return CommandCost();
* Clear the lateness counter to make the vehicle on time.
* @param p2 unused
CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
v->lateness_counter = 0;
* Set the start date of the timetable.
* @param p1 Vehicle id.
* @param p2 The timetable start date.
* @param text Not used.
* @return The error or cost of the operation.
CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));
/* Don't let a timetable start more than 15 years into the future or 1 year in the past. */
Date start_date = (Date)p2;
if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR;
if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (_date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR;
ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
v->timetable_start = start_date;
* Start or stop filling the timetable automatically from the time the vehicle
Status change: