@@ -235,22 +235,33 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
235235 var config = new Configuration { ImperatorPath = "TestFiles/LandedTitlesTests/Imperator" } ;
236236 var imperatorWorld = new TestImperatorWorld ( config ) ;
237237
238- imperatorWorld . Provinces . Add ( new Province ( 1 ) ) ;
239- imperatorWorld . Provinces . Add ( new Province ( 2 ) ) ;
240- imperatorWorld . Provinces . Add ( new Province ( 3 ) ) ;
238+ var irProv1 = new Province ( 1 ) ;
239+ var irProv2 = new Province ( 2 ) ;
240+ var irProv3 = new Province ( 3 ) ;
241+ imperatorWorld . Provinces . Add ( irProv1 ) ;
242+ imperatorWorld . Provinces . Add ( irProv2 ) ;
243+ imperatorWorld . Provinces . Add ( irProv3 ) ;
241244
242245 var governor = new ImperatorToCK3 . Imperator . Characters . Character ( 25212 ) ;
243246 imperatorWorld . Characters . Add ( governor ) ;
244247
245248 var countryReader = new BufferedReader ( "tag=PRY capital=1" ) ;
246249 var country = Country . Parse ( countryReader , 589 ) ;
250+ irProv1 . OwnerCountry = country ;
251+ irProv2 . OwnerCountry = country ;
252+ irProv3 . OwnerCountry = country ;
253+ country . RegisterProvince ( irProv1 ) ;
254+ country . RegisterProvince ( irProv2 ) ;
255+ country . RegisterProvince ( irProv3 ) ;
247256 imperatorWorld . Countries . Add ( country ) ;
248257
249258 imperatorWorld . Areas . LoadAreas ( imperatorWorld . ModFS , imperatorWorld . Provinces ) ;
250259 var irRegionMapper = new ImperatorRegionMapper ( imperatorWorld . Areas , irMapData ) ;
251260 irRegionMapper . LoadRegions ( imperatorWorld . ModFS , new ColorFactory ( ) ) ;
252261 Assert . True ( irRegionMapper . RegionNameIsValid ( "galatia_area" ) ) ;
253262 Assert . True ( irRegionMapper . RegionNameIsValid ( "galatia_region" ) ) ;
263+ Assert . True ( irRegionMapper . ProvinceIsInRegion ( 2 , "galatia_region" ) ) ;
264+ Assert . True ( irRegionMapper . ProvinceIsInRegion ( 3 , "galatia_region" ) ) ;
254265 var ck3RegionMapper = new CK3RegionMapper ( ) ;
255266
256267 var reader = new BufferedReader (
@@ -335,14 +346,14 @@ public void GovernorshipsCanBeRecognizedAsCountyLevel() {
335346 title => Assert . Equal ( "d_IRTOCK3_PRY" , title . Id )
336347 ) ;
337348
338- var provinces = new ProvinceCollection ( ck3ModFS ) ;
349+ var ck3Provinces = new ProvinceCollection ( ck3ModFS ) ;
339350 var ck3MapData = new MapData ( ck3ModFS ) ;
340351 ck3MapData . ProvinceDefinitions . Add ( new ( 1 ) ) ;
341352 ck3MapData . ProvinceDefinitions . Add ( new ( 2 ) ) ;
342353 ck3MapData . ProvinceDefinitions . Add ( new ( 3 ) ) ;
343- provinces . ImportImperatorProvinces ( imperatorWorld , ck3MapData , titles , cultureMapper , religionMapper , provinceMapper , conversionDate , config ) ;
354+ ck3Provinces . ImportImperatorProvinces ( imperatorWorld , ck3MapData , titles , cultureMapper , religionMapper , provinceMapper , conversionDate , config ) ;
344355 // Country 589 is imported as duchy-level title, so its governorship of galatia_region will be county level.
345- titles . ImportImperatorGovernorships ( imperatorWorld , provinces , tagTitleMapper , irLocDB , ck3LocDB , config , provinceMapper , definiteFormMapper , irRegionMapper , coaMapper , countyLevelGovernorships ) ;
356+ titles . ImportImperatorGovernorships ( imperatorWorld , ck3Provinces , tagTitleMapper , irLocDB , ck3LocDB , config , provinceMapper , definiteFormMapper , irRegionMapper , coaMapper , countyLevelGovernorships ) ;
346357
347358 Assert . Collection ( titles ,
348359 title => Assert . Equal ( "c_county1" , title . Id ) ,
@@ -610,6 +621,68 @@ public void TitlesCanBeExpandedInOtherFiles() {
610621 Assert . Equal ( "c_karakorum" , mongoliaKingdom . CapitalCountyId ) ;
611622 }
612623
624+ [ Fact ]
625+ public void KingdomUsesNextDominantHeritageWhenMostDominantOneCannotProvideEmpire ( ) {
626+ var date = new Date ( 867 , 1 , 1 ) ;
627+ var titles = new Title . LandedTitles ( ) ;
628+ titles . LoadTitles ( new BufferedReader (
629+ "e_mongolia = { }\n " +
630+ "k_test = {\n " +
631+ "\t d_test = {\n " +
632+ "\t \t c_county1 = { b_barony1 = { province = 1 } }\n " +
633+ "\t \t c_county2 = { b_barony2 = { province = 2 } }\n " +
634+ "\t \t c_county3 = { b_barony3 = { province = 3 } }\n " +
635+ "\t }\n " +
636+ "}\n " +
637+ "k_xia = {\n " +
638+ "\t d_xia = {\n " +
639+ "\t \t c_xia_county = { b_xia_barony = { province = 4 } }\n " +
640+ "\t }\n " +
641+ "}\n "
642+ ) , colorFactory ) ;
643+
644+ var cultureCollection = new TestCK3CultureCollection ( ) ;
645+ cultureCollection . GenerateTestCulture ( "han" , "heritage_chinese" ) ;
646+ cultureCollection . GenerateTestCulture ( "mongol" , "heritage_mongolic" ) ;
647+
648+ var characters = new CharacterCollection ( ) ;
649+ var hanHolder1 = new Character ( "1" , "Han Holder 1" , new Date ( 800 , 1 , 1 ) , characters ) ;
650+ hanHolder1 . SetCultureId ( "han" , null ) ;
651+ characters . Add ( hanHolder1 ) ;
652+
653+ var hanHolder2 = new Character ( "2" , "Han Holder 2" , new Date ( 801 , 1 , 1 ) , characters ) ;
654+ hanHolder2 . SetCultureId ( "han" , null ) ;
655+ characters . Add ( hanHolder2 ) ;
656+
657+ var mongolHolder = new Character ( "3" , "Mongol Holder" , new Date ( 802 , 1 , 1 ) , characters ) ;
658+ mongolHolder . SetCultureId ( "mongol" , null ) ;
659+ characters . Add ( mongolHolder ) ;
660+
661+ titles [ "c_county1" ] . SetHolder ( hanHolder1 , date ) ;
662+ titles [ "c_county2" ] . SetHolder ( hanHolder2 , date ) ;
663+ titles [ "c_county3" ] . SetHolder ( mongolHolder , date ) ;
664+ titles [ "c_xia_county" ] . SetHolder ( mongolHolder , date ) ;
665+
666+ var heritageMapPath = Path . Combine ( "configurables" , "heritage_empires_map.txt" ) ;
667+ var originalHeritageMap = File . Exists ( heritageMapPath ) ? File . ReadAllText ( heritageMapPath ) : null ;
668+ Directory . CreateDirectory ( "configurables" ) ;
669+ File . WriteAllText ( heritageMapPath ,
670+ "heritage_chinese = none\n " +
671+ "heritage_mongolic = e_mongolia\n " ) ;
672+
673+ try {
674+ titles . SetDeJureKingdomsAndAbove ( date , cultureCollection , characters , new MapData ( ck3ModFS ) , new CK3RegionMapper ( ) , new TestCK3LocDB ( ) ) ;
675+
676+ Assert . Equal ( "e_mongolia" , titles [ "k_test" ] . DeJureLiege ? . Id ) ;
677+ } finally {
678+ if ( originalHeritageMap is null ) {
679+ File . Delete ( heritageMapPath ) ;
680+ } else {
681+ File . WriteAllText ( heritageMapPath , originalHeritageMap ) ;
682+ }
683+ }
684+ }
685+
613686 [ Fact ]
614687 public void RemoveBreaksAllLinks ( ) {
615688 var landedTitles = new Title . LandedTitles ( ) ;
0 commit comments