Skip to content

Commit

Permalink
Support for converting from the I:R "Terra Indomita" mod to the CK3 "…
Browse files Browse the repository at this point in the history
…Asia Expansion Project" mod (#2239) #minor
  • Loading branch information
IhateTrains authored Oct 8, 2024
1 parent 703ae81 commit cc0da92
Show file tree
Hide file tree
Showing 49 changed files with 19,924 additions and 10,846 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build_dev_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ jobs:
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
env:
GITHUB_REF: ${{ github.ref }}
- name: "Modify the branch name to be used in artifact name (Windows)"
if: runner.os == 'Windows'
run: echo "BRANCH_NAME=${BRANCH_NAME.Replace('/', '-').Replace('\', '-').Replace(':', '-').Replace('<', '-').Replace('>', '-').Replace('|', '-').Replace('*', '-').Replace('?', '-').Replace('\r', '-').Replace('\n', '-').Replace('/', '-').Replace('\\', '-')}" | Out-File -Append $env:GITHUB_ENV
- name: "Modify the branch name to be used in artifact name (Unix)"
if: runner.os != 'Windows'
# Invalid characters include: Double quote ", Colon :, Less than <, Greater than >, Vertical bar |, Asterisk *, Question mark ?, Carriage return \r, Line feed \n, Backslash \, Forward slash /
run: echo "BRANCH_NAME=${BRANCH_NAME//[^a-zA-Z0-9]/-}" >> $GITHUB_ENV

- name: Remove old artifacts
uses: ThreadsStyling/purge-artifacts-action@v1
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {

var tagTitleMapper = new TagTitleMapper();
var provinceMapper = new ProvinceMapper();
provinceMapper.LoadMappings(provinceMappingsPath, "test_version");
provinceMapper.LoadMappings(provinceMappingsPath);

var countryLocBlock = imperatorWorld.LocDB.AddLocBlock("PRY");
countryLocBlock["english"] = "Phrygian Empire"; // this ensures that the CK3 title will be an empire
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3.UnitTests/CK3/Provinces/ProvincesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public void PrimaryImperatorProvinceIsProperlyDeterminedForCK3Province() {
irWorld.Provinces.Add(irProvince6);

var provinceMapper = new ProvinceMapper();
const string provinceMappingsPath = "TestFiles/LandedTitlesTests/province_mappings.txt";
provinceMapper.LoadMappings(provinceMappingsPath, "6_to_1");
const string provinceMappingsPath = "TestFiles/LandedTitlesTests/province_mappings_6_to_1.txt";
provinceMapper.LoadMappings(provinceMappingsPath);

var ck3Provinces = new ProvinceCollection { new(1) };
var ck3RegionMapper = new CK3RegionMapper();
Expand Down
8 changes: 4 additions & 4 deletions ImperatorToCK3.UnitTests/CK3/Titles/LandedTitlesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {

var tagTitleMapper = new TagTitleMapper();
var provinceMapper = new ProvinceMapper();
provinceMapper.LoadMappings(provinceMappingsPath, "test_version");
provinceMapper.LoadMappings(provinceMappingsPath);
var irLocDB = new LocDB("english");
var ck3Religions = new ReligionCollection(titles);
var religionMapper = new ReligionMapper(ck3Religions, irRegionMapper, ck3RegionMapper);
Expand Down Expand Up @@ -387,7 +387,7 @@ public void DevelopmentIsCorrectlyCalculatedFor1ProvinceTo1BaronyCountyMapping()
irWorld.Provinces.Add(irProvince);

var provinceMapper = new ProvinceMapper();
provinceMapper.LoadMappings(provinceMappingsPath, "test_version");
provinceMapper.LoadMappings(provinceMappingsPath);

var ck3Provinces = new ProvinceCollection { new(1), new(2), new(3) };
var ck3RegionMapper = new CK3RegionMapper();
Expand Down Expand Up @@ -423,7 +423,7 @@ public void DevelopmentFromImperatorProvinceCanBeUsedForMultipleCK3Provinces() {
irWorld.Provinces.Add(irProvince);

var provinceMapper = new ProvinceMapper();
provinceMapper.LoadMappings("TestFiles/LandedTitlesTests/province_mappings_1_to_3.txt", "test_version");
provinceMapper.LoadMappings("TestFiles/LandedTitlesTests/province_mappings_1_to_3.txt");

var ck3Provinces = new ProvinceCollection { new(1), new(2), new(3) };
var ck3RegionMapper = new CK3RegionMapper();
Expand Down Expand Up @@ -461,7 +461,7 @@ public void DevelopmentOfCountyIsCalculatedFromAllCountyProvinces() {
irWorld.Provinces.Add(irProvince2);

var provinceMapper = new ProvinceMapper();
provinceMapper.LoadMappings(provinceMappingsPath, "test_version");
provinceMapper.LoadMappings(provinceMappingsPath);

var ck3Provinces = new ProvinceCollection { new(1), new(2), new(3) };
var ck3RegionMapper = new CK3RegionMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ namespace ImperatorToCK3.UnitTests.Mappers.Province;
[CollectionDefinition("Sequential", DisableParallelization = true)]
public class ProvinceMapperTests {
private const string TestFilesPath = "TestFiles/MapperTests/ProvinceMapper";
private const string MappingsVersionName = "test_version";

[Fact]
public void EmptyMappingsDefaultToEmpty() {
var mapper = new ProvinceMapper();
var mappingsPath = Path.Combine(TestFilesPath, "empty.txt");
mapper.LoadMappings(mappingsPath, "test_version");
mapper.LoadMappings(mappingsPath);

Assert.Empty(mapper.GetImperatorProvinceNumbers(1));
}
Expand All @@ -23,7 +22,7 @@ public void EmptyMappingsDefaultToEmpty() {
public void CanLookupImperatorProvinces() {
var mapper = new ProvinceMapper();
var mappingsPath = Path.Combine(TestFilesPath, "many_to_many.txt");
mapper.LoadMappings(mappingsPath, MappingsVersionName);
mapper.LoadMappings(mappingsPath);

Assert.Equal(2, mapper.GetImperatorProvinceNumbers(1).Count);
Assert.Equal((ulong)2, mapper.GetImperatorProvinceNumbers(1)[0]);
Expand All @@ -37,7 +36,7 @@ public void CanLookupImperatorProvinces() {
public void CanLookupCK3Provinces() {
var mapper = new ProvinceMapper();
var mappingsPath = Path.Combine(TestFilesPath, "many_to_many.txt");
mapper.LoadMappings(mappingsPath, MappingsVersionName);
mapper.LoadMappings(mappingsPath);

Assert.Equal(2, mapper.GetCK3ProvinceNumbers(1).Count);
Assert.Equal((ulong)2, mapper.GetCK3ProvinceNumbers(1)[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void GovernorshipToDeJureDuchyMappingFailsIfDuchyIsNot60PercentControlled

var provinceMapper = new ProvinceMapper();
const string provinceMappingsPath = "TestFiles/LandedTitlesTests/province_mappings.txt";
provinceMapper.LoadMappings(provinceMappingsPath, "test_version");
provinceMapper.LoadMappings(provinceMappingsPath);
Assert.Equal((ulong)1, provinceMapper.GetCK3ProvinceNumbers(1).First());
Assert.Equal((ulong)2, provinceMapper.GetCK3ProvinceNumbers(2).First());
Assert.Equal((ulong)3, provinceMapper.GetCK3ProvinceNumbers(3).First());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,3 @@ test_version = {
link={imp=5 ck3=5}
link={imp=6 ck3=6}
}

6_to_1 = {
link = {
imp = 1
imp = 2
imp = 3
imp = 4
imp = 5
imp = 6

ck3 = 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
6_to_1 = {
link = {
imp = 1
imp = 2
imp = 3
imp = 4
imp = 5
imp = 6

ck3 = 1
}
}
2 changes: 2 additions & 0 deletions ImperatorToCK3.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AD/@EntryIndexedValue">AD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AEP/@EntryIndexedValue">AEP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AI/@EntryIndexedValue">AI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BC/@EntryIndexedValue">BC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BOM/@EntryIndexedValue">BOM</s:String>
Expand All @@ -11,6 +12,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FS/@EntryIndexedValue">FS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IR/@EntryIndexedValue">IR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PDX/@EntryIndexedValue">PDX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TI/@EntryIndexedValue">TI</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=adjacencies/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Adnanite/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Alexandros/@EntryIndexedValue">True</s:Boolean>
Expand Down
47 changes: 33 additions & 14 deletions ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
config.CK3BookmarkDate = CorrectedDate;
}

LoadCorrectProvinceMappingsVersion(impWorld);

Logger.Info("Detecting selected CK3 mods...");
List<Mod> incomingCK3Mods = new();
foreach (var modPath in config.SelectedCK3Mods) {
Expand Down Expand Up @@ -117,6 +115,7 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
ColorFactory ck3ColorFactory = new();
// Now that we have the mod filesystem, we can initialize the localization database.
Parallel.Invoke(
() => LoadCorrectProvinceMappingsFile(impWorld), // Depends on loaded mods.
() => {
LocDB.LoadLocFromModFS(ModFS, config.GetActiveCK3ModFlags());
Logger.IncrementProgress();
Expand Down Expand Up @@ -219,19 +218,29 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac
foreach (var irReligionId in impWorld.Religions.Select(r => r.Id)) {
var baseMapping = religionMapper.Match(irReligionId, null, null, null, null, config);
if (baseMapping is null) {
Logger.Warn($"No base mapping found for I:R religion {irReligionId}!");
string religionStr = "ID: " + irReligionId;
var localizedName = impWorld.LocDB.GetLocBlockForKey(irReligionId)?["english"];
if (localizedName is not null) {
religionStr += $", name: {localizedName}";
}
Logger.Warn($"No base mapping found for I:R religion {religionStr}!");
}
}
},
() => { // depends on cultureMapper
// Check if all I:R cultures have a base mapping.
var irCultureIds = impWorld.CulturesDB.SelectMany(g => g.Select(c => c.Id));
foreach (var irCultureId in irCultureIds) {
var baseMapping = cultureMapper.Match(irCultureId, null, null, null);
if (baseMapping is null) {
Logger.Warn($"No base mapping found for I:R culture {irCultureId}!");
}
}
var baseMapping = cultureMapper.Match(irCultureId, null, null, null);
if (baseMapping is null) {
string cultureStr = "ID: " + irCultureId;
var localizedName = impWorld.LocDB.GetLocBlockForKey(irCultureId)?["english"];
if (localizedName is not null) {
cultureStr += $", name: {localizedName}";
}
Logger.Warn($"No base mapping found for I:R culture {cultureStr}!");
}
}
}
);

Expand Down Expand Up @@ -413,14 +422,24 @@ private void ImportImperatorWars(Imperator.World irWorld, Date ck3BookmarkDate)
Logger.IncrementProgress();
}

private void LoadCorrectProvinceMappingsVersion(Imperator.World imperatorWorld) {
var mappingsVersion = "imperator_invictus";
if (!imperatorWorld.GlobalFlags.Contains("is_playing_invictus")) {
private void LoadCorrectProvinceMappingsFile(Imperator.World imperatorWorld) {
string mappingsToUse;

bool irHasTI = imperatorWorld.Countries.Any(c => c.Variables.Contains("unification_points"));
bool ck3HasAEP = LoadedMods.Any(m => m.Name == "Asia Expansion Project");
if (irHasTI && ck3HasAEP) {
mappingsToUse = "terra_indomita_to_aep";
} else if (imperatorWorld.GlobalFlags.Contains("is_playing_invictus")) {
mappingsToUse = "imperator_invictus";
} else {
mappingsToUse = "imperator_vanilla";
Logger.Warn("Support for non-Invictus Imperator saves is deprecated.");
mappingsVersion = "imperator_vanilla";
}
Logger.Debug($"Using mappings version: {mappingsVersion}");
provinceMapper.LoadMappings("configurables/province_mappings.txt", mappingsVersion);

Logger.Info($"Using province mappings: {mappingsToUse}");
var mappingsPath = Path.Combine("configurables/province_mappings", mappingsToUse + ".txt");

provinceMapper.LoadMappings(mappingsPath);
}

private void LoadMenAtArmsTypes(ModFilesystem ck3ModFS, ScriptValueCollection scriptValues) {
Expand Down
20 changes: 18 additions & 2 deletions ImperatorToCK3/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public sealed class Configuration {
public LegionConversion LegionConversion { get; set; } = LegionConversion.MenAtArms;
public Date CK3BookmarkDate { get; set; } = new(0, 1, 1);
public bool SkipDynamicCoAExtraction { get; set; } = false;
public bool FallenEagleEnabled { get; set; }
public bool WhenTheWorldStoppedMakingSenseEnabled { get; set; }
public bool FallenEagleEnabled { get; private set; }
public bool WhenTheWorldStoppedMakingSenseEnabled { get; private set; }
public bool RajasOfAsiaEnabled { get; private set; }
public bool AsiaExpansionProjectEnabled { get; private set; }

public Configuration() { }
public Configuration(ConverterVersion converterVersion) {
Expand Down Expand Up @@ -316,13 +318,27 @@ public void DetectSpecificCK3Mods(ICollection<Mod> loadedMods) {
WhenTheWorldStoppedMakingSenseEnabled = true;
Logger.Info($"WtWSMS detected: {wtwsmsMod.Name}");
}

var roaMod = loadedMods.FirstOrDefault(m => m.Name.StartsWith("Rajas of Asia", StringComparison.Ordinal));
if (roaMod is not null) {
RajasOfAsiaEnabled = true;
Logger.Info($"RoA detected: {roaMod.Name}");
}

var aepMod = loadedMods.FirstOrDefault(m => m.Name.StartsWith("Asia Expansion Project", StringComparison.Ordinal));
if (aepMod is not null) {
AsiaExpansionProjectEnabled = true;
Logger.Info($"AEP detected: {aepMod.Name}");
}
}

/// <summary>Returns a collection of CK3 mod flags with values based on the enabled mods. "vanilla" flag is set to true if no other flags are set.</summary>
public OrderedDictionary<string, bool> GetCK3ModFlags() {
var flags = new OrderedDictionary<string, bool> {
["tfe"] = FallenEagleEnabled,
["wtwsms"] = WhenTheWorldStoppedMakingSenseEnabled,
["roa"] = RajasOfAsiaEnabled,
["aep"] = AsiaExpansionProjectEnabled,
};

flags["vanilla"] = flags.Count(f => f.Value) == 0;
Expand Down
Loading

0 comments on commit cc0da92

Please sign in to comment.