Ejemplo n.º 1
0
    public void InitializeFromTag(
        Country country,
        CountryCollection imperatorCountries,
        LocDB locDB,
        ProvinceMapper provinceMapper,
        CoaMapper coaMapper,
        GovernmentMapper governmentMapper,
        SuccessionLawMapper successionLawMapper,
        DefiniteFormMapper definiteFormMapper,
        ReligionMapper religionMapper,
        CultureMapper cultureMapper,
        NicknameMapper nicknameMapper,
        CharacterCollection characters,
        Date conversionDate
        )
    {
        IsImportedOrUpdatedFromImperator = true;
        ImperatorCountry          = country;
        ImperatorCountry.CK3Title = this;

        LocBlock?validatedName = GetValidatedName(country, imperatorCountries, locDB);

        HasDefiniteForm.Value    = definiteFormMapper.IsDefiniteForm(ImperatorCountry.Name);
        RulerUsesTitleName.Value = false;

        PlayerCountry = ImperatorCountry.PlayerCountry;

        ClearHolderSpecificHistory();

        FillHolderAndGovernmentHistory();

        // ------------------ determine color
        var color1Opt = ImperatorCountry.Color1;

        if (color1Opt is not null)
        {
            Color1 = color1Opt;
        }
        var color2Opt = ImperatorCountry.Color2;

        if (color2Opt is not null)
        {
            Color2 = color2Opt;
        }

        // determine successions laws
        history.InternalHistory.AddFieldValue("succession_laws",
                                              successionLawMapper.GetCK3LawsForImperatorLaws(ImperatorCountry.GetLaws()),
                                              conversionDate,
                                              "succession_laws"
                                              );

        // determine CoA
        CoA = coaMapper.GetCoaForFlagName(ImperatorCountry.Flag);

        // determine other attributes
        var srcCapital = ImperatorCountry.Capital;

        if (srcCapital is not null)
        {
            var provMappingsForImperatorCapital = provinceMapper.GetCK3ProvinceNumbers((ulong)srcCapital);
            if (provMappingsForImperatorCapital.Count > 0)
            {
                var foundCounty = parentCollection.GetCountyForProvince(provMappingsForImperatorCapital[0]);
                if (foundCounty is not null)
                {
                    CapitalCounty = foundCounty;
                }
            }
        }

        // determine country name localization
        var nameSet = false;

        if (validatedName is not null)
        {
            var nameLocBlock = Localizations.AddLocBlock(Id);
            nameLocBlock.CopyFrom(validatedName);
            nameSet = true;
        }
        if (!nameSet)
        {
            var impTagLoc = locDB.GetLocBlockForKey(ImperatorCountry.Tag);
            if (impTagLoc is not null)
            {
                var nameLocBlock = Localizations.AddLocBlock(Id);
                nameLocBlock.CopyFrom(impTagLoc);
                nameSet = true;
            }
        }
        if (!nameSet)
        {
            // use unlocalized name if not empty
            var name = ImperatorCountry.Name;
            if (!string.IsNullOrEmpty(name))
            {
                Logger.Warn($"Using unlocalized Imperator name {name} as name for {Id}!");
                var nameLocBlock = Localizations.AddLocBlock(Id);
                nameLocBlock["english"] = name;
                nameLocBlock.FillMissingLocWithBaseLanguageLoc();
                nameSet = true;
            }
        }
        // giving up
        if (!nameSet)
        {
            Logger.Warn($"{Id} needs help with localization! {ImperatorCountry.Name}?");
        }

        // determine adjective localization
        TrySetAdjectiveLoc(locDB, imperatorCountries);

        void FillHolderAndGovernmentHistory()
        {
            // ------------------ determine previous and current holders
            // there was no 0 AD, but year 0 works in game and serves well for adding BC characters to holder history
            var firstPossibleDate = new Date(0, 1, 1);

            foreach (var impRulerTerm in ImperatorCountry.RulerTerms)
            {
                var rulerTerm = new RulerTerm(
                    impRulerTerm,
                    characters,
                    governmentMapper,
                    locDB,
                    religionMapper,
                    cultureMapper,
                    nicknameMapper,
                    provinceMapper
                    );

                var characterId = rulerTerm.CharacterId;
                var gov         = rulerTerm.Government;

                var startDate = new Date(rulerTerm.StartDate);
                if (startDate < firstPossibleDate)
                {
                    startDate = new Date(firstPossibleDate);                     // TODO: remove this workaround if CK3 supports negative dates
                    firstPossibleDate.ChangeByDays(1);
                }

                history.InternalHistory.AddFieldValue("holder", characterId, startDate, "holder");
                if (gov is not null)
                {
                    history.InternalHistory.AddFieldValue("government", gov, startDate, "government");
                }
            }

            if (ImperatorCountry.Government is not null)
            {
                var lastCK3TermGov = history.GetGovernment(conversionDate);
                var ck3CountryGov  = governmentMapper.GetCK3GovernmentForImperatorGovernment(ImperatorCountry.Government);
                if (lastCK3TermGov != ck3CountryGov && ck3CountryGov is not null)
                {
                    history.InternalHistory.AddFieldValue("government", ck3CountryGov, conversionDate, "government");
                }
            }
        }
    }