Loading

Paste #pbq3ammjp

  1. function Utils::GetVehicleID(vehicle_unitnumber, vehicle_type)
  2. {
  3.     if (!(vehicle_unitnumber > 0 && vehicle_unitnumber <= 0xFFFF)) return AIVehicle.VEHICLE_INVALID;
  4.     if (!(vehicle_type >= AIVehicle.VT_RAIL && vehicle_type <= AIVehicle.VT_AIR)) return AIVehicle.VEHICLE_INVALID;
  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 AIVehicle.VEHICLE_INVALID;
  11. }
  12.  
  13. function Utils::VehicleUnitNumberList(vehicle_type)
  14. {
  15.     local vehicleUnitNumberList = AIList();
  16.     local vehicleList = AIVehicleList();
  17.     local count = 0;
  18.     for (local vehicle_id = vehicleList.Begin(); !vehicleList.IsEnd(); vehicle_id = vehicleList.Next()) {
  19.         if (AIVehicle.IsValidVehicle(vehicle_id)) {
  20.             local vehicle_id_type = AIVehicle.GetVehicleType(vehicle_id);
  21.             if (vehicle_id_type == vehicle_type) {
  22.                 local vehicle_unitnumber = AIVehicle.GetUnitNumber(vehicle_id);
  23.                 if (Utils.IsValidVehicle(vehicle_unitnumber, vehicle_id_type)) {
  24.                     if (!vehicleUnitNumberList.HasItem(vehicle_unitnumber)) {
  25.                         count++;
  26.                         AILog.Info("vehicleUnitNumberList.AddItem(" + vehicle_unitnumber + "," + vehicle_id_type + ") #" + count);
  27.                         vehicleUnitNumberList.AddItem(vehicle_unitnumber, vehicle_id_type);
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.     }
  33.     return vehicleUnitNumberList;
  34. }
  35.  
  36. function Utils::VehicleUnitNumberList_Station(station_id, vehicle_type)
  37. {
  38.     local vehicleUnitNumberList_Station = AIList();
  39.     if (AIBaseStation.IsValidBaseStation(station_id)) {
  40.         local vehicleUnitNumberList = Utils.VehicleUnitNumberList(vehicle_type);
  41.         local count = 0;
  42.         for (local vehicle_unitnumber = vehicleUnitNumberList.Begin(); !vehicleUnitNumberList.IsEnd(); vehicle_unitnumber = vehicleUnitNumberList.Next()) {
  43.             local vehicle_unitnumber_type = vehicleUnitNumberList.GetValue(vehicle_unitnumber);
  44.             if (Utils.IsValidVehicle(vehicle_unitnumber, vehicle_unitnumber_type)) {
  45.                 if (vehicle_unitnumber_type == vehicle_type) {
  46.                     local order_count = Utils.GetOrderCount(vehicle_unitnumber, vehicle_unitnumber_type);
  47.                     if (order_count > 0) {
  48.                         local orderList = AIList();
  49.                         for (local order_position = 0; order_position < order_count; ++order_position) {
  50.                             if (Utils.IsValidVehicleOrder(vehicle_unitnumber, vehicle_unitnumber_type, order_position)) {
  51.                                 if (Utils.IsGotoStationOrder(vehicle_unitnumber, vehicle_unitnumber_type, order_position) || Utils.IsGotoWaypointOrder(vehicle_unitnumber, vehicle_unitnumber_type, order_position)) {
  52.                                     local order_destination_tile = Utils.GetOrderDestination(vehicle_unitnumber, vehicle_unitnumber_type, order_position);
  53.                                     if (AIMap.IsValidTile(order_destination_tile)) {
  54.                                         local order_destination_station_id = AIStation.GetStationID(order_destination_tile);
  55.                                         if (AIBaseStation.IsValidBaseStation(order_destination_station_id)) {
  56.                                             if (order_destination_station_id == station_id) {
  57.                                                 if (!vehicleUnitNumberList_Station.HasItem(vehicle_unitnumber)) {
  58.                                                     count++;
  59.                                                     AILog.Info("vehicleUnitNumberList_Station.AddItem(" + vehicle_unitnumber + "," + vehicle_unitnumber_type + ") #" + count);
  60.                                                     vehicleUnitNumberList_Station.AddItem(vehicle_unitnumber, vehicle_unitnumber_type);
  61.                                                 }
  62.                                             }
  63.                                         }
  64.                                     }
  65.                                 }
  66.                             }
  67.                         }
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.     }
  73.     return vehicleUnitNumberList_Station;
  74. }
  75.  
  76. function Utils::VehicleUnitNumberList_Group(group_id, vehicle_type)
  77. {
  78.     local vehicleUnitNumberList_Group = AIList();
  79.     if (AIGroup.IsValidGroup(group_id)) {
  80.         local vehicleUnitNumberList = Utils.VehicleUnitNumberList(vehicle_type);
  81.         local count = 0;
  82.         for (local vehicle_unitnumber = vehicleUnitNumberList.Begin(); !vehicleUnitNumberList.IsEnd(); vehicle_unitnumber = vehicleUnitNumberList.Next()) {
  83.             local vehicle_unitnumber_type = vehicleUnitNumberList.GetValue(vehicle_unitnumber);
  84.             if (Utils.IsValidVehicle(vehicle_unitnumber, vehicle_unitnumber_type)) {
  85.                 if (vehicle_unitnumber_type == vehicle_type) {
  86.                     local vehicle_group_id = Utils.GetGroupID(vehicle_unitnumber, vehicle_unitnumber_type);
  87.                     if (AIGroup.IsValidGroup(vehicle_group_id)) {
  88.                         if (vehicle_group_id == group_id) {
  89.                             if (!vehicleUnitNumberList_Group.HasItem(vehicle_unitnumber)) {
  90.                                 count++;
  91.                                 AILog.Info("vehicleUnitNumberList_Group.AddItem(" + vehicle_unitnumber + "," + vehicle_unitnumber_type + ") #" + count);
  92.                                 vehicleUnitNumberList_Group.AddItem(vehicle_unitnumber, vehicle_unitnumber_type);
  93.                             }
  94.                         }
  95.                     }
  96.                 }
  97.             }
  98.         }
  99.     }
  100.     return vehicleUnitNumberList_Group;
  101. }
  102.  
  103. function Utils::MoveVehicle(group_id, vehicle_unitnumber, vehicle_type)
  104. {
  105.     return AIGroup.MoveVehicle(group_id, Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  106. }
  107.  
  108. function Utils::IsValidVehicleOrder(vehicle_unitnumber, vehicle_type, order_position)
  109. {
  110.     return AIOrder.IsValidVehicleOrder(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
  111. }
  112.  
  113. function Utils::IsGotoStationOrder(vehicle_unitnumber, vehicle_type, order_position)
  114. {
  115.     return AIOrder.IsGotoStationOrder(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
  116. }
  117.  
  118. function Utils::IsGotoWaypointOrder(vehicle_unitnumber, vehicle_type, order_position)
  119. {
  120.     return AIOrder.IsGotoWaypointOrder(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
  121. }
  122.  
  123. function Utils::GetOrderCount(vehicle_unitnumber, vehicle_type)
  124. {
  125.     return AIOrder.GetOrderCount(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  126. }
  127.  
  128. function Utils::GetOrderDestination(vehicle_unitnumber, vehicle_type, order_position)
  129. {
  130.     return AIOrder.GetOrderDestination(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
  131. }
  132.  
  133. function Utils::GetOrderFlags(vehicle_unitnumber, vehicle_type, order_position)
  134. {
  135.     return AIOrder.GetOrderFlags(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
  136. }
  137.  
  138. function Utils::AppendOrder(vehicle_unitnumber, vehicle_type, destination_tile, order_flags)
  139. {
  140.     return AIOrder.AppendOrder(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), destination_tile, order_flags);
  141. }
  142.  
  143. function Utils::ShareOrders(vehicle_unitnumber, vehicle_type, main_vehicle_unitnumber, main_vehicle_type)
  144. {
  145.     return AIOrder.ShareOrders(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), Utils.GetVehicleID(main_vehicle_unitnumber, main_vehicle_type));
  146. }
  147.  
  148. function Utils::IsValidVehicle(vehicle_unitnumber, vehicle_type)
  149. {
  150.     return AIVehicle.IsValidVehicle(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  151. }
  152.  
  153. function Utils::GetName(vehicle_unitnumber, vehicle_type)
  154. {
  155.     return AIVehicle.GetName(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  156. }
  157.  
  158. function Utils::GetEngineType(vehicle_unitnumber, vehicle_type)
  159. {
  160.     return AIVehicle.GetEngineType(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  161. }
  162.  
  163. function Utils::GetAge(vehicle_unitnumber, vehicle_type)
  164. {
  165.     return AIVehicle.GetAge(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  166. }
  167.  
  168. function Utils::GetAgeLeft(vehicle_unitnumber, vehicle_type)
  169. {
  170.     return AIVehicle.GetAgeLeft(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  171. }
  172.  
  173. function Utils::GetCurrentSpeed(vehicle_unitnumber, vehicle_type)
  174. {
  175.     return AIVehicle.GetCurrentSpeed(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  176. }
  177.  
  178. function Utils::GetState(vehicle_unitnumber, vehicle_type)
  179. {
  180.     return AIVehicle.GetState(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  181. }
  182.  
  183. function Utils::GetProfitThisYear(vehicle_unitnumber, vehicle_type)
  184. {
  185.     return AIVehicle.GetProfitThisYear(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  186. }
  187.  
  188. function Utils::GetProfitLastYear(vehicle_unitnumber, vehicle_type)
  189. {
  190.     return AIVehicle.GetProfitLastYear(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  191. }
  192.  
  193. function Utils::GetVehicleType(vehicle_unitnumber, vehicle_type)
  194. {
  195.     return AIVehicle.GetVehicleType(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  196. }
  197.  
  198. function Utils::GetRoadType(vehicle_unitnumber, vehicle_type)
  199. {
  200.     return AIVehicle.GetRoadType(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  201. }
  202.  
  203. function Utils::IsStoppedInDepot(vehicle_unitnumber, vehicle_type)
  204. {
  205.     return AIVehicle.IsStoppedInDepot(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  206. }
  207.  
  208. function Utils::SellVehicle(vehicle_unitnumber, vehicle_type)
  209. {
  210.     return AIVehicle.SellVehicle(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  211. }
  212.  
  213. function Utils::SendVehicleToDepot(vehicle_unitnumber, vehicle_type)
  214. {
  215.     return AIVehicle.SendVehicleToDepot(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  216. }
  217.  
  218. function Utils::StartStopVehicle(vehicle_unitnumber, vehicle_type)
  219. {
  220.     return AIVehicle.StartStopVehicle(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  221. }
  222.  
  223. function Utils::GetGroupID(vehicle_unitnumber, vehicle_type)
  224. {
  225.     return AIVehicle.GetGroupID(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  226. }
  227.  
  228. function Utils::IsArticulated(vehicle_unitnumber, vehicle_type)
  229. {
  230.     return AIVehicle.IsArticulated(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  231. }
  232.  
  233. function Utils::HasSharedOrders(vehicle_unitnumber, vehicle_type)
  234. {
  235.     return AIVehicle.HasSharedOrders(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
  236. }

Comments