Go to the documentation of this file.
18 #include "table/strings.h"
34 int timetable_delta = 0;
108 if (ret.
Failed())
return ret;
122 wait_time =
GB(p2, 0, 16);
126 travel_time =
GB(p2, 0, 16);
130 max_speed =
GB(p2, 0, 16);
131 if (max_speed == 0) max_speed = UINT16_MAX;
140 case OT_GOTO_STATION:
202 if (ret.
Failed())
return ret;
224 int j = (int)b_order - (
int)a_order;
234 if (!a_load) a_order--;
235 if (!b_load) b_order--;
238 int i = (int)b_order - (
int)a_order;
239 if (i != 0)
return i < 0;
240 if (j != 0)
return j < 0;
244 if (i != 0)
return i < 0;
263 bool timetable_all =
HasBit(p1, 20);
268 if (ret.
Failed())
return ret;
278 std::vector<Vehicle *> vehs;
289 int num_vehs = (uint)vehs.size();
295 int idx = vehs.begin() - std::find(vehs.begin(), vehs.end(), v);
299 w->lateness_counter = 0;
302 w->timetable_start = start_date + idx * total_duration / num_vehs /
DAY_TICKS;
334 if (ret.
Failed())
return ret;
385 ++first_manual_order;
388 bool just_started =
false;
413 if (travelling && remeasure_wait_time) {
419 if (just_started)
return;
422 if (!real_current_order->
IsType(OT_CONDITIONAL) &&
423 (travelling || time_taken > real_current_order->
GetWaitTime() || remeasure_wait_time)) {
437 }
else if (!travelling && (autofilling || !real_current_order->
IsWaitTimetabled())) {
450 if (autofilling)
return;
@ VEH_AIRCRAFT
Aircraft vehicle type.
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
uint32 TileIndex
The index/ID of a Tile.
@ MTF_TRAVEL_SPEED
Set max travel speed.
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
bool IsType(OrderType type) const
Check whether this order is of the given type.
uint16 GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
@ MTF_WAIT_TIME
Set wait time.
void UpdateTimetableDuration(Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
DateFract _date_fract
Fractional part of the day.
uint16 GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
Tindex index
Index of this pool item.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
void SetTravelTimetabled(bool timetabled)
Set if the travel time is explicitly timetabled (unless the order is conditional).
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
#define MAX_DAY
The number of days till the last day.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Ticks GetTimetableTotalDuration() const
Gets the total duration of the vehicles timetable or INVALID_TICKS is the timetable is not complete.
Owner owner
Which company owns the vehicle?
@ DC_EXEC
execute the given command
@ MTF_TRAVEL_TIME
Set travel time.
DoCommandFlag
List of flags for a command.
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.
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Common return value for all commands.
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
Date _date
Current date in days (day counter)
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
uint16 GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
bool Failed() const
Did this command fail?
Order current_order
The current order (+ status, like: loading)
int32 Date
The type to store our dates in.
void SetTravelTime(uint16 time)
Set the time in ticks to take for travelling to the destination.
int32 Ticks
The type to store ticks in.
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
static const Ticks INVALID_TICKS
Representation of an invalid number of ticks.
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
OrderList * list
Pointer to the order list for this vehicle.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
void UpdateTotalDuration(Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
uint32 current_order_time
How many ticks have passed since this order started.
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
union Vehicle::@51 orders
The orders currently assigned to the vehicle.
Date timetable_start
When the vehicle is supposed to start the timetable.
void SetWaitTime(uint16 time)
Set the time in ticks to wait at the destination.
UnitID unitnumber
unit number, for display purposes only
@ VF_AUTOFILL_PRES_WAIT_TIME
Whether non-destructive auto-fill should preserve waiting times.
uint32 VehicleID
The type all our vehicle IDs have.
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
void SetMaxSpeed(uint16 speed)
Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
VehicleType type
Type of vehicle.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
bool Equals(const Order &other) const
Does this order have the same type, flags and destination?
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
void SetWaitTimetabled(bool timetabled)
Set if the wait time is explicitly timetabled (unless the order is conditional).