Skip to content

Commit 51f5436

Browse files
committed
Merge branch 'master' into treasures
2 parents e251464 + 41b6ccf commit 51f5436

22 files changed

+674
-38
lines changed

Fronter.NET

Submodule Fronter.NET deleted from 5edf620

Fronter.NET

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7e8f6e4a8e49a8ad79abd2d7d1782e2f11aa44d5

ImperatorToCK3.UnitTests/ImperatorToCK3.UnitTests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="AwesomeAssertions" Version="8.0.0" />
15+
<PackageReference Include="AwesomeAssertions" Version="8.0.1" />
1616
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
<PrivateAssets>all</PrivateAssets>
1919
</PackageReference>
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
2121
<PackageReference Include="xunit" Version="2.9.3" />
22-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
22+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
<PrivateAssets>all</PrivateAssets>
2525
</PackageReference>

ImperatorToCK3/CK3/CK3LocDB.cs

+23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using commonItems.Localization;
44
using commonItems.Mods;
55
using ImperatorToCK3.CK3.Localization;
6+
using Murmur;
67
using System.Collections.Generic;
78
using System.IO;
89
using System.Linq;
@@ -83,6 +84,15 @@ public CK3LocBlock GetOrCreateLocBlock(string id) {
8384
return locBlock;
8485
}
8586

87+
// Check for hash collision.
88+
var murmur3A = MurmurHash.Create32();
89+
var hashStr = GetHashStrForKey(murmur3A, id);
90+
if (hashToKeyDict.TryGetValue(hashStr, out var existingKey)) {
91+
Logger.Warn($"Hash collision detected for loc key: {id}. Existing key: {existingKey}");
92+
} else {
93+
hashToKeyDict[hashStr] = id;
94+
}
95+
8696
// Create new loc block.
8797
locBlock = new CK3LocBlock(id, ConverterGlobals.PrimaryLanguage);
8898
Add(locBlock);
@@ -144,4 +154,17 @@ public List<string> GetLocLinesToOutputForLanguage(string language) {
144154

145155
return locLinesToOutput;
146156
}
157+
158+
public bool KeyHasConflictingHash(string key) {
159+
var murmur3A = MurmurHash.Create32();
160+
return hashToKeyDict.ContainsKey(GetHashStrForKey(murmur3A, key));
161+
}
162+
163+
private string GetHashStrForKey(Murmur32 murmur32, string key) {
164+
var keyBytes = System.Text.Encoding.UTF8.GetBytes(key);
165+
var hash = murmur32.ComputeHash(keyBytes);
166+
return string.Join("", hash.Select(b => b.ToString("X2")));
167+
}
168+
169+
private readonly Dictionary<string, string> hashToKeyDict = new(); // stores MurmurHash3A hash to key mapping
147170
}

ImperatorToCK3/CK3/Cultures/PillarCollection.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ private void InitPillarDataParser(ColorFactory colorFactory, OrderedDictionary<s
119119
}
120120
});
121121
pillarDataParser.RegisterKeyword("parameters", reader => {
122-
pillarData.Parameters = reader.GetAssignments()
123-
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
122+
pillarData.Parameters = reader.GetAssignmentsAsDict();
124123
});
125124
pillarDataParser.RegisterRegex(CommonRegexes.String, (reader, keyword) => {
126125
pillarData.Attributes.Add(new KeyValuePair<string, StringOfItem>(keyword, reader.GetStringOfItem()));

ImperatorToCK3/CK3/Dynasties/Dynasty.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public Dynasty(Family irFamily, CharacterCollection irCharacters, CulturesDB irC
3939

4040
public Dynasty(CK3.Characters.Character character, string irFamilyName, ImperatorCharacter[] irMembers, CulturesDB irCulturesDB, LocDB irLocDB, CK3LocDB ck3LocDB, Date date) {
4141
FromImperator = true;
42-
Id = $"dynn_irtock3_from_{character.Id}";
42+
43+
string id = $"dynn_irtock3_from_{character.Id}";
44+
uint counter = 0;
45+
while (ck3LocDB.KeyHasConflictingHash(id)) {
46+
id = $"dynn_irtock3_from_{character.Id}_{counter++}";
47+
}
48+
Id = id;
4349
Name = Id;
4450

4551
CultureId = character.GetCultureId(date) ?? character.Father?.GetCultureId(date);

ImperatorToCK3/CK3/Titles/LandedTitles.cs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1727,9 +1727,7 @@ public void LoadCulturalNamesFromConfigurables() {
17271727

17281728
var parser = new Parser();
17291729
parser.RegisterRegex(CommonRegexes.String, (reader, titleId) => {
1730-
var nameListToLocKeyDict = reader.GetAssignments()
1731-
.GroupBy(a => a.Key)
1732-
.ToDictionary(g => g.Key, g => g.Last().Value);
1730+
var nameListToLocKeyDict = reader.GetAssignmentsAsDict();
17331731

17341732
if (!TryGetValue(titleId, out var title)) {
17351733
return;
@@ -1762,5 +1760,20 @@ internal void SetCoatsOfArms(CoaMapper coaMapper) {
17621760

17631761
Logger.Debug($"Set coats of arms for {counter} CK3 titles.");
17641762
}
1763+
1764+
public void RemoveLiegeEntriesFromReligiousHeadHistory(ReligionCollection religions) {
1765+
var religiousHeadTitleIds = religions.Faiths
1766+
.Select(f => f.ReligiousHeadTitleId)
1767+
.Distinct()
1768+
.Where(id => id is not null)
1769+
.Select(id => id!);
1770+
foreach (var religiousHeadTitleId in religiousHeadTitleIds) {
1771+
if (!TryGetValue(religiousHeadTitleId, out var religiousHeadTitle)) {
1772+
continue;
1773+
}
1774+
1775+
religiousHeadTitle.History.Fields.Remove("liege");
1776+
}
1777+
}
17651778
}
17661779
}

ImperatorToCK3/CK3/Titles/Title.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1153,9 +1153,7 @@ private void RegisterKeys(Parser parser) {
11531153
parser.RegisterKeyword("de_jure_drift_disabled", reader => DeJureDriftDisabled = reader.GetBool());
11541154
parser.RegisterKeyword("can_be_named_after_dynasty", reader => CanBeNamedAfterDynasty = reader.GetBool());
11551155
parser.RegisterKeyword("male_names", reader => MaleNames = reader.GetStrings());
1156-
parser.RegisterKeyword("cultural_names", reader => CulturalNames = reader.GetAssignments()
1157-
.GroupBy(a => a.Key)
1158-
.ToDictionary(g => g.Key, g => g.Last().Value));
1156+
parser.RegisterKeyword("cultural_names", reader => CulturalNames = reader.GetAssignmentsAsDict());
11591157

11601158
parser.RegisterRegex(CommonRegexes.Catchall, (reader, token) => {
11611159
IgnoredTokens.Add(token);

ImperatorToCK3/CK3/World.cs

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
193193
Logger.Info("Loaded converter faiths.");
194194
Logger.IncrementProgress();
195195
Religions.RemoveChristianAndIslamicSyncretismFromAllFaiths();
196+
// Now that all the faiths are loaded, remove liege entries from the history of religious head titles.
197+
LandedTitles.RemoveLiegeEntriesFromReligiousHeadHistory(Religions);
196198

197199
Religions.LoadReplaceableHolySites("configurables/replaceable_holy_sites.txt");
198200
Logger.Info("Loaded replaceable holy sites.");
@@ -1147,6 +1149,8 @@ private void DetermineCK3Dlcs(Configuration config) {
11471149
{"dlc014.dlc", "roads_to_power"},
11481150
{"dlc015.dlc", "wandering_nobles"},
11491151
{"dlc016.dlc", "west_slavic_attire"},
1152+
{"dlc017.dlc", "medieval_monuments"},
1153+
{"dlc018.dlc", "arctic_attire"},
11501154
};
11511155

11521156
var dlcFiles = Directory.GetFiles(dlcFolderPath, "*.dlc", SearchOption.AllDirectories);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using commonItems;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace ImperatorToCK3.CommonUtils;
6+
7+
internal static class BufferedReaderExtensions {
8+
internal static Dictionary<string, string> GetAssignmentsAsDict(this BufferedReader reader) {
9+
return reader.GetAssignments()
10+
.GroupBy(a => a.Key)
11+
.ToDictionary(g => g.Key, g => g.Last().Value);
12+
}
13+
}

ImperatorToCK3/Data_Files/blankMod/output/common/culture/creation_names/IRToCK3_names.liquid

+16
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ anatolian = {
171171
}
172172
}
173173
}
174+
174175
euxinian = {
175176
name = euxinian
176177
trigger = {
@@ -200,6 +201,7 @@ euxinian = {
200201
}
201202
}
202203
}
204+
203205
hyperborean = {
204206
name = hyperborean
205207
trigger = {
@@ -223,3 +225,17 @@ hyperborean = {
223225
}
224226
}
225227
}
228+
229+
coptic = {
230+
trigger = {
231+
religion = religion:christianity
232+
culture = culture:ancient_egyptian
233+
any_sub_realm_county = {
234+
AND = {
235+
culture = culture:ancient_egyptian
236+
religion = religion:christianity
237+
}
238+
}
239+
}
240+
}
241+

0 commit comments

Comments
 (0)