Exemple #1
0
        public static bool PreGetColor(ref Color __result, ushort vehicleID, ref Vehicle data, InfoManager.InfoMode infoMode)
        {
            if (data.m_transportLine == 0)
            {
                if (infoMode != InfoManager.InfoMode.None)
                {
                    return(true);
                }

                ServiceSystemDefinition def = ServiceSystemDefinition.from(data.Info);
                if (def == default(ServiceSystemDefinition))
                {
                    return(true);
                }
                ushort buildingId = data.m_sourceBuilding;
                if (buildingId == 0)
                {
                    return(true);
                }

                Color c = def.GetTransportExtension().GetEffectiveColorBuilding(buildingId);
                if (c == Color.clear)
                {
                    return(true);
                }
                __result = c;
                return(false);
            }
            return(true);
        }
        public void openInfo(ushort buildingID)
        {
            WorldInfoPanel.HideAllWorldInfoPanels();

            var ssds = ServiceSystemDefinition.from(Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingID].Info);
            var ext  = ssds.First().GetTransportExtension();

            m_buildingIdSelecionado          = default(InstanceID);
            m_ignoreDistrict.isChecked       = ext.GetIgnoreDistrict(buildingID);
            m_buildingIdSelecionado.Building = buildingID;
            buildingNameField.text           = Singleton <BuildingManager> .instance.GetBuildingName(buildingID, default(InstanceID));


            var configIdx = ssds.First().toConfigIndex();


            String bgIcon = SVMConfigWarehouse.getIconServiceSystem(configIdx);
            String fgIcon = SVMConfigWarehouse.getFgIconServiceSystem(configIdx);

            buildingTypeIcon.normalFgSprite = bgIcon;
            buildingTypeIconFg.spriteName   = fgIcon;

            SVMController.instance.CloseSVMPanel();
            Show();
            EventOnBuildingSelChanged?.Invoke(buildingID);
        }
        private void updateBuildingEditShortcutButton(UIPanel parent)
        {
            if (parent != null)
            {
                UIButton buildingEditShortcut = parent.Find <UIButton>("SVMBuildingShortcut");
                if (!buildingEditShortcut)
                {
                    buildingEditShortcut = initBuildingEditOnWorldInfoPanel(parent);
                }
                var prop = typeof(WorldInfoPanel).GetField("m_InstanceID", System.Reflection.BindingFlags.NonPublic
                                                           | System.Reflection.BindingFlags.Instance);
                ushort buildingId = ((InstanceID)(prop.GetValue(parent.gameObject.GetComponent <WorldInfoPanel>()))).Building;
                var    ssds       = ServiceSystemDefinition.from(Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingId].Info);

                byte count = 0;
                foreach (var ssd in ssds)
                {
                    var maxCount = SVMBuildingUtils.GetMaxVehiclesBuilding(buildingId, ssd.vehicleType, ssd.level);
                    if (maxCount > 0)
                    {
                        count++;
                        break;
                    }
                }
                buildingEditShortcut.isVisible = count > 0;
            }
        }
Exemple #4
0
        public static void RemoveAllUnwantedVehicles()
        {
            var r = new Randomizer();

            for (ushort vehicleId = 1; vehicleId < Singleton <VehicleManager> .instance.m_vehicles.m_size; vehicleId++)
            {
                if ((Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId].m_flags & Vehicle.Flags.Created) != 0)
                {
                    ref Vehicle vehicle     = ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleId];
                    VehicleInfo vehicleInfo = vehicle.Info;
                    if (vehicleInfo != null && !VehicleUtils.IsTrailer(vehicleInfo) && vehicle.m_transportLine == 0 && vehicle.m_sourceBuilding > 0)
                    {
                        var buildingSsd = ServiceSystemDefinition.from(vehicleInfo);
                        if (buildingSsd != null)
                        {
                            if (!ExtensionStaticExtensionMethods.IsModelCompatible(vehicle.m_sourceBuilding, vehicleInfo, ref buildingSsd))
                            {
                                if (vehicleInfo.m_vehicleAI is CarAI)
                                {
                                    var model = buildingSsd.GetAModel(ref r, vehicle.m_sourceBuilding);
                                    VehicleUtils.ReplaceVehicleModel(vehicleId, model);
                                }
                                else
                                {
                                    Singleton <VehicleManager> .instance.ReleaseVehicle(vehicleId);
                                }
                            }
                        }
                    }
                }
            }
Exemple #5
0
        public void Hide()
        {
            m_buildingInfoPanel.Hide();
            ServiceSystemDefinition ssd = ServiceSystemDefinition.from(Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingIdSel.Building].Info).FirstOrDefault();

            VMCTabPanel.Instance.OpenAt(ref ssd);
        }
Exemple #6
0
        //    public static void RemoveAllUnwantedVehicles() { using var x = new EnumerableActionThread(new Func<ThreadBase, IEnumerator>(RemoveAllUnwantedVehicles)); }
        public static IEnumerator RemoveAllUnwantedVehicles(ThreadBase t)
        {
            ushort num = 0;

            while (num < Singleton <VehicleManager> .instance.m_vehicles.m_size)
            {
                VehicleInfo vehicleInfo = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].Info;
                if (vehicleInfo != null && !VehicleUtils.IsTrailer(vehicleInfo) && Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].m_transportLine == 0 && Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].m_sourceBuilding > 0)
                {
                    BuildingInfo buildingInfo = Singleton <BuildingManager> .instance.m_buildings.m_buffer[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].m_sourceBuilding].Info;
                    var          buildingSsd  = ServiceSystemDefinition.from(buildingInfo, vehicleInfo.m_vehicleType);
                    if (buildingSsd != null)
                    {
                        if (!ExtensionStaticExtensionMethods.IsModelCompatible(Singleton <VehicleManager> .instance.m_vehicles.m_buffer[num].m_sourceBuilding, vehicleInfo, ref buildingSsd))
                        {
                            Singleton <VehicleManager> .instance.ReleaseVehicle(num);
                        }
                    }
                }
                if (num % 256 == 255)
                {
                    yield return(num);
                }
                num++;
            }
            yield break;
        }
 protected virtual bool ProcessOffer(ushort buildingID, Building data, TransferManager.TransferReason material, TransferManager.TransferOffer offer, TransferManager.TransferReason trTarget, Tuple <VehicleInfo.VehicleType, bool, bool> tup, U instance)
 {
     if (material == trTarget)
     {
         ServiceSystemDefinition def = ServiceSystemDefinition.from(instance.m_info, tup.First);
         if (def == null)
         {
             SVMUtils.doLog("SSD Não definido para: {0} {1} {2} {3}", instance.m_info.m_class.m_service, instance.m_info.m_class.m_subService, instance.m_info.m_class.m_level, tup.First);
             return(false);
         }
         SVMUtils.doLog("[{1}] SSD = {0}", def, material);
         VehicleInfo randomVehicleInfo = ServiceSystemDefinition.availableDefinitions[def].GetAModel(buildingID);
         SVMUtils.doLog("[{1}] Veh = {0}", randomVehicleInfo?.ToString() ?? "<NULL>", material);
         if (randomVehicleInfo != null)
         {
             Array16 <Vehicle> vehicles = Singleton <VehicleManager> .instance.m_vehicles;
             instance.CalculateSpawnPosition(buildingID, ref data, ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, out Vector3 position, out Vector3 vector2);
             if (Singleton <VehicleManager> .instance.CreateVehicle(out ushort num, ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, position, material, tup.Second, tup.Third))
             {
                 randomVehicleInfo.m_vehicleAI.SetSource(num, ref vehicles.m_buffer[(int)num], buildingID);
                 randomVehicleInfo.m_vehicleAI.StartTransfer(num, ref vehicles.m_buffer[(int)num], material, offer);
                 return(true);
             }
         }
     }
     return(false);
 }
        private static bool CreateIncomingVehicle(bool __result, TransportStationAI __instance, ushort buildingID, ref Building buildingData, ushort startStop, int gateIndex)
        {
            if (__instance.m_transportLineInfo != null && (ushort)FindConnectionVehicle.Invoke(__instance, new object[] { buildingID, buildingData, startStop, 3000f }) == 0)
            {
                SVMUtils.doLog("START CreateIncomingVehicle: {0} , {1}", typeof(TransportStationAI), __instance.name);
                ServiceSystemDefinition def = ServiceSystemDefinition.from(buildingData.Info).FirstOrDefault();
                if (def == null)
                {
                    SVMUtils.doLog("SSD Não definido para: {0} {1} {2}", buildingData.Info.m_class.m_service, buildingData.Info.m_class.m_subService, buildingData.Info.m_class.m_level);
                    return(false);
                }
                SVMUtils.doLog("[{1}] SSD = {0}", def, "CreateIncomingVehicle");
                VehicleInfo randomVehicleInfo = ServiceSystemDefinition.availableDefinitions[def].GetAModel(buildingID);
                SVMUtils.doLog("[{1}] Veh = {0}", randomVehicleInfo?.ToString() ?? "<NULL>", "CreateIncomingVehicle");

                if (randomVehicleInfo != null)
                {
                    ushort num = (ushort)FindConnectionBuilding.Invoke(__instance, new object[] { startStop });
                    if (num != 0)
                    {
                        Array16 <Vehicle> vehicles   = Singleton <VehicleManager> .instance.m_vehicles;
                        BuildingInfo      info       = Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)num].Info;
                        Randomizer        randomizer = default(Randomizer);
                        randomizer.seed = (ulong)((long)gateIndex);
                        Vector3 vector;
                        Vector3 vector2;
                        info.m_buildingAI.CalculateSpawnPosition(num, ref Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)num], ref randomizer, randomVehicleInfo, out vector, out vector2);
                        TransportInfo transportInfo = __instance.m_transportInfo;
                        if (__instance.m_secondaryTransportInfo != null && __instance.m_secondaryTransportInfo.m_class.m_subService == __instance.m_transportLineInfo.m_class.m_subService)
                        {
                            transportInfo = __instance.m_secondaryTransportInfo;
                        }
                        if (randomVehicleInfo.m_vehicleAI.CanSpawnAt(vector) && Singleton <VehicleManager> .instance.CreateVehicle(out ushort num2, ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, vector, transportInfo.m_vehicleReason, true, false))
                        {
                            vehicles.m_buffer[(int)num2].m_gateIndex = (byte)gateIndex;
                            Vehicle[] expr_172_cp_0 = vehicles.m_buffer;
                            ushort    expr_172_cp_1 = num2;
                            expr_172_cp_0[(int)expr_172_cp_1].m_flags = (expr_172_cp_0[(int)expr_172_cp_1].m_flags | (Vehicle.Flags.Importing | Vehicle.Flags.Exporting));
                            randomVehicleInfo.m_vehicleAI.SetSource(num2, ref vehicles.m_buffer[(int)num2], num);
                            randomVehicleInfo.m_vehicleAI.SetSource(num2, ref vehicles.m_buffer[(int)num2], buildingID);
                            randomVehicleInfo.m_vehicleAI.SetTarget(num2, ref vehicles.m_buffer[(int)num2], startStop);
                            SVMUtils.doLog("END CreateIncomingVehicle: {0} , {1}", typeof(TransportStationAI), __instance.name);
                            __result = true;
                            return(false);
                        }
                    }
                }
            }
            SVMUtils.doLog("END2 CreateIncomingVehicle: {0} , {1}", typeof(TransportStationAI), __instance.name);
            __result = false;
            return(false);
        }
        public static VehicleInfo GetRandomVehicleInfoWithVehicle(VehicleManager vm, ref Randomizer randomizer, ItemClass.Service service, ItemClass.SubService subService, ItemClass.Level level, VehicleInfo.VehicleType vehicleType, ushort buildingId, ref Building building)
        {
            // A
            var ssds = ServiceSystemDefinition.from(service, subService, level, vehicleType, building.Info.m_buildingAI is OutsideConnectionAI);

            if (ssds != default)
            {
                var vehicleInfo = ssds.GetAModel(ref randomizer, buildingId);
                if (vehicleInfo != default)
                {
                    return(vehicleInfo);
                }
            }
            return(VehicleManager.instance.GetRandomVehicleInfo(ref randomizer, service, subService, level, vehicleType));
        }
Exemple #10
0
 private void CreateIgnoreDistrictOption()
 {
     m_ignoreDistrict = m_uiHelper.AddCheckboxLocale("K45_VMC_IGNORE_DISTRICT_CONFIG", false);
     m_ignoreDistrict.relativePosition   = new Vector3(5f, 150f);
     m_ignoreDistrict.eventCheckChanged += delegate(UIComponent comp, bool value)
     {
         if (Singleton <BuildingManager> .exists && m_buildingIdSelecionado.Building != 0)
         {
             IEnumerable <ServiceSystemDefinition> ssds = ServiceSystemDefinition.from(Singleton <BuildingManager> .instance.m_buildings.m_buffer[m_buildingIdSelecionado.Building].Info);
             foreach (ServiceSystemDefinition ssd in ssds)
             {
                 ssd.GetBuildingExtension().SetIgnoreDistrict(m_buildingIdSelecionado.Building, value);
             }
             EventOnBuildingSelChanged?.Invoke(m_buildingIdSelecionado.Building);
         }
     };
     m_ignoreDistrict.label.textScale = 0.9f;
 }
        private void OnBuildingChange(ushort buildingId)
        {
            SVMUtils.doLog("EventOnBuildingSelChanged");
            m_isLoading = true;
            IEnumerable <ServiceSystemDefinition> ssds = ServiceSystemDefinition.from(Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingId].Info);

            if (!ssds.Contains(Singleton <T> .instance.GetSSD()))
            {
                m_mainPanel.isVisible = false;
                return;
            }
            m_mainPanel.isVisible = true;
            var ssd = Singleton <T> .instance.GetSSD();

            var  ext            = ssd.GetTransportExtension();
            bool isCustomConfig = ext.GetIgnoreDistrict(buildingId);

            SVMUtils.doLog("ssd = {0}", ssd);

            List <string> selectedAssets;
            Color         selectedColor;

            if (isCustomConfig)
            {
                selectedAssets = ext.GetAssetListBuilding(buildingId);
                selectedColor  = ext.GetColorBuilding(buildingId);
            }
            else
            {
                var districtId = SVMUtils.GetBuildingDistrict(buildingId);
                selectedAssets = ext.GetAssetListDistrict(districtId);
                selectedColor  = ext.GetColorDistrict(districtId);
            }
            foreach (var i in m_checkboxes.Keys)
            {
                m_checkboxes[i].isChecked = selectedAssets.Contains(i);
            }
            if (m_color != null)
            {
                m_color.selectedColor = selectedColor;
            }

            if (isCustomConfig)
            {
                m_title.text = string.Format(Locale.Get("SVM_ASSET_SELECT_WINDOW_TITLE"), Singleton <BuildingManager> .instance.GetBuildingName(buildingId, default(InstanceID)), SVMConfigWarehouse.getNameForServiceSystem(ssd.toConfigIndex()));
            }
            else
            {
                var districtId = SVMUtils.GetBuildingDistrict(buildingId);
                if (districtId > 0)
                {
                    m_title.text = string.Format(Locale.Get("SVM_ASSET_SELECT_WINDOW_TITLE_DISTRICT"), Singleton <DistrictManager> .instance.GetDistrictName(SVMUtils.GetBuildingDistrict(buildingId)), SVMConfigWarehouse.getNameForServiceSystem(ssd.toConfigIndex()));
                }
                else
                {
                    m_title.text = string.Format(Locale.Get("SVM_ASSET_SELECT_WINDOW_TITLE_CITY"), SVMConfigWarehouse.getNameForServiceSystem(ssd.toConfigIndex()));
                }
            }

            m_isLoading = false;
            m_previewPanel.isVisible = false;
        }
        public void Update()
        {
            if (!this.m_buildingInfoPanel.isVisible)
            {
                return;
            }
            Building b = Singleton <BuildingManager> .instance.m_buildings.m_buffer[m_buildingIdSelecionado.Building];

            if (!(b.Info.GetAI() is BuildingAI basicAI))
            {
                closeBuildingInfo(null, null);
                return;
            }

            var           ssds         = ServiceSystemDefinition.from(b.Info);
            List <string> textVehicles = new List <string>();

            foreach (var ssd in ssds)
            {
                int count    = 0;
                int cargo    = 0;
                int capacity = 0;
                int inbound  = 0;
                int outbound = 0;
                var ext      = SVMBuildingAIOverrideUtils.getBuildingOverrideExtension(b.Info);
                SVMBuildingUtils.CalculateOwnVehicles(m_buildingIdSelecionado.Building, ref b, ext.GetManagedReasons(b.Info).Keys, ref count, ref cargo, ref capacity, ref inbound, ref outbound);
                var    maxField       = ext.GetVehicleMaxCountField(ssd.vehicleType);
                int    maxVehicles    = (SVMUtils.GetPrivateField <int>(b.Info.GetAI(), maxField) * SVMBuildingUtils.GetProductionRate(ref b) / 100);
                string maxVehiclesStr = maxField == null || maxVehicles > 0x3FFF ? "∞" : maxVehicles.ToString();
                textVehicles.Add($"{count}/{maxVehiclesStr} ({Locale.Get("SVM_VEHICLE_TYPE", ssd.vehicleType.ToString())})");
            }
            vehiclesInUseLabel.text = string.Join(" | ", textVehicles.ToArray());
            upkeepCost.text         = LocaleFormatter.FormatUpkeep(basicAI.GetResourceRate(m_buildingIdSelecionado.Building, ref Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)m_buildingIdSelecionado.Building], EconomyManager.Resource.Maintenance), false);

            uint num         = Singleton <BuildingManager> .instance.m_buildings.m_buffer[m_buildingIdSelecionado.Building].m_citizenUnits;
            int  num2        = 0;
            int  num3        = 0;
            int  unskill     = 0;
            int  oneSchool   = 0;
            int  twoSchool   = 0;
            int  threeSchool = 0;

            CitizenManager instance = Singleton <CitizenManager> .instance;

            while (num != 0u)
            {
                uint nextUnit = instance.m_units.m_buffer[(int)((UIntPtr)num)].m_nextUnit;
                if ((ushort)(instance.m_units.m_buffer[(int)((UIntPtr)num)].m_flags & CitizenUnit.Flags.Work) != 0)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        uint citizen = instance.m_units.m_buffer[(int)((UIntPtr)num)].GetCitizen(i);
                        if (citizen != 0u && !instance.m_citizens.m_buffer[(int)((UIntPtr)citizen)].Dead && (instance.m_citizens.m_buffer[(int)((UIntPtr)citizen)].m_flags & Citizen.Flags.MovingIn) == Citizen.Flags.None)
                        {
                            num3++;
                            switch (instance.m_citizens.m_buffer[(int)((UIntPtr)citizen)].EducationLevel)
                            {
                            case Citizen.Education.Uneducated:
                                unskill++;
                                break;

                            case Citizen.Education.OneSchool:
                                oneSchool++;
                                break;

                            case Citizen.Education.TwoSchools:
                                twoSchool++;
                                break;

                            case Citizen.Education.ThreeSchools:
                                threeSchool++;
                                break;
                            }
                        }
                    }
                }
                num = nextUnit;
                if (++num2 > 524288)
                {
                    CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                    break;
                }
            }

            workerChart.SetValues(new int[] { unskill, oneSchool, twoSchool, threeSchool }, new int[] { SVMUtils.GetPrivateField <int>(basicAI, "m_workPlaceCount0"), SVMUtils.GetPrivateField <int>(basicAI, "m_workPlaceCount1"), SVMUtils.GetPrivateField <int>(basicAI, "m_workPlaceCount2"), SVMUtils.GetPrivateField <int>(basicAI, "m_workPlaceCount3") });
        }
 public void Hide()
 {
     m_buildingInfoPanel.Hide();
     SVMServiceBuildingDetailPanel.Get().OpenAt(ServiceSystemDefinition.from(Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingIdSel.Building].Info).FirstOrDefault());
 }
        protected virtual bool ProcessOffer(ushort buildingID, ref Building data, TransferManager.TransferReason material, TransferManager.TransferOffer offer, TransferManager.TransferReason trTarget, StartTransferCallStructure tup, U instance)
        {
            if (material == trTarget)
            {
                ServiceSystemDefinition def = ServiceSystemDefinition.from(instance.m_info, tup.vehicleType);
                if (def == null)
                {
                    SVMUtils.doLog("SSD Não definido para: {0} {1} {2} {3}", instance.m_info.m_class.m_service, instance.m_info.m_class.m_subService, tup.vehicleLevel ?? instance.m_info.m_class.m_level, tup.vehicleType);
                    return(false);
                }

                #region District Check
                var ext = def.GetTransportExtension();

                if (ext.GetAllowDistrictServiceRestrictions())
                {
                    var buildingDistrict = DistrictManager.instance.GetDistrict(data.m_position);
                    var offerDistrict    = DistrictManager.instance.GetDistrict(offer.Position);
                    if (buildingDistrict != offerDistrict)
                    {
                        if (ServiceVehiclesManagerMod.debugMode)
                        {
                            SVMUtils.doLog($"Building serving different district: building {data.Info} ({buildingID} - districtId {buildingDistrict} {DistrictManager.instance.GetDistrictName(buildingDistrict)}) => offerDistrict: {offerDistrict} {DistrictManager.instance.GetDistrictName(offerDistrict)}");
                        }
                        if (!ext.GetAllowOutsidersEffective(offerDistrict))
                        {
                            var districtBuildings = SVMBuildingUtils.getAllBuildingsFromCity(def, offerDistrict, true, true);

                            if (ServiceVehiclesManagerMod.debugMode)
                            {
                                SVMUtils.doLog($"Offer doesn't allow outsiders. Available buildings found: {districtBuildings}");
                            }
                            if (districtBuildings.Count > 0)
                            {
                                var newBuildingId = districtBuildings[Singleton <SimulationManager> .instance.m_randomizer.Int32((uint)districtBuildings.Count)];
                                return(ProcessOffer(newBuildingId, ref BuildingManager.instance.m_buildings.m_buffer[newBuildingId], material, offer, trTarget, tup, instance));
                            }
                            if (ServiceVehiclesManagerMod.debugMode)
                            {
                                SVMUtils.doLog($"Ignoring because no buildings can handle it");
                            }
                        }
                        if (!ext.GetAllowGoOutsideEffective(buildingDistrict))
                        {
                            var districtBuildings = SVMBuildingUtils.getAllBuildingsFromCity(def, offerDistrict, false, true);
                            if (ServiceVehiclesManagerMod.debugMode)
                            {
                                SVMUtils.doLog($"Building district doesn't allow go out. Available buildings found: {districtBuildings}");
                            }
                            if (districtBuildings.Count > 0)
                            {
                                var newBuildingId = districtBuildings[Singleton <SimulationManager> .instance.m_randomizer.Int32((uint)districtBuildings.Count)];
                                return(ProcessOffer(newBuildingId, ref BuildingManager.instance.m_buildings.m_buffer[newBuildingId], material, offer, trTarget, tup, instance));
                            }
                            if (ServiceVehiclesManagerMod.debugMode)
                            {
                                SVMUtils.doLog($"Ignoring because no buildings can handle it (2)");
                            }
                        }
                    }
                }
                #endregion

                SVMUtils.doLog("[{1}] SSD = {0}", def, material);
                VehicleInfo randomVehicleInfo = ServiceSystemDefinition.availableDefinitions[def].GetAModel(buildingID);
                SVMUtils.doLog("[{1}] Veh = {0}", randomVehicleInfo?.ToString() ?? "<NULL>", material);
                if (randomVehicleInfo != null)
                {
                    Array16 <Vehicle> vehicles = Singleton <VehicleManager> .instance.m_vehicles;
                    instance.CalculateSpawnPosition(buildingID, ref data, ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, out Vector3 position, out Vector3 vector2);
                    if (Singleton <VehicleManager> .instance.CreateVehicle(out ushort num, ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, position, material, tup.tramsferToSource, tup.transferToTarget))
                    {
                        randomVehicleInfo.m_vehicleAI.SetSource(num, ref vehicles.m_buffer[(int)num], buildingID);
                        randomVehicleInfo.m_vehicleAI.StartTransfer(num, ref vehicles.m_buffer[(int)num], material, offer);
                        return(true);
                    }
                }
            }
            return(false);
        }
        private void OnBuildingChange(ushort buildingId)
        {
            LogUtils.DoLog("EventOnBuildingSelChanged");
            m_isLoading = true;
            IEnumerable <ServiceSystemDefinition> ssds = ServiceSystemDefinition.from(Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingId].Info);

            if (!ssds.Contains(SingletonLite <T> .instance.GetSSD()))
            {
                m_mainPanel.isVisible = false;
                return;
            }
            m_mainPanel.isVisible = true;
            ServiceSystemDefinition ssd = SingletonLite <T> .instance.GetSSD();

            IVMCBuildingExtension ext = ssd.GetBuildingExtension();
            bool isCustomConfig       = ext.GetIgnoreDistrict(buildingId);

            LogUtils.DoLog("ssd = {0}", ssd);

            List <string> selectedAssets;
            Color         selectedColor;

            if (isCustomConfig)
            {
                selectedAssets = ext.GetAssetList(buildingId);
                selectedColor  = ext.GetColor(buildingId);
            }
            else
            {
                ushort districtId             = BuildingUtils.GetBuildingDistrict(buildingId);
                IVMCDistrictExtension distExt = ssd.GetDistrictExtension();
                selectedAssets = distExt.GetAssetList(districtId);
                selectedColor  = distExt.GetColor(districtId);
            }
            foreach (string i in m_checkboxes.Keys)
            {
                m_checkboxes[i].isChecked = selectedAssets?.Contains(i) ?? false;
            }
            if (m_color != null)
            {
                m_color.selectedColor = selectedColor;
            }

            if (isCustomConfig)
            {
                m_title.text = string.Format(Locale.Get("K45_VMC_ASSET_SELECT_WINDOW_TITLE"), Singleton <BuildingManager> .instance.GetBuildingName(buildingId, default), ssd.NameForServiceSystem);
            }
            else
            {
                ushort districtId = BuildingUtils.GetBuildingDistrict(buildingId);
                if (districtId > 0)
                {
                    m_title.text = string.Format(Locale.Get("K45_VMC_ASSET_SELECT_WINDOW_TITLE_DISTRICT"), Singleton <DistrictManager> .instance.GetDistrictName(districtId), ssd.NameForServiceSystem);
                }
                else
                {
                    m_title.text = string.Format(Locale.Get("K45_VMC_ASSET_SELECT_WINDOW_TITLE_CITY"), ssd.NameForServiceSystem);
                }
            }

            m_isLoading = false;
            m_previewPanel.isVisible = false;
        }