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:
176 default:
return CommandCost(STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
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);
482 for (
Order *o = v->
GetFirstOrder(); o !=
nullptr && o->IsType(OT_IMPLICIT); o = o->next) {
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)) {
532 uint time_to_set =
CeilDiv(std::max(time_taken, 1), factor) * factor;
536 }
else if (!travelling && (autofilling || !real_current_order->
IsWaitTimetabled())) {
549 if (autofilling)
return;
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Common return value for all commands.
bool Failed() const
Did this command fail?
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static constexpr TimerGameTick::Ticks INVALID_TICKS
Representation of an invalid number of ticks.
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
static constexpr TimerGame< struct Economy >::Date MAX_DATE
The date of the last day of the max year.
static constexpr int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
static Date date
Current date in days (day counter).
static DateFract date_fract
Fractional part of the day.
uint64_t TickCounter
The type that the tick counter is stored in.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
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.
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
DoCommandFlag
List of flags for a command.
@ DC_EXEC
execute the given command
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Functions related to companies.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
@ MTF_TRAVEL_TIME
Set travel time.
@ MTF_WAIT_TIME
Set wait time.
@ MTF_TRAVEL_SPEED
Set max travel speed.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Definition of base types and functions in a cross-platform compatible way.
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
void ResetDepotUnbunching()
Resets all the data used for depot unbunching.
VehicleType type
Type of vehicle.
GUISettings gui
settings related to the GUI
TimetableMode timetable_mode
Time units for timetables: days, seconds, or ticks.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
void UpdateTotalDuration(TimerGameTick::Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
void UpdateTimetableDuration(TimerGameTick::Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
TimerGameTick::Ticks GetTimetableTotalDuration() const
Gets the total duration of the vehicles timetable or Ticks::INVALID_TICKS is the timetable is not com...
uint16_t GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
bool Equals(const Order &other) const
Does this order have the same type, flags and destination?
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
void SetTravelTimetabled(bool timetabled)
Set if the travel time is explicitly timetabled (unless the order is conditional).
bool IsType(OrderType type) const
Check whether this order is of the given type.
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
OrderType GetType() const
Get the type of order of this order.
void SetWaitTime(uint16_t time)
Set the time in ticks to wait at the destination.
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
void SetTravelTime(uint16_t time)
Set the time in ticks to take for travelling to the destination.
void SetWaitTimetabled(bool timetabled)
Set if the wait time is explicitly timetabled (unless the order is conditional).
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
uint16_t GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
uint16_t GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
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.
Tindex index
Index of this pool item.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
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.
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Order current_order
The current order (+ status, like: loading)
OrderList * orders
Pointer to the order list for this vehicle.
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Owner owner
Which company owns the vehicle?
UnitID unitnumber
unit number, for display purposes only
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
Base class for all vehicles.
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
@ VF_AUTOFILL_PRES_WAIT_TIME
Whether non-destructive auto-fill should preserve waiting times.
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
@ VEH_AIRCRAFT
Aircraft vehicle type.
uint32_t VehicleID
The type all our vehicle IDs have.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Window functions not directly related to making/drawing windows.
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers: