Skip to content

Commit 85a0fc0

Browse files
authored
Compatch for WtWSMS 0.1.8.5 (#3070) #minor
- Updated removable_file_blocks_wtwsms.txt for latest WtWSMS. - Added a separate province mappings file for Invictus -> WtWSMS conversions, needed at least until WtWSMS adds playable East Asia. - Disabled the East Asian Rome division regions for WtWSMS. - Fixed `k_xia` not having any de jure empire. Previously the converter tried to assign an empire based on the dominant heritage in the kingdom (Chinese), but because the Chinese heritage has intentionally no heritage->empire mapping, the kingdom was skipped. Now the converter iterates over all heritages in the kingdom (from dominant to least present) until a usable heritage is found. - Fixed Rome division regions to work with the WtWSMS de jure setup. Now the resulting empires are roughly the same as in a vanilla CK3 conversion. Here's a result for I:R Rome owning the entire map: <img width="1378" height="874" alt="obraz" src="https://github.com/user-attachments/assets/02bc2abd-375a-41e6-b2ab-df8d2b426371" /> <img width="1421" height="878" alt="obraz" src="https://github.com/user-attachments/assets/a03af871-c8b4-447f-a981-e0061e2daec1" /> closes #3056
1 parent b9d63f1 commit 85a0fc0

18 files changed

Lines changed: 6346 additions & 40 deletions

File tree

.github/workflows/build_dev_version.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ jobs:
5454
onlyPrefix: 'ImperatorToCK3-${{ matrix.build }}-dev-${{ env.BRANCH_NAME }}'
5555
- uses: actions/checkout@v6
5656
with:
57-
fetch-depth: 0
5857
submodules: recursive
5958
- name: "Setup Dotnet for use with actions"
6059
# don't run on self-hosted Windows

.github/workflows/integration_tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v6
2626
with:
27-
fetch-depth: 0
2827
submodules: recursive
2928
- name: "Check if docs folders exist"
3029
run: |

.github/workflows/spelling.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ jobs:
2323
**/*_l_polish.yml
2424
**/*_l_korean.yml
2525
**/*_l_german.yml
26+
ImperatorToCK3/Data_Files/configurables/province_mappings/invictus_to_wtwsms.txt
2627
2728

.github/workflows/steam_mod_update_notifier.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
check-steam-mod-updates:
1919
runs-on: ubuntu-latest
2020
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
2124
- name: Check Steam Workshop mods and notify
2225
shell: bash
2326
env:

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v6
1616
with:
17-
fetch-depth: 0
1817
submodules: recursive
1918
- name: "Setup Dotnet for use with actions"
2019
uses: actions/setup-dotnet@v5
@@ -54,7 +53,6 @@ jobs:
5453
steps:
5554
- uses: actions/checkout@v6
5655
with:
57-
fetch-depth: 0
5856
submodules: recursive
5957
- name: "Setup Dotnet for use with actions"
6058
# don't run on self-hosted Windows

ImperatorToCK3.UnitTests/CK3/Characters/CharacterCollectionTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {
273273
ruler_term={ character=1000 start_date=440.10.1 }
274274
");
275275
var country = Country.Parse(countryReader, 589);
276+
277+
imperatorWorld.Provinces[1].OwnerCountry = country;
278+
imperatorWorld.Provinces[2].OwnerCountry = country;
279+
imperatorWorld.Provinces[3].OwnerCountry = country;
280+
imperatorWorld.Provinces[4].OwnerCountry = country;
281+
imperatorWorld.Provinces[5].OwnerCountry = country;
282+
imperatorWorld.Provinces[6].OwnerCountry = country;
283+
276284
Assert.Equal(200, country.Currencies.Gold);
277285
imperatorWorld.Countries.Add(country);
278286
imperatorWorld.Characters.LinkCountries(imperatorWorld.Countries);
@@ -499,9 +507,9 @@ private static void SetPrivateProperty(object target, string propertyName, objec
499507
var targetType = target.GetType();
500508
var property = targetType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
501509
Assert.NotNull(property);
502-
var setter = property!.GetSetMethod(nonPublic: true);
510+
var setter = property.GetSetMethod(nonPublic: true);
503511
Assert.NotNull(setter);
504-
setter!.Invoke(target, new[] { value });
512+
setter.Invoke(target, [value]);
505513
}
506514

507515
private static ImperatorRulerTerm CreateRulerTerm(Date startDate, string governmentId) {

ImperatorToCK3.UnitTests/CK3/Titles/LandedTitlesTests.cs

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,22 +235,33 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
235235
var config = new Configuration { ImperatorPath = "TestFiles/LandedTitlesTests/Imperator" };
236236
var imperatorWorld = new TestImperatorWorld(config);
237237

238-
imperatorWorld.Provinces.Add(new Province(1));
239-
imperatorWorld.Provinces.Add(new Province(2));
240-
imperatorWorld.Provinces.Add(new Province(3));
238+
var irProv1 = new Province(1);
239+
var irProv2 = new Province(2);
240+
var irProv3 = new Province(3);
241+
imperatorWorld.Provinces.Add(irProv1);
242+
imperatorWorld.Provinces.Add(irProv2);
243+
imperatorWorld.Provinces.Add(irProv3);
241244

242245
var governor = new ImperatorToCK3.Imperator.Characters.Character(25212);
243246
imperatorWorld.Characters.Add(governor);
244247

245248
var countryReader = new BufferedReader("tag=PRY capital=1");
246249
var country = Country.Parse(countryReader, 589);
250+
irProv1.OwnerCountry = country;
251+
irProv2.OwnerCountry = country;
252+
irProv3.OwnerCountry = country;
253+
country.RegisterProvince(irProv1);
254+
country.RegisterProvince(irProv2);
255+
country.RegisterProvince(irProv3);
247256
imperatorWorld.Countries.Add(country);
248257

249258
imperatorWorld.Areas.LoadAreas(imperatorWorld.ModFS, imperatorWorld.Provinces);
250259
var irRegionMapper = new ImperatorRegionMapper(imperatorWorld.Areas, irMapData);
251260
irRegionMapper.LoadRegions(imperatorWorld.ModFS, new ColorFactory());
252261
Assert.True(irRegionMapper.RegionNameIsValid("galatia_area"));
253262
Assert.True(irRegionMapper.RegionNameIsValid("galatia_region"));
263+
Assert.True(irRegionMapper.ProvinceIsInRegion(2, "galatia_region"));
264+
Assert.True(irRegionMapper.ProvinceIsInRegion(3, "galatia_region"));
254265
var ck3RegionMapper = new CK3RegionMapper();
255266

256267
var reader = new BufferedReader(
@@ -335,14 +346,14 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
335346
title => Assert.Equal("d_IRTOCK3_PRY", title.Id)
336347
);
337348

338-
var provinces = new ProvinceCollection(ck3ModFS);
349+
var ck3Provinces = new ProvinceCollection(ck3ModFS);
339350
var ck3MapData = new MapData(ck3ModFS);
340351
ck3MapData.ProvinceDefinitions.Add(new(1));
341352
ck3MapData.ProvinceDefinitions.Add(new(2));
342353
ck3MapData.ProvinceDefinitions.Add(new(3));
343-
provinces.ImportImperatorProvinces(imperatorWorld, ck3MapData, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
354+
ck3Provinces.ImportImperatorProvinces(imperatorWorld, ck3MapData, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
344355
// Country 589 is imported as duchy-level title, so its governorship of galatia_region will be county level.
345-
titles.ImportImperatorGovernorships(imperatorWorld, provinces, tagTitleMapper, irLocDB, ck3LocDB, config, provinceMapper, definiteFormMapper, irRegionMapper, coaMapper, countyLevelGovernorships);
356+
titles.ImportImperatorGovernorships(imperatorWorld, ck3Provinces, tagTitleMapper, irLocDB, ck3LocDB, config, provinceMapper, definiteFormMapper, irRegionMapper, coaMapper, countyLevelGovernorships);
346357

347358
Assert.Collection(titles,
348359
title => Assert.Equal("c_county1", title.Id),
@@ -610,6 +621,68 @@ public void TitlesCanBeExpandedInOtherFiles() {
610621
Assert.Equal("c_karakorum", mongoliaKingdom.CapitalCountyId);
611622
}
612623

624+
[Fact]
625+
public void KingdomUsesNextDominantHeritageWhenMostDominantOneCannotProvideEmpire() {
626+
var date = new Date(867, 1, 1);
627+
var titles = new Title.LandedTitles();
628+
titles.LoadTitles(new BufferedReader(
629+
"e_mongolia = { }\n" +
630+
"k_test = {\n" +
631+
"\td_test = {\n" +
632+
"\t\tc_county1 = { b_barony1 = { province = 1 } }\n" +
633+
"\t\tc_county2 = { b_barony2 = { province = 2 } }\n" +
634+
"\t\tc_county3 = { b_barony3 = { province = 3 } }\n" +
635+
"\t}\n" +
636+
"}\n" +
637+
"k_xia = {\n" +
638+
"\td_xia = {\n" +
639+
"\t\tc_xia_county = { b_xia_barony = { province = 4 } }\n" +
640+
"\t}\n" +
641+
"}\n"
642+
), colorFactory);
643+
644+
var cultureCollection = new TestCK3CultureCollection();
645+
cultureCollection.GenerateTestCulture("han", "heritage_chinese");
646+
cultureCollection.GenerateTestCulture("mongol", "heritage_mongolic");
647+
648+
var characters = new CharacterCollection();
649+
var hanHolder1 = new Character("1", "Han Holder 1", new Date(800, 1, 1), characters);
650+
hanHolder1.SetCultureId("han", null);
651+
characters.Add(hanHolder1);
652+
653+
var hanHolder2 = new Character("2", "Han Holder 2", new Date(801, 1, 1), characters);
654+
hanHolder2.SetCultureId("han", null);
655+
characters.Add(hanHolder2);
656+
657+
var mongolHolder = new Character("3", "Mongol Holder", new Date(802, 1, 1), characters);
658+
mongolHolder.SetCultureId("mongol", null);
659+
characters.Add(mongolHolder);
660+
661+
titles["c_county1"].SetHolder(hanHolder1, date);
662+
titles["c_county2"].SetHolder(hanHolder2, date);
663+
titles["c_county3"].SetHolder(mongolHolder, date);
664+
titles["c_xia_county"].SetHolder(mongolHolder, date);
665+
666+
var heritageMapPath = Path.Combine("configurables", "heritage_empires_map.txt");
667+
var originalHeritageMap = File.Exists(heritageMapPath) ? File.ReadAllText(heritageMapPath) : null;
668+
Directory.CreateDirectory("configurables");
669+
File.WriteAllText(heritageMapPath,
670+
"heritage_chinese = none\n" +
671+
"heritage_mongolic = e_mongolia\n");
672+
673+
try {
674+
titles.SetDeJureKingdomsAndAbove(date, cultureCollection, characters, new MapData(ck3ModFS), new CK3RegionMapper(), new TestCK3LocDB());
675+
676+
Assert.Equal("e_mongolia", titles["k_test"].DeJureLiege?.Id);
677+
} finally {
678+
if (originalHeritageMap is null) {
679+
File.Delete(heritageMapPath);
680+
} else {
681+
File.WriteAllText(heritageMapPath, originalHeritageMap);
682+
}
683+
}
684+
}
685+
613686
[Fact]
614687
public void RemoveBreaksAllLinks() {
615688
var landedTitles = new Title.LandedTitles();

ImperatorToCK3/CK3/Titles/LandedTitles.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ IReadOnlyCollection<string> enabledCK3Dlcs
265265
return newTitle;
266266
}
267267

268-
internal Title Add(
268+
private Title Add(
269269
string id,
270270
Governorship governorship,
271271
Country country,
@@ -778,6 +778,11 @@ List<Governorship> countyLevelGovernorships
778778
// add new ones from Imperator governorships.
779779
var counter = 0;
780780
foreach (var governorship in governorships) {
781+
// Don't import if the governorship has no I:R provinces.
782+
if (governorship.GetIRProvinceCount(irWorld.Provinces) == 0) {
783+
continue;
784+
}
785+
781786
ImportImperatorGovernorship(
782787
governorship,
783788
this,
@@ -819,7 +824,8 @@ Configuration config
819824

820825
var id = DetermineId(governorship, titles, irProvinces, ck3Provinces, imperatorRegionMapper, tagTitleMapper, provinceMapper);
821826
if (id is null) {
822-
Logger.Warn($"Cannot convert {governorship.Region.Id} of country {country.Id}");
827+
Logger.Warn($"Cannot convert {governorship.Region.Id} of country {country.Id}. " +
828+
$"I:R provinces: {string.Join(", ", governorship.GetIRProvinces(irProvinces).Select(p => p.Id))}");
823829
return;
824830
}
825831

@@ -1388,21 +1394,23 @@ Date ck3BookmarkDate
13881394
}
13891395
kingdomToDominantHeritagesDict[kingdom.Id] = dominantHeritages;
13901396

1391-
var dominantHeritage = dominantHeritages[0];
1392-
1393-
if (heritageToEmpireDict.TryGetValue(dominantHeritage.Id, out var empire)) {
1394-
if (empire is null) {
1395-
// The heritage is not supposed to have an empire.
1396-
continue;
1397+
foreach (var dominantHeritage in dominantHeritages) {
1398+
if (heritageToEmpireDict.TryGetValue(dominantHeritage.Id, out var empire)) {
1399+
if (empire is null) {
1400+
// The heritage is not supposed to have an empire, try the next dominant heritage.
1401+
continue;
1402+
}
1403+
kingdom.DeJureLiege = empire;
1404+
break;
13971405
}
1398-
kingdom.DeJureLiege = empire;
1399-
} else {
1400-
// Create new de jure empire based on heritage.
1406+
1407+
// Create new de jure empire based on the first usable heritage.
14011408
var heritageEmpire = CreateEmpireForHeritage(dominantHeritage, ck3Cultures, ck3LocDB);
14021409
removableEmpireIds.Add(heritageEmpire.Id);
14031410

14041411
kingdom.DeJureLiege = heritageEmpire;
14051412
heritageToEmpireDict[dominantHeritage.Id] = heritageEmpire;
1413+
break;
14061414
}
14071415
}
14081416
}

ImperatorToCK3/CK3/World.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ private void ImportImperatorWars(Imperator.World irWorld, Date ck3BookmarkDate)
551551
private void LoadCorrectProvinceMappingsFile(Imperator.World irWorld, Configuration config) {
552552
// Terra Indomita mappings should be used if either TI or Antiquitas is detected.
553553
bool irHasTI = config.TerraIndomitaDetected;
554-
554+
555555
bool ck3HasRajasOfAsia = config.RajasOfAsiaEnabled;
556556
bool ck3HasAEP = config.AsiaExpansionProjectEnabled;
557557

@@ -562,6 +562,8 @@ private void LoadCorrectProvinceMappingsFile(Imperator.World irWorld, Configurat
562562
mappingsToUse = "terra_indomita_to_aep";
563563
} else if (irHasTI) {
564564
mappingsToUse = "terra_indomita_to_vanilla_ck3";
565+
} else if (config.WhenTheWorldStoppedMakingSenseEnabled) {
566+
mappingsToUse = "invictus_to_wtwsms";
565567
} else if (config is {InvictusDetected: true, Invictus1_7Detected: true}) {
566568
mappingsToUse = "invictus_1_7_to_vanilla_ck3";
567569
} else if (config.InvictusDetected) {

ImperatorToCK3/Configuration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using ImperatorToCK3.CommonUtils;
77
using System;
88
using System.Collections.Generic;
9-
using System.Globalization;
109
using System.IO;
1110
using System.Linq;
1211

0 commit comments

Comments
 (0)