Skip to content

Commit 31084a6

Browse files
authored
Fix for governor-held titles preserving vanilla holders (#332) #patch
* Update commonItems.NET * Fix for governor-held titles preserving vanilla holders * Update Fronter
1 parent 9fe7686 commit 31084a6

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

Fronter

Submodule Fronter updated 1 file

ImperatorToCK3/CK3/Titles/Title.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ DefiniteFormMapper definiteFormMapper
9292

9393
PlayerCountry = ImperatorCountry.PlayerCountry;
9494

95+
ClearHolderSpecificHistory();
96+
9597
// ------------------ determine previous and current holders
96-
history.InternalHistory.SimpleFields.Remove("holder");
97-
history.InternalHistory.SimpleFields.Remove("government");
9898
// there was no 0 AD, but year 0 works in game and serves well for adding BC characters to holder history
9999
var firstPossibleDate = new Date(0, 1, 1);
100100

@@ -239,11 +239,14 @@ ImperatorRegionMapper imperatorRegionMapper
239239

240240
var impGovernor = imperatorCharacters[governorship.CharacterID];
241241
var normalizedStartDate = governorship.StartDate.Year > 0 ? governorship.StartDate : new Date(1, 1, 1);
242+
243+
ClearHolderSpecificHistory();
244+
242245
// ------------------ determine holder
243246
history.InternalHistory.AddSimpleFieldValue("holder", $"imperator{impGovernor.ID}", normalizedStartDate);
244247

245248
// ------------------ determine government
246-
var ck3LiegeGov = country.CK3Title.GetGovernment(governorship.StartDate);
249+
var ck3LiegeGov = country.CK3Title.GetGovernment(normalizedStartDate);
247250
if (ck3LiegeGov is not null) {
248251
history.InternalHistory.AddSimpleFieldValue("government", ck3LiegeGov, normalizedStartDate);
249252
}

ImperatorToCK3/CK3/World.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private void OverWriteCountiesHistory(List<Governorship> governorships, Date ck3
440440
Logger.Warn(nameof(ck3GovernorshipName) + $" is null for {ck3Country.Name} {governorship.RegionName}!");
441441
continue;
442442
}
443-
GiveCountryToGovernor(ck3BookmarkDate, title, ck3GovernorshipName);
443+
GiveCountyToGovernor(ck3BookmarkDate, title, ck3GovernorshipName);
444444
} else if (impMonarch is not null) {
445445
GiveCountyToMonarch(title, ck3Country, (ulong)impMonarch);
446446
}
@@ -458,12 +458,13 @@ void GiveCountyToMonarch(Title title, Title ck3Country, ulong impMonarch) {
458458
title.DeFactoLiege = null;
459459
}
460460

461-
void GiveCountryToGovernor(Date ck3BookmarkDate, Title title, string ck3GovernorshipName) {
461+
void GiveCountyToGovernor(Date ck3BookmarkDate, Title title, string ck3GovernorshipName) {
462462
var ck3Governorship = LandedTitles[ck3GovernorshipName];
463463
var holderId = ck3Governorship.GetHolderId(ck3BookmarkDate);
464464
if (Characters.TryGetValue(holderId, out var governor)) {
465465
title.ClearHolderSpecificHistory();
466-
title.SetHolderId(governor.ID, ck3Governorship.GetDateOfLastHolderChange());
466+
var date = ck3Governorship.GetDateOfLastHolderChange();
467+
title.SetHolderId(governor.ID, date);
467468
} else {
468469
Logger.Warn($"Holder {holderId} of county {title.Name} doesn't exist!");
469470
}

ImperatorToCK3/CommonUtils/History.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ public History(Dictionary<string, SimpleField> simpleFields, Dictionary<string,
2626
}
2727

2828
public void AddSimpleFieldValue(string fieldName, string value, Date date) {
29-
if (SimpleFields.ContainsKey(fieldName)) {
30-
SimpleFields[fieldName].AddValueToHistory(value, date);
31-
} else {
32-
var field = new SimpleField(null);
29+
if (SimpleFields.TryGetValue(fieldName, out var field)) {
3330
field.AddValueToHistory(value, date);
34-
SimpleFields.Add(fieldName, field);
31+
} else {
32+
var newField = new SimpleField(null);
33+
newField.AddValueToHistory(value, date);
34+
SimpleFields.Add(fieldName, newField);
3535
}
3636
}
3737
public void AddContainerFieldValue(string fieldName, List<string> value, Date date) {
38-
if (ContainerFields.ContainsKey(fieldName)) {
39-
ContainerFields[fieldName].AddValueToHistory(value, date);
40-
} else {
41-
var field = new ContainerField(new());
38+
if (ContainerFields.TryGetValue(fieldName, out var field)) {
4239
field.AddValueToHistory(value, date);
43-
ContainerFields.Add(fieldName, field);
40+
} else {
41+
var newField = new ContainerField(new());
42+
newField.AddValueToHistory(value, date);
43+
ContainerFields.Add(fieldName, newField);
4444
}
4545
}
4646
}

commonItems.NET

0 commit comments

Comments
 (0)