Skip to content

Commit

Permalink
Fix valid subject vassalships being removed by history cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Oct 12, 2024
1 parent 6ba9f56 commit 69be9e4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ImperatorToCK3/CK3/Titles/LandedTitles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,20 @@ public void CleanUpHistory(CharacterCollection characters, Date ck3BookmarkDate)
if (!TryGetValue(liegeTitleId, out var liegeTitle)) {
liegeField.DateToEntriesDict.Remove(date);
} else if (liegeTitle.GetHolderId(date) == "0") {
liegeField.DateToEntriesDict.Remove(date);
// Instead of removing the liege entry, see if the liege title has a holder at a later date,
// and move the liege entry to that date.
liegeTitle.History.Fields.TryGetValue("holder", out var liegeHolderField);
Date? laterDate = liegeHolderField?.DateToEntriesDict.Keys
.Where(d => d > date && d <= ck3BookmarkDate)
.Min();

if (laterDate == null) {
liegeField.DateToEntriesDict.Remove(date);
} else {
var (setter, value) = liegeField.DateToEntriesDict[date].Last();
liegeField.DateToEntriesDict.Remove(date);
liegeField.AddEntryToHistory(laterDate, setter, value);
}
}
}
}
Expand Down

0 comments on commit 69be9e4

Please sign in to comment.