Loading

Paste #p0irrknxg

  1.     function GetVehicleIndex(vehicle_unitnumber, vehicle_type)
  2.     {
  3.         if (!(vehicle_unitnumber > 0 && vehicle_unitnumber <= 0xFFFF)) return INVALID_VEHICLE;
  4.         if (!(vehicle_type >= AIVehicle.VT_RAIL && vehicle_type <= AIVehicle.VT_AIR)) return INVALID_VEHICLE;
  5.        
  6.         local VehicleList = AIVehicleList();
  7.         for (local vehicle = VehicleList.Begin(); !VehicleList.IsEnd(); vehicle = VehicleList.Next()) {
  8.             if (AIVehicle.GetVehicleType(vehicle) == vehicle_type && AIVehicle.GetUnitNumber(vehicle) == vehicle_unitnumber) return vehicle;
  9.         }
  10.         return INVALID_VEHICLE;
  11.     }
  12.    
  13.     function GroupVehicles() {
  14.         local vehicleList = AIVehicleList();
  15.         local unitnumberList = AIList();
  16.         for (local vehicle = vehicleList.Begin(); !vehicleList.IsEnd(); vehicle = vehicleList.Next()) {
  17.             local vehicle_type = AIVehicle.GetVehicleType(vehicle);
  18.             if (AIVehicle.IsValidVehicle(vehicle) && vehicle_type == AIVehicle.VT_ROAD) {
  19.                 local unitnumber = AIVehicle.GetUnitNumber(vehicle);
  20.                 if (unitnumber > 0 && unitnumber <= 0xFFFF) {
  21.                     if (!unitnumberList.HasItem(unitnumber)) {
  22.                         unitnumberList.AddItem(unitnumber, vehicle_type));
  23.                     } else {
  24.                         local value = unitnumberList.GetValue(unitnumber);
  25.                         if (value != vehicle_type) {
  26.                             unitnumberList.SetValue(unitnumber, vehicle_type);
  27.                         }
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.        
  33.         // Later on....
  34.         for (local unitnumber = unitnumberList.Begin(); !unitnumberList.IsEnd(); unitnumber = unitnumberList.Next()) {
  35.             local vehicle_type = unitnumberList.GetValue(unitnumber);
  36.             local vehicle_id = GetVehicleIndex(unitnumber, vehicle_type);
  37.             if (AIVehicle.IsValidVehicle(vehicle_id) && AIVehicle.GetVehicleType(vehicle_id) == AIVehicle.VT.ROAD) {
  38.                 AILog.Info("The vehicle with unitnumber " + unitnumber + " has a redirected VehicleID of " + vehicle_id);
  39.             }
  40.         }
  41.     }

Comments