Skip to content

Commit

Permalink
Optimize the flattening of dynasties with no founders (#2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Sep 3, 2024
1 parent 61f4505 commit 2d0e0ef
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ImperatorToCK3/CK3/Dynasties/DynastyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,21 @@ public void FlattenDynastiesWithNoFounders(CharacterCollection characters, House
Logger.Info("Flattening dynasties with no founders...");
int count = 0;

var charactersWithDynastyIds = characters
.Select(c => (c, c.GetDynastyId(date)))
.Where(c => c.Item2 is not null)
.Select(c => (c.c, c.Item2!))
.ToArray();
var charactersWithHouseIds = characters
.Select(c => (c, c.GetDynastyHouseId(date)))
.Where(c => c.Item2 is not null)
.Select(c => (c.c, c.Item2!))
.ToArray();

foreach (var dynasty in this) {
var mainBranchMembers = characters.Where(c => c.GetDynastyId(date) == dynasty.Id).ToArray();
var mainBranchMembers = charactersWithDynastyIds
.Where(c => c.Item2 == dynasty.Id)
.ToArray();
if (mainBranchMembers.Length > 0) {
continue;
}
Expand All @@ -150,8 +163,9 @@ public void FlattenDynastiesWithNoFounders(CharacterCollection characters, House
.Where(h => h.DynastyId == dynasty.Id)
.Select(h => h.Id)
.ToArray();
var cadetHouseMembers = characters
.Where(c => dynastyHouseIds.Contains(c.GetDynastyHouseId(date)))
var cadetHouseMembers = charactersWithHouseIds
.Where(c => dynastyHouseIds.Contains(c.Item2))
.Select(c => c.c)
.ToArray();

if (cadetHouseMembers.Length == 0) {
Expand Down

0 comments on commit 2d0e0ef

Please sign in to comment.