Skip to content

Commit

Permalink
Compatch for CK3 1.12 (#1811)
Browse files Browse the repository at this point in the history
closes #1810
closes #1791
  • Loading branch information
IhateTrains authored Mar 7, 2024
1 parent 5e275ee commit 6c54f18
Show file tree
Hide file tree
Showing 20 changed files with 278 additions and 43 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/validate_dds_files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "Validate DDS files"

on:
pull_request:
merge_group:

concurrency:
group: ci-validate-dds-files-${{ github.ref }}-1
cancel-in-progress: true

jobs:
validate-dds-files:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: mfinelli/setup-imagemagick@v5
with:
cache: true
install-libfuse2: true
- name: "Install Wand library"
run: |
pip3 install Wand
- name: "Validate faith icons"
run: |
python3 ./tools/validate_dds_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
heritage_arvanite = {
REPLACED_BY = { heritage_arberian heritage_arvanite }
type = heritage
is_shown = {
heritage_is_shown_trigger = {
HERITAGE = heritage_arvanite
}
}
audio_parameter = european
}

language_albanian = {
Expand Down
10 changes: 10 additions & 0 deletions ImperatorToCK3/CK3/Characters/CharacterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ private static void ImportFriendships(Imperator.Characters.CharacterCollection i
}

foreach (var irFriendId in irCharacter.FriendIds) {
// Make sure to only add this relation once.
if (irCharacter.Id.CompareTo(irFriendId) > 0) {
continue;
}

var irFriend = irCharacters[irFriendId];
var ck3Friend = irFriend.CK3Character;

Expand All @@ -254,6 +259,11 @@ private static void ImportRivalries(Imperator.Characters.CharacterCollection irC
}

foreach (var irRivalId in irCharacter.RivalIds) {
// Make sure to only add this relation once.
if (irCharacter.Id.CompareTo(irRivalId) > 0) {
continue;
}

var irRival = irCharacters[irRivalId];
var ck3Rival = irRival.CK3Character;

Expand Down
92 changes: 60 additions & 32 deletions ImperatorToCK3/CK3/Characters/DNAFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,29 +261,7 @@ public DNA GenerateDNA(Imperator.Characters.Character irCharacter, PortraitData

morphDNAValues.Add("gene_age", GetAgeGeneValue(irCharacter));

// Convert baldness.
if (irCharacter.IsBald) {
morphDNAValues["gene_baldness"] = new DNAGeneValue {
TemplateName = "male_pattern_baldness",
IntSliderValue = 255,
TemplateRecessiveName = "male_pattern_baldness",
IntSliderValueRecessive = 127
};
// CK3 does not seem to actually support baldness (as of CK3 1.8.1) despite the gene being there.
// So we just remove the hair.
if (accessoryDNAValues.TryGetValue("hairstyles", out var hairstylesGeneValue)) {
accessoryDNAValues["hairstyles"] = hairstylesGeneValue with {
TemplateName = "no_hairstyles", IntSliderValue = 0
};
}
} else {
morphDNAValues["gene_baldness"] = new DNAGeneValue {
TemplateName = "no_baldness",
IntSliderValue = 127,
TemplateRecessiveName = "no_baldness",
IntSliderValueRecessive = 127
};
}
ConvertBaldness(irCharacter, morphDNAValues, accessoryDNAValues);

// Use middle values for the rest of the genes.
var missingMorphGenes = ck3GenesDB.MorphGenes
Expand Down Expand Up @@ -324,7 +302,62 @@ public DNA GenerateDNA(Imperator.Characters.Character irCharacter, PortraitData

return new DNA(id, colorDNAValues, morphDNAValues, accessoryDNAValues);
}

private void ConvertBaldness(Imperator.Characters.Character irCharacter, Dictionary<string, DNAGeneValue> morphDNAValues, Dictionary<string, DNAGeneValue> accessoryDNAValues) {
if (irCharacter.IsBald) { // TODO: CHECK IF BALD CHARACTERS STILL CORRECTLY APPEAR BALD IN CK3

Check warning on line 307 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / Upload development build (win-x64)

TODO CHECK IF BALD CHARACTERS STILL CORRECTLY APPEAR BALD IN CK3 (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)

Check warning on line 307 in ImperatorToCK3/CK3/Characters/DNAFactory.cs

View workflow job for this annotation

GitHub Actions / Upload development build (linux-x64)

TODO CHECK IF BALD CHARACTERS STILL CORRECTLY APPEAR BALD IN CK3 (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0026.md)
morphDNAValues["gene_baldness"] = new DNAGeneValue {
TemplateName = "male_pattern_baldness",
IntSliderValue = 127,
TemplateRecessiveName = "male_pattern_baldness",
IntSliderValueRecessive = 127
};

// If m_hair_fp4_indian_01_full_bald (which is close to I:R baldness) exists, use it.
DNAGeneValue? hairstylesGeneValue = null;
if (ck3GenesDB.SpecialAccessoryGenes.TryGetValue("hairstyles", out var hairstylesGene)) {
const string baldnessObjectName = "m_hair_fp4_indian_01_full_bald";

if (hairstylesGene.GeneTemplates.TryGetValue("fp4_bald_hairstyles", out var ck3GeneTemplate)) {
var ageSexWeightBlock = ck3GeneTemplate.AgeSexWeightBlocks[irCharacter.AgeSex];

if (ageSexWeightBlock.ContainsObject(baldnessObjectName)) {
hairstylesGeneValue = new DNAGeneValue {
TemplateName = ck3GeneTemplate.Id,
IntSliderValue = ck3GeneTemplate.AgeSexWeightBlocks[irCharacter.AgeSex]
.GetSliderValueForObject(baldnessObjectName),
TemplateRecessiveName = ck3GeneTemplate.Id,
IntSliderValueRecessive = 128
};
}
}
}
// Otherwise, just use the no_hairstyles template.
if (hairstylesGeneValue is null && accessoryDNAValues.TryGetValue("hairstyles", out var existingHairStylesGeneValue)) {
hairstylesGeneValue = existingHairStylesGeneValue with {
TemplateName = "no_hairstyles", IntSliderValue = 0
};
}

if (hairstylesGeneValue.HasValue) {
accessoryDNAValues["hairstyles"] = hairstylesGeneValue.Value;
}

morphDNAValues["gene_balding_hair_effect"] = new DNAGeneValue {
TemplateName = "baldness_stage_2",
IntSliderValue = 255,
TemplateRecessiveName = "baldness_stage_2",
IntSliderValueRecessive = 255
};
} else {
morphDNAValues["gene_baldness"] = new DNAGeneValue {
TemplateName = "no_baldness",
IntSliderValue = 127,
TemplateRecessiveName = "no_baldness",
IntSliderValueRecessive = 127
};
}
}

/// Returns CK3 gene value string after object-to-object matching
/// (for example I:R male_beard_1 to CK3 male_beard_western_03).
private DNAGeneValue? MatchAccessoryGeneValueByObject(
Expand Down Expand Up @@ -359,19 +392,14 @@ AccessoryGene ck3Gene
Logger.Warn($"No template found for {convertedSetEntryRecessive} in CK3 gene {ck3Gene.Id}!");
return null;
}

var matchingPercentage = ck3GeneTemplate.AgeSexWeightBlocks[irCharacter.AgeSex]
.GetMatchingPercentage(convertedSetEntry);
var matchingPercentageRecessive = ck3GeneTemplateRecessive.AgeSexWeightBlocks[irCharacter.AgeSex]
.GetMatchingPercentage(convertedSetEntryRecessive);
byte intSliderValue = (byte)Math.Ceiling(matchingPercentage * 255);
byte intSliderValueRecessive = (byte)Math.Ceiling(matchingPercentageRecessive * 255);

return new DNAGeneValue {
TemplateName = ck3GeneTemplate.Id,
IntSliderValue = intSliderValue,
IntSliderValue = ck3GeneTemplate.AgeSexWeightBlocks[irCharacter.AgeSex]
.GetSliderValueForObject(convertedSetEntry),
TemplateRecessiveName = ck3GeneTemplateRecessive.Id,
IntSliderValueRecessive = intSliderValueRecessive
IntSliderValueRecessive = ck3GeneTemplateRecessive.AgeSexWeightBlocks[irCharacter.AgeSex]
.GetSliderValueForObject(convertedSetEntryRecessive),
};
}

Expand Down
14 changes: 13 additions & 1 deletion ImperatorToCK3/CK3/Titles/LandedTitles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,11 @@ public void RemoveInvalidLandlessTitles(Date ck3BookmarkDate) {

private void SetDeJureKingdoms(Date ck3BookmarkDate) {
Logger.Info("Setting de jure kingdoms...");
foreach (var duchy in this.Where(t => t.Rank == TitleRank.duchy && t.DeJureVassals.Count > 0)) {

var duchies = this.Where(t => t.Rank == TitleRank.duchy).ToHashSet();
var duchiesWithDeJureVassals = duchies.Where(d => d.DeJureVassals.Count > 0).ToHashSet();

foreach (var duchy in duchiesWithDeJureVassals) {
// If capital county belongs to a kingdom, make the kingdom a de jure liege of the duchy.
var capitalRealm = duchy.CapitalCounty?.GetRealmOfRank(TitleRank.kingdom, ck3BookmarkDate);
if (capitalRealm is not null) {
Expand All @@ -644,6 +648,14 @@ private void SetDeJureKingdoms(Date ck3BookmarkDate) {
duchy.DeJureLiege = this[biggestShare.Key];
}
}

// Duchies without de jure vassals should not be de jure part of any kingdom.
var duchiesWithoutDeJureVassals = duchies.Except(duchiesWithDeJureVassals);
foreach (var duchy in duchiesWithoutDeJureVassals) {
Logger.Debug($"Duchy {duchy.Id} has no de jure vassals. Removing de jure liege.");
duchy.DeJureLiege = null;
}

Logger.IncrementProgress();
}

Expand Down
4 changes: 4 additions & 0 deletions ImperatorToCK3/CommonUtils/Genes/WeightBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public double GetMatchingPercentage(string objectName) {
}
throw new KeyNotFoundException($"Set entry {objectName} not found!");
}

public byte GetSliderValueForObject(string objectName) {
return (byte)Math.Ceiling(GetMatchingPercentage(objectName) * 255);
}
public string? GetMatchingObject(double percentAsDecimal) { // argument must be in range <0; 1>
if (percentAsDecimal < 0 || percentAsDecimal > 1) {
throw new ArgumentOutOfRangeException($"percentAsDecimal is {percentAsDecimal}, should be >=0 and <=1");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Last updated: CK3 patch 1.9.0.4
# Last updated: CK3 patch 1.12.1
MountedWarriorTerm = {
type = character

Expand Down Expand Up @@ -689,7 +689,7 @@ Abortifacient = {
#Christian only
#Balkans, Anatolia, Mediterranean
trigger = {
religion = religion:christianity_religion
faith.religion = religion:christianity_religion
location = {
OR = {
geographical_region = world_europe_south
Expand Down Expand Up @@ -749,7 +749,7 @@ VenomousCreature = {
text = {
localization_key = venomous_creature_rare_spider
trigger = {
scope:venomous_creature = flag:rare_spider #Not Northern Europe or the Steppes
scope:venomous_creature = flag:rare_spider #Very rare, as spiders poisonous enough to kill a man would need to come from VERY far
}
}

Expand Down Expand Up @@ -777,7 +777,7 @@ VenomousCreature = {
text = {
localization_key = venomous_creature_viper
trigger = {
scope:venomous_creature = flag:viper #Northern and Eastern Europe
scope:venomous_creature = flag:viper #Fallback - Everywhere
}
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ additional_fatimids_1
159137
109607
6878
107590
107590
3 changes: 1 addition & 2 deletions ImperatorToCK3/Data_Files/configurables/converter_faiths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4605,8 +4605,6 @@ hurrian_religion_group = {
doctrine = doctrine_adultery_men_shunned
doctrine = doctrine_adultery_women_crime
doctrine = doctrine_kinslaying_close_kin_crime
#Infanticide
doctrine = doctrine_infanticide_any

#Clerical Functions
doctrine = doctrine_clerical_gender_either
Expand Down Expand Up @@ -4774,6 +4772,7 @@ hurrian_religion_group = {

color = hsv { 0.5 0.8 0.7 }
icon = custom_faith_7
reformed_icon = custom_faith_7

# IRToCK3: Holy sites copied from mesopotamian_pagan, this "Hurrian" is revivalist anyway.
holy_site = babylon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ heritage_venetic = {
heritage_group_latin = yes
heritage_family_european = yes
}

is_shown = {
heritage_is_shown_trigger = {
HERITAGE = heritage_venetic
}
}
audio_parameter = european
}
Loading

0 comments on commit 6c54f18

Please sign in to comment.