public static VehicleInfo GetVehicleInfo(ref Randomizer randomizer, ItemClass m_class, ushort lineID, string prefabName)
        {
            PrefabData prefabData = Array.Find(VehiclePrefabs.instance.GetPrefabs(m_class.m_service, m_class.m_subService, m_class.m_level),
                                               item => item.ObjectName == prefabName);

            if (prefabData != null)
            {
                return(PrefabCollection <VehicleInfo> .GetPrefab((uint)prefabData.PrefabDataIndex));
            }
            Utils.LogWarning((object)("Unknown prefab: " + prefabName));
            VehicleManager instance = Singleton <VehicleManager> .instance;

            instance.RefreshTransferVehicles();

            int service    = (int)m_class.m_service;
            int subService = (int)m_class.m_subService;
            int level      = (int)m_class.m_level;

            return(instance.GetRandomVehicleInfo(ref randomizer, (ItemClass.Service)service, (ItemClass.SubService)subService, (ItemClass.Level)level));
        }
        private static VehicleInfo GetCargoVehicleInfo(
            VehicleManager instance,
            ushort cargoStation1, ushort cargoStation2,
            ItemClass.Service service, ItemClass.SubService subService, ItemClass.Level level)
        {
            var infoFrom = BuildingManager.instance.m_buildings.m_buffer[cargoStation1].Info;

            if (infoFrom?.m_class?.name == ItemClasses.cargoFerryFacility.name) //to support Cargo Ferries
            {
                level = ItemClass.Level.Level5;
            }

            var vehicleInfo = instance.GetRandomVehicleInfo(
                ref Singleton <SimulationManager> .instance.m_randomizer, service, subService, level);

            if (vehicleInfo == null && infoFrom?.m_class?.name == ItemClasses.cargoFerryFacility.name)
            {
                UnityEngine.Debug.LogWarning("Barges: no barges found!");
            }
            return(vehicleInfo);
        }
        public static VehicleInfo GetVehicleInfo(ref Randomizer randomizer, ItemClass m_class, ushort lineID, string prefabName)
        {
            PrefabData prefabData = Array.Find <PrefabData>(VehiclePrefabs.instance.GetPrefabs(m_class.m_subService), (Predicate <PrefabData>)(item => item.ObjectName == prefabName));

            if (prefabData != null)
            {
                return(PrefabCollection <VehicleInfo> .GetPrefab((uint)prefabData.PrefabDataIndex));
            }
            Utils.LogWarning((object)("Unknown prefab: " + prefabName));
            VehicleManager instance = Singleton <VehicleManager> .instance;

            instance.RefreshTransferVehicles();
            // ISSUE: explicit reference operation
            // ISSUE: variable of a reference type
            Randomizer& r          = @randomizer;
            int         service    = (int)m_class.m_service;
            int         subService = (int)m_class.m_subService;
            int         level      = (int)m_class.m_level;

            return(instance.GetRandomVehicleInfo(r, (ItemClass.Service)service, (ItemClass.SubService)subService, (ItemClass.Level)level));
        }
Пример #4
0
        /// <summary>
        /// Creates the service vehicle.
        /// </summary>
        /// <param name="serviceBuildingId">The service building identifier.</param>
        /// <param name="material">The material.</param>
        /// <param name="targetBuildingId">The target building identifier.</param>
        /// <param name="targetCitizenId">The target citizen identifier.</param>
        /// <param name="vehicleId">The vehicle identifier.</param>
        /// <returns>
        /// The vehicle information.
        /// </returns>
        /// <exception cref="System.NotImplementedException">Target citizen not implemented yet.</exception>
        /// <exception cref="System.InvalidOperationException">Hospital assigments reuires target citizen.</exception>
        /// <exception cref="System.ArgumentException">Unhandled material.</exception>
        /// <exception cref="ArgumentException">Unhandled material.</exception>
        public static VehicleInfo CreateServiceVehicle(ushort serviceBuildingId, TransferManager.TransferReason material, ushort targetBuildingId, uint targetCitizenId, out ushort vehicleId)
        {
            if (targetCitizenId != 0)
            {
                throw new NotImplementedException("Target citizen not implemented yet");
            }

            vehicleId = 0;

            VehicleManager manager = Singleton <VehicleManager> .instance;

            ColossalFramework.Math.Randomizer randomizer = Singleton <SimulationManager> .instance.m_randomizer;

            Building building = BuildingHelper.GetBuilding(serviceBuildingId);

            if (building.Info.m_buildingAI is HospitalAI && targetCitizenId == 0)
            {
                throw new InvalidOperationException("Hospital assigments reuires target citizen");
            }

            VehicleInfo info = manager.GetRandomVehicleInfo(ref randomizer, building.Info.m_class.m_service, building.Info.m_class.m_subService, building.Info.m_class.m_level);

            if (info == null)
            {
                Log.Debug(typeof(VehicleKeeper), "CreateVehicle", "GetRandomVehicleInfo", "no vehicle");
                return(null);
            }

            bool transferToSource;
            bool transferToTarget;

            switch (material)
            {
            case TransferManager.TransferReason.Dead:
                transferToSource = true;
                transferToTarget = false;
                break;

            case TransferManager.TransferReason.DeadMove:
                transferToSource = false;
                transferToTarget = true;
                break;

            case TransferManager.TransferReason.Garbage:
                transferToSource = true;
                transferToTarget = false;
                break;

            case TransferManager.TransferReason.GarbageMove:
                transferToSource = false;
                transferToTarget = true;
                break;

            default:
                throw new ArgumentException("Unhandled material: " + material.ToString());
            }

            if (!manager.CreateVehicle(out vehicleId, ref randomizer, info, building.m_position, material, transferToSource, transferToTarget))
            {
                Log.Debug(typeof(VehicleKeeper), "CreateVehicle", "CreateVehicle", "not created");
                return(null);
            }

            info.m_vehicleAI.SetSource(vehicleId, ref manager.m_vehicles.m_buffer[vehicleId], serviceBuildingId);

            if (targetBuildingId != 0 && !AssignTarget(vehicleId, ref manager.m_vehicles.m_buffer[vehicleId], material, targetBuildingId, 0))
            {
                Log.Debug(typeof(VehicleKeeper), "CreateVehicle", "SetTarget", "target not set");
                return(null);
            }

            return(info);
        }