Skip to content

Commit

Permalink
Fix for GetCultureIdForGeneratedHeadOfFaith logic
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Jan 18, 2025
1 parent 66b5488 commit 9dbcc03
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ImperatorToCK3/CK3/Religions/ReligionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ Date date
private static string GetCultureIdForGeneratedHeadOfFaith(Faith faith,
CharacterCollection characters,
ProvinceCollection provinces,
Title.LandedTitles titles,
CultureCollection cultures,
Date date) {
var cultureId = provinces
Expand All @@ -334,10 +335,20 @@ private static string GetCultureIdForGeneratedHeadOfFaith(Faith faith,
.FirstOrDefault();
if (cultureId is null) {
cultureId = characters
.Where(c => c.BirthDate <= date && (c.DeathDate is null || c.DeathDate > date))
.Where(c => c.GetFaithId(date) == faith.Id)
.Select(c => c.GetCultureId(date))
.FirstOrDefault();
}
if (cultureId is null && faith.ReligiousHeadTitleId is not null) {
if (titles.TryGetValue(faith.ReligiousHeadTitleId, out var title)) {
var capitalCounty = title.CapitalCounty;
var capitalProvince = capitalCounty?.CapitalBaronyProvinceId;
if (capitalProvince is not null) {
cultureId = provinces[capitalProvince.Value].GetCultureId(date);
}
}
}
if (cultureId is null) {
Logger.Warn($"Found no matching culture for religious head of {faith.Id}, using first one in database!");
cultureId = cultures.First().Id;
Expand Down Expand Up @@ -380,7 +391,7 @@ Date date
Logger.Debug($"Generating religious head for faith {faith.Id}...");

// Determine culture.
string cultureId = GetCultureIdForGeneratedHeadOfFaith(faith, characters, provinces, cultures, date);
string cultureId = GetCultureIdForGeneratedHeadOfFaith(faith, characters, provinces, titles, cultures, date);
if (!cultures.TryGetValue(cultureId, out var culture)) {
Logger.Warn($"Culture {cultureId} not found!");
return;
Expand Down

0 comments on commit 9dbcc03

Please sign in to comment.