Skip to content

Commit 82b1604

Browse files
authored
Remove all many-to-many province mappings (#2609)
The converter also logs a warning when such a mapping is found. closes #2435
1 parent 5c84ede commit 82b1604

File tree

6 files changed

+5510
-4565
lines changed

6 files changed

+5510
-4565
lines changed

ImperatorToCK3/CK3/Characters/CharacterCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public void LoadCharacterIDsToPreserve(Date ck3BookmarkDate) {
435435

436436
const string configurablePath = "configurables/ck3_characters_to_preserve.txt";
437437
var parser = new Parser();
438-
parser.RegisterRegex("keep_as_is", reader => {
438+
parser.RegisterKeyword("keep_as_is", reader => {
439439
var ids = reader.GetStrings();
440440
foreach (var id in ids) {
441441
if (!TryGetValue(id, out var character)) {

ImperatorToCK3/Data_Files/configurables/province_mappings/imperator_invictus.txt

Lines changed: 153 additions & 128 deletions
Large diffs are not rendered by default.

ImperatorToCK3/Data_Files/configurables/province_mappings/imperator_vanilla.txt

Lines changed: 5338 additions & 4430 deletions
Large diffs are not rendered by default.

ImperatorToCK3/Imperator/Diplomacy/War.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using commonItems;
22
using ImperatorToCK3.CommonUtils;
33
using System.Collections.Generic;
4+
using System.Text.RegularExpressions;
45

56
namespace ImperatorToCK3.Imperator.Diplomacy;
67

7-
internal sealed class War {
8+
internal sealed partial class War {
89
public Date StartDate { get; private set; } = new(1, 1, 1);
910
public bool Previous { get; private set; }
1011
public List<ulong> AttackerCountryIds { get; } = [];
@@ -23,7 +24,7 @@ static War() {
2324
parser.RegisterKeyword("defender", reader => {
2425
warToReturn.DefenderCountryIds.Add(reader.GetULong());
2526
});
26-
parser.RegisterRegex(WargoalTypeRegex, reader => {
27+
parser.RegisterRegex(wargoalTypeRegex, reader => {
2728
var wargoalParser = new Parser();
2829
wargoalParser.RegisterKeyword("type", typeReader =>
2930
warToReturn.WarGoal = typeReader.GetString()
@@ -43,10 +44,14 @@ public static War Parse(BufferedReader reader) {
4344
return warToReturn;
4445
}
4546

46-
// Wargoal types seem to be hardcoded, they don't need to be loaded from game files.
47-
private const string WargoalTypeRegex = "take_province|naval_superiority|superiority|enforce_military_access|independence";
47+
private static readonly Regex wargoalTypeRegex = WargoalTypeRegex();
4848

4949
private static readonly Parser parser = new();
5050
private static War warToReturn = new();
51-
public static IgnoredKeywordsSet IgnoredTokens { get; } = new();
51+
public static IgnoredKeywordsSet IgnoredTokens { get; } = [];
52+
53+
// Wargoal types seem to be hardcoded, they don't need to be loaded from game files.
54+
private const string WargoalTypeRegexStr = "take_province|naval_superiority|superiority|enforce_military_access|independence";
55+
[GeneratedRegex(WargoalTypeRegexStr, RegexOptions.Compiled)]
56+
private static partial Regex WargoalTypeRegex();
5257
}

ImperatorToCK3/Imperator/World.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ private void ParseSave(Configuration config, ConverterVersion converterVersion,
336336

337337
Thread? localCoaExtractThread = null;
338338

339-
parser.RegisterRegex(@"\bSAV\w*\b", _ => { });
339+
parser.RegisterRegex(SaveStartRegex(), _ => { });
340340
parser.RegisterKeyword("version", reader => VerifySaveVersion(converterVersion, reader));
341341
parser.RegisterKeyword("date", reader => LoadSaveDate(config, reader));
342342
parser.RegisterKeyword("enabled_dlcs", LogEnabledDLCs);
@@ -795,6 +795,8 @@ private static BufferedReader ProcessCompressedEncodedSave(string saveGamePath)
795795

796796
private readonly IgnoredKeywordsSet ignoredTokens = [];
797797

798+
[GeneratedRegex(@"\bSAV\w*\b")]
799+
private static partial Regex SaveStartRegex();
798800
[GeneratedRegex(@"^\S+=\s*\{[\s\S]*?^\}", RegexOptions.Multiline)]
799801
private static partial Regex FlagDefinitionRegex();
800802
[GeneratedRegex(@"\$[A-Z_]*\$")]

ImperatorToCK3/Mappers/Province/ProvinceMapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ private void CreateMappings(ProvinceMappingsVersion mappingsVersion) {
3737
continue;
3838
}
3939

40+
// We don't want many-to-many mappings.
41+
if (mapping.ImperatorProvinces.Count > 1 && mapping.CK3Provinces.Count > 1) {
42+
Logger.Warn($"Many-to-many province mapping found: {string.Join(", ", mapping.ImperatorProvinces)} -> {string.Join(", ", mapping.CK3Provinces)}");
43+
}
44+
4045
foreach (var impNumber in mapping.ImperatorProvinces) {
4146
if (impNumber != 0) {
4247
imperatorToCK3ProvinceMap.Add(impNumber, mapping.CK3Provinces);

0 commit comments

Comments
 (0)