Esempio n. 1
0
        public VehicleInfo CustomGetVehicleInfo(ushort instanceID, ref CitizenInstance citizenData, bool forceCar, out VehicleInfo trailer)
        {
#if DEBUG
            bool citDebug = (GlobalConfig.Instance.Debug.CitizenInstanceId == 0 || GlobalConfig.Instance.Debug.CitizenInstanceId == instanceID) &&
                            (GlobalConfig.Instance.Debug.CitizenId == 0 || GlobalConfig.Instance.Debug.CitizenId == citizenData.m_citizen) &&
                            (GlobalConfig.Instance.Debug.SourceBuildingId == 0 || GlobalConfig.Instance.Debug.SourceBuildingId == citizenData.m_sourceBuilding) &&
                            (GlobalConfig.Instance.Debug.TargetBuildingId == 0 || GlobalConfig.Instance.Debug.TargetBuildingId == citizenData.m_targetBuilding)
            ;
            bool debug     = GlobalConfig.Instance.Debug.Switches[2] && citDebug;
            bool fineDebug = GlobalConfig.Instance.Debug.Switches[4] && citDebug;
#endif

            trailer = null;

            if (citizenData.m_citizen == 0u)
            {
                return(null);
            }

            // NON-STOCK CODE START
            bool forceTaxi = false;
#if BENCHMARK
            using (var bm = new Benchmark(null, "forceTaxi")) {
#endif
            if (Options.prohibitPocketCars)
            {
                if (ExtCitizenInstanceManager.Instance.ExtInstances[instanceID].pathMode == ExtPathMode.TaxiToTarget)
                {
                    forceTaxi = true;
                }
            }
#if BENCHMARK
        }
#endif
            // NON-STOCK CODE END

            Citizen.AgeGroup ageGroup = CustomCitizenAI.GetAgeGroup(citizenData.Info.m_agePhase);

            int carProb;
            int bikeProb;
            int taxiProb;
            // NON-STOCK CODE START
            if (forceTaxi)
            {
                carProb  = 0;
                bikeProb = 0;
                taxiProb = 100;
            }
            else
            // NON-STOCK CODE END
            if (forceCar || (citizenData.m_flags & CitizenInstance.Flags.BorrowCar) != CitizenInstance.Flags.None)
            {
                carProb  = 100;
                bikeProb = 0;
                taxiProb = 0;
            }
            else
            {
                carProb  = GetCarProbability(instanceID, ref citizenData, ageGroup);
                bikeProb = GetBikeProbability(instanceID, ref citizenData, ageGroup);
                taxiProb = GetTaxiProbability(instanceID, ref citizenData, ageGroup);
            }
            Randomizer randomizer = new Randomizer(citizenData.m_citizen);
            bool useCar           = randomizer.Int32(100u) < carProb;
            bool useBike          = !useCar && randomizer.Int32(100u) < bikeProb;
            bool useTaxi          = !useCar && !useBike && randomizer.Int32(100u) < taxiProb;
            bool useElectricCar   = false;
            if (useCar)
            {
                int electricProb = GetElectricCarProbability(instanceID, ref citizenData, this.m_info.m_agePhase);
                useElectricCar = randomizer.Int32(100u) < electricProb;
            }

            ItemClass.Service service       = ItemClass.Service.Residential;
            ItemClass.SubService subService = useElectricCar ? ItemClass.SubService.ResidentialLowEco : ItemClass.SubService.ResidentialLow;
            if (useTaxi)
            {
                service    = ItemClass.Service.PublicTransport;
                subService = ItemClass.SubService.PublicTransportTaxi;
            }
            // NON-STOCK CODE START
            VehicleInfo carInfo = null;
#if BENCHMARK
            using (var bm = new Benchmark(null, "find-parked-vehicle")) {
#endif
            if (Options.prohibitPocketCars && useCar)
            {
                ushort parkedVehicleId = Singleton <CitizenManager> .instance.m_citizens.m_buffer[citizenData.m_citizen].m_parkedVehicle;
                if (parkedVehicleId != 0)
                {
#if DEBUG
                    if (debug)
                    {
                        Log._Debug($"CustomResidentAI.CustomGetVehicleInfo({instanceID}): Citizen instance {instanceID} owns a parked vehicle {parkedVehicleId}. Reusing vehicle info.");
                    }
#endif
                    carInfo = Singleton <VehicleManager> .instance.m_parkedVehicles.m_buffer[parkedVehicleId].Info;
                }
            }
#if BENCHMARK
        }
#endif

            if (carInfo == null && (useCar || useTaxi))
            {
                // NON-STOCK CODE END
                carInfo = Singleton <VehicleManager> .instance.GetRandomVehicleInfo(ref randomizer, service, subService, ItemClass.Level.Level1);
            }

            if (useBike)
            {
                VehicleInfo bikeInfo = Singleton <VehicleManager> .instance.GetRandomVehicleInfo(ref randomizer, ItemClass.Service.Residential, ItemClass.SubService.ResidentialHigh, (ageGroup != Citizen.AgeGroup.Child)?ItemClass.Level.Level2 : ItemClass.Level.Level1);

                if (bikeInfo != null)
                {
                    return(bikeInfo);
                }
            }

            if ((useCar || useTaxi) && carInfo != null)
            {
                return(carInfo);
            }
            return(null);
        }
        public VehicleInfo CustomGetVehicleInfo(ushort instanceID, ref CitizenInstance citizenData, bool forceCar)
        {
            if (citizenData.m_citizen == 0u)
            {
                return(null);
            }

            // NON-STOCK CODE START
            bool forceTaxi = false;

            if (Options.prohibitPocketCars)
            {
                ExtCitizenInstance extInstance = ExtCitizenInstanceManager.Instance.GetExtInstance(instanceID);
                if (extInstance.PathMode == ExtPathMode.TaxiToTarget)
                {
                    forceTaxi = true;
                }
            }
            // NON-STOCK CODE END

            Citizen.AgeGroup ageGroup = CustomCitizenAI.GetAgeGroup(citizenData.Info.m_agePhase);

            int carProb;
            int bikeProb;
            int taxiProb;

            // NON-STOCK CODE START
            if (forceTaxi)
            {
                carProb  = 0;
                bikeProb = 0;
                taxiProb = 100;
            }
            else
            // NON-STOCK CODE END
            if (forceCar || (citizenData.m_flags & CitizenInstance.Flags.BorrowCar) != CitizenInstance.Flags.None)
            {
                carProb  = 100;
                bikeProb = 0;
                taxiProb = 0;
            }
            else
            {
                carProb  = GetCarProbability(instanceID, ref citizenData, ageGroup);
                bikeProb = GetBikeProbability(instanceID, ref citizenData, ageGroup);
                taxiProb = GetTaxiProbability(instanceID, ref citizenData, ageGroup);
            }
            Randomizer randomizer = new Randomizer(citizenData.m_citizen);
            bool       useCar     = randomizer.Int32(100u) < carProb;
            bool       useBike    = randomizer.Int32(100u) < bikeProb;
            bool       useTaxi    = randomizer.Int32(100u) < taxiProb;

            ItemClass.Service    service    = ItemClass.Service.Residential;
            ItemClass.SubService subService = ItemClass.SubService.ResidentialLow;
            if (!useCar && useTaxi)
            {
                service    = ItemClass.Service.PublicTransport;
                subService = ItemClass.SubService.PublicTransportTaxi;
            }
            // NON-STOCK CODE START
            VehicleInfo carInfo = null;

            if (Options.prohibitPocketCars && useCar && !useTaxi)
            {
                ExtCitizenInstance extInstance     = ExtCitizenInstanceManager.Instance.GetExtInstance(instanceID);
                ushort             parkedVehicleId = Singleton <CitizenManager> .instance.m_citizens.m_buffer[citizenData.m_citizen].m_parkedVehicle;
                if (parkedVehicleId != 0)
                {
#if DEBUG
                    if (GlobalConfig.Instance.DebugSwitches[2])
                    {
                        Log._Debug($"CustomResidentAI.GetVehicleInfo: Citizen instance {instanceID} owns a parked vehicle {parkedVehicleId}. Reusing vehicle info.");
                    }
#endif
                    carInfo = Singleton <VehicleManager> .instance.m_parkedVehicles.m_buffer[parkedVehicleId].Info;
                }
            }
            if (carInfo == null && (useCar || useTaxi))
            {
                // NON-STOCK CODE END
                carInfo = Singleton <VehicleManager> .instance.GetRandomVehicleInfo(ref randomizer, service, subService, ItemClass.Level.Level1);
            }

            VehicleInfo bikeInfo = Singleton <VehicleManager> .instance.GetRandomVehicleInfo(ref randomizer, ItemClass.Service.Residential, ItemClass.SubService.ResidentialHigh, (ageGroup != Citizen.AgeGroup.Child)?ItemClass.Level.Level2 : ItemClass.Level.Level1);

            if (useBike && bikeInfo != null)
            {
                return(bikeInfo);
            }
            if ((useCar || useTaxi) && carInfo != null)
            {
                return(carInfo);
            }
            return(null);
        }