From c170c58c6fb44a4d524c5577aca559a35b020a4d Mon Sep 17 00:00:00 2001 From: Seweryn Presnal Date: Wed, 4 Sep 2024 22:11:22 +0200 Subject: [PATCH 1/2] Fix I:R holding owners getting baronies outside their counties --- ImperatorToCK3/CK3/Titles/LandedTitles.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ImperatorToCK3/CK3/Titles/LandedTitles.cs b/ImperatorToCK3/CK3/Titles/LandedTitles.cs index 049cc2183..85b2108eb 100644 --- a/ImperatorToCK3/CK3/Titles/LandedTitles.cs +++ b/ImperatorToCK3/CK3/Titles/LandedTitles.cs @@ -545,6 +545,10 @@ public void ImportImperatorHoldings(ProvinceCollection ck3Provinces, Imperator.C .Where(b => !titleCapitalBaronyIds.Contains(b.Id)) .ToImmutableHashSet(); + // In CK3, a county holder shouldn't own baronies in counties that are not their own. + // This dictionary tracks what counties are held by what characters. + Dictionary> countiesPerCharacter = []; // characterId -> countyIds + foreach (var barony in eligibleBaronies) { var ck3ProvinceId = barony.ProvinceId; if (ck3ProvinceId is null) { @@ -596,7 +600,23 @@ public void ImportImperatorHoldings(ProvinceCollection ck3Provinces, Imperator.C } county.SetHolder(ck3Owner, conversionDate); county.SetDeFactoLiege(deFactoLiege, conversionDate); + + if (!countiesPerCharacter.TryGetValue(ck3Owner.Id, out var countyIds)) { + countyIds = []; + countiesPerCharacter[ck3Owner.Id] = countyIds; + } + countyIds.Add(county.Id); } else { + var county = barony.DeJureLiege; + if (county is null) { + Logger.Warn($"Barony {barony.Id} has no de jure county!"); + continue; + } + // A non-capital barony cannot be held by a character that doesn't hold the county. + if (!countiesPerCharacter.TryGetValue(ck3Owner.Id, out var countyIds) || !countyIds.Contains(county.Id)) { + continue; + } + barony.SetHolder(ck3Owner, conversionDate); // No need to set de facto liege for baronies, they are tied to counties. } From 427cd498f3aa019adb0e977cfb3587d9739c4a08 Mon Sep 17 00:00:00 2001 From: Seweryn Presnal Date: Wed, 4 Sep 2024 22:14:05 +0200 Subject: [PATCH 2/2] change the fix logic --- ImperatorToCK3/CK3/Titles/LandedTitles.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ImperatorToCK3/CK3/Titles/LandedTitles.cs b/ImperatorToCK3/CK3/Titles/LandedTitles.cs index 85b2108eb..a302793c5 100644 --- a/ImperatorToCK3/CK3/Titles/LandedTitles.cs +++ b/ImperatorToCK3/CK3/Titles/LandedTitles.cs @@ -612,8 +612,8 @@ public void ImportImperatorHoldings(ProvinceCollection ck3Provinces, Imperator.C Logger.Warn($"Barony {barony.Id} has no de jure county!"); continue; } - // A non-capital barony cannot be held by a character that doesn't hold the county. - if (!countiesPerCharacter.TryGetValue(ck3Owner.Id, out var countyIds) || !countyIds.Contains(county.Id)) { + // A non-capital barony cannot be held by a character that owns a county but not the county the barony is in. + if (countiesPerCharacter.TryGetValue(ck3Owner.Id, out var countyIds) && !countyIds.Contains(county.Id)) { continue; }