private Title( LandedTitles parentCollection, Governorship governorship, Country country, Imperator.Characters.CharacterCollection imperatorCharacters, bool regionHasMultipleGovernorships, LocDB locDB, ProvinceMapper provinceMapper, CoaMapper coaMapper, TagTitleMapper tagTitleMapper, DefiniteFormMapper definiteFormMapper, ImperatorRegionMapper imperatorRegionMapper ) { this.parentCollection = parentCollection; Id = DetermineName(governorship, country, tagTitleMapper); SetRank(); InitializeFromGovernorship( governorship, country, imperatorCharacters, regionHasMultipleGovernorships, locDB, provinceMapper, definiteFormMapper, imperatorRegionMapper ); }
public Title Add( Governorship governorship, Country country, Imperator.Characters.CharacterCollection imperatorCharacters, bool regionHasMultipleGovernorships, LocDB locDB, ProvinceMapper provinceMapper, CoaMapper coaMapper, TagTitleMapper tagTitleMapper, DefiniteFormMapper definiteFormMapper, ImperatorRegionMapper imperatorRegionMapper ) { var newTitle = new Title(this, governorship, country, imperatorCharacters, regionHasMultipleGovernorships, locDB, provinceMapper, coaMapper, tagTitleMapper, definiteFormMapper, imperatorRegionMapper ); dict[newTitle.Id] = newTitle; return(newTitle); }
public void LoadingBrokenAreaWillThrowException() { const string imperatorPath = "TestFiles/ImperatorRegionMapper/test1"; var mods = new List <Mod>(); Assert.Throws <KeyNotFoundException>(() => _ = new ImperatorRegionMapper(imperatorPath, mods)); }
public void LoadRegionMappers(ImperatorRegionMapper imperatorRegionMapper, CK3RegionMapper ck3RegionMapper) { foreach (var mapping in religionMappings) { mapping.ImperatorRegionMapper = imperatorRegionMapper; mapping.CK3RegionMapper = ck3RegionMapper; } }
public void LocationServicesFailForNonsense() { const string imperatorPath = "TestFiles/ImperatorRegionMapper/test4"; var mods = new List <Mod>(); var theMapper = new ImperatorRegionMapper(imperatorPath, mods); Assert.False(theMapper.ProvinceIsInRegion(1, "nonsense")); }
public void LoadRegionMappers(ImperatorRegionMapper imperatorRegionMapper, CK3RegionMapper ck3RegionMapper) { foreach (var mapping in cultureMappingRules) { mapping.ImperatorRegionMapper = imperatorRegionMapper; mapping.CK3RegionMapper = ck3RegionMapper; } }
public void LocationServicesWork() { const string imperatorPath = "TestFiles/ImperatorRegionMapper/test2"; var mods = new List <Mod>(); var theMapper = new ImperatorRegionMapper(imperatorPath, mods); Assert.True(theMapper.ProvinceIsInRegion(3, "test_area")); Assert.True(theMapper.ProvinceIsInRegion(3, "test_region")); }
public void WrongParentLocationsReturnNull() { const string imperatorPath = "TestFiles/ImperatorRegionMapper/test6"; var mods = new List <Mod>(); var theMapper = new ImperatorRegionMapper(imperatorPath, mods); Assert.Null(theMapper.GetParentAreaName(5)); Assert.Null(theMapper.GetParentRegionName(5)); }
public void RegionMapperCanBeEnabled() { // We start humble, it's a machine. var theMapper = new ImperatorRegionMapper(); Assert.False(theMapper.ProvinceIsInRegion(1, "test")); Assert.False(theMapper.RegionNameIsValid("test")); Assert.Null(theMapper.GetParentAreaName(1)); Assert.Null(theMapper.GetParentRegionName(1)); }
public void LoadingBrokenAreaWillThrowException() { var theMapper = new ImperatorRegionMapper(); var areaReader = new BufferedReader(string.Empty); var regionReader = new BufferedReader( "test_region = { areas = { testarea } }" ); Assert.Throws <KeyNotFoundException>(() => theMapper.LoadRegions(areaReader, regionReader)); }
public void LocationServicesCorrectlyFail() { const string imperatorPath = "TestFiles/ImperatorRegionMapper/test3"; var mods = new List <Mod>(); var theMapper = new ImperatorRegionMapper(imperatorPath, mods); Assert.False(theMapper.ProvinceIsInRegion(3, "test_area2")); // province in different area Assert.False(theMapper.ProvinceIsInRegion(9, "test_region")); // province in different region Assert.False(theMapper.ProvinceIsInRegion(9, "test_region")); // province missing completely }
public void CorrectParentLocationsReported() { const string imperatorPath = "TestFiles/ImperatorRegionMapper/test5"; var mods = new List <Mod>(); var theMapper = new ImperatorRegionMapper(imperatorPath, mods); Assert.Equal("test_area", theMapper.GetParentAreaName(2)); Assert.Equal("test_region", theMapper.GetParentRegionName(2)); Assert.Equal("test_area2", theMapper.GetParentAreaName(5)); Assert.Equal("test_region2", theMapper.GetParentRegionName(5)); }
public void LocationServicesWork() { var theMapper = new ImperatorRegionMapper(); var areaReader = new BufferedReader("test_area = { provinces = { 1 2 3 } }\n"); var regionReader = new BufferedReader("test_region = { areas = { test_area } }\n"); theMapper.LoadRegions(areaReader, regionReader); Assert.True(theMapper.ProvinceIsInRegion(3, "test_area")); Assert.True(theMapper.ProvinceIsInRegion(3, "test_region")); }
public void LocationNameValidationWorks() { const string imperatorPath = "TestFiles/ImperatorRegionMapper/test7"; var mods = new List <Mod>(); var theMapper = new ImperatorRegionMapper(imperatorPath, mods); Assert.True(theMapper.RegionNameIsValid("test_area")); Assert.True(theMapper.RegionNameIsValid("test_area2")); Assert.True(theMapper.RegionNameIsValid("test_region")); Assert.True(theMapper.RegionNameIsValid("test_region2")); Assert.False(theMapper.RegionNameIsValid("nonsense")); }
public void RegionMapperCanBeEnabled() { // We start humble, it's a machine. var theMapper = new ImperatorRegionMapper(); var areaReader = new BufferedReader(string.Empty); var regionReader = new BufferedReader(string.Empty); theMapper.LoadRegions(areaReader, regionReader); Assert.False(theMapper.ProvinceIsInRegion(1, "test")); Assert.False(theMapper.RegionNameIsValid("test")); Assert.Null(theMapper.GetParentAreaName(1)); Assert.Null(theMapper.GetParentRegionName(1)); }
public void LocationServicesFailForNonsense() { var theMapper = new ImperatorRegionMapper(); var areaReader = new BufferedReader( "test1 = { provinces = { 1 2 3 } }" ); var regionReader = new BufferedReader( "test_region = { areas = { test1 } }" ); theMapper.LoadRegions(areaReader, regionReader); Assert.False(theMapper.ProvinceIsInRegion(1, "nonsense")); }
public void ModAreasAndRegionsAreLoaded() { const string imperatorPath = "TestFiles/ImperatorRegionMapper/test8/CK3"; var mods = new List <Mod> { new("mod1", "TestFiles/ImperatorRegionMapper/test8/mod1") }; var theMapper = new ImperatorRegionMapper(imperatorPath, mods); Assert.True(theMapper.RegionNameIsValid("vanilla_area")); Assert.True(theMapper.RegionNameIsValid("common_area")); Assert.True(theMapper.RegionNameIsValid("mod_area")); Assert.True(theMapper.RegionNameIsValid("vanilla_region")); Assert.True(theMapper.RegionNameIsValid("common_region")); Assert.True(theMapper.RegionNameIsValid("mod_region")); }
public void WrongParentLocationsReturnNullopt() { var theMapper = new ImperatorRegionMapper(); var areaReader = new BufferedReader( "test_area = { provinces = { 1 2 3 } }\n" ); var regionReader = new BufferedReader( "test_region = { areas = { test_area } }\n" ); theMapper.LoadRegions(areaReader, regionReader); Assert.Null(theMapper.GetParentAreaName(5)); Assert.Null(theMapper.GetParentRegionName(5)); }
private void ImportImperatorGovernorship( Governorship governorship, CountryCollection imperatorCountries, Imperator.Characters.CharacterCollection imperatorCharacters, bool regionHasMultipleGovernorships, TagTitleMapper tagTitleMapper, LocDB locDB, ProvinceMapper provinceMapper, DefiniteFormMapper definiteFormMapper, ImperatorRegionMapper imperatorRegionMapper, CoaMapper coaMapper) { var country = imperatorCountries[governorship.CountryId]; // Create a new title or update existing title var name = DetermineName(governorship, country, tagTitleMapper); if (TryGetValue(name, out var existingTitle)) { existingTitle.InitializeFromGovernorship( governorship, country, imperatorCharacters, regionHasMultipleGovernorships, locDB, provinceMapper, definiteFormMapper, imperatorRegionMapper ); } else { Add( governorship, country, imperatorCharacters, regionHasMultipleGovernorships, locDB, provinceMapper, coaMapper, tagTitleMapper, definiteFormMapper, imperatorRegionMapper ); } }
public void LocationServicesCorrectlyFail() { var theMapper = new ImperatorRegionMapper(); var areaReader = new BufferedReader( "test_area = { provinces = { 1 2 3 } }\n" + "test_area2 = { provinces = { 4 5 6 } }\n" + "test_area3 = { provinces = { 7 8 9 } }\n" ); var regionReader = new BufferedReader( "test_region = { areas = { test_area test_area2 } }\n" + "test_region2 = { areas = { test_area3 } }\n" ); theMapper.LoadRegions(areaReader, regionReader); Assert.False(theMapper.ProvinceIsInRegion(3, "test_area2")); // province in different area Assert.False(theMapper.ProvinceIsInRegion(9, "test_region")); // province in different region Assert.False(theMapper.ProvinceIsInRegion(9, "test_region")); // province missing completely }
public void CorrectParentLocationsReported() { var theMapper = new ImperatorRegionMapper(); var areaReader = new BufferedReader( "test_area = { provinces = { 1 2 3 } }\n" + "test_area2 = { provinces = { 4 5 6 } }\n" ); var regionReader = new BufferedReader( "test_region = { areas = { test_area } }\n" + "test_region2 = { areas = { test_area2 } }\n" ); theMapper.LoadRegions(areaReader, regionReader); Assert.Equal("test_area", theMapper.GetParentAreaName(2)); Assert.Equal("test_region", theMapper.GetParentRegionName(2)); Assert.Equal("test_area2", theMapper.GetParentAreaName(5)); Assert.Equal("test_region2", theMapper.GetParentRegionName(5)); }
public void LocationNameValidationWorks() { var theMapper = new ImperatorRegionMapper(); var areaReader = new BufferedReader( "test_area = { provinces = { 1 2 3 } }" + "test_area2 = { provinces = { 4 5 6 } }\n" ); var regionReader = new BufferedReader( "test_region = { areas = { test_area } }" + "test_region2 = { areas = { test_area2 } }\n" ); theMapper.LoadRegions(areaReader, regionReader); Assert.True(theMapper.RegionNameIsValid("test_area")); Assert.True(theMapper.RegionNameIsValid("test_area2")); Assert.True(theMapper.RegionNameIsValid("test_region")); Assert.True(theMapper.RegionNameIsValid("test_region2")); Assert.False(theMapper.RegionNameIsValid("nonsense")); }
public void ImportImperatorGovernorships( Imperator.World impWorld, TagTitleMapper tagTitleMapper, LocDB locDB, ProvinceMapper provinceMapper, DefiniteFormMapper definiteFormMapper, ImperatorRegionMapper imperatorRegionMapper, CoaMapper coaMapper ) { Logger.Info("Importing Imperator Governorships..."); var governorships = impWorld.Jobs.Governorships; var imperatorCountries = impWorld.Countries; var governorshipsPerRegion = governorships.GroupBy(g => g.RegionName) .ToDictionary(g => g.Key, g => g.Count()); // landedTitles holds all titles imported from CK3. We'll now overwrite some and // add new ones from Imperator governorships. var counter = 0; foreach (var governorship in governorships) { ImportImperatorGovernorship( governorship, imperatorCountries, impWorld.Characters, governorshipsPerRegion[governorship.RegionName] > 1, tagTitleMapper, locDB, provinceMapper, definiteFormMapper, imperatorRegionMapper, coaMapper ); ++counter; } Logger.Info($"Imported {counter} governorships from I:R."); }
public string?Match( string impCulture, string ck3Religion, ulong ck3ProvinceId, ulong impProvinceId, string ck3OwnerTitle ) { // We need at least a viable impCulture. if (string.IsNullOrEmpty(impCulture)) { return(null); } if (!cultures.Contains(impCulture)) { return(null); } if (owners.Count > 0) { if (string.IsNullOrEmpty(ck3OwnerTitle) || !owners.Contains(ck3OwnerTitle)) { return(null); } } if (religions.Count > 0) { if (string.IsNullOrEmpty(ck3Religion) || !religions.Contains(ck3Religion)) // (CK3 religion empty) or (CK3 religion not empty but not found in religions) { return(null); } } // simple culture-culture match if (ck3Provinces.Count == 0 && imperatorProvinces.Count == 0 && ck3Regions.Count == 0 && imperatorRegions.Count == 0) { return(destinationCulture); } if (ck3ProvinceId == 0 && impProvinceId == 0) { return(null); } // This is a CK3 provinces check if (ck3Provinces.Contains(ck3ProvinceId)) { return(destinationCulture); } // This is a CK3 regions check, it checks if provided ck3Province is within the mapping's ck3Regions foreach (var region in ck3Regions) { if (!CK3RegionMapper.RegionNameIsValid(region)) { Logger.Warn($"Checking for culture {impCulture} inside invalid CK3 region: {region}! Fix the mapping rules!"); // We could say this was a match, and thus pretend this region entry doesn't exist, but it's better // for the converter to explode across the logs with invalid names. So, continue. continue; } if (CK3RegionMapper.ProvinceIsInRegion(ck3ProvinceId, region)) { return(destinationCulture); } } // This is an Imperator provinces check if (imperatorProvinces.Contains(impProvinceId)) { return(destinationCulture); } // This is an Imperator regions check, it checks if provided impProvince is within the mapping's imperatorRegions foreach (var region in imperatorRegions) { if (!ImperatorRegionMapper.RegionNameIsValid(region)) { Logger.Warn($"Checking for religion {impCulture} inside invalid Imperator region: {region}! Fix the mapping rules!"); // We could say this was a match, and thus pretend this region entry doesn't exist, but it's better // for the converter to explode across the logs with invalid names. So, continue. continue; } if (ImperatorRegionMapper.ProvinceIsInRegion(impProvinceId, region)) { return(destinationCulture); } } return(null); }