Skip to content

Commit

Permalink
Compatch for CK3 1.13 (#2225) #major
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Sep 24, 2024
1 parent c730885 commit 7ec3b69
Show file tree
Hide file tree
Showing 23 changed files with 1,350 additions and 219 deletions.
34 changes: 34 additions & 0 deletions ImperatorToCK3.UnitTests/CommonUtils/HistoryTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using commonItems;
using commonItems.Collections;
using commonItems.Serialization;
using FluentAssertions;
using ImperatorToCK3.CommonUtils;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -201,6 +202,39 @@ public void ContainerFieldValueCanBeAdded() {
);
}

[Fact]
public void ConditionalOperatorIsSupported() {
var reader = new BufferedReader(
@"= {
domicile ?= { move_domicile = root.top_liege.capital_province }
culture ?= roman
insert ?= item1
750.1.2 = {
domicile ?= { move_domicile = root.capital_province }
culture ?= greek
remove ?= item1
insert ?= item2
}
}"
);

var provHistoryFactory = new HistoryFactory.HistoryFactoryBuilder()
.WithLiteralField("domicile", "domicile")
.WithSimpleField("culture", "culture", null)
.WithDiffField("diff_field", "insert", "remove")
.Build();

var provHistory = provHistoryFactory.GetHistory(reader);

Assert.Equal("{ move_domicile = root.top_liege.capital_province }", provHistory.GetFieldValue("domicile", new Date(1, 1, 1))?.ToString());
Assert.Equal("roman", provHistory.GetFieldValue("culture", new Date(1, 1, 1))!.ToString());
provHistory.GetFieldValueAsCollection("diff_field", new Date(1, 1, 1)).Should().BeEquivalentTo(["item1"]);

Assert.Equal("{ move_domicile = root.capital_province }", provHistory.GetFieldValue("domicile", new Date(750, 1, 2))?.ToString());
Assert.Equal("greek", provHistory.GetFieldValue("culture", new Date(750, 1, 2))!.ToString());
provHistory.GetFieldValueAsCollection("diff_field", new Date(750, 1, 2)).Should().BeEquivalentTo(["item2"]);
}

[Fact]
public void HistoryCanBeSerialized() {
var fields = new IdObjectCollection<string, IHistoryField> {
Expand Down
1 change: 1 addition & 0 deletions ImperatorToCK3/CK3/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public string? DeathReason {
.WithLiteralField("spawn_army", "spawn_army")
.WithLiteralField("if", "if")
.WithSimpleField("sexuality", "sexuality", null)
.WithLiteralField("domicile", "domicile")
.Build();

public History History { get; } = historyFactory.GetHistory();
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/CK3/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public void PurgeUnneededCharacters(Title.LandedTitles titles, DynastyCollection
Logger.Info("Purging unneeded characters...");

// Characters from CK3 that hold titles at the bookmark date should be kept.
var currentTitleHolderIds = titles.GetHolderIds(ck3BookmarkDate);
var currentTitleHolderIds = titles.GetHolderIdsForAllTitlesExceptNobleFamilyTitles(ck3BookmarkDate);
var landedCharacters = this
.Where(character => currentTitleHolderIds.Contains(character.Id))
.ToArray();
Expand Down Expand Up @@ -564,7 +564,7 @@ public void PurgeUnneededCharacters(Title.LandedTitles titles, DynastyCollection

public void RemoveEmployerIdFromLandedCharacters(Title.LandedTitles titles, Date conversionDate) {
Logger.Info("Removing employer id from landed characters...");
var landedCharacterIds = titles.GetHolderIds(conversionDate);
var landedCharacterIds = titles.GetHolderIdsForAllTitlesExceptNobleFamilyTitles(conversionDate);
foreach (var character in this.Where(character => landedCharacterIds.Contains(character.Id))) {
character.History.Fields["employer"].RemoveAllEntries();
}
Expand Down
6 changes: 4 additions & 2 deletions ImperatorToCK3/CK3/Titles/LandedTitles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,10 @@ public override void Remove(string name) {
return baronies.FirstOrDefault(b => provinceId == b?.ProvinceId, defaultValue: null);
}

public ImmutableHashSet<string> GetHolderIds(Date date) {
return this.Select(t => t.GetHolderId(date)).ToImmutableHashSet();
public ImmutableHashSet<string> GetHolderIdsForAllTitlesExceptNobleFamilyTitles(Date date) {
return this
.Where(t => t.NobleFamily != true)
.Select(t => t.GetHolderId(date)).ToImmutableHashSet();
}
public ImmutableHashSet<string> GetAllHolderIds() {
return this.SelectMany(t => t.GetAllHolderIds()).ToImmutableHashSet();
Expand Down
2 changes: 2 additions & 0 deletions ImperatorToCK3/CK3/Titles/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ public IDictionary<string, Title> GetDeFactoVassalsAndBelow(Date date, string ra
[SerializedName("destroy_if_invalid_heir")] public bool? DestroyIfInvalidHeir { get; set; }
[SerializedName("destroy_on_succession")] public bool? DestroyOnSuccession { get; set; }
[SerializedName("no_automatic_claims")] public bool? NoAutomaticClaims { get; set; }
[SerializedName("noble_family")] public bool? NobleFamily { get; set; }
[SerializedName("always_follows_primary_heir")] public bool? AlwaysFollowsPrimaryHeir { get; set; }
[SerializedName("de_jure_drift_disabled")] public bool? DeJureDriftDisabled { get; set; }
[SerializedName("can_be_named_after_dynasty")] public bool? CanBeNamedAfterDynasty { get; set; }
Expand Down Expand Up @@ -1104,6 +1105,7 @@ private void RegisterKeys(Parser parser) {
parser.RegisterKeyword("destroy_if_invalid_heir", reader => DestroyIfInvalidHeir = reader.GetBool());
parser.RegisterKeyword("destroy_on_succession", reader => DestroyOnSuccession = reader.GetBool());
parser.RegisterKeyword("no_automatic_claims", reader => NoAutomaticClaims = reader.GetBool());
parser.RegisterKeyword("noble_family", reader => NobleFamily = reader.GetBool());
parser.RegisterKeyword("always_follows_primary_heir", reader => AlwaysFollowsPrimaryHeir = reader.GetBool());
parser.RegisterKeyword("de_jure_drift_disabled", reader => DeJureDriftDisabled = reader.GetBool());
parser.RegisterKeyword("can_be_named_after_dynasty", reader => CanBeNamedAfterDynasty = reader.GetBool());
Expand Down
14 changes: 12 additions & 2 deletions ImperatorToCK3/CommonUtils/DiffHistoryField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,23 @@ public void AddEntryToHistory(Date? date, string keyword, object value) {
public void RegisterKeywords(Parser parser, Date date) {
foreach (var keyword in insertKeywords) {
parser.RegisterKeyword(keyword, reader => {
var value = HistoryFactory.GetValue(reader.GetString());
var valueStr = reader.GetString();
// If valueStr is the question sign from the "?=" operator, get another string.
if (valueStr == "?") {
valueStr = reader.GetString();
}
var value = HistoryFactory.GetValue(valueStr);
AddEntryToHistory(date, keyword, value);
});
}
foreach (var keyword in removeKeywords) {
parser.RegisterKeyword(keyword, reader => {
var value = HistoryFactory.GetValue(reader.GetString());
var valueStr = reader.GetString();
// If valueStr is the question sign from the "?=" operator, get another string.
if (valueStr == "?") {
valueStr = reader.GetString();
}
var value = HistoryFactory.GetValue(valueStr);
AddEntryToHistory(date, keyword, value);
});
}
Expand Down
27 changes: 22 additions & 5 deletions ImperatorToCK3/CommonUtils/HistoryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ private Parser GetParser(History history) {
parser.RegisterKeyword(setter, reader => {
// If the value is set outside of dated blocks, override the initial value.
var itemStr = reader.GetStringOfItem().ToString();
// If itemStr is the question sign from the "?=" operator, get another string.
if (itemStr == "?") {
itemStr = reader.GetStringOfItem().ToString();
}
var value = GetValue(itemStr);
history.Fields[def.FieldName].InitialEntries.Add(
Expand All @@ -72,28 +76,41 @@ private Parser GetParser(History history) {
foreach (var setter in def.Setters) {
parser.RegisterKeyword(setter, reader => {
// If the value is set outside of dated blocks, override the initial value.
var itemStr = reader.GetStringOfItem().ToString();
var value = GetValue(itemStr);
var itemStr = reader.GetStringOfItem();
// If itemStr is the question sign from the "?=" operator, get another string.
if (itemStr.ToString() == "?") {
itemStr = reader.GetStringOfItem();
}
history.Fields[def.FieldName].InitialEntries.Add(
new KeyValuePair<string, object>(setter, value)
new KeyValuePair<string, object>(setter, itemStr)
);
});
}
}
foreach (var def in this.diffFieldDefs) {
foreach (var inserterKeyword in def.Inserters) {
parser.RegisterKeyword(inserterKeyword, reader => {
var valueStr = reader.GetString();
// If valueStr is the question sign from the "?=" operator, get another string.
if (valueStr == "?") {
valueStr = reader.GetString();
}
var diffField = history.Fields[def.FieldName];
var valueToInsert = GetValue(reader.GetString());
var valueToInsert = GetValue(valueStr);
diffField.InitialEntries.Add(new KeyValuePair<string, object>(inserterKeyword, valueToInsert));
});
}

foreach (var removerKeyword in def.Removers) {
parser.RegisterKeyword(removerKeyword, reader => {
var valueStr = reader.GetString();
// If valueStr is the question sign from the "?=" operator, get another string.
if (valueStr == "?") {
valueStr = reader.GetString();
}
var diffField = history.Fields[def.FieldName];
var valueToRemove = GetValue(reader.GetString());
var valueToRemove = GetValue(valueStr);
diffField.InitialEntries.Add(new KeyValuePair<string, object>(removerKeyword, valueToRemove));
});
}
Expand Down
6 changes: 5 additions & 1 deletion ImperatorToCK3/CommonUtils/LiteralHistoryField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public void RegexReplaceAllEntries(Regex regex, string replacement) {
public void RegisterKeywords(Parser parser, Date date) {
foreach (var setter in setterKeywords) {
parser.RegisterKeyword(setter, reader => {
var itemStr = reader.GetStringOfItem().ToString();
var itemStr = reader.GetStringOfItem();
// If itemStr is the question sign from the "?=" operator, get another string.
if (itemStr.ToString() == "?") {
itemStr = reader.GetStringOfItem();
}
AddEntryToHistory(date, setter, itemStr);
});
}
Expand Down
4 changes: 4 additions & 0 deletions ImperatorToCK3/CommonUtils/SimpleHistoryField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public void RegisterKeywords(Parser parser, Date date) {
foreach (var setter in setterKeywords) {
parser.RegisterKeyword(setter, reader => {
var itemStr = reader.GetStringOfItem().ToString();
// If itemStr is the question sign from the "?=" operator, get another string.
if (itemStr == "?") {
itemStr = reader.GetStringOfItem().ToString();
}
var value = HistoryFactory.GetValue(itemStr);
AddEntryToHistory(date, setter, value);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ImperatorToCK3: Last updated CK3 patch 1.11.0.1
# ImperatorToCK3: Last updated CK3 patch 1.13.0

ToleranceValue = {
type = character
Expand Down Expand Up @@ -53,6 +53,59 @@ ToleranceValue = {
}
}

ToleranceValueConcept = {
type = character

text = {
localization_key = FAITH_HOSTILITY_RIGHTEOUS

trigger = {
faith = {
faith_hostility_level = {
target = scope:second.faith
value = faith_fully_accepted_level
}
}
}
}
text = {
localization_key = FAITH_HOSTILITY_ASTRAY

trigger = {
faith = {
faith_hostility_level = {
target = scope:second.faith
value = faith_astray_level
}
}
}
}
text = {
localization_key = FAITH_HOSTILITY_HOSTILE

trigger = {
faith = {
faith_hostility_level = {
target = scope:second.faith
value = faith_hostile_level
}
}
}
}
text = {
localization_key = FAITH_HOSTILITY_EVIL

trigger = {
faith = {
faith_hostility_level = {
target = scope:second.faith
value = faith_evil_level
}
}
}
}
}

MyPriestTitle = {
type = character

Expand Down Expand Up @@ -83,6 +136,24 @@ MyPriestTitle = {
}
}

PriestTitle = {
type = character

text = {
trigger = { is_female = no }
localization_key = male_priest_title
}
text = {
trigger = { is_female = yes }
localization_key = female_priest_title
}
text = {
trigger = { always = no }
localization_key = neuter_priest_title
fallback = yes
}
}

# For use when refering to a priest of unspecified gender, or the concept of priests in general.
DefaultPriestTitle = {
type = character
Expand Down Expand Up @@ -599,7 +670,7 @@ GetActualBishopTitle = {
}
text = {
trigger = {
is_landed = yes
is_playable_character = yes
}
localization_key = ruler_title_name
}
Expand Down
Loading

0 comments on commit 7ec3b69

Please sign in to comment.