Skip to content

Commit

Permalink
Convert holding owners to barony holders (#1154) #minor
Browse files Browse the repository at this point in the history
closes #314
  • Loading branch information
IhateTrains authored Jan 7, 2023
1 parent 2bcf3b5 commit ad270b7
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ImperatorToCK3.UnitTests/Imperator/Countries/CountryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void FieldsDefaultToCorrectValues() {
Assert.Equal(string.Empty, country.Tag);
Assert.Equal(string.Empty, country.HistoricalTag);
Assert.Equal(string.Empty, country.Name);
Assert.Null(country.Capital);
Assert.Null(country.CapitalProvinceId);
Assert.Equal(0, country.Currencies.Manpower);
Assert.Equal(0, country.Currencies.Gold);
Assert.Equal(50, country.Currencies.Stability);
Expand Down Expand Up @@ -64,7 +64,7 @@ public void FieldsCanBeSet() {
Assert.Equal("WTF", country.HistoricalTag);
Assert.Equal("WTF", country.Name);
Assert.Equal("WTF", country.Flag);
Assert.Equal((ulong)32, country.Capital);
Assert.Equal((ulong)32, country.CapitalProvinceId);
Assert.Equal(1, country.Currencies.Manpower);
Assert.Equal(2, country.Currencies.Gold);
Assert.Equal(69, country.Currencies.Stability);
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/CK3/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ Configuration config
ulong impProvince = 0;
var srcReligion = preImperatorRuler.Religion ?? imperatorCountry.Religion;
var srcCulture = preImperatorRuler.Culture ?? imperatorCountry.PrimaryCulture;
if (imperatorCountry.Capital is not null) {
impProvince = (ulong)imperatorCountry.Capital;
if (imperatorCountry.CapitalProvinceId is not null) {
impProvince = imperatorCountry.CapitalProvinceId.Value;
var ck3Provinces = provinceMapper.GetCK3ProvinceNumbers(impProvince);
if (ck3Provinces.Count > 0) {
ck3Province = ck3Provinces[0];
Expand Down
44 changes: 44 additions & 0 deletions ImperatorToCK3/CK3/Titles/LandedTitles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using ImperatorToCK3.Mappers.TagTitle;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -446,6 +447,49 @@ ICollection<Governorship> countryLevelGovernorships
);
}
}

public void ImportImperatorHoldings(ProvinceCollection ck3Provinces, Imperator.Characters.CharacterCollection irCharacters, Date conversionDate) {
Logger.Info("Importing Imperator Holdings...");
var counter = 0;

// Get baronies except county capitals.
var potentialBaronies = this
.Where(t => t.Rank == TitleRank.barony)
.Where(b => b.DeJureLiege?.CapitalBaronyId != b.Id)
.ToImmutableList();

foreach (var barony in potentialBaronies) {
var ck3ProvinceId = barony.Province;
if (ck3ProvinceId is null) {
continue;
}
if (!ck3Provinces.TryGetValue(ck3ProvinceId.Value, out var ck3Province)) {
continue;
}

// Skip temple holdings.
if (ck3Province.GetHoldingType(conversionDate) == "church_holding") {
continue;
}

var irProvince = ck3Province.PrimaryImperatorProvince;
var holdingOwnerId = irProvince?.HoldingOwnerId;
if (holdingOwnerId is null) {
continue;
}

var irOwner = irCharacters[holdingOwnerId.Value];
var ck3Owner = irOwner.CK3Character;
if (ck3Owner is null) {
continue;
}

barony.SetHolder(ck3Owner, conversionDate);
++counter;
}
Logger.Info($"Imported {counter} holdings from I:R.");
Logger.IncrementProgress();
}

public void RemoveInvalidLandlessTitles(Date ck3BookmarkDate) {
Logger.Info("Removing invalid landless titles...");
Expand Down
4 changes: 2 additions & 2 deletions ImperatorToCK3/CK3/Titles/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ Configuration config

// Determine other attributes:
// Set capital to Imperator tag's capital.
if (ImperatorCountry.Capital is not null) {
var srcCapital = (ulong)ImperatorCountry.Capital;
if (ImperatorCountry.CapitalProvinceId is not null) {
var srcCapital = ImperatorCountry.CapitalProvinceId.Value;
foreach (var ck3ProvId in provinceMapper.GetCK3ProvinceNumbers(srcCapital)) {
var foundCounty = parentCollection.GetCountyForProvince(ck3ProvId);
if (foundCounty is null) {
Expand Down
7 changes: 6 additions & 1 deletion ImperatorToCK3/CK3/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
using ImperatorToCK3.Mappers.War;
using ImperatorToCK3.Mappers.UnitType;
using Open.Collections;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -47,6 +46,10 @@ public class World {
public IdObjectCollection<string, MenAtArmsType> MenAtArmsTypes { get; } = new();
public MapData MapData { get; }
public List<Wars.War> Wars { get; } = new();

/// <summary>
/// Date based on I:R save date, but normalized for CK3 purposes.
/// </summary>
public Date CorrectedDate { get; }

public World(Imperator.World impWorld, Configuration config) {
Expand Down Expand Up @@ -182,6 +185,8 @@ public World(Imperator.World impWorld, Configuration config) {
coaMapper,
countyLevelGovernorships
);

LandedTitles.ImportImperatorHoldings(Provinces, impWorld.Characters, CorrectedDate);

OverwriteCountiesHistory(impWorld.Jobs.Governorships, countyLevelGovernorships, impWorld.Characters, CorrectedDate);
LandedTitles.ImportDevelopmentFromImperator(Provinces, CorrectedDate, config.ImperatorCivilizationWorth);
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Countries/Country.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public string HistoricalTag {
public CountryName CountryName { get; private set; } = new();
public string Flag { get; private set; } = "";
public CountryType CountryType { get; private set; } = CountryType.real;
public ulong? Capital { get; private set; }
public ulong? CapitalProvinceId { get; private set; }
public string? Government { get; private set; }
public GovernmentType GovernmentType { get; private set; } = GovernmentType.monarchy;
private readonly SortedSet<string> monarchyLaws = new();
Expand Down
2 changes: 1 addition & 1 deletion ImperatorToCK3/Imperator/Countries/CountryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static Country() {
parser.RegisterKeyword("capital", reader => {
var capitalProvId = reader.GetULong();
if (capitalProvId > 0) {
parsedCountry.Capital = capitalProvId;
parsedCountry.CapitalProvinceId = capitalProvId;
}
});
parser.RegisterKeyword("historical_regnal_numbers", reader => {
Expand Down
1 change: 1 addition & 0 deletions ImperatorToCK3/Imperator/Provinces/Province.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class Province : IIdentifiable<ulong> {
public bool Fort { get; set; } = false;
public bool IsHolySite => HolySiteId is not null;
public ulong? HolySiteId { get; set; } = null;
public ulong? HoldingOwnerId { get; set; } = null;
public uint BuildingCount { get; set; } = 0;
public double CivilizationValue { get; set; } = 0;

Expand Down
8 changes: 8 additions & 0 deletions ImperatorToCK3/Imperator/Provinces/ProvinceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ static Province() {
provinceParser.RegisterKeyword("fort", reader =>
parsedProvince.Fort = reader.GetBool()
);
provinceParser.RegisterKeyword("holdings", reader => {
var holdingOwnerId = reader.GetULong();
// 4294967295 equals (2^32 − 1) and is the default value
// otherwise, the value is the ID of a character
if (holdingOwnerId != 4294967295) {
parsedProvince.HoldingOwnerId = holdingOwnerId;
}
});
provinceParser.RegisterKeyword("holy_site", reader => {
var holySiteId = reader.GetULong();
// 4294967295 equals (2^32 − 1) and is the default value
Expand Down

0 comments on commit ad270b7

Please sign in to comment.