public override bool CheckConditionKind(Person person)
 {
     return person.BelongedFactionWithPrincess != null && person.GetRelation(person.BelongedFactionWithPrincess.Leader) >= this.number;
 }
Пример #2
0
        public static Person createChildren(Person father, Person mother)
        {
            Person r = new Person();

            //look for empty id
            int id = 5000;
            PersonList pl = father.Scenario.Persons as PersonList;
            pl.SmallToBig = true;
            pl.IsNumber = true;
            pl.PropertyName = "ID";
            pl.ReSort();
            foreach (Person p in pl)
            {
                if (p.ID == id)
                {
                    id++;
                    if (id >= 7000 && id < 10000)
                    {
                        id = 10000;
                    }
                }
                else if (p.ID > id)
                {
                    break;
                }
                /*if (id >= 7000)
                {
                    //no more room!
                    throw new Exception("No more room for children!");
                }*/
            }
            r.ID = id;

            r.Father = father;
            r.Mother = mother;
            r.Generation = father.Generation + 1;
            r.Strain = father.Strain;

            r.Sex = GameObject.Chance(50) ? true : false;

            r.SurName = father.SurName;
            List<String> givenNameList = r.Sex ? Person.readTextList("CreateChildrenTextFile/femalegivenname.txt") : Person.readTextList("CreateChildrenTextFile/malegivenname.txt");
            r.GivenName = givenNameList[GameObject.Random(givenNameList.Count)];
            if (r.GivenName.Length <= 1 && GameObject.Chance(r.Sex ? 90 : 10))
            {
                String s;
                int tries = 0;
                do
                {
                    s = givenNameList[GameObject.Random(givenNameList.Count)];
                    tries++;
                } while (s.Length > 1 && tries < 100);
                r.GivenName += s;
            }
            r.CalledName = "";

            int var = 5; //variance / maximum divert from parent ability
            r.BaseCommand = GameObject.Random(Math.Abs(father.BaseCommand - mother.BaseCommand) + 2 * var + 1) + Math.Min(father.BaseCommand, mother.BaseCommand) - var + father.childrenAbilityIncrease + mother.childrenAbilityIncrease;
            r.BaseStrength = GameObject.Random(Math.Abs(father.BaseStrength - mother.BaseStrength) + 2 * var + 1) + Math.Min(father.BaseStrength, mother.BaseStrength) - var + father.childrenAbilityIncrease + mother.childrenAbilityIncrease;
            r.BaseIntelligence = GameObject.Random(Math.Abs(father.BaseIntelligence - mother.BaseIntelligence) + 2 * var + 1) + Math.Min(father.BaseIntelligence, mother.BaseIntelligence) - var + father.childrenAbilityIncrease + mother.childrenAbilityIncrease;
            r.BasePolitics = GameObject.Random(Math.Abs(father.BasePolitics - mother.BasePolitics) + 2 * var + 1) + Math.Min(father.BasePolitics, mother.BasePolitics) - var + father.childrenAbilityIncrease + mother.childrenAbilityIncrease;
            r.BaseGlamour = GameObject.Random(Math.Abs(father.BaseGlamour - mother.BaseGlamour) + 2 * var + 1) + Math.Min(father.BaseGlamour, mother.BaseGlamour) - var + father.childrenAbilityIncrease + mother.childrenAbilityIncrease;
            if (!GlobalVariables.createChildrenIgnoreLimit)
            {
                if (r.BaseStrength > 100) r.BaseStrength = 100;
                if (r.BaseStrength < 0) r.BaseStrength = 0;
                if (r.BaseCommand > 100) r.BaseCommand = 100;
                if (r.BaseCommand < 0) r.BaseCommand = 0;
                if (r.BaseIntelligence > 100) r.BaseIntelligence = 100;
                if (r.BaseIntelligence < 0) r.BaseIntelligence = 0;
                if (r.BasePolitics > 100) r.BasePolitics = 100;
                if (r.BasePolitics < 0) r.BasePolitics = 0;
                if (r.BaseGlamour > 100) r.BaseGlamour = 100;
                if (r.BaseGlamour < 0) r.BaseGlamour = 0;
            }

            List<int> pictureList;
            if (r.Sex)
            {
                if (r.BaseCommand + r.BaseStrength > r.BaseIntelligence + r.BasePolitics)
                {
                    pictureList = Person.readNumberList("CreateChildrenTextFile/femalefaceM.txt");
                }
                else
                {
                    pictureList = Person.readNumberList("CreateChildrenTextFile/femalefaceA.txt");
                }
            }
            else
            {
                if (r.BaseCommand < 50 && r.BaseStrength < 50 && r.BaseIntelligence < 50 && r.BasePolitics < 50 && r.BaseGlamour < 50)
                {
                    pictureList = Person.readNumberList("CreateChildrenTextFile/malefaceU.txt");
                }
                else if (r.BaseCommand + r.BaseStrength > r.BaseIntelligence + r.BasePolitics)
                {
                    pictureList = Person.readNumberList("CreateChildrenTextFile/malefaceM.txt");
                }
                else
                {
                    pictureList = Person.readNumberList("CreateChildrenTextFile/malefaceA.txt");
                }
            }
            r.PictureIndex = pictureList[GameObject.Random(pictureList.Count)];

            r.YearBorn = father.Scenario.Date.Year;
            r.YearAvailable = father.Scenario.Date.Year;
            r.YearDead = r.YearBorn + GameObject.Random(69) + 30;

            r.Ideal = GameObject.Chance(50) ? father.Ideal + GameObject.Random(10) - 5 : mother.Ideal + GameObject.Random(10) - 5;
            r.Ideal = (r.Ideal + 150) % 150;

            r.Reputation = (int)((father.Reputation + mother.Reputation) * (GameObject.Random(100) / 100.0 * 0.1 + 0.05)) + father.childrenReputationIncrease + mother.childrenReputationIncrease;

            r.PersonalLoyalty = (GameObject.Chance(50) ? father.PersonalLoyalty : mother.PersonalLoyalty) + GameObject.Random(3) - 1;
            if (r.PersonalLoyalty < 0) r.PersonalLoyalty = 0;
            if ((int)r.PersonalLoyalty > Enum.GetNames(typeof(PersonLoyalty)).Length) r.PersonalLoyalty = Enum.GetNames(typeof(PersonLoyalty)).Length;

            r.Ambition = (GameObject.Chance(50) ? father.Ambition : mother.Ambition) + GameObject.Random(3) - 1;
            if (r.Ambition < 0) r.Ambition = 0;
            if ((int)r.Ambition > Enum.GetNames(typeof(PersonAmbition)).Length) r.Ambition = Enum.GetNames(typeof(PersonAmbition)).Length;

            r.Qualification = GameObject.Chance(84) ? (GameObject.Chance(50) ? father.Qualification : mother.Qualification) : (PersonQualification)GameObject.Random(Enum.GetNames(typeof(PersonQualification)).Length);

            r.Braveness = (GameObject.Chance(50) ? father.BaseBraveness : mother.BaseBraveness) + GameObject.Random(5) - 2;
            if (r.BaseBraveness < 1) r.Braveness = 1;
            if (r.BaseBraveness > 10 && !GlobalVariables.createChildrenIgnoreLimit) r.Braveness = 10;

            r.Calmness = (GameObject.Chance(50) ? father.BaseCalmness : mother.BaseCalmness) + GameObject.Random(5) - 2;
            if (r.BaseCalmness < 1) r.Calmness = 1;
            if (r.BaseCalmness > 10 && !GlobalVariables.createChildrenIgnoreLimit) r.Calmness = 10;

            r.ValuationOnGovernment = (GameObject.Chance(50) ? father.ValuationOnGovernment : mother.ValuationOnGovernment);

            r.StrategyTendency = (GameObject.Chance(50) ? father.StrategyTendency : mother.StrategyTendency);

            r.IdealTendency = GameObject.Chance(84) ? (GameObject.Chance(50) ? father.IdealTendency : mother.IdealTendency) : father.Scenario.GameCommonData.AllIdealTendencyKinds.GetRandomList()[0] as IdealTendencyKind;
            if (father.BelongedFaction != null || mother.BelongedFaction != null)
            {
                Person leader = father.BelongedFaction == null ? mother.BelongedFaction.Leader : father.BelongedFaction.Leader;
                if (r.IdealTendency.Offset < Person.GetIdealOffset(r, leader))
                {
                    if (leader.IdealTendency.Offset >= 0)
                    {
                        r.Ideal = leader.Ideal + GameObject.Random(r.IdealTendency.Offset * 2 + 1) - r.IdealTendency.Offset;
                        r.Ideal = (r.Ideal + 150) % 150;
                    }
                    else
                    {
                        r.Ideal = leader.Ideal;
                    }
                }
            }

            Architecture bornArch = mother.BelongedArchitecture != null ? mother.BelongedArchitecture : father.BelongedArchitecture;

            try //best-effort approach for getting PersonBornRegion
            {
                r.BornRegion = (PersonBornRegion)Enum.Parse(typeof(PersonBornRegion), bornArch.LocationState.Name); //mother has no locationarch...
            }
            catch (Exception)
            {
                r.BornRegion = (PersonBornRegion)GameObject.Random(Enum.GetNames(typeof(PersonBornRegion)).Length);
            }

            int characterId = 0;
            do
            {
                characterId = GameObject.Random(father.Scenario.GameCommonData.AllCharacterKinds.Count);
            } while (characterId == 0);
            r.Character = GameObject.Chance(84) ? (GameObject.Chance(50) ? father.Character : mother.Character) : father.Scenario.GameCommonData.AllCharacterKinds[characterId];

            foreach (Skill i in father.Skills.GetSkillList())
            {
                if (GameObject.Chance(50 + father.childrenSkillChanceIncrease) && i.CanBeBorn(r))
                {
                    r.Skills.AddSkill(i);
                }
            }
            foreach (Skill i in mother.Skills.GetSkillList())
            {
                if (GameObject.Chance(50 + mother.childrenSkillChanceIncrease) && i.CanBeBorn(r))
                {
                    r.Skills.AddSkill(i);
                }
            }
            foreach (Skill i in father.Scenario.GameCommonData.AllSkills.GetSkillList())
            {
                if (((GameObject.Random(father.Scenario.GameCommonData.AllSkills.GetSkillList().Count / 2) == 0 && GameObject.Random(i.Level * i.Level / 2 + i.Level) == 0)
                    ||
                    GameObject.Chance(father.childrenSkillChanceIncrease + mother.childrenSkillChanceIncrease)) && i.CanBeBorn(r))
                {
                    r.Skills.AddSkill(i);
                }
            }

            foreach (Stunt i in father.Stunts.GetStuntList())
            {
                if (GameObject.Chance(50 + father.childrenStuntChanceIncrease) && i.CanBeBorn(r))
                {
                    r.Stunts.AddStunt(i);
                }
            }
            foreach (Stunt i in mother.Stunts.GetStuntList())
            {
                if (GameObject.Chance(50 + mother.childrenStuntChanceIncrease) && i.CanBeBorn(r))
                {
                    r.Stunts.AddStunt(i);
                }
            }
            foreach (Stunt i in father.Scenario.GameCommonData.AllStunts.GetStuntList())
            {
                if ((GameObject.Random(father.Scenario.GameCommonData.AllStunts.GetStuntList().Count * 2) == 0 ||
                    GameObject.Chance(father.childrenStuntChanceIncrease + mother.childrenStuntChanceIncrease)) && i.CanBeBorn(r))
                {
                    bool ok = true;
                    foreach (Condition j in i.LearnConditions.Conditions.Values)
                    {
                        if (j.Kind.ID == 600 || j.Kind.ID == 610) //check personality kind only
                        {
                            if (!j.CheckCondition(r))
                            {
                                ok = false;
                                break;
                            }
                        }
                    }
                    if (ok)
                    {
                        r.Stunts.AddStunt(i);
                    }
                }
            }

            GameObjectList rawTitles = father.Scenario.GameCommonData.AllTitles.GetTitleList().GetRandomList();
            Dictionary<TitleKind, List<Title>> titles = new Dictionary<TitleKind, List<Title>>();
            foreach (Title t in rawTitles)
            {
                if (!titles.ContainsKey(t.Kind))
                {
                    titles[t.Kind] = new List<Title>();
                }
                titles[t.Kind].Add(t);
            }
            foreach (KeyValuePair<TitleKind, List<Title>> i in titles)
            {
                Title ft = father.getTitleOfKind(i.Key);
                Title mt = mother.getTitleOfKind(i.Key);
                int levelTendency = (((ft == null ? 0 : ft.Level) + (mt == null ? 0 : mt.Level)) / 2)
                    + father.childrenTitleChanceIncrease + mother.childrenTitleChanceIncrease;

                if (GameObject.Chance(20) && ft != null && ft.CanBeBorn(r))
                {
                    r.RealTitles.Add(ft);
                }
                else if (GameObject.Chance(25) && mt != null && mt.CanBeBorn(r)) //20% of remaining 80% = 25%
                {
                    r.RealTitles.Add(mt);
                }
                else
                {
                    int targetLevel = levelTendency + GameObject.Random(3) - 1;
                    if (targetLevel <= 0) continue;

                    List<Title> candidates = new List<Title>();
                    List<Title> lesserCandidates = new List<Title>();
                    List<Title> leastCandidates = new List<Title>();

                    foreach (Title t in i.Value)
                    {
                        if (t.Level == targetLevel && t.CanBeBorn(r))
                        {
                            candidates.Add(t);
                        }
                        else if ((t.Level + 1 == targetLevel || t.Level - 1 == targetLevel) && t.CanBeBorn(r))
                        {
                            lesserCandidates.Add(t);
                        }
                        else if (t.Level < targetLevel && t.CanBeBorn(r))
                        {
                            leastCandidates.Add(t);
                        }
                    }

                    if (candidates.Count > 0)
                    {
                        r.RealTitles.Add(candidates[GameObject.Random(candidates.Count)]);
                    }
                    else if (lesserCandidates.Count > 0)
                    {
                        r.RealTitles.Add(lesserCandidates[GameObject.Random(lesserCandidates.Count)]);
                    }
                    else if (leastCandidates.Count > 0)
                    {
                        r.RealTitles.Add(leastCandidates[GameObject.Random(lesserCandidates.Count)]);
                    }
                }
            }

            String biography = "";
            int fatherChildCount = father.NumberOfChildren;
            int motherChildCount = mother.NumberOfChildren;
            String[] order = new String[] { "长", "次", "三", "四", "五", "六", "七", "八" };
            biography += r.Father.Name + "之" + (fatherChildCount > 7 ? "" : order[fatherChildCount]) + (r.Sex ? "女" : "子") + "," +
                r.Mother.Name + "之" + (motherChildCount > 7 ? "" : order[motherChildCount]) + (r.Sex ? "女" : "子") + "。" +
                "在" + r.father.Scenario.Date.Year + "年" + r.Father.Scenario.Date.Month + "月於" + bornArch.Name + "出生。";

            List<String> adjectives = new List<String>();
            List<String> suffixes = new List<String>();
            int strength, command, intelligence, politics, glamour, braveness, calmness, personalLoyalty, ambition;
            strength = command = intelligence = politics = glamour = braveness = calmness = personalLoyalty = ambition = 0;
            foreach (BiographyAdjectives b in father.Scenario.GameCommonData.AllBiographyAdjectives)
            {
                if (b.Male && r.Sex)
                {
                    continue;
                }
                if (b.Female && !r.Sex)
                {
                    continue;
                }

                if ((b.Strength == 0 || (b.Strength > strength && r.BaseStrength >= b.Strength)) &&
                    (b.Command == 0 || (b.Command > command && r.BaseCommand >= b.Command)) &&
                    (b.Intelligence == 0 || (b.Intelligence > intelligence && r.BaseIntelligence >= b.Intelligence)) &&
                    (b.Politics == 0 || (b.Politics > politics && r.BasePolitics >= b.Politics)) &&
                    (b.Glamour == 0 || (b.Glamour > glamour && r.BaseGlamour >= b.Glamour)) &&
                    (b.Braveness == 0 || (b.Braveness > braveness && r.BaseBraveness >= b.Braveness)) &&
                    (b.Calmness == 0 || (b.Calmness > calmness && r.BaseCalmness >= b.Calmness)) &&
                    (b.PersonalLoyalty == 0 || (b.PersonalLoyalty > personalLoyalty && r.PersonalLoyalty >= b.PersonalLoyalty)) &&
                    (b.Ambition == 0 || (b.Ambition > ambition && r.Ambition >= b.Ambition))
                    )
                {
                    strength = b.Strength;
                    command = b.Command;
                    intelligence = b.Intelligence;
                    politics = b.Politics;
                    glamour = b.Glamour;
                    braveness = b.Braveness;
                    calmness = b.Calmness;
                    personalLoyalty = b.PersonalLoyalty;
                    ambition = b.Ambition;

                    if (b.Text.Count > 0)
                    {
                        adjectives.Add(b.Text[GameObject.Random(b.Text.Count)]);
                    }
                    if (b.SuffixText.Count > 0)
                    {
                        suffixes.Add(b.SuffixText[GameObject.Random(b.SuffixText.Count)]);
                    }
                }
            }
            if (adjectives.Count > 0)
            {
                foreach (String s in adjectives)
                {
                    biography += s + ",";
                }
                biography = biography.Substring(0, biography.Length - 1);
                if (adjectives.Count > 0)
                {
                    biography += "的" + (suffixes.Count > 0 ? suffixes[GameObject.Random(suffixes.Count)] : "將領");
                }
                biography += "。";
            }

            Biography bio = new Biography();
            bio.Brief = biography;
            bio.ID = r.ID;
            Biography fatherBio = father.Scenario.GameCommonData.AllBiographies.GetBiography(father.ID);
            if (fatherBio != null)
            {
                bio.FactionColor = fatherBio.FactionColor;
                bio.MilitaryKinds = fatherBio.MilitaryKinds;
            }
            else
            {
                bio.FactionColor = 52;
                bio.MilitaryKinds.AddBasicMilitaryKinds(father.Scenario);
            }
            father.Scenario.GameCommonData.AllBiographies.AddBiography(bio);
            r.PersonBiography = bio;

            /*r.LocationArchitecture = father.BelongedArchitecture; //mother has no location arch!
            r.BelongedFaction = r.BelongedArchitecture.BelongedFaction;
            r.Available = true;*/
            r.Alive = true;

            father.Scenario.Persons.Add(r);

            r.Scenario = father.Scenario;

            foreach (Person p in father.Scenario.Persons)
            {
                int fatherRel = father.GetRelation(p);
                int motherRel = mother.GetRelation(p);

                if (fatherRel != 0 && motherRel != 0)
                {
                    int rel = GameObject.Random(Math.Abs(fatherRel - motherRel)) + Math.Min(fatherRel, motherRel);
                    p.SetRelation(p, rel);
                }
            }

            foreach (Person p in father.GetClosePersons())
            {
                if (!GameObject.Chance((int)r.personalLoyalty * 25))
                {
                    r.AddClose(p);
                }
            }
            foreach (Person p in father.GetClosePersons())
            {
                if (!GameObject.Chance((int)r.personalLoyalty * 25))
                {
                    r.AddClose(p);
                }
            }

            foreach (Person p in father.GetHatedPersons())
            {
                if (!GameObject.Chance((int)r.personalLoyalty * 25))
                {
                    r.AddHated(p);
                }
            }
            foreach (Person p in father.GetHatedPersons())
            {
                if (!GameObject.Chance((int)r.personalLoyalty * 25))
                {
                    r.AddHated(p);
                }
            }

            ExtensionInterface.call("CreateChildren", new Object[] { father.Scenario, r });

            return r;
        }