@@ -257,7 +257,7 @@ public ImmutableHashSet<string> GetAllHolderIds() {
257
257
return this . SelectMany ( t => t . GetAllHolderIds ( ) ) . ToImmutableHashSet ( ) ;
258
258
}
259
259
260
- public void RemoveInvalidHoldersFromHistory ( CharacterCollection characters ) {
260
+ public void CleanUpHistory ( CharacterCollection characters , Date ck3BookmarkDate ) {
261
261
Logger . Debug ( "Removing invalid holders from history..." ) ;
262
262
263
263
var validIds = characters . Select ( c => c . Id ) . ToImmutableHashSet ( ) ;
@@ -270,6 +270,31 @@ public void RemoveInvalidHoldersFromHistory(CharacterCollection characters) {
270
270
value => value . ToString ( ) is string valStr && valStr != "0" && ! validIds . Contains ( valStr )
271
271
) ;
272
272
}
273
+
274
+ // Remove liege entries that are not valid (liege title is not held at the entry date).
275
+ foreach ( var title in this ) {
276
+ if ( ! title . History . Fields . TryGetValue ( "liege" , out var liegeField ) ) {
277
+ continue ;
278
+ }
279
+
280
+ foreach ( var ( date , entriesList ) in liegeField . DateToEntriesDict . ToArray ( ) ) {
281
+ if ( entriesList . Count == 0 ) {
282
+ continue ;
283
+ }
284
+
285
+ var lastEntry = entriesList . Last ( ) ;
286
+ var liegeTitleId = lastEntry . Value . ToString ( ) ;
287
+ if ( liegeTitleId is null || liegeTitleId == "0" ) {
288
+ continue ;
289
+ }
290
+
291
+ if ( ! TryGetValue ( liegeTitleId , out var liegeTitle ) ) {
292
+ liegeField . DateToEntriesDict . Remove ( date ) ;
293
+ } else if ( liegeTitle . GetHolderId ( date ) == "0" ) {
294
+ liegeField . DateToEntriesDict . Remove ( date ) ;
295
+ }
296
+ }
297
+ }
273
298
}
274
299
275
300
public void ImportImperatorCountries (
0 commit comments