Пример #1
0
        private Dictionary <DateTime, string> AddHistory(PdxSublist history, string type)
        {
            var storedHistory = new Dictionary <DateTime, string>();

            if (!history.KeyValuePairs.ContainsKey(type))
            {
                return(storedHistory);
            }
            var startDate = new DateTime(1444, 11, 11);

            history.KeyValuePairs.ForEach(type, (h =>
            {
                storedHistory[startDate] = h;
            }));
            foreach (var entry in history.Sublists)
            {
                var sub = entry.Value;
                if (sub.KeyValuePairs.ContainsKey(type))
                {
                    var date = PdxSublist.ParseDate(sub.Key);
                    sub.KeyValuePairs.ForEach(type, v =>
                    {
                        storedHistory[date] = v;
                    });
                }
            }
            return(storedHistory);
        }
Пример #2
0
 public CK2Province(int id, CK2World world, PdxSublist historyData)
 {
     World            = world;
     ID               = id;
     county           = historyData.KeyValuePairs["title"];
     _cultureHistory  = new List <Dated <CK2Culture> >();
     _religionHistory = new List <Dated <CK2Religion> >();
     if (historyData.KeyValuePairs.ContainsKey("culture"))
     {
         _cultureHistory.Add(new Dated <CK2Culture>(new DateTime(769, 1, 1), world.CK2Cultures[historyData.KeyValuePairs["culture"]]));
     }
     if (historyData.KeyValuePairs.ContainsKey("religion"))
     {
         _religionHistory.Add(new Dated <CK2Religion>(new DateTime(769, 1, 1), world.CK2Religions[historyData.KeyValuePairs["religion"]]));
     }
     historyData.ForEachSublist((sub) =>
     {
         var date = PdxSublist.ParseDate(sub.Key);
         if (sub.Value.KeyValuePairs.ContainsKey("religion"))
         {
             _religionHistory.Add(new Dated <CK2Religion>(date, world.CK2Religions[sub.Value.KeyValuePairs["religion"]]));
         }
         if (sub.Value.KeyValuePairs.ContainsKey("culture"))
         {
             _cultureHistory.Add(new Dated <CK2Culture>(date, world.CK2Cultures[sub.Value.KeyValuePairs["culture"]]));
         }
     });
 }
Пример #3
0
        public Eu4Country(PdxSublist country, Eu4Save save)
        {
            World      = save;
            CountryTag = country.Key;
            Opinions   = country.GetSublist("opinion_cache").Values.Select(int.Parse).ToList();
            //Console.WriteLine($"Loading {CountryTag}...");
            if (country.KeyValuePairs.ContainsKey("name"))
            {
                DisplayNoun = country.GetString("name").Replace("\"", string.Empty);
            }
            else
            {
                DisplayNoun = save.Localisation[CountryTag];
            }
            if (country.KeyValuePairs.ContainsKey("adjective"))
            {
                DisplayAdj = country.GetString("adjective").Replace("\"", string.Empty);
            }
            else
            {
                DisplayAdj = save.Localisation[$"{CountryTag}_ADJ"];
            }

            Exists = country.Sublists.ContainsKey("owned_provinces");

            if (country.KeyValuePairs.ContainsKey("overlord"))
            {
                Overlord = country.GetString("overlord").Replace("\"", string.Empty);
            }
            Subjects = new List <string>();
            if (country.Sublists.ContainsKey("subjects"))
            {
                country.Sublists["subjects"].Values.ForEach(s =>
                {
                    Subjects.Add(s);
                });
            }
            if (country.KeyValuePairs.ContainsKey("liberty_desire"))
            {
                LibertyDesire = float.Parse(country.GetString("liberty_desire"));
            }
            if (country.KeyValuePairs.ContainsKey("colonial_parent"))
            {
                IsColonialNation = true;
            }
            States = new HashSet <Eu4Area>();
            if (country.Sublists.ContainsKey("state"))
            {
                country.Sublists.ForEach("state", stData =>
                {
                    var area = save.Areas[stData.KeyValuePairs["area"]];
                    States.Add(area);
                    area.Prosperity = stData.GetFloat("prosperity");
                    //area.Owner = this;
                });
            }

            var institutions     = country.GetSublist("institutions");
            var listInstitutions = institutions.FloatValues[string.Empty].Select(ins => ins == 1).ToList();

            Institutions = new Dictionary <string, bool>();
            for (var i = 0; i < listInstitutions.Count; i++)
            {
                Institutions.Add(INSTITUTION_NAMES[i], listInstitutions[i]);
            }
            Capital = (int)country.GetFloat("capital");
            var colours   = country.GetSublist("colors");
            var mapColour = colours.GetSublist("map_color");

            MapColour = new Colour(mapColour.FloatValues[string.Empty]);

            PrimaryCulture = country.GetString("primary_culture");

            AcceptedCultures = new List <string>();

            country.KeyValuePairs.ForEach("accepted_culture", (value) =>
            {
                AcceptedCultures.Add(value);
            });
            if (country.KeyValuePairs.ContainsKey("religion"))
            {
                Religion = country.GetString("religion");
            }
            else
            {
                Religion = (country.Sublists["history"].Sublists.Where(s => s.Value.KeyValuePairs.ContainsKey("religion")).OrderByDescending(s => PdxSublist.ParseDate(s.Key).Ticks).FirstOrDefault().Value ?? country.Sublists["history"]).GetString("religion");
            }


            GovernmentRank = (byte)country.GetFloat("government_rank");

            var tech = country.GetSublist("technology");

            AdmTech = (byte)tech.GetFloat("adm_tech");
            DipTech = (byte)tech.GetFloat("dip_tech");
            MilTech = (byte)tech.GetFloat("adm_tech");

            Estates = new List <Estate>();
            country.Sublists.ForEach("estate", (est) =>
            {
                Estates.Add(new Estate(est));
            });


            PowerProjection = LoadFloat(country, "current_power_projection");

            LastElection = country.GetDate("last_election");

            Prestige = LoadFloat(country, "prestige");

            Stability = (sbyte)country.GetFloat("stability");
            Inflation = LoadFloat(country, "inflation");


            country.GetAllMatchingSublists("loan", (loan) =>
            {
                Debt += (int)loan.GetFloat("amount");
            });

            Absolutism          = LoadFloat(country, "absolutism");
            Legitimacy          = LoadFloat(country, "legitimacy", 50);
            RepublicanTradition = LoadFloat(country, "republican_tradition", 50);
            Corruption          = LoadFloat(country, "corruption");
            Mercantilism        = LoadFloat(country, "mercantilism");

            Ideas = new Dictionary <string, byte>();
            var ideas = country.GetSublist("active_idea_groups");

            foreach (var idp in ideas.FloatValues)
            {
                Ideas.Add(idp.Key, (byte)idp.Value.Single());
            }

            Flags    = country.Sublists.ContainsKey("flags") ? country.GetSublist("flags").KeyValuePairs.Keys.ToList() : new List <string>();
            Policies = new List <string>();
            country.Sublists.ForEach("active_policy", (pol) =>
            {
                Policies.Add(pol.GetString("policy"));
            });

            Government = country.GetSublist("government").GetString("government");
            if (country.Key == "GBR")
            {
                //	Console.WriteLine(Institutions);
            }
        }
Пример #4
0
        public void AddPop(Eu4ProvinceBase fromProvince, PopType type, int quantity)
        {
            var history = new Dictionary <DateTime, DemographicEvent>();

            fromProvince.CulturalHistory.ToList().ForEach(ce => history.Add(ce.Key, new DemographicEvent().SetCulture(World.V2Mapper.GetV2Culture(ce.Value, fromProvince, province))));
            fromProvince.ReligiousHistory.ToList().ForEach(re =>
            {
                if (history.ContainsKey(re.Key))
                {
                    history[re.Key].SetReligion(World.V2Mapper.GetV2Religion(re.Value));
                }
                else
                {
                    history[re.Key] = new DemographicEvent().SetReligion(World.V2Mapper.GetV2Religion(re.Value));
                }
            });
            if (history.Count == 0)
            {
                history[new DateTime(1444, 11, 11)] = new DemographicEvent().SetCulture(World.V2Mapper.GetV2Culture(fromProvince.Culture, fromProvince, province)).SetReligion(World.V2Mapper.GetV2Religion(fromProvince.Religion));
            }
            var orderedHistory = history.OrderBy(he => he.Key.Ticks);

            var popsList = new List <Pop>();

            popsList.Add(new Pop(type, quantity, orderedHistory.First().Value.Culture ?? fromProvince.Culture, orderedHistory.First().Value.Religion ?? fromProvince.Religion));
            KeyValuePair <DateTime, DemographicEvent> lastEntry = orderedHistory.First();
            //if (fromProvince.ProvinceID == 233)
            //{
            //	Console.WriteLine("Cornwall!");
            //}
            //bool firstTime = true;
            var majorityReligion = lastEntry.Value.Religion ?? fromProvince.Religion;
            var majorityCulture  = lastEntry.Value.Culture ?? fromProvince.Culture;

            foreach (var entry in orderedHistory)
            {
                var since = entry.Key - lastEntry.Key;
                // 200 years -> +50%
                //set[lastEntry.Value.Value] += (since.Days * 1.369863013698630136986301369863e-5); quantity *
                MergePops(popsList, SplitPops((int)(quantity * Math.Min(1, since.Days * 6.8493150684931506849315068493151e-6)), popsList, c => majorityCulture, r => majorityReligion));


                if (entry.Value.Religion == null)
                {
                    if (entry.Value.Culture == null)
                    {
                        // something is probably broken here
                        Console.WriteLine($"Warning: Province {fromProvince.ProvinceID} has an invalid history entry for {entry.Key.ToShortDateString()}");
                    }
                    else
                    {
                        majorityCulture = entry.Value.Culture;
                        // flip 50% of population to new culture. only true faith will convert culture as in eu4
                        MergePops(popsList, SplitPops(1 + quantity / 2, popsList.Where(p => p.Religion == majorityReligion).ToList(), c => entry.Value.Culture, r => r));
                    }
                }
                else
                {
                    majorityReligion = entry.Value.Religion;
                    if (entry.Value.Culture == null)
                    {
                        // flip 50% of population to new religion
                        MergePops(popsList, SplitPops(1 + quantity / 2, popsList, c => c, r => entry.Value.Religion));
                    }
                    else
                    {
                        majorityCulture = entry.Value.Culture;
                        // flip 50% to new religion + culture
                        MergePops(popsList, SplitPops(1 + quantity / 2, popsList, c => entry.Value.Culture, r => entry.Value.Religion));
                    }
                }
            }
            var now        = PdxSublist.ParseDate(World.StartDate);
            var finalSince = now - lastEntry.Key;

            // 200 years -> +50%
            MergePops(popsList, SplitPops((int)(quantity * Math.Min(1, finalSince.Days * 6.8493150684931506849315068493151e-6)), popsList, c => majorityCulture, r => majorityReligion));
            foreach (var pop in popsList)
            {
                AddPop(pop);
            }
        }