Skip to content

Commit

Permalink
More reliable marriage date estimation (#931) #patch
Browse files Browse the repository at this point in the history
* Estimate marriages to start 305 days before child's birth

* More reliable marriage date estimation
  • Loading branch information
IhateTrains authored Sep 2, 2022
1 parent 6ceac78 commit be07a5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void MarriageDateCanBeEstimatedFromChild() {
Assert.Collection(ck3Characters,
ck3Male => {
var marriageDate = ck3Male.History.Fields["spouses"].DateToEntriesDict.FirstOrDefault().Key;
Assert.Equal(new Date(899, 3, 7, AUC: true), marriageDate);
Assert.Equal(new Date(899, 3, 27, AUC: true), marriageDate);
},
ck3Female => {
Assert.Equal("imperator2", ck3Female.Id);
Expand Down Expand Up @@ -110,7 +110,7 @@ public void MarriageDateCanBeEstimatedFromUnbornChild() {

Assert.Collection(ck3Characters,
ck3Male => {
Assert.Equal(new Date(899, 3, 7, AUC: true),
Assert.Equal(new Date(899, 3, 27, AUC: true),
ck3Male.History.Fields["spouses"].DateToEntriesDict.FirstOrDefault().Key);
},
ck3Female => Assert.Equal("imperator2", ck3Female.Id)
Expand Down
32 changes: 19 additions & 13 deletions ImperatorToCK3/CK3/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,24 @@ private void LinkSpouses(Date conversionDate) {
Logger.Info($"{spouseCounter} spouses linked in CK3.");

Date GetEstimatedMarriageDate(Imperator.Characters.Character imperatorCharacter, Imperator.Characters.Character imperatorSpouse) {
// Imperator saves don't seem to store marriage date
// Imperator saves don't seem to store marriage date.

var marriageDeathDate = GetMarriageDeathDate(imperatorCharacter, imperatorSpouse);
var birthDateOfCommonChild = GetBirthDateOfFirstCommonChild(imperatorCharacter, imperatorSpouse);
if (birthDateOfCommonChild is not null) {
return birthDateOfCommonChild.ChangeByDays(-300); // we assume the child was conceived after marriage
}
if (imperatorCharacter.DeathDate is not null && imperatorSpouse.DeathDate is not null) {
Date marriageDeathDate;
if (imperatorCharacter.DeathDate < imperatorSpouse.DeathDate) {
marriageDeathDate = imperatorCharacter.DeathDate;
} else {
marriageDeathDate = imperatorSpouse.DeathDate;
// We assume the child was conceived after marriage.
var estimatedConceptionDate = birthDateOfCommonChild.ChangeByDays(-280);
if (marriageDeathDate is not null && marriageDeathDate < estimatedConceptionDate) {
estimatedConceptionDate = marriageDeathDate.ChangeByDays(-1);
}
return marriageDeathDate.ChangeByDays(-1); // death is not a good moment to marry
return estimatedConceptionDate;
}
if (imperatorCharacter.DeathDate is not null) {
return imperatorCharacter.DeathDate.ChangeByDays(-1);

if (marriageDeathDate is not null) {
return marriageDeathDate.ChangeByDays(-1); // Death is not a good moment to marry.
}
return imperatorSpouse.DeathDate is not null ? imperatorSpouse.DeathDate.ChangeByDays(-1) : conversionDate;

return conversionDate;
}
Date? GetBirthDateOfFirstCommonChild(Imperator.Characters.Character father, Imperator.Characters.Character mother) {
var childrenOfFather = father.Children.Values.ToHashSet();
Expand All @@ -186,6 +185,13 @@ Date GetEstimatedMarriageDate(Imperator.Characters.Character imperatorCharacter,
var unborns = mother.Unborns.Where(u => u.FatherId == father.Id).OrderBy(u => u.BirthDate).ToList();
return unborns.FirstOrDefault()?.BirthDate;
}

Date? GetMarriageDeathDate(Imperator.Characters.Character husband, Imperator.Characters.Character wife) {
if (husband.DeathDate is not null && wife.DeathDate is not null) {
return husband.DeathDate < wife.DeathDate ? husband.DeathDate : wife.DeathDate;
}
return husband.DeathDate ?? wife.DeathDate;
}
}

private void LinkPrisoners() {
Expand Down

0 comments on commit be07a5f

Please sign in to comment.