Codechange: Replace vehicle related FOR_ALL with range-based for loops

This commit is contained in:
glx
2019-12-17 03:37:43 +01:00
committed by Niels Martin Hansen
parent 9892d90b26
commit d8a1be48cd
39 changed files with 155 additions and 317 deletions

View File

@@ -71,8 +71,7 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine
engines->clear();
if (wagons != nullptr && wagons != engines) wagons->clear();
const Vehicle *v;
FOR_ALL_VEHICLES(v) {
for (const Vehicle *v : Vehicle::Iterate()) {
/* General tests for all vehicle types */
if (v->type != type) continue;
if (v->tile != tile) continue;
@@ -115,11 +114,9 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
{
list->clear();
const Vehicle *v;
switch (vli.type) {
case VL_STATION_LIST:
FOR_ALL_VEHICLES(v) {
for (const Vehicle *v : Vehicle::Iterate()) {
if (v->type == vli.vtype && v->IsPrimaryVehicle()) {
const Order *order;
@@ -134,19 +131,20 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
}
break;
case VL_SHARED_ORDERS:
case VL_SHARED_ORDERS: {
/* Add all vehicles from this vehicle's shared order list */
v = Vehicle::GetIfValid(vli.index);
const Vehicle *v = Vehicle::GetIfValid(vli.index);
if (v == nullptr || v->type != vli.vtype || !v->IsPrimaryVehicle()) return false;
for (; v != nullptr; v = v->NextShared()) {
list->push_back(v);
}
break;
}
case VL_GROUP_LIST:
if (vli.index != ALL_GROUP) {
FOR_ALL_VEHICLES(v) {
for (const Vehicle *v : Vehicle::Iterate()) {
if (v->type == vli.vtype && v->IsPrimaryVehicle() &&
v->owner == vli.company && GroupIsInGroup(v->group_id, vli.index)) {
list->push_back(v);
@@ -157,7 +155,7 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
FALLTHROUGH;
case VL_STANDARD:
FOR_ALL_VEHICLES(v) {
for (const Vehicle *v : Vehicle::Iterate()) {
if (v->type == vli.vtype && v->owner == vli.company && v->IsPrimaryVehicle()) {
list->push_back(v);
}
@@ -165,7 +163,7 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
break;
case VL_DEPOT_LIST:
FOR_ALL_VEHICLES(v) {
for (const Vehicle *v : Vehicle::Iterate()) {
if (v->type == vli.vtype && v->IsPrimaryVehicle()) {
const Order *order;