mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Iterate group vehicle lists for GenerateVehicleSortList
parent
021817aa61
commit
b9627b36b9
|
@ -116,8 +116,11 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
|
||||||
|
|
||||||
switch (vli.type) {
|
switch (vli.type) {
|
||||||
case VL_STATION_LIST:
|
case VL_STATION_LIST:
|
||||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
for (const Company *c : Company::Iterate()) {
|
||||||
if (v->type == vli.vtype && v->IsPrimaryVehicle()) {
|
/* Only iterate over all companies in the case of neutral Oil Rig stations */
|
||||||
|
if (vli.company != c->index && vli.company != OWNER_NONE) continue;
|
||||||
|
const VehicleList &vehicle_list = c->group_all[vli.vtype].vehicle_list;
|
||||||
|
for (const Vehicle *v : vehicle_list) {
|
||||||
for (const Order *order : v->Orders()) {
|
for (const Order *order : v->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() == vli.index) {
|
&& order->GetDestination() == vli.index) {
|
||||||
|
@ -141,37 +144,48 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
|
||||||
}
|
}
|
||||||
|
|
||||||
case VL_GROUP_LIST:
|
case VL_GROUP_LIST:
|
||||||
|
if (vli.index == DEFAULT_GROUP) {
|
||||||
|
const VehicleList &vehicle_list = Company::Get(vli.company)->group_default[vli.vtype].vehicle_list;
|
||||||
|
for (const Vehicle *v : vehicle_list) {
|
||||||
|
list->push_back(v);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (vli.index != ALL_GROUP) {
|
if (vli.index != ALL_GROUP) {
|
||||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
for (const Group *g : Group::Iterate()) {
|
||||||
if (v->type == vli.vtype && v->IsPrimaryVehicle() &&
|
if (g->owner != vli.company || g->vehicle_type != vli.vtype) continue;
|
||||||
v->owner == vli.company && GroupIsInGroup(v->group_id, vli.index)) {
|
if (GroupIsInGroup(g->index, vli.index)) {
|
||||||
list->push_back(v);
|
const VehicleList &vehicle_list = g->statistics.vehicle_list;
|
||||||
|
for (const Vehicle *v : vehicle_list) {
|
||||||
|
list->push_back(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
|
|
||||||
case VL_STANDARD:
|
case VL_STANDARD: {
|
||||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
const VehicleList &vehicle_list = Company::Get(vli.company)->group_all[vli.vtype].vehicle_list;
|
||||||
if (v->type == vli.vtype && v->owner == vli.company && v->IsPrimaryVehicle()) {
|
for (const Vehicle *v : vehicle_list) {
|
||||||
list->push_back(v);
|
list->push_back(v);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case VL_DEPOT_LIST:
|
case VL_DEPOT_LIST: {
|
||||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
const VehicleList &vehicle_list = Company::Get(vli.company)->group_all[vli.vtype].vehicle_list;
|
||||||
if (v->type == vli.vtype && v->IsPrimaryVehicle()) {
|
for (const Vehicle *v : vehicle_list) {
|
||||||
for (const Order *order : v->Orders()) {
|
for (const Order *order : v->Orders()) {
|
||||||
if (order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == vli.index) {
|
if (order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == vli.index) {
|
||||||
list->push_back(v);
|
list->push_back(v);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue