Esempio n. 1
0
 private void CalcPopEffects(Dictionary <string, float> effects, Eu4ProvinceBase fromProvince)
 {
     foreach (PopType popType in Enum.GetValues(typeof(PopType)))
     {
         var name = Enum.GetName(typeof(PopType), popType);
         if (effects.ContainsKey(name))
         {
             Pops.AddPop(fromProvince, popType, (int)effects[name]);
         }
     }
 }
Esempio n. 2
0
 private void CalcRelativePopEffects(Dictionary <string, float> effects, Eu4ProvinceBase fromProvince)
 {
     foreach (PopType popType in Enum.GetValues(typeof(PopType)))
     {
         var name = Enum.GetName(typeof(PopType), popType);
         if (effects.ContainsKey("relative_" + name))
         {
             Pops.IncreaseJob(popType, effects["relative_" + name]);
         }
     }
 }
Esempio n. 3
0
        public string GetV2Culture(string eu4Culture, Eu4ProvinceBase prov, Vic2Province vProv)
        {
            var culture = Map(Culture, eu4Culture);

            if (prov != null)
            {
                Vic2CultureGroup group = null;
                if (World.Cultures.ContainsKey(culture))
                {
                    group = World.Cultures[culture].Group;
                }
                else if (World.CultureGroups.ContainsKey(culture))
                {
                    group = World.CultureGroups[culture];
                }
                else
                {
                    group = new Vic2CultureGroup(World.Eu4Save.Cultures[eu4Culture].Group, World);
                }
                var dist = group.GetDistance(vProv);
                if (dist > 20)                 //diff cul, same group

                // different cultures for off colonies
                {
                    var neoEu4Culture = $"{eu4Culture}:{prov.Continent.Name}";
                    var neoCulture    = Map(Culture, neoEu4Culture);
                    if (neoCulture == null)
                    {
                        // todo: fix what this will do to nations on borders between continents such as the ottomans
                        neoCulture = World.GenerateCulture(eu4Culture, culture + '_' + prov.Continent.Name + 'n', World.Eu4Save.Localisation[prov.Continent.Name], true);

                        NeoCultures[neoCulture] = culture;
                        Culture.Add(neoEu4Culture, neoCulture);
                    }
                    return(neoCulture);
                }
            }

            if (culture == null || !World.Cultures.ContainsKey(culture))
            {
                culture = World.GenerateCulture(eu4Culture, culture);
                if (!Culture.ContainsKey(eu4Culture))
                {
                    Culture.Add(eu4Culture, culture);
                }
            }
            return(culture);
        }
Esempio n. 4
0
 private float CalcFactoryEffects(Dictionary <string, float> effects, Eu4ProvinceBase fromProvince, Dictionary <string, float> factories)
 {
     foreach (var factory in World.Factories.Sublists["priority"].Values)
     {
         if (effects.ContainsKey(factory))
         {
             if (!factories.ContainsKey(factory))
             {
                 factories[factory] = 0;
             }
             factories[factory] += effects[factory];
         }
     }
     if (effects.ContainsKey("factory"))
     {
         return(effects["factory"]);
     }
     return(0);
 }
Esempio n. 5
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);
            }
        }