Rename DateTicksScaled to StateTicks

Rename various other related/derived types and variables
pull/647/head
Jonathan G Rennison 3 months ago
parent 39b4772a34
commit 0ea57528c9

@ -22,7 +22,7 @@ struct BaseConsist {
/* Used for timetabling. */
uint32_t current_order_time; ///< How many ticks have passed since this order started.
int32_t lateness_counter; ///< How many ticks late (or early if negative) this vehicle is.
DateTicksScaled timetable_start; ///< When the vehicle is supposed to start the timetable.
StateTicks timetable_start; ///< When the vehicle is supposed to start the timetable.
uint16_t service_interval; ///< The interval for (automatic) servicing; either in days or %.

@ -32,8 +32,8 @@ DateFract _date_fract; ///< Fractional part of the day.
uint64_t _tick_counter; ///< Ever incrementing tick counter for setting off various events
uint8_t _tick_skip_counter; ///< Counter for ticks, when only vehicles are moving and nothing else happens
uint64_t _scaled_tick_counter; ///< Tick counter in daylength-scaled ticks
DateTicksScaled _scaled_date_ticks; ///< Date as ticks in daylength-scaled ticks
DateTicksScaled _scaled_date_ticks_offset; ///< Offset to add when generating _scaled_date_ticks
StateTicks _state_ticks; ///< Current state tick
StateTicks _state_ticks_offset; ///< Offset to add when calculating a StateTicks value from a date/date fract/tick skip counter
uint32_t _quit_after_days; ///< Quit after this many days of run time
YearMonthDay _game_load_cur_date_ymd;
@ -42,43 +42,43 @@ uint8_t _game_load_tick_skip_counter;
extern void ClearOutOfDateSignalSpeedRestrictions();
void CheckScaledDateTicksWrap()
void CheckStateTicksWrap()
{
DateTicksScaledDelta tick_adjust = 0;
auto get_tick_adjust = [&](DateTicksScaled target) {
StateTicksDelta tick_adjust = 0;
auto get_tick_adjust = [&](StateTicks target) {
int32_t rounding = _settings_time.time_in_minutes * 1440;
return target.AsDelta() - (target.base() % rounding);
};
if (_scaled_date_ticks >= ((int64_t)1 << 60)) {
tick_adjust = get_tick_adjust(_scaled_date_ticks);
} else if (_scaled_date_ticks <= -((int64_t)1 << 60)) {
tick_adjust = -get_tick_adjust(-(_scaled_date_ticks.base()));
if (_state_ticks >= ((int64_t)1 << 60)) {
tick_adjust = get_tick_adjust(_state_ticks);
} else if (_state_ticks <= -((int64_t)1 << 60)) {
tick_adjust = -get_tick_adjust(-(_state_ticks.base()));
} else {
return;
}
_scaled_date_ticks_offset -= tick_adjust;
_scaled_date_ticks -= tick_adjust;
_state_ticks_offset -= tick_adjust;
_state_ticks -= tick_adjust;
extern void AdjustAllSignalSpeedRestrictionTickValues(DateTicksScaledDelta delta);
extern void AdjustAllSignalSpeedRestrictionTickValues(StateTicksDelta delta);
AdjustAllSignalSpeedRestrictionTickValues(-tick_adjust);
extern void AdjustVehicleScaledTickBase(DateTicksScaledDelta delta);
AdjustVehicleScaledTickBase(-tick_adjust);
extern void AdjustVehicleStateTicksBase(StateTicksDelta delta);
AdjustVehicleStateTicksBase(-tick_adjust);
extern void AdjustLinkGraphScaledTickBase(DateTicksScaledDelta delta);
AdjustLinkGraphScaledTickBase(-tick_adjust);
extern void AdjustLinkGraphStateTicksBase(StateTicksDelta delta);
AdjustLinkGraphStateTicksBase(-tick_adjust);
}
void RebaseScaledDateTicksBase()
void RebaseStateTicksBase()
{
DateTicksScaled old_scaled_date_ticks = _scaled_date_ticks;
StateTicks old_state_ticks = _state_ticks;
SetScaledTickVariables();
_scaled_date_ticks_offset += (old_scaled_date_ticks - _scaled_date_ticks);
_state_ticks_offset += (old_state_ticks - _state_ticks);
SetScaledTickVariables();
assert(old_scaled_date_ticks == _scaled_date_ticks);
assert(old_state_ticks == _state_ticks);
CheckScaledDateTicksWrap();
CheckStateTicksWrap();
}
/**
@ -86,7 +86,7 @@ void RebaseScaledDateTicksBase()
* @param date New date
* @param fract The number of ticks that have passed on this date.
*/
void SetDate(Date date, DateFract fract, bool preserve_scaled_ticks)
void SetDate(Date date, DateFract fract, bool preserve_state_tick)
{
assert(fract < DAY_TICKS);
@ -94,8 +94,8 @@ void SetDate(Date date, DateFract fract, bool preserve_scaled_ticks)
_date_fract = fract;
YearMonthDay ymd = ConvertDateToYMD(date);
_cur_date_ymd = ymd;
if (preserve_scaled_ticks) {
RebaseScaledDateTicksBase();
if (preserve_state_tick) {
RebaseStateTicksBase();
} else {
SetScaledTickVariables();
}
@ -104,7 +104,7 @@ void SetDate(Date date, DateFract fract, bool preserve_scaled_ticks)
void SetScaledTickVariables()
{
_scaled_date_ticks = ((int64_t)(DateToDateTicks(_date, _date_fract).base()) * _settings_game.economy.day_length_factor) + _tick_skip_counter + _scaled_date_ticks_offset;
_state_ticks = ((int64_t)(DateToDateTicks(_date, _date_fract).base()) * _settings_game.economy.day_length_factor) + _tick_skip_counter + _state_ticks_offset;
}
#define M(a, b) ((a << 5) | b)
@ -270,14 +270,14 @@ static void OnNewYear()
LinkGraphSchedule::instance.ShiftDates(-days_this_year);
ShiftOrderDates(-days_this_year);
ShiftVehicleDates(-days_this_year);
_scaled_date_ticks_offset += ((int64_t)days_this_year) * (DAY_TICKS * _settings_game.economy.day_length_factor);
_state_ticks_offset += ((int64_t)days_this_year) * (DAY_TICKS * _settings_game.economy.day_length_factor);
/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out
* all of them if the date is set back, else those messages will hang for ever */
NetworkInitChatMessage();
}
CheckScaledDateTicksWrap();
CheckStateTicksWrap();
if (_settings_client.gui.auto_euro) CheckSwitchToEuro();
IConsoleCmdExec("exec scripts/on_newyear.scr 0");

@ -20,8 +20,8 @@ extern DateFract _date_fract;
extern uint64_t _tick_counter;
extern uint8_t _tick_skip_counter;
extern uint64_t _scaled_tick_counter;
extern DateTicksScaled _scaled_date_ticks;
extern DateTicksScaled _scaled_date_ticks_offset;
extern StateTicks _state_ticks;
extern StateTicks _state_ticks_offset;
extern uint32_t _quit_after_days;
extern YearMonthDay _game_load_cur_date_ymd;
@ -50,24 +50,24 @@ inline bool IsLeapYear(Year yr)
return yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0);
}
inline Date ScaledDateTicksToDate(DateTicksScaled ticks)
inline Date StateTicksToDate(StateTicks ticks)
{
return (ticks.base() - _scaled_date_ticks_offset.base()) / (DAY_TICKS * _settings_game.economy.day_length_factor);
return (ticks.base() - _state_ticks_offset.base()) / (DAY_TICKS * _settings_game.economy.day_length_factor);
}
inline DateTicksScaled DateToScaledDateTicks(Date date)
inline StateTicks DateToStateTicks(Date date)
{
return ((int64_t)date.base() * DAY_TICKS * _settings_game.economy.day_length_factor) + _scaled_date_ticks_offset.base();
return ((int64_t)date.base() * DAY_TICKS * _settings_game.economy.day_length_factor) + _state_ticks_offset.base();
}
inline DateTicks ScaledDateTicksToDateTicks(DateTicksScaled ticks)
inline DateTicks StateTicksToDateTicks(StateTicks ticks)
{
return (ticks.base() - _scaled_date_ticks_offset.base()) / _settings_game.economy.day_length_factor;
return (ticks.base() - _state_ticks_offset.base()) / _settings_game.economy.day_length_factor;
}
inline DateTicksScaled DateTicksToScaledDateTicks(DateTicks date_ticks)
inline StateTicks DateTicksToStateTicks(DateTicks date_ticks)
{
return ((int64_t)date_ticks.base() * _settings_game.economy.day_length_factor) + _scaled_date_ticks_offset.base();
return ((int64_t)date_ticks.base() * _settings_game.economy.day_length_factor) + _state_ticks_offset.base();
}
/**

@ -24,7 +24,7 @@
/** Window to select a date graphically by using dropdowns */
struct SetDateWindow : Window {
SetDateCallback *callback; ///< Callback to call when a date has been selected
SetTickCallback *callback; ///< Callback to call when a date has been selected
YearMonthDay date; ///< The currently selected date
Year min_year; ///< The minimum year in the year dropdown
Year max_year; ///< The maximum year (inclusive) in the year dropdown
@ -40,7 +40,7 @@ struct SetDateWindow : Window {
* @param callback the callback to call once a date has been selected
*/
SetDateWindow(WindowDesc *desc, WindowNumber window_number, Window *parent, Date initial_date, Year min_year, Year max_year,
SetDateCallback *callback, StringID button_text, StringID button_tooltip) :
SetTickCallback *callback, StringID button_text, StringID button_tooltip) :
Window(desc),
callback(callback),
min_year(std::max(MIN_YEAR, min_year)),
@ -153,7 +153,7 @@ struct SetDateWindow : Window {
break;
case WID_SD_SET_DATE:
if (this->callback != nullptr) {
this->callback(this, DateToScaledDateTicks(ConvertYMDToDate(this->date.year, this->date.month, this->date.day)));
this->callback(this, DateToStateTicks(ConvertYMDToDate(this->date.year, this->date.month, this->date.day)));
}
this->Close();
break;
@ -184,10 +184,10 @@ struct SetMinutesWindow : SetDateWindow
TickMinutes minutes;
/** Constructor. */
SetMinutesWindow(WindowDesc *desc, WindowNumber window_number, Window *parent, DateTicksScaled initial_date, Year min_year, Year max_year,
SetDateCallback *callback, StringID button_text, StringID button_tooltip) :
SetMinutesWindow(WindowDesc *desc, WindowNumber window_number, Window *parent, StateTicks initial_tick, Year min_year, Year max_year,
SetTickCallback *callback, StringID button_text, StringID button_tooltip) :
SetDateWindow(desc, window_number, parent, 0, min_year, max_year, callback, button_text, button_tooltip),
minutes(_settings_time.ToTickMinutes(initial_date))
minutes(_settings_time.ToTickMinutes(initial_tick))
{
}
@ -361,19 +361,19 @@ static WindowDesc _set_minutes_desc(__FILE__, __LINE__,
* Create the new 'set date' window
* @param window_number number for the window
* @param parent the parent window, i.e. if this closes we should close too
* @param initial_date the initial date to show
* @param initial_tick the initial tick to show
* @param min_year the minimum year to show in the year dropdown
* @param max_year the maximum year (inclusive) to show in the year dropdown
* @param callback the callback to call once a date has been selected
*/
void ShowSetDateWindow(Window *parent, int window_number, DateTicksScaled initial_date, Year min_year, Year max_year,
SetDateCallback *callback, StringID button_text, StringID button_tooltip)
void ShowSetDateWindow(Window *parent, int window_number, StateTicks initial_tick, Year min_year, Year max_year,
SetTickCallback *callback, StringID button_text, StringID button_tooltip)
{
CloseWindowByClass(WC_SET_DATE);
if (!_settings_time.time_in_minutes) {
new SetDateWindow(&_set_date_desc, window_number, parent, ScaledDateTicksToDate(initial_date), min_year, max_year, callback, button_text, button_tooltip);
new SetDateWindow(&_set_date_desc, window_number, parent, StateTicksToDate(initial_tick), min_year, max_year, callback, button_text, button_tooltip);
} else {
new SetMinutesWindow(&_set_minutes_desc, window_number, parent, initial_date, min_year, max_year, callback, button_text, button_tooltip);
new SetMinutesWindow(&_set_minutes_desc, window_number, parent, initial_tick, min_year, max_year, callback, button_text, button_tooltip);
}
}

@ -14,13 +14,13 @@
#include "window_type.h"
/**
* Callback for when a date has been chosen
* Callback for when a tick has been chosen
* @param w the window that sends the callback
* @param date the date that has been chosen
* @param tick the tick that has been chosen
*/
typedef void SetDateCallback(const Window *w, DateTicksScaled date);
typedef void SetTickCallback(const Window *w, StateTicks tick);
void ShowSetDateWindow(Window *parent, int window_number, DateTicksScaled initial_date, Year min_year, Year max_year, SetDateCallback *callback,
void ShowSetDateWindow(Window *parent, int window_number, StateTicks initial_tick, Year min_year, Year max_year, SetTickCallback *callback,
StringID button_text = STR_NULL, StringID button_tooltip = STR_NULL);
#endif /* DATE_GUI_H */

@ -54,8 +54,8 @@ struct DateTicksOperations {
using DateTicksDelta = StrongType::Typedef<int64_t, struct DateTicksDeltaTag, StrongType::Compare, StrongType::IntegerScalable>;
using DateTicks = StrongType::Typedef<int64_t, struct DateTicksTag, StrongType::Compare, StrongType::IntegerDelta<DateTicksDelta>, DateTicksOperations>;
/* Mixin for DateTicksScaledDelta */
struct DateTicksScaledDeltaOperations {
/* Mixin for StateTicksDelta */
struct StateTicksDeltaOperations {
template <typename TType, typename TBaseType>
struct mixin {
private:
@ -69,9 +69,9 @@ struct DateTicksScaledDeltaOperations {
};
};
/* The type to store dates scaled by the day length factor in when tick-precision is required */
using DateTicksScaledDelta = StrongType::Typedef<int64_t, struct DateTicksScaledDeltaTag, StrongType::Compare, StrongType::IntegerScalable, DateTicksScaledDeltaOperations>;
using DateTicksScaled = StrongType::Typedef<int64_t, struct DateTicksScaledTag, StrongType::Compare, StrongType::IntegerDelta<DateTicksScaledDelta>>;
/* The type to store state ticks (this always ticks at the same rate regardless of day length, even in the scenario editor */
using StateTicksDelta = StrongType::Typedef<int64_t, struct StateTicksDeltaTag, StrongType::Compare, StrongType::IntegerScalable, StateTicksDeltaOperations>;
using StateTicks = StrongType::Typedef<int64_t, struct StateTicksTag, StrongType::Compare, StrongType::IntegerDelta<StateTicksDelta>>;
/* Mixin for TickMinutes, ClockFaceMinutes */
template <bool TNegativeCheck>
@ -134,7 +134,7 @@ struct TickMinuteOperations {
};
};
/* The type to store DateTicksScaled-based minutes in */
/* The type to store StateTicks-based minutes in */
using TickMinutes = StrongType::Typedef<int64_t, struct TickMinutesTag, StrongType::Compare, StrongType::Integer, MinuteOperations<true>, TickMinuteOperations>;
#define DATE_UNIT_SIZE (_settings_time.time_in_minutes ? _settings_time.ticks_per_minute : (DAY_TICKS * _settings_game.economy.day_length_factor))

@ -40,7 +40,7 @@
#include <algorithm>
/* A cache of used departure time for scheduled dispatch in departure time calculation */
typedef btree::btree_map<const DispatchSchedule *, btree::btree_set<DateTicksScaled>> schdispatch_cache_t;
typedef btree::btree_map<const DispatchSchedule *, btree::btree_set<StateTicks>> schdispatch_cache_t;
/** A scheduled order. */
struct OrderDate {
@ -87,21 +87,21 @@ static bool IsArrival(const Order *order, StationID station) {
!(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION));
}
static uint8_t GetDepartureConditionalOrderMode(const Order *order, const Vehicle *v, DateTicksScaled eval_date)
static uint8_t GetDepartureConditionalOrderMode(const Order *order, const Vehicle *v, StateTicks eval_tick)
{
if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) return 1;
if (order->GetConditionVariable() == OCV_TIME_DATE) {
int value = GetTraceRestrictTimeDateValueFromDate(static_cast<TraceRestrictTimeDateValueField>(order->GetConditionValue()), eval_date);
int value = GetTraceRestrictTimeDateValueFromStateTicks(static_cast<TraceRestrictTimeDateValueField>(order->GetConditionValue()), eval_tick);
return OrderConditionCompare(order->GetConditionComparator(), value, order->GetXData()) ? 1 : 2;
}
if (order->GetConditionVariable() == OCV_DISPATCH_SLOT) {
extern bool EvaluateDispatchSlotConditionalOrder(const Order *order, const Vehicle *v, DateTicksScaled date_time, bool *predicted);
return EvaluateDispatchSlotConditionalOrder(order, v, eval_date, nullptr) ? 1 : 2;
extern bool EvaluateDispatchSlotConditionalOrder(const Order *order, const Vehicle *v, StateTicks state_ticks, bool *predicted);
return EvaluateDispatchSlotConditionalOrder(order, v, eval_tick, nullptr) ? 1 : 2;
}
return _settings_client.gui.departure_conditionals;
}
static bool VehicleSetNextDepartureTime(Ticks *previous_departure, Ticks *waiting_time, const DateTicksScaled date_ticks_base, const Vehicle *v, const Order *order, bool arrived_at_timing_point, schdispatch_cache_t &dept_schedule_last)
static bool VehicleSetNextDepartureTime(Ticks *previous_departure, Ticks *waiting_time, const StateTicks state_ticks_base, const Vehicle *v, const Order *order, bool arrived_at_timing_point, schdispatch_cache_t &dept_schedule_last)
{
if (HasBit(v->vehicle_flags, VF_SCHEDULED_DISPATCH)) {
auto is_current_implicit_order = [&v](const Order *o) -> bool {
@ -114,27 +114,27 @@ static bool VehicleSetNextDepartureTime(Ticks *previous_departure, Ticks *waitin
if (order->IsScheduledDispatchOrder(true) && !(arrived_at_timing_point && is_current_implicit_order(order))) {
const DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(order->GetDispatchScheduleIndex());
DateTicksScaled actual_departure = -1;
const DateTicksScaled begin_time = ds.GetScheduledDispatchStartTick();
StateTicks actual_departure = -1;
const StateTicks begin_time = ds.GetScheduledDispatchStartTick();
const uint32_t dispatch_duration = ds.GetScheduledDispatchDuration();
const int32_t max_delay = ds.GetScheduledDispatchDelay();
/* Earliest possible departure according to schedue */
DateTicksScaled earliest_departure = begin_time + ds.GetScheduledDispatchLastDispatch();
StateTicks earliest_departure = begin_time + ds.GetScheduledDispatchLastDispatch();
/* Earliest possible departure according to vehicle current timetable */
const DateTicksScaled ready_to_depart_time = date_ticks_base + *previous_departure + order->GetTravelTime() + order->GetTimetabledWait();
const StateTicks ready_to_depart_time = state_ticks_base + *previous_departure + order->GetTravelTime() + order->GetTimetabledWait();
if (earliest_departure + max_delay < ready_to_depart_time) {
earliest_departure = ready_to_depart_time - max_delay - 1;
/* -1 because this number is actually a moment before actual departure */
}
btree::btree_set<DateTicksScaled> &slot_cache = dept_schedule_last[&ds];
btree::btree_set<StateTicks> &slot_cache = dept_schedule_last[&ds];
/* Find next available slots */
for (const DispatchSlot &slot : ds.GetScheduledDispatch()) {
if (slot.offset >= dispatch_duration) continue;
DateTicksScaled current_departure = begin_time + slot.offset;
StateTicks current_departure = begin_time + slot.offset;
while (current_departure <= earliest_departure) {
current_departure += dispatch_duration;
}
@ -153,8 +153,8 @@ static bool VehicleSetNextDepartureTime(Ticks *previous_departure, Ticks *waitin
}
}
*waiting_time = (actual_departure - date_ticks_base).AsTicks() - *previous_departure - order->GetTravelTime();
*previous_departure = (actual_departure - date_ticks_base).AsTicks();
*waiting_time = (actual_departure - state_ticks_base).AsTicks() - *previous_departure - order->GetTravelTime();
*previous_departure = (actual_departure - state_ticks_base).AsTicks();
if (!ds.GetScheduledDispatchReuseSlots()) {
slot_cache.insert(actual_departure);
}
@ -191,24 +191,24 @@ static void ScheduledDispatchDepartureLocalFix(DepartureList *departure_list)
/* If the group is scheduled dispatch, then */
if (HasBit(d_list[0]->vehicle->vehicle_flags, VF_SCHEDULED_DISPATCH)) {
/* Separate departure time and sort them ascendently */
std::vector<DateTicksScaled> departure_time_list;
std::vector<StateTicks> departure_time_list;
for (const auto& d : d_list) {
departure_time_list.push_back(d->scheduled_date);
departure_time_list.push_back(d->scheduled_tick);
}
std::sort(departure_time_list.begin(), departure_time_list.end());
/* Sort the departure list by arrival time */
std::sort(d_list.begin(), d_list.end(), [](const Departure * const &a, const Departure * const &b) -> bool {
DateTicksScaled arr_a = a->scheduled_date - a->EffectiveWaitingTime();
DateTicksScaled arr_b = b->scheduled_date - b->EffectiveWaitingTime();
StateTicks arr_a = a->scheduled_tick - a->EffectiveWaitingTime();
StateTicks arr_b = b->scheduled_tick - b->EffectiveWaitingTime();
return arr_a < arr_b;
});
/* Re-assign them sequentially */
for (size_t i = 0; i < d_list.size(); i++) {
const DateTicksScaled arrival = d_list[i]->scheduled_date - d_list[i]->EffectiveWaitingTime();
const StateTicks arrival = d_list[i]->scheduled_tick - d_list[i]->EffectiveWaitingTime();
d_list[i]->scheduled_waiting_time = (departure_time_list[i] - arrival).AsTicks();
d_list[i]->scheduled_date = departure_time_list[i];
d_list[i]->scheduled_tick = departure_time_list[i];
if (d_list[i]->scheduled_waiting_time == (Ticks)d_list[i]->order->GetWaitTime()) {
d_list[i]->scheduled_waiting_time = 0;
@ -219,7 +219,7 @@ static void ScheduledDispatchDepartureLocalFix(DepartureList *departure_list)
/* Re-sort the departure list */
std::sort(departure_list->begin(), departure_list->end(), [](Departure * const &a, Departure * const &b) -> bool {
return a->scheduled_date < b->scheduled_date;
return a->scheduled_tick < b->scheduled_tick;
});
}
@ -253,7 +253,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
/* The maximum possible date for departures to be scheduled to occur. */
const Ticks max_ticks = GetDeparturesMaxTicksAhead();
const DateTicksScaled date_ticks_base = _scaled_date_ticks;
const StateTicks state_ticks_base = _state_ticks;
/* The scheduled order in next_orders with the earliest expected_tick field. */
OrderDate *least_order = nullptr;
@ -321,13 +321,13 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
/* Loop through the vehicle's orders until we've found a suitable order or we've determined that no such order exists. */
/* We only need to consider each order at most once. */
for (int i = v->GetNumOrders(); i > 0; --i) {
if (VehicleSetNextDepartureTime(&start_ticks, &waiting_time, date_ticks_base, v, order, status == D_ARRIVED, schdispatch_last_planned_dispatch)) {
if (VehicleSetNextDepartureTime(&start_ticks, &waiting_time, state_ticks_base, v, order, status == D_ARRIVED, schdispatch_last_planned_dispatch)) {
should_reset_lateness = true;
}
/* If the order is a conditional branch, handle it. */
if (order->IsType(OT_CONDITIONAL)) {
switch(GetDepartureConditionalOrderMode(order, v, date_ticks_base + start_ticks)) {
switch(GetDepartureConditionalOrderMode(order, v, state_ticks_base + start_ticks)) {
case 0: {
/* Give up */
break;
@ -453,7 +453,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
/* We already know the least order and that it's a suitable departure, so make it into a departure. */
Departure *d = new Departure();
d->scheduled_date = date_ticks_base + least_order->expected_tick - least_order->lateness;
d->scheduled_tick = state_ticks_base + least_order->expected_tick - least_order->lateness;
d->lateness = least_order->lateness;
d->status = least_order->status;
d->vehicle = least_order->v;
@ -486,7 +486,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
order = (order->next == nullptr) ? least_order->v->GetFirstOrder() : order->next;
/* We only need to consider each order at most once. */
bool found_terminus = false;
CallAt c = CallAt((StationID)order->GetDestination(), d->scheduled_date);
CallAt c = CallAt((StationID)order->GetDestination(), d->scheduled_tick);
for (int i = least_order->v->GetNumOrders(); i > 0; --i) {
/* If we reach the order at which the departure occurs again, then use the departure station as the terminus. */
if (order == least_order->order) {
@ -497,23 +497,23 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
/* If the order is a conditional branch, handle it. */
if (order->IsType(OT_CONDITIONAL)) {
switch (GetDepartureConditionalOrderMode(order, least_order->v, c.scheduled_date != 0 ? c.scheduled_date : _scaled_date_ticks)) {
switch (GetDepartureConditionalOrderMode(order, least_order->v, c.scheduled_tick != 0 ? c.scheduled_tick : _state_ticks)) {
case 0: {
/* Give up */
break;
}
case 1: {
/* Take the branch */
if (c.scheduled_date != 0 && (order->GetWaitTime() != 0 || order->IsWaitTimetabled())) {
c.scheduled_date += order->GetWaitTime();
if (c.scheduled_tick != 0 && (order->GetWaitTime() != 0 || order->IsWaitTimetabled())) {
c.scheduled_tick += order->GetWaitTime();
} else {
c.scheduled_date = 0;
c.scheduled_tick = 0;
}
order = least_order->v->GetOrder(order->GetConditionSkipToOrder());
if (order == nullptr) {
break;
}
if (c.scheduled_date != 0) c.scheduled_date -= order->GetTravelTime();
if (c.scheduled_tick != 0) c.scheduled_tick -= order->GetTravelTime();
continue;
}
case 2: {
@ -561,10 +561,10 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
d->remove_vias.push_back({ (StationID)order->GetDestination(), (uint)(d->calling_at.size() - 1) });
}
if (c.scheduled_date != 0 && (order->GetTravelTime() != 0 || order->IsTravelTimetabled())) {
c.scheduled_date += order->GetTravelTime(); /* TODO smart terminal may not work correctly */
if (c.scheduled_tick != 0 && (order->GetTravelTime() != 0 || order->IsTravelTimetabled())) {
c.scheduled_tick += order->GetTravelTime(); /* TODO smart terminal may not work correctly */
} else {
c.scheduled_date = 0;
c.scheduled_tick = 0;
}
c.station = (StationID)order->GetDestination();
@ -576,7 +576,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
order->GetType() != OT_IMPLICIT) ||
order->GetNonStopType() == ONSF_NO_STOP_AT_ANY_STATION ||
order->GetNonStopType() == ONSF_NO_STOP_AT_DESTINATION_STATION) {
if (c.scheduled_date != 0) c.scheduled_date += order->GetWaitTime();
if (c.scheduled_tick != 0) c.scheduled_tick += order->GetWaitTime();
order = (order->next == nullptr) ? least_order->v->GetFirstOrder() : order->next;
continue;
}
@ -612,7 +612,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
break;
}
if (c.scheduled_date != 0) c.scheduled_date += order->GetWaitTime();
if (c.scheduled_tick != 0) c.scheduled_tick += order->GetWaitTime();
/* Get the next order, which may be the vehicle's first order. */
order = (order->next == nullptr) ? least_order->v->GetFirstOrder() : order->next;
@ -684,7 +684,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
/* Again, we define a station as being called at if the vehicle loads from it. */
/* However, the very first thing we do is use the arrival time as the scheduled time instead of the departure time. */
d->scheduled_date -= d->scheduled_waiting_time > 0 ? d->scheduled_waiting_time : order->GetWaitTime();
d->scheduled_tick -= d->scheduled_waiting_time > 0 ? d->scheduled_waiting_time : order->GetWaitTime();
const Order *candidate_origin = (order->next == nullptr) ? least_order->v->GetFirstOrder() : order->next;
bool found_origin = false;
@ -769,7 +769,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
/* Go to the next order so we don't add the current order again. */
order = (order->next == nullptr) ? least_order->v->GetFirstOrder() : order->next;
if (VehicleSetNextDepartureTime(&least_order->expected_tick, &least_order->scheduled_waiting_time, date_ticks_base, least_order->v, order, false, schdispatch_last_planned_dispatch)) {
if (VehicleSetNextDepartureTime(&least_order->expected_tick, &least_order->scheduled_waiting_time, state_ticks_base, least_order->v, order, false, schdispatch_last_planned_dispatch)) {
least_order->lateness = 0;
}
@ -793,7 +793,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
}
least_order->expected_tick -= order->GetTravelTime(); /* Added in next VehicleSetNextDepartureTime */
if (VehicleSetNextDepartureTime(&least_order->expected_tick, &least_order->scheduled_waiting_time, date_ticks_base, least_order->v, order, false, schdispatch_last_planned_dispatch)) {
if (VehicleSetNextDepartureTime(&least_order->expected_tick, &least_order->scheduled_waiting_time, state_ticks_base, least_order->v, order, false, schdispatch_last_planned_dispatch)) {
least_order->lateness = 0;
}
require_travel_time = false;
@ -803,7 +803,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
/* Do not take the branch */
least_order->expected_tick -= order->GetWaitTime(); /* Added previously in VehicleSetNextDepartureTime */
order = (order->next == nullptr) ? least_order->v->GetFirstOrder() : order->next;
if (VehicleSetNextDepartureTime(&least_order->expected_tick, &least_order->scheduled_waiting_time, date_ticks_base, least_order->v, order, false, schdispatch_last_planned_dispatch)) {
if (VehicleSetNextDepartureTime(&least_order->expected_tick, &least_order->scheduled_waiting_time, state_ticks_base, least_order->v, order, false, schdispatch_last_planned_dispatch)) {
least_order->lateness = 0;
}
require_travel_time = true;
@ -833,7 +833,7 @@ DepartureList* MakeDepartureList(StationID station, const std::vector<const Vehi
}
order = (order->next == nullptr) ? least_order->v->GetFirstOrder() : order->next;
if (VehicleSetNextDepartureTime(&least_order->expected_tick, &least_order->scheduled_waiting_time, date_ticks_base, least_order->v, order, false, schdispatch_last_planned_dispatch)) {
if (VehicleSetNextDepartureTime(&least_order->expected_tick, &least_order->scheduled_waiting_time, state_ticks_base, least_order->v, order, false, schdispatch_last_planned_dispatch)) {
least_order->lateness = 0;
}
require_travel_time = true;

@ -424,7 +424,7 @@ public:
d = (*(this->departures))[departure];
const Departure *a = (*(this->arrivals))[arrival];
if (a->scheduled_date < d->scheduled_date) {
if (a->scheduled_tick < d->scheduled_tick) {
d = a;
arrival++;
} else {
@ -745,8 +745,8 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
uint departure = 0;
uint arrival = 0;
DateTicksScaled now_date = _scaled_date_ticks;
DateTicksScaled max_date = now_date + GetDeparturesMaxTicksAhead();
StateTicks now_date = _state_ticks;
StateTicks max_date = now_date + GetDeparturesMaxTicksAhead();
/* Draw each departure. */
for (uint i = 0; i < max_departures; ++i) {
@ -760,7 +760,7 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
d = (*(this->departures))[departure];
const Departure *a = (*(this->arrivals))[arrival];
if (a->scheduled_date < d->scheduled_date) {
if (a->scheduled_tick < d->scheduled_tick) {
d = a;
arrival++;
} else {
@ -773,7 +773,7 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
}
/* If for some reason the departure is too far in the future or is at a negative time, skip it. */
if (d->scheduled_date > max_date || d->scheduled_date < 0) {
if (d->scheduled_tick > max_date || d->scheduled_tick < 0) {
continue;
}
@ -784,8 +784,8 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
if (_settings_client.gui.departure_show_both) time_str = STR_DEPARTURES_TIME_BOTH;
/* Time */
SetDParam(0, d->scheduled_date);
SetDParam(1, d->scheduled_date - (d->scheduled_waiting_time > 0 ? d->scheduled_waiting_time : d->order->GetWaitTime()));
SetDParam(0, d->scheduled_tick);
SetDParam(1, d->scheduled_tick - (d->scheduled_waiting_time > 0 ? d->scheduled_waiting_time : d->order->GetWaitTime()));
ltr ? DrawString( text_left, text_left + time_width, y + 1, time_str)
: DrawString(text_right - time_width, text_right, y + 1, time_str);
@ -928,17 +928,17 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
/* The vehicle has been cancelled. */
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_CANCELLED);
} else{
if (d->lateness <= DATE_UNIT_SIZE && d->scheduled_date > now_date) {
if (d->lateness <= DATE_UNIT_SIZE && d->scheduled_tick > now_date) {
/* We have no evidence that the vehicle is late, so assume it is on time. */
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_ON_TIME);
} else {
if ((d->scheduled_date + d->lateness) < now_date) {
if ((d->scheduled_tick + d->lateness) < now_date) {
/* The vehicle was expected to have arrived by now, even if we knew it was going to be late. */
/* We assume that the train stays at least a day at a station so it won't accidentally be marked as delayed for a fraction of a day. */
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_DELAYED);
} else {
/* The vehicle is expected to be late and is not yet due to arrive. */
SetDParam(0, d->scheduled_date + d->lateness);
SetDParam(0, d->scheduled_tick + d->lateness);
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_EXPECTED);
}
}

@ -32,11 +32,11 @@ enum DepartureType : uint8_t {
struct CallAt {
StationID station;
DateTicksScaled scheduled_date;
StateTicks scheduled_tick;
CallAt(const StationID& s) : station(s), scheduled_date(0) { }
CallAt(const StationID& s, DateTicksScaled t) : station(s), scheduled_date(t) { }
CallAt(const CallAt& c) : station(c.station), scheduled_date(c.scheduled_date) { }
CallAt(const StationID& s) : station(s), scheduled_tick(0) { }
CallAt(const StationID& s, StateTicks t) : station(s), scheduled_tick(t) { }
CallAt(const CallAt& c) : station(c.station), scheduled_tick(c.scheduled_tick) { }
inline bool operator==(const CallAt& c) const {
return this->station == c.station;
@ -48,14 +48,14 @@ struct CallAt {
inline bool operator>=(const CallAt& c) const {
return this->station == c.station &&
this->scheduled_date != 0 &&
c.scheduled_date != 0 &&
this->scheduled_date >= c.scheduled_date;
this->scheduled_tick != 0 &&
c.scheduled_tick != 0 &&
this->scheduled_tick >= c.scheduled_tick;
}
CallAt& operator=(const CallAt& c) {
this->station = c.station;
this->scheduled_date = c.scheduled_date;
this->scheduled_tick = c.scheduled_tick;
return *this;
}
@ -71,7 +71,7 @@ struct RemoveVia {
/** A scheduled departure. */
struct Departure {
DateTicksScaled scheduled_date; ///< The date this departure is scheduled to finish on (i.e. when the vehicle leaves the station)
StateTicks scheduled_tick; ///< The tick this departure is scheduled to finish on (i.e. when the vehicle leaves the station)
Ticks lateness; ///< How delayed the departure is expected to be
StationID via; ///< The station the departure should list as going via
StationID via2; ///< Secondary station the departure should list as going via
@ -93,7 +93,7 @@ struct Departure {
}
return
(this->scheduled_date.base() / DATE_UNIT_SIZE) == (d.scheduled_date.base() / DATE_UNIT_SIZE) &&
(this->scheduled_tick.base() / DATE_UNIT_SIZE) == (d.scheduled_tick.base() / DATE_UNIT_SIZE) &&
this->vehicle->type == d.vehicle->type &&
this->via == d.via &&
this->via2 == d.via2 &&

@ -53,7 +53,7 @@ void FlowMapper::Run(LinkGraphJob &job) const
/* Scale by time the graph has been running without being compressed. Add 1 to avoid
* division by 0 if spawn date == last compression date. This matches
* LinkGraph::Monthly(). */
uint runtime = (uint)Clamp<DateTicksScaledDelta>(DateTicksToScaledDateTicks(job.StartDateTicks()) - job.LastCompression() + 1, 1, UINT32_MAX).base();
uint runtime = (uint)Clamp<StateTicksDelta>(DateTicksToStateTicks(job.StartDateTicks()) - job.LastCompression() + 1, 1, UINT32_MAX).base();
for (auto &it : flows) {
it.ScaleToMonthly(runtime);
}

@ -54,7 +54,7 @@ void LinkGraph::ShiftDates(DateDelta interval)
void LinkGraph::Compress()
{
this->last_compression = (_scaled_date_ticks.base() + this->last_compression.base()) / 2;
this->last_compression = (_state_ticks.base() + this->last_compression.base()) / 2;
for (NodeID node1 = 0; node1 < this->Size(); ++node1) {
this->nodes[node1].supply /= 2;
}
@ -79,8 +79,8 @@ void LinkGraph::Compress()
*/
void LinkGraph::Merge(LinkGraph *other)
{
uint32_t age = ClampTo<uint32_t>(CeilDivT<int64_t>(_scaled_date_ticks.base() - this->last_compression.base() + 1, DAY_TICKS));
uint32_t other_age = ClampTo<uint32_t>(CeilDivT<int64_t>(_scaled_date_ticks.base() - other->last_compression.base() + 1, DAY_TICKS));
uint32_t age = ClampTo<uint32_t>(CeilDivT<int64_t>(_state_ticks.base() - this->last_compression.base() + 1, DAY_TICKS));
uint32_t other_age = ClampTo<uint32_t>(CeilDivT<int64_t>(_state_ticks.base() - other->last_compression.base() + 1, DAY_TICKS));
NodeID first = this->Size();
this->nodes.reserve(first + other->Size());
for (NodeID node1 = 0; node1 < other->Size(); ++node1) {
@ -266,7 +266,7 @@ void LinkGraph::Init(uint size)
this->nodes.resize(size);
}
void AdjustLinkGraphScaledTickBase(DateTicksScaledDelta delta)
void AdjustLinkGraphStateTicksBase(StateTicksDelta delta)
{
for (LinkGraph *lg : LinkGraph::Iterate()) lg->last_compression += delta;
@ -278,11 +278,11 @@ void AdjustLinkGraphScaledTickBase(DateTicksScaledDelta delta)
void LinkGraphFixupLastCompressionAfterLoad()
{
/* last_compression was previously a Date, change it to a DateTicksScaled */
for (LinkGraph *lg : LinkGraph::Iterate()) lg->last_compression = DateToScaledDateTicks((Date)lg->last_compression.base());
/* last_compression was previously a Date, change it to a StateTicks */
for (LinkGraph *lg : LinkGraph::Iterate()) lg->last_compression = DateToStateTicks((Date)lg->last_compression.base());
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
LinkGraph *lg = &(const_cast<LinkGraph &>(lgj->Graph()));
lg->last_compression = DateToScaledDateTicks((Date)lg->last_compression.base());
lg->last_compression = DateToStateTicks((Date)lg->last_compression.base());
}
}

@ -290,7 +290,7 @@ public:
static constexpr DateDelta STALE_LINK_DEPOT_TIMEOUT = 1024;
/** Minimum number of ticks between subsequent compressions of a LG. */
static constexpr DateTicksScaledDelta COMPRESSION_INTERVAL = 256 * DAY_TICKS;
static constexpr StateTicksDelta COMPRESSION_INTERVAL = 256 * DAY_TICKS;
/**
* Scale a value from a link graph of age orig_age for usage in one of age
@ -311,7 +311,7 @@ public:
* Real constructor.
* @param cargo Cargo the link graph is about.
*/
LinkGraph(CargoID cargo) : cargo(cargo), last_compression(_scaled_date_ticks) {}
LinkGraph(CargoID cargo) : cargo(cargo), last_compression(_state_ticks) {}
void Init(uint size);
void ShiftDates(DateDelta interval);
@ -350,7 +350,7 @@ public:
* Get date of last compression.
* @return Date of last compression.
*/
inline DateTicksScaled LastCompression() const { return this->last_compression; }
inline StateTicks LastCompression() const { return this->last_compression; }
/**
* Get the cargo ID this component's link graph refers to.
@ -365,7 +365,7 @@ public:
*/
inline uint Monthly(uint base) const
{
return (uint)((static_cast<uint64_t>(base) * 30 * DAY_TICKS * _settings_game.economy.day_length_factor) / std::max<uint64_t>((_scaled_date_ticks - this->last_compression).base(), DAY_TICKS));
return (uint)((static_cast<uint64_t>(base) * 30 * DAY_TICKS * _settings_game.economy.day_length_factor) / std::max<uint64_t>((_state_ticks - this->last_compression).base(), DAY_TICKS));
}
NodeID AddNode(const Station *st);
@ -392,11 +392,11 @@ protected:
friend upstream_sl::SlLinkgraphNode;
friend upstream_sl::SlLinkgraphEdge;
friend void AdjustLinkGraphScaledTickBase(DateTicksScaledDelta delta);
friend void AdjustLinkGraphStateTicksBase(StateTicksDelta delta);
friend void LinkGraphFixupLastCompressionAfterLoad();
CargoID cargo; ///< Cargo of this component's link graph.
DateTicksScaled last_compression; ///< Last time the capacities and supplies were compressed.
StateTicks last_compression; ///< Last time the capacities and supplies were compressed.
NodeVector nodes; ///< Nodes in the component.
EdgeMatrix edges; ///< Edges in the component.

@ -348,10 +348,10 @@ public:
inline CargoID Cargo() const { return this->link_graph.Cargo(); }
/**
* Get the date when the underlying link graph was last compressed.
* Get the state tick when the underlying link graph was last compressed.
* @return Compression date.
*/
inline DateTicksScaled LastCompression() const { return this->link_graph.LastCompression(); }
inline StateTicks LastCompression() const { return this->link_graph.LastCompression(); }
/**
* Get the ID of the underlying link graph.

@ -131,7 +131,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
_tick_counter = 0;
_tick_skip_counter = 0;
_scaled_tick_counter = 0;
_scaled_date_ticks_offset = 0;
_state_ticks_offset = 0;
_cur_tileloop_tile = 1;
_aux_tileloop_tile = 1;
_thd.redsq = INVALID_TILE;

@ -11605,7 +11605,7 @@ void LoadNewGRF(uint load_index, uint num_baseset)
uint64_t tick_counter = _tick_counter;
uint8_t tick_skip_counter = _tick_skip_counter;
uint64_t scaled_tick_counter = _scaled_tick_counter;
DateTicksScaled scaled_date_ticks_offset = _scaled_date_ticks_offset;
StateTicks state_ticks_offset = _state_ticks_offset;
byte display_opt = _display_opt;
if (_networking) {
@ -11615,7 +11615,7 @@ void LoadNewGRF(uint load_index, uint num_baseset)
_tick_counter = 0;
_tick_skip_counter = 0;
_scaled_tick_counter = 0;
_scaled_date_ticks_offset = 0;
_state_ticks_offset = 0;
_display_opt = 0;
UpdateCachedSnowLine();
SetScaledTickVariables();
@ -11722,7 +11722,7 @@ void LoadNewGRF(uint load_index, uint num_baseset)
_tick_counter = tick_counter;
_tick_skip_counter = tick_skip_counter;
_scaled_tick_counter = scaled_tick_counter;
_scaled_date_ticks_offset = scaled_date_ticks_offset;
_state_ticks_offset = state_ticks_offset;
_display_opt = display_opt;
UpdateCachedSnowLine();
SetScaledTickVariables();

@ -1567,7 +1567,7 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log, CheckC
desync_level = 1;
if (HasChickenBit(DCBF_DESYNC_CHECK_NO_GENERAL)) flags &= ~CHECK_CACHE_GENERAL;
}
if (unlikely(HasChickenBit(DCBF_DESYNC_CHECK_PERIODIC_SIGNALS)) && desync_level < 2 && _scaled_date_ticks.base() % 256 == 0) {
if (unlikely(HasChickenBit(DCBF_DESYNC_CHECK_PERIODIC_SIGNALS)) && desync_level < 2 && _state_ticks.base() % 256 == 0) {
if (!SignalInfraTotalMatches()) desync_level = 2;
}
@ -1575,7 +1575,7 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log, CheckC
* always to aid testing of caches. */
if (desync_level < 1) return;
if (desync_level == 1 && _scaled_date_ticks.base() % 500 != 0) return;
if (desync_level == 1 && _state_ticks.base() % 500 != 0) return;
}
SCOPE_INFO_FMT([flags], "CheckCaches: %X", flags);
@ -2114,13 +2114,13 @@ void StateGameLoop()
if (_game_mode == GM_EDITOR) {
BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
/* _scaled_date_ticks and _scaled_date_ticks_offset must update in lockstep here,
/* _state_ticks and _state_ticks_offset must update in lockstep here,
* as _date, _tick_skip_counter, etc are not updated in the scenario editor,
* but _scaled_date_ticks should still update in case there are vehicles running,
* but _state_ticks should still update in case there are vehicles running,
* to avoid problems with timetables and train speed adaptation
*/
_scaled_date_ticks++;
_scaled_date_ticks_offset++;
_state_ticks++;
_state_ticks_offset++;
RunTileLoop();
CallVehicleTicks();
@ -2149,11 +2149,11 @@ void StateGameLoop()
_tick_skip_counter++;
_scaled_tick_counter++;
if (_game_mode != GM_MENU && _game_mode != GM_BOOTSTRAP) {
_scaled_date_ticks++; // This must update in lock-step with _tick_skip_counter, such that it always matches what SetScaledTickVariables would return.
_state_ticks++; // This must update in lock-step with _tick_skip_counter, such that it always matches what SetScaledTickVariables would return.
}
if (!(_game_mode == GM_MENU || _game_mode == GM_BOOTSTRAP) && !_settings_client.gui.autosave_realtime &&
(_scaled_date_ticks.base() % (_settings_client.gui.autosave_interval * (_settings_game.economy.tick_rate == TRM_MODERN ? (60000 / 27) : (60000 / 30)))) == 0) {
(_state_ticks.base() % (_settings_client.gui.autosave_interval * (_settings_game.economy.tick_rate == TRM_MODERN ? (60000 / 27) : (60000 / 30)))) == 0) {
_do_autosave = true;
_check_special_modes = true;
SetWindowDirty(WC_STATUS_BAR, 0);

@ -740,7 +740,7 @@ private:
friend SaveLoadTable GetDispatchScheduleDescription(); ///< Saving and loading of dispatch schedules
std::vector<DispatchSlot> scheduled_dispatch; ///< Scheduled dispatch slots
DateTicksScaled scheduled_dispatch_start_tick = -1; ///< Scheduled dispatch start tick
StateTicks scheduled_dispatch_start_tick = -1; ///< Scheduled dispatch start tick
uint32_t scheduled_dispatch_duration = 0; ///< Scheduled dispatch duration
int32_t scheduled_dispatch_last_dispatch = INVALID_SCHEDULED_DISPATCH_OFFSET; ///< Last vehicle dispatched offset
int32_t scheduled_dispatch_max_delay = 0; ///< Maximum allowed delay
@ -777,7 +777,7 @@ public:
void RemoveScheduledDispatch(uint32_t offset);
void AdjustScheduledDispatch(int32_t adjust);
void ClearScheduledDispatch() { this->scheduled_dispatch.clear(); }
bool UpdateScheduledDispatchToDate(DateTicksScaled now);
bool UpdateScheduledDispatchToDate(StateTicks now);
void UpdateScheduledDispatch(const Vehicle *v);
/**
@ -796,7 +796,7 @@ public:
* Set the scheduled dispatch start
* @param start_ticks New start ticks
*/
inline void SetScheduledDispatchStartTick(DateTicksScaled start_tick)
inline void SetScheduledDispatchStartTick(StateTicks start_tick)
{
this->scheduled_dispatch_start_tick = start_tick;
}
@ -805,7 +805,7 @@ public:
* Get the scheduled dispatch start date, in absolute scaled tick
* @return scheduled dispatch start date
*/
inline DateTicksScaled GetScheduledDispatchStartTick() const { return this->scheduled_dispatch_start_tick; }
inline StateTicks GetScheduledDispatchStartTick() const { return this->scheduled_dispatch_start_tick; }
/**
* Whether the scheduled dispatch setting is valid

@ -3045,7 +3045,7 @@ static uint16_t GetFreeStationPlatforms(StationID st_id)
return counter;
}
bool EvaluateDispatchSlotConditionalOrder(const Order *order, const Vehicle *v, DateTicksScaled date_time, bool *predicted)
bool EvaluateDispatchSlotConditionalOrder(const Order *order, const Vehicle *v, StateTicks state_ticks, bool *predicted)
{
uint schedule_index = GB(order->GetXData(), 0, 16);
if (schedule_index >= v->orders->GetScheduledDispatchScheduleCount()) return false;
@ -3066,7 +3066,7 @@ bool EvaluateDispatchSlotConditionalOrder(const Order *order, const Vehicle *v,
}
offset = last % sched.GetScheduledDispatchDuration();
} else {
DateTicksScaled slot = GetScheduledDispatchTime(sched, _scaled_date_ticks);
StateTicks slot = GetScheduledDispatchTime(sched, state_ticks);
offset = (slot - sched.GetScheduledDispatchStartTick()).base() % sched.GetScheduledDispatchDuration();
}
@ -3256,7 +3256,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v, Pro
break;
}
case OCV_DISPATCH_SLOT: {
skip_order = EvaluateDispatchSlotConditionalOrder(order, v, _scaled_date_ticks, nullptr);
skip_order = EvaluateDispatchSlotConditionalOrder(order, v, _state_ticks, nullptr);
break;
}
default: NOT_REACHED();
@ -3394,7 +3394,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
/* If the vehicle can't find its destination, delay its next search.
* In case many vehicles are in this state, use the vehicle index to spread out pathfinder calls. */
if (v->dest_tile == 0 && (_scaled_date_ticks.base() & 0x3F) != (v->index & 0x3F)) break;
if (v->dest_tile == 0 && (_state_ticks.base() & 0x3F) != (v->index & 0x3F)) break;
/* We need to search for the nearest depot (hangar). */
ClosestDepot closestDepot = v->FindClosestDepot();

@ -3608,7 +3608,7 @@ bool AfterLoadGame()
/* If the start date is 0, the vehicle is not waiting to start and can be ignored. */
if (v->timetable_start == 0) continue;
v->timetable_start += _scaled_date_ticks.base() - _tick_counter;
v->timetable_start += _state_ticks.base() - _tick_counter;
}
} else if (!SlXvIsFeaturePresent(XSLFI_TIMETABLES_START_TICKS, 3)) {
extern btree::btree_map<VehicleID, uint16_t> _old_timetable_start_subticks_map;
@ -3620,7 +3620,7 @@ bool AfterLoadGame()
v->timetable_start.edit_base() *= DAY_TICKS;
}
v->timetable_start = DateTicksToScaledDateTicks(v->timetable_start.base());
v->timetable_start = DateTicksToStateTicks(v->timetable_start.base());
if (SlXvIsFeaturePresent(XSLFI_TIMETABLES_START_TICKS, 2, 2)) {
v->timetable_start += _old_timetable_start_subticks_map[v->index];
@ -3907,10 +3907,10 @@ bool AfterLoadGame()
/* Use current order time to approximate last loading time */
if (IsSavegameVersionBefore(SLV_LAST_LOADING_TICK) && SlXvIsFeatureMissing(XSLFI_LAST_LOADING_TICK)) {
for (Vehicle *v : Vehicle::Iterate()) {
v->last_loading_tick = _scaled_date_ticks - v->current_order_time;
v->last_loading_tick = _state_ticks - v->current_order_time;
}
} else if (SlXvIsFeatureMissing(XSLFI_LAST_LOADING_TICK, 3)) {
const DateTicksScaledDelta delta = _scaled_date_ticks.base() - (int64_t)_scaled_tick_counter;
const StateTicksDelta delta = _state_ticks.base() - (int64_t)_scaled_tick_counter;
for (Vehicle *v : Vehicle::Iterate()) {
if (v->last_loading_tick != 0) {
if (SlXvIsFeaturePresent(XSLFI_LAST_LOADING_TICK, 1, 1)) v->last_loading_tick = v->last_loading_tick.base() * _settings_game.economy.day_length_factor;
@ -4228,7 +4228,7 @@ bool AfterLoadGame()
for (OrderList *order_list : OrderList::Iterate()) {
for (DispatchSchedule &ds : order_list->GetScheduledDispatchScheduleSet()) {
DateTicksScaled start_tick = DateToScaledDateTicks(ds.GetScheduledDispatchStartTick().base()) + _old_scheduled_dispatch_start_full_date_fract_map[&ds];
StateTicks start_tick = DateToStateTicks(ds.GetScheduledDispatchStartTick().base()) + _old_scheduled_dispatch_start_full_date_fract_map[&ds];
ds.SetScheduledDispatchStartTick(start_tick);
}
}

@ -202,7 +202,7 @@ CommandCost CmdScheduledDispatchSetStartDate(TileIndex tile, DoCommandFlag flags
if (flags & DC_EXEC) {
DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(schedule_index);
ds.SetScheduledDispatchStartTick((DateTicksScaled)p3);
ds.SetScheduledDispatchStartTick((StateTicks)p3);
ds.UpdateScheduledDispatch(nullptr);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
@ -375,7 +375,7 @@ CommandCost CmdScheduledDispatchAddNewSchedule(TileIndex tile, DoCommandFlag fla
v->orders->GetScheduledDispatchScheduleSet().emplace_back();
DispatchSchedule &ds = v->orders->GetScheduledDispatchScheduleSet().back();
ds.SetScheduledDispatchDuration(p2);
ds.SetScheduledDispatchStartTick((DateTicksScaled)p3);
ds.SetScheduledDispatchStartTick((StateTicks)p3);
ds.UpdateScheduledDispatch(nullptr);
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
@ -752,11 +752,11 @@ void DispatchSchedule::AdjustScheduledDispatch(int32_t adjust)
std::sort(this->scheduled_dispatch.begin(), this->scheduled_dispatch.end());
}
bool DispatchSchedule::UpdateScheduledDispatchToDate(DateTicksScaled now)
bool DispatchSchedule::UpdateScheduledDispatchToDate(StateTicks now)
{
bool update_windows = false;
if (this->GetScheduledDispatchStartTick() == 0) {
DateTicksScaled start = now - (now.base() % this->GetScheduledDispatchDuration());
StateTicks start = now - (now.base() % this->GetScheduledDispatchDuration());
this->SetScheduledDispatchStartTick(start);
int64_t last_dispatch = -(start.base());
if (last_dispatch < INT_MIN && _settings_game.game_time.time_in_minutes) {
@ -795,7 +795,7 @@ bool DispatchSchedule::UpdateScheduledDispatchToDate(DateTicksScaled now)
*/
void DispatchSchedule::UpdateScheduledDispatch(const Vehicle *v)
{
if (this->UpdateScheduledDispatchToDate(_scaled_date_ticks) && v != nullptr) {
if (this->UpdateScheduledDispatchToDate(_state_ticks) && v != nullptr) {
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
}
}

@ -68,7 +68,7 @@ enum SchdispatchWidgets {
* @param p1 The p1 parameter to send to CmdScheduledDispatchSetStartDate
* @param date the actually chosen date
*/
static void SetScheduleStartDateIntl(uint32_t p1, DateTicksScaled date)
static void SetScheduleStartDateIntl(uint32_t p1, StateTicks date)
{
DoCommandPEx(0, p1, 0, (uint64_t)date.base(), CMD_SCHEDULED_DISPATCH_SET_START_DATE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE), nullptr, nullptr, 0);
}
@ -78,7 +78,7 @@ static void SetScheduleStartDateIntl(uint32_t p1, DateTicksScaled date)
* @param window the window related to the setting of the date
* @param date the actually chosen date
*/
static void SetScheduleStartDateCallback(const Window *w, DateTicksScaled date)
static void SetScheduleStartDateCallback(const Window *w, StateTicks date)
{
SetScheduleStartDateIntl(w->window_number, date);
}
@ -88,7 +88,7 @@ static void SetScheduleStartDateCallback(const Window *w, DateTicksScaled date)
* @param p1 The p1 parameter to send to CmdScheduledDispatchAdd
* @param date the actually chosen date
*/
static void ScheduleAddIntl(uint32_t p1, DateTicksScaled date, uint extra_slots, uint offset, bool wrap_mode = false)
static void ScheduleAddIntl(uint32_t p1, StateTicks date, uint extra_slots, uint offset, bool wrap_mode = false)
{
VehicleID veh = GB(p1, 0, 20);
uint schedule_index = GB(p1, 20, 12);
@ -98,13 +98,13 @@ static void ScheduleAddIntl(uint32_t p1, DateTicksScaled date, uint extra_slots,
const DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(schedule_index);
/* Make sure the time is the closest future to the timetable start */
DateTicksScaled start_tick = ds.GetScheduledDispatchStartTick();
StateTicks start_tick = ds.GetScheduledDispatchStartTick();
uint32_t duration = ds.GetScheduledDispatchDuration();
while (date > start_tick) date -= duration;
while (date < start_tick) date += duration;
if (extra_slots > 0 && offset > 0 && !wrap_mode) {
DateTicksScaled end_tick = start_tick + duration;
StateTicks end_tick = start_tick + duration;
int64_t max_extra_slots = (end_tick - 1 - date).base() / offset;
if (max_extra_slots < extra_slots) extra_slots = static_cast<uint>(std::max<int64_t>(0, max_extra_slots));
extra_slots = std::min<uint>(extra_slots, UINT16_MAX);
@ -118,7 +118,7 @@ static void ScheduleAddIntl(uint32_t p1, DateTicksScaled date, uint extra_slots,
* @param window the window related to the setting of the date
* @param date the actually chosen date
*/
static void ScheduleAddCallback(const Window *w, DateTicksScaled date)
static void ScheduleAddCallback(const Window *w, StateTicks date)
{
ScheduleAddIntl(w->window_number, date, 0, 0);
}
@ -160,7 +160,7 @@ static int CalculateMaxRequiredVehicle(Ticks timetable_duration, uint32_t schedu
static void AddNewScheduledDispatchSchedule(VehicleID vindex)
{
DateTicksScaled start_tick;
StateTicks start_tick;
uint32_t duration;
const Company *c = Company::GetIfValid(_local_company);
@ -179,7 +179,7 @@ static void AddNewScheduledDispatchSchedule(VehicleID vindex)
duration = 24 * 60 * _settings_time.ticks_per_minute;
} else {
/* Set Jan 1st and 365 day */
start_tick = DateToScaledDateTicks(DateAtStartOfYear(_cur_year));
start_tick = DateToStateTicks(DateAtStartOfYear(_cur_year));
duration = 365 * DAY_TICKS;
}
@ -193,7 +193,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
uint num_columns; ///< Number of columns.
uint item_count = 0; ///< Number of scheduled item
DateTicksScaled next_departure_update = INT64_MAX; ///< Time after which the last departure value should be re-drawn
StateTicks next_departure_update = INT64_MAX; ///< Time after which the last departure value should be re-drawn
uint warning_count = 0;
uint extra_line_count = 0;
@ -467,7 +467,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
GuiShowTooltips(this, STR_SCHDISPATCH_REMOVE_SLOT, close_cond);
} else {
const DispatchSchedule &ds = this->GetSelectedSchedule();
const DateTicksScaled start_tick = ds.GetScheduledDispatchStartTick();
const StateTicks start_tick = ds.GetScheduledDispatchStartTick();
SetDParam(0, start_tick + slot->offset);
_temp_special_strings[0] = GetString(STR_SCHDISPATCH_SLOT_TOOLTIP);
@ -493,7 +493,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
}
have_last = true;
}
DateTicksScaled next_slot = GetScheduledDispatchTime(ds, _scaled_date_ticks);
StateTicks next_slot = GetScheduledDispatchTime(ds, _state_ticks);
if ((next_slot - ds.GetScheduledDispatchStartTick()).AsTicks() % ds.GetScheduledDispatchDuration() == slot->offset) {
if (!have_last) _temp_special_strings[0] += '\n';
_temp_special_strings[0] += GetString(STR_SCHDISPATCH_SLOT_TOOLTIP_NEXT);
@ -540,7 +540,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
* @param right Right side of the box to draw in.
* @param y Top of the box to draw in.
*/
void DrawScheduledTime(const DateTicksScaled time, int left, int right, int y, TextColour colour, bool last, bool next, bool flagged) const
void DrawScheduledTime(const StateTicks time, int left, int right, int y, TextColour colour, bool last, bool next, bool flagged) const
{
bool rtl = _current_text_dir == TD_RTL;
@ -571,7 +571,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
virtual void OnGameTick() override
{
if (_scaled_date_ticks >= this->next_departure_update) {
if (_state_ticks >= this->next_departure_update) {
this->next_departure_update = INT64_MAX;
SetWidgetDirty(WID_SCHDISPATCH_SUMMARY_PANEL);
}
@ -600,10 +600,10 @@ struct SchdispatchWindow : GeneralVehicleWindow {
const uint maxval = std::min<uint>(this->item_count, num + (rows_in_display * this->num_columns));
auto current_schedule = ds.GetScheduledDispatch().begin() + num;
const DateTicksScaled start_tick = ds.GetScheduledDispatchStartTick();
const DateTicksScaled end_tick = ds.GetScheduledDispatchStartTick() + ds.GetScheduledDispatchDuration();
const StateTicks start_tick = ds.GetScheduledDispatchStartTick();
const StateTicks end_tick = ds.GetScheduledDispatchStartTick() + ds.GetScheduledDispatchDuration();
DateTicksScaled slot = GetScheduledDispatchTime(ds, _scaled_date_ticks);
StateTicks slot = GetScheduledDispatchTime(ds, _state_ticks);
int32_t next_offset = (slot - ds.GetScheduledDispatchStartTick()).AsTicks() % ds.GetScheduledDispatchDuration();
int32_t last_dispatch = ds.GetScheduledDispatchLastDispatch() % ds.GetScheduledDispatchDuration();
@ -613,7 +613,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
/* Draw all departure time in the current row */
if (current_schedule != ds.GetScheduledDispatch().end()) {
int x = r.left + (rtl ? (this->num_columns - i - 1) : i) * this->resize.step_width;
DateTicksScaled draw_time = start_tick + current_schedule->offset;
StateTicks draw_time = start_tick + current_schedule->offset;
bool last = last_dispatch == (int32_t)current_schedule->offset;
bool next = next_offset == (int32_t)current_schedule->offset;
TextColour colour;
@ -640,7 +640,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
int y = ir.top;
auto set_next_departure_update = [&](DateTicksScaled time) {
auto set_next_departure_update = [&](StateTicks time) {
if (time < this->next_departure_update) const_cast<SchdispatchWindow*>(this)->next_departure_update = time;
};
@ -670,8 +670,8 @@ struct SchdispatchWindow : GeneralVehicleWindow {
warnings++;
};
auto departure_time_warnings = [&](DateTicksScaled time) {
if (_settings_time.time_in_minutes && time > (_scaled_date_ticks + (1350 * (uint)_settings_time.ticks_per_minute))) {
auto departure_time_warnings = [&](StateTicks time) {
if (_settings_time.time_in_minutes && time > (_state_ticks + (1350 * (uint)_settings_time.ticks_per_minute))) {
/* If the departure slot is more than 23 hours ahead of now, show a warning */
const TickMinutes now = _settings_time.NowInTickMinutes();
const TickMinutes target = _settings_time.ToTickMinutes(time);
@ -741,9 +741,9 @@ struct SchdispatchWindow : GeneralVehicleWindow {
y += WidgetDimensions::scaled.vsep_wide;
if (ds.GetScheduledDispatchLastDispatch() != INVALID_SCHEDULED_DISPATCH_OFFSET) {
const DateTicksScaled last_departure = ds.GetScheduledDispatchStartTick() + ds.GetScheduledDispatchLastDispatch();
const StateTicks last_departure = ds.GetScheduledDispatchStartTick() + ds.GetScheduledDispatchLastDispatch();
StringID str;
if (_scaled_date_ticks < last_departure) {
if (_state_ticks < last_departure) {
str = STR_SCHDISPATCH_SUMMARY_LAST_DEPARTURE_FUTURE;
set_next_departure_update(last_departure);
} else {
@ -755,7 +755,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
departure_time_warnings(last_departure);
if (_settings_time.time_in_minutes && last_departure < (_scaled_date_ticks + (1350 * (uint)_settings_time.ticks_per_minute))) {
if (_settings_time.time_in_minutes && last_departure < (_state_ticks + (1350 * (uint)_settings_time.ticks_per_minute))) {
/* If the departure slot is more than 23 hours behind now, show a warning */
const TickMinutes now = _settings_time.NowInTickMinutes();
const TickMinutes target = _settings_time.ToTickMinutes(last_departure);
@ -775,7 +775,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
y += GetCharacterHeight(FS_NORMAL);
}
const DateTicksScaled next_departure = GetScheduledDispatchTime(ds, _scaled_date_ticks);
const StateTicks next_departure = GetScheduledDispatchTime(ds, _state_ticks);
set_next_departure_update(next_departure + ds.GetScheduledDispatchDelay());
SetDParam(0, next_departure);
DrawString(ir.left, ir.right, y, STR_SCHDISPATCH_SUMMARY_NEXT_AVAILABLE_DEPARTURE);
@ -940,7 +940,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
} else if (_settings_time.time_in_minutes && _settings_client.gui.timetable_start_text_entry) {
ShowQueryString(STR_EMPTY, STR_SCHDISPATCH_ADD_CAPTION, 31, this, CS_NUMERAL, QSF_NONE);
} else {
ShowSetDateWindow(this, v->index | (this->schedule_index << 20), _scaled_date_ticks, _cur_year, _cur_year + 15, ScheduleAddCallback, STR_SCHDISPATCH_ADD, STR_SCHDISPATCH_ADD_TOOLTIP);
ShowSetDateWindow(this, v->index | (this->schedule_index << 20), _state_ticks, _cur_year, _cur_year + 15, ScheduleAddCallback, STR_SCHDISPATCH_ADD, STR_SCHDISPATCH_ADD_TOOLTIP);
}
break;
}
@ -959,7 +959,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
SetDParam(0, _settings_time.NowInTickMinutes().ClockHHMM());
ShowQueryString(STR_JUST_INT, STR_SCHDISPATCH_START_CAPTION_MINUTE, 31, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
} else {
ShowSetDateWindow(this, v->index | (this->schedule_index << 20), _scaled_date_ticks, _cur_year, _cur_year + 15, SetScheduleStartDateCallback, STR_SCHDISPATCH_SET_START, STR_SCHDISPATCH_START_TOOLTIP);
ShowSetDateWindow(this, v->index | (this->schedule_index << 20), _state_ticks, _cur_year, _cur_year + 15, SetScheduleStartDateCallback, STR_SCHDISPATCH_SET_START, STR_SCHDISPATCH_START_TOOLTIP);
}
break;
}
@ -1169,7 +1169,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
if (val >= 0 && end != nullptr && *end == 0) {
uint minutes = (val % 100) % 60;
uint hours = (val / 100) % 24;
DateTicksScaled slot = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(hours, minutes));
StateTicks slot = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(hours, minutes));
ScheduleAddIntl(v->index | (this->schedule_index << 20), slot, 0, 0);
}
break;
@ -1185,7 +1185,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
if (val >= 0 && end != nullptr && *end == 0) {
uint minutes = (val % 100) % 60;
uint hours = (val / 100) % 24;
DateTicksScaled start = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(hours, minutes));
StateTicks start = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(hours, minutes));
SetScheduleStartDateIntl(v->index | (this->schedule_index << 20), start);
}
break;
@ -1272,7 +1272,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
}
if (end < start || step == 0 || !this->IsScheduleSelected()) return;
DateTicksScaled slot = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(0, start));
StateTicks slot = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(0, start));
ScheduleAddIntl(this->vehicle->index | (this->schedule_index << 20), slot, (end - start) / step, step * _settings_time.ticks_per_minute, wrap_mode);
}
};

@ -85,17 +85,17 @@
/* static */ SQInteger ScriptDate::GetCurrentScaledDateTicks()
{
return _scaled_date_ticks.base();
return _state_ticks.base();
}
/* static */ SQInteger ScriptDate::GetHour(SQInteger ticks)
{
TickMinutes minutes = _settings_game.game_time.ToTickMinutes(DateTicksScaled(ticks));
TickMinutes minutes = _settings_game.game_time.ToTickMinutes(StateTicks(ticks));
return minutes.ClockHour();
}
/* static */ SQInteger ScriptDate::GetMinute(SQInteger ticks)
{
TickMinutes minutes = _settings_game.game_time.ToTickMinutes(DateTicksScaled(ticks));
TickMinutes minutes = _settings_game.game_time.ToTickMinutes(StateTicks(ticks));
return minutes.ClockMinute();
}

@ -1850,8 +1850,8 @@ static bool DayLengthPreChange(int32_t &new_value)
static void DayLengthChanged(int32_t new_value)
{
extern void RebaseScaledDateTicksBase();
RebaseScaledDateTicksBase();
extern void RebaseStateTicksBase();
RebaseStateTicksBase();
SetupTileLoopCounts();
UpdateCargoScalers();

@ -136,18 +136,18 @@ struct TimeSettings {
uint16_t ticks_per_minute; ///< how many ticks per minute
uint16_t clock_offset; ///< clock offset in minutes
TickMinutes ToTickMinutes(DateTicksScaled ticks) const
TickMinutes ToTickMinutes(StateTicks ticks) const
{
return (ticks.base() / this->ticks_per_minute) + this->clock_offset;
}
TickMinutes NowInTickMinutes() const
{
extern DateTicksScaled _scaled_date_ticks;
return this->ToTickMinutes(_scaled_date_ticks);
extern StateTicks _state_ticks;
return this->ToTickMinutes(_state_ticks);
}
DateTicksScaled FromTickMinutes(TickMinutes minutes) const
StateTicks FromTickMinutes(TickMinutes minutes) const
{
return (minutes.base() - this->clock_offset) * this->ticks_per_minute;
}

@ -42,7 +42,7 @@ enum SlXvFeatureIndex {
XSLFI_ADJACENT_CROSSINGS, ///< Adjacent level crossings closure patch
XSLFI_SAFER_CROSSINGS, ///< Safer level crossings
XSLFI_DEPARTURE_BOARDS, ///< Departure boards patch, in ticks mode
XSLFI_TIMETABLES_START_TICKS, ///< Timetable start time format: 1: is in ticks, instead of days, 2: also has subticks, 3: uses DateTicksScaled
XSLFI_TIMETABLES_START_TICKS, ///< Timetable start time format: 1: is in ticks, instead of days, 2: also has subticks, 3: uses StateTicks
XSLFI_TOWN_CARGO_ADJ, ///< Town cargo adjustment patch
XSLFI_SIG_TUNNEL_BRIDGE, ///< Signals on tunnels and bridges
XSLFI_IMPROVED_BREAKDOWNS, ///< Improved breakdowns patch

@ -91,7 +91,7 @@ static const SaveLoad _date_desc[] = {
SLEG_CONDVAR_X(_tick_counter, SLE_UINT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_U64_TICK_COUNTER)),
SLEG_CONDVAR_X(_tick_skip_counter, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH)),
SLEG_CONDVAR_X(_scaled_tick_counter, SLE_UINT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)),
SLEG_CONDVAR_X(_scaled_date_ticks_offset, SLE_INT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)),
SLEG_CONDVAR_X(_state_ticks_offset, SLE_INT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)),
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_157), // _vehicle_id_ctr_day
SLEG_CONDVAR(_age_cargo_skip_counter, SLE_UINT8, SL_MIN_VERSION, SLV_162),
SLE_CONDNULL(1, SL_MIN_VERSION, SLV_46),
@ -128,7 +128,7 @@ static const SaveLoad _date_check_desc[] = {
SLE_CONDNULL_X(8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_U64_TICK_COUNTER)), // _tick_counter
SLE_CONDNULL_X(1, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH)), // _tick_skip_counter
SLE_CONDNULL_X(8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)), // _scaled_tick_counter
SLE_CONDNULL_X(8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)), // _scaled_date_ticks_offset
SLE_CONDNULL_X(8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VARIABLE_DAY_LENGTH, 3)), // _state_ticks_offset
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_157), // _vehicle_id_ctr_day
SLE_CONDNULL(1, SL_MIN_VERSION, SLV_162), // _age_cargo_skip_counter
SLE_CONDNULL(1, SL_MIN_VERSION, SLV_46),

@ -4550,8 +4550,8 @@ void DeleteStaleLinks(Station *from)
return result;
});
assert(_scaled_date_ticks >= lg->LastCompression());
if ((_scaled_date_ticks - lg->LastCompression()) > LinkGraph::COMPRESSION_INTERVAL) {
assert(_state_ticks >= lg->LastCompression());
if ((_state_ticks - lg->LastCompression()) > LinkGraph::COMPRESSION_INTERVAL) {
lg->Compress();
}
}

@ -93,7 +93,7 @@ struct StatusBarWindow : Window {
Dimension d;
switch (widget) {
case WID_S_LEFT:
SetDParam(0, DateToScaledDateTicks(MAX_YEAR * DAYS_IN_YEAR));
SetDParam(0, DateToStateTicks(MAX_YEAR * DAYS_IN_YEAR));
d = GetStringBoundingBox(STR_JUST_DATE_WALLCLOCK_LONG);
break;
@ -121,7 +121,7 @@ struct StatusBarWindow : Window {
switch (widget) {
case WID_S_LEFT:
/* Draw the date */
SetDParam(0, _scaled_date_ticks);
SetDParam(0, _state_ticks);
DrawString(tr, STR_JUST_DATE_WALLCLOCK_LONG, TC_WHITE, SA_HOR_CENTER);
break;

@ -473,14 +473,14 @@ static void FormatBytes(StringBuilder builder, int64_t number)
fmt::format_to(builder, NBSP "{}B", iec_prefixes[id]);
}
static void FormatWallClockString(StringBuilder builder, DateTicksScaled ticks, bool show_date, uint case_index)
static void FormatWallClockString(StringBuilder builder, StateTicks ticks, bool show_date, uint case_index)
{
TickMinutes minutes = _settings_time.ToTickMinutes(ticks);
char hour[3], minute[3];
seprintf(hour, lastof(hour), "%02i", minutes.ClockHour());
seprintf(minute, lastof(minute), "%02i", minutes.ClockMinute());
if (show_date) {
Date date = ScaledDateTicksToDate(ticks);
Date date = StateTicksToDate(ticks);
int64_t final_arg;
if (_settings_client.gui.date_with_time == 1) {
YearMonthDay ymd = ConvertDateToYMD(date);
@ -1538,36 +1538,36 @@ static void FormatString(StringBuilder builder, const char *str_arg, StringParam
case SCC_DATE_WALLCLOCK_LONG: { // {DATE_WALLCLOCK_LONG}
if (_settings_time.time_in_minutes) {
FormatWallClockString(builder, args.GetNextParameter<DateTicksScaled>(), _settings_client.gui.date_with_time, next_substr_case_index);
FormatWallClockString(builder, args.GetNextParameter<StateTicks>(), _settings_client.gui.date_with_time, next_substr_case_index);
} else {
FormatYmdString(builder, ScaledDateTicksToDate(args.GetNextParameter<DateTicksScaled>()), next_substr_case_index);
FormatYmdString(builder, StateTicksToDate(args.GetNextParameter<StateTicks>()), next_substr_case_index);
}
break;
}
case SCC_DATE_WALLCLOCK_SHORT: { // {DATE_WALLCLOCK_SHORT}
if (_settings_time.time_in_minutes) {
FormatWallClockString(builder, args.GetNextParameter<DateTicksScaled>(), _settings_client.gui.date_with_time, next_substr_case_index);
FormatWallClockString(builder, args.GetNextParameter<StateTicks>(), _settings_client.gui.date_with_time, next_substr_case_index);
} else {
FormatYmdString(builder, ScaledDateTicksToDate(args.GetNextParameter<DateTicksScaled>()), next_substr_case_index);
FormatYmdString(builder, StateTicksToDate(args.GetNextParameter<StateTicks>()), next_substr_case_index);
}
break;
}
case SCC_DATE_WALLCLOCK_TINY: { // {DATE_WALLCLOCK_TINY}
if (_settings_time.time_in_minutes) {
FormatWallClockString(builder, args.GetNextParameter<DateTicksScaled>(), false, next_substr_case_index);
FormatWallClockString(builder, args.GetNextParameter<StateTicks>(), false, next_substr_case_index);
} else {
FormatTinyOrISODate(builder, ScaledDateTicksToDate(args.GetNextParameter<DateTicksScaled>()), STR_FORMAT_DATE_TINY);
FormatTinyOrISODate(builder, StateTicksToDate(args.GetNextParameter<StateTicks>()), STR_FORMAT_DATE_TINY);
}
break;
}
case SCC_DATE_WALLCLOCK_ISO: { // {DATE_WALLCLOCK_ISO}
if (_settings_time.time_in_minutes) {
FormatWallClockString(builder, args.GetNextParameter<DateTicksScaled>(), false, next_substr_case_index);
FormatWallClockString(builder, args.GetNextParameter<StateTicks>(), false, next_substr_case_index);
} else {
FormatTinyOrISODate(builder, ScaledDateTicksToDate(args.GetNextParameter<DateTicksScaled>()), STR_FORMAT_DATE_ISO);
FormatTinyOrISODate(builder, StateTicksToDate(args.GetNextParameter<StateTicks>()), STR_FORMAT_DATE_ISO);
}
break;
}

@ -263,7 +263,7 @@ class NIHVehicle : public NIHelper {
seprintf(buffer, lastof(buffer), " V Last loading station: %u, %s", v->last_loading_station, BaseStation::Get(v->last_loading_station)->GetCachedName());
output.print(buffer);
seprintf(buffer, lastof(buffer), " V Last loading tick: " OTTD_PRINTF64 " (" OTTD_PRINTF64 ", " OTTD_PRINTF64 " mins ago)",
v->last_loading_tick.base(), (_scaled_date_ticks - v->last_loading_tick).base(), (_scaled_date_ticks - v->last_loading_tick).base() / _settings_time.ticks_per_minute);
v->last_loading_tick.base(), (_state_ticks - v->last_loading_tick).base(), (_state_ticks - v->last_loading_tick).base() / _settings_time.ticks_per_minute);
output.print(buffer);
}
if (v->IsGroundVehicle()) {
@ -1449,7 +1449,7 @@ class NIHSignals : public NIHelper {
if (it.second.IsOutOfDate()) {
b += seprintf(b, lastof(buffer), ", expired");
} else {
b += seprintf(b, lastof(buffer), ", expires in %u ticks", (uint)(it.second.time_stamp - _scaled_date_ticks).base());
b += seprintf(b, lastof(buffer), ", expires in %u ticks", (uint)(it.second.time_stamp - _state_ticks).base());
}
output.print(buffer);
}

@ -41,6 +41,6 @@ struct TimetableProgress {
std::vector<TimetableProgress> PopulateSeparationState(const Vehicle *v_start);
struct DispatchSchedule;
DateTicksScaled GetScheduledDispatchTime(const DispatchSchedule &ds, DateTicksScaled leave_time);
StateTicks GetScheduledDispatchTime(const DispatchSchedule &ds, StateTicks leave_time);
#endif /* TIMETABLE_H */

@ -486,12 +486,12 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32_t p
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
DateTicksScaled start_date_scaled = (DateTicksScaled)p3;
StateTicks start_date_scaled = (StateTicks)p3;
/* Don't let a timetable start more than 15 unscaled years into the future... */
if (start_date_scaled - _scaled_date_ticks > 15 * DAY_TICKS * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (start_date_scaled - _state_ticks > 15 * DAY_TICKS * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
/* ...or 1 unscaled year in the past. */
if (_scaled_date_ticks - start_date_scaled > DAY_TICKS * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (_state_ticks - start_date_scaled > DAY_TICKS * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (timetable_all && !v->orders->IsCompleteTimetable()) return CommandCost(STR_ERROR_TIMETABLE_INCOMPLETE);
@ -787,12 +787,12 @@ void UpdateSeparationOrder(Vehicle *v_start)
}
}
DateTicksScaled GetScheduledDispatchTime(const DispatchSchedule &ds, DateTicksScaled leave_time)
StateTicks GetScheduledDispatchTime(const DispatchSchedule &ds, StateTicks leave_time)
{
const uint32_t dispatch_duration = ds.GetScheduledDispatchDuration();
const int32_t max_delay = ds.GetScheduledDispatchDelay();
const DateTicksScaled minimum = leave_time - max_delay;
DateTicksScaled begin_time = ds.GetScheduledDispatchStartTick();
const StateTicks minimum = leave_time - max_delay;
StateTicks begin_time = ds.GetScheduledDispatchStartTick();
if (ds.GetScheduledDispatchReuseSlots()) {
begin_time -= dispatch_duration;
}
@ -804,7 +804,7 @@ DateTicksScaled GetScheduledDispatchTime(const DispatchSchedule &ds, DateTicksSc
last_dispatched_offset = ds.GetScheduledDispatchLastDispatch();
}
DateTicksScaled first_slot = -1;
StateTicks first_slot = -1;
/* Find next available slots */
for (const DispatchSlot &slot : ds.GetScheduledDispatch()) {
@ -817,7 +817,7 @@ DateTicksScaled GetScheduledDispatchTime(const DispatchSchedule &ds, DateTicksSc
current_offset += dispatch_duration * ((threshold + dispatch_duration - current_offset) / dispatch_duration);
}
DateTicksScaled current_departure = begin_time + current_offset;
StateTicks current_departure = begin_time + current_offset;
if (current_departure < minimum) {
current_departure += dispatch_duration * ((minimum + dispatch_duration - current_departure - 1) / dispatch_duration);
}
@ -873,11 +873,11 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
ds.UpdateScheduledDispatch(v);
const int wait_offset = real_current_order->GetTimetabledWait();
DateTicksScaled slot = GetScheduledDispatchTime(ds, _scaled_date_ticks + wait_offset);
StateTicks slot = GetScheduledDispatchTime(ds, _state_ticks + wait_offset);
if (slot > -1) {
just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
v->lateness_counter = (_scaled_date_ticks - slot + wait_offset).AsTicks();
v->lateness_counter = (_state_ticks - slot + wait_offset).AsTicks();
ds.SetScheduledDispatchLastDispatch((slot - ds.GetScheduledDispatchStartTick()).AsTicks());
SetTimetableWindowsDirty(v, STWDF_SCHEDULED_DISPATCH);
set_scheduled_dispatch = true;
@ -905,7 +905,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
if (!set_scheduled_dispatch) just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
if (v->timetable_start != 0) {
v->lateness_counter = (_scaled_date_ticks - v->timetable_start).AsTicks();
v->lateness_counter = (_state_ticks - v->timetable_start).AsTicks();
v->timetable_start = 0;
}

@ -144,17 +144,17 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID
case OCV_TIME_DATE: {
predicted = true;
DateTicksScaled time = _scaled_date_ticks + sum;
StateTicks time = _state_ticks + sum;
if (!no_offset) time -= v->lateness_counter;
int value = GetTraceRestrictTimeDateValueFromDate(static_cast<TraceRestrictTimeDateValueField>(order->GetConditionValue()), time);
int value = GetTraceRestrictTimeDateValueFromStateTicks(static_cast<TraceRestrictTimeDateValueField>(order->GetConditionValue()), time);
jump = OrderConditionCompare(order->GetConditionComparator(), value, order->GetXData());
break;
}
case OCV_DISPATCH_SLOT: {
DateTicksScaled time = _scaled_date_ticks + sum;
StateTicks time = _state_ticks + sum;
if (!no_offset) time -= v->lateness_counter;
extern bool EvaluateDispatchSlotConditionalOrder(const Order *order, const Vehicle *v, DateTicksScaled date_time, bool *predicted);
extern bool EvaluateDispatchSlotConditionalOrder(const Order *order, const Vehicle *v, StateTicks state_ticks, bool *predicted);
jump = EvaluateDispatchSlotConditionalOrder(order, v, time, &predicted);
break;
}
@ -193,11 +193,11 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID
DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(order->GetDispatchScheduleIndex());
DispatchSchedule predicted_ds;
predicted_ds.BorrowSchedule(ds);
predicted_ds.UpdateScheduledDispatchToDate(_scaled_date_ticks + sum);
DateTicksScaled slot = GetScheduledDispatchTime(predicted_ds, _scaled_date_ticks + sum + order->GetTimetabledWait());
predicted_ds.UpdateScheduledDispatchToDate(_state_ticks + sum);
StateTicks slot = GetScheduledDispatchTime(predicted_ds, _state_ticks + sum + order->GetTimetabledWait());
predicted_ds.ReturnSchedule(ds);
if (slot <= -1) return;
sum = (slot - _scaled_date_ticks).AsTicks();
sum = (slot - _state_ticks).AsTicks();
predicted = true;
no_offset = true;
} else {
@ -234,21 +234,21 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID
/**
* Callback for when a time has been chosen to start the time table
* @param p1 The p1 parameter to send to CmdSetTimetableStart
* @param date the actually chosen date
* @param tick the actually chosen state tick
*/
static void ChangeTimetableStartIntl(uint32_t p1, DateTicksScaled date)
static void ChangeTimetableStartIntl(uint32_t p1, StateTicks tick)
{
DoCommandPEx(0, p1, 0, (uint64_t)date.base(), CMD_SET_TIMETABLE_START | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE), nullptr, nullptr, 0);
DoCommandPEx(0, p1, 0, (uint64_t)tick.base(), CMD_SET_TIMETABLE_START | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE), nullptr, nullptr, 0);
}
/**
* Callback for when a time has been chosen to start the time table
* @param w the window related to the setting of the date
* @param date the actually chosen date
* @param tick the actually chosen tick
*/
static void ChangeTimetableStartCallback(const Window *w, DateTicksScaled date)
static void ChangeTimetableStartCallback(const Window *w, StateTicks tick)
{
ChangeTimetableStartIntl(w->window_number, date);
ChangeTimetableStartIntl(w->window_number, tick);
}
void ProcessTimetableWarnings(const Vehicle *v, std::function<void(StringID, bool)> handler)
@ -762,10 +762,10 @@ struct TimetableWindow : GeneralVehicleWindow {
if (arr_dep[i / 2].arrival != INVALID_TICKS) {
DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_ARRIVAL_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
if (this->show_expected && i / 2 == earlyID) {
SetDParam(0, _scaled_date_ticks + arr_dep[i / 2].arrival);
SetDParam(0, _state_ticks + arr_dep[i / 2].arrival);
DrawString(time.left, time.right, tr.top, STR_JUST_DATE_WALLCLOCK_TINY, TC_GREEN);
} else {
SetDParam(0, _scaled_date_ticks + arr_dep[i / 2].arrival + (HasBit(arr_dep[i / 2].flags, TADF_ARRIVAL_NO_OFFSET) ? 0 : offset));
SetDParam(0, _state_ticks + arr_dep[i / 2].arrival + (HasBit(arr_dep[i / 2].flags, TADF_ARRIVAL_NO_OFFSET) ? 0 : offset));
DrawString(time.left, time.right, tr.top, STR_JUST_DATE_WALLCLOCK_TINY,
HasBit(arr_dep[i / 2].flags, TADF_ARRIVAL_PREDICTED) ? (TextColour)(TC_IS_PALETTE_COLOUR | TC_NO_SHADE | 4) : (show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK));
}
@ -773,7 +773,7 @@ struct TimetableWindow : GeneralVehicleWindow {
} else {
if (arr_dep[i / 2].departure != INVALID_TICKS) {
DrawString(abbr.left, abbr.right, tr.top, STR_TIMETABLE_DEPARTURE_ABBREVIATION, i == selected ? TC_WHITE : TC_BLACK);
SetDParam(0, _scaled_date_ticks + arr_dep[i/2].departure + (HasBit(arr_dep[i / 2].flags, TADF_DEPARTURE_NO_OFFSET) ? 0 : offset));
SetDParam(0, _state_ticks + arr_dep[i/2].departure + (HasBit(arr_dep[i / 2].flags, TADF_DEPARTURE_NO_OFFSET) ? 0 : offset));
DrawString(time.left, time.right, tr.top, STR_JUST_DATE_WALLCLOCK_TINY,
HasBit(arr_dep[i / 2].flags, TADF_DEPARTURE_PREDICTED) ? (TextColour)(TC_IS_PALETTE_COLOUR | TC_NO_SHADE | 4) : (show_late ? TC_RED : i == selected ? TC_WHITE : TC_BLACK));
}
@ -909,7 +909,7 @@ struct TimetableWindow : GeneralVehicleWindow {
ShowQueryString(str, STR_TIMETABLE_START, 31, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
} else {
ShowSetDateWindow(this, v->index | (_ctrl_pressed ? 1U << 20 : 0),
_scaled_date_ticks, _cur_year, _cur_year + 15, ChangeTimetableStartCallback);
_state_ticks, _cur_year, _cur_year + 15, ChangeTimetableStartCallback);
}
break;

@ -2417,9 +2417,9 @@ int GetTraceRestrictTimeDateValue(TraceRestrictTimeDateValueField type)
}
}
int GetTraceRestrictTimeDateValueFromDate(TraceRestrictTimeDateValueField type, DateTicksScaled scaled_date_ticks)
int GetTraceRestrictTimeDateValueFromStateTicks(TraceRestrictTimeDateValueField type, StateTicks state_ticks)
{
const TickMinutes minutes = _settings_game.game_time.ToTickMinutes(scaled_date_ticks);
const TickMinutes minutes = _settings_game.game_time.ToTickMinutes(state_ticks);
switch (type) {
case TRTDVF_MINUTE:
@ -2432,12 +2432,12 @@ int GetTraceRestrictTimeDateValueFromDate(TraceRestrictTimeDateValueField type,
return minutes.ClockHHMM();
case TRTDVF_DAY: {
YearMonthDay ymd = ConvertDateToYMD(ScaledDateTicksToDate(scaled_date_ticks));
YearMonthDay ymd = ConvertDateToYMD(StateTicksToDate(state_ticks));
return ymd.day;
}
case TRTDVF_MONTH: {
YearMonthDay ymd = ConvertDateToYMD(ScaledDateTicksToDate(scaled_date_ticks));
YearMonthDay ymd = ConvertDateToYMD(StateTicksToDate(state_ticks));
return ymd.month + 1;
}

@ -1169,7 +1169,7 @@ bool TraceRestrictProgramDuplicateItemAtDryRun(const std::vector<TraceRestrictIt
void ShowTraceRestrictProgramWindow(TileIndex tile, Track track);
int GetTraceRestrictTimeDateValue(TraceRestrictTimeDateValueField type);
int GetTraceRestrictTimeDateValueFromDate(TraceRestrictTimeDateValueField type, DateTicksScaled scaled_date_ticks);
int GetTraceRestrictTimeDateValueFromStateTicks(TraceRestrictTimeDateValueField type, StateTicks state_ticks);
void TraceRestrictRemoveDestinationID(TraceRestrictOrderCondAuxField type, uint16_t index);
void TraceRestrictRemoveGroupID(GroupID index);

@ -101,7 +101,7 @@ static bool CheckTrainStayInWormHolePathReserve(Train *t, TileIndex tile);
/** Return the scaled date ticks by which the speed restriction
* at the current position of the train is going to be invalid */
static DateTicksScaled GetSpeedRestrictionTimeout(const Train *t)
static StateTicks GetSpeedRestrictionTimeout(const Train *t)
{
const int64_t velocity = std::max<int64_t>(25, t->cur_speed);
const int64_t look_ahead_distance = Clamp(t->cur_speed / 8, 4, 16); // In tiles, varying between 4 and 16 depending on current speed
@ -111,7 +111,7 @@ static DateTicksScaled GetSpeedRestrictionTimeout(const Train *t)
const int64_t ticks = ticks_per_tile * look_ahead_distance;
return _scaled_date_ticks + ticks;
return _state_ticks + ticks;
}
/** Removes all speed restrictions from all signals */
@ -120,7 +120,7 @@ void ClearAllSignalSpeedRestrictions()
_signal_speeds.clear();
}
void AdjustAllSignalSpeedRestrictionTickValues(DateTicksScaledDelta delta)
void AdjustAllSignalSpeedRestrictionTickValues(StateTicksDelta delta)
{
for (auto &it : _signal_speeds) {
it.second.time_stamp += delta;

@ -36,12 +36,12 @@ struct SignalSpeedKey {
struct SignalSpeedValue {
uint16_t train_speed;
DateTicksScaled time_stamp;
StateTicks time_stamp;
/** Checks if the timeout has passed */
bool IsOutOfDate() const
{
return _scaled_date_ticks > this->time_stamp;
return _state_ticks > this->time_stamp;
}
};

@ -3239,7 +3239,7 @@ static void VehicleIncreaseStats(const Vehicle *front)
{
for (const Vehicle *v = front; v != nullptr; v = v->Next()) {
StationID last_loading_station = HasBit(front->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? v->last_loading_station : front->last_loading_station;
DateTicksScaled loading_tick = HasBit(front->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? v->last_loading_tick : front->last_loading_tick;
StateTicks loading_tick = HasBit(front->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? v->last_loading_tick : front->last_loading_tick;
if (v->refit_cap > 0 &&
last_loading_station != INVALID_STATION &&
last_loading_station != front->last_station_visited &&
@ -3254,7 +3254,7 @@ static void VehicleIncreaseStats(const Vehicle *front)
EdgeUpdateMode restricted_mode = EUM_INCREASE;
if (v->type == VEH_AIRCRAFT) restricted_mode |= EUM_AIRCRAFT;
IncreaseStats(Station::Get(last_loading_station), v->cargo_type, front->last_station_visited, v->refit_cap,
std::min<uint>(v->refit_cap, v->cargo.StoredCount()), (_scaled_date_ticks - loading_tick).AsTicksT<uint32_t>(), restricted_mode);
std::min<uint>(v->refit_cap, v->cargo.StoredCount()), (_state_ticks - loading_tick).AsTicksT<uint32_t>(), restricted_mode);
}
}
}
@ -3474,7 +3474,7 @@ void Vehicle::LeaveStation()
/* if the vehicle could load here or could stop with cargo loaded set the last loading station */
this->last_loading_station = this->last_station_visited;
this->last_loading_tick = _scaled_date_ticks;
this->last_loading_tick = _state_ticks;
ClrBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP);
} else if (cargoes_can_leave_with_cargo == 0) {
/* can leave with no cargoes */
@ -3488,14 +3488,14 @@ void Vehicle::LeaveStation()
/* NB: this is saved here as we overwrite it on the first iteration of the loop below */
StationID head_last_loading_station = this->last_loading_station;
DateTicksScaled head_last_loading_tick = this->last_loading_tick;
StateTicks head_last_loading_tick = this->last_loading_tick;
for (Vehicle *u = this; u != nullptr; u = u->Next()) {
StationID last_loading_station = HasBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? u->last_loading_station : head_last_loading_station;
DateTicksScaled last_loading_tick = HasBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? u->last_loading_tick : head_last_loading_tick;
StateTicks last_loading_tick = HasBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? u->last_loading_tick : head_last_loading_tick;
if (u->cargo_type < NUM_CARGO && HasBit(cargoes_can_load_unload, u->cargo_type)) {
if (HasBit(cargoes_can_leave_with_cargo, u->cargo_type)) {
u->last_loading_station = this->last_station_visited;
u->last_loading_tick = _scaled_date_ticks;
u->last_loading_tick = _state_ticks;
} else {
u->last_loading_station = INVALID_STATION;
}
@ -4688,7 +4688,7 @@ void DumpVehicleStats(char *buffer, const char *last)
buffer += seprintf(buffer, last, "Total vehicles: %u\n", (uint)Vehicle::GetNumItems());
}
void AdjustVehicleScaledTickBase(DateTicksScaledDelta delta)
void AdjustVehicleStateTicksBase(StateTicksDelta delta)
{
for (Vehicle *v : Vehicle::Iterate()) {
if (v->timetable_start != 0) v->timetable_start += delta;

@ -380,7 +380,7 @@ public:
StationID last_station_visited; ///< The last station we stopped at.
StationID last_loading_station; ///< Last station the vehicle has stopped at and could possibly leave from with any cargo loaded. (See VF_LAST_LOAD_ST_SEP).
DateTicksScaled last_loading_tick; ///< Last tick (_scaled_date_ticks) the vehicle has stopped at a station and could possibly leave with any cargo loaded. (See VF_LAST_LOAD_ST_SEP).
StateTicks last_loading_tick; ///< Last tick (_state_ticks) the vehicle has stopped at a station and could possibly leave with any cargo loaded. (See VF_LAST_LOAD_ST_SEP).
VehicleCargoList cargo; ///< The cargo this vehicle is carrying
uint16_t cargo_cap; ///< total capacity

Loading…
Cancel
Save