Skip to content

Commit bbfc388

Browse files
authored
Fix warning about GenerateSuccessorsForOldCharacters being too long (#3025) #patch
2 parents 83de929 + 3ca9554 commit bbfc388

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

ImperatorToCK3/CK3/Characters/CharacterCollection.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -795,25 +795,13 @@ internal void GenerateSuccessorsForOldCharacters(Title.LandedTitles titles, Cult
795795
oldCharactersWithoutTitles.Add(character);
796796
}
797797
}
798-
798+
799799
// For characters that don't hold any titles, just set up a death date.
800800
var randomForCharactersWithoutTitles = new Random((int)randomSeed);
801801
foreach (var oldCharacter in oldCharactersWithoutTitles) {
802-
// Roll a dice to determine how much longer the character will live.
803-
var monthsToLive = randomForCharactersWithoutTitles.Next(1, 30 * 12); // Can live up to 30 years more.
804-
805-
// If the character is female and pregnant, make sure she doesn't die before the pregnancy ends.
806-
if (oldCharacter is {Female: true, ImperatorCharacter: not null}) {
807-
var lastPregnancy = oldCharacter.Pregnancies.OrderBy(p => p.BirthDate).LastOrDefault();
808-
if (lastPregnancy is not null) {
809-
oldCharacter.DeathDate = lastPregnancy.BirthDate.ChangeByMonths(monthsToLive);
810-
continue;
811-
}
812-
}
813-
814-
oldCharacter.DeathDate = irSaveDate.ChangeByMonths(monthsToLive);
802+
SetUpDeathDateForCharacterWithoutTitles(oldCharacter, irSaveDate, randomForCharactersWithoutTitles);
815803
}
816-
804+
817805
var heldTitlesByHolderIdLists = new Dictionary<string, List<Title>>(StringComparer.Ordinal);
818806
foreach (var title in titles) {
819807
var holderId = title.GetHolderId(ck3BookmarkDate);
@@ -841,6 +829,22 @@ internal void GenerateSuccessorsForOldCharacters(Title.LandedTitles titles, Cult
841829
Parallel.ForEach(oldTitleHolders, oldCharacter => GenerateSuccessorsForCharacter(oldCharacter, titlesByHolderId, cultureIdToMaleNames, irSaveDate, ck3BookmarkDate, randomSeed));
842830
}
843831

832+
private void SetUpDeathDateForCharacterWithoutTitles(Character oldCharacter, Date irSaveDate, Random random) {
833+
// Roll a dice to determine how much longer the character will live.
834+
var monthsToLive = random.Next(1, 30 * 12); // Can live up to 30 years more.
835+
836+
// If the character is female and pregnant, make sure she doesn't die before the pregnancy ends.
837+
if (oldCharacter is {Female: true, ImperatorCharacter: not null}) {
838+
var lastPregnancy = oldCharacter.Pregnancies.OrderBy(p => p.BirthDate).LastOrDefault();
839+
if (lastPregnancy is not null) {
840+
oldCharacter.DeathDate = lastPregnancy.BirthDate.ChangeByMonths(monthsToLive);
841+
return;
842+
}
843+
}
844+
845+
oldCharacter.DeathDate = irSaveDate.ChangeByMonths(monthsToLive);
846+
}
847+
844848
private void GenerateSuccessorsForCharacter(Character oldCharacter, IReadOnlyDictionary<string, Title[]> titlesByHolderId,
845849
IReadOnlyDictionary<string, string[]> cultureIdToMaleNames, Date irSaveDate, Date ck3BookmarkDate, ulong randomSeed)
846850
{

0 commit comments

Comments
 (0)