Skip to content

Commit

Permalink
Don't try to set culture and religion for water provinces (#2110) #patch
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains authored Aug 22, 2024
1 parent 4a20b84 commit a6b0192
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ public void ImperatorCountriesGoldCanBeDistributedAmongRulerAndVassals() {
new List<KeyValuePair<Country, Dependency?>>());

var provinces = new ProvinceCollection(ck3ModFS);
provinces.ImportImperatorProvinces(imperatorWorld, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
var ck3MapData = new MapData(ck3ModFS);
provinces.ImportImperatorProvinces(imperatorWorld, ck3MapData, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);

titles.ImportImperatorGovernorships(
imperatorWorld,
Expand Down
6 changes: 4 additions & 2 deletions ImperatorToCK3.UnitTests/CK3/Provinces/ProvincesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ public void PrimaryImperatorProvinceIsProperlyDeterminedForCK3Province() {
var cultureMapper = new CultureMapper(irRegionMapper, ck3RegionMapper, cultures);
var religions = new ReligionCollection(titles);
var religionMapper = new ReligionMapper(religions, irRegionMapper, ck3RegionMapper);
ck3Provinces.ImportImperatorProvinces(irWorld, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
var ck3MapData = new MapData(ck3ModFs);
ck3MapData.ProvinceDefinitions.Add(new ProvinceDefinition(1) {});
ck3Provinces.ImportImperatorProvinces(irWorld, ck3MapData, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);

var targetProvince = ck3Provinces[1];
Assert.Equal((ulong)1, targetProvince.Id);
Expand All @@ -123,7 +125,7 @@ public void PrimaryImperatorProvinceIsProperlyDeterminedForCK3Province() {
// Scenario 2: Single developed province in country 2 outweighs sum of civilisation in country 1.
irProvince6.CivilizationValue = 100;
ck3Provinces = new ProvinceCollection { new(1) };
ck3Provinces.ImportImperatorProvinces(irWorld, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
ck3Provinces.ImportImperatorProvinces(irWorld, ck3MapData, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);

targetProvince = ck3Provinces[1];
Assert.Equal((ulong)1, targetProvince.Id);
Expand Down
24 changes: 20 additions & 4 deletions ImperatorToCK3.UnitTests/CK3/Titles/LandedTitlesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
);

var provinces = new ProvinceCollection(ck3ModFS);
provinces.ImportImperatorProvinces(imperatorWorld, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
var ck3MapData = new MapData(ck3ModFS);
ck3MapData.ProvinceDefinitions.Add(new(1));
ck3MapData.ProvinceDefinitions.Add(new(2));
ck3MapData.ProvinceDefinitions.Add(new(3));
provinces.ImportImperatorProvinces(imperatorWorld, ck3MapData, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
// Country 589 is imported as duchy-level title, so its governorship of galatia_region will be county level.
titles.ImportImperatorGovernorships(imperatorWorld, provinces, tagTitleMapper, irLocDB, ck3LocDB, config, provinceMapper, definiteFormMapper, irRegionMapper, coaMapper, countyLevelGovernorships);

Expand Down Expand Up @@ -372,7 +376,11 @@ public void DevelopmentIsCorrectlyCalculatedFor1ProvinceTo1BaronyCountyMapping()
var cultureMapper = new CultureMapper(irRegionMapper, ck3RegionMapper, cultures);
var religions = new ReligionCollection(titles);
var religionMapper = new ReligionMapper(religions, irRegionMapper, ck3RegionMapper);
ck3Provinces.ImportImperatorProvinces(irWorld, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
var ck3MapData = new MapData(ck3ModFS);
ck3MapData.ProvinceDefinitions.Add(new(1));
ck3MapData.ProvinceDefinitions.Add(new(2));
ck3MapData.ProvinceDefinitions.Add(new(3));
ck3Provinces.ImportImperatorProvinces(irWorld, ck3MapData, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);

var date = config.CK3BookmarkDate;
titles.ImportDevelopmentFromImperator(ck3Provinces, date, defaultConfig.ImperatorCivilizationWorth);
Expand Down Expand Up @@ -404,7 +412,11 @@ public void DevelopmentFromImperatorProvinceCanBeUsedForMultipleCK3Provinces() {
var cultureMapper = new CultureMapper(irRegionMapper, ck3RegionMapper, cultures);
var religions = new ReligionCollection(titles);
var religionMapper = new ReligionMapper(religions, irRegionMapper, ck3RegionMapper);
ck3Provinces.ImportImperatorProvinces(irWorld, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
var ck3MapData = new MapData(ck3ModFS);
ck3MapData.ProvinceDefinitions.Add(new(1));
ck3MapData.ProvinceDefinitions.Add(new(2));
ck3MapData.ProvinceDefinitions.Add(new(3));
ck3Provinces.ImportImperatorProvinces(irWorld, ck3MapData, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);

var date = config.CK3BookmarkDate;
titles.ImportDevelopmentFromImperator(ck3Provinces, date, defaultConfig.ImperatorCivilizationWorth);
Expand Down Expand Up @@ -438,7 +450,11 @@ public void DevelopmentOfCountyIsCalculatedFromAllCountyProvinces() {
var cultureMapper = new CultureMapper(irRegionMapper, ck3RegionMapper, cultures);
var religions = new ReligionCollection(titles);
var religionMapper = new ReligionMapper(religions, irRegionMapper, ck3RegionMapper);
ck3Provinces.ImportImperatorProvinces(irWorld, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);
var ck3MapData = new MapData(ck3ModFS);
ck3MapData.ProvinceDefinitions.Add(new(1));
ck3MapData.ProvinceDefinitions.Add(new(2));
ck3MapData.ProvinceDefinitions.Add(new(3));
ck3Provinces.ImportImperatorProvinces(irWorld, ck3MapData, titles, cultureMapper, religionMapper, provinceMapper, conversionDate, config);

var date = config.CK3BookmarkDate;
titles.ImportDevelopmentFromImperator(ck3Provinces, date, defaultConfig.ImperatorCivilizationWorth);
Expand Down
9 changes: 8 additions & 1 deletion ImperatorToCK3/CK3/Provinces/ProvinceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using commonItems.Collections;
using commonItems.Mods;
using ImperatorToCK3.CK3.Titles;
using ImperatorToCK3.CommonUtils.Map;
using ImperatorToCK3.Exceptions;
using ImperatorToCK3.Mappers.Culture;
using ImperatorToCK3.Mappers.Province;
Expand Down Expand Up @@ -104,6 +105,7 @@ public void ImportVanillaProvinces(ModFilesystem ck3ModFs) {

public void ImportImperatorProvinces(
Imperator.World irWorld,
MapData ck3MapData,
Title.LandedTitles titles,
CultureMapper cultureMapper,
ReligionMapper religionMapper,
Expand All @@ -115,8 +117,13 @@ Configuration config

int importedIRProvsCount = 0;
int modifiedCK3ProvsCount = 0;

var provinceDefs = ck3MapData.ProvinceDefinitions;
var landProvinces = this
.Where(p => provinceDefs.TryGetValue(p.Id, out var def) && def.IsLand);

// Imperator provinces map to a subset of CK3 provinces. We'll only rewrite those we are responsible for.
Parallel.ForEach(this, province => {
Parallel.ForEach(landProvinces, province => {
var sourceProvinceIds = provinceMapper.GetImperatorProvinceNumbers(province.Id);
// Provinces we're not affecting will not be in this list.
if (sourceProvinceIds.Count == 0) {
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public World(Imperator.World impWorld, Configuration config) {
Provinces.ImportVanillaProvinces(ModFS);

// Next we import Imperator provinces and translate them ontop a significant part of all imported provinces.
Provinces.ImportImperatorProvinces(impWorld, LandedTitles, cultureMapper, religionMapper, provinceMapper, CorrectedDate, config);
Provinces.ImportImperatorProvinces(impWorld, MapData, LandedTitles, cultureMapper, religionMapper, provinceMapper, CorrectedDate, config);
Provinces.LoadPrehistory();

var countyLevelGovernorships = new List<Governorship>();
Expand Down
Loading

0 comments on commit a6b0192

Please sign in to comment.