Reduce duplication when iterating shared orders for departure board

This commit is contained in:
Jonathan G Rennison
2024-06-27 21:19:54 +01:00
parent 93d2b6716e
commit af11b76877

View File

@@ -164,29 +164,31 @@ protected:
CompanyMask companies = 0; CompanyMask companies = 0;
int unitnumber_max[4] = { -1, -1, -1, -1 }; int unitnumber_max[4] = { -1, -1, -1, -1 };
for (const Vehicle *v : Vehicle::IterateFrontOnly()) { for (const Vehicle *veh : Vehicle::IterateFrontOnly()) {
if (v->type < 4 && this->show_types[v->type] && v->IsPrimaryVehicle()) { if (veh->type < 4 && this->show_types[veh->type] && veh->IsPrimaryVehicle() && veh == veh->FirstShared()) {
for(const Order *order : v->Orders()) { for (const Order *order : veh->Orders()) {
if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT) || order->IsType(OT_IMPLICIT)) if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT) || order->IsType(OT_IMPLICIT))
&& order->GetDestination() == this->station) { && order->GetDestination() == this->station) {
this->vehicles.push_back(v); for (const Vehicle *v = veh; v != nullptr; v = v->NextShared()) {
this->vehicles.push_back(v);
if (_settings_client.gui.departure_show_vehicle) { if (_settings_client.gui.departure_show_vehicle) {
if (v->name.empty() && !(v->group_id != DEFAULT_GROUP && _settings_client.gui.vehicle_names != 0)) { if (v->name.empty() && !(v->group_id != DEFAULT_GROUP && _settings_client.gui.vehicle_names != 0)) {
if (v->unitnumber > unitnumber_max[v->type]) unitnumber_max[v->type] = v->unitnumber; if (v->unitnumber > unitnumber_max[v->type]) unitnumber_max[v->type] = v->unitnumber;
} else { } else {
SetDParam(0, v->index | (_settings_client.gui.departure_show_group ? VEHICLE_NAME_NO_GROUP : 0)); SetDParam(0, v->index | (_settings_client.gui.departure_show_group ? VEHICLE_NAME_NO_GROUP : 0));
int width = (GetStringBoundingBox(STR_DEPARTURES_VEH)).width + 4; int width = (GetStringBoundingBox(STR_DEPARTURES_VEH)).width + 4;
if (width > this->veh_width) this->veh_width = width; if (width > this->veh_width) this->veh_width = width;
}
} }
}
if (v->group_id != INVALID_GROUP && v->group_id != DEFAULT_GROUP && _settings_client.gui.departure_show_group) { if (v->group_id != INVALID_GROUP && v->group_id != DEFAULT_GROUP && _settings_client.gui.departure_show_group) {
groups.insert(v->group_id); groups.insert(v->group_id);
} }
if (_settings_client.gui.departure_show_company) { if (_settings_client.gui.departure_show_company) {
SetBit(companies, v->owner); SetBit(companies, v->owner);
}
} }
break; break;
} }