Skip to content

Commit

Permalink
Fix the logic for handling invalid duchy capitals (#2461)
Browse files Browse the repository at this point in the history
Fixes the problem found in AEP, which as of version 0.8.2 has 2 duchies
with invalid capitals.
  • Loading branch information
IhateTrains authored Jan 21, 2025
1 parent 2a40c5c commit 3c05d96
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ImperatorToCK3/CK3/Titles/LandedTitles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,18 @@ public void LoadTitles(ModFilesystem ck3ModFS, CK3LocDB ck3LocDB) {
continue;
}
// Try to use the first valid capital of a de jure vassal.
var newCapitalId = title.DeJureVassals
.Select(v => v.CapitalCountyId)
.FirstOrDefault(vassalCapitalId => vassalCapitalId is not null && validTitleIds.Contains(vassalCapitalId));
string? newCapitalId;
if (title.Rank >= TitleRank.kingdom) {
newCapitalId = title.DeJureVassals
.Select(v => v.CapitalCountyId)
.FirstOrDefault(vassalCapitalId => vassalCapitalId is not null && validTitleIds.Contains(vassalCapitalId));
} else {
newCapitalId = title.DeJureVassals
.Where(v => v.Rank == TitleRank.county)
.Select(c => c.Id)
.FirstOrDefault();
}

// If not found, for landless titles try using capital of de jure liege.
if (newCapitalId is null && title.Landless) {
newCapitalId = title.DeJureLiege?.CapitalCountyId;
Expand Down

0 comments on commit 3c05d96

Please sign in to comment.