Esempio n. 1
0
#pragma warning disable IDE0051 // Remover membros privados não utilizados
        private static bool GenerateName(int district, DistrictManager __instance, ref string __result)
        {
            if (AddressesMod.Controller == null)
            {
                return(true);
            }

            Randomizer randomizer = new Randomizer(__instance.m_districts.m_buffer[district].m_randomSeed);
            string     format, arg;
            string     filenamePrefix = AdrController.CurrentConfig.GlobalConfig.AddressingConfig.DistrictsConfig.QualifierFile;
            string     filenameName   = AdrController.CurrentConfig.GlobalConfig.AddressingConfig.DistrictsConfig.NamesFile;

            if (AdrController.LoadedLocalesDistrictPrefix.ContainsKey(filenamePrefix ?? ""))
            {
                int arrLen = AdrController.LoadedLocalesDistrictPrefix[filenamePrefix].Length;
                format = AdrController.LoadedLocalesDistrictPrefix[filenamePrefix][randomizer.Int32((uint)arrLen)];
            }
            else
            {
                format = Locale.Get("DISTRICT_PATTERN", randomizer.Int32(Locale.Count("DISTRICT_PATTERN")));
            }

            if (AdrController.LoadedLocalesDistrictName.ContainsKey(filenameName ?? ""))
            {
                int arrLen = AdrController.LoadedLocalesDistrictName[filenameName].Length;
                arg = AdrController.LoadedLocalesDistrictName[filenameName][randomizer.Int32((uint)arrLen)];
            }
            else
            {
                arg = Locale.Get("DISTRICT_NAME", randomizer.Int32(Locale.Count("DISTRICT_NAME")));
            }

            __result = StringUtils.SafeFormat(format, arg);
            return(false);
        }
Esempio n. 2
0
        public static bool GenerateCitizenName(uint citizenID, byte family, ref string __result)
        {
            Randomizer randomizer  = new Randomizer(citizenID);
            Randomizer randomizer2 = new Randomizer(family);
            bool       isMale      = Citizen.GetGender(citizenID) == Citizen.Gender.Male;

            string name, surname;

            if (isMale)
            {
                string filenameFirst = AdrController.CurrentConfig?.GlobalConfig?.CitizenConfig?.MaleNamesFile ?? "";
                if (AdrController.LoadedLocalesCitizenFirstNameMasc.ContainsKey(filenameFirst))
                {
                    int arrLen = AdrController.LoadedLocalesCitizenFirstNameMasc[filenameFirst].Length;
                    name = AdrController.LoadedLocalesCitizenFirstNameMasc[filenameFirst][randomizer.Int32((uint)arrLen)];
                }
                else
                {
                    name = Locale.Get("NAME_MALE_FIRST", randomizer.Int32(Locale.Count("NAME_MALE_FIRST")));
                }
            }
            else
            {
                string filenameFirst = AdrController.CurrentConfig?.GlobalConfig?.CitizenConfig?.FemaleNamesFile ?? "";
                if (AdrController.LoadedLocalesCitizenFirstNameFem.ContainsKey(filenameFirst))
                {
                    int arrLen = AdrController.LoadedLocalesCitizenFirstNameFem[filenameFirst].Length;
                    name = AdrController.LoadedLocalesCitizenFirstNameFem[filenameFirst][randomizer.Int32((uint)arrLen)];
                }
                else
                {
                    name = Locale.Get("NAME_FEMALE_FIRST", randomizer.Int32(Locale.Count("NAME_FEMALE_FIRST")));
                }
            }
            string filenameLast = AdrController.CurrentConfig?.GlobalConfig?.CitizenConfig?.SurnamesFile ?? "";

            if (AdrController.LoadedLocalesCitizenLastName.ContainsKey(filenameLast))
            {
                int arrLen = AdrController.LoadedLocalesCitizenLastName[filenameLast].Length;
                surname = AdrController.LoadedLocalesCitizenLastName[filenameLast][randomizer2.Int32((uint)arrLen)];
            }
            else
            {
                if (isMale)
                {
                    surname = Locale.Get("NAME_MALE_LAST", randomizer2.Int32(Locale.Count("NAME_MALE_LAST")));
                }
                else
                {
                    surname = Locale.Get("NAME_FEMALE_LAST", randomizer2.Int32(Locale.Count("NAME_FEMALE_LAST")));
                }
            }

            __result = StringUtils.SafeFormat(surname, name);
            return(false);
        }
Esempio n. 3
0
        private string GenerateMapName(string environment)
        {
            CityNameGroups.Environment environment2 = this.m_CityNameGroups.FindGroup(environment);
            string key    = environment2.m_closeDistance[UnityEngine.Random.Range(0, environment2.m_closeDistance.Length)];
            int    max    = (int)Locale.Count("CONNECTIONS_PATTERN", key);
            string format = Locale.Get("CONNECTIONS_PATTERN", key, UnityEngine.Random.Range(0, max));
            int    num2   = (int)Locale.Count("CONNECTIONS_NAME", key);
            string str3   = Locale.Get("CONNECTIONS_NAME", key, UnityEngine.Random.Range(0, num2));

            return(string.Format(format, str3));
        }
        public static bool GenerateSegmentNameInternal(ushort segmentID, ref string __result, ref List <ushort> usedQueue, bool removePrefix)
        {
            LogUtils.DoLog($"[START {segmentID}]" + __result);
            if ((NetManager.instance.m_segments.m_buffer[segmentID].m_flags & NetSegment.Flags.CustomName) != 0)
            {
                if (usedQueue.Count == 0)
                {
                    return(true);
                }
                else
                {
                    InstanceID id = default;
                    id.NetSegment = segmentID;
                    __result      = Singleton <InstanceManager> .instance.GetName(id);

                    return(false);
                }
            }
            NetSegment segment    = NetManager.instance.m_segments.m_buffer[segmentID];
            NetInfo    info       = segment.Info;
            PrefabAI   ai         = info.GetAI();
            string     format     = null;
            Randomizer randomizer = new Randomizer(segment.m_nameSeed);
            ushort     district   = (ushort)(DistrictManager.instance.GetDistrict(segment.m_middlePosition) & 0xFF);

            Xml.AdrDistrictConfig districtConfig = AdrController.CurrentConfig.GetConfigForDistrict(district);
            Xml.AdrDistrictConfig cityConfig     = AdrController.CurrentConfig.GetConfigForDistrict(0);

            if ((info.m_vehicleTypes & VehicleInfo.VehicleType.Car) != VehicleInfo.VehicleType.None)
            {
                string filenamePrefix = districtConfig.RoadConfig?.QualifierFile ?? "";
                ;
                if ((filenamePrefix == null || !AdrController.LoadedLocalesRoadPrefix.ContainsKey(filenamePrefix)) && district > 0)
                {
                    filenamePrefix = cityConfig.RoadConfig?.QualifierFile;
                }

                if (filenamePrefix != null && AdrController.LoadedLocalesRoadPrefix.ContainsKey(filenamePrefix))
                {
                    LocaleStruct.RoadPrefixFileIndexer currentPrefixFile = AdrController.LoadedLocalesRoadPrefix[filenamePrefix];
                    format = currentPrefixFile.GetPrefix(ai, info.m_forwardVehicleLaneCount == 0 || info.m_backwardVehicleLaneCount == 0, info.m_forwardVehicleLaneCount == info.m_backwardVehicleLaneCount, info.m_halfWidth * 2, (byte)(info.m_forwardVehicleLaneCount + info.m_backwardVehicleLaneCount), randomizer, segmentID);
                }
                LogUtils.DoLog("selectedPrefix = {0}", format);
                if (format == null)
                {
                    string key         = DefaultPrefix(info, ai);
                    uint   rangeFormat = Locale.Count(key);
                    format = Locale.Get(key, randomizer.Int32(rangeFormat));
                }
            }

            if (format == null)
            {
                return(true);
            }

            if (removePrefix)
            {
                format = Regex.Replace(format, "(?!\\{)(\\w+|\\.)(?!\\})", "");
                if (format.IsNullOrWhiteSpace())
                {
                    return(true);
                }
            }

            string genName             = "";
            string sourceRoad          = "";
            string targetRoad          = "";
            string sourceKm            = "";
            string sourceKmWithDecimal = "";
            string sourceDistrict      = "";
            string targetDistrict      = "";
            string direction           = "";

            if (format.Contains("{0}"))
            {
                GetGeneratedRoadName(segment, ai, district, out genName);
                if (genName == null)
                {
                    return(true);
                }
            }
            ushort sourceSeg = 0;
            ushort targetSeg = 0;

            if (format.Contains("{1}") || format.Contains("{2}") || format.Contains("{3}") || format.Contains("{4}") || format.Contains("{7}"))
            {
                SegmentUtils.GetSegmentRoadEdges(segmentID, true, true, true, out ComparableRoad startRef, out ComparableRoad endRef, out _);

                sourceSeg = startRef.segmentReference;
                targetSeg = endRef.segmentReference;

                if (format.Contains("{1}"))
                {
                    if (!usedQueue.Contains(sourceSeg))
                    {
                        usedQueue.Add(sourceSeg);
                        GenerateSegmentNameInternal(sourceSeg, ref sourceRoad, ref usedQueue, false);
                    }
                }
                if (format.Contains("{2}"))
                {
                    if (!usedQueue.Contains(targetSeg))
                    {
                        usedQueue.Add(targetSeg);
                        GenerateSegmentNameInternal(targetSeg, ref targetRoad, ref usedQueue, false);
                    }
                }
                if (format.Contains("{3}") || format.Contains("{4}"))
                {
                    float km = GetNumberAt(startRef.segmentReference, NetManager.instance.m_segments.m_buffer[startRef.segmentReference].m_startNode == startRef.nodeReference) / 1000f;
                    sourceKm            = km.ToString("0");
                    sourceKmWithDecimal = km.ToString("0.0");
                }
                if (format.Contains("{7}"))//direction
                {
                    int cardinalDirection = SegmentUtils.GetCardinalDirection(startRef, endRef);

                    direction = Locale.Get("K45_CARDINAL_POINT_SHORT", cardinalDirection.ToString());
                }
            }
            if (format.Contains("{5}") || format.Contains("{6}"))
            {
                GetSegmentRoadEdges(segmentID, false, false, false, out ComparableRoad startRef, out ComparableRoad endRef, out _);
                if (format.Contains("{5}"))//source district
                {
                    sourceDistrict = GetDistrictAt(startRef);
                }
                if (format.Contains("{6}"))//target district
                {
                    targetDistrict = GetDistrictAt(endRef);
                }
            }
            if (AddressesMod.DebugMode)
            {
                __result = $"[{segmentID}] " + StringUtils.SafeFormat(format, genName, sourceSeg, targetSeg, sourceKm, sourceKmWithDecimal, sourceDistrict, targetDistrict, direction)?.Trim();
            }
            else
            {
                __result = StringUtils.SafeFormat(format, genName, sourceRoad, targetRoad, sourceKm, sourceKmWithDecimal, sourceDistrict, targetDistrict, direction)?.Trim();
            }
            LogUtils.DoLog($"[END {segmentID}]" + __result);
            return(false);
        }
Esempio n. 5
0
        private static string OriginalGenerateName(OutsideConnectionAI __instance, InstanceID caller)
        {
            CityNameGroups.Environment cityNameGroups = Singleton <BuildingManager> .instance.m_cityNameGroups;
            if (cityNameGroups == null)
            {
                return(null);
            }
            var num = 0;

            if (__instance.m_useCloseNames)
            {
                num += cityNameGroups.m_closeDistance.Length;
            }
            if (__instance.m_useMediumNames)
            {
                num += cityNameGroups.m_mediumDistance.Length;
            }
            if (__instance.m_useFarNames)
            {
                num += cityNameGroups.m_farDistance.Length;
            }
            if (num != 0)
            {
                var randomizer = new Randomizer(caller.Index);
                num = randomizer.Int32((uint)num);
                string text = null;
                if (text == null && __instance.m_useCloseNames)
                {
                    if (num < cityNameGroups.m_closeDistance.Length)
                    {
                        text = cityNameGroups.m_closeDistance[num];
                    }
                    else
                    {
                        num -= cityNameGroups.m_closeDistance.Length;
                    }
                }
                if (text == null && __instance.m_useMediumNames)
                {
                    if (num < cityNameGroups.m_mediumDistance.Length)
                    {
                        text = cityNameGroups.m_mediumDistance[num];
                    }
                    else
                    {
                        num -= cityNameGroups.m_mediumDistance.Length;
                    }
                }
                if (text == null && __instance.m_useFarNames)
                {
                    if (num < cityNameGroups.m_farDistance.Length)
                    {
                        text = cityNameGroups.m_farDistance[num];
                    }
                }
                var range  = Locale.Count("CONNECTIONS_PATTERN", text);
                var format = Locale.Get("CONNECTIONS_PATTERN", text, randomizer.Int32(range));
                var range2 = Locale.Count("CONNECTIONS_NAME", text);
                var arg    = Locale.Get("CONNECTIONS_NAME", text, randomizer.Int32(range2));
                return(StringUtils.SafeFormat(format, arg));
            }
            return(null);
        }
        /*********** building updates *************/

        //residential building history updates
        public void UpdateResidentFamilies(int resilient_index)
        {
            if (!Settings.inst.listResidentsAndWorkers)
            {
                return;
            }

            List <uint> current_families_id = new List <uint>();

            Building       build          = Singleton <BuildingManager> .instance.m_buildings.m_buffer[m_resilients[resilient_index].buildingID];
            CitizenManager instance       = Singleton <CitizenManager> .instance;
            uint           num            = build.m_citizenUnits;
            int            num2           = 0;
            int            aliveHomeCount = 0;

            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.Home) != 0)
                {
                    current_families_id.Add(num);
                    aliveHomeCount++;
                }
                num = nextUnit;

                if (++num2 > 524288)
                {
                    CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace);

                    break;
                }
            }

            //update history family list with any new names
            int index_families_before_now = Math.Max(m_resilients[resilient_index].namesBuffer.Count - aliveHomeCount, 0);

            for (int i = 0; i < current_families_id.Count; i++)
            {
//				if(!m_resilients[resilient_index].idsBuffer.Contains(current_families_id[i]))
//				{
//					m_resilients[resilient_index].idsBuffer.Add(current_families_id[i]);
//				}

                uint        valid_citizen = 0u;
                CitizenUnit cu            = Singleton <CitizenManager> .instance.m_units.m_buffer[current_families_id[i]];
                if (cu.m_citizen0 != 0u)
                {
                    valid_citizen = cu.m_citizen0;
                }
                else if (cu.m_citizen1 != 0u)
                {
                    valid_citizen = cu.m_citizen1;
                }
                else if (cu.m_citizen2 != 0u)
                {
                    valid_citizen = cu.m_citizen2;
                }
                else if (cu.m_citizen3 != 0u)
                {
                    valid_citizen = cu.m_citizen3;
                }
                else if (cu.m_citizen4 != 0u)
                {
                    valid_citizen = cu.m_citizen4;
                }

                if (valid_citizen != 0u)
                {
                    int        family      = Singleton <CitizenManager> .instance.m_citizens.m_buffer[valid_citizen].m_family;
                    Randomizer randomizer2 = new Randomizer(family);
                    string     name        = "NAME_FEMALE_LAST";
                    //					if (Citizen.GetGender(citizenID) == Citizen.Gender.Male)
                    //					{
                    //						text = "NAME_MALE_FIRST";
                    //						text2 = "NAME_MALE_LAST";
                    //					}
                    name = Locale.Get(name, randomizer2.Int32(Locale.Count(name)));
                    name = name.Substring(4);                                                                                                                            //remove placeholder in front

                    if (m_resilients[resilient_index].namesBuffer.Count == 0 || m_resilients[resilient_index].namesBuffer.LastIndexOf(name) < index_families_before_now) //-1 if family was never present, otherwise check if it is not currently in
                    {
                        m_resilients[resilient_index].namesBuffer.Add(name);
                    }
                }
            }
        }