Esempio n. 1
0
        public TitleParser CreateBaronyScriptScope(ProvinceParser capital, CultureParser culture)
        {
            var place = culture.dna.GetPlaceName();
            var text  = place;

            place = StarNames.SafeName(text);
            if (TitleManager.instance.TieredTitles.ContainsKey("b_" + place))
            {
                return(CreateBaronyScriptScope(capital, culture));
            }
            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 = capital.Title.Scope;


            scope.Name = "b_" + place;
            LanguageManager.instance.Add("b_" + place, text);
            //  scope.Kids.Add(new ScriptCommand() { Name = "rebel", Value = false });

            TitleParser title = new TitleParser(scope);

            TieredTitles[title.Name] = title;
            capital.Title.Scope.Add(title.Scope);

            //          if (culture.dna.horde)
//                title.Scope.Do("historical_nomad = yes");
            //   AddTitle(title);

            return(title);
        }
Esempio n. 2
0
        public void RemoveProvince(ProvinceParser provinceParser)
        {
            Group.RemoveProvince(provinceParser);

            Provinces.Remove(provinceParser);
            dirty = true;
        }
Esempio n. 3
0
        public ReligionParser BranchReligion(string religion, ProvinceParser capital = null)
        {
            var rel   = this.ReligionMap[religion];
            var group = rel.Group;

            if (rel.Group.Religions.Count > 3 && Rand.Next(2) == 0)
            {
                String name = StarNames.Generate(capital.Title.culture);
                String safe = StarNames.SafeName(name);
                LanguageManager.instance.Add(safe, name);
                group = AddReligionGroup(safe);
                var rel2 = group.AddReligion(StarNames.Generate(capital.Title.culture));
                rel2.RandomReligionProperties();
                //rel2.Init(Rand.Next(255), Rand.Next(255), Rand.Next(255));
                rel2.CreateRandomReligion(group);
                return(rel2);
            }
            else
            {
                var rel2 = group.AddReligion(StarNames.Generate(capital.Title.culture));
                //rel2.Init(Rand.Next(255), Rand.Next(255), Rand.Next(255));
                rel2.RandomReligionProperties();
                rel2.CreateRandomReligion(group);
                rel2.Mutate(rel, capital.Title.Culture, 6);
                return(rel2);
            }
        }
Esempio n. 4
0
        public ReligionParser BranchReligion(string religion, ProvinceParser capital = null)
        {
            var rel = this.ReligionMap[religion];
            var group = rel.Group;

            if (rel.Group.Religions.Count > 3 && Rand.Next(2)==0)
            {
                String name = StarNames.Generate(capital.Title.culture);
                String safe = StarNames.SafeName(name);
                LanguageManager.instance.Add(safe, name);
                group = AddReligionGroup(safe);
                var rel2 = group.AddReligion(StarNames.Generate(capital.Title.culture));
                rel2.RandomReligionProperties();
                //rel2.Init(Rand.Next(255), Rand.Next(255), Rand.Next(255));
                rel2.CreateRandomReligion(group);
                return rel2;
            }
            else
            {
                var rel2 = group.AddReligion(StarNames.Generate(capital.Title.culture));
                //rel2.Init(Rand.Next(255), Rand.Next(255), Rand.Next(255));
                rel2.RandomReligionProperties();
                rel2.CreateRandomReligion(group);
                rel2.Mutate(rel, capital.Title.Culture, 6);
                return rel2;
            }
         
        }
Esempio n. 5
0
 public void SetCapital(ProvinceParser cap)
 {
     Scope.Add(new ScriptCommand()
     {
         Name = "capital", Value = cap.id
     });
 }
Esempio n. 6
0
 public void AddProvince(ProvinceParser provinceParser)
 {
     if (!Provinces.Contains(provinceParser))
     {
         Provinces.Add(provinceParser);
     }
 }
Esempio n. 7
0
        public float DistanceTo(ProvinceParser other)
        {
            var   x = other;
            var   p = this.Points[0];
            float a = p.X - x.Points[0].X;
            float b = p.Y - x.Points[0].Y;

            return(Math.Abs(a) + Math.Abs(b));
        }
Esempio n. 8
0
 public void AddAdjacent(ProvinceParser prov)
 {
     if (!Adjacent.Contains(prov))
     {
         Adjacent.Add(prov);
     }
     if (!prov.Adjacent.Contains(this))
     {
         prov.Adjacent.Add(this);
     }
 }
Esempio n. 9
0
        public TitleParser CreateKingScriptScope(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);

                if (TitleManager.instance.TitleMap.ContainsKey("k_" + place))
                {
                    return(CreateKingScriptScope(capital, chr.culture));
                }

                LanguageManager.instance.Add(place, text);
                scope.Name = "k_" + 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);
        }
Esempio n. 10
0
        public TitleParser CreateDukeScriptScope(ProvinceParser capital, String name = null)
        {
            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;

            if (name == null)
            {
                String place = capital.Title.Holder.Culture.dna.GetPlaceName();
                String text  = place;
                place = StarNames.SafeName(place);
                LanguageManager.instance.Add(place, text);
                scope.Name = "d_" + place;
                LanguageManager.instance.Add(scope.Name, text);
            }
            else
            {
                scope.Name = "d_" + name;
            }

            //  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);

            //          if (capital.Title.Culture.dna.horde)
//                title.Scope.Do("historical_nomad = yes");

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

            return(title);
        }
Esempio n. 11
0
        public void AddProvince(ProvinceParser provinceParser)
        {
            if (provinceParser.Religion != null)
            {
                provinceParser.Religion.RemoveProvince(provinceParser);
            }

            if (!Provinces.Contains(provinceParser))
            {
                Provinces.Add(provinceParser);
            }

            Group.AddProvince(provinceParser);
            dirty = true;
        }
Esempio n. 12
0
        private int SortByDistance(ProvinceParser x, ProvinceParser y)
        {
            float dist  = x.DistanceTo(distanceTest);
            float dist2 = y.DistanceTo(distanceTest);

            if (dist < dist2)
            {
                return(-1);
            }
            if (dist > dist2)
            {
                return(1);
            }

            return(0);
        }
Esempio n. 13
0
        public TitleParser CreateKingScriptScope(ProvinceParser capital, String name = null)
        {
            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;


            if (name == null)
            {
                scope.Name = "k_" + capital.Title.Name.Substring(2);
            }
            else
            {
                scope.Name = "k_" + name;
            }


            //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);
        }
Esempio n. 14
0
        public void AddProvince(ProvinceParser provinceParser)
        {
            if (provinceParser.Culture != null)
            {
                provinceParser.Culture.RemoveProvince(provinceParser);
            }
            if (!Group.Provinces.Contains(provinceParser))
            {
                Group.AddProvince(provinceParser);
            }

            if (!Provinces.Contains(provinceParser))
            {
                Provinces.Add(provinceParser);
            }

            dirty = true;
        }
Esempio n. 15
0
        public void DoLeader(ProvinceParser capital)
        {
            String popeName = StarNames.SafeName(StarNames.Generate(10000000));

            LanguageManager.instance.Add(popeName, StarNames.Generate(10000000));

            TitleParser title = null;

            switch (Rand.Next(3))
            {
                case 0:
                   title = TitleManager.instance.CreateKingScriptScope(capital, Name);
                    break;
                case 1:
                    title = TitleManager.instance.CreateEmpireScriptScope(capital, Name);
                    break;
                case 2:
                    title = TitleManager.instance.CreateDukeScriptScope(capital, Name);
                    break;
            }
     
            ReligiousHeadTitle = title;
            ReligiousHeadTitle.Religious = true;
            ReligiousHeadTitle.Active = true;
            //  ch.UpdateCultural();
            var ch = SimulationManager.instance.AddCharacterForTitle(ReligiousHeadTitle, true);
            ch.religion = Name;
            ch.UpdateCultural();
            var liege = ReligiousHeadTitle.CapitalProvince.Title;
            if(Rand.Next(3)==0)
                ch.GiveTitle(ReligiousHeadTitle.CapitalProvince.Title);
             String religious_names = "";

            for (int n = 0; n < 40; n++)
            {
                religious_names = CultureManager.instance.CultureMap[ch.culture].dna.GetMaleName() + " ";
            }
            title.Scope.Do(@"

	        title = """ + popeName + @"""
	        foa = ""POPE_FOA""
	        short_name = yes
	        location_ruler_title = yes
	        landless = yes
	        controls_religion = """ + Name + @"""
	        religion = """ + Name + @"""
	        primary = yes
	        dynasty_title_names = no
	        male_names = {
			        " + religious_names + @"
        }

");

       
                
            LanguageManager.instance.Add(title.Name, this.LanguageName);
        }
Esempio n. 16
0
        public void Load()
        {
            String provincesDir = Globals.GameDir + "history\\provinces\\";
            foreach (var file in Directory.GetFiles(provincesDir))
            {
                String name = file.Substring(file.LastIndexOf('\\') + 1);
                int id = Convert.ToInt32(name.Split('-')[0].Trim());


            }
            TitleManager.instance.Load();

        //    foreach (var provinceParser in Provinces)
            {
        //        provinceParser.DoTitleOwnership();
            }

            for (int n = 0; n < 2000; n++)
            {
                ProvinceParser parser = new ProvinceParser(new ScriptScope());
                parser.Name = "c_unnamed" + n;
                parser.id = n + 1;
                ProvinceIDMap[parser.id] = parser;
           //     TitleManager.instance.CreateDukeScriptScope();
                Provinces.Add(parser);
            }
            provincesDir = Globals.GameDir + "history\\provinces\\";
            foreach (var file in Directory.GetFiles(provincesDir))
            {
                String name = file.Substring(file.LastIndexOf('\\') + 1);
                int id = Convert.ToInt32(name.Split('-')[0].Trim());

                {
                    Script s = ScriptLoader.instance.Load(file);

                    ScriptCommand terrain = (ScriptCommand)s.Root.Find("terrain");

                    if (terrain != null)
                    {
                        var ter = terrain.Value.ToString();
                        LoadedTerrain[id] = ter;
                    }
                    else
                    {
                        
                    }

                }
                ProvinceIDMap[id].land = true;

            }
            //s
            ProvinceBitmap = new Bitmap(Globals.MapDir + "map\\provinces.bmp");
            ProvinceBitmap = ResizeBitmap(ProvinceBitmap, (int)(ProvinceBitmap.Width * SizeMod), (int)(ProvinceBitmap.Height * SizeMod));
            ProvinceRenderBitmap = new Bitmap(ProvinceBitmap.Width, ProvinceBitmap.Height);
            LoadDefinitions();
          
            ProvincePixelMap = new ProvinceParser[ProvinceBitmap.Width, ProvinceBitmap.Height];

            CreateLandscape();

            LockBitmap lockBitmap = new LockBitmap(ProvinceBitmap);
            lockBitmap.LockBits();
            for (int x = 0; x < lockBitmap.Width; x++)
                for (int y = 0; y < lockBitmap.Height; y++)
                {
                    Color col = lockBitmap.GetPixel(x, y);
                    // col2 = Color.FromArgb(255, col.R, col.G, col.B);
                    if (ProvinceColorMap.ContainsKey(col))
                    {
                        ProvincePixelMap[x, y] = ProvinceColorMap[col];
                        ProvinceColorMap[col].Points.Add(new Point(x, y));
         
                    }

                    int minX = x - 1;
                    int minY = y - 1;
                    if (minX < 0)
                        minX = 0;
                    if (minY < 0)
                        minY = 0;

                    for (int xx = minX; xx <= x; xx++)
                    {
                        for (int yy = minY; yy <= y; yy++)
                        {
                            if (xx == x && yy == y)
                                continue;

                            Color col2 = lockBitmap.GetPixel(xx, yy);
                            if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col))
                            {
                                ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]);
                            }
                        }
                    }



                }

            for (int y = lockBitmap.Height - 1; y >= 0; y--)
                for (int x = lockBitmap.Width - 1; x >= 0; x--)
                {
                    Color col = lockBitmap.GetPixel(x, y);
                    // col2 = Color.FromArgb(255, col.R, col.G, col.B);
                   
                    int maxX = x+1;
                    int maxY = y+1;

                    maxX = Math.Min(lockBitmap.Width - 1, maxX);
                    maxY = Math.Min(lockBitmap.Height - 1, maxY);

                    for (int xx = x; xx <= maxX; xx++)
                    {
                        for (int yy = y; yy <= maxY; yy++)
                        {
                            if (xx == x && yy == y)
                                continue;

                            Color col2 = lockBitmap.GetPixel(xx, yy);
                            if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col))
                            {
                                ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]);
                            }
                        }
                    }



                }
            lockBitmap.UnlockBits();

            foreach (var provinceParser in Provinces)
            {
                int maxX = -1000000;
                int maxY = -1000000;
                int minX = 1000000;
                int minY = 1000000;
                if (provinceParser.Points.Count == 0)
                    continue;

                foreach (var point in provinceParser.Points)
                {
                    if (point.X > maxX)
                        maxX = point.X;
                    if (point.Y > maxY)
                        maxY = point.Y;
                    if (point.X < minX)
                        minX = point.X;
                    if (point.Y < minY)
                        minY = point.Y;


                }

                Bitmap bmp = new Bitmap(maxX - minX + 1, maxY - minY + 1);
                ProvinceMapBitmap b = new ProvinceMapBitmap() {Bitmap = bmp, MapPoint = new Point(minX, minY)};
                LockBitmap lb = new LockBitmap(b.Bitmap);

                lb.LockBits();
                for (int x = 0; x < lb.Width; x++)
                {
                    for (int y = 0; y < lb.Height; y++)
                    {
                        lb.SetPixel(x, y, Color.Transparent);
                    }
                }
                foreach (var point in provinceParser.Points)
                {
                    lb.SetPixel(point.X-minX, point.Y-minY, Color.White);
                }
                lb.UnlockBits();

                ProvinceBitmaps[provinceParser.id] = b;
            }

            LoadAdjacencies();

            Simulation.SimulationManager.instance.Init();
        }
Esempio n. 17
0
        public void Load()
        {
            String provincesDir = Globals.GameDir + "history\\provinces\\";

            foreach (var file in Directory.GetFiles(provincesDir))
            {
                String name = file.Substring(file.LastIndexOf('\\') + 1);
                int    id   = Convert.ToInt32(name.Split('-')[0].Trim());
            }
            TitleManager.instance.Load();

            //    foreach (var provinceParser in Provinces)
            {
                //        provinceParser.DoTitleOwnership();
            }

            for (int n = 0; n < 2000; n++)
            {
                ProvinceParser parser = new ProvinceParser(new ScriptScope());
                parser.Name = "c_unnamed" + n;
                parser.id   = n + 1;
                ProvinceIDMap[parser.id] = parser;
                //     TitleManager.instance.CreateDukeScriptScope();
                Provinces.Add(parser);
            }
            provincesDir = Globals.GameDir + "history\\provinces\\";
            foreach (var file in Directory.GetFiles(provincesDir))
            {
                String name = file.Substring(file.LastIndexOf('\\') + 1);
                int    id   = Convert.ToInt32(name.Split('-')[0].Trim());

                {
                    Script s = ScriptLoader.instance.Load(file);

                    ScriptCommand terrain = (ScriptCommand)s.Root.Find("terrain");

                    if (terrain != null)
                    {
                        var ter = terrain.Value.ToString();
                        LoadedTerrain[id] = ter;
                    }
                    else
                    {
                    }
                }
                ProvinceIDMap[id].land = true;
            }
            //s
            ProvinceBitmap       = new Bitmap(Globals.MapDir + "map\\provinces.bmp");
            ProvinceBitmap       = ResizeBitmap(ProvinceBitmap, (int)(ProvinceBitmap.Width * SizeMod), (int)(ProvinceBitmap.Height * SizeMod));
            ProvinceRenderBitmap = new Bitmap(ProvinceBitmap.Width, ProvinceBitmap.Height);
            LoadDefinitions();

            ProvincePixelMap = new ProvinceParser[ProvinceBitmap.Width, ProvinceBitmap.Height];

            CreateLandscape();

            LockBitmap lockBitmap = new LockBitmap(ProvinceBitmap);

            lockBitmap.LockBits();
            for (int x = 0; x < lockBitmap.Width; x++)
            {
                for (int y = 0; y < lockBitmap.Height; y++)
                {
                    Color col = lockBitmap.GetPixel(x, y);
                    // col2 = Color.FromArgb(255, col.R, col.G, col.B);
                    if (ProvinceColorMap.ContainsKey(col))
                    {
                        ProvincePixelMap[x, y] = ProvinceColorMap[col];
                        ProvinceColorMap[col].Points.Add(new Point(x, y));
                    }

                    int minX = x - 1;
                    int minY = y - 1;
                    if (minX < 0)
                    {
                        minX = 0;
                    }
                    if (minY < 0)
                    {
                        minY = 0;
                    }

                    for (int xx = minX; xx <= x; xx++)
                    {
                        for (int yy = minY; yy <= y; yy++)
                        {
                            if (xx == x && yy == y)
                            {
                                continue;
                            }

                            Color col2 = lockBitmap.GetPixel(xx, yy);
                            if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col))
                            {
                                ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]);
                            }
                        }
                    }
                }
            }

            for (int y = lockBitmap.Height - 1; y >= 0; y--)
            {
                for (int x = lockBitmap.Width - 1; x >= 0; x--)
                {
                    Color col = lockBitmap.GetPixel(x, y);
                    // col2 = Color.FromArgb(255, col.R, col.G, col.B);

                    int maxX = x + 1;
                    int maxY = y + 1;

                    maxX = Math.Min(lockBitmap.Width - 1, maxX);
                    maxY = Math.Min(lockBitmap.Height - 1, maxY);

                    for (int xx = x; xx <= maxX; xx++)
                    {
                        for (int yy = y; yy <= maxY; yy++)
                        {
                            if (xx == x && yy == y)
                            {
                                continue;
                            }

                            Color col2 = lockBitmap.GetPixel(xx, yy);
                            if (col2 != col && ProvinceColorMap.ContainsKey(col2) && ProvinceColorMap.ContainsKey(col))
                            {
                                ProvinceColorMap[col].AddAdjacent(ProvinceColorMap[col2]);
                            }
                        }
                    }
                }
            }
            lockBitmap.UnlockBits();

            foreach (var provinceParser in Provinces)
            {
                int maxX = -1000000;
                int maxY = -1000000;
                int minX = 1000000;
                int minY = 1000000;
                if (provinceParser.Points.Count == 0)
                {
                    continue;
                }

                foreach (var point in provinceParser.Points)
                {
                    if (point.X > maxX)
                    {
                        maxX = point.X;
                    }
                    if (point.Y > maxY)
                    {
                        maxY = point.Y;
                    }
                    if (point.X < minX)
                    {
                        minX = point.X;
                    }
                    if (point.Y < minY)
                    {
                        minY = point.Y;
                    }
                }

                Bitmap            bmp = new Bitmap(maxX - minX + 1, maxY - minY + 1);
                ProvinceMapBitmap b   = new ProvinceMapBitmap()
                {
                    Bitmap = bmp, MapPoint = new Point(minX, minY)
                };
                LockBitmap lb = new LockBitmap(b.Bitmap);

                lb.LockBits();
                for (int x = 0; x < lb.Width; x++)
                {
                    for (int y = 0; y < lb.Height; y++)
                    {
                        lb.SetPixel(x, y, Color.Transparent);
                    }
                }
                foreach (var point in provinceParser.Points)
                {
                    lb.SetPixel(point.X - minX, point.Y - minY, Color.White);
                }
                lb.UnlockBits();

                ProvinceBitmaps[provinceParser.id] = b;
            }

            LoadAdjacencies();

            Simulation.SimulationManager.instance.Init();
        }
Esempio n. 18
0
        public TitleParser CreateEmperor(ProvinceParser capital)
        {
            TitleParser s = CreateEmpireScriptScope(capital);

            return s;
        }
Esempio n. 19
0
        public TitleParser(ScriptScope scope)
            : base(scope)
        {
            String newName = "";

            Name = scope.Name;
            if (Name.StartsWith("b_"))
            {
                //      newName = LanguageManager.instance.Add(Name, StarNames.Generate(culture));
                Rank = 0;
            }
            if (Name.StartsWith("c_"))
            {
                //     newName = LanguageManager.instance.Add(Name, StarNames.Generate(culture));
                Rank = 1;
            }
            if (Name.StartsWith("d_"))
            {
                //     newName = LanguageManager.instance.Add(Name, StarNames.Generate(culture));
                Rank = 2;
            }
            if (Name.StartsWith("k_"))
            {
                //   newName = LanguageManager.instance.Add(Name, StarNames.Generate(culture));
                Rank = 3;
            }
            if (Name.StartsWith("e_"))
            {
                // newName = LanguageManager.instance.Add(Name, StarNames.Generate(culture) + " Empire");
                Rank = 4;
            }


            if (TitleManager.instance.TitleMap.ContainsKey(Name))
            {
            }
            TitleManager.instance.TitleMap[Name] = this;
            TitleManager.instance.Titles.Add(this);
            int line = 0;

            foreach (var child in scope.Children)
            {
                if (child is ScriptCommand)
                {
                    RegisterProperty(line, ((child as ScriptCommand).Name), child);
                }
                line++;
                if (child is ScriptScope)
                {
                    var subscope = (child as ScriptScope);
                    if (subscope.Name == "OR" || subscope.Name == "NOT" || subscope.Name == "AND" ||
                        subscope.Name == "allow" ||
                        subscope.Name == "male_names" ||
                        subscope.Name == "coat_of_arms")
                    {
                        continue;
                    }
                    SubTitles[subscope.Name] = new TitleParser(subscope);

                    SubTitles[subscope.Name].Liege = this;
                    if (subscope.Name.StartsWith("b_"))
                    {
                        MapManager.instance.RegisterBarony(subscope.Name, SubTitles[subscope.Name]);
                    }
                }
            }

            if (capital != 0)
            {
                if (MapManager.instance.ProvinceIDMap.ContainsKey(capital))
                {
                    ProvinceParser provinceParser = MapManager.instance.ProvinceIDMap[capital];
                    CapitalProvince = provinceParser;
                    if (Name.StartsWith("c_"))
                    {
                        Owns.Add(CapitalProvince);
                        CapitalProvince.title = this.Name;
                    }
                }
            }
            else if (MapManager.instance.ProvinceMap.ContainsKey(Name) && Rank == 1)
            {
                ProvinceParser provinceParser = MapManager.instance.ProvinceMap[Name];
                CapitalProvince = provinceParser;
                if (!Name.StartsWith("d_"))
                {
                    Owns.Add(CapitalProvince);
                    CapitalProvince.title = this.Name;
                }
            }
        }
Esempio n. 20
0
 public void SetCapital(ProvinceParser cap)
 {
     Scope.Add(new ScriptCommand() { Name = "capital", Value = cap.id });
    
 }
Esempio n. 21
0
        public void DoLeader(ProvinceParser capital)
        {
            String popeName = StarNames.SafeName(StarNames.Generate(10000000));

            LanguageManager.instance.Add(popeName, StarNames.Generate(10000000));

            PopeName = popeName;
            TitleParser title = null;
            bool        bNew  = false;

            ReligiousHeadTitle = null;

            if (ReligiousHeadTitle == null)
            {
                bNew = true;

                switch (Rand.Next(8))
                {
                case 0:
                case 1:
                case 2:
                case 3:
                    title = TitleManager.instance.CreateKingScriptScope(capital, Name);
                    break;

                case 4:
                    title = TitleManager.instance.CreateEmpireScriptScope(capital, Name);
                    break;

                case 5:
                case 6:
                case 7:
                    title = TitleManager.instance.CreateDukeScriptScope(capital, Name);
                    break;
                }

                ReligiousHeadTitle = title;
            }

            ReligiousHeadTitle.Religious = true;
            ReligiousHeadTitle.Active    = true;
            ReligiousHeadTitle.religion  = Name;

            TitleManager.instance.ReligiousTitles.Add(ReligiousHeadTitle);

            if (bNew)
            {
                var ch = SimulationManager.instance.AddCharacterForTitle(ReligiousHeadTitle, true);
                ch.religion = Name;
                ch.UpdateCultural();
            }

            String religious_names = "";

            for (int n = 0; n < 40; n++)
            {
                religious_names = CultureManager.instance.CultureMap[ReligiousHeadTitle.Holder.culture].dna.GetMaleName() + " ";
            }

            ReligiousHeadTitle.Scope.Do(@"

	        title = """     + popeName + @"""
	        foa = ""POPE_FOA""
	        short_name = "     + (Rand.Next(2) == 0 ? "yes" : "no") + @"
	        location_ruler_title = "     + (Rand.Next(2) == 0 ? "yes" : "no") + @"
	        landless = "     + (bNew ? "yes" : "no") + @"
	        controls_religion = """     + Name + @"""
	        religion = """     + Name + @"""
	        primary = yes
	        dynasty_title_names = no
	    

");

            LanguageManager.instance.Add(ReligiousHeadTitle.Name, this.LanguageName);
        }
Esempio n. 22
0
 public void RemoveProvince(ProvinceParser provinceParser)
 {
     Provinces.Remove(provinceParser);
 }
Esempio n. 23
0
        public void DoLeader(ProvinceParser capital)
        {
            String popeName = StarNames.SafeName(StarNames.Generate(10000000));

            LanguageManager.instance.Add(popeName, StarNames.Generate(10000000));

            TitleParser title = null;

            switch (Rand.Next(3))
            {
            case 0:
                title = TitleManager.instance.CreateKingScriptScope(capital, Name);
                break;

            case 1:
                title = TitleManager.instance.CreateEmpireScriptScope(capital, Name);
                break;

            case 2:
                title = TitleManager.instance.CreateDukeScriptScope(capital, Name);
                break;
            }

            ReligiousHeadTitle           = title;
            ReligiousHeadTitle.Religious = true;
            ReligiousHeadTitle.Active    = true;
            //  ch.UpdateCultural();
            var ch = SimulationManager.instance.AddCharacterForTitle(ReligiousHeadTitle, true);

            ch.religion = Name;
            ch.UpdateCultural();
            var liege = ReligiousHeadTitle.CapitalProvince.Title;

            if (Rand.Next(3) == 0)
            {
                ch.GiveTitle(ReligiousHeadTitle.CapitalProvince.Title);
            }
            String religious_names = "";

            for (int n = 0; n < 40; n++)
            {
                religious_names = CultureManager.instance.CultureMap[ch.culture].dna.GetMaleName() + " ";
            }
            title.Scope.Do(@"

	        title = """     + popeName + @"""
	        foa = ""POPE_FOA""
	        short_name = yes
	        location_ruler_title = yes
	        landless = yes
	        controls_religion = """     + Name + @"""
	        religion = """     + Name + @"""
	        primary = yes
	        dynasty_title_names = no
	        male_names = {
			        "             + religious_names + @"
        }

");



            LanguageManager.instance.Add(title.Name, this.LanguageName);
        }
Esempio n. 24
0
        public TitleParser CreateBaronyScriptScope(ProvinceParser capital, CultureParser culture)
        {
            var place = culture.dna.GetPlaceName();
            var text = place;
            place = StarNames.SafeName(text);
            if (TitleManager.instance.TieredTitles.ContainsKey("b_" + place))
            {
                return CreateBaronyScriptScope(capital, culture);
            }
            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 = capital.Title.Scope;

            
                scope.Name = "b_" + place;
                LanguageManager.instance.Add("b_" + place, text);
            //  scope.Kids.Add(new ScriptCommand() { Name = "rebel", Value = false });
         
            TitleParser title = new TitleParser(scope);
            TieredTitles[title.Name] = title;
            capital.Title.Scope.Add(title.Scope);

  //          if (culture.dna.horde)
//                title.Scope.Do("historical_nomad = yes");
         //   AddTitle(title);
         
            return title;
        }
Esempio n. 25
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;
        }
Esempio n. 26
0
        public TitleParser CreateEmperor(ProvinceParser capital)
        {
            TitleParser s = CreateEmpireScriptScope(capital);

            return(s);
        }
Esempio n. 27
0
        public TitleParser CreateKingScriptScope(ProvinceParser capital, String name = null)
        {
            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;


            if (name == null)
                scope.Name = "k_" + capital.Title.Name.Substring(2);
            else
                scope.Name = "k_" + name;


            //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;
        }
Esempio n. 28
0
        public TitleParser CreateDukeScriptScope(ProvinceParser capital, String name = null)
        {
            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;

            if (name == null)
            {
                String place = capital.Title.Holder.Culture.dna.GetPlaceName();
                String text = place;
                place = StarNames.SafeName(place);
                LanguageManager.instance.Add(place, text);
                scope.Name = "d_" + place;
                LanguageManager.instance.Add(scope.Name, text);
            }
            else
                scope.Name = "d_" + name;

            //  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);
            
  //          if (capital.Title.Culture.dna.horde)
//                title.Scope.Do("historical_nomad = yes");
            
            AddTitle(title);
            if (title.capital != 0)
                title.CapitalProvince = MapManager.instance.ProvinceIDMap[title.capital];
            // now place the counties into it...

            return title;
        }
Esempio n. 29
0
        public void CalculateCulturesProper()
        {
            foreach (var cultureGroupParser in AllCultureGroups)
            {
                if (cultureGroupParser.Name == "norse")
                {
                    continue;
                }
                if (cultureGroupParser.Provinces.Count == 0)
                {
                    continue;
                }

                var province = cultureGroupParser.Provinces[Rand.Next(cultureGroupParser.Provinces.Count)];

                List <ProvinceParser> target = new List <ProvinceParser>();
                target.Add(province);
                target.AddRange(province.Adjacent.Where(p => p.land == true && p.title != null));

                for (int x = 0; x < 8; x++)
                {
                    var toAdd = new List <ProvinceParser>();
                    target.ForEach(p => toAdd.AddRange(p.Adjacent.Where(pp => pp.land && pp.title != null && !target.Contains(pp))));
                    target.AddRange(toAdd);
                }
                HashSet <ProvinceParser> toDo = new HashSet <ProvinceParser>(target);
                foreach (var provinceParser in toDo)
                {
                    provinceParser.Culture = cultureGroupParser.Cultures[0];
                    if (provinceParser.Culture.Group.ReligionGroup != null)
                    {
                        provinceParser.Religion = provinceParser.Culture.Group.ReligionGroup.Religions[0];
                    }
                    else
                    {
                        provinceParser.Religion = ReligionManager.instance.AllReligions[0];
                    }
                }
            }

            for (int index = 0; index < AllCultureGroups.Count; index++)
            {
                var cultureGroupParser = AllCultureGroups[index];

                if (cultureGroupParser.Provinces.Count < 20)
                {
                    bool possible = true;
                    while (cultureGroupParser.Provinces.Count > 0 && possible)
                    {
                        for (int i = 0; i < cultureGroupParser.Provinces.Count; i++)
                        {
                            var provinceParser = cultureGroupParser.Provinces[i];
                            var difcul         =
                                provinceParser.Adjacent.Where(
                                    p => p.Culture != provinceParser.Culture && p.Culture != null);
                            if (!difcul.Any())
                            {
                                if (i == cultureGroupParser.Provinces.Count - 1)
                                {
                                    possible = false;
                                }
                                continue;
                            }
                            var list = new List <ProvinceParser>(difcul);
                            provinceParser.Culture  = list[Rand.Next(list.Count)].Culture;
                            provinceParser.Religion = list[Rand.Next(list.Count)].Religion;
                            break;
                        }
                    }
                }

                if (cultureGroupParser.Provinces.Count == 0)
                {
                    AllCultureGroups.Remove(cultureGroupParser);
                    Script.Root.Remove(cultureGroupParser.Scope);
                    CultureMap.Remove(cultureGroupParser.Cultures[0].Name);
                    AllCultures.Remove(cultureGroupParser.Cultures[0]);
                    foreach (var characterParser in CharacterManager.instance.Characters)
                    {
                        if (characterParser.culture == cultureGroupParser.Cultures[0].Name)
                        {
                            characterParser.culture = AllCultures[AllCultures.Count - 1].Name;
                        }
                    }

                    foreach (var value in DynastyManager.instance.DynastyMap.Values)
                    {
                        if ((string)(value.Scope.Children[1] as ScriptCommand).Value == cultureGroupParser.Cultures[0].Name)
                        {
                            (value.Scope.Children[1] as ScriptCommand).Value = AllCultures[AllCultures.Count - 1].Name;
                        }
                    }
                    index--;
                }
            }
            allowMultiCultureGroups = true;
            for (int index = 0; index < AllCultureGroups.Count; index++)
            {
                var cultureGroupParser = AllCultureGroups[index];

                var provinces = new List <ProvinceParser>(cultureGroupParser.Provinces);
                // Now do the same for cultures...

                var mainCulture = cultureGroupParser.Cultures[0];

                int size = cultureGroupParser.Provinces.Count;
                if (size <= 4)
                {
                    size = 2;
                }
                else if (size < 12)
                {
                    size = 4;
                }
                else if (size < 24)
                {
                    size = 5;
                }
                else if (size < 32)
                {
                    size = 6;
                }
                else if (size < 40)
                {
                    size = 7;
                }
                else
                {
                    size = 8;
                }

                for (int c = 0; c < size; c++)
                {
                    if (provinces.Count == 0)
                    {
                        break;
                    }
                    var start = provinces[Rand.Next(provinces.Count)];

                    if (!CultureManager.instance.CultureMap.ContainsKey(mainCulture.Name))
                    {
                        mainCulture = cultureGroupParser.Cultures[cultureGroupParser.Cultures.Count - 1];
                    }
                    if (!CultureMap.ContainsKey(mainCulture.Name))
                    {
                        CultureMap[mainCulture.Name] = mainCulture;
                    }

                    start.Culture = BranchCulture(mainCulture.Name);
                    var newC = start.Culture;
                    List <ProvinceParser> target = new List <ProvinceParser>();
                    target.Add(start);
                    target.AddRange(start.Adjacent.Where(p => provinces.Contains(p)));
                    int s = 1;
                    if (size > 8)
                    {
                        s = 2;
                    }
                    if (size > 15)
                    {
                        s = 3;
                    }

                    for (int x = 0; x < s; x++)
                    {
                        var toAdd = new List <ProvinceParser>();
                        target.ForEach(p => toAdd.AddRange(p.Adjacent.Where(pp => pp.land && pp.title != null)));
                        target.AddRange(toAdd);
                    }
                    HashSet <ProvinceParser> toDo = new HashSet <ProvinceParser>(target);
                    foreach (var provinceParser in toDo)
                    {
                        provinceParser.Culture = newC;
                        provinces.Remove(provinceParser);
                    }
                }
            }
            // Create big religion groups covering multiple culture groups

            foreach (var religionGroupParser in ReligionManager.instance.AllReligionGroups)
            {
                var cgenum = AllCultureGroups.Where(cg => cg.ReligionGroup == religionGroupParser);

                var cultureGroupList = new List <CultureGroupParser>(cgenum);

                int n = Rand.Next(5) + 4;

                for (int x = 0; x < n; x++)
                {
                    var adjacentProv = new List <ProvinceParser>();
                    var adjacent     = new HashSet <CultureGroupParser>();
                    cultureGroupList.ForEach(g => g.Provinces.ForEach(p => adjacentProv.AddRange(p.Adjacent.Where(pa => pa.land && pa.title != null && pa.Culture != null && pa.Culture.Group != g))));
                    adjacentProv.ForEach(p => adjacent.Add(p.Culture.Group));

                    if (adjacent.Count > 0)
                    {
                        List <CultureGroupParser> list = new List <CultureGroupParser>(adjacent);

                        var chosen = list[Rand.Next(list.Count)];
                        chosen.ReligionGroup = religionGroupParser;
                        chosen.Provinces.ForEach(p => p.Religion = religionGroupParser.Religions[0]);
                    }
                }
            }

            // Cut out small ones


            // Now find the biggest two and make them bigger...
            ReligionGroupParser biggest = null;
            ReligionGroupParser second  = null;


            for (int index = 0; index < ReligionManager.instance.AllReligionGroups.Count; index++)
            {
                var religionGroupParser = ReligionManager.instance.AllReligionGroups[index];


                if (religionGroupParser.Provinces.Count < 50)
                {
                    while (religionGroupParser.Provinces.Count > 0)
                    {
                        bool possible = true;
                        while (religionGroupParser.Provinces.Count > 0 && possible)
                        {
                            for (int i = 0; i < religionGroupParser.Provinces.Count; i++)
                            {
                                var provinceParser = religionGroupParser.Provinces[i];
                                var difcul         =
                                    provinceParser.Adjacent.Where(
                                        p => p.Religion != provinceParser.Religion && p.Religion != null);
                                if (!difcul.Any())
                                {
                                    if (i == religionGroupParser.Provinces.Count - 1)
                                    {
                                        possible = false;
                                    }
                                    continue;
                                }
                                var list = new List <ProvinceParser>(difcul);
                                provinceParser.Religion = list[Rand.Next(list.Count)].Religion;
                                break;
                            }
                        }

                        if (!possible)
                        {
                            var provinceParser = religionGroupParser.Provinces[0];

                            var list =
                                MapManager.instance.Provinces.Where(
                                    p => p.land && p.title != null && p.Religion.Group != religionGroupParser).ToList();

                            distanceTest = provinceParser;
                            list.Sort(SortByDistance);

                            provinceParser.Religion = list[0].Religion;
                            provinceParser.Culture.Group.ReligionGroup = list[0].Religion.Group;
                        }
                    }
                }

                if (religionGroupParser.Provinces.Count == 0)
                {
                    ReligionManager.instance.AllReligionGroups.Remove(religionGroupParser);
                    System.Console.Out.WriteLine(religionGroupParser.Religions[0].Name + " removed");

                    religionGroupParser.Scope.Remove(religionGroupParser.Religions[0].Scope);
                    ReligionManager.instance.Script.Root.Remove(religionGroupParser.Scope);
                    ReligionManager.instance.ReligionMap.Remove(religionGroupParser.Religions[0].Name);
                    ReligionManager.instance.AllReligions.Remove(religionGroupParser.Religions[0]);

                    foreach (var characterParser in CharacterManager.instance.Characters)
                    {
                        if (characterParser.religion == religionGroupParser.Religions[0].Name)
                        {
                            characterParser.religion = ReligionManager.instance.AllReligions[ReligionManager.instance.AllReligions.Count - 1].Name;
                        }
                    }
                    index--;
                }
            }

            ReligionManager.instance.AllReligionGroups.Sort(ReligionManager.instance.SortByBelievers);

            biggest = ReligionManager.instance.AllReligionGroups[0];
            if (ReligionManager.instance.AllReligionGroups.Count > 1)
            {
                second = ReligionManager.instance.AllReligionGroups[1];
            }

            for (int index = 0; index < ReligionManager.instance.AllReligionGroups.Count; index++)
            {
                var religionGroup = ReligionManager.instance.AllReligionGroups[index];

                var provinces = new List <ProvinceParser>(religionGroup.Provinces);
                // Now do the same for cultures...

                var mainReligion = religionGroup.Religions[0];

                int size = religionGroup.Provinces.Count;
                if (size <= 4)
                {
                    size = 1;
                }
                else if (size < 12)
                {
                    size = 1;
                }
                else if (size < 32)
                {
                    size = 2;
                }
                else
                {
                    size = 3;
                }


                if (biggest == religionGroup || second == religionGroup)
                {
                    size = 3;
                }

                for (int c = 0; c < size; c++)
                {
                    if (provinces.Count == 0)
                    {
                        break;
                    }


                    var start = provinces[Rand.Next(provinces.Count)];

                    start.Religion = ReligionManager.instance.BranchReligion(mainReligion.Name, start.Culture.Name);
                    var newC = start.Religion;
                    List <ProvinceParser> target = new List <ProvinceParser>();
                    target.Add(start);
                    target.AddRange(start.Adjacent.Where(p => provinces.Contains(p)));
                    int s = 2;
                    if (size > 16)
                    {
                        s = 3;
                    }
                    if (size > 32)
                    {
                        s = 4;
                    }

                    if (biggest == religionGroup || second == religionGroup)
                    {
                        if (c <= 2)
                        {
                            s += 2;
                        }
                    }

                    for (int x = 0; x < s; x++)
                    {
                        var toAdd = new List <ProvinceParser>();
                        target.ForEach(p => toAdd.AddRange(p.Adjacent.Where(pp => pp.land && pp.title != null && pp.Religion.Group == start.Religion.Group)));
                        target.AddRange(toAdd);
                    }
                    HashSet <ProvinceParser> toDo = new HashSet <ProvinceParser>(target);
                    foreach (var provinceParser in toDo)
                    {
                        provinceParser.Religion = newC;
                        provinces.Remove(provinceParser);
                    }
                }
            }

            for (int index = 0; index < ReligionManager.instance.AllReligionGroups.Count; index++)
            {
                var religionParser = ReligionManager.instance.AllReligionGroups[index];
                if (religionParser.Provinces.Count == 0)
                {
                    ReligionManager.instance.AllReligionGroups.Remove(religionParser);
                    index--;
                    continue;
                }
                religionParser.TryFillHolySites();
            }

            for (int index = 0; index < ReligionManager.instance.AllReligions.Count; index++)
            {
                var religionParser = ReligionManager.instance.AllReligions[index];
                if (religionParser.Provinces.Count == 0)
                {
                    System.Console.Out.WriteLine(religionParser.Name + " removed");
                    if (religionParser.Scope.Name == "enuique")
                    {
                    }

                    ReligionManager.instance.AllReligions.Remove(religionParser);
                    ReligionManager.instance.ReligionMap.Remove(religionParser.Name);
                    religionParser.Group.Scope.Remove(religionParser.Scope);
                    index--;
                    continue;
                }
                religionParser.TryFillHolySites();
            }


            foreach (var characterParser in CharacterManager.instance.Characters)
            {
                if (characterParser.Titles.Count > 0)
                {
                    if (characterParser.PrimaryTitle.Rank == 2)
                    {
                        characterParser.culture  = characterParser.PrimaryTitle.SubTitles.First().Value.Owns[0].Culture.Name;
                        characterParser.religion = characterParser.PrimaryTitle.SubTitles.First().Value.Owns[0].Religion.Name;
                    }
                    else
                    {
                        characterParser.culture  = characterParser.PrimaryTitle.Owns[0].Culture.Name;
                        characterParser.religion = characterParser.PrimaryTitle.Owns[0].Religion.Name;
                    }

                    foreach (var titleParser in characterParser.Titles)
                    {
                        titleParser.culture = characterParser.culture;
                    }
                }
            }

            var l = MapManager.instance.Provinces.Where(p => p.title != null).ToList();

            foreach (var provinceParser in l)
            {
                provinceParser.initialReligion = provinceParser.Religion.Name;
                provinceParser.initialCulture  = provinceParser.Culture.Name;
            }


            foreach (var religionParser in ReligionManager.instance.AllReligions)
            {
                if (religionParser.Provinces.Count > 0)
                {
                    ReligionManager.instance.ReligionMap[religionParser.Name] = religionParser;
                }
                if (religionParser.Provinces.Count > 0 && (religionParser.hasLeader || religionParser.autocephaly))
                {
                    religionParser.DoLeader(religionParser.Provinces[Rand.Next(religionParser.Provinces.Count)]);
                }
            }
        }
Esempio n. 30
0
 public void AddAdjacent(ProvinceParser prov)
 {
     if (!Adjacent.Contains(prov))
         Adjacent.Add(prov);
     if (!prov.Adjacent.Contains(this))
         prov.Adjacent.Add(this);
 }
Esempio n. 31
0
        // Following function sets 'allowMultiCultureGroups' to true

        public void CalculateCulturesProper()
        {
            foreach (var cultureGroupParser in AllCultureGroups)
            {
                if (cultureGroupParser.Name == "Urtru")
                {
                    continue;
                }
                if (cultureGroupParser.Provinces.Count == 0)
                {
                    continue;
                }

                var province = cultureGroupParser.Provinces[Rand.Next(cultureGroupParser.Provinces.Count)];

                List <ProvinceParser> target = new List <ProvinceParser>();
                target.Add(province);
                target.AddRange(province.Adjacent.Where(p => p.land == true && p.title != null));

                for (int x = 0; x < 8; x++)
                {
                    var toAdd = new List <ProvinceParser>();
                    target.ForEach(p => toAdd.AddRange(p.Adjacent.Where(pp => pp.land && pp.title != null && !target.Contains(pp))));
                    target.AddRange(toAdd);
                }

                HashSet <ProvinceParser> toDo = new HashSet <ProvinceParser>(target);

                foreach (var provinceParser in toDo)
                {
                    provinceParser.Culture = cultureGroupParser.Cultures[0];
                    if (provinceParser.Culture.Group.ReligionGroup != null)
                    {
                        provinceParser.Religion = provinceParser.Culture.Group.ReligionGroup.Religions[0];
                    }
                    else
                    {
                        provinceParser.Religion = ReligionManager.instance.AllReligions[0];
                    }
                }
            }

            for (int index = 0; index < AllCultureGroups.Count; index++)
            {
                var cultureGroupParser = AllCultureGroups[index];

                if (cultureGroupParser.Provinces.Count < 20)
                {
                    bool possible = true;
                    while (cultureGroupParser.Provinces.Count > 0 && possible)
                    {
                        for (int i = 0; i < cultureGroupParser.Provinces.Count; i++)
                        {
                            var provinceParser = cultureGroupParser.Provinces[i];
                            var difcul         =
                                provinceParser.Adjacent.Where(
                                    p => p.Culture != provinceParser.Culture && p.Culture != null);
                            if (!difcul.Any())
                            {
                                if (i == cultureGroupParser.Provinces.Count - 1)
                                {
                                    possible = false;
                                }
                                continue;
                            }
                            var list = new List <ProvinceParser>(difcul);
                            provinceParser.Culture  = list[Rand.Next(list.Count)].Culture;
                            provinceParser.Religion = list[Rand.Next(list.Count)].Religion;
                            break;
                        }
                    }
                }

                if (cultureGroupParser.Provinces.Count == 0)
                {
                    AllCultureGroups.Remove(cultureGroupParser);
                    Script.Root.Remove(cultureGroupParser.Scope);
                    CultureMap.Remove(cultureGroupParser.Cultures[0].Name);
                    AllCultures.Remove(cultureGroupParser.Cultures[0]);

                    foreach (var characterParser in CharacterManager.instance.Characters)
                    {
                        if (characterParser.culture == cultureGroupParser.Cultures[0].Name)
                        {
                            characterParser.culture = AllCultures[AllCultures.Count - 1].Name;
                        }
                    }

                    foreach (var value in DynastyManager.instance.DynastyMap.Values)
                    {
                        if ((string)(value.Scope.Children[1] as ScriptCommand).Value == cultureGroupParser.Cultures[0].Name)
                        {
                            (value.Scope.Children[1] as ScriptCommand).Value = AllCultures[AllCultures.Count - 1].Name;
                        }
                    }
                    index--;
                }
            }

            //Enable in-group culture branching

            allowMultiCultureGroups = true;

            for (int index = 0; index < AllCultureGroups.Count; index++)
            {
                var cultureGroupParser = AllCultureGroups[index];

                var provinces = new List <ProvinceParser>(cultureGroupParser.Provinces);

                // Sets a main culture for the culture group

                var mainCulture = cultureGroupParser.Cultures[0];

                int size = cultureGroupParser.Provinces.Count;

                int iterations = 0;

                if (size <= 4)
                {
                    iterations = 2;
                }
                else if (size < 12)
                {
                    iterations = 4;
                }
                else if (size < 24)
                {
                    iterations = 5;
                }
                else if (size < 32)
                {
                    iterations = 6;
                }
                else if (size < 40)
                {
                    iterations = 7;
                }
                else
                {
                    iterations = 8;
                }

                for (int c = 0; c < iterations; c++)
                {
                    if (provinces.Count == 0)
                    {
                        break;
                    }

                    ProvinceParser start = provinces[Rand.Next(provinces.Count)];

                    if (!instance.CultureMap.ContainsKey(mainCulture.Name))
                    {
                        mainCulture = cultureGroupParser.Cultures[cultureGroupParser.Cultures.Count - 1];
                    }

                    if (!CultureMap.ContainsKey(mainCulture.Name))
                    {
                        CultureMap[mainCulture.Name] = mainCulture;
                    }

                    start.Culture = BranchCulture(mainCulture.Name);

                    var newCulture = start.Culture;

                    List <ProvinceParser> target = new List <ProvinceParser>();

                    target.Add(start);
                    target.AddRange(start.Adjacent.Where(p => provinces.Contains(p)));

                    int s = 1;

                    if (iterations > 8)
                    {
                        s = 2;
                    }

                    if (iterations > 15)
                    {
                        s = 3;
                    }

                    for (int x = 0; x < s; x++)
                    {
                        var toAdd = new List <ProvinceParser>();
                        target.ForEach(p => toAdd.AddRange(p.Adjacent.Where(pp => pp.land && pp.title != null)));
                        target.AddRange(toAdd);
                    }

                    HashSet <ProvinceParser> toDo = new HashSet <ProvinceParser>(target);

                    foreach (var provinceParser in toDo)
                    {
                        provinceParser.Culture = newCulture;
                        provinces.Remove(provinceParser);
                    }
                }
            }

            // Create big religion groups covering multiple culture groups

            foreach (var religionGroupParser in ReligionManager.instance.AllReligionGroups)
            {
                var cgenum = AllCultureGroups.Where(cg => cg.ReligionGroup == religionGroupParser);

                var cultureGroupList = new List <CultureGroupParser>(cgenum);

                int n = Rand.Next(5) + 4;

                for (int x = 0; x < n; x++)
                {
                    var adjacentProv = new List <ProvinceParser>();
                    var adjacent     = new HashSet <CultureGroupParser>();

                    cultureGroupList.ForEach(g => g.Provinces.ForEach(p => adjacentProv.AddRange(p.Adjacent.Where(pa => pa.land && pa.title != null && pa.Culture != null && pa.Culture.Group != g))));

                    adjacentProv.ForEach(p => adjacent.Add(p.Culture.Group));

                    if (adjacent.Count > 0)
                    {
                        List <CultureGroupParser> list = new List <CultureGroupParser>(adjacent);

                        var chosen = list[Rand.Next(list.Count)];

                        chosen.ReligionGroup = religionGroupParser;

                        chosen.Provinces.ForEach(p => p.Religion = religionGroupParser.Religions[0]);
                    }
                }
            }

            // Now find the biggest two and make them bigger...

            ReligionGroupParser biggest = null;
            ReligionGroupParser second  = null;

            for (int index = 0; index < ReligionManager.instance.AllReligionGroups.Count; index++)
            {
                var religionGroupParser = ReligionManager.instance.AllReligionGroups[index];

                if (religionGroupParser.Provinces.Count < 50)
                {
                    while (religionGroupParser.Provinces.Count > 0)
                    {
                        bool possible = true;

                        while (religionGroupParser.Provinces.Count > 0 && possible)
                        {
                            for (int i = 0; i < religionGroupParser.Provinces.Count; i++)
                            {
                                var provinceParser = religionGroupParser.Provinces[i];

                                var difcul = provinceParser.Adjacent.Where(p => p.Religion != provinceParser.Religion && p.Religion != null);

                                if (!difcul.Any())
                                {
                                    if (i == religionGroupParser.Provinces.Count - 1)
                                    {
                                        possible = false;
                                    }

                                    continue;
                                }

                                var list = new List <ProvinceParser>(difcul);

                                provinceParser.Religion = list[Rand.Next(list.Count)].Religion;

                                break;
                            }
                        }

                        if (!possible)
                        {
                            var provinceParser = religionGroupParser.Provinces[0];

                            var list = MapManager.instance.Provinces.Where(p => p.land && p.title != null && p.Religion.Group != religionGroupParser).ToList();

                            distanceTest = provinceParser;

                            list.Sort(SortByDistance);

                            provinceParser.Religion = list[0].Religion;

                            provinceParser.Culture.Group.ReligionGroup = list[0].Religion.Group;
                        }
                    }
                }

                if (religionGroupParser.Provinces.Count == 0)
                {
                    ReligionManager.instance.AllReligionGroups.Remove(religionGroupParser);

                    Console.Out.WriteLine(religionGroupParser.Religions[0].Name + " removed");

                    religionGroupParser.Scope.Remove(religionGroupParser.Religions[0].Scope);

                    ReligionManager.instance.Script.Root.Remove(religionGroupParser.Scope);
                    ReligionManager.instance.ReligionMap.Remove(religionGroupParser.Religions[0].Name);
                    ReligionManager.instance.AllReligions.Remove(religionGroupParser.Religions[0]);

                    foreach (var characterParser in CharacterManager.instance.Characters)
                    {
                        if (characterParser.religion == religionGroupParser.Religions[0].Name)
                        {
                            characterParser.religion = ReligionManager.instance.AllReligions[ReligionManager.instance.AllReligions.Count - 1].Name;
                        }
                    }

                    index--;
                }
            }

            ReligionManager.instance.AllReligionGroups.Sort(ReligionManager.instance.SortByBelievers);

            //After sorting grab largest & second-largest religions

            biggest = ReligionManager.instance.AllReligionGroups[0];

            if (ReligionManager.instance.AllReligionGroups.Count > 1)
            {
                second = ReligionManager.instance.AllReligionGroups[1];
            }

            for (int index = 0; index < ReligionManager.instance.AllReligionGroups.Count; index++)
            {
                var religionGroup = ReligionManager.instance.AllReligionGroups[index];

                var provinces = new List <ProvinceParser>(religionGroup.Provinces);

                var mainReligion = religionGroup.Religions[0];

                int size = religionGroup.Provinces.Count;

                int iterations = 0;

                if (size <= 4)
                {
                    iterations = 1;
                }
                else if (size < 12)
                {
                    iterations = 1;
                }
                else if (size < 32)
                {
                    iterations = 2;
                }
                else
                {
                    iterations = 3;
                }

                // Do max iterations for first & second groups to make them larger

                if (biggest == religionGroup || second == religionGroup)
                {
                    iterations = 3;
                }

                for (int c = 0; c < iterations; c++)
                {
                    if (provinces.Count == 0)
                    {
                        break;
                    }

                    var start = provinces[Rand.Next(provinces.Count)];

                    start.Religion = ReligionManager.instance.BranchReligion(mainReligion.Name, start.Culture.Name);

                    var newC = start.Religion;

                    List <ProvinceParser> target = new List <ProvinceParser>();

                    target.Add(start);
                    target.AddRange(start.Adjacent.Where(p => provinces.Contains(p)));

                    int s = 2;
                    if (size > 16)
                    {
                        s = 3;
                    }
                    if (size > 32)
                    {
                        s = 4;
                    }

                    //If this is for first/second group, do the next loop two more times than usual the first few iterations

                    if (biggest == religionGroup || second == religionGroup)
                    {
                        if (c <= 2)
                        {
                            s += 2;
                        }
                    }

                    for (int x = 0; x < s; x++)
                    {
                        var toAdd = new List <ProvinceParser>();
                        target.ForEach(p => toAdd.AddRange(p.Adjacent.Where(pp => pp.land && pp.title != null && pp.Religion.Group == start.Religion.Group)));
                        target.AddRange(toAdd);
                    }

                    HashSet <ProvinceParser> toDo = new HashSet <ProvinceParser>(target);

                    foreach (var provinceParser in toDo)
                    {
                        provinceParser.Religion = newC;
                        provinces.Remove(provinceParser);
                    }
                }
            }

            //Remove any groups with no provinces? then fill some holy sites?

            for (int index = 0; index < ReligionManager.instance.AllReligionGroups.Count; index++)
            {
                var religionParser = ReligionManager.instance.AllReligionGroups[index];

                if (religionParser.Provinces.Count == 0)
                {
                    ReligionManager.instance.AllReligionGroups.Remove(religionParser);
                    index--;
                    continue;
                }

                religionParser.TryFillHolySites();
            }

            for (int index = 0; index < ReligionManager.instance.AllReligions.Count; index++)
            {
                var religionParser = ReligionManager.instance.AllReligions[index];

                if (religionParser.Provinces.Count == 0)
                {
                    Console.Out.WriteLine(religionParser.Name + " removed");
                    ReligionManager.instance.AllReligions.Remove(religionParser);
                    ReligionManager.instance.ReligionMap.Remove(religionParser.Name);
                    religionParser.Group.Scope.Remove(religionParser.Scope);

                    index--;

                    continue;
                }

                religionParser.TryFillHolySites();
            }

            //What's going on here? Setting char culture and religion to that of their primary title? Hmmm

            foreach (var characterParser in CharacterManager.instance.Characters)
            {
                if (characterParser.Titles.Count > 0)
                {
                    if (characterParser.PrimaryTitle.Rank == 2)
                    {
                        characterParser.culture  = characterParser.PrimaryTitle.SubTitles.First().Value.Owns[0].Culture.Name;
                        characterParser.religion = characterParser.PrimaryTitle.SubTitles.First().Value.Owns[0].Religion.Name;
                    }
                    else
                    {
                        characterParser.culture  = characterParser.PrimaryTitle.Owns[0].Culture.Name;
                        characterParser.religion = characterParser.PrimaryTitle.Owns[0].Religion.Name;
                    }

                    foreach (var titleParser in characterParser.Titles)
                    {
                        titleParser.culture = characterParser.culture;
                    }
                }
            }

            var l = MapManager.instance.Provinces.Where(p => p.title != null).ToList();

            foreach (var provinceParser in l)
            {
                provinceParser.initialReligion = provinceParser.Religion.Name;
                provinceParser.initialCulture  = provinceParser.Culture.Name;
            }

            //Set up map & leader for any religion with > 0 provinces

            foreach (var religionParser in ReligionManager.instance.AllReligions)
            {
                if (religionParser.Provinces.Count > 0)
                {
                    ReligionManager.instance.ReligionMap[religionParser.Name] = religionParser;
                }

                if (religionParser.Provinces.Count > 0 && (religionParser.hasLeader || religionParser.autocephaly))
                {
                    religionParser.DoLeader(religionParser.Provinces[Rand.Next(religionParser.Provinces.Count)]);
                }
            }
        }