public void AddElement(Element.Instance element) { #if DEBUG ElementIds.Add(element.Id); #endif Elements.Add(element); }
private void GenerateName() { _rngOffset = RngOffsets.AGENT_GENERATE_NAME + unchecked ((int)Id); Profiler.BeginSample("region.Elements.Where"); List <Element.Instance> elements = BirthRegionInfo.Elements; Profiler.EndSample(); Profiler.BeginSample("region.Attributes.Where"); List <RegionAttribute.Instance> attributes = BirthRegionInfo.AttributeList; Profiler.EndSample(); int optionCount = elements.Count + attributes.Count; if (optionCount <= 0) { throw new System.Exception("No elements nor attributes to choose name from"); } Profiler.BeginSample("remainingElements.Count > getRandomInt"); if (elements.Count > GetRandomInt(optionCount)) { Profiler.BeginSample("RandomSelectAndRemove"); Element.Instance element = elements.RandomSelect(GetRandomInt); Profiler.EndSample(); Profiler.BeginSample("GenerateName - GenerateNameFromElement"); GenerateNameFromElement(element, GetRandomInt); Profiler.EndSample(); } else { Profiler.BeginSample("RandomSelectAndRemove"); RegionAttribute.Instance attribute = attributes.RandomSelect(GetRandomInt); Profiler.EndSample(); Profiler.BeginSample("GenerateName - GenerateNameFromRegionAttribute"); GenerateNameFromRegionAttribute(attribute, GetRandomInt); Profiler.EndSample(); } Profiler.EndSample(); }
private void GenerateNameFromElement(Element.Instance element, GetRandomIntDelegate getRandomInt) { string untranslatedName; string adjective = element.Adjectives.RandomSelect(getRandomInt, 15); if (!string.IsNullOrEmpty(adjective)) { adjective = "[adj]" + adjective + " "; } Association association = element.Associations.RandomSelect(getRandomInt); string nounGender = (IsFemale) ? "[fn]" : "[mn]"; string subjectNoun = "[name]" + nounGender + association.Noun; if (association.IsAdjunction) { untranslatedName = "[Proper][NP](" + adjective + Language.CreateNounAdjunct(element.SingularName) + " " + subjectNoun + ")"; } else { string article = ((association.Form == AssociationForms.DefiniteSingular) || (association.Form == AssociationForms.DefinitePlural) || (association.Form == AssociationForms.NameSingular)) ? "the " : ""; string uncountableProp = (association.Form == AssociationForms.Uncountable) ? "[un]" : ""; string elementNoun = element.SingularName; if ((association.Form == AssociationForms.DefinitePlural) || (association.Form == AssociationForms.IndefinitePlural)) { elementNoun = element.PluralName; } elementNoun = article + adjective + uncountableProp + elementNoun; untranslatedName = "[PpPP]([Proper][NP](" + subjectNoun + ") [PP](" + association.Relation + " [Proper][NP](" + elementNoun + ")))"; } _name = new Name(untranslatedName, Language, World); }
private void GenerateName() { _rngOffset = RngOffsets.REGION_GENERATE_NAME + unchecked ((int)Language.Id); string untranslatedName; int wordCount = 1; List <RegionAttribute.Instance> remainingAttributes = new List <RegionAttribute.Instance>(AttributeList); RegionAttribute.Instance primaryAttribute = remainingAttributes.RandomSelectAndRemove(GetRandomInt); List <Element.Instance> remainingElements = new List <Element.Instance>(Elements); Element.Instance firstElementInstance = remainingElements.RandomSelect(GetRandomInt, 5, true); Element firstElement = null; IEnumerable <string> possibleAdjectives = primaryAttribute.Adjectives; if (firstElementInstance != null) { possibleAdjectives = firstElementInstance.Adjectives; wordCount++; firstElement = firstElementInstance.Element; } string primaryAttributeNoun = primaryAttribute.GetRandomVariation(GetRandomInt); if ((firstElementInstance != null) && primaryAttributeNoun.Contains(firstElement.SingularName)) { firstElementInstance = null; } string secondaryAttributeNoun = string.Empty; int elementFactor = (firstElementInstance != null) ? 8 : 4; float secondaryAttributeChance = 4f / (elementFactor + possibleAdjectives.Count()); if ((remainingAttributes.Count > 0) && (GetRandomFloat() < secondaryAttributeChance)) { RegionAttribute.Instance secondaryAttribute = remainingAttributes.RandomSelectAndRemove(GetRandomInt); secondaryAttributeNoun = Language.CreateNounAdjunct(secondaryAttribute.GetRandomVariation(GetRandomInt)) + " "; if ((firstElementInstance != null) && secondaryAttributeNoun.Contains(firstElement.SingularName)) { firstElementInstance = null; } if (firstElementInstance == null) { possibleAdjectives = possibleAdjectives.Union(secondaryAttribute.Adjectives); } wordCount++; } string adjective = possibleAdjectives.RandomSelect(GetRandomInt, (int)Mathf.Pow(2, wordCount)); if (!string.IsNullOrEmpty(adjective)) { adjective = "[adj]" + adjective + " "; } string elementNoun = string.Empty; if (firstElementInstance != null) { elementNoun = Language.CreateNounAdjunct(firstElementInstance.SingularName) + " "; } untranslatedName = "[Proper][NP](" + adjective + elementNoun + secondaryAttributeNoun + primaryAttributeNoun + ")"; _name = new Name(untranslatedName, Language, World); }
public string GetRandomUnstranslatedAreaName(GetRandomIntDelegate getRandomInt, bool isNounAdjunct) { string untranslatedName; Element.Instance elementInstance = Elements.RandomSelect(getRandomInt, isNounAdjunct ? 5 : 20); List <RegionAttribute.Instance> remainingAttributes = new List <RegionAttribute.Instance>(AttributeList); RegionAttribute.Instance attribute = remainingAttributes.RandomSelectAndRemove(getRandomInt); List <string> possibleAdjectives = attribute.Adjectives; bool addAttributeNoun = true; int wordCount = 0; if (elementInstance != null) { possibleAdjectives = elementInstance.Adjectives; wordCount++; if (isNounAdjunct && (getRandomInt(10) > 4)) { addAttributeNoun = false; } } string attributeNoun = string.Empty; if (addAttributeNoun) { attributeNoun = attribute.GetRandomVariation(getRandomInt); if ((elementInstance != null) && attributeNoun.Contains(elementInstance.SingularName)) { elementInstance = null; } wordCount++; } int nullAdjectives = 4 * wordCount * (isNounAdjunct ? 4 : 1); string adjective = possibleAdjectives.RandomSelect(getRandomInt, nullAdjectives); if (!string.IsNullOrEmpty(adjective)) { adjective = "[adj]" + adjective + " "; } string elementNoun = string.Empty; if (elementInstance != null) { elementNoun = Language.CreateNounAdjunct(elementInstance.SingularName) + ((addAttributeNoun) ? " " : string.Empty); } untranslatedName = adjective + elementNoun; if (isNounAdjunct) { untranslatedName += (addAttributeNoun) ? Language.CreateNounAdjunct(attributeNoun) : string.Empty; } else { untranslatedName += attributeNoun; } //#if DEBUG // if ((Manager.RegisterDebugEvent != null) && (Manager.TracingData.Priority <= 0)) // { // //if (Manager.TracingData.RegionId == Id) // //{ // SaveLoadTest.DebugMessage debugMessage = new SaveLoadTest.DebugMessage( // "RegionInfo.GetRandomUnstranslatedAreaName - Region.Id:" + Id, // "CurrentDate: " + World.CurrentDate + // ", EstablishmentDate: " + EstablishmentDate + // ", attribute.Name: " + attribute.Name + // ", Attributes.Count: " + Attributes.Count + // ", AttributeNames: [" + string.Join(",", AttributeNames.ToArray()) + "]" + // ", nullAdjectives: " + nullAdjectives + // ", possibleAdjectives: [" + string.Join(",", possibleAdjectives) + "]" + // ", untranslatedName: " + untranslatedName + // ""); // Manager.RegisterDebugEvent("DebugMessage", debugMessage); // //} // } //#endif return(untranslatedName); }
protected override void GenerateName(Faction parentFaction) { int rngOffset = RngOffsets.CLAN_GENERATE_NAME + unchecked ((int)Polity.Id); if (parentFaction != null) { rngOffset += unchecked ((int)parentFaction.Id); } GetRandomIntDelegate getRandomInt = (int maxValue) => Polity.GetNextLocalRandomInt(rngOffset++, maxValue); GetRandomFloatDelegate getRandomFloat = () => Polity.GetNextLocalRandomFloat(rngOffset++); Language language = Polity.Culture.Language; Region region = CoreGroup.Cell.Region; string untranslatedName = ""; if (region.Elements.Count <= 0) { throw new System.Exception("No elements to choose name from"); } List <string> possibleAdjectives = null; List <Element.Instance> remainingElements = new List <Element.Instance>(region.Elements); bool addMoreWords = true; bool isPrimaryNoun = true; float extraWordChance = 0.2f; List <Element.Instance> usedElements = new List <Element.Instance>(); while (addMoreWords) { addMoreWords = false; bool hasRemainingElements = remainingElements.Count > 0; if ((!hasRemainingElements) && (usedElements.Count <= 0)) { throw new System.Exception("No elements to use for name"); } Element.Instance element = null; if (hasRemainingElements) { element = remainingElements.RandomSelectAndRemove(getRandomInt); usedElements.Add(element); } else { element = usedElements.RandomSelect(getRandomInt); } if (isPrimaryNoun) { untranslatedName = element.SingularName; isPrimaryNoun = false; possibleAdjectives = element.Adjectives; } else { bool first = true; foreach (Element.Instance usedElement in usedElements) { if (first) { untranslatedName = usedElement.SingularName; first = false; } else { untranslatedName = usedElement.SingularName + ":" + untranslatedName; } } } string adjective = possibleAdjectives.RandomSelect(getRandomInt, 2 * usedElements.Count); if (!string.IsNullOrEmpty(adjective)) { untranslatedName = "[adj]" + adjective + " " + untranslatedName; } addMoreWords = extraWordChance > getRandomFloat(); if (!addMoreWords) { foreach (Faction faction in Polity.GetFactions()) { if (Language.ClearConstructCharacters(untranslatedName) == faction.Name.Meaning) { addMoreWords = true; break; } } } extraWordChance /= 2f; } untranslatedName = "[Proper][NP](" + untranslatedName + ")"; Info.Name = new Name(untranslatedName, language, World); // #if DEBUG // Debug.Log ("Clan #" + Id + " name: " + Name); // #endif }