Initial implementation of trace restrict slots

This commit is contained in:
Jonathan G Rennison
2017-03-30 21:14:14 +01:00
parent 688ee9ac11
commit 6417fb16c3
20 changed files with 1514 additions and 20 deletions

View File

@@ -13,6 +13,7 @@
#include "train.h"
#include "vehiclelist.h"
#include "group.h"
#include "tracerestrict.h"
#include "safeguards.h"
@@ -119,6 +120,14 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
const Vehicle *v;
auto fill_all_vehicles = [&]() {
FOR_ALL_VEHICLES(v) {
if (v->type == vli.vtype && v->owner == vli.company && v->IsPrimaryVehicle()) {
*list->Append() = v;
}
}
};
switch (vli.type) {
case VL_STATION_LIST:
FOR_ALL_VEHICLES(v) {
@@ -156,14 +165,11 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
}
break;
}
/* FALL THROUGH */
fill_all_vehicles();
break;
case VL_STANDARD:
FOR_ALL_VEHICLES(v) {
if (v->type == vli.vtype && v->owner == vli.company && v->IsPrimaryVehicle()) {
*list->Append() = v;
}
}
fill_all_vehicles();
break;
case VL_DEPOT_LIST:
@@ -181,6 +187,19 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
}
break;
case VL_SLOT_LIST: {
if (vli.index == ALL_TRAINS_TRACE_RESTRICT_SLOT_ID) {
fill_all_vehicles();
} else {
const TraceRestrictSlot *slot = TraceRestrictSlot::GetIfValid(vli.index);
if (slot == NULL) return false;
for (VehicleID id : slot->occupants) {
*list->Append() = Vehicle::Get(id);
}
}
break;
}
default: return false;
}