OpenTTD
Functions
timetable_cmd.cpp File Reference

Commands related to time tabling. More...

#include "stdafx.h"
#include "command_func.h"
#include "company_func.h"
#include "date_func.h"
#include "window_func.h"
#include "vehicle_base.h"
#include "cmd_helper.h"
#include "core/sort_func.hpp"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

static void ChangeTimetable (Vehicle *v, VehicleOrderID order_number, uint16 val, ModifyTimetableFlags mtf, bool timetabled)
 Change/update a particular timetable entry.
CommandCost CmdChangeTimetable (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Change timetable data of an order.
CommandCost CmdSetVehicleOnTime (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Clear the lateness counter to make the vehicle on time.
static int CDECL VehicleTimetableSorter (Vehicle *const *ap, Vehicle *const *bp)
 Order vehicles based on their timetable.
CommandCost CmdSetTimetableStart (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Set the start date of the timetable.
CommandCost CmdAutofillTimetable (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 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

static void ChangeTimetable ( Vehicle v,
VehicleOrderID  order_number,
uint16  val,
ModifyTimetableFlags  mtf,
bool  timetabled 
)
static
CommandCost CmdAutofillTimetable ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

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
tileNot used.
flagsOperation to perform.
p1Vehicle index.
p2Various bitstuffed elements
  • p2 = (bit 0) - Set to 1 to enable, 0 to disable autofill.
  • p2 = (bit 1) - Set to 1 to preserve waiting times in non-destructive mode
textunused
Returns
the cost of this operation or an error

Definition at line 333 of file timetable_cmd.cpp.

References CheckOwnership(), ClrBit(), CMD_ERROR, DC_EXEC, CommandCost::Failed(), Vehicle::FirstShared(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), HasBit(), Vehicle::IsPrimaryVehicle(), BaseConsist::lateness_counter, Vehicle::list, Vehicle::NextShared(), Vehicle::orders, Vehicle::owner, SetBit(), SetWindowDirty(), BaseConsist::timetable_start, BaseConsist::vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME, VF_AUTOFILL_TIMETABLE, VF_TIMETABLE_STARTED, and WC_VEHICLE_TIMETABLE.

CommandCost CmdChangeTimetable ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Change timetable data of an order.

Parameters
tileNot used.
flagsOperation to perform.
p1Various 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 Also
ModifyTimetableFlags)
Parameters
p2The amount of time to wait.
  • p2 = (bit 0-15) - The data to modify as specified by p1 bits 28-29. 0 to clear times, UINT16_MAX to clear speed limit.
textunused
Returns
the cost of this operation or an error

Definition at line 103 of file timetable_cmd.cpp.

References ChangeTimetable(), CheckOwnership(), CMD_ERROR, DC_EXEC, CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), 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, ONSF_NO_STOP_AT_DESTINATION_STATION, Vehicle::owner, return_cmd_error, BaseVehicle::type, and VEH_AIRCRAFT.

CommandCost CmdSetTimetableStart ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)
CommandCost CmdSetVehicleOnTime ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Clear the lateness counter to make the vehicle on time.

Parameters
tileNot used.
flagsOperation to perform.
p1Various bitstuffed elements
  • p1 = (bit 0-19) - Vehicle with the orders to change.
p2unused
textunused
Returns
the cost of this operation or an error

Definition at line 197 of file timetable_cmd.cpp.

References CheckOwnership(), CMD_ERROR, DC_EXEC, CommandCost::Failed(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsPrimaryVehicle(), BaseConsist::lateness_counter, Vehicle::list, Vehicle::orders, Vehicle::owner, SetWindowDirty(), and WC_VEHICLE_TIMETABLE.

void UpdateVehicleTimetable ( Vehicle v,
bool  travelling 
)
static int CDECL VehicleTimetableSorter ( Vehicle *const *  ap,
Vehicle *const *  bp 
)
static

Order vehicles based on their timetable.

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

Parameters
apFirst Vehicle pointer.
bpSecond Vehicle pointer.
Returns
Comparison value.

Definition at line 223 of file timetable_cmd.cpp.

References BaseConsist::cur_real_order_index, Vehicle::current_order, BaseConsist::current_order_time, Order::GetNonStopType(), Order::IsType(), ONSF_STOP_EVERYWHERE, and Vehicle::unitnumber.

Referenced by CmdSetTimetableStart().