21 #include "table/strings.h" 37 int timetable_delta = 0;
111 if (ret.
Failed())
return ret;
125 wait_time =
GB(p2, 0, 16);
129 travel_time =
GB(p2, 0, 16);
133 max_speed =
GB(p2, 0, 16);
134 if (max_speed == 0) max_speed = UINT16_MAX;
143 case OT_GOTO_STATION:
205 if (ret.
Failed())
return ret;
230 int j = (int)b_order - (
int)a_order;
240 if (!a_load) a_order--;
241 if (!b_load) b_order--;
244 int i = (int)b_order - (
int)a_order;
245 if (i != 0)
return i;
246 if (j != 0)
return j;
250 if (i != 0)
return i;
269 bool timetable_all =
HasBit(p1, 20);
274 if (ret.
Failed())
return ret;
295 int num_vehs = vehs.
Length();
304 int idx = (viter - vehs.
Begin()) - base;
341 if (ret.
Failed())
return ret;
392 ++first_manual_order;
395 bool just_started =
false;
420 if (travelling && remeasure_wait_time) {
426 if (just_started)
return;
429 if (!real_current_order->
IsType(OT_CONDITIONAL) &&
430 (travelling || time_taken > real_current_order->
GetWaitTime() || remeasure_wait_time)) {
444 }
else if (!travelling && (autofilling || !real_current_order->
IsWaitTimetabled())) {
457 if (autofilling)
return;
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
uint16 GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not)...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Ticks GetTimetableTotalDuration() const
Gets the total duration of the vehicles timetable or INVALID_TICKS is the timetable is not complete...
Whether the vehicle has started running on the timetable yet.
Functions related to dates.
void UpdateTimetableDuration(Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
void SetWaitTime(uint16 time)
Set the time in ticks to wait at the destination.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static const Ticks INVALID_TICKS
Representation of an invalid number of ticks.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
OrderList * list
Pointer to the order list for this vehicle.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
uint32 current_order_time
How many ticks have passed since this order started.
const T * Begin() const
Get the pointer to the first item (const)
Tindex index
Index of this pool item.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Helper functions to extract data from command parameters.
Simple vector template class.
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
Common return value for all commands.
static T max(const T a, const T b)
Returns the maximum of two values.
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
const T * End() const
Get the pointer behind the last valid item (const)
void SetMaxSpeed(uint16 speed)
Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination...
The vehicle will stop at any station it passes except the destination.
T * Append(uint to_add=1)
Append an item and return it.
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
The vehicle will stop at any station it passes and the destination.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
UnitID unitnumber
unit number, for display purposes only
uint Length() const
Get the number of items in the list.
DateFract _date_fract
Fractional part of the day.
uint32 VehicleID
The type all our vehicle IDs have.
bool IsType(OrderType type) const
Check whether this order is of the given type.
DoCommandFlag
List of flags for a command.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Whether the vehicle should fill in the timetable automatically.
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
uint16 GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled...
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Vehicle timetable; Window numbers:
void SetWaitTimetabled(bool timetabled)
Set if the wait time is explicitly timetabled (unless the order is conditional).
bool Equals(const Order &other) const
Does this order have the same type, flags and destination?
bool Failed() const
Did this command fail?
Date timetable_start
When the vehicle is supposed to start the timetable.
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not)...
execute the given command
Functions related to companies.
uint16 GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
int FindIndex(const T &item) const
Search for the first occurrence of an item.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Base class for all vehicles.
uint32 TileIndex
The index/ID of a Tile.
int32 Ticks
The type to store ticks in.
OwnerByte owner
Which company owns the vehicle?
void SetTravelTimetabled(bool timetabled)
Set if the travel time is explicitly timetabled (unless the order is conditional).
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Functions related to sorting operations.
#define MAX_DAY
The number of days till the last day.
void UpdateTotalDuration(Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
Functions related to commands.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or NULL when it doesn't exists.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
int32 Date
The type to store our dates in.
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Whether non-destructive auto-fill should preserve waiting times.
OrderType GetType() const
Get the type of order of this order.
uint16 GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination...
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Window functions not directly related to making/drawing windows.
union Vehicle::@46 orders
The orders currently assigned to the vehicle.
Date _date
Current date in days (day counter)
void SetTravelTime(uint16 time)
Set the time in ticks to take for travelling to the destination.
static void QSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe qsort()
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
VehicleTypeByte type
Type of vehicle.
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Order current_order
The current order (+ status, like: loading)
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...