Exemplo n.º 1
0
        public void FindAdjacent(List<ProvinceParser> provinces, int c, CharacterParser head)
        {
            List<ProvinceParser> choices = new List<ProvinceParser>();
            foreach (var provinceParser in provinces)
            {
                foreach (var parser in provinceParser.Adjacent)
                {
                    var t = parser.Title;
                    if (!provinces.Contains(parser) && (head == null || (head == t.Holder || (head.PrimaryTitle.Rank == 2 && parser.Title.TopmostTitle == head.PrimaryTitle.TopmostTitle)) && (parser.Title.Liege == null || parser.Title.Rank == 2)))
                        choices.Add(parser);

                }
            }
            for (int i = 0; i < c; i++)
            {
                if (choices.Count > 0)
                {
                    int cc = Rand.Next(choices.Count);

                    provinces.Add(choices[cc]);
                    choices.RemoveAt(cc);
                }
            }
        }
Exemplo n.º 2
0
 public void RemoveCharacter(CharacterParser characterParser)
 {
     Characters.Remove(characterParser);
     CharacterMap.Remove(characterParser.ID);
     CharactersScript.Root.Remove(characterParser.Scope);
 }
Exemplo n.º 3
0
        public CharacterParser CreateNewHistoricCharacter(Dynasty dynasty, bool bFemale, string religion, String culture, int dateOfBirth, int dateOfDeath = -1, bool adult = true)
        {
            if (!bInit)
                Init();

            //   var scope = new ScriptScope();
            //  scope.Name = CharacterParser.IDMax.ToString();
            //  scope.SetChild(CharactersScript.Root);
            var chr = new CharacterParser();
            //   chr.SetProperty("dynasty", Rand.Next(1235)+1);
            //    chr.SetProperty("culture", new ScriptReference("norse"));
            //     chr.SetProperty("religion", new ScriptReference("pagan"));
            //  chr.DeleteProperty("name");
            Characters.Add(chr);
            chr.YearOfBirth = dateOfBirth;
            chr.isFemale = bFemale;
            chr.culture = culture;
            chr.religion = religion;
            if (dateOfDeath != -1)
            {
                chr.YearOfDeath = dateOfDeath;
            }
            else
            {
                chr.YearOfDeath = dateOfBirth + Rand.Next(40);
                if(Rand.Next(4)==0)
                    chr.YearOfDeath = dateOfBirth + Rand.Next(80);
                
                if (adult)
                    chr.YearOfDeath = dateOfBirth + 16 + Rand.Next(80 - 16);
  
            }
           
            this.CharactersScript.Root.SetChild(chr.Scope);
            AddedSinceLastPrune.Add(chr);
            CharacterMap[chr.ID] = chr;
            chr.Dynasty = dynasty;
            chr.SetupExistingDynasty();
            chr.UpdateCultural();
        //    CharacterManager.instance.SetAllDates(chr.YearOfBirth, chr.YearOfDeath,  chr.Scope);
            return chr;
        }
Exemplo n.º 4
0
        public CharacterParser CreateNewCharacter(String culture, String religion, bool bFemale)
        {
            if (!bInit)
                Init();

            //   var scope = new ScriptScope();
            //  scope.Name = CharacterParser.IDMax.ToString();
            //  scope.SetChild(CharactersScript.Root);
            var chr = new CharacterParser();
            //   chr.SetProperty("dynasty", Rand.Next(1235)+1);
            //    chr.SetProperty("culture", new ScriptReference("norse"));
            //     chr.SetProperty("religion", new ScriptReference("pagan"));
            //  chr.DeleteProperty("name");
            Characters.Add(chr);
            chr.YearOfBirth = 769 - Rand.Next(60);
            chr.Dynasty = DynastyManager.instance.GetDynasty(CultureManager.instance.CultureMap[culture]);
            chr.religion = religion;
            chr.isFemale = bFemale;
            chr.culture = culture;
            chr.YearOfDeath = 769 + Rand.Next(30);
            this.CharactersScript.Root.SetChild(chr.Scope);
            AddedSinceLastPrune.Add(chr);
            CharacterMap[chr.ID] = chr;
            chr.SetupExistingDynasty();
            chr.UpdateCultural();
            return chr;
        }
Exemplo n.º 5
0
  public CharacterParser GetNewCharacter(bool adult = false)
  {
      if (!bInit)
          Init();
      
   //   var scope = new ScriptScope();
    //  scope.Name = CharacterParser.IDMax.ToString();
    //  scope.SetChild(CharactersScript.Root);
      var chr = new CharacterParser();
      
      //   chr.SetProperty("dynasty", Rand.Next(1235)+1);
  //    chr.SetProperty("culture", new ScriptReference("norse"));
 //     chr.SetProperty("religion", new ScriptReference("pagan"));
      //  chr.DeleteProperty("name");
      Characters.Add(chr);
      this.CharactersScript.Root.SetChild(chr.Scope);
      AddedSinceLastPrune.Add(chr);
      CharacterMap[chr.ID] = chr;
      return chr;
  }
Exemplo n.º 6
0
        public List<ProvinceParser> GetProvinceGroupSameRealm(int i, CharacterParser chr)
        {
            List<ProvinceParser> list = new List<ProvinceParser>();
            List<ProvinceParser> list2 = new List<ProvinceParser>();
            foreach (var titleParser in Titles)
            {
                titleParser.GetAllProvinces(list);
            }

            foreach (var provinceParser in list)
            {
                //      if ((provinceParser.Title.SameRealm(chr.PrimaryTitle)))
                {
                    list2.Add(provinceParser);

                }
            }
            if (list2.Count == 0)
                return list2;
            ProvinceParser p = null;
            p = list2[Rand.Next(list2.Count)];

            List<ProvinceParser> provinces = new List<ProvinceParser>();
            provinces.Add(p);

            int last = provinces.Count;

            do
            {
                last = provinces.Count;
                MapManager.instance.FindAdjacentSameRealm(provinces, i - provinces.Count, chr);

            }
            while (last != provinces.Count && provinces.Count < i);

            return provinces;
        }
Exemplo n.º 7
0
        public List<ProvinceParser> GetProvinceGroup(int i, CharacterParser chr)
        {
            List<ProvinceParser> list = new List<ProvinceParser>();
            List<ProvinceParser> list2 = new List<ProvinceParser>();
            foreach (var titleParser in Titles)
            {
                titleParser.GetAllProvinces(list);
            }

            foreach (var provinceParser in list)
            {
                if (!provinceParser.land)
                    continue;
                if (provinceParser.title == null)
                    continue;

                if (!(provinceParser.Title.Liege == null && (chr == provinceParser.Title.Holder || chr == null)))
                {
                    list2.Add(provinceParser);

                }
            }
            if (list2.Count == 0)
                return list2;
            ProvinceParser p = null;
            p = list2[Rand.Next(list2.Count)];

            List<ProvinceParser> provinces = new List<ProvinceParser>();
            provinces.Add(p);

            int last = provinces.Count;

            do
            {
                last = provinces.Count;
                MapManager.instance.FindAdjacent(provinces, i - provinces.Count, chr);

            }
            while (last != provinces.Count && provinces.Count < i);

            return provinces;
        }
Exemplo n.º 8
0
        public CharacterParser CreateKidWith(CharacterParser otherParent, int dateOfBirth)
        {
            var kid = CharacterManager.instance.CreateNewHistoricCharacter(Dynasty, Rand.Next(2) == 0, religion, culture, dateOfBirth, -1, false);
            if (!isFemale)
            {
                kid.Father = this;
                kid.Mother = otherParent;
            }
            else
            {
                kid.Mother = this;
                kid.Father = otherParent;
            }
          
            kid.SetupExistingDynasty();
            Kids.Add(kid);
            otherParent.Kids.Add(kid);

            return kid;
        }
Exemplo n.º 9
0
        public void CreateFamily(int depth = 0, int maxdepth = 4, int minYearForHeirs = -1)
        {
     

            if (depth > maxdepth)
                return;

            int deathdate = -1;
            if (depth == 0)
            {
                deathdate = 768 - 1;
            }
            if (deathdate <= YearOfBirth)
                deathdate = YearOfBirth + 1;

            Father = CharacterManager.instance.CreateNewHistoricCharacter(Dynasty, false, religion, culture, this.YearOfBirth - (16 + Rand.Next(30)), deathdate);
            int max = YearOfBirth - 19;
            int min = Father.YearOfBirth - 5;

            Mother = GetSuitableMotherForChild(religion, culture, min, max, YearOfBirth);
            if (Mother.ID == 1002182)
            {

            }
            Father.Spouses.Add(Mother);
            Mother.Spouses.Add(Father);
            if (Age > 16 && Spouses.Count < Religion.max_wives && !isFemale)
            {
                int numWives = 1;
                if (Age > 30)
                {
                    numWives++;
                }
                if (Age > 40)
                {
                    numWives++;
                }

                numWives = 1;
                min = YearOfBirth - 3;
                max = YearOfBirth + 16;
                max = DateFunctions.MakeDOBAtLeastAdult(max);
                numWives = Math.Min(numWives, Religion.max_wives - Spouses.Count);

                int dateWhenSixteen = YearOfBirth + 16;
                int startAdulthood = dateWhenSixteen;
                if (minYearForHeirs > startAdulthood)
                    startAdulthood = minYearForHeirs;

            }

            if (Father.YearOfDeath < YearOfBirth)
                Father.YearOfDeath = YearOfBirth + 1;
            if (Mother.YearOfDeath < YearOfBirth)
                Mother.YearOfDeath = YearOfBirth + 1;

            Father.CreateFamily(depth + 1, maxdepth);
            Father.Kids.Add(this);
            Mother.Kids.Add(this);
            if (depth < 4)
                Mother.CreateFamily(depth + 1, maxdepth);

            Father.UpdateCultural();
            Mother.UpdateCultural();
            //  Father.SetupExistingDynasty();
            //   Mother.SetupExistingDynasty();
        }
Exemplo n.º 10
0
        public void FindAdjacentSameRealm(List<ProvinceParser> provinces, int c, CharacterParser head)
        {
            List<ProvinceParser> choices = new List<ProvinceParser>();
            foreach (var provinceParser in provinces)
            {
                foreach (var parser in provinceParser.Adjacent)
                {
                    if (!parser.land)
                        continue;
                    if (parser.title == null)
                        continue;

                    var t = parser.Title;
                    if (!provinces.Contains(parser) && (head == parser.Title.Holder || parser.Title.Holder == null || (parser.Title.Liege != null && head == parser.TotalLeader)))
                        choices.Add(parser);

                }
            }
            for (int i = 0; i < c; i++)
            {
                if (choices.Count > 0)
                {
                    int cc = Rand.Next(choices.Count);

                    provinces.Add(choices[cc]);
                    choices.RemoveAt(cc);
                }
            }
        }
Exemplo n.º 11
0
        public TitleParser CreateEmpireScriptScope(ProvinceParser capital, CharacterParser chr)
        {
            var rand = Rand.Get();
            Color col = Color.FromArgb(255, rand.Next(200) + 55, rand.Next(200) + 55, rand.Next(200) + 55);
            ScriptScope scope = new ScriptScope();
            scope.Parent = LandedTitlesScript.Root;



            {
                String place = chr.Culture.dna.GetPlaceName();
                String text = place;
                place = StarNames.SafeName(place);
                LanguageManager.instance.Add(place, text);
                scope.Name = "e_" + place;
                LanguageManager.instance.Add(scope.Name, text);
            }


            //scope.Kids.Add(new ScriptCommand() { Name = "rebel", Value = false });
            scope.Add(new ScriptCommand() { Name = "color", Value = col });
            scope.Add(new ScriptCommand() { Name = "color2", Value = col });

            scope.Add(new ScriptCommand() { Name = "capital", Value = capital.id });

            TitleParser title = new TitleParser(scope);
            AddTitle(title);

            // now place the counties into it...
            if (title.capital != 0)
                title.CapitalProvince = MapManager.instance.ProvinceIDMap[title.capital];

            return title;
        }
Exemplo n.º 12
0
        private void HandleRevolt(CharacterParser character)
        {
            if (character.NumberofCountTitles > 0)
            {
                foreach (var titleParser in character.Titles)
                {
                    if (titleParser.Owns.Count > 0)
                    {
                        if (
                            !ReligionManager.instance.ReligionMap[character.religion].Believers.Contains(
                                titleParser.CapitalProvince))
                        {
                            ReligionManager.instance.ReligionMap[character.religion].Believers.Add(titleParser.CapitalProvince);
                        }
                    }
                }
            }    
            var pr = new List<ProvinceParser>();

            foreach (var title in character.Titles)
            {
                title.AddChildProvinces(pr);
                if (title.Owns.Count > 0)
                {
                    bool bDo = false;
                    foreach (var provinceParser in title.Owns[0].Adjacent)
                    {
                        if (provinceParser.land && (provinceParser.title == null || provinceParser.Title.Holder == null))
                        {
                            bDo = true;
                            break;
                        }
                    }
                    if(bDo)
                        pr.Add(title.Owns[0]);
                }
            }

            pr.Remove(character.PrimaryTitle.CapitalProvince);
            for (int index = 0; index < pr.Count; index++)
            {
                var provinceParser = pr[index];
                bool keep = false;
                foreach (var parser in provinceParser.Adjacent)
                {
                    if(parser.title == null)
                        continue;
                    ;
                    if (parser.Title.Holder == null)
                    {
                        keep = true;
                        break;
                    }
                }
                if (!keep)
                {
                    pr.Remove(provinceParser);
                    index--;
                }
              
            }
            if (pr.Count == 0)
                return;

            var p = pr[Rand.Next(pr.Count)];
            List<ProvinceParser> provinces = new List<ProvinceParser>();
            provinces.Add(p);
            while (provinces.Count < character.Titles.Count / 2)
            {
                MapManager.instance.FindAdjacent(provinces, provinces.Count/2);
            }
            var ch = CharacterManager.instance.GetNewCharacter();
            characters.Add(ch);
            foreach (var provinceParser in provinces)
            {
                if(provinceParser.title != null)
                    ch.GiveTitle(TitleManager.instance.TitleMap[provinceParser.title]);
            }

            int nn = Globals.OneInChanceOfReligionSplinter;
            if (ReligionManager.instance.ReligionMap[character.religion].Believers.Count > 100)
                nn--;
            if (ReligionManager.instance.ReligionMap[character.religion].Believers.Count > 300)
                nn--;
            if (character.religion == "pagan")
                nn = 0;
            else
                nn += ReligionManager.instance.ReligionMap[character.religion].Resilience;


         
            if (Rand.Next(nn) == 0)
            {
                ReligionParser r = ReligionManager.instance.BranchReligion(character.religion, pr[Rand.Next(pr.Count)]);
                ch.religion = r.Name;
            }
            if (Rand.Next(Globals.OneInChanceOfCultureSplinter) == 0)
            {
                ch.culture = CultureManager.instance.BranchCulture(character.culture).Name;
                if (character.PrimaryTitle.Government != null)
                {
                    ch.PrimaryTitle.Government = GovernmentManager.instance.BranchGovernment(character.PrimaryTitle.Government, ch.Culture);
                    if (ch.PrimaryTitle.Government.uses_decadence)
                        ch.Religion.uses_decadence = true;
                }
            }
        }