public void AddAttribute(RegionAttribute.Instance attribute)
    {
#if DEBUG
        AttributeNames.Add(attribute.Name);
#endif

        Attributes.Add(attribute.Id, attribute);
        AttributeList.Add(attribute);
    }
Exemplo n.º 2
0
    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();
    }
Exemplo n.º 3
0
    private void GenerateNameFromRegionAttribute(RegionAttribute.Instance attribute, GetRandomIntDelegate getRandomInt)
    {
        string untranslatedName;

        string adjective = attribute.Adjectives.RandomSelect(getRandomInt, 15);

        if (!string.IsNullOrEmpty(adjective))
        {
            adjective = "[adj]" + adjective + " ";
        }

        Association association = attribute.Associations.RandomSelect(getRandomInt);

        string nounGender = (IsFemale) ? "[fn]" : "[mn]";

        string subjectNoun = "[name]" + nounGender + association.Noun;

        if (association.IsAdjunction)
        {
            string variationNoun = attribute.GetRandomSingularVariation(getRandomInt, false);

            untranslatedName = "[Proper][NP](" + adjective + Language.CreateNounAdjunct(variationNoun) + " " + 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 variationNoun;

            if ((association.Form == AssociationForms.DefinitePlural) ||
                (association.Form == AssociationForms.IndefinitePlural))
            {
                variationNoun = attribute.GetRandomPluralVariation(getRandomInt, false);
            }
            else
            {
                variationNoun = attribute.GetRandomSingularVariation(getRandomInt, false);
            }

            variationNoun = article + adjective + uncountableProp + variationNoun;

            untranslatedName = "[PpPP]([Proper][NP](" + subjectNoun + ") [PP](" + association.Relation + " [Proper][NP](" + variationNoun + ")))";
        }

        _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);
    }