function GetVehicleIndex(vehicle_unitnumber, vehicle_type)
{
if (!(vehicle_unitnumber > 0 && vehicle_unitnumber <= 0xFFFF)) return INVALID_VEHICLE;
if (!(vehicle_type >= AIVehicle.VT_RAIL && vehicle_type <= AIVehicle.VT_AIR)) return INVALID_VEHICLE;
local VehicleList = AIVehicleList();
for (local vehicle = VehicleList.Begin(); !VehicleList.IsEnd(); vehicle = VehicleList.Next()) {
if (AIVehicle.GetVehicleType(vehicle) == vehicle_type && AIVehicle.GetUnitNumber(vehicle) == vehicle_unitnumber) return vehicle;
}
return INVALID_VEHICLE;
}
function GroupVehicles() {
local vehicleList = AIVehicleList();
local unitnumberList = AIList();
for (local vehicle = vehicleList.Begin(); !vehicleList.IsEnd(); vehicle = vehicleList.Next()) {
local vehicle_type = AIVehicle.GetVehicleType(vehicle);
if (AIVehicle.IsValidVehicle(vehicle) && vehicle_type == AIVehicle.VT_ROAD) {
local unitnumber = AIVehicle.GetUnitNumber(vehicle);
if (unitnumber > 0 && unitnumber <= 0xFFFF) {
if (!unitnumberList.HasItem(unitnumber)) {
unitnumberList.AddItem(unitnumber, vehicle_type));
} else {
local value = unitnumberList.GetValue(unitnumber);
if (value != vehicle_type) {
unitnumberList.SetValue(unitnumber, vehicle_type);
}
}
}
}
}
// Later on....
for (local unitnumber = unitnumberList.Begin(); !unitnumberList.IsEnd(); unitnumber = unitnumberList.Next()) {
local vehicle_type = unitnumberList.GetValue(unitnumber);
local vehicle_id = GetVehicleIndex(unitnumber, vehicle_type);
if (AIVehicle.IsValidVehicle(vehicle_id) && AIVehicle.GetVehicleType(vehicle_id) == AIVehicle.VT.ROAD) {
AILog.Info("The vehicle with unitnumber " + unitnumber + " has a redirected VehicleID of " + vehicle_id);
}
}
}