public void RefreshLines()
        {
            if (Singleton <BuildingManager> .exists)
            {
                int count        = 0;
                var buildingList = SVMBuildingUtils.getAllBuildingsFromCity(Singleton <T> .instance.GetSSD());

                SVMUtils.doLog("{0} buildingList = [{1}] (s={2})", GetType(), string.Join(",", buildingList.Select(x => x.ToString()).ToArray()), buildingList.Count);
                foreach (ushort buildingID in buildingList)
                {
                    Building b             = Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingID];
                    var      ext           = SVMBuildingAIOverrideUtils.getBuildingOverrideExtension(b.Info);
                    var      maxCountField = ext.GetVehicleMaxCountField(SVMSysDef <T> .instance.GetSSD().vehicleType);
                    var      maxVehicle    = SVMUtils.GetPrivateField <int>(b.Info.GetAI(), maxCountField);
                    if (maxCountField == null || maxVehicle > 0)
                    {
                        AddToList(buildingID, ref count);
                    }
                }
                RemoveExtraLines(count);
                SVMUtils.doLog("{0} final count = {1}", GetType(), count);

                m_LinesUpdated = true;
            }
        }
Пример #2
0
        private static void loadLocaleIntern(string localeId, bool setLocale)
        {
            string load = ResourceLoader.loadResourceString("UI.i18n." + localeId + ".properties");

            if (load == null)
            {
                SVMUtils.doErrorLog("FILE " + "UI.i18n." + localeId + ".properties" + " NOT LOADED!!!!");
                load = ResourceLoader.loadResourceString("UI.i18n.en.properties");
                if (load == null)
                {
                    SVMUtils.doErrorLog("LOCALE NOT LOADED!!!!");
                    return;
                }
                localeId = "en";
            }
            var locale = SVMUtils.GetPrivateField <Locale>(LocaleManager.instance, "m_Locale");

            Locale.Key k;


            foreach (var myString in load.Split(new string[] { lineSeparator }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (myString.StartsWith(commentChar))
                {
                    continue;
                }
                if (!myString.Contains(kvSeparator))
                {
                    continue;
                }
                bool   noPrefix  = myString.StartsWith(ignorePrefixChar);
                var    array     = myString.Split(kvSeparator.ToCharArray(), 2);
                string value     = array[1];
                int    idx       = 0;
                string localeKey = null;
                if (array[0].Contains(idxSeparator))
                {
                    var arrayIdx = array[0].Split(idxSeparator.ToCharArray());
                    if (!int.TryParse(arrayIdx[1], out idx))
                    {
                        continue;
                    }
                    array[0] = arrayIdx[0];
                }
                if (array[0].Contains(localeKeySeparator))
                {
                    array     = array[0].Split(localeKeySeparator.ToCharArray());
                    localeKey = array[1];
                }

                k = new Locale.Key()
                {
                    m_Identifier = noPrefix ? array[0].Substring(1) : "SVM_" + array[0],
                    m_Key        = localeKey,
                    m_Index      = idx
                };
                if (!locale.Exists(k))
                {
                    locale.AddLocalizedString(k, value.Replace("\\n", "\n"));
                }
            }

            if (localeId != "en")
            {
                loadLocaleIntern("en", false);
            }
            if (setLocale)
            {
                language = localeId;
            }
        }
        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") });
        }