OpenTTD Source 20260206-master-g4d4e37dbf1
timetable_cmd.cpp File Reference

Commands related to time tabling. More...

#include "stdafx.h"
#include "command_func.h"
#include "company_func.h"
#include "timer/timer_game_tick.h"
#include "timer/timer_game_economy.h"
#include "window_func.h"
#include "vehicle_base.h"
#include "timetable_cmd.h"
#include "timetable.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

TimerGameTick::TickCounter GetStartTickFromDate (TimerGameEconomy::Date start_date)
 Get the TimerGameTick::TickCounter tick of a given date.
TimerGameEconomy::Date GetDateFromStartTick (TimerGameTick::TickCounter start_tick)
 Get a date from a given start tick of timetable.
static void ChangeTimetable (Vehicle *v, VehicleOrderID order_number, uint16_t val, ModifyTimetableFlags mtf, bool timetabled)
 Change/update a particular timetable entry.
CommandCost CmdChangeTimetable (DoCommandFlags flags, VehicleID veh, VehicleOrderID order_number, ModifyTimetableFlags mtf, uint16_t data)
 Change timetable data of an order.
CommandCost CmdBulkChangeTimetable (DoCommandFlags flags, VehicleID veh, ModifyTimetableFlags mtf, uint16_t data)
 Change timetable data of all orders of a vehicle.
CommandCost CmdSetVehicleOnTime (DoCommandFlags flags, VehicleID veh, bool apply_to_group)
 Clear the lateness counter to make the vehicle on time.
static bool VehicleTimetableSorter (Vehicle *const &a, Vehicle *const &b)
 Order vehicles based on their timetable.
CommandCost CmdSetTimetableStart (DoCommandFlags flags, VehicleID veh_id, bool timetable_all, TimerGameTick::TickCounter start_tick)
 Set the start date of the timetable.
CommandCost CmdAutofillTimetable (DoCommandFlags flags, VehicleID veh, bool autofill, bool preserve_wait_time)
 Start or stop filling the timetable automatically from the time the vehicle actually takes to complete it.
void UpdateVehicleTimetable (Vehicle *v, bool travelling)
 Update the timetable for the vehicle.

Detailed Description

Commands related to time tabling.

Definition in file timetable_cmd.cpp.

Function Documentation

◆ ChangeTimetable()

void ChangeTimetable ( Vehicle * v,
VehicleOrderID order_number,
uint16_t val,
ModifyTimetableFlags mtf,
bool timetabled )
static

Change/update a particular timetable entry.

Parameters
vThe vehicle to change the timetable of.
order_numberThe index of the timetable in the order list.
valThe new data of the timetable entry.
mtfWhich part of the timetable entry to change.
timetabledIf the new value is explicitly timetabled.

Definition at line 66 of file timetable_cmd.cpp.

References BaseConsist::cur_real_order_index, Vehicle::current_order, Order::Equals(), Vehicle::FirstShared(), Vehicle::GetOrder(), Order::GetTimetabledTravel(), Order::GetTimetabledWait(), Order::GetTravelTime(), Order::GetWaitTime(), MTF_TRAVEL_SPEED, MTF_TRAVEL_TIME, MTF_WAIT_TIME, Vehicle::NextShared(), Vehicle::orders, Order::SetMaxSpeed(), Order::SetTravelTime(), Order::SetTravelTimetabled(), Order::SetWaitTime(), Order::SetWaitTimetabled(), SetWindowDirty(), OrderList::UpdateTimetableDuration(), OrderList::UpdateTotalDuration(), and WC_VEHICLE_TIMETABLE.

Referenced by CmdChangeTimetable(), and UpdateVehicleTimetable().

◆ CmdAutofillTimetable()

CommandCost CmdAutofillTimetable ( DoCommandFlags flags,
VehicleID veh,
bool autofill,
bool preserve_wait_time )

Start or stop filling the timetable automatically from the time the vehicle actually takes to complete it.

When starting to autofill the current times are cleared and the timetable will start again from scratch.

Parameters
flagsOperation to perform.
vehVehicle index.
autofillEnable or disable autofill
preserve_wait_timeSet to preserve waiting times in non-destructive mode
Returns
the cost of this operation or an error

Definition at line 425 of file timetable_cmd.cpp.

References AutofillPreserveWaitTime, AutofillTimetable, CheckOwnership(), CMD_ERROR, Execute, CommandCost::Failed(), Vehicle::FirstShared(), Vehicle::IsPrimaryVehicle(), BaseConsist::lateness_counter, Vehicle::NextShared(), Vehicle::orders, Vehicle::owner, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), BaseConsist::timetable_start, TimetableStarted, BaseConsist::vehicle_flags, and WC_VEHICLE_TIMETABLE.

◆ CmdBulkChangeTimetable()

CommandCost CmdBulkChangeTimetable ( DoCommandFlags flags,
VehicleID veh,
ModifyTimetableFlags mtf,
uint16_t data )

Change timetable data of all orders of a vehicle.

Parameters
flagsOperation to perform.
vehVehicle with the orders to change.
mtfTimetable data to change (
See also
ModifyTimetableFlags)
Parameters
dataThe data to modify as specified by mtf. 0 to clear times, UINT16_MAX to clear speed limit.
Returns
the cost of this operation or an error

Definition at line 228 of file timetable_cmd.cpp.

References CheckOwnership(), CMD_ERROR, Execute, CommandCost::Failed(), Vehicle::GetNumOrders(), Vehicle::GetOrder(), Vehicle::IsPrimaryVehicle(), Order::IsType(), Vehicle::owner, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

◆ CmdChangeTimetable()

CommandCost CmdChangeTimetable ( DoCommandFlags flags,
VehicleID veh,
VehicleOrderID order_number,
ModifyTimetableFlags mtf,
uint16_t data )

Change timetable data of an order.

Parameters
flagsOperation to perform.
vehVehicle with the orders to change.
order_numberOrder index to modify.
mtfTimetable data to change (
See also
ModifyTimetableFlags)
Parameters
dataThe data to modify as specified by mtf. 0 to clear times, UINT16_MAX to clear speed limit.
Returns
the cost of this operation or an error

Definition at line 133 of file timetable_cmd.cpp.

References ChangeTimetable(), CheckOwnership(), CMD_ERROR, Execute, CommandCost::Failed(), Vehicle::FirstShared(), Order::GetMaxSpeed(), Order::GetNonStopType(), Vehicle::GetOrder(), Order::GetTravelTime(), Order::GetType(), Order::GetWaitTime(), Vehicle::IsPrimaryVehicle(), Order::IsTravelTimetabled(), Order::IsType(), Order::IsWaitTimetabled(), MTF_TRAVEL_SPEED, MTF_TRAVEL_TIME, MTF_WAIT_TIME, Vehicle::NextShared(), NoDestination, Vehicle::owner, BaseConsist::ResetDepotUnbunching(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), BaseVehicle::type, and VEH_AIRCRAFT.

◆ CmdSetTimetableStart()

◆ CmdSetVehicleOnTime()

CommandCost CmdSetVehicleOnTime ( DoCommandFlags flags,
VehicleID veh,
bool apply_to_group )

Clear the lateness counter to make the vehicle on time.

Parameters
flagsOperation to perform.
vehVehicle with the orders to change.
apply_to_groupSet to reset the late counter for all vehicles sharing the orders.
Returns
the cost of this operation or an error

Definition at line 259 of file timetable_cmd.cpp.

References CheckOwnership(), CMD_ERROR, Execute, CommandCost::Failed(), Vehicle::FirstShared(), Vehicle::IsPrimaryVehicle(), BaseConsist::lateness_counter, Vehicle::NextShared(), Vehicle::orders, Vehicle::owner, BaseConsist::ResetDepotUnbunching(), SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TimetableStarted, BaseConsist::vehicle_flags, and WC_VEHICLE_TIMETABLE.

◆ GetDateFromStartTick()

TimerGameEconomy::Date GetDateFromStartTick ( TimerGameTick::TickCounter start_tick)

Get a date from a given start tick of timetable.

Parameters
start_tickThe TimerGameTick::TickCounter when the timetable starts.
Returns
The date when we reach this tick.

Definition at line 46 of file timetable_cmd.cpp.

References TimerGameTick::counter, TimerGameEconomy::date, TimerGameEconomy::date_fract, and Ticks::DAY_TICKS.

Referenced by CmdSetTimetableStart(), and TimetableWindow::DrawSummaryPanel().

◆ GetStartTickFromDate()

TimerGameTick::TickCounter GetStartTickFromDate ( TimerGameEconomy::Date start_date)

Get the TimerGameTick::TickCounter tick of a given date.

Parameters
start_dateThe date when the timetable starts.
Returns
The first tick of this date.

Definition at line 29 of file timetable_cmd.cpp.

References TimerGameTick::counter, TimerGameEconomy::date, TimerGameEconomy::date_fract, and Ticks::DAY_TICKS.

Referenced by OrderList::AfterLoadVehiclesPhase1.

◆ UpdateVehicleTimetable()

◆ VehicleTimetableSorter()

bool VehicleTimetableSorter ( Vehicle *const & a,
Vehicle *const & b )
static

Order vehicles based on their timetable.

The vehicles will be sorted in order they would reach the first station.

Parameters
aFirst Vehicle pointer.
bSecond Vehicle pointer.
Returns
Comparison value.

Definition at line 313 of file timetable_cmd.cpp.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), BaseConsist::cur_real_order_index, Vehicle::current_order, BaseConsist::current_order_time, Order::GetNonStopType(), Order::IsType(), and Vehicle::unitnumber.

Referenced by CmdSetTimetableStart().