Ejemplo n.º 1
0
        protected void WriteTitleOwner(FileInfo titleFile, Character curChars)
        {
            StreamWriter titleWriter = new StreamWriter(titleFile.Open(FileMode.Create, FileAccess.Write),
                                                        Encoding.GetEncoding(1252));

            titleWriter.WriteLine(curChars.Events[0].GetIDString + " = {");

            titleWriter.WriteLine("\tholder = " + curChars.ID.ToString());

            if (curChars.CustomFlags.ContainsKey("laws"))
            {
                LawSet laws = (LawSet)curChars.CustomFlags["laws"];

                titleWriter.WriteLine("\tlaw = " + laws.Succession);
                titleWriter.WriteLine("\tlaw = " + laws.Gender);
                titleWriter.WriteLine("\tlaw = " + laws.CityLevy);
                titleWriter.WriteLine("\tlaw = " + laws.CityTax);
                if (laws.isMuslim)
                {
                    titleWriter.WriteLine("\tlaw = " + laws.IqtaLevy);
                    titleWriter.WriteLine("\tlaw = " + laws.IqtaTax);
                }
                else
                {
                    titleWriter.WriteLine("\tlaw = " + laws.FeudalLevy);
                    titleWriter.WriteLine("\tlaw = " + laws.FeudalTax);
                    titleWriter.WriteLine("\tlaw = " + laws.ChurchLevy);
                    titleWriter.WriteLine("\tlaw = " + laws.ChurchTax);
                }

                if (titleFile.Name.StartsWith("k"))
                {
                    titleWriter.WriteLine("\tlaw = " + laws.CrownAuthority);
                }
            }

            titleWriter.WriteLine("}");

            titleWriter.Close();
        }
Ejemplo n.º 2
0
        protected List <Character> CreateRandomCharacter(CharacterOption charOptions, Dictionary <int, Dynasty> availDynasties, bool outputLaws)
        {
            List <Character> retList = new List <Character>();

            #region This Character
            #region Culture, Religion, Dynasty
            Culture curCul;
            if (charOptions.SpecifiedCulture)
            {
                curCul = charOptions.Culture;
            }
            else
            {
                curCul = charOptions.CultureList.RandomItem(m_options.Random);
            }

            Religion curRel;
            if (charOptions.SpecifiedReligion)
            {
                curRel = charOptions.Religion;
            }
            else
            {
                curRel = charOptions.ReligionList.RandomItem(m_options.Random);
            }

            Dynasty dyn;

            if (charOptions.SpecifiedDynasty)
            {
                dyn = charOptions.Dynasty;
            }
            else
            {
                dyn = m_options.Data.GetDynastyByCulture(availDynasties, curCul, m_options.Random);
                while (dyn == null)
                {
                    if (availDynasties.Count == 0)
                    {
                        availDynasties = new Dictionary <int, Dynasty>(m_options.Data.Dynasties);
                    }

                    dyn = m_options.Data.GetDynastyByCulture(availDynasties,
                                                             m_options.Data.GetRandomCulture(m_options.Random).Value,
                                                             m_options.Random);
                }
                availDynasties.Remove(dyn.ID);
            }

            #endregion

            Character curChar = new Character();
            retList.Add(curChar);


            int age;
            if (!charOptions.IsSpouse)
            {
                age = m_options.Random.Normal(17, 40);
            }
            else
            {
                age = m_options.Random.Normal(charOptions.PartnerAge, 3.0).Clamp(17, 99);
            }

            curChar.CustomFlags["age"] = age;

            int birthYear = m_options.StartDate - 1 - age;
            curChar.Events.Add(GetBirthDeathEvent(birthYear, "birth"));

            int deathYear = m_options.StartDate + m_options.Random.Normal(5, 40);
            curChar.Events.Add(GetBirthDeathEvent(deathYear, "death"));

            curChar.ID       = charOptions.ID != 0 ? charOptions.ID : m_options.CharID++;
            curChar.Culture  = curCul.Name;
            curChar.Religion = curRel.Name;
            curChar.Dynasty  = dyn.ID;

            // Check rule set restrictions.
            if (charOptions.Gender == RuleSet.Gender.Random)
            {
                charOptions.Gender = m_options.RuleSet.GetGender(curCul, curRel);
            }

            if (charOptions.Gender == RuleSet.Gender.Random)
            {
                curChar.IsFemale = (m_options.Random.Next(101) <= m_options.RuleSet.FemaleRulerChance);
            }
            else
            {
                curChar.IsFemale = charOptions.Gender == RuleSet.Gender.Female;
            }

            curChar.Name = curCul.GetRandomName(curChar.IsFemale, m_options.Random);
            #endregion

            #region Spouse

            if (!charOptions.IsSpouse && age > 20 && m_options.Random.Next(0, 101) < m_options.RuleSet.RulerSpouseChance)
            {
                CharacterOption spouseOptions = charOptions;

                spouseOptions.Gender           = curChar.IsFemale ? RuleSet.Gender.Male : RuleSet.Gender.Female;
                spouseOptions.IsSpouse         = true;
                spouseOptions.PartnerAge       = age;
                spouseOptions.SpecifiedDynasty = false;
                spouseOptions.ID = 0;

                List <Character> posSpouse = CreateRandomCharacter(spouseOptions, availDynasties, false);

                curChar.CurrentSpouse      = posSpouse[0];
                posSpouse[0].CurrentSpouse = curChar;

                int youngestAge = (int)curChar.CurrentSpouse.CustomFlags["age"];

                if (age < youngestAge)
                {
                    youngestAge = age;
                }

                int marriageYear = m_options.Random.Next(1, youngestAge - 16);
                int month        = m_options.Random.Next(1, 12);
                int day          = m_options.Random.Next(1, 28);

                EventOption spouseEvent = new EventOption(new DateTime(m_options.StartDate - marriageYear, month, day));
                spouseEvent.SubOptions.Add(new IntegerOption("add_spouse", curChar.ID));
                curChar.CurrentSpouse.Events.Add(spouseEvent);

                EventOption curCharEvent = new EventOption(new DateTime(m_options.StartDate - marriageYear, month, day));
                curCharEvent.SubOptions.Add(new IntegerOption("add_spouse", posSpouse[0].ID));
                curChar.Events.Add(curCharEvent);

                retList.Add(posSpouse[0]);
            }
            #endregion

            #region Law Generation

            if (!charOptions.IsSpouse)
            {
                LawSet laws = m_options.RuleSet.LawRules.GetLawSet(curCul, curRel, m_options.Random);
                if (outputLaws)
                {
                    Log(" --Fetched realm laws: " +
                        "\n      Succession: " + laws.Succession +
                        "\n      Gender: " + laws.Gender +
                        "\n      Crown: " + laws.CrownAuthority +
                        "\n      Feudal Levy: " + laws.FeudalLevy +
                        "\n      Feudal Tax: " + laws.FeudalTax +
                        "\n      City Levy: " + laws.CityLevy +
                        "\n      City Tax: " + laws.CityTax +
                        "\n      Church Levy: " + laws.ChurchLevy +
                        "\n      Church Tax: " + laws.ChurchTax +
                        "\n      Iqta Levy: " + laws.IqtaLevy +
                        "\n      Iqta Tax:" + laws.IqtaTax);
                }
                curChar.CustomFlags["laws"] = laws;
            }
            #endregion

            return(retList);
        }