Skip to content

Commit

Permalink
Fix for governor-held titles preserving vanilla holders (#332) #patch
Browse files Browse the repository at this point in the history
* Update commonItems.NET

* Fix for governor-held titles preserving vanilla holders

* Update Fronter
  • Loading branch information
IhateTrains authored Oct 2, 2021
1 parent 9fe7686 commit 31084a6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Fronter
Submodule Fronter updated 1 files
+1 −1 build_linux.sh
9 changes: 6 additions & 3 deletions ImperatorToCK3/CK3/Titles/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ DefiniteFormMapper definiteFormMapper

PlayerCountry = ImperatorCountry.PlayerCountry;

ClearHolderSpecificHistory();

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

Expand Down Expand Up @@ -239,11 +239,14 @@ ImperatorRegionMapper imperatorRegionMapper

var impGovernor = imperatorCharacters[governorship.CharacterID];
var normalizedStartDate = governorship.StartDate.Year > 0 ? governorship.StartDate : new Date(1, 1, 1);

ClearHolderSpecificHistory();

// ------------------ determine holder
history.InternalHistory.AddSimpleFieldValue("holder", $"imperator{impGovernor.ID}", normalizedStartDate);

// ------------------ determine government
var ck3LiegeGov = country.CK3Title.GetGovernment(governorship.StartDate);
var ck3LiegeGov = country.CK3Title.GetGovernment(normalizedStartDate);
if (ck3LiegeGov is not null) {
history.InternalHistory.AddSimpleFieldValue("government", ck3LiegeGov, normalizedStartDate);
}
Expand Down
7 changes: 4 additions & 3 deletions ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ private void OverWriteCountiesHistory(List<Governorship> governorships, Date ck3
Logger.Warn(nameof(ck3GovernorshipName) + $" is null for {ck3Country.Name} {governorship.RegionName}!");
continue;
}
GiveCountryToGovernor(ck3BookmarkDate, title, ck3GovernorshipName);
GiveCountyToGovernor(ck3BookmarkDate, title, ck3GovernorshipName);
} else if (impMonarch is not null) {
GiveCountyToMonarch(title, ck3Country, (ulong)impMonarch);
}
Expand All @@ -458,12 +458,13 @@ void GiveCountyToMonarch(Title title, Title ck3Country, ulong impMonarch) {
title.DeFactoLiege = null;
}

void GiveCountryToGovernor(Date ck3BookmarkDate, Title title, string ck3GovernorshipName) {
void GiveCountyToGovernor(Date ck3BookmarkDate, Title title, string ck3GovernorshipName) {
var ck3Governorship = LandedTitles[ck3GovernorshipName];
var holderId = ck3Governorship.GetHolderId(ck3BookmarkDate);
if (Characters.TryGetValue(holderId, out var governor)) {
title.ClearHolderSpecificHistory();
title.SetHolderId(governor.ID, ck3Governorship.GetDateOfLastHolderChange());
var date = ck3Governorship.GetDateOfLastHolderChange();
title.SetHolderId(governor.ID, date);
} else {
Logger.Warn($"Holder {holderId} of county {title.Name} doesn't exist!");
}
Expand Down
20 changes: 10 additions & 10 deletions ImperatorToCK3/CommonUtils/History.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ public History(Dictionary<string, SimpleField> simpleFields, Dictionary<string,
}

public void AddSimpleFieldValue(string fieldName, string value, Date date) {
if (SimpleFields.ContainsKey(fieldName)) {
SimpleFields[fieldName].AddValueToHistory(value, date);
} else {
var field = new SimpleField(null);
if (SimpleFields.TryGetValue(fieldName, out var field)) {
field.AddValueToHistory(value, date);
SimpleFields.Add(fieldName, field);
} else {
var newField = new SimpleField(null);
newField.AddValueToHistory(value, date);
SimpleFields.Add(fieldName, newField);
}
}
public void AddContainerFieldValue(string fieldName, List<string> value, Date date) {
if (ContainerFields.ContainsKey(fieldName)) {
ContainerFields[fieldName].AddValueToHistory(value, date);
} else {
var field = new ContainerField(new());
if (ContainerFields.TryGetValue(fieldName, out var field)) {
field.AddValueToHistory(value, date);
ContainerFields.Add(fieldName, field);
} else {
var newField = new ContainerField(new());
newField.AddValueToHistory(value, date);
ContainerFields.Add(fieldName, newField);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion commonItems.NET

0 comments on commit 31084a6

Please sign in to comment.