OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
20 #include "table/strings.h"
69 assert(order !=
nullptr);
71 int timetable_delta = 0;
139 if (ret.
Failed())
return ret;
160 if (max_speed == 0) max_speed = UINT16_MAX;
169 case OT_GOTO_STATION:
234 if (ret.
Failed())
return ret;
243 if (order ==
nullptr || order->
IsType(OT_IMPLICIT))
continue;
269 if (ret.
Failed())
return ret;
272 if (apply_to_group) {
278 if (u->lateness_counter > most_late) {
279 most_late = u->lateness_counter;
283 u->ResetDepotUnbunching();
290 u->lateness_counter -= most_late;
317 int j = (int)b_order - (
int)a_order;
327 if (!a_load) a_order--;
328 if (!b_load) b_order--;
331 int i = (int)b_order - (
int)a_order;
332 if (i != 0)
return i < 0;
333 if (j != 0)
return j < 0;
337 if (i != 0)
return i < 0;
357 if (ret.
Failed())
return ret;
378 std::vector<Vehicle *> vehs;
388 int num_vehs = (uint)vehs.size();
397 w->lateness_counter = 0;
400 w->timetable_start = start_tick + (idx * total_duration / num_vehs);
431 if (ret.
Failed())
return ret;
479 assert(real_current_order !=
nullptr);
483 ++first_manual_order;
486 bool just_started =
false;
511 if (travelling && remeasure_wait_time) {
517 if (just_started)
return;
520 if (!real_current_order->
IsType(OT_CONDITIONAL) &&
521 (travelling || time_taken > real_current_order->
GetWaitTime() || remeasure_wait_time)) {
534 }
else if (!travelling && (autofilling || !real_current_order->
IsWaitTimetabled())) {
547 if (autofilling)
return;
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
bool IsType(OrderType type) const
Check whether this order is of the given type.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
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.
void UpdateTimetableDuration(TimerGameTick::Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
@ MTF_TRAVEL_TIME
Set travel time.
Tindex index
Index of this pool item.
void SetTravelTimetabled(bool timetabled)
Set if the travel time is explicitly timetabled (unless the order is conditional).
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
static DateFract date_fract
Fractional part of the day.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Owner owner
Which company owns the vehicle?
uint64_t TickCounter
The type that the tick counter is stored in.
@ DC_EXEC
execute the given command
DoCommandFlag
List of flags for a command.
OrderType GetType() const
Get the type of order of this order.
static constexpr TimerGame< struct Economy >::Date MAX_DATE
The date of the last day of the max year.
void UpdateTotalDuration(TimerGameTick::Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
@ 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.
static constexpr int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Common return value for all commands.
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
uint16_t GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
bool Failed() const
Did this command fail?
Order current_order
The current order (+ status, like: loading)
static constexpr TimerGameTick::Ticks INVALID_TICKS
Representation of an invalid number of ticks.
void SetWaitTime(uint16_t time)
Set the time in ticks to wait at the destination.
uint32_t VehicleID
The type all our vehicle IDs have.
void SetTravelTime(uint16_t time)
Set the time in ticks to take for travelling to the destination.
void ResetDepotUnbunching()
Resets all the data used for depot unbunching.
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
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.
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
int32_t Ticks
The type to store ticks in.
static constexpr Date DateAtStartOfYear(Year year)
Calculate the date of the first day of a given year.
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
uint16_t GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
uint16_t GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
@ MTF_TRAVEL_SPEED
Set max travel speed.
UnitID unitnumber
unit number, for display purposes only
@ VF_AUTOFILL_PRES_WAIT_TIME
Whether non-destructive auto-fill should preserve waiting times.
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
@ VEH_AIRCRAFT
Aircraft vehicle type.
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
VehicleType type
Type of vehicle.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
TimerGameTick::Ticks GetTimetableTotalDuration() const
Gets the total duration of the vehicles timetable or Ticks::INVALID_TICKS is the timetable is not com...
void SetMaxSpeed(uint16_t speed)
Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
OrderList * orders
Pointer to the order list for this vehicle.
bool Equals(const Order &other) const
Does this order have the same type, flags and destination?
@ MTF_WAIT_TIME
Set wait time.
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).
static Date date
Current date in days (day counter).
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.