Skip to content

Commit

Permalink
More tweaks for TFE
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Jan 14, 2025
1 parent 5296bda commit 66735c5
Show file tree
Hide file tree
Showing 6 changed files with 1,530 additions and 18 deletions.
3 changes: 2 additions & 1 deletion ImperatorToCK3/CK3/Characters/CharactersLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public void LoadCK3Characters(ModFilesystem ck3ModFS, Date bookmarkDate) {
];
string[] fieldsToClear = [
"friends", "best_friends", "lovers", "rivals", "nemesis",
"primary_title", "dna", "spawn_army",
"primary_title", "dna", "spawn_army", "add_character_modifier", "languages",
"claims",
];

var femaleCharacterIds = loadedCharacters.Where(c => c.Female).Select(c => c.Id).ToHashSet();
Expand Down
35 changes: 20 additions & 15 deletions ImperatorToCK3/CK3/Titles/LandedTitles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,28 @@ public void LoadTitles(ModFilesystem ck3ModFS, CK3LocDB ck3LocDB) {
// Cleanup for titles having invalid capital counties.
var validTitleIds = this.Select(t => t.Id).ToHashSet();
var placeholderCountyId = validTitleIds.Order().First(t => t.StartsWith("c_"));
foreach (var title in this) {
if (title.CapitalCountyId is null) {
foreach (var title in this.Where(t => t.Rank > TitleRank.county)) {
if (title.CapitalCountyId is null && !title.Landless) {
// For landed titles, the game will generate capitals.
continue;
}

if (!validTitleIds.Contains(title.CapitalCountyId)) {
// 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));
if (newCapitalId is not null) {
Logger.Debug($"Title {title.Id} has invalid capital county {title.CapitalCountyId}, replacing it with {newCapitalId}.");
title.CapitalCountyId = newCapitalId;
} else {
Logger.Warn($"Using placeholder county as capital for title {title.Id} with invalid capital county {title.CapitalCountyId}.");
title.CapitalCountyId = placeholderCountyId;
}
if (title.CapitalCountyId is not null && validTitleIds.Contains(title.CapitalCountyId)) {
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));
// If not found, for landless titles try using capital of de jure liege.
if (newCapitalId is null && title.Landless) {
newCapitalId = title.DeJureLiege?.CapitalCountyId;
}
if (newCapitalId is not null) {
Logger.Debug($"Title {title.Id} has invalid capital county {title.CapitalCountyId ?? "NULL"}, replacing it with {newCapitalId}.");
title.CapitalCountyId = newCapitalId;
} else {
Logger.Warn($"Using placeholder county as capital for title {title.Id} with invalid capital county {title.CapitalCountyId ?? "NULL"}.");
title.CapitalCountyId = placeholderCountyId;
}
}

Expand Down
Loading

0 comments on commit 66735c5

Please sign in to comment.