Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ImperatorToCK3/CK3/Titles/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@
[SerializedName("posthumous_regnal_female_names")] public StringOfItem? PosthumousRegnalFemaleNames { get; private set; }
[SerializedName("personal_relation_entry")] public StringOfItem? PersonalRelationEntry { get; private set; }
[SerializedName("personal_relation_vassal")] public StringOfItem? PersonalRelationVassal { get; private set; }
[SerializedName("disable_regnal_numbers")] public bool? DisableRegnalNumbers { get; set; }

public int? GetOwnOrInheritedDevelopmentLevel(Date date) {
// Latest date (<= date) takes precedence.
Expand Down Expand Up @@ -1225,6 +1226,7 @@
parser.RegisterKeyword("posthumous_regnal_female_names", reader => PosthumousRegnalFemaleNames = reader.GetStringOfItem());
parser.RegisterKeyword("personal_relation_entry", reader => PersonalRelationEntry = reader.GetStringOfItem());
parser.RegisterKeyword("personal_relation_vassal", reader => PersonalRelationVassal = reader.GetStringOfItem());
parser.RegisterKeyword("disable_regnal_numbers", reader => DisableRegnalNumbers = reader.GetBool());

parser.RegisterRegex(CommonRegexes.Catchall, (reader, token) => {
IgnoredTokens.Add(token);
Expand Down Expand Up @@ -1526,62 +1528,62 @@
}
}

private void AppointCouncilMembersFromImperator(ReligionCollection religionCollection,
Dictionary<string, string[]> councilPositionToSourcesDict,
List<OfficeJob> convertibleJobs,
HashSet<string> alreadyEmployedCharacters,
Character ck3Ruler,
Date irSaveDate) {
Dictionary<string, int> heldTitlesPerCharacterCache = [];

foreach (var (ck3Position, sources) in councilPositionToSourcesDict) {
// The order of I:R source position types is important - the first filled one found will be used.
foreach (var sourceOfficeType in sources) {
var job = convertibleJobs.Find(o => o.OfficeType == sourceOfficeType);
if (job is null) {
continue;
}

var ck3Official = job.Character.CK3Character;
if (ck3Official is null || alreadyEmployedCharacters.Contains(ck3Official.Id)) {
continue;
}

// A ruler cannot be their own councillor.
if (ck3Official.Id == ck3Ruler.Id) {
continue;
}

if (!heldTitlesPerCharacterCache.TryGetValue(ck3Official.Id, out int heldTitlesCount)) {
heldTitlesCount = parentCollection.Count(t => t.GetHolderId(irSaveDate) == ck3Official.Id);
heldTitlesPerCharacterCache[ck3Official.Id] = heldTitlesCount;
}

if (ck3Position == "councillor_court_chaplain") {
if (!CanAppointAsCourtChaplain(religionCollection, ck3Ruler, ck3Official, irSaveDate, heldTitlesCount)) {
continue;
}
} else if (ck3Position == "councillor_steward" || ck3Position == "councillor_chancellor" || ck3Position == "councillor_marshal") {
if (!CanAppointAsStewardChancellorMarshal(religionCollection, ck3Ruler, ck3Official, irSaveDate, heldTitlesCount)) {
continue;
}
}

// We only need to set the employer when the council member is landless.
if (heldTitlesCount == 0) {
ck3Official.History.AddFieldValue(irSaveDate, "employer", "employer", ck3Ruler.Id);
}
ck3Official.History.AddFieldValue(irSaveDate, "council_position", "give_council_position", ck3Position);

// One character should only hold one CK3 position.
convertibleJobs.Remove(job);
alreadyEmployedCharacters.Add(ck3Official.Id);

break;
}
}
}

Check notice on line 1586 in ImperatorToCK3/CK3/Titles/Title.cs

View check run for this annotation

codefactor.io / CodeFactor

ImperatorToCK3/CK3/Titles/Title.cs#L1531-L1586

Complex Method
private static bool CanAppointAsCourtChaplain(ReligionCollection religionCollection, Character ck3Ruler, Character ck3Official, Date irSaveDate, int heldTitlesCount) {
// Court chaplains need to have the same faith as the ruler.
var rulerFaithId = ck3Ruler.GetFaithId(irSaveDate);
Expand Down
Loading