Skip to content

Commit

Permalink
Don't convert to Administrative government if Roads to Power is missi…
Browse files Browse the repository at this point in the history
…ng (#2234) #patch
  • Loading branch information
IhateTrains committed Sep 26, 2024
1 parent b1a2894 commit 674a51c
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {
characters,
conversionDate,
config,
new List<KeyValuePair<Country, Dependency?>>());
new List<KeyValuePair<Country, Dependency?>>(),
enabledCK3Dlcs: []);

var provinces = new ProvinceCollection(ck3ModFS);
var ck3MapData = new MapData(ck3ModFS);
Expand Down
20 changes: 19 additions & 1 deletion ImperatorToCK3.UnitTests/CK3/Titles/LandedTitlesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,25 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
var ck3LocDB = new TestCK3LocDB();

// Import country 589.
titles.ImportImperatorCountries(imperatorWorld.Countries, imperatorWorld.Dependencies, tagTitleMapper, irLocDB, ck3LocDB, provinceMapper, coaMapper, new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()), new SuccessionLawMapper(), definiteFormMapper, religionMapper, cultureMapper, nicknameMapper, characters, conversionDate, config, new List<KeyValuePair<Country, Dependency?>>());
titles.ImportImperatorCountries(
imperatorWorld.Countries,
imperatorWorld.Dependencies,
tagTitleMapper,
irLocDB,
ck3LocDB,
provinceMapper,
coaMapper,
new GovernmentMapper(ck3GovernmentIds: Array.Empty<string>()),
new SuccessionLawMapper(),
definiteFormMapper,
religionMapper,
cultureMapper,
nicknameMapper,
characters,
conversionDate,
config,
new List<KeyValuePair<Country, Dependency?>>(),
enabledCK3Dlcs: []);
Assert.Collection(titles,
title => Assert.Equal("c_county1", title.Id),
title => Assert.Equal("b_barony1", title.Id),
Expand Down
6 changes: 4 additions & 2 deletions ImperatorToCK3.UnitTests/CK3/Titles/RulerTermTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public void ImperatorRulerTermIsCorrectlyConverted() {
new CultureMapper(irRegionMapper, ck3RegionMapper, new CultureCollection(new ColorFactory(), new PillarCollection(new ColorFactory(), []), [])),
new NicknameMapper("TestFiles/configurables/nickname_map.txt"),
new ProvinceMapper(),
new Configuration()
new Configuration(),
enabledCK3Dlcs: []
);
Assert.Equal("imperator69", ck3RulerTerm.CharacterId);
Assert.Equal(new Date(500, 2, 3, AUC: true), ck3RulerTerm.StartDate);
Expand Down Expand Up @@ -104,7 +105,8 @@ public void PreImperatorTermIsCorrectlyConverted() {
new CultureMapper(new BufferedReader("link = { ir=spartan ck3=greek }"), irRegionMapper, ck3RegionMapper, cultures),
new NicknameMapper("TestFiles/configurables/nickname_map.txt"),
new ProvinceMapper(),
new Configuration()
new Configuration(),
enabledCK3Dlcs: []
);
Assert.Equal("imperatorRegnalSPAAlexander504_1_1BC", ck3RulerTerm.CharacterId);
Assert.Equal(new Date(250, 1, 1, AUC: true), ck3RulerTerm.StartDate);
Expand Down
3 changes: 2 additions & 1 deletion ImperatorToCK3.UnitTests/CK3/Titles/TitleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public Title BuildFromTag() {
nicknameMapper,
characters,
ck3BookmarkDate,
config
config,
enabledCK3Dlcs: []
);
}
public TitleBuilder WithCountry(Country country) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ public class GovernmentMapperTests {
public void NonMatchGivesNull() {
var reader = new BufferedReader("link = { ck3 = ck3Government ir = irGovernment }");
var mapper = new GovernmentMapper(reader, ck3GovernmentIds: new List<string> { "ck3Government" });
var ck3Gov = mapper.GetCK3GovernmentForImperatorGovernment("nonMatchingGovernment", null);
var ck3Gov = mapper.GetCK3GovernmentForImperatorGovernment("nonMatchingGovernment", null, []);
Assert.Null(ck3Gov);
}
[Fact]
public void CK3GovernmentCanBeFound() {
var reader = new BufferedReader("link = { ck3 = ck3Government ir = irGovernment }");
var mapper = new GovernmentMapper(reader, ck3GovernmentIds: new List<string> { "ck3Government" });
var ck3Gov = mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", null);
var ck3Gov = mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", null, []);
Assert.Equal("ck3Government", ck3Gov);
}
[Fact]
public void MultipleImperatorGovernmentsCanBeInARule() {
var reader = new BufferedReader("link = { ck3 = ck3Government ir = irGovernment ir = irGovernment2 }");
var mapper = new GovernmentMapper(reader, ck3GovernmentIds: new List<string> { "ck3Government" });
var ck3Gov1 = mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", null);
var ck3Gov2 = mapper.GetCK3GovernmentForImperatorGovernment("irGovernment2", null);
var ck3Gov1 = mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", null, []);
var ck3Gov2 = mapper.GetCK3GovernmentForImperatorGovernment("irGovernment2", null, []);
Assert.Equal("ck3Government", ck3Gov1);
Assert.Equal("ck3Government", ck3Gov2);
}
Expand All @@ -36,7 +36,7 @@ public void CorrectRuleMatches() {
"link = { ck3 = ck3Government2 ir = irGovernment2 }"
);
var mapper = new GovernmentMapper(reader, ck3GovernmentIds: new List<string> { "ck3Government", "ck3Government2" });
var ck3Gov = mapper.GetCK3GovernmentForImperatorGovernment("irGovernment2", null);
var ck3Gov = mapper.GetCK3GovernmentForImperatorGovernment("irGovernment2", null, []);
Assert.Equal("ck3Government2", ck3Gov);
}

Expand All @@ -48,9 +48,29 @@ public void CultureCanBeUsedToMatch() {
"link = { ck3 = govC ir = irGovernment }"
);
var mapper = new GovernmentMapper(reader, ck3GovernmentIds: new List<string> { "govA", "govB", "govC" });
Assert.Equal("govA", mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", "roman"));
Assert.Equal("govB", mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", "greek"));
Assert.Equal("govC", mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", "thracian"));
Assert.Equal("govC", mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", null));
Assert.Equal("govA", mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", "roman", []));
Assert.Equal("govB", mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", "greek", []));
Assert.Equal("govC", mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", "thracian", []));
Assert.Equal("govC", mapper.GetCK3GovernmentForImperatorGovernment("irGovernment", null, []));
}

[Fact]
public void CK3DlcCanBeUsedToMatch() {
var reader = new BufferedReader(
"""
link = { ck3 = administrative_government
has_ck3_dlc = roads_to_power
ir = imperium
ir = imperial_cult
}
link = { ck3 = feudal_government
ir = imperium # When the user doesn't have the Roads to Power DLC.
ir = imperial_cult # When the user doesn't have the Roads to Power DLC.
}
""");
var mapper = new GovernmentMapper(reader, ck3GovernmentIds: [ "administrative_government", "feudal_government" ]);

Assert.Equal("administrative_government", mapper.GetCK3GovernmentForImperatorGovernment("imperium", null, enabledCK3Dlcs: ["roads_to_power"]));
Assert.Equal("feudal_government", mapper.GetCK3GovernmentForImperatorGovernment("imperium", null, enabledCK3Dlcs: []));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public void TitleCanBeMatchedFromGovernorship() {
new CharacterCollection(),
new Date(),
new Configuration(),
new List<KeyValuePair<Country, Dependency?>>()
new List<KeyValuePair<Country, Dependency?>>(),
enabledCK3Dlcs: []
);

irRegionMapper.Regions.Add(new ImperatorRegion("central_italy_region", new BufferedReader(), Areas, ColorFactory));
Expand Down Expand Up @@ -168,7 +169,8 @@ public void TitleCanBeGeneratedFromGovernorship() {
new CharacterCollection(),
new Date(),
new Configuration(),
new List<KeyValuePair<Country, Dependency?>>()
new List<KeyValuePair<Country, Dependency?>>(),
enabledCK3Dlcs: []
);

irRegionMapper.Regions.Add(new ImperatorRegion("apulia_region", new BufferedReader(), Areas, ColorFactory));
Expand Down Expand Up @@ -262,7 +264,8 @@ public void GovernorshipCanBeRegistered() {
new CharacterCollection(),
new Date(),
new Configuration(),
new List<KeyValuePair<Country, Dependency?>>()
new List<KeyValuePair<Country, Dependency?>>(),
enabledCK3Dlcs: []
);

var ck3Provinces = new ProvinceCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public async Task CoaIsOutputtedForCountryWithFlagSet() {
new CharacterCollection(),
new Date(400, 1, 1),
new Configuration(),
new List<KeyValuePair<Country, Dependency?>>()
new List<KeyValuePair<Country, Dependency?>>(),
enabledCK3Dlcs: []
);

await CoatOfArmsOutputter.OutputCoas(outputModPath, titles, new List<Dynasty>(), new CoaMapper());
Expand Down Expand Up @@ -119,7 +120,8 @@ public async Task CoaIsNotOutputtedForCountryWithoutFlagSet() {
new CharacterCollection(),
new Date(400, 1, 1),
new Configuration(),
new List<KeyValuePair<Country, Dependency?>>()
new List<KeyValuePair<Country, Dependency?>>(),
enabledCK3Dlcs: []
);

await CoatOfArmsOutputter.OutputCoas(outputModPath, titles, new List<Dynasty>(), new CoaMapper());
Expand Down
24 changes: 16 additions & 8 deletions ImperatorToCK3/CK3/Titles/LandedTitles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public Title Add(
NicknameMapper nicknameMapper,
CharacterCollection characters,
Date conversionDate,
Configuration config
Configuration config,
IReadOnlyCollection<string> enabledCK3Dlcs
) {
var newTitle = new Title(this,
country,
Expand All @@ -178,7 +179,8 @@ Configuration config
nicknameMapper,
characters,
conversionDate,
config
config,
enabledCK3Dlcs
);
dict[newTitle.Id] = newTitle;
return newTitle;
Expand Down Expand Up @@ -338,7 +340,8 @@ public void ImportImperatorCountries(
CharacterCollection characters,
Date conversionDate,
Configuration config,
List<KeyValuePair<Country, Dependency?>> countyLevelCountries
List<KeyValuePair<Country, Dependency?>> countyLevelCountries,
IReadOnlyCollection<string> enabledCK3Dlcs
) {
Logger.Info("Importing Imperator countries...");

Expand Down Expand Up @@ -372,7 +375,8 @@ public void ImportImperatorCountries(
characters,
conversionDate,
config,
countyLevelCountries
countyLevelCountries,
enabledCK3Dlcs
);
++counter;
}
Expand All @@ -395,7 +399,8 @@ public void ImportImperatorCountries(
characters,
conversionDate,
config,
countyLevelCountries
countyLevelCountries,
enabledCK3Dlcs
);
++counter;
}
Expand All @@ -420,7 +425,8 @@ private void ImportImperatorCountry(
CharacterCollection characters,
Date conversionDate,
Configuration config,
List<KeyValuePair<Country, Dependency?>> countyLevelCountries) {
List<KeyValuePair<Country, Dependency?>> countyLevelCountries,
IReadOnlyCollection<string> enabledCK3Dlcs) {
// Create a new title or update existing title.
var titleId = DetermineId(country, dependency, imperatorCountries, tagTitleMapper, irLocDB);

Expand All @@ -447,7 +453,8 @@ private void ImportImperatorCountry(
nicknameMapper,
characters,
conversionDate,
config
config,
enabledCK3Dlcs
);
} else {
Add(
Expand All @@ -467,7 +474,8 @@ private void ImportImperatorCountry(
nicknameMapper,
characters,
conversionDate,
config
config,
enabledCK3Dlcs
);
}
}
Expand Down
7 changes: 4 additions & 3 deletions ImperatorToCK3/CK3/Titles/RulerTerm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ImperatorToCK3.Mappers.Nickname;
using ImperatorToCK3.Mappers.Province;
using ImperatorToCK3.Mappers.Religion;
using System.Collections.Generic;

namespace ImperatorToCK3.CK3.Titles;

Expand All @@ -25,14 +26,14 @@ public RulerTerm(
CultureMapper cultureMapper,
NicknameMapper nicknameMapper,
ProvinceMapper provinceMapper,
Configuration config
) {
Configuration config,
IReadOnlyCollection<string> enabledCK3Dlcs) {
if (imperatorRulerTerm.CharacterId is not null) {
CharacterId = $"imperator{imperatorRulerTerm.CharacterId}";
}
StartDate = imperatorRulerTerm.StartDate;
if (imperatorRulerTerm.Government is not null) {
Government = governmentMapper.GetCK3GovernmentForImperatorGovernment(imperatorRulerTerm.Government, null);
Government = governmentMapper.GetCK3GovernmentForImperatorGovernment(imperatorRulerTerm.Government, null, enabledCK3Dlcs);
}

PreImperatorRuler = imperatorRulerTerm.PreImperatorRuler;
Expand Down
19 changes: 12 additions & 7 deletions ImperatorToCK3/CK3/Titles/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ private Title(LandedTitles parentCollection,
NicknameMapper nicknameMapper,
CharacterCollection characters,
Date conversionDate,
Configuration config
Configuration config,
IReadOnlyCollection<string> enabledCK3Dlcs
) {
IsCreatedFromImperator = true;
this.parentCollection = parentCollection;
Expand All @@ -84,7 +85,8 @@ Configuration config
nicknameMapper,
characters,
conversionDate,
config
config,
enabledCK3Dlcs
);
}
private Title(LandedTitles parentCollection,
Expand Down Expand Up @@ -188,7 +190,8 @@ public void InitializeFromTag(
NicknameMapper nicknameMapper,
CharacterCollection characters,
Date conversionDate,
Configuration config
Configuration config,
IReadOnlyCollection<string> enabledCK3Dlcs
) {
ImperatorCountry = country;
ImperatorCountry.CK3Title = this;
Expand All @@ -202,7 +205,7 @@ Configuration config

ClearHolderSpecificHistory();

FillHolderAndGovernmentHistory(country, characters, governmentMapper, irLocDB, ck3LocDB, religionMapper, cultureMapper, nicknameMapper, provinceMapper, config, conversionDate);
FillHolderAndGovernmentHistory(country, characters, governmentMapper, irLocDB, ck3LocDB, religionMapper, cultureMapper, nicknameMapper, provinceMapper, config, conversionDate, enabledCK3Dlcs);

// Determine color.
var color1Opt = ImperatorCountry.Color1;
Expand Down Expand Up @@ -299,7 +302,8 @@ private void FillHolderAndGovernmentHistory(Country imperatorCountry,
NicknameMapper nicknameMapper,
ProvinceMapper provinceMapper,
Configuration config,
Date conversionDate) {
Date conversionDate,
IReadOnlyCollection<string> enabledCK3Dlcs) {
// ------------------ determine previous and current holders

foreach (var impRulerTerm in imperatorCountry.RulerTerms) {
Expand All @@ -313,7 +317,8 @@ private void FillHolderAndGovernmentHistory(Country imperatorCountry,
cultureMapper,
nicknameMapper,
provinceMapper,
config
config,
enabledCK3Dlcs
);

var characterId = rulerTerm.CharacterId;
Expand All @@ -337,7 +342,7 @@ private void FillHolderAndGovernmentHistory(Country imperatorCountry,

if (imperatorCountry.Government is not null) {
var lastCK3TermGov = GetGovernment(conversionDate);
var ck3CountryGov = governmentMapper.GetCK3GovernmentForImperatorGovernment(imperatorCountry.Government, imperatorCountry.PrimaryCulture);
var ck3CountryGov = governmentMapper.GetCK3GovernmentForImperatorGovernment(imperatorCountry.Government, imperatorCountry.PrimaryCulture, enabledCK3Dlcs);
if (lastCK3TermGov != ck3CountryGov && ck3CountryGov is not null) {
History.AddFieldValue(conversionDate, "government", "government", ck3CountryGov);
}
Expand Down
Loading

0 comments on commit 674a51c

Please sign in to comment.