Update departure board to handle changed minutes.
Use scaled date ticks internally.
This commit is contained in:
@@ -94,7 +94,10 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
|
|||||||
SmallVector<OrderDate*, 32> next_orders;
|
SmallVector<OrderDate*, 32> next_orders;
|
||||||
|
|
||||||
/* The maximum possible date for departures to be scheduled to occur. */
|
/* The maximum possible date for departures to be scheduled to occur. */
|
||||||
DateTicks max_date = _settings_client.gui.max_departure_time * DAY_TICKS;
|
DateTicksScaled max_date = _settings_client.gui.max_departure_time * DAY_TICKS * _settings_game.economy.day_length_factor;
|
||||||
|
|
||||||
|
DateTicksScaled date_only_scaled = ((DateTicksScaled)_date * DAY_TICKS * _settings_game.economy.day_length_factor);
|
||||||
|
DateTicksScaled date_fract_scaled = ((DateTicksScaled)_date_fract * _settings_game.economy.day_length_factor) + _tick_skip_counter;
|
||||||
|
|
||||||
/* The scheduled order in next_orders with the earliest expected_date field. */
|
/* The scheduled order in next_orders with the earliest expected_date field. */
|
||||||
OrderDate *least_order = NULL;
|
OrderDate *least_order = NULL;
|
||||||
@@ -138,7 +141,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Order *order = (*v)->GetOrder((*v)->cur_implicit_order_index % (*v)->GetNumOrders());
|
const Order *order = (*v)->GetOrder((*v)->cur_implicit_order_index % (*v)->GetNumOrders());
|
||||||
DateTicks start_date = (DateTicks)_date_fract - ((*v)->current_order_time / _settings_game.economy.day_length_factor);
|
DateTicksScaled start_date = date_fract_scaled - (*v)->current_order_time;
|
||||||
DepartureStatus status = D_TRAVELLING;
|
DepartureStatus status = D_TRAVELLING;
|
||||||
|
|
||||||
/* If the vehicle is stopped in a depot, ignore it. */
|
/* If the vehicle is stopped in a depot, ignore it. */
|
||||||
@@ -280,7 +283,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
|
|||||||
|
|
||||||
/* We already know the least order and that it's a suitable departure, so make it into a departure. */
|
/* We already know the least order and that it's a suitable departure, so make it into a departure. */
|
||||||
Departure *d = new Departure();
|
Departure *d = new Departure();
|
||||||
d->scheduled_date = (DateTicks)_date * DAY_TICKS + least_order->expected_date - least_order->lateness;
|
d->scheduled_date = date_only_scaled + least_order->expected_date - least_order->lateness;
|
||||||
d->lateness = least_order->lateness;
|
d->lateness = least_order->lateness;
|
||||||
d->status = least_order->status;
|
d->status = least_order->status;
|
||||||
d->vehicle = least_order->v;
|
d->vehicle = least_order->v;
|
||||||
@@ -645,16 +648,6 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
|
|||||||
delete od;
|
delete od;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 day_len = _settings_game.economy.day_length_factor;
|
|
||||||
if (day_len > 1) {
|
|
||||||
DateTicks now = ((DateTicks)_date * DAY_TICKS) + _date_fract;
|
|
||||||
for (size_t i = 0; i < result->Length(); i++) {
|
|
||||||
Departure *dep = (*result)[i];
|
|
||||||
dep->scheduled_date = now + (dep->scheduled_date - now) / day_len;
|
|
||||||
dep->lateness /= day_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Done. Phew! */
|
/* Done. Phew! */
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -566,6 +566,9 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
|
|||||||
uint departure = 0;
|
uint departure = 0;
|
||||||
uint arrival = 0;
|
uint arrival = 0;
|
||||||
|
|
||||||
|
DateTicksScaled now_date = CURRENT_SCALED_TICKS;
|
||||||
|
DateTicksScaled max_date = now_date + (_settings_client.gui.max_departure_time * DAY_TICKS * _settings_game.economy.day_length_factor);
|
||||||
|
|
||||||
/* Draw each departure. */
|
/* Draw each departure. */
|
||||||
for (uint i = 0; i < max_departures; ++i) {
|
for (uint i = 0; i < max_departures; ++i) {
|
||||||
const Departure *d;
|
const Departure *d;
|
||||||
@@ -591,8 +594,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 for some reason the departure is too far in the future or is at a negative time, skip it. */
|
||||||
if ((d->scheduled_date / DAY_TICKS) > (_date + _settings_client.gui.max_departure_time) ||
|
if (d->scheduled_date > max_date || d->scheduled_date < 0) {
|
||||||
d->scheduled_date < 0) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -724,11 +726,11 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
|
|||||||
/* The vehicle has been cancelled. */
|
/* The vehicle has been cancelled. */
|
||||||
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_CANCELLED);
|
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_CANCELLED);
|
||||||
} else{
|
} else{
|
||||||
if (d->lateness <= DAY_TICKS && d->scheduled_date > ((_date * DAY_TICKS) + _date_fract)) {
|
if (d->lateness <= DATE_UNIT_SIZE && d->scheduled_date > now_date) {
|
||||||
/* We have no evidence that the vehicle is late, so assume it is on time. */
|
/* 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);
|
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_ON_TIME);
|
||||||
} else {
|
} else {
|
||||||
if ((d->scheduled_date + d->lateness) < ((_date * DAY_TICKS) + _date_fract)) {
|
if ((d->scheduled_date + d->lateness) < now_date) {
|
||||||
/* The vehicle was expected to have arrived by now, even if we knew it was going to be late. */
|
/* 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. */
|
/* 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);
|
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_DELAYED);
|
||||||
|
@@ -65,8 +65,8 @@ typedef struct CallAt {
|
|||||||
|
|
||||||
/** A scheduled departure. */
|
/** A scheduled departure. */
|
||||||
typedef struct Departure {
|
typedef struct Departure {
|
||||||
DateTicks scheduled_date; ///< The date this departure is scheduled to finish on (i.e. when the vehicle leaves the station)
|
DateTicksScaled scheduled_date; ///< The date this departure is scheduled to finish on (i.e. when the vehicle leaves the station)
|
||||||
DateTicks lateness; ///< How delayed the departure is expected to be
|
Ticks lateness; ///< How delayed the departure is expected to be
|
||||||
CallAt terminus; ///< The station at which the vehicle will terminate following this departure
|
CallAt terminus; ///< The station at which the vehicle will terminate following this departure
|
||||||
StationID via; ///< The station the departure should list as going via
|
StationID via; ///< The station the departure should list as going via
|
||||||
SmallVector<CallAt, 32> calling_at; ///< The stations both called at and unloaded at by the vehicle after this departure before it terminates
|
SmallVector<CallAt, 32> calling_at; ///< The stations both called at and unloaded at by the vehicle after this departure before it terminates
|
||||||
|
Reference in New Issue
Block a user