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;
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...
union Vehicle::@49 orders
The orders currently assigned to the vehicle.
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.
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.
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.
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.
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
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).
Owner owner
Which company owns the vehicle?
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.
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.
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.
VehicleType type
Type of vehicle.
#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 nullptr 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.
Date _date
Current date in days (day counter)
void SetTravelTime(uint16 time)
Set the time in ticks to take for travelling to the destination.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
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...