function Utils::GetVehicleID(vehicle_unitnumber, vehicle_type)
{
if (!(vehicle_unitnumber > 0 && vehicle_unitnumber <= 0xFFFF)) return AIVehicle.VEHICLE_INVALID;
if (!(vehicle_type >= AIVehicle.VT_RAIL && vehicle_type <= AIVehicle.VT_AIR)) return AIVehicle.VEHICLE_INVALID;
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 AIVehicle.VEHICLE_INVALID;
}
function Utils::VehicleUnitNumberList(vehicle_type)
{
local vehicleUnitNumberList = AIList();
local vehicleList = AIVehicleList();
local count = 0;
for (local vehicle_id = vehicleList.Begin(); !vehicleList.IsEnd(); vehicle_id = vehicleList.Next()) {
if (AIVehicle.IsValidVehicle(vehicle_id)) {
local vehicle_id_type = AIVehicle.GetVehicleType(vehicle_id);
if (vehicle_id_type == vehicle_type) {
local vehicle_unitnumber = AIVehicle.GetUnitNumber(vehicle_id);
if (Utils.IsValidVehicle(vehicle_unitnumber, vehicle_id_type)) {
if (!vehicleUnitNumberList.HasItem(vehicle_unitnumber)) {
count++;
AILog.Info("vehicleUnitNumberList.AddItem(" + vehicle_unitnumber + "," + vehicle_id_type + ") #" + count);
vehicleUnitNumberList.AddItem(vehicle_unitnumber, vehicle_id_type);
}
}
}
}
}
return vehicleUnitNumberList;
}
function Utils::VehicleUnitNumberList_Station(station_id, vehicle_type)
{
local vehicleUnitNumberList_Station = AIList();
if (AIBaseStation.IsValidBaseStation(station_id)) {
local vehicleUnitNumberList = Utils.VehicleUnitNumberList(vehicle_type);
local count = 0;
for (local vehicle_unitnumber = vehicleUnitNumberList.Begin(); !vehicleUnitNumberList.IsEnd(); vehicle_unitnumber = vehicleUnitNumberList.Next()) {
local vehicle_unitnumber_type = vehicleUnitNumberList.GetValue(vehicle_unitnumber);
if (Utils.IsValidVehicle(vehicle_unitnumber, vehicle_unitnumber_type)) {
if (vehicle_unitnumber_type == vehicle_type) {
local order_count = Utils.GetOrderCount(vehicle_unitnumber, vehicle_unitnumber_type);
if (order_count > 0) {
local orderList = AIList();
for (local order_position = 0; order_position < order_count; ++order_position) {
if (Utils.IsValidVehicleOrder(vehicle_unitnumber, vehicle_unitnumber_type, order_position)) {
if (Utils.IsGotoStationOrder(vehicle_unitnumber, vehicle_unitnumber_type, order_position) || Utils.IsGotoWaypointOrder(vehicle_unitnumber, vehicle_unitnumber_type, order_position)) {
local order_destination_tile = Utils.GetOrderDestination(vehicle_unitnumber, vehicle_unitnumber_type, order_position);
if (AIMap.IsValidTile(order_destination_tile)) {
local order_destination_station_id = AIStation.GetStationID(order_destination_tile);
if (AIBaseStation.IsValidBaseStation(order_destination_station_id)) {
if (order_destination_station_id == station_id) {
if (!vehicleUnitNumberList_Station.HasItem(vehicle_unitnumber)) {
count++;
AILog.Info("vehicleUnitNumberList_Station.AddItem(" + vehicle_unitnumber + "," + vehicle_unitnumber_type + ") #" + count);
vehicleUnitNumberList_Station.AddItem(vehicle_unitnumber, vehicle_unitnumber_type);
}
}
}
}
}
}
}
}
}
}
}
}
return vehicleUnitNumberList_Station;
}
function Utils::VehicleUnitNumberList_Group(group_id, vehicle_type)
{
local vehicleUnitNumberList_Group = AIList();
if (AIGroup.IsValidGroup(group_id)) {
local vehicleUnitNumberList = Utils.VehicleUnitNumberList(vehicle_type);
local count = 0;
for (local vehicle_unitnumber = vehicleUnitNumberList.Begin(); !vehicleUnitNumberList.IsEnd(); vehicle_unitnumber = vehicleUnitNumberList.Next()) {
local vehicle_unitnumber_type = vehicleUnitNumberList.GetValue(vehicle_unitnumber);
if (Utils.IsValidVehicle(vehicle_unitnumber, vehicle_unitnumber_type)) {
if (vehicle_unitnumber_type == vehicle_type) {
local vehicle_group_id = Utils.GetGroupID(vehicle_unitnumber, vehicle_unitnumber_type);
if (AIGroup.IsValidGroup(vehicle_group_id)) {
if (vehicle_group_id == group_id) {
if (!vehicleUnitNumberList_Group.HasItem(vehicle_unitnumber)) {
count++;
AILog.Info("vehicleUnitNumberList_Group.AddItem(" + vehicle_unitnumber + "," + vehicle_unitnumber_type + ") #" + count);
vehicleUnitNumberList_Group.AddItem(vehicle_unitnumber, vehicle_unitnumber_type);
}
}
}
}
}
}
}
return vehicleUnitNumberList_Group;
}
function Utils::MoveVehicle(group_id, vehicle_unitnumber, vehicle_type)
{
return AIGroup.MoveVehicle(group_id, Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::IsValidVehicleOrder(vehicle_unitnumber, vehicle_type, order_position)
{
return AIOrder.IsValidVehicleOrder(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
}
function Utils::IsGotoStationOrder(vehicle_unitnumber, vehicle_type, order_position)
{
return AIOrder.IsGotoStationOrder(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
}
function Utils::IsGotoWaypointOrder(vehicle_unitnumber, vehicle_type, order_position)
{
return AIOrder.IsGotoWaypointOrder(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
}
function Utils::GetOrderCount(vehicle_unitnumber, vehicle_type)
{
return AIOrder.GetOrderCount(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetOrderDestination(vehicle_unitnumber, vehicle_type, order_position)
{
return AIOrder.GetOrderDestination(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
}
function Utils::GetOrderFlags(vehicle_unitnumber, vehicle_type, order_position)
{
return AIOrder.GetOrderFlags(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), order_position);
}
function Utils::AppendOrder(vehicle_unitnumber, vehicle_type, destination_tile, order_flags)
{
return AIOrder.AppendOrder(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), destination_tile, order_flags);
}
function Utils::ShareOrders(vehicle_unitnumber, vehicle_type, main_vehicle_unitnumber, main_vehicle_type)
{
return AIOrder.ShareOrders(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type), Utils.GetVehicleID(main_vehicle_unitnumber, main_vehicle_type));
}
function Utils::IsValidVehicle(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.IsValidVehicle(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetName(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetName(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetEngineType(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetEngineType(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetAge(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetAge(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetAgeLeft(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetAgeLeft(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetCurrentSpeed(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetCurrentSpeed(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetState(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetState(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetProfitThisYear(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetProfitThisYear(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetProfitLastYear(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetProfitLastYear(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetVehicleType(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetVehicleType(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetRoadType(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetRoadType(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::IsStoppedInDepot(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.IsStoppedInDepot(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::SellVehicle(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.SellVehicle(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::SendVehicleToDepot(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.SendVehicleToDepot(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::StartStopVehicle(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.StartStopVehicle(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::GetGroupID(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.GetGroupID(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::IsArticulated(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.IsArticulated(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}
function Utils::HasSharedOrders(vehicle_unitnumber, vehicle_type)
{
return AIVehicle.HasSharedOrders(Utils.GetVehicleID(vehicle_unitnumber, vehicle_type));
}