public void TestCreateVehicleWithCorrectData()
        {
            //arrange

            //set expected result variable

            //act
            //execute method test, set to variable to test
            testVehicleId = _vehicleManager.CreateVehicle(testVehicle);

            //assert
            //compare result to expected result
            Assert.IsTrue(testVehicleId > 0);
        }
        public void TestRetrieveRepairListByVehicleId()
        {
            //arrange
            //create new object
            testVehicle               = new Vehicle();
            testVehicle.Active        = true;
            testVehicle.CheckedOut    = false;
            testVehicle.Color         = "White";
            testVehicle.Make          = "Test Make";
            testVehicle.Model         = "Test Model";
            testVehicle.Mileage       = 123456;
            testVehicle.VehicleTypeID = "Truck";
            testVehicle.VIN           = "123TEST456";
            testVehicle.Year          = "2000";
            //set expected result variable
            List <Repair> repairListbyVehicleId;

            //act
            //execute method test, set to variable to test
            testVehicleId         = _vehicleManager.CreateVehicle(testVehicle);
            repairListbyVehicleId = _repairManager.RetreiveAllRepairsForVehicle(testVehicleId);

            //assert
            //compare result to expected result
            Assert.IsTrue(repairListbyVehicleId != null);
        }
示例#3
0
 /// <summary>
 /// Mason Allen
 /// Created: 2017/03/01
 /// Saves a new _vehicle record to the db based on information entered into text fields
 /// </summary>
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     if (btnSave.Content as String == "Save")
     {
         try
         {
             bool active = (radYes.IsChecked == true);
             _myVehicleManager.CreateVehicle(new Vehicle
             {
                 VIN           = txtVIN.Text,
                 Make          = txtMake.Text,
                 Model         = txtModel.Text,
                 Mileage       = Convert.ToInt32(txtMileage.Text),
                 Year          = txtYear.Text,
                 Color         = txtColor.Text,
                 Active        = active,
                 VehicleTypeID = ((VehicleType)cboType.SelectedItem).VehicleTypeID.ToString()
             });
             MessageBox.Show("Vehicle saved successfully");
             this.Close();
         }
         catch (Exception)
         {
             MessageBox.Show("There was a problem saving this vehicle");
         }
     }
 }
示例#4
0
        /// <summary>
        /// Создает транспорт игрока
        /// </summary>
        private VehInst CreateMemberCar(Vehicle vehicleInfo, int index)
        {
            var startPosition = CarRaceData.StartPositions[index];
            var car           = VehicleManager.CreateVehicle(vehicleInfo, startPosition.Item1, startPosition.Item2, Dimension.CAR_RACE);

            car.engineStatus = true;
            _memberVehicles.Add(car);
            return(car);
        }
示例#5
0
        /// <summary>
        /// Создает транспорт игрока
        /// </summary>
        private VehInst CreateMemberMoto(Vehicle vehicleInfo, int index)
        {
            var startPosition = MotoRaceData.StartPositions[index];
            var moto          = VehicleManager.CreateVehicle(vehicleInfo, startPosition.Item1, startPosition.Item2, Dimension.MOTO_RACE);

            moto.engineStatus = true;
            _memberVehicles.Add(moto);
            return(moto);
        }
示例#6
0
        /// <summary>
        /// Создает транспорт игрока
        /// </summary>
        private VehInst CreateMemberCar(int index)
        {
            var vehicleInfo = new Vehicle {
                Hash   = (int)VehicleHash.Brawler,
                Fuel   = 70,
                Tuning = new VehicleTuning {
                    PrimaryColor = 160, SecondColor = 0
                }
            };
            var startPosition = RallyRaceData.StartPositions[index];
            var car           = VehicleManager.CreateVehicle(vehicleInfo, startPosition.Item1, startPosition.Item2, Dimension.RALLY);

            car.engineStatus = true;
            _memberVehicles.Add(car);
            return(car);
        }
        /// <summary>
        /// Создает транспорт игрока
        /// </summary>
        private VehInst CreateMemberMoto(int index)
        {
            var vehicleInfo = new Vehicle {
                Hash   = (int)VehicleHash.Sanchez,
                Fuel   = 50,
                Tuning = new VehicleTuning {
                    PrimaryColor = 0, SecondColor = 0
                }
            };
            var startPosition = MountainRaceData.StartPositions[index];
            var moto          = VehicleManager.CreateVehicle(vehicleInfo, startPosition.Item1, startPosition.Item2, Dimension.MOUNT_RACE);

            moto.engineStatus = true;
            _memberVehicles.Add(moto);
            return(moto);
        }
示例#8
0
        public void OnResourceStart()
        {
            //Creating the vehicles.
            foreach (var car in _testVehicles)
            {
                car[2] = VehicleManager.CreateVehicle(VehicleHash.Asea, car[0], car[1], "DMV", 0,
                                                      vehicle_manager.GameVehicle.VehTypePerm, 89, 89);

                VehicleManager.spawn_vehicle(car[2]);
            }

            ObjectRemoval.RegisterObject(new Vector3(266.102691650391, -348.641571044922, 43.7301368713379), 242636620);
            ObjectRemoval.RegisterObject(new Vector3(285.719482421875, -356.067474365234, 44.1401863098145), 406416082);

            NAPI.Util.ConsoleOutput("Spawned DMV Vehicles.");
        }
        public static ushort StartTransfer(ushort buildingID, ref Building data, TransferManager.TransferReason reason, TransferManager.TransferOffer offer, string prefabName)
        {
            SimulationManager instance1  = Singleton <SimulationManager> .instance;
            VehicleManager    instance2  = Singleton <VehicleManager> .instance;
            ushort            vehicle    = 0;
            DepotAI           buildingAi = Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)buildingID].Info.m_buildingAI as DepotAI;

            if (reason == buildingAi.m_transportInfo.m_vehicleReason)
            {
                VehicleInfo vehicleInfo = VehicleManagerMod.GetVehicleInfo(ref instance1.m_randomizer, buildingAi.m_info.m_class, offer.TransportLine, prefabName);
                if ((Object)vehicleInfo != (Object)null)
                {
                    Vector3 position;
                    Vector3 target;
                    buildingAi.CalculateSpawnPosition(buildingID, ref data, ref instance1.m_randomizer, vehicleInfo, out position, out target);
                    if (instance2.CreateVehicle(out vehicle, ref instance1.m_randomizer, vehicleInfo, position, reason, false, true))
                    {
                        vehicleInfo.m_vehicleAI.SetSource(vehicle, ref instance2.m_vehicles.m_buffer[(int)vehicle], buildingID);
                        vehicleInfo.m_vehicleAI.StartTransfer(vehicle, ref instance2.m_vehicles.m_buffer[(int)vehicle], reason, offer);
                    }
                }
            }
            return(vehicle);
        }
示例#10
0
        public void ChoppDealerSelectCar(Client sender, params object[] arguments)
        {
            Character character = sender.GetCharacter();

            string[] selectedCar = null;
            switch ((int)arguments[0])
            {
            case 0:
                selectedCar = _helicopters[(int)arguments[1]];
                break;
            }

            if (selectedCar == null)
            {
                return;
            }

            if (Money.GetCharacterMoney(character) >= Convert.ToInt32(selectedCar[2]))
            {
                //Remove price.
                InventoryManager.DeleteInventoryItem(character, typeof(Money), Convert.ToInt32(selectedCar[2]));

                //Spawn positions.
                Vector3[] spawnPoss =
                {
                    new Vector3(-1112.07,  -2883.274, 13.94603),
                    new Vector3(-1145.618, -2864.848, 13.94607),
                    new Vector3(-1177.989, -2845.755, 13.94576),
                };
                var randomPos = new Random().Next(1, spawnPoss.Length) - 1;

                //Create the vehicle.
                var theVehicle = VehicleManager.CreateVehicle(
                    (VehicleHash)Convert.ToInt32(selectedCar[1]),
                    spawnPoss[randomPos],
                    new Vector3(0.1917319, 0.1198539, -177.1394),
                    "Unregistered",
                    character.Id,
                    vehicle_manager.GameVehicle.VehTypePerm
                    );
                //theVehicle.IsVip = true;
                theVehicle.OwnerName = character.CharacterName;
                //Add it to the players cars.
                theVehicle.Insert();

                //Spawn it.
                if (VehicleManager.spawn_vehicle(theVehicle) != 1)
                {
                    NAPI.Chat.SendChatMessageToPlayer(sender, "An error occured while spawning your vehicle.");
                }

                //Notify.
                NAPI.Chat.SendChatMessageToPlayer(sender,
                                                  $"You have sucessfully bought the ~g~{selectedCar[0]}~w~ for ${selectedCar[2]}.");
                NAPI.Chat.SendChatMessageToPlayer(sender, "Use /myvehicles to manage it.");

                //Log it.
                LogManager.Log(LogManager.LogTypes.Stats, $"[Chopper Dealership] {sender.GetCharacter().CharacterName}[{sender.GetAccount().AccountName}] has bought a(n) {NAPI.Vehicle.GetVehicleDisplayName(theVehicle.VehModel)} for ${selectedCar[2]}.");

                //Exit.
                NAPI.ClientEvent.TriggerClientEvent(sender, "chopperdealership_exitdealermenu");
            }
            else
            {
                NAPI.Chat.SendChatMessageToPlayer(sender,
                                                  $"You don't have enough money to buy the ~g~{selectedCar[0]}~w~.");
            }
        }
示例#11
0
        public void VehicleDealerSelectCar(Player sender, params object[] arguments)
        {
            Character character = sender.GetCharacter();

            string[] selectedCar = null;
            switch ((int)arguments[0])
            {
            case 0:
                selectedCar = _motorsycles[(int)arguments[1]];
                break;

            case 1:
                selectedCar = _copues[(int)arguments[1]];
                break;

            case 2:
                selectedCar = _trucksnvans[(int)arguments[1]];
                break;

            case 3:
                selectedCar = _offroad[(int)arguments[1]];
                break;

            case 4:
                selectedCar = _musclecars[(int)arguments[1]];
                break;

            case 5:
                selectedCar = _suv[(int)arguments[1]];
                break;

            case 6:
                selectedCar = _supercars[(int)arguments[1]];
                break;

            case 7:
                selectedCar = _cycles[(int)arguments[1]];
                break;

            case 8:
                selectedCar = _sedans[(int)arguments[1]];
                break;

            case 9:
                selectedCar = _sportsCars[(int)arguments[1]];
                break;

            case 10:
                selectedCar = _compactCars[(int)arguments[1]];
                break;
            }

            if (selectedCar == null)
            {
                return;
            }

            if (Money.GetCharacterMoney(character) >= Convert.ToInt32(selectedCar[2]))
            {
                //Remove price.
                InventoryManager.DeleteInventoryItem(character, typeof(Money), Convert.ToInt32(selectedCar[2]));

                //Spawn positions.
                Vector3[] spawnPoss =
                {
                    new Vector3(-42.44885, -1115.865, 25.86397),
                    new Vector3(-45.04674, -1116.336, 25.86318),
                    new Vector3(-47.77579, -1116.404, 25.86377),
                    new Vector3(-50.53339, -1116.758, 25.86334),
                    new Vector3(-53.56507, -1116.645, 25.86412),
                    new Vector3(-56.42249, -1116.668,  25.8641),
                    new Vector3(-59.06798, -1117.206, 25.86339),
                    new Vector3(-61.86055, -1117.122, 25.8629)
                };
                var randomPos = new Random().Next(1, spawnPoss.Length) - 1;
                //Create the vehicle.
                var theVehicle = VehicleManager.CreateVehicle(
                    (VehicleHash)Convert.ToInt32(selectedCar[1]),
                    spawnPoss[randomPos],
                    new Vector3(0.1917319, 0.1198539, -177.1394),
                    "...",
                    character.Id,
                    vehicle_manager.GameVehicle.VehTypePerm
                    );
                theVehicle.OwnerName = character.CharacterName;

                //Add it to the players cars.
                theVehicle.Insert();

                //Spawn it.
                if (VehicleManager.spawn_vehicle(theVehicle) != 1)
                {
                    NAPI.Chat.SendChatMessageToPlayer(sender, "An error occured while spawning your vehicle.");
                }

                //Notify.
                NAPI.Chat.SendChatMessageToPlayer(sender,
                                                  $"You have sucessfully bought the ~g~{selectedCar[0]}~w~ for ${selectedCar[2]}.");
                NAPI.Chat.SendChatMessageToPlayer(sender, "Use /myvehicles to manage it.");

                //Log it.
                LogManager.Log(LogManager.LogTypes.Stats, $"[Vehicle Dealership] {sender.GetCharacter().CharacterName}[{sender.GetAccount().AccountName}] has bought a(n) {NAPI.Vehicle.GetVehicleDisplayName(theVehicle.VehModel)} for ${selectedCar[2]}.");

                //Exit.
                NAPI.ClientEvent.TriggerClientEvent(sender, "dealership_exitdealermenu");
            }
            else
            {
                NAPI.Chat.SendChatMessageToPlayer(sender,
                                                  $"You don't have enough money to buy the ~g~{selectedCar[0]}~w~.");
            }
        }
示例#12
0
        public override void SimulationStep(ushort eventID, ref EventData data)
        {
            //begin mod
            var crawlerVehicle = Configuration.Get(eventID).Crawler;
            var rocketVehicle  = Configuration.Get(eventID).Rocket;
            //end mod
            VehicleManager  instance1 = Singleton <VehicleManager> .instance;
            BuildingManager instance2 = Singleton <BuildingManager> .instance;
            EventManager    instance3 = Singleton <EventManager> .instance;
            ushort          vehicleID1;
            ushort          vehicleID2;

            this.FindVehicles(eventID, ref data, out vehicleID1, out vehicleID2);
            bool flag1 = false;

            if ((data.m_flags & (EventData.Flags.Active | EventData.Flags.Expired | EventData.Flags.Completed | EventData.Flags.Disorganizing | EventData.Flags.Cancelled)) == EventData.Flags.None)
            {
                if ((data.m_flags & EventData.Flags.Ready) == EventData.Flags.None && this.m_resourceConsumption != 0)
                {
                    int num1 = (int)data.m_popularityDelta * 10;
                    int num2 = Mathf.Clamp(num1 / this.m_resourceConsumption, 0, 256);
                    data.m_startFrame  += (uint)(256 - num2);
                    data.m_expireFrame += (uint)(256 - num2);
                    int num3 = num1 - num2 * this.m_resourceConsumption;
                    data.m_popularityDelta = (short)Mathf.Clamp(num3 / 10, 0, (int)short.MaxValue);
                    int  num4 = 0;
                    uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
                    if (data.m_startFrame > currentFrameIndex)
                    {
                        num4 = ((int)data.m_startFrame - (int)currentFrameIndex) * this.m_resourceConsumption;
                    }
                    if ((int)data.m_building != 0 && num4 > num3)
                    {
                        int    num5       = 100000;
                        ushort vehicleID3 = instance2.m_buildings.m_buffer[(int)data.m_building].m_guestVehicles;
                        int    num6       = 0;
                        while ((int)vehicleID3 != 0)
                        {
                            switch ((TransferManager.TransferReason)instance1.m_vehicles.m_buffer[(int)vehicleID3].m_transferType)
                            {
                            case TransferManager.TransferReason.Coal:
                            case TransferManager.TransferReason.Petrol:
                                int size;
                                int max;
                                instance1.m_vehicles.m_buffer[(int)vehicleID3].Info.m_vehicleAI.GetSize(vehicleID3, ref instance1.m_vehicles.m_buffer[(int)vehicleID3], out size, out max);
                                num3 += Mathf.Min(size, max);
                                break;
                            }
                            vehicleID3 = instance1.m_vehicles.m_buffer[(int)vehicleID3].m_nextGuestVehicle;
                            if (++num6 > 16384)
                            {
                                CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);

                                break;
                            }
                        }
                        if (num3 <= num5 - 8000)
                        {
                            Singleton <TransferManager> .instance.AddIncomingOffer((data.m_flags & EventData.Flags.Preparing) == EventData.Flags.None?TransferManager.TransferReason.Coal : TransferManager.TransferReason.Petrol, new TransferManager.TransferOffer()
                            {
                                Priority = Mathf.Max(1, (num5 - num3) * 8 / num5),
                                Building = data.m_building,
                                Position = instance2.m_buildings.m_buffer[(int)data.m_building].m_position,
                                Amount   = 1,
                                Active   = false
                            });
                        }
                        if (num3 < 16000)
                        {
                            flag1 = true;
                        }
                    }
                }
                if ((data.m_flags & (EventData.Flags.Preparing | EventData.Flags.Ready)) != EventData.Flags.None && (int)data.m_building != 0)
                {
                    if ((int)vehicleID1 == 0 && crawlerVehicle != null)
                    {
                        Vector3 position = instance2.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_rocketSpawnPosition);
                        if (instance1.CreateVehicle(out vehicleID1, ref Singleton <SimulationManager> .instance.m_randomizer, crawlerVehicle, position, TransferManager.TransferReason.None, false, false))
                        {
                            crawlerVehicle.m_vehicleAI.SetSource(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1], data.m_building);
                            crawlerVehicle.m_vehicleAI.SetTarget(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1], data.m_building);
                        }
                    }
                    if ((int)vehicleID1 != 0 && (int)vehicleID2 == 0 && rocketVehicle != null)
                    {
                        Vector3 position = instance2.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_rocketSpawnPosition);
                        if (instance1.CreateVehicle(out vehicleID2, ref Singleton <SimulationManager> .instance.m_randomizer, rocketVehicle, position, TransferManager.TransferReason.None, false, false))
                        {
                            rocketVehicle.m_vehicleAI.SetSource(vehicleID2, ref instance1.m_vehicles.m_buffer[(int)vehicleID2], data.m_building);
                            rocketVehicle.m_vehicleAI.SetTarget(vehicleID2, ref instance1.m_vehicles.m_buffer[(int)vehicleID2], data.m_building);
                            ushort lastVehicle = instance1.m_vehicles.m_buffer[(int)vehicleID1].GetLastVehicle(vehicleID1);
                            if ((int)lastVehicle != 0)
                            {
                                instance1.m_vehicles.m_buffer[(int)vehicleID2].m_leadingVehicle   = lastVehicle;
                                instance1.m_vehicles.m_buffer[(int)lastVehicle].m_trailingVehicle = vehicleID2;
                            }
                        }
                    }
                }
            }
            if ((int)data.m_building != 0)
            {
                ushort num = instance2.m_buildings.m_buffer[(int)data.m_building].m_eventIndex;
                if ((int)num == (int)eventID)
                {
                    Notification.Problem problems = instance2.m_buildings.m_buffer[(int)data.m_building].m_problems;
                    Notification.Problem problem  = Notification.RemoveProblems(problems, Notification.Problem.NoResources);
                    if (flag1)
                    {
                        instance2.m_buildings.m_buffer[(int)data.m_building].m_incomingProblemTimer = (byte)Mathf.Min((int)byte.MaxValue, (int)instance2.m_buildings.m_buffer[(int)data.m_building].m_incomingProblemTimer + 1);
                        if ((int)instance2.m_buildings.m_buffer[(int)data.m_building].m_incomingProblemTimer >= 4)
                        {
                            problem = Notification.AddProblems(problem, Notification.Problem.NoResources);
                        }
                    }
                    else
                    {
                        instance2.m_buildings.m_buffer[(int)data.m_building].m_incomingProblemTimer = (byte)0;
                    }
                    if (problem != problems)
                    {
                        instance2.m_buildings.m_buffer[(int)data.m_building].m_problems = problem;
                        Singleton <BuildingManager> .instance.UpdateNotifications(data.m_building, problems, problem);
                    }
                    GuideController properties = Singleton <GuideManager> .instance.m_properties;
                    if (properties != null)
                    {
                        Singleton <BuildingManager> .instance.m_rocketLaunchSite.Activate(properties.m_rocketLaunchSite, data.m_building);
                    }
                }
                if ((int)num != 0 && (instance3.m_events.m_buffer[(int)num].m_flags & (EventData.Flags.Preparing | EventData.Flags.Active | EventData.Flags.Completed | EventData.Flags.Cancelled | EventData.Flags.Ready)) == EventData.Flags.None)
                {
                    num = instance3.m_events.m_buffer[(int)num].m_nextBuildingEvent;
                }
                bool flag2 = false;
                if ((int)vehicleID1 != 0 && crawlerVehicle != null)
                {
                    Vector3 position          = instance2.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_doorPosition);
                    Vector3 lastFramePosition = instance1.m_vehicles.m_buffer[(int)vehicleID1].GetLastFramePosition();
                    Vector3 targetPos0        = (Vector3)instance1.m_vehicles.m_buffer[(int)vehicleID1].m_targetPos0;
                    Vector3 b = lastFramePosition + Vector3.ClampMagnitude(targetPos0 - lastFramePosition, crawlerVehicle.m_maxSpeed * 16f);
                    flag2 = (double)Vector3.Distance(position, b) < 40.0;
                }
                if (flag2)
                {
                    if ((data.m_flags & EventData.Flags.Loading) == EventData.Flags.None)
                    {
                        data.m_flags |= EventData.Flags.Loading;
                        if (this.m_doorOpenEffect != null && (int)num == (int)eventID)
                        {
                            InstanceID instance4 = new InstanceID();
                            instance4.Event = eventID;
                            EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_doorPosition), Vector3.up, 10f);
                            Singleton <EffectManager> .instance.DispatchEffect(this.m_doorOpenEffect, instance4, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <AudioManager> .instance.DefaultGroup);
                        }
                    }
                }
                else if ((data.m_flags & EventData.Flags.Loading) != EventData.Flags.None)
                {
                    data.m_flags &= ~EventData.Flags.Loading;
                    if (this.m_doorCloseEffect != null && (int)num == (int)eventID)
                    {
                        InstanceID instance4 = new InstanceID();
                        instance4.Event = eventID;
                        EffectInfo.SpawnArea spawnArea = new EffectInfo.SpawnArea(Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)data.m_building].CalculatePosition(this.m_doorPosition), Vector3.up, 10f);
                        Singleton <EffectManager> .instance.DispatchEffect(this.m_doorCloseEffect, instance4, spawnArea, Vector3.zero, 0.0f, 1f, Singleton <AudioManager> .instance.DefaultGroup);
                    }
                }
            }
            base.SimulationStep(eventID, ref data);
        }
示例#13
0
        protected override bool SpawnVehicle(ushort instanceID, ref CitizenInstance citizenData, PathUnit.Position pathPos)
        {
            VehicleManager instance = Singleton <VehicleManager> .instance;
            float          num      = 20f;
            int            num2     = Mathf.Max((int)((citizenData.m_targetPos.x - num) / 32f + 270f), 0);
            int            num3     = Mathf.Max((int)((citizenData.m_targetPos.z - num) / 32f + 270f), 0);
            int            num4     = Mathf.Min((int)((citizenData.m_targetPos.x + num) / 32f + 270f), 539);
            int            num5     = Mathf.Min((int)((citizenData.m_targetPos.z + num) / 32f + 270f), 539);

            for (int i = num3; i <= num5; i++)
            {
                for (int j = num2; j <= num4; j++)
                {
                    ushort num6 = instance.m_vehicleGrid [i * 540 + j];
                    int    num7 = 0;
                    while (num6 != 0)
                    {
                        if (this.TryJoinVehicle(instanceID, ref citizenData, num6, ref instance.m_vehicles.m_buffer [(int)num6]))
                        {
                            citizenData.m_flags      |= CitizenInstance.Flags.EnteringVehicle;
                            citizenData.m_flags      &= ~CitizenInstance.Flags.TryingSpawnVehicle;
                            citizenData.m_flags      &= ~CitizenInstance.Flags.BoredOfWaiting;
                            citizenData.m_waitCounter = 0;
                            return(true);
                        }
                        num6 = instance.m_vehicles.m_buffer [(int)num6].m_nextGridVehicle;
                        if (++num7 > 65536)
                        {
                            CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                            break;
                        }
                    }
                }
            }
            NetManager     instance2 = Singleton <NetManager> .instance;
            CitizenManager instance3 = Singleton <CitizenManager> .instance;
            Vector3        vector    = Vector3.zero;
            Quaternion     rotation  = Quaternion.identity;
            ushort         num8      = instance3.m_citizens.m_buffer [(int)((UIntPtr)citizenData.m_citizen)].m_parkedVehicle;

            if (num8 != 0)
            {
                vector   = instance.m_parkedVehicles.m_buffer [(int)num8].m_position;
                rotation = instance.m_parkedVehicles.m_buffer [(int)num8].m_rotation;
            }
            VehicleInfo vehicleInfo = this.GetVehicleInfo(instanceID, ref citizenData, false);

            if (vehicleInfo == null || vehicleInfo.m_vehicleType == VehicleInfo.VehicleType.Bicycle)
            {
                instance3.m_citizens.m_buffer [(int)((UIntPtr)citizenData.m_citizen)].SetParkedVehicle(citizenData.m_citizen, 0);
                if ((citizenData.m_flags & CitizenInstance.Flags.TryingSpawnVehicle) == CitizenInstance.Flags.None)
                {
                    citizenData.m_flags      |= CitizenInstance.Flags.TryingSpawnVehicle;
                    citizenData.m_flags      &= ~CitizenInstance.Flags.BoredOfWaiting;
                    citizenData.m_waitCounter = 0;
                }
                return(true);
            }
            if (vehicleInfo.m_class.m_subService == ItemClass.SubService.PublicTransportTaxi)
            {
                instance3.m_citizens.m_buffer [(int)((UIntPtr)citizenData.m_citizen)].SetParkedVehicle(citizenData.m_citizen, 0);
                if ((citizenData.m_flags & CitizenInstance.Flags.WaitingTaxi) == CitizenInstance.Flags.None)
                {
                    citizenData.m_flags      |= CitizenInstance.Flags.WaitingTaxi;
                    citizenData.m_flags      &= ~CitizenInstance.Flags.BoredOfWaiting;
                    citizenData.m_waitCounter = 0;
                }
                return(true);
            }
            uint    laneID  = PathManager.GetLaneID(pathPos);
            Vector3 vector2 = citizenData.m_targetPos;

            if (num8 != 0 && Vector3.SqrMagnitude(vector - vector2) < 1024f)
            {
                vector2 = vector;
            }
            else
            {
                num8 = 0;
            }
            Vector3 a;
            float   num9;

            instance2.m_lanes.m_buffer [(int)((UIntPtr)laneID)].GetClosestPosition(vector2, out a, out num9);
            byte lastPathOffset = (byte)Mathf.Clamp(Mathf.RoundToInt(num9 * 255f), 0, 255);

            a = vector2 + Vector3.ClampMagnitude(a - vector2, 5f);
            ushort num10;

            if (instance.CreateVehicle(out num10, ref Singleton <SimulationManager> .instance.m_randomizer, vehicleInfo, vector2, TransferManager.TransferReason.None, false, false))
            {
                Vehicle.Frame frame = instance.m_vehicles.m_buffer [(int)num10].m_frame0;
                if (num8 != 0)
                {
                    frame.m_rotation = rotation;
                }
                else
                {
                    Vector3 forward = a - citizenData.GetLastFrameData().m_position;
                    if (forward.sqrMagnitude > 0.01f)
                    {
                        frame.m_rotation = Quaternion.LookRotation(forward);
                    }
                }
                instance.m_vehicles.m_buffer [(int)num10].m_frame0 = frame;
                instance.m_vehicles.m_buffer [(int)num10].m_frame1 = frame;
                instance.m_vehicles.m_buffer [(int)num10].m_frame2 = frame;
                instance.m_vehicles.m_buffer [(int)num10].m_frame3 = frame;
                vehicleInfo.m_vehicleAI.FrameDataUpdated(num10, ref instance.m_vehicles.m_buffer [(int)num10], ref frame);
                instance.m_vehicles.m_buffer [(int)num10].m_targetPos0 = new Vector4(a.x, a.y, a.z, 2f);
                Vehicle[] expr_4E5_cp_0 = instance.m_vehicles.m_buffer;
                ushort    expr_4E5_cp_1 = num10;
                expr_4E5_cp_0 [(int)expr_4E5_cp_1].m_flags       = (expr_4E5_cp_0 [(int)expr_4E5_cp_1].m_flags | Vehicle.Flags.Stopped);
                instance.m_vehicles.m_buffer [(int)num10].m_path = citizenData.m_path;
                instance.m_vehicles.m_buffer [(int)num10].m_pathPositionIndex = citizenData.m_pathPositionIndex;
                instance.m_vehicles.m_buffer [(int)num10].m_lastPathOffset    = lastPathOffset;
                instance.m_vehicles.m_buffer [(int)num10].m_transferSize      = (ushort)(citizenData.m_citizen & 65535u);
                vehicleInfo.m_vehicleAI.TrySpawn(num10, ref instance.m_vehicles.m_buffer [(int)num10]);
                if (num8 != 0)
                {
                    InstanceID empty = InstanceID.Empty;
                    empty.ParkedVehicle = num8;
                    InstanceID empty2 = InstanceID.Empty;
                    empty2.Vehicle = num10;
                    Singleton <InstanceManager> .instance.ChangeInstance(empty, empty2);
                }
                citizenData.m_path = 0u;
                instance3.m_citizens.m_buffer [(int)((UIntPtr)citizenData.m_citizen)].SetParkedVehicle(citizenData.m_citizen, 0);
                instance3.m_citizens.m_buffer [(int)((UIntPtr)citizenData.m_citizen)].SetVehicle(citizenData.m_citizen, num10, 0u);
                citizenData.m_flags      |= CitizenInstance.Flags.EnteringVehicle;
                citizenData.m_flags      &= ~CitizenInstance.Flags.TryingSpawnVehicle;
                citizenData.m_flags      &= ~CitizenInstance.Flags.BoredOfWaiting;
                citizenData.m_waitCounter = 0;
                return(true);
            }
            instance3.m_citizens.m_buffer [(int)((UIntPtr)citizenData.m_citizen)].SetParkedVehicle(citizenData.m_citizen, 0);
            if ((citizenData.m_flags & CitizenInstance.Flags.TryingSpawnVehicle) == CitizenInstance.Flags.None)
            {
                citizenData.m_flags      |= CitizenInstance.Flags.TryingSpawnVehicle;
                citizenData.m_flags      &= ~CitizenInstance.Flags.BoredOfWaiting;
                citizenData.m_waitCounter = 0;
            }
            return(true);
        }
示例#14
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);
        }
示例#15
0
        private void API_onClientEventTrigger(Client sender, string eventName, params object[] arguments)
        {
            if (eventName == "vipdealer_selectcar")
            {
                Character character = sender.GetCharacter();

                string[] selectedCar = null;

                #region Get Car Info.

                switch ((int)arguments[0])
                {
                case 0:
                    selectedCar = _motorsycles[(int)arguments[1]];
                    break;

                case 1:
                    selectedCar = _copues[(int)arguments[1]];
                    break;

                case 2:
                    selectedCar = _trucksnvans[(int)arguments[1]];
                    break;

                case 3:
                    selectedCar = _offroad[(int)arguments[1]];
                    break;

                case 4:
                    selectedCar = _musclecars[(int)arguments[1]];
                    break;

                case 5:
                    selectedCar = _suv[(int)arguments[1]];
                    break;

                case 6:
                    selectedCar = _supercars[(int)arguments[1]];
                    break;
                }

                #endregion

                if (selectedCar == null)
                {
                    return;
                }

                if (Money.GetCharacterMoney(character) >= Convert.ToInt32(selectedCar[2]))
                {
                    //Remove price.
                    InventoryManager.DeleteInventoryItem(character, typeof(Money), Convert.ToInt32(selectedCar[2]));

                    //Spawn positions.
                    Vector3[] spawnPoss =
                    {
                        new Vector3(-51.88548, -1694.663, 29.09777),
                        new Vector3(-52.7189,  -1689.862, 29.09228),
                        new Vector3(-58.41274, -1683.702, 29.09858),
                        new Vector3(-55.86712, -1687.208, 29.09822),
                    };
                    var randomPos = new Random().Next(1, spawnPoss.Length) - 1;

                    //Create the vehicle.
                    var theVehicle = VehicleManager.CreateVehicle(
                        (VehicleHash)Convert.ToInt32(selectedCar[1]),
                        spawnPoss[randomPos],
                        new Vector3(0.1917319, 0.1198539, -177.1394),
                        " ",
                        character.Id,
                        vehicle_manager.Vehicle.VehTypePerm
                        );
                    theVehicle.OwnerName = character.CharacterName;
                    theVehicle.IsVip     = true;
                    //Add it to the players cars.
                    theVehicle.Insert();

                    //Spawn it.
                    if (VehicleManager.spawn_vehicle(theVehicle) != 1)
                    {
                        API.SendChatMessageToPlayer(sender, "An error occured while spawning your vehicle.");
                    }

                    //Notify.
                    API.SendChatMessageToPlayer(sender,
                                                $"You have sucessfully bought the ~g~{selectedCar[0]}~w~ for ${selectedCar[2]}.");
                    API.SendChatMessageToPlayer(sender, "Use /myvehicles to manage it.");

                    //Exit.
                    API.TriggerClientEvent(sender, "vipdealership_exitdealermenu");
                }
                else
                {
                    API.SendChatMessageToPlayer(sender,
                                                $"You don't have enough money to buy the ~g~{selectedCar[0]}~w~.");
                }
            }
        }
示例#16
0
        public void BoatDealerSelectCar(Client sender, params object[] arguments)
        {
            Character character = sender.GetCharacter();

            string[] selectedCar = null;

            switch ((int)arguments[0])
            {
            case 0:
                selectedCar = _boats[(int)arguments[1]];
                break;
            }

            if (selectedCar == null)
            {
                return;
            }

            if (Money.GetCharacterMoney(character) >= Convert.ToInt32(selectedCar[2]))
            {
                //Remove price.
                InventoryManager.DeleteInventoryItem(character, typeof(Money), Convert.ToInt32(selectedCar[2]));

                //Spawn positions.
                Vector3[] spawnPoss =
                {
                    new Vector3(-1792.381,  -1235.88, -0.3676317),
                    new Vector3(-1775.264,  -1213.21,  0.5480041),
                    new Vector3(-1771.058, -1238.927, -0.6069559)
                };
                var randomPos = new Random().Next(1, spawnPoss.Length) - 1;

                //Create the vehicle.
                var theVehicle = VehicleManager.CreateVehicle(
                    (VehicleHash)Convert.ToInt32(selectedCar[1]),
                    spawnPoss[randomPos],
                    new Vector3(0.1917319, 0.1198539, -177.1394),
                    "...",
                    character.Id,
                    vehicle_manager.GameVehicle.VehTypePerm
                    );
                theVehicle.OwnerName = character.CharacterName;

                //Add it to the players cars.
                theVehicle.Insert();

                //Spawn it.
                if (VehicleManager.spawn_vehicle(theVehicle) != 1)
                {
                    NAPI.Chat.SendChatMessageToPlayer(sender, "An error occured while spawning your vehicle.");
                }

                //Notify.
                NAPI.Chat.SendChatMessageToPlayer(sender,
                                                  $"You have sucessfully bought the ~g~{selectedCar[0]}~w~ for ${selectedCar[2]}.");
                NAPI.Chat.SendChatMessageToPlayer(sender, "Use /myvehicles to manage it.");

                //Exit.
                NAPI.ClientEvent.TriggerClientEvent(sender, "dealership_exitdealermenu");
            }
            else
            {
                NAPI.Chat.SendChatMessageToPlayer(sender,
                                                  $"You don't have enough money to buy the ~g~{selectedCar[0]}~w~.");
            }
        }
        public static void Spawn(ref Vehicle vehicleData, ushort vehicleId)
        {
            //Log._Debug($"CustomVehicle.Spawn({vehicleId}) called.");

            VehicleManager vehManager  = Singleton <VehicleManager> .instance;
            VehicleInfo    vehicleInfo = vehicleData.Info;

            if ((vehicleData.m_flags & Vehicle.Flags.Spawned) == (Vehicle.Flags) 0)
            {
                vehicleData.m_flags |= Vehicle.Flags.Spawned;
                vehManager.AddToGrid(vehicleId, ref vehicleData, vehicleInfo.m_isLargeVehicle);
            }
            if (vehicleData.m_leadingVehicle == 0 && vehicleData.m_trailingVehicle == 0 && vehicleInfo.m_trailers != null)
            {
                bool          hasTrailers   = vehicleInfo.m_vehicleAI.VerticalTrailers();
                ushort        curVehicleId  = vehicleId;
                bool          reversed      = (vehManager.m_vehicles.m_buffer[curVehicleId].m_flags & Vehicle.Flags.Reversed) != (Vehicle.Flags) 0;
                Vehicle.Frame lastFrameData = vehicleData.GetLastFrameData();
                float         length        = (!hasTrailers) ? (vehicleInfo.m_generatedInfo.m_size.z * 0.5f) : 0f;
                length -= (((vehicleData.m_flags & Vehicle.Flags.Inverted) == (Vehicle.Flags) 0) ? vehicleInfo.m_attachOffsetBack : vehicleInfo.m_attachOffsetFront);
                Randomizer randomizer = new Randomizer((int)vehicleId);
                for (int i = 0; i < vehicleInfo.m_trailers.Length; i++)
                {
                    if (randomizer.Int32(100u) < vehicleInfo.m_trailers[i].m_probability)
                    {
                        VehicleInfo trailerInfo = vehicleInfo.m_trailers[i].m_info;
                        bool        inverted    = randomizer.Int32(100u) < vehicleInfo.m_trailers[i].m_invertProbability;
                        length += ((!hasTrailers) ? (trailerInfo.m_generatedInfo.m_size.z * 0.5f) : trailerInfo.m_generatedInfo.m_size.y);
                        length -= ((!inverted) ? trailerInfo.m_attachOffsetFront : trailerInfo.m_attachOffsetBack);
                        Vector3 position = lastFrameData.m_position - lastFrameData.m_rotation * new Vector3(0f, (!hasTrailers) ? 0f : length, (!hasTrailers) ? length : 0f);
                        ushort  trailerVehicleId;
                        if (vehManager.CreateVehicle(out trailerVehicleId, ref Singleton <SimulationManager> .instance.m_randomizer, trailerInfo, position, (TransferManager.TransferReason)vehicleData.m_transferType, false, false))
                        {
                            vehManager.m_vehicles.m_buffer[(int)curVehicleId].m_trailingVehicle    = trailerVehicleId;
                            vehManager.m_vehicles.m_buffer[(int)trailerVehicleId].m_leadingVehicle = curVehicleId;
                            if (inverted)
                            {
                                vehManager.m_vehicles.m_buffer[trailerVehicleId].m_flags |= Vehicle.Flags.Inverted;
                            }
                            if (reversed)
                            {
                                vehManager.m_vehicles.m_buffer[trailerVehicleId].m_flags |= Vehicle.Flags.Reversed;
                            }
                            vehManager.m_vehicles.m_buffer[(int)trailerVehicleId].m_frame0.m_rotation = lastFrameData.m_rotation;
                            vehManager.m_vehicles.m_buffer[(int)trailerVehicleId].m_frame1.m_rotation = lastFrameData.m_rotation;
                            vehManager.m_vehicles.m_buffer[(int)trailerVehicleId].m_frame2.m_rotation = lastFrameData.m_rotation;
                            vehManager.m_vehicles.m_buffer[(int)trailerVehicleId].m_frame3.m_rotation = lastFrameData.m_rotation;
                            trailerInfo.m_vehicleAI.FrameDataUpdated(trailerVehicleId, ref vehManager.m_vehicles.m_buffer[(int)trailerVehicleId], ref vehManager.m_vehicles.m_buffer[(int)trailerVehicleId].m_frame0);
                            CustomVehicle.Spawn(ref vehManager.m_vehicles.m_buffer[(int)trailerVehicleId], trailerVehicleId);                             // NON-STOCK CODE
                            curVehicleId = trailerVehicleId;
                        }
                        length += ((!hasTrailers) ? (trailerInfo.m_generatedInfo.m_size.z * 0.5f) : 0f);
                        length -= ((!inverted) ? trailerInfo.m_attachOffsetBack : trailerInfo.m_attachOffsetFront);
                    }
                }
            }

            // NON-STOCK CODE START
#if BENCHMARK
            using (var bm = new Benchmark(null, "OnSpawnVehicle")) {
#endif
            VehicleStateManager.Instance.OnSpawnVehicle(vehicleId, ref vehicleData);
#if BENCHMARK
        }
#endif
            // NON-STOCK CODE END
        }
示例#18
0
        /// <summary>
        /// Makes the given citizen instance enter their parked car.
        /// </summary>
        /// <param name="instanceID">Citizen instance id</param>
        /// <param name="instanceData">Citizen instance data</param>
        /// <param name="parkedVehicleId">Parked vehicle id</param>
        /// <param name="vehicleId">Vehicle id</param>
        /// <returns>true if entering the car succeeded, false otherwise</returns>
        public static bool EnterParkedCar(ushort instanceID, ref CitizenInstance instanceData, ushort parkedVehicleId, out ushort vehicleId)
        {
#if DEBUG
            if (GlobalConfig.Instance.Debug.Switches[2])
            {
                Log._Debug($"CustomHumanAI.EnterParkedCar({instanceID}, ..., {parkedVehicleId}) called.");
            }
#endif
            VehicleManager vehManager = Singleton <VehicleManager> .instance;
            NetManager     netManager = Singleton <NetManager> .instance;
            CitizenManager citManager = Singleton <CitizenManager> .instance;

            Vector3     parkedVehPos = vehManager.m_parkedVehicles.m_buffer[parkedVehicleId].m_position;
            Quaternion  parkedVehRot = vehManager.m_parkedVehicles.m_buffer[parkedVehicleId].m_rotation;
            VehicleInfo vehicleInfo  = vehManager.m_parkedVehicles.m_buffer[parkedVehicleId].Info;

            PathUnit.Position vehLanePathPos;
            if (!CustomPathManager._instance.m_pathUnits.m_buffer[instanceData.m_path].GetPosition(0, out vehLanePathPos))
            {
#if DEBUG
                if (GlobalConfig.Instance.Debug.Switches[2])
                {
                    Log._Debug($"CustomHumanAI.EnterParkedCar: Could not get first car path position of citizen instance {instanceID}!");
                }
#endif

                vehicleId = 0;
                return(false);
            }
            uint vehLaneId = PathManager.GetLaneID(vehLanePathPos);
#if DEBUG
            if (GlobalConfig.Instance.Debug.Switches[4])
            {
                Log._Debug($"CustomHumanAI.EnterParkedCar: Determined vehicle position for citizen instance {instanceID}: seg. {vehLanePathPos.m_segment}, lane {vehLanePathPos.m_lane}, off {vehLanePathPos.m_offset} (lane id {vehLaneId})");
            }
#endif

            Vector3 vehLanePos;
            float   vehLaneOff;
            netManager.m_lanes.m_buffer[vehLaneId].GetClosestPosition(parkedVehPos, out vehLanePos, out vehLaneOff);
            byte vehLaneOffset = (byte)Mathf.Clamp(Mathf.RoundToInt(vehLaneOff * 255f), 0, 255);

            // movement vector from parked vehicle position to road position
            Vector3 forwardVector = parkedVehPos + Vector3.ClampMagnitude(vehLanePos - parkedVehPos, 5f);
            if (vehManager.CreateVehicle(out vehicleId, ref Singleton <SimulationManager> .instance.m_randomizer, vehicleInfo, parkedVehPos, TransferManager.TransferReason.None, false, false))
            {
                // update frame data
                Vehicle.Frame frame = vehManager.m_vehicles.m_buffer[(int)vehicleId].m_frame0;
                frame.m_rotation = parkedVehRot;

                vehManager.m_vehicles.m_buffer[vehicleId].m_frame0 = frame;
                vehManager.m_vehicles.m_buffer[vehicleId].m_frame1 = frame;
                vehManager.m_vehicles.m_buffer[vehicleId].m_frame2 = frame;
                vehManager.m_vehicles.m_buffer[vehicleId].m_frame3 = frame;
                vehicleInfo.m_vehicleAI.FrameDataUpdated(vehicleId, ref vehManager.m_vehicles.m_buffer[vehicleId], ref frame);

                // update vehicle target position
                vehManager.m_vehicles.m_buffer[vehicleId].m_targetPos0 = new Vector4(vehLanePos.x, vehLanePos.y, vehLanePos.z, 2f);

                // update other fields
                vehManager.m_vehicles.m_buffer[vehicleId].m_flags             = (vehManager.m_vehicles.m_buffer[vehicleId].m_flags | Vehicle.Flags.Stopped);
                vehManager.m_vehicles.m_buffer[vehicleId].m_path              = instanceData.m_path;
                vehManager.m_vehicles.m_buffer[vehicleId].m_pathPositionIndex = 0;
                vehManager.m_vehicles.m_buffer[vehicleId].m_lastPathOffset    = vehLaneOffset;
                vehManager.m_vehicles.m_buffer[vehicleId].m_transferSize      = (ushort)(instanceData.m_citizen & 65535u);

                if (!vehicleInfo.m_vehicleAI.TrySpawn(vehicleId, ref vehManager.m_vehicles.m_buffer[vehicleId]))
                {
#if DEBUG
                    if (GlobalConfig.Instance.Debug.Switches[2])
                    {
                        Log._Debug($"CustomHumanAI.EnterParkedCar: Could not spawn a {vehicleInfo.m_vehicleType} for citizen instance {instanceID}!");
                    }
#endif
                    return(false);
                }

                // change instances
                InstanceID parkedVehInstance = InstanceID.Empty;
                parkedVehInstance.ParkedVehicle = parkedVehicleId;
                InstanceID vehInstance = InstanceID.Empty;
                vehInstance.Vehicle = vehicleId;
                Singleton <InstanceManager> .instance.ChangeInstance(parkedVehInstance, vehInstance);

                // set vehicle id for citizen instance
                instanceData.m_path = 0u;
                citManager.m_citizens.m_buffer[instanceData.m_citizen].SetParkedVehicle(instanceData.m_citizen, 0);
                citManager.m_citizens.m_buffer[instanceData.m_citizen].SetVehicle(instanceData.m_citizen, vehicleId, 0u);

                // update citizen instance flags
                instanceData.m_flags      &= ~CitizenInstance.Flags.WaitingPath;
                instanceData.m_flags      &= ~CitizenInstance.Flags.EnteringVehicle;
                instanceData.m_flags      &= ~CitizenInstance.Flags.TryingSpawnVehicle;
                instanceData.m_flags      &= ~CitizenInstance.Flags.BoredOfWaiting;
                instanceData.m_waitCounter = 0;

                // unspawn citizen instance
                instanceData.Unspawn(instanceID);

#if DEBUG
                if (GlobalConfig.Instance.Debug.Switches[4])
                {
                    Log._Debug($"CustomHumanAI.EnterParkedCar: Citizen instance {instanceID} is now entering vehicle {vehicleId}. Set vehicle target position to {vehLanePos} (segment={vehLanePathPos.m_segment}, lane={vehLanePathPos.m_lane}, offset={vehLanePathPos.m_offset})");
                }
#endif

                return(true);
            }
            else
            {
                // failed to find a road position
#if DEBUG
                if (GlobalConfig.Instance.Debug.Switches[2])
                {
                    Log._Debug($"CustomHumanAI.EnterParkedCar: Could not find a road position for citizen instance {instanceID} near parked vehicle {parkedVehicleId}!");
                }
#endif
                return(false);
            }
        }
示例#19
0
        public Guid AddVehicle(VehicleDTO vehicleDto)
        {
            VehicleManager vehicleManager = new VehicleManager();

            return(vehicleManager.CreateVehicle(vehicleDto));
        }