diff --git a/src/departures.cpp b/src/departures.cpp index 8f7d7d20ff..8e9975fe03 100644 --- a/src/departures.cpp +++ b/src/departures.cpp @@ -94,7 +94,10 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5], SmallVector next_orders; /* 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. */ 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()); - 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; /* 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. */ 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->status = least_order->status; d->vehicle = least_order->v; @@ -645,16 +648,6 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5], 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! */ return result; } diff --git a/src/departures_gui.cpp b/src/departures_gui.cpp index c88326d2f3..94891d7681 100644 --- a/src/departures_gui.cpp +++ b/src/departures_gui.cpp @@ -566,6 +566,9 @@ void DeparturesWindow::DrawDeparturesListItems(const Rect &r) const uint departure = 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. */ for (uint i = 0; i < max_departures; ++i) { const Departure *d; @@ -591,8 +594,7 @@ void DeparturesWindow::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 / DAY_TICKS) > (_date + _settings_client.gui.max_departure_time) || - d->scheduled_date < 0) { + if (d->scheduled_date > max_date || d->scheduled_date < 0) { continue; } @@ -724,11 +726,11 @@ void DeparturesWindow::DrawDeparturesListItems(const Rect &r) const /* The vehicle has been cancelled. */ DrawString(status_left, status_right, y + 1, STR_DEPARTURES_CANCELLED); } 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. */ DrawString(status_left, status_right, y + 1, STR_DEPARTURES_ON_TIME); } 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. */ /* 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); diff --git a/src/departures_type.h b/src/departures_type.h index b92509463c..b71ea62d7e 100644 --- a/src/departures_type.h +++ b/src/departures_type.h @@ -65,11 +65,11 @@ typedef struct CallAt { /** A scheduled departure. */ typedef struct Departure { - DateTicks 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 - CallAt terminus; ///< The station at which the vehicle will terminate following this departure + DateTicksScaled scheduled_date; ///< The date 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 + CallAt terminus; ///< The station at which the vehicle will terminate following this departure StationID via; ///< The station the departure should list as going via - SmallVector calling_at; ///< The stations both called at and unloaded at by the vehicle after this departure before it terminates + SmallVector calling_at; ///< The stations both called at and unloaded at by the vehicle after this departure before it terminates DepartureStatus status; ///< Whether the vehicle has arrived yet for this departure DepartureType type; ///< The type of the departure (departure or arrival) const Vehicle *vehicle; ///< The vehicle performing this departure