Exemplo n.º 1
0
    private static string GenerateSyllable(
        Letter[] onsetLetters,
        float onsetChance,
        Letter[] nucleusLetters,
        float nucleusChance,
        Letter[] codaLetters,
        float codaChance,
        GetRandomFloatDelegate getRandomFloat)
    {
        string onset   = (onsetChance > getRandomFloat()) ? CollectionUtility.WeightedSelection(onsetLetters, GetLettersTotalWeight(onsetLetters), getRandomFloat()) : string.Empty;
        string nucleus = (nucleusChance > getRandomFloat()) ? CollectionUtility.WeightedSelection(nucleusLetters, GetLettersTotalWeight(nucleusLetters), getRandomFloat()) : string.Empty;
        string coda    = (codaChance > getRandomFloat()) ? CollectionUtility.WeightedSelection(codaLetters, GetLettersTotalWeight(codaLetters), getRandomFloat()) : string.Empty;

        if (nucleus == string.Empty)
        {
            return(coda);
        }

        return(onset + nucleus + coda);
    }
Exemplo n.º 2
0
    public string GetRandomSyllable(GetRandomFloatDelegate getRandomFloat)
    {
        float randValue = getRandomFloat();

        randValue *= randValue; // Emulate a Zipf's Distribution
        int randOption = (int)Mathf.Floor(MaxNumberOfSyllables * randValue);

        if (_syllables.ContainsKey(randOption))
        {
            return(_syllables[randOption]);
        }
        else
        {
            string syllable = GenerateSyllable(OnsetLetters, OnsetChance, NucleusLetters, NucleusChance, CodaLetters, CodaChance, getRandomFloat);

            _syllables.Add(randOption, syllable);

            return(syllable);
        }
    }
    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
    }