|
31 | 31 | using ImperatorToCK3.Mappers.UnitType; |
32 | 32 | using ImperatorToCK3.Outputter; |
33 | 33 | using log4net.Core; |
| 34 | +using System; |
34 | 35 | using System.Collections.Generic; |
35 | 36 | using System.Collections.Immutable; |
36 | 37 | using System.IO; |
@@ -272,20 +273,9 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac |
272 | 273 | Characters.RemoveInvalidDynastiesFromHistory(Dynasties); |
273 | 274 | Dynasties.ImportImperatorFamilies(impWorld, cultureMapper, impWorld.LocDB, LocDB, CorrectedDate); |
274 | 275 | DynastyHouses.LoadCK3Houses(ModFS); |
275 | | - |
276 | | - // Load existing CK3 government IDs. |
277 | | - Logger.Info("Loading CK3 government IDs..."); |
278 | | - var ck3GovernmentIds = new HashSet<string>(); |
279 | | - var governmentsParser = new Parser(); |
280 | | - governmentsParser.RegisterRegex(CommonRegexes.String, (reader, governmentId) => { |
281 | | - ck3GovernmentIds.Add(governmentId); |
282 | | - ParserHelpers.IgnoreItem(reader); |
283 | | - }); |
284 | | - governmentsParser.ParseGameFolder("common/governments", ModFS, "txt", recursive: false, logFilePaths: true); |
285 | | - Logger.IncrementProgress(); |
286 | | - GovernmentMapper governmentMapper = new(ck3GovernmentIds); |
287 | | - Logger.IncrementProgress(); |
288 | | - |
| 276 | + |
| 277 | + GovernmentMapper governmentMapper = InitializeGovernmentMapper(); |
| 278 | + |
289 | 279 | // Before we can import Imperator countries and governorships, the I:R CoA extraction thread needs to finish. |
290 | 280 | irCoaExtractThread?.Join(); |
291 | 281 |
|
@@ -337,30 +327,16 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac |
337 | 327 |
|
338 | 328 | // Give counties to rulers and governors. |
339 | 329 | OverwriteCountiesHistory(impWorld.Countries, impWorld.JobsDB.Governorships, countyLevelCountries, countyLevelGovernorships, impWorld.Characters, impWorld.Provinces, CorrectedDate); |
340 | | - // Import holding owners as barons and counts (optional). |
341 | | - if (!config.SkipHoldingOwnersImport) { |
342 | | - LandedTitles.ImportImperatorHoldings(Provinces, impWorld.Characters, impWorld.EndDate); |
343 | | - } else { |
344 | | - Logger.Info("Skipping holding owners import per configuration."); |
345 | | - } |
346 | | - |
| 330 | + ImportImperatorHoldingsIfNotDisabledByConfiguration(impWorld, config); |
| 331 | + |
347 | 332 | LandedTitles.ImportDevelopmentFromImperator(Provinces, CorrectedDate, config.ImperatorCivilizationWorth); |
348 | 333 | LandedTitles.RemoveInvalidLandlessTitles(config.CK3BookmarkDate); |
349 | 334 |
|
350 | 335 | // Apply region-specific tweaks. |
351 | 336 | HandleIcelandAndFaroeIslands(impWorld, config); |
352 | | - |
353 | | - // Check if any muslim religion exists in Imperator. Otherwise, remove Islam from the entire CK3 map. |
354 | | - var possibleMuslimReligionNames = new List<string> { "muslim", "islam", "sunni", "shiite" }; |
355 | | - var muslimReligionExists = impWorld.Religions |
356 | | - .Any(r => possibleMuslimReligionNames.Contains(r.Id.ToLowerInvariant())); |
357 | | - if (muslimReligionExists) { |
358 | | - Logger.Info("Found muslim religion in Imperator save, keeping Islam in CK3."); |
359 | | - } else { |
360 | | - RemoveIslam(config); |
361 | | - } |
362 | | - Logger.IncrementProgress(); |
363 | | - |
| 337 | + |
| 338 | + RemoveIslamFromMapIfNotInImperator(impWorld, config); |
| 339 | + |
364 | 340 | // Now that Islam has been handled, we can generate filler holders without the risk of making them Muslim. |
365 | 341 | GenerateFillerHoldersForUnownedLands(Cultures, config); |
366 | 342 | Logger.IncrementProgress(); |
@@ -414,6 +390,44 @@ public World(Imperator.World impWorld, Configuration config, Thread? irCoaExtrac |
414 | 390 | ); |
415 | 391 | } |
416 | 392 |
|
| 393 | + private void ImportImperatorHoldingsIfNotDisabledByConfiguration(Imperator.World irWorld, Configuration config) { |
| 394 | + if (!config.SkipHoldingOwnersImport) { |
| 395 | + // Import holding owners as barons and counts. |
| 396 | + LandedTitles.ImportImperatorHoldings(Provinces, irWorld.Characters, irWorld.EndDate); |
| 397 | + } else { |
| 398 | + Logger.Info("Skipping holding owners import per configuration."); |
| 399 | + } |
| 400 | + } |
| 401 | + |
| 402 | + private GovernmentMapper InitializeGovernmentMapper() { |
| 403 | + // Load existing CK3 government IDs. |
| 404 | + Logger.Info("Loading CK3 government IDs..."); |
| 405 | + var ck3GovernmentIds = new HashSet<string>(); |
| 406 | + var governmentsParser = new Parser(); |
| 407 | + governmentsParser.RegisterRegex(CommonRegexes.String, (reader, governmentId) => { |
| 408 | + ck3GovernmentIds.Add(governmentId); |
| 409 | + ParserHelpers.IgnoreItem(reader); |
| 410 | + }); |
| 411 | + governmentsParser.ParseGameFolder("common/governments", ModFS, "txt", recursive: false, logFilePaths: true); |
| 412 | + Logger.IncrementProgress(); |
| 413 | + |
| 414 | + GovernmentMapper governmentMapper = new(ck3GovernmentIds); |
| 415 | + Logger.IncrementProgress(); |
| 416 | + return governmentMapper; |
| 417 | + } |
| 418 | + |
| 419 | + private void RemoveIslamFromMapIfNotInImperator(Imperator.World irWorld, Configuration config) { |
| 420 | + // Check if any muslim religion exists in Imperator. Otherwise, remove Islam from the entire CK3 map. |
| 421 | + var possibleMuslimReligionNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "muslim", "islam", "sunni", "shiite" }; |
| 422 | + var muslimReligionExists = irWorld.Religions.Any(r => possibleMuslimReligionNames.Contains(r.Id)); |
| 423 | + if (muslimReligionExists) { |
| 424 | + Logger.Info("Found muslim religion in Imperator save, keeping Islam in CK3."); |
| 425 | + } else { |
| 426 | + RemoveIslam(config); |
| 427 | + } |
| 428 | + Logger.IncrementProgress(); |
| 429 | + } |
| 430 | + |
417 | 431 | private void DetermineCK3BookmarkDate(Imperator.World irWorld, Configuration config) { |
418 | 432 | CorrectedDate = irWorld.EndDate.Year > 1 ? irWorld.EndDate : new Date(2, 1, 1); |
419 | 433 | if (config.CK3BookmarkDate.Year == 0) { // bookmark date is not set |
|
0 commit comments