Departures: Use enum for departure show as type

Tidy up struct Departure field init
This commit is contained in:
Jonathan G Rennison 2024-09-09 17:49:21 +01:00
parent db9e2e545c
commit e7bd85926c
3 changed files with 35 additions and 21 deletions

View File

@ -121,9 +121,10 @@ bool DepartureCallingSettings::IsArrival(const Order *order, const DepartureOrde
});
}
bool DepartureCallingSettings::ShouldShowAsVia(const Order *order) const
DepartureShowAs DepartureCallingSettings::GetShowAsType(const Order *order, DepartureType type) const
{
return this->CheckShowAsViaType() && (order->GetType() == OT_GOTO_STATION) && !IsStationOrderWithWait(order);
if (this->CheckShowAsViaType() && (order->GetType() == OT_GOTO_STATION) && !IsStationOrderWithWait(order)) return DSA_VIA;
return DSA_NORMAL;
}
static uint8_t GetNonScheduleDepartureConditionalOrderMode(const Order *order, const Vehicle *v, StateTicks eval_tick)
@ -352,7 +353,7 @@ static void ScheduledDispatchSmartTerminusDetection(DepartureList &departure_lis
for (auto iter = departure_list.rbegin(); iter != departure_list.rend(); ++iter) {
Departure *d = iter->get();
if (d->show_as_via) continue;
if (d->show_as != DSA_NORMAL) continue;
check_departure(d);
}
@ -366,7 +367,7 @@ static void ScheduledDispatchSmartTerminusDetection(DepartureList &departure_lis
for (auto iter = departure_list.rbegin(); iter != departure_list.rend(); ++iter) {
Departure *d = iter->get();
if (d->show_as_via) continue;
if (d->show_as != DSA_NORMAL) continue;
check_departure(d);
}
@ -807,7 +808,7 @@ static DepartureList MakeDepartureListLiveMode(DepartureOrderDestinationDetector
d->status = lod.status;
d->vehicle = lod.v;
d->type = type;
d->show_as_via = calling_settings.ShouldShowAsVia(lod.order);
d->show_as = calling_settings.GetShowAsType(lod.order, type);
d->order = lod.order;
d->scheduled_waiting_time = lod.scheduled_waiting_time;
@ -1179,7 +1180,7 @@ void DepartureListScheduleModeSlotEvaluator::EvaluateFromSourceOrder(const Order
d.status = D_SCHEDULED;
d.vehicle = this->v;
d.type = this->type;
d.show_as_via = this->calling_settings.ShouldShowAsVia(source_order);
d.show_as = this->calling_settings.GetShowAsType(source_order, type);
d.order = source_order;
d.scheduled_waiting_time = 0;

View File

@ -907,7 +907,16 @@ void DeparturesWindow::DrawDeparturesListItems(const Rect &r) const
if (time_width > 0) {
StringID time_str;
TextColour time_colour = d->show_as_via ? TC_YELLOW : TC_ORANGE;
TextColour time_colour;
switch (d->show_as) {
default:
time_colour = TC_ORANGE;
break;
case DSA_VIA:
time_colour = TC_YELLOW;
break;
}
if (this->mode == DM_COMBINED) {
time_str = STR_DEPARTURES_TIME_BOTH;
SetDParam(0, time_colour);

View File

@ -60,22 +60,26 @@ struct RemoveVia {
uint calling_at_offset;
};
enum DepartureShowAs : uint8_t {
DSA_NORMAL,
DSA_VIA,
};
/** A scheduled departure. */
struct Departure {
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
CallAt terminus; ///< The station at which the vehicle will terminate following this departure
StateTicks scheduled_tick = 0; ///< The tick this departure is scheduled to finish on (i.e. when the vehicle leaves the station)
Ticks lateness = 0; ///< How delayed the departure is expected to be
StationID via = INVALID_STATION; ///< The station the departure should list as going via
StationID via2 = INVALID_STATION; ///< Secondary station the departure should list as going via
CallAt terminus = INVALID_STATION; ///< The station at which the vehicle will terminate following this departure
std::vector<CallAt> calling_at; ///< The stations both called at and unloaded at by the vehicle after this departure before it terminates
std::vector<RemoveVia> remove_vias; ///< Vias to remove when using smart terminus.
DepartureStatus status; ///< Whether the vehicle has arrived yet for this departure
DepartureType type; ///< The type of the departure (departure or arrival)
bool show_as_via; ///< Show as via departure
const Vehicle *vehicle; ///< The vehicle performing this departure
const Order *order; ///< The order corresponding to this departure
Ticks scheduled_waiting_time; ///< Scheduled waiting time if scheduled dispatch is used
Departure() : via(INVALID_STATION), via2(INVALID_STATION), terminus(INVALID_STATION), vehicle(nullptr), order(nullptr) { }
DepartureStatus status{}; ///< Whether the vehicle has arrived yet for this departure
DepartureType type{}; ///< The type of the departure (departure or arrival)
DepartureShowAs show_as = DSA_NORMAL; ///< Show as type
const Vehicle *vehicle = nullptr; ///< The vehicle performing this departure
const Order *order = nullptr; ///< The order corresponding to this departure
Ticks scheduled_waiting_time = 0; ///< Scheduled waiting time if scheduled dispatch is used
inline bool operator==(const Departure& d) const {
if (this->calling_at.size() != d.calling_at.size()) return false;
@ -92,7 +96,7 @@ struct Departure {
this->via == d.via &&
this->via2 == d.via2 &&
this->type == d.type &&
this->show_as_via == d.show_as_via;
this->show_as == d.show_as;
}
inline Ticks EffectiveWaitingTime() const
@ -186,7 +190,7 @@ public:
bool IsDeparture(const Order *order, const DepartureOrderDestinationDetector &source) const;
bool IsArrival(const Order *order, const DepartureOrderDestinationDetector &source) const;
bool ShouldShowAsVia(const Order *order) const;
DepartureShowAs GetShowAsType(const Order *order, DepartureType type) const;
};
typedef std::vector<std::unique_ptr<Departure>> DepartureList;