@@ -101,12 +101,7 @@ public void PurgeUnneededCharacters(CountryCollection countries, List<Governorsh
101101 Logger . Info ( "Purging unneeded Imperator characters..." ) ;
102102
103103 // All landed characters should be kept.
104- var allRulerIds = countries
105- . SelectMany ( country => country . RulerTerms . Select ( term => term . CharacterId ) )
106- . Where ( id => id is not null )
107- . Cast < ulong > ( ) ;
108- var allGovernorIds = governorships . Select ( g => g . CharacterId ) ;
109- var landedCharacterIds = allRulerIds . Concat ( allGovernorIds ) . ToFrozenSet ( ) ;
104+ FrozenSet < ulong > landedCharacterIds = GetLandedCharacterIds ( countries , governorships ) ;
110105
111106 // Alive and landed characters should be kept.
112107 Character [ ] charactersToCheck = [ .. this . Where ( character => character . IsDead && ! landedCharacterIds . Contains ( character . Id ) ) ] ;
@@ -157,12 +152,20 @@ public void PurgeUnneededCharacters(CountryCollection countries, List<Governorsh
157152 charactersToCheck = [ .. filteredCharactersToCheck ] ;
158153 }
159154 } while ( charactersToRemove . Count > 0 ) ;
160-
161- // At this point we may have families with no characters left.
162- // Let's purge them.
155+
156+ // At this point we may have families with no characters left. Purge them.
163157 families . PurgeUnneededFamilies ( this ) ;
164158 }
165159
160+ private static FrozenSet < ulong > GetLandedCharacterIds ( CountryCollection countries , List < Governorship > governorships ) {
161+ var allRulerIds = countries
162+ . SelectMany ( country => country . RulerTerms . Select ( term => term . CharacterId ) )
163+ . Where ( id => id is not null )
164+ . Cast < ulong > ( ) ;
165+ var allGovernorIds = governorships . Select ( g => g . CharacterId ) ;
166+ return allRulerIds . Concat ( allGovernorIds ) . ToFrozenSet ( ) ;
167+ }
168+
166169 private FrozenSet < ulong > GetFamilyIdsOfLandedCharacters ( FrozenSet < ulong > landedCharacterIds )
167170 {
168171 var result = new HashSet < ulong > ( ) ;
0 commit comments