Skip to content

Commit 29fe944

Browse files
committed
Merge branch 'master' into variables-conversion
2 parents f5f68fa + f9e9f53 commit 29fe944

File tree

282 files changed

+52609
-25081
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

282 files changed

+52609
-25081
lines changed

.github/workflows/ck3-tiger.conf

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,33 @@ filter = {
9696
text = "missing english localization key d_kasi_adj"
9797
text = "missing english localization key d_pandya_nadu_adj"
9898
text = "missing english localization key d_ruhunu_adj"
99+
text = "missing english localization key d_xingyuan_adj"
100+
text = "missing english localization key d_lilang_adj"
101+
text = "missing english localization key d_baqu_adj"
102+
text = "missing english localization key d_dongchuan_adj"
103+
text = "missing english localization key d_lingnan_adj"
104+
text = "missing english localization key d_huixun_adj"
105+
text = "missing english localization key d_gaoliang_adj"
106+
text = "missing english localization key d_qiongguan_adj"
107+
text = "missing english localization key d_guiguan_adj"
108+
text = "missing english localization key d_jingjiang_adj"
109+
text = "missing english localization key d_rongguan_adj"
110+
text = "missing english localization key d_yongguan_adj"
111+
text = "missing english localization key d_hai_dong_adj"
112+
text = "missing english localization key d_nghe_an_adj"
113+
text = "missing english localization key d_lam_tay_adj"
114+
text = "missing english localization key d_thang_long_adj"
115+
text = "missing english localization key d_tonghai_adj"
116+
text = "missing english localization key d_tuodong_adj"
117+
text = "missing english localization key d_yinsheng_adj"
118+
text = "missing english localization key d_huichuan_adj"
119+
text = "missing english localization key d_jianchuan_adj"
120+
text = "missing english localization key d_dali_adj"
121+
text = "missing english localization key d_xiyuan_adj"
122+
text = "missing english localization key d_zangke_adj"
123+
text = "missing english localization key d_shimen_adj"
124+
text = "missing english localization key d_luoshi_adj"
125+
text = "missing english localization key d_luodian_adj"
99126
text = "missing english localization key k_mentese_adj"
100127
text = "missing english localization key k_mediterranean_sea_adj"
101128
text = "missing english localization key k_visigoths_adj"
@@ -106,6 +133,16 @@ filter = {
106133
text = "missing english localization key k_aydin_adj"
107134
text = "missing english localization key k_bihar_adj"
108135
text = "missing english localization key k_andhra_adj"
136+
text = "missing english localization key k_lingxi_adj"
137+
text = "missing english localization key k_viet_adj"
138+
text = "missing english localization key k_funan_adj"
139+
text = "missing english localization key k_chenla_adj"
140+
text = "missing english localization key k_champa_adj"
141+
text = "missing english localization key k_yongson_throne_adj"
142+
text = "missing english localization key k_sulawesi_adj"
143+
text = "missing english localization key k_lingnan_adj"
144+
text = "missing english localization key k_dali_adj"
145+
text = "missing english localization key k_qianzhong_adj"
109146
text = "missing english localization key e_rajastan_adj"
110147
text = "missing english localization key e_ilkhanate_adj"
111148
text = "missing english localization key e_chagatai_adj"
@@ -115,6 +152,11 @@ filter = {
115152
text = "missing english localization key e_togskol_khanate_adj"
116153
text = "missing english localization key e_baruun_khanate_adj"
117154
text = "missing english localization key e_mali_adj"
155+
text = "missing english localization key e_goryeo_adj"
156+
text = "missing english localization key e_nusantara_adj"
157+
text = "missing english localization key e_kambuja_adj"
158+
text = "missing english localization key e_suvarnabhumi_adj"
159+
text = "missing english localization key e_lingnan_adj"
118160
text = "missing english localization key d_laamp_" # ignores all missing adjectives for LAAMP titles
119161
text = "missing english localization key d_nf_" # ignores all missing adjectives for noble family titles
120162

@@ -180,6 +222,26 @@ filter = {
180222
text = "missing english localization key NEGOTIATE_LAND_DISTANCE_REASON"
181223
text = "missing english localization key hinduism_trickster_god_namepossessive"
182224
text = "missing english localization key urartuism_fertility_god_name_possessiv"
225+
226+
# vanilla problems as of CK3 1.18
227+
text = "missing english localization key Builder or Pious Builder"
228+
text = "missing english localization key lesser ruler, high medieval"
229+
text = "missing english localization key significant ruler, high medieval"
230+
text = "missing english localization key lesser ruler, high medieval"
231+
text = "missing english localization key lesser ruler, late medieval"
232+
text = "missing english localization key ai_directive"
233+
text = "missing english localization key default value"
234+
text = "subject contract flag meritocratic_province_protectorate not defined in common/subject_contracts/contracts/"
235+
text = "subject contract flag celestial_province_celestial not defined in common/subject_contracts/contracts/"
236+
text = "missing english localization key grand_marshal"
237+
text = "missing english localization key hunt_every_attendee_tt"
238+
text = "missing english localization key is_kampaku_tt"
239+
text = "missing english localization key ceremonial_liege_appointment_support_desc"
240+
text = "missing english localization key situation_parameter_era_type_chaotic"
241+
text = "missing english localization key situation_parameter_era_type_unstable"
242+
text = "missing english localization key situation_parameter_hide_in_phases_list"
243+
text = "missing english localization key situation_parameter_era_type_stable"
244+
text = "missing english localization key dynastic_cycle_situation_dynastic_cycle_phase_stability_situation_phase"
183245
}
184246
}
185247
}

.github/workflows/integration_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
echo 'CK3directory = "C:\Program Files (x86)\Steam\steamapps\common\Crusader Kings III"' >> configuration.txt
5151
echo 'targetGameModPath = "C:\Users\Administrator\Documents\Paradox Interactive\Crusader Kings III\mod"' >> configuration.txt
5252
echo 'SaveGame = "../../save.rome"' >> configuration.txt
53-
echo 'SkipDynamicCoAExtraction = 1' >> configuration.txt
53+
echo 'SkipDynamicCoAExtraction = yes' >> configuration.txt
5454
echo 'output_name = "test_save"' >> configuration.txt
5555
cat configuration.txt
5656
- name: "Run conversion"
@@ -60,7 +60,7 @@ jobs:
6060
6161
- name: "Download and unzip ck3-tiger"
6262
run: |
63-
Invoke-WebRequest -Uri "https://github.com/amtep/tiger/releases/download/v1.12.0/ck3-tiger-windows-v1.12.0.zip" -OutFile "ck3-tiger.zip"
63+
Invoke-WebRequest -Uri "https://github.com/amtep/tiger/releases/download/v1.16.0/ck3-tiger-windows-v1.16.0.zip" -OutFile "ck3-tiger.zip"
6464
Expand-Archive -Path "ck3-tiger.zip" -DestinationPath "ck3-tiger"
6565
Remove-Item -Path "ck3-tiger.zip"
6666

.github/workflows/spelling.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ jobs:
1313
locale: "US"
1414
reporter: github-pr-review
1515
level: warning
16+
ignore: councillor,favour,flavour,favourable,prioritised
17+
exclude: |
18+
**/*_l_french.yml
19+
**/*_l_italian.yml
20+
**/*_l_russian.yml
21+
**/*_l_simp_chinese.yml
22+
**/*_l_spanish.yml
23+
**/*_l_polish.yml
24+
**/*_l_korean.yml
25+
**/*_l_german.yml
26+
27+

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/ImperatorToCK3/obj/
2828
/Publish/
2929
/Output/
30+
/TestResults/
3031

3132
DocsGenerator/bin/
3233
DocsGenerator/obj/
@@ -43,3 +44,8 @@ validate-with-ck3-tiger.ps1
4344
result-error.txt
4445
result.txt
4546
validate-with-ck3-tiger_wtwsms.ps1
47+
previous-problem-count.txt
48+
49+
# Benchmark stuff
50+
/BenchmarkDotNet.Artifacts/
51+
/BenchmarkSuite1/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
/obj/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<LangVersion>latest</LangVersion>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="BenchmarkDotNet" Version="0.15.6" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\ImperatorToCK3\ImperatorToCK3.csproj" />
15+
</ItemGroup>
16+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using BenchmarkDotNet.Running;
2+
3+
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

ImperatorToCK3.UnitTests/CK3/Characters/CK3CharacterTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,19 +383,37 @@ public void NameCanBeInitializedFromImperator() {
383383
Name = "alexandros"
384384
};
385385

386-
var locDB = new LocDB("english");
387-
var nameLocBlock = locDB.AddLocBlock("alexandros");
386+
var irLocDB = new LocDB("english");
387+
var nameLocBlock = irLocDB.AddLocBlock("alexandros");
388388
nameLocBlock["english"] = "Alexandros";
389389

390390
var ck3LocDB = new TestCK3LocDB();
391391

392392
var character = builder
393393
.WithImperatorCharacter(imperatorCharacter)
394-
.WithIRLocDB(locDB)
394+
.WithIRLocDB(irLocDB)
395395
.WithCK3LocDB(ck3LocDB)
396396
.Build();
397397
Assert.Equal("alexandros", character.GetName(ConversionDate));
398398
Assert.Equal("Alexandros", ck3LocDB.GetLocBlockForKey("alexandros")!["english"]);
399+
400+
// Also check if names with escaped quotes are converted correctly.
401+
const string irCharacter2Input = """
402+
first_name_loc={
403+
name="Predrag \"Peja\" Stojaković"
404+
}
405+
""";
406+
imperatorCharacter = ImperatorToCK3.Imperator.Characters.Character.Parse(new BufferedReader(irCharacter2Input), "2", new GenesDB());
407+
character = builder
408+
.WithImperatorCharacter(imperatorCharacter)
409+
.WithIRLocDB(irLocDB)
410+
.WithCK3LocDB(ck3LocDB)
411+
.Build();
412+
string? irCharacter2NameLocKey = character.GetName(ConversionDate);
413+
Assert.NotNull(irCharacter2NameLocKey);
414+
Assert.Equal("irtock3_char_2", irCharacter2NameLocKey);
415+
Assert.Equal("Predrag \"Peja\" Stojaković", ck3LocDB.GetLocBlockForKey(irCharacter2NameLocKey)!["english"]);
416+
Assert.Equal($" {irCharacter2NameLocKey}: \"Predrag \\\"Peja\\\" Stojaković\"", ck3LocDB.GetYmlLocLineForLanguage(irCharacter2NameLocKey, "english"));
399417
}
400418

401419
[Fact]

ImperatorToCK3.UnitTests/CK3/Characters/CharacterCollectionTests.cs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using ImperatorToCK3.CK3.Provinces;
99
using ImperatorToCK3.CK3.Titles;
1010
using ImperatorToCK3.CommonUtils.Map;
11+
using ImperatorToCK3.CK3.Dynasties;
1112
using ImperatorToCK3.Imperator.Countries;
1213
using ImperatorToCK3.Imperator.Diplomacy;
1314
using ImperatorToCK3.Imperator.Geography;
@@ -30,6 +31,10 @@
3031
using Xunit;
3132
using System;
3233
using System.IO;
34+
using System.Globalization;
35+
using System.Reflection;
36+
using System.Text.RegularExpressions;
37+
using ImperatorRulerTerm = ImperatorToCK3.Imperator.Countries.RulerTerm;
3338

3439
namespace ImperatorToCK3.UnitTests.CK3.Characters;
3540

@@ -205,6 +210,31 @@ public void OnlyEarlyPregnanciesAreImportedFromImperator() {
205210
ck3Characters["imperator4"].Pregnancies.Should().BeEmpty();
206211
}
207212

213+
[Fact]
214+
public void RemoveInvalidDynastiesFromHistory_FiltersCorrectly() {
215+
var cc = new CharacterCollection();
216+
var date = new Date(1, 1, 1, AUC: true);
217+
var char1 = new Character("c1", "one", date, cc) { FromImperator = false };
218+
char1.History.Fields["dynasty"].InitialEntries.Add(new KeyValuePair<string, object>("dynasty", "valid"));
219+
char1.History.Fields["dynasty"].InitialEntries.Add(new KeyValuePair<string, object>("dynasty", ""));
220+
char1.History.Fields["dynasty"].InitialEntries.Add(new KeyValuePair<string, object>("dynasty", "invalid"));
221+
cc.AddOrReplace(char1);
222+
223+
var char2 = new Character("c2", "two", date, cc) { FromImperator = true };
224+
char2.History.Fields["dynasty"].InitialEntries.Add(new KeyValuePair<string, object>("dynasty", "valid"));
225+
cc.AddOrReplace(char2);
226+
227+
var dyns = new DynastyCollection();
228+
dyns.AddOrReplace(new Dynasty("valid", new BufferedReader("")));
229+
230+
cc.RemoveInvalidDynastiesFromHistory(dyns);
231+
232+
var entries = char1.History.Fields["dynasty"].InitialEntries.Select(kvp => kvp.Value.ToString()).ToList();
233+
entries.Should().Equal(new[] { "valid" });
234+
var entries2 = char2.History.Fields["dynasty"].InitialEntries.Select(kvp => kvp.Value.ToString()).ToList();
235+
entries2.Should().Equal(new[] { "valid" });
236+
}
237+
208238
[Fact]
209239
public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {
210240
var conversionDate = new Date(470, 2, 1, AUC: true);
@@ -410,4 +440,75 @@ public void ImperatorCharacterNamesCanBeOverriddenByConfigurable() {
410440
// Clean up.
411441
File.Delete(overridesFilePath);
412442
}
443+
444+
[Fact]
445+
public void ChineseDynasticCycleVariablesAreCorrectlyCalculatedForChineseEmpireCountryRulers() {
446+
Date ck3BookmarkDate = new(810, 1, 1);
447+
Date irEndDate = new(780, 1, 1);
448+
449+
var characters = new CharacterCollection();
450+
var holder = new Character("imperator_han_emperor", "Han Emperor", new Date(760, 1, 1), characters) {
451+
FromImperator = true
452+
};
453+
characters.Add(holder);
454+
455+
var landedTitles = new Title.LandedTitles();
456+
var celestialEmpire = landedTitles.Add("e_chinese_empire");
457+
celestialEmpire.SetHolder(holder, ck3BookmarkDate);
458+
459+
var imperatorCountry = new Country(1) { Tag = "HAN" };
460+
SetPrivateProperty(imperatorCountry, nameof(Country.Government), "chinese_empire");
461+
imperatorCountry.TotalPowerBase = 60f;
462+
imperatorCountry.NonLoyalPowerBase = 15f;
463+
464+
var precedingNonChineseStartDate = new Date(700, 3, 1);
465+
var earliestChineseStartDate = new Date(720, 6, 1);
466+
var laterChineseStartDate = new Date(760, 2, 1);
467+
468+
imperatorCountry.RulerTerms.Add(CreateRulerTerm(precedingNonChineseStartDate, "tribal"));
469+
imperatorCountry.RulerTerms.Add(CreateRulerTerm(earliestChineseStartDate, "chinese_empire"));
470+
imperatorCountry.RulerTerms.Add(CreateRulerTerm(laterChineseStartDate, "chinese_empire"));
471+
472+
imperatorCountry.CK3Title = celestialEmpire;
473+
SetPrivateProperty(celestialEmpire, nameof(Title.ImperatorCountry), imperatorCountry);
474+
475+
characters.CalculateChineseDynasticCycleVariables(landedTitles, irEndDate, ck3BookmarkDate);
476+
477+
var effectsField = holder.History.Fields["effects"];
478+
var effectEntry = Assert.Single(effectsField.DateToEntriesDict);
479+
Assert.Equal(ck3BookmarkDate, effectEntry.Key);
480+
var effectString = Assert.IsType<StringOfItem>(Assert.Single(effectEntry.Value).Value).ToString();
481+
482+
var expectedYearsWithGovernment = ck3BookmarkDate.DiffInYears(earliestChineseStartDate) + (earliestChineseStartDate.DiffInYears(precedingNonChineseStartDate) / 2);
483+
var expectedUnrest = imperatorCountry.NonLoyalPowerBase / imperatorCountry.TotalPowerBase;
484+
var effectLines = effectString.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
485+
var yearsLine = Assert.Single(effectLines, line => line.Contains("years_with_government", StringComparison.Ordinal));
486+
var yearsValue = ExtractVariableValue(yearsLine);
487+
Assert.Equal(expectedYearsWithGovernment, yearsValue, precision: 5);
488+
var unrestLine = Assert.Single(effectLines, line => line.Contains("imperator_unrest", StringComparison.Ordinal));
489+
var unrestValue = ExtractVariableValue(unrestLine);
490+
Assert.Equal(expectedUnrest, unrestValue, precision: 5);
491+
}
492+
493+
private static void SetPrivateProperty(object target, string propertyName, object? value) {
494+
var targetType = target.GetType();
495+
var property = targetType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
496+
Assert.NotNull(property);
497+
var setter = property!.GetSetMethod(nonPublic: true);
498+
Assert.NotNull(setter);
499+
setter!.Invoke(target, new[] { value });
500+
}
501+
502+
private static ImperatorRulerTerm CreateRulerTerm(Date startDate, string governmentId) {
503+
var term = new ImperatorRulerTerm();
504+
SetPrivateProperty(term, nameof(ImperatorRulerTerm.StartDate), startDate);
505+
SetPrivateProperty(term, nameof(ImperatorRulerTerm.Government), governmentId);
506+
return term;
507+
}
508+
509+
private static double ExtractVariableValue(string line) {
510+
var match = Regex.Match(line, "value\\s*=\\s*(?<value>[-+]?[0-9]*\\.?[0-9]+)");
511+
Assert.True(match.Success, $"Could not parse value from line '{line}'.");
512+
return double.Parse(match.Groups["value"].Value, CultureInfo.InvariantCulture);
513+
}
413514
}

0 commit comments

Comments
 (0)