﻿### Add All Lifestyle Perks
DI_ce_add_all_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_martial_present_effect = yes
                DI_lifestyle_diplomacy_present_effect = yes
                DI_lifestyle_stewardship_present_effect = yes
                DI_lifestyle_intrigue_present_effect = yes
                DI_lifestyle_learning_present_effect = yes
                DI_lifestyle_wandering_present_effect = yes
            }
        }
        else = {
            DI_lifestyle_martial_present_effect = yes
            DI_lifestyle_diplomacy_present_effect = yes
            DI_lifestyle_stewardship_present_effect = yes
            DI_lifestyle_intrigue_present_effect = yes
            DI_lifestyle_learning_present_effect = yes
            DI_lifestyle_wandering_present_effect = yes
        }
    }
}

### Remove All Lifestyle Perks
DI_ce_remove_all_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_martial_present_no_effect = yes
                DI_lifestyle_diplomacy_present_no_effect = yes
                DI_lifestyle_stewardship_present_no_effect = yes
                DI_lifestyle_intrigue_present_no_effect = yes
                DI_lifestyle_learning_present_no_effect = yes
                DI_lifestyle_wandering_present_no_effect = yes
            }
        }
        else = {
            DI_lifestyle_martial_present_no_effect = yes
            DI_lifestyle_diplomacy_present_no_effect = yes
            DI_lifestyle_stewardship_present_no_effect = yes
            DI_lifestyle_intrigue_present_no_effect = yes
            DI_lifestyle_learning_present_no_effect = yes
            DI_lifestyle_wandering_present_no_effect = yes
        }
    }
}

### Add All Martial Lifestyle Perks
DI_ce_add_martial_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_martial_present_effect = yes
            }
        }
        else = {
            DI_lifestyle_martial_present_effect = yes
        }
    }
}

### Remove All Martial Lifestyle Perks
DI_ce_remove_martial_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_martial_present_no_effect = yes
            }
        }
        else = {
            DI_lifestyle_martial_present_no_effect = yes
        }
    }
}

### Add All Diplomacy Lifestyle Perks
DI_ce_add_diplomacy_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_diplomacy_present_effect = yes
            }
        }
        else = {
            DI_lifestyle_diplomacy_present_effect = yes
        }
    }
}

### Remove All Diplomacy Lifestyle Perks
DI_ce_remove_diplomacy_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_diplomacy_present_no_effect = yes
            }
        }
        else = {
            DI_lifestyle_diplomacy_present_no_effect = yes
        }
    }
}

### Add All stewardship Lifestyle Perks
DI_ce_add_stewardship_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_stewardship_present_effect = yes
            }
        }
        else = {
            DI_lifestyle_stewardship_present_effect = yes
        }
    }
}

### Remove All stewardship Lifestyle Perks
DI_ce_remove_stewardship_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_stewardship_present_no_effect = yes
            }
        }
        else = {
            DI_lifestyle_stewardship_present_no_effect = yes
        }
    }
}

### Add All intrigue Lifestyle Perks
DI_ce_add_intrigue_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_intrigue_present_effect = yes
            }
        }
        else = {
            DI_lifestyle_intrigue_present_effect = yes
        }
    }
}

### Remove All intrigue Lifestyle Perks
DI_ce_remove_intrigue_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_intrigue_present_no_effect = yes
            }
        }
        else = {
            DI_lifestyle_intrigue_present_no_effect = yes
        }
    }
}

### Add All learning Lifestyle Perks
DI_ce_add_learning_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_learning_present_effect = yes
            }
        }
        else = {
            DI_lifestyle_learning_present_effect = yes
        }
    }
}

### Remove All learning Lifestyle Perks
DI_ce_remove_learning_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_learning_present_no_effect = yes
            }
        }
        else = {
            DI_lifestyle_learning_present_no_effect = yes
        }
    }
}

### Add All Wandering Lifestyle Perks
DI_ce_add_wandering_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_wandering_present_effect = yes
            }
        }
        else = {
            DI_lifestyle_wandering_present_effect = yes
        }
    }
}

### Remove All Wandering Lifestyle Perks
DI_ce_remove_wandering_lifestyle = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_lifestyle_wandering_present_no_effect = yes
            }
        }
        else = {
            DI_lifestyle_wandering_present_no_effect = yes
        }
    }
}

### Eliminate Health Issues
DI_ce_eliminate_health_issues = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_set_weight_0 = yes
                DI_eliminated_health_problem_effect = yes
            }
        }
        else = {
            DI_set_weight_0 = yes
            DI_eliminated_health_problem_effect = yes
        }
    }
}

### Add Good Health Genes
DI_ce_add_good_genes = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_remove_health_conflict_effect = yes

                add_trait = physique_good_3
                add_trait = intellect_good_3
                add_trait = beauty_good_3
                add_trait = pure_blooded
                add_trait = fecund
            }
        }
        else = {
            DI_remove_health_conflict_effect = yes
            add_trait = physique_good_3
            add_trait = intellect_good_3
            add_trait = beauty_good_3
            add_trait = pure_blooded
            add_trait = fecund
        }
    }
}

### Remove Good Health Genes
DI_ce_remove_good_genes = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }

                remove_trait = physique_good_3
                remove_trait = intellect_good_3
                remove_trait = beauty_good_3
                remove_trait = pure_blooded
                remove_trait = fecund
            }
        }
        else = {
            remove_trait = physique_good_3
            remove_trait = intellect_good_3
            remove_trait = beauty_good_3
            remove_trait = pure_blooded
            remove_trait = fecund
        }
    }
}

### Add Bad Health Traits
DI_ce_add_bad_genes = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_remove_health_conflict_forbadgene_effect = yes
                remove_trait = physique_good_3
                remove_trait = intellect_good_3
                remove_trait = beauty_good_3
                remove_trait = pure_blooded
                remove_trait = fecund
                add_trait = beauty_bad_3
                add_trait = intellect_bad_3
                add_trait = physique_bad_3
                add_trait = inbred
                add_trait = impotent
            }
        }
        else = {
            DI_remove_health_conflict_forbadgene_effect = yes
            remove_trait = physique_good_3
            remove_trait = intellect_good_3
            remove_trait = beauty_good_3
            remove_trait = pure_blooded
            remove_trait = fecund
            add_trait = beauty_bad_3
            add_trait = intellect_bad_3
            add_trait = physique_bad_3
            add_trait = inbred
            add_trait = impotent
        }
    }
}

### Remove Bad Health Traits
DI_ce_remove_bad_genes = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_trait = beauty_bad_3
                remove_trait = intellect_bad_3
                remove_trait = physique_bad_3
                remove_trait = inbred
                remove_trait = impotent
            }
        }
        else = {
            remove_trait = beauty_bad_3
            remove_trait = intellect_bad_3
            remove_trait = physique_bad_3
            remove_trait = inbred
            remove_trait = impotent
        }
    }
}

### No stress change
DI_ce_lock_stress = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                add_character_modifier = no_stress_change
            }
        }
        else = {
            add_character_modifier = no_stress_change
        }
    }
}

DI_ce_unlock_stress = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_character_modifier = no_stress_change
            }
        }
        else = {
            remove_character_modifier = no_stress_change
        }
    }
}

### No tyranny change
DI_ce_lock_tyranny = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                add_character_modifier = no_tyranny_change
            }
        }
        else = {
            add_character_modifier = no_tyranny_change
        }
    }
}

DI_ce_unlock_tyranny = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_character_modifier = no_tyranny_change
            }
        }
        else = {
            remove_character_modifier = no_tyranny_change
        }
    }
}

### No dread change
DI_ce_lock_dread = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                add_character_modifier = no_dread_change
            }
        }
        else = {
            add_character_modifier = no_dread_change
        }
    }
}

DI_ce_unlock_dread = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_character_modifier = no_dread_change
            }
        }
        else = {
            remove_character_modifier = no_dread_change
        }
    }
}

### Randomize Three Personality Traits
DI_ce_randomize_personality = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_clear_personality_traits_effect = yes
                DI_personality_trait_randomizer_effect = yes
            }
        }
        else = {
            DI_clear_personality_traits_effect = yes
            DI_personality_trait_randomizer_effect = yes
        }
    }
}

### Remove Personality Traits
DI_ce_clear_personality = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_clear_personality_traits_effect = yes
            }
        }
        else = {
            DI_clear_personality_traits_effect = yes
        }
    }

}

### Add Special Mod Traits
DI_ce_add_special_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                add_trait = DI_immortal
                set_immortal_age = 30
                add_trait = 100_stat_man
                add_trait = nnn_challenger
                add_trait = build_speed_cheat
                add_trait = stress_gain_remove
                add_trait = tyranny_gain_remove
            }
        }
        else = {
            add_trait = DI_immortal
            set_immortal_age = 30
            add_trait = 100_stat_man
            add_trait = nnn_challenger
            add_trait = build_speed_cheat
            add_trait = stress_gain_remove
            add_trait = tyranny_gain_remove
        }
    }
}

### Remove Special Mod Traits
DI_ce_remove_special_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_trait = DI_immortal
                remove_trait = 100_stat_man
                remove_trait = nnn_challenger
                remove_trait = build_speed_cheat
                remove_trait = stress_gain_remove
                remove_trait = tyranny_gain_remove
            }
        }
        else = {
            remove_trait = DI_immortal
            remove_trait = 100_stat_man
            remove_trait = nnn_challenger
            remove_trait = build_speed_cheat
            remove_trait = stress_gain_remove
            remove_trait = tyranny_gain_remove
        }
    }
}

### Add All Commander Traits
DI_ce_add_commander_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_add_commander_traits_effect = yes
            }
        }
        else = {
            DI_add_commander_traits_effect = yes
        }
    }
}

### Remove All Commander Traits
DI_ce_remove_commander_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_remove_commander_traits_effect = yes
            }
        }
        else = {
            DI_remove_commander_traits_effect = yes
        }
    }
}


### Add All education Traits
DI_ce_add_education_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_remove_education_traits_effect = yes
                DI_add_education_traits_effect = yes
            }
        }
        else = {
            DI_remove_education_traits_effect = yes
            DI_add_education_traits_effect = yes
        }
    }
}

### Remove All education Traits
DI_ce_remove_education_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_remove_education_traits_effect = yes
            }
        }
        else = {
            DI_remove_education_traits_effect = yes
        }
    }
}

### Boost Education Traits
DI_ce_boost_education = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_boost_education_traits_effect = yes
            }
        }
        else = {
            DI_boost_education_traits_effect = yes
        }
    }
}

### Add Extra Education Perks
DI_ce_boost_education_extra_perks = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_boost_education_extra_traits_effect = yes
            }
        }
        else = {
            DI_boost_education_extra_traits_effect = yes
        }
    }
}


### Aggressive Traits
DI_ce_add_aggressive_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_clear_personality_traits_effect = yes
                add_trait = wrathful
                add_trait = brave
                add_trait = vengeful
            }
        }
        else = {
            DI_clear_personality_traits_effect = yes
            add_trait = wrathful
            add_trait = brave
            add_trait = vengeful

        }
    }
}

DI_ce_remove_aggressive_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_trait = wrathful
                remove_trait = brave
                remove_trait = vengeful
            }
        }
        else = {
            remove_trait = wrathful
            remove_trait = brave
            remove_trait = vengeful
        }
    }
}

### Timid Traits
DI_ce_add_timid_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_clear_personality_traits_effect = yes
                add_trait = shy
                add_trait = craven
                add_trait = forgiving
            }
        }
        else = {
            DI_clear_personality_traits_effect = yes
            add_trait = shy
            add_trait = craven
            add_trait = forgiving
        }
    }
}

DI_ce_remove_timid_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_trait = shy
                remove_trait = craven
                remove_trait = forgiving
            }
        }
        else = {
            remove_trait = shy
            remove_trait = craven
            remove_trait = forgiving
        }
    }
}

#Correct Personality Traits
DI_ce_correct_personality = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                if = { limit = { has_trait = gluttonous } remove_trait = gluttonous add_trait = temperate }
                if = { limit = { has_trait = greedy } remove_trait = greedy add_trait = generous }
                if = { limit = { has_trait = wrathful } remove_trait = wrathful add_trait = calm }
                if = { limit = { has_trait = impatient } remove_trait = impatient add_trait = patient }
                if = { limit = { has_trait = arrogant } remove_trait = arrogant add_trait = humble }
                if = { limit = { has_trait = craven } remove_trait = craven add_trait = brave }
                if = { limit = { has_trait = arbitrary } remove_trait = arbitrary add_trait = just }
                if = { limit = { has_trait = lustful } remove_trait = lustful add_trait = chaste }
                if = { limit = { has_trait = deceitful } remove_trait = deceitful add_trait = honest }
                if = { limit = { has_trait = shy } remove_trait = shy add_trait = gregarious }
                if = { limit = { has_trait = callous } remove_trait = callous add_trait = compassionate }
                if = { limit = { has_trait = sadistic } remove_trait = sadistic add_trait = compassionate }
                if = { limit = { has_trait = vengeful } remove_trait = vengeful add_trait = forgiving }
                if = { limit = { has_trait = lazy } remove_trait = lazy add_trait = diligent }
            }
        }
        else = {
            if = { limit = { has_trait = gluttonous } remove_trait = gluttonous add_trait = temperate }
            if = { limit = { has_trait = greedy } remove_trait = greedy add_trait = generous }
            if = { limit = { has_trait = wrathful } remove_trait = wrathful add_trait = calm }
            if = { limit = { has_trait = impatient } remove_trait = impatient add_trait = patient }
            if = { limit = { has_trait = arrogant } remove_trait = arrogant add_trait = humble }
            if = { limit = { has_trait = craven } remove_trait = craven add_trait = brave }
            if = { limit = { has_trait = arbitrary } remove_trait = arbitrary add_trait = just }
            if = { limit = { has_trait = lustful } remove_trait = lustful add_trait = chaste }
            if = { limit = { has_trait = deceitful } remove_trait = deceitful add_trait = honest }
            if = { limit = { has_trait = shy } remove_trait = shy add_trait = gregarious }
            if = { limit = { has_trait = callous } remove_trait = callous add_trait = compassionate }
            if = { limit = { has_trait = sadistic } remove_trait = sadistic add_trait = compassionate }
            if = { limit = { has_trait = vengeful } remove_trait = vengeful add_trait = forgiving }
            if = { limit = { has_trait = lazy } remove_trait = lazy add_trait = diligent }
        }
    }
}

### Add Character traits that make the character a giant
DI_ce_add_giant_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_trait = dwarf
                remove_trait = physique_good_1
                remove_trait = physique_good_2
                remove_trait = physique_bad_1
                remove_trait = physique_bad_2
                remove_trait = physique_bad_3
                change_current_weight = 100
                add_trait = physique_good_3
                add_trait = giant
            }
        }
        else = {
            remove_trait = dwarf
            remove_trait = physique_good_1
            remove_trait = physique_good_2
            remove_trait = physique_bad_1
            remove_trait = physique_bad_2
            remove_trait = physique_bad_3
            change_current_weight = 100
            add_trait = physique_good_3
            add_trait = giant
        }
    }
}

### Remove Traits Giant
DI_ce_remove_giant_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                DI_set_weight_0 = yes
                remove_trait = physique_good_3
                remove_trait = giant
            }
        }
        else = {
            DI_set_weight_0 = yes
            remove_trait = physique_good_3
            remove_trait = giant
        }
    }
}

### Add Character traits that make the character a midget
DI_ce_add_dwarf_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_trait = giant
                remove_trait = physique_good_1
                remove_trait = physique_good_2
                remove_trait = physique_good_3
                remove_trait = physique_bad_1
                remove_trait = physique_bad_2
                change_current_weight = 0
                add_trait = physique_bad_3
                add_trait = dwarf
            }
        }
        else = {
            remove_trait = giant
            remove_trait = physique_good_1
            remove_trait = physique_good_2
            remove_trait = physique_good_3
            remove_trait = physique_bad_1
            remove_trait = physique_bad_2
            change_current_weight = 0
            add_trait = physique_bad_3
            add_trait = dwarf
        }
    }
}

### Remove Traits Midget
DI_ce_remove_dwarf_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_trait = physique_bad_3
                remove_trait = dwarf
            }
        }
        else = {
            remove_trait = physique_bad_3
            remove_trait = dwarf
        }
    }
}

### Add Character traits that make the character ghostly
DI_ce_add_albino_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                change_current_weight = 0
                add_trait = albino
                add_trait = spindly
            }
        }
        else = {
            change_current_weight = 0
            add_trait = albino
            add_trait = spindly
        }
    }
}

### Remove Traits Ghostly
DI_ce_remove_albino_traits = {
    scope = character

    effect = {
        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        if = {
            limit = {
                scope:DI_story = { has_variable = DI_pinned_char_var }
            }
            every_living_character = {
                limit = {
                    has_character_flag = pinned_for_edit
                }
                remove_trait = albino
                remove_trait = spindly
            }
        }
        else = {
            remove_trait = albino
            remove_trait = spindly
        }
    }
}

### Present Laws ###
DI_ce_gender_equality = {
    scope = character # Player

    effect = {
        save_scope_as = player

        scope:player.faith = {
            ## DOCTRINE_GENDER
            if = {
                limit = { has_doctrine = doctrine_gender_male_dominated }
                remove_doctrine = doctrine_gender_male_dominated
            }
            else_if = {
                limit = { has_doctrine = doctrine_gender_female_dominated }
                remove_doctrine = doctrine_gender_female_dominated
            }

            if = {
                limit = { NOT = { has_doctrine = doctrine_gender_equal } }
                add_doctrine = doctrine_gender_equal
            }

            ## DOCTRINE_CLERICAL_GENDER
            if = {
                limit = { has_doctrine = doctrine_clerical_gender_male_only }
                remove_doctrine = doctrine_clerical_gender_male_only
            }
            else_if = {
                limit = { has_doctrine = doctrine_clerical_gender_female_only }
                remove_doctrine = doctrine_clerical_gender_female_only
            }

            if = {
                limit = { NOT = { has_doctrine = doctrine_clerical_gender_either } }
                add_doctrine = doctrine_clerical_gender_either
            }


            ## DOCTRINE_ADULTERY_MEN & DOCTRINE_ADULTERY_WOMEN
            #Makes the adultery doctrine same for both genders (picks lesser version)

            #Any of them accepted? Both should be accepted
            if = {
                limit = {
                    OR = {
                        has_doctrine = doctrine_adultery_men_accepted
                        has_doctrine = doctrine_adultery_women_accepted
                    }
                }

                #Is male wrong?
                if = {
                    limit = { NOT = { has_doctrine = doctrine_adultery_men_accepted } }

                    if = {
                        limit = { has_doctrine = doctrine_adultery_men_crime }
                        remove_doctrine = doctrine_adultery_men_crime
                    }
                    else_if = {
                        limit = { has_doctrine = doctrine_adultery_men_shunned }
                        remove_doctrine = doctrine_adultery_men_shunned
                    }
                    add_doctrine = doctrine_adultery_men_accepted
                }

                #Is female wrong?
                if = {
                    limit = { NOT = { has_doctrine = doctrine_adultery_women_accepted } }

                    if = {
                        limit = { has_doctrine = doctrine_adultery_women_crime }
                        remove_doctrine = doctrine_adultery_women_crime
                    }
                    else_if = {
                        limit = { has_doctrine = doctrine_adultery_women_shunned }
                        remove_doctrine = doctrine_adultery_women_shunned
                    }
                    add_doctrine = doctrine_adultery_women_accepted
                }
            }
            ##Any of them shunned? Both should be shunned
            else_if = {
                limit = {
                    OR = {
                        has_doctrine = doctrine_adultery_men_shunned
                        has_doctrine = doctrine_adultery_women_shunned
                    }
                }

                #Is male wrong?
                if = {
                    limit = { NOT = { has_doctrine = doctrine_adultery_men_shunned } }
                    remove_doctrine = doctrine_adultery_men_crime
                    add_doctrine = doctrine_adultery_men_shunned
                }

                #Is female wrong?
                if = {
                    limit = { NOT = { has_doctrine = doctrine_adultery_women_shunned } }
                    remove_doctrine = doctrine_adultery_women_crime
                    add_doctrine = doctrine_adultery_women_shunned
                }
            }
            ##Else: they're both criminal, nothing to do here
        }

        if = {
            limit = {
                OR = {
                    has_realm_law = male_preference_law
                    has_realm_law = female_preference_law
                    has_realm_law = female_only_law
                    has_realm_law = male_only_law
                }
            }
            add_realm_law = equal_law
        }

        scope:player.culture = {
            if = {
                limit = {
                    OR = {
                        has_cultural_pillar = martial_custom_male_only
                        has_cultural_pillar = martial_custom_female_only
                    }
                }
                set_culture_pillar = martial_custom_equal
            }
        }
    }
}

DI_ce_inverse_genders = {
    scope = character # Player

    effect = {
        save_scope_as = player

        scope:player.faith = {
            ## DOCTRINE_GENDER
            if = {
                limit = { has_doctrine = doctrine_gender_male_dominated }
                remove_doctrine = doctrine_gender_male_dominated
                add_doctrine = doctrine_gender_female_dominated
            }
            else_if = {
                limit = { has_doctrine = doctrine_gender_female_dominated }
                remove_doctrine = doctrine_gender_female_dominated
                add_doctrine = doctrine_gender_male_dominated
            }
            #Else: equal, do nothing

            ## DOCTRINE_CLERICAL_GENDER
            if = {
                limit = { has_doctrine = doctrine_clerical_gender_male_only }
                remove_doctrine = doctrine_clerical_gender_male_only
                add_doctrine = doctrine_clerical_gender_female_only
            }
            else_if = {
                limit = { has_doctrine = doctrine_clerical_gender_female_only }
                remove_doctrine = doctrine_clerical_gender_female_only
                add_doctrine = doctrine_clerical_gender_male_only
            }
            #Else: either, do nothing

            ## DOCTRINE_ADULTERY_MEN & DOCTRINE_ADULTERY_WOMEN
            # Men and women swap doctrine
            if = {
                limit = {
                    NOR = {
                        AND = {
                            has_doctrine = doctrine_adultery_women_accepted
                            has_doctrine = doctrine_adultery_men_accepted
                        }
                        AND = {
                            has_doctrine = doctrine_adultery_women_shunned
                            has_doctrine = doctrine_adultery_men_shunned
                        }
                        AND = {
                            has_doctrine = doctrine_adultery_women_crime
                            has_doctrine = doctrine_adultery_men_crime
                        }
                    }
                }
                # Save women's doctrine
                if = {
                    limit = { has_doctrine = doctrine_adultery_women_accepted }
                    save_scope_value_as = {
                        name = doctrine_adultery_women
                        value = flag:doctrine_adultery_women_accepted
                    }
                }
                else_if = {
                    limit = {  has_doctrine = doctrine_adultery_women_shunned }
                    save_scope_value_as = {
                        name = doctrine_adultery_women
                        value = flag:doctrine_adultery_women_shunned
                    }
                }
                else_if = {
                    limit = {  has_doctrine = doctrine_adultery_women_crime }
                    save_scope_value_as = {
                        name = doctrine_adultery_women
                        value = flag:doctrine_adultery_women_crime
                    }
                }

                # Give women mens' doctrine
                if = {
                    limit = { has_doctrine = doctrine_adultery_men_accepted }
                    if = {
                        limit = { has_doctrine = doctrine_adultery_women_shunned }
                        remove_doctrine = doctrine_adultery_women_shunned
                    }
                    else_if = {
                        limit = { has_doctrine = doctrine_adultery_women_crime }
                        remove_doctrine = doctrine_adultery_women_crime
                    }
                    add_doctrine = doctrine_adultery_women_accepted
                }
                else_if = {
                    limit = { has_doctrine = doctrine_adultery_men_shunned }
                    if = {
                        limit = { has_doctrine = doctrine_adultery_women_accepted }
                        remove_doctrine = doctrine_adultery_women_accepted
                    }
                    else_if = {
                        limit = { has_doctrine = doctrine_adultery_women_crime }
                        remove_doctrine = doctrine_adultery_women_crime
                    }
                    add_doctrine = doctrine_adultery_women_shunned
                }
                else_if = {
                    limit = { has_doctrine = doctrine_adultery_men_crime }
                    if = {
                        limit = { has_doctrine = doctrine_adultery_women_accepted }
                        remove_doctrine = doctrine_adultery_women_accepted
                    }
                    else_if = {
                        limit = { has_doctrine = doctrine_adultery_women_shunned }
                        remove_doctrine = doctrine_adultery_women_shunned
                    }
                    add_doctrine = doctrine_adultery_women_crime
                }

                # Give men women' doctrine
                if = {
                    limit = { scope:doctrine_adultery_women = flag:doctrine_adultery_women_accepted }
                    if = {
                        limit = { has_doctrine = doctrine_adultery_men_shunned }
                        remove_doctrine = doctrine_adultery_men_shunned
                    }
                    else_if = {
                        limit = { has_doctrine = doctrine_adultery_men_crime }
                        remove_doctrine = doctrine_adultery_men_crime
                    }
                    add_doctrine = doctrine_adultery_men_accepted
                }
                else_if = {
                    limit = { scope:doctrine_adultery_women = flag:doctrine_adultery_women_shunned }
                    if = {
                        limit = { has_doctrine = doctrine_adultery_men_accepted }
                        remove_doctrine = doctrine_adultery_men_accepted
                    }
                    else_if = {
                        limit = { has_doctrine = doctrine_adultery_men_crime }
                        remove_doctrine = doctrine_adultery_men_crime
                    }
                    add_doctrine = doctrine_adultery_men_shunned
                }
                else_if = {
                    limit = { scope:doctrine_adultery_women = flag:doctrine_adultery_women_crime }
                    if = {
                        limit = { has_doctrine = doctrine_adultery_men_accepted }
                        remove_doctrine = doctrine_adultery_men_accepted
                    }
                    else_if = {
                        limit = { has_doctrine = doctrine_adultery_men_shunned }
                        remove_doctrine = doctrine_adultery_men_shunned
                    }
                    add_doctrine = doctrine_adultery_men_crime
                }
            }
        }

        # Take care of any titles with their own title laws.
        every_held_title = {
            limit = { can_title_have_law_general_trigger = yes }
            # Invert male-only.
            if = {
                limit = { has_title_law = male_only_law }
                remove_title_law = male_only_law
                add_title_law = female_only_law
            }
            # Invert female-only.
            else_if = {
                limit = { has_title_law = female_only_law }
                remove_title_law = female_only_law
                add_title_law = male_only_law
            }
        }
        # Now realm law.
        if = {
            limit = { has_realm_law = male_only_law }
            add_realm_law = female_only_law
            if = {
                limit = {
                    highest_held_title_tier >= tier_county
                    is_male = yes
                    is_ai = yes
                    any_heir = { is_female = yes }
                }
                depose = yes
            }
        }
        else_if = {
            limit = { has_realm_law = male_preference_law }
            add_realm_law = female_preference_law
            if = {
                limit = {
                    highest_held_title_tier >= tier_county
                    is_male = yes
                    is_ai = yes
                    any_heir = { is_female = yes }
                }
                depose = yes
            }
        }
        else_if = {
            limit = { has_realm_law = female_preference_law }
            add_realm_law = male_preference_law
            if = {
                limit = {
                    highest_held_title_tier >= tier_county
                    is_female = yes
                    is_ai = yes
                    any_heir = { is_male = yes }
                }
                depose = yes
            }
        }
        else_if = {
            limit = { has_realm_law = female_only_law }
            add_realm_law = male_only_law
            if = {
                limit = {
                    highest_held_title_tier >= tier_county
                    is_female = yes
                    is_ai = yes
                    any_heir = { is_male = yes }
                }
                depose = yes
            }
        }
        #Else: equal, nothing changes

        scope:player.faith = {
            if = {
                limit = {
                    has_doctrine = doctrine_clerical_gender_male_only
                    religious_head ?= { is_female = yes }
                }
                religious_head = { depose = yes }
            }
            else_if = {
                limit = {
                    has_doctrine = doctrine_clerical_gender_female_only
                    religious_head ?= { is_male = yes }
                }
                religious_head = { depose = yes }
            }
        }

        scope:player.culture = {
            if = {
                limit = { has_cultural_pillar = martial_custom_male_only }
                set_culture_pillar = martial_custom_female_only
            }
            else_if = {
                limit = { has_cultural_pillar = martial_custom_female_only }
                set_culture_pillar = martial_custom_male_only
            }
        }
    }
}

DI_ce_female_dominated = {
    scope = character # Player

    effect = {
        save_scope_as = player

        scope:player.faith = {
            ## DOCTRINE_GENDER
            if = {
                limit = { has_doctrine = doctrine_gender_equal }
                remove_doctrine = doctrine_gender_equal
            }
            else_if = {
                limit = { has_doctrine = doctrine_gender_male_dominated }
                remove_doctrine = doctrine_gender_male_dominated
            }

            if = {
                limit = { NOT = { has_doctrine = doctrine_gender_female_dominated } }
                add_doctrine = doctrine_gender_female_dominated
            }

            ## DOCTRINE_CLERICAL_GENDER
            if = {
                limit = { has_doctrine = doctrine_clerical_gender_male_only }
                remove_doctrine = doctrine_clerical_gender_male_only
            }
            else_if = {
                limit = { has_doctrine = doctrine_clerical_gender_either }
                remove_doctrine = doctrine_clerical_gender_either
            }

            if = {
                limit = { NOT = { has_doctrine = doctrine_clerical_gender_female_only } }
                add_doctrine = doctrine_clerical_gender_female_only
            }

            ## DOCTRINE_ADULTERY_MEN & DOCTRINE_ADULTERY_WOMEN
            # Remove accepted for men, add shunned
            # Add accepted for women, remove shunned
            if = {
                limit = {
                    has_doctrine = doctrine_adultery_women_shunned
                }
                remove_doctrine = doctrine_adultery_women_shunned
            }
            if = {
                limit = {
                    has_doctrine = doctrine_adultery_women_crime
                }
                remove_doctrine = doctrine_adultery_women_crime
            }
            if = {
                limit = {
                    NOT = {
                        has_doctrine = doctrine_adultery_women_accepted
                    }
                }
                add_doctrine = doctrine_adultery_women_accepted
            }
            if = {
                limit = {
                    has_doctrine = doctrine_adultery_men_accepted
                }
                remove_doctrine = doctrine_adultery_men_accepted
            }
            if = {
                limit = {
                    NOT = {
                        has_doctrine = doctrine_adultery_men_shunned
                    }
                }
                add_doctrine = doctrine_adultery_men_shunned
            }

            if = {
                limit = {
                    has_doctrine = doctrine_clerical_gender_female_only
                    religious_head ?= { is_male = yes }
                }
                religious_head = { depose = yes }
            }
        }

        scope:player.culture = {
            if = {
                limit = { has_cultural_pillar = martial_custom_male_only }
                set_culture_pillar = martial_custom_female_only
            }
            else_if = {
                limit = { has_cultural_pillar = martial_custom_female_only }
                set_culture_pillar = martial_custom_male_only
            }
        }

        if = {
            limit = {
                OR = {
                    has_realm_law = male_preference_law
                    has_realm_law = male_only_law
                    has_realm_law = female_preference_law
                    has_realm_law = equal_law
                }
            }
            add_realm_law = female_only_law
        }
        if = {
            limit = {
                scope:player.primary_title = title:e_hre
            }
            scope:player.primary_title = {
                remove_title_law = male_only_law
                add_title_law = female_only_law
            }
        }

        scope:player.culture = {
            if = {
                limit = {
                    OR = {
                        has_cultural_pillar = martial_custom_male_only
                        has_cultural_pillar = martial_custom_equal
                    }
                }
                set_culture_pillar = martial_custom_female_only
            }
        }
    }
}

DI_ce_male_dominated = {
    scope = character # Player

    effect = {
        save_scope_as = player

        scope:player.faith = {
            ## DOCTRINE_GENDER
            if = {
                limit = { has_doctrine = doctrine_gender_equal }
                remove_doctrine = doctrine_gender_equal
            }
            else_if = {
                limit = { has_doctrine = doctrine_gender_female_dominated }
                remove_doctrine = doctrine_gender_female_dominated
            }

            if = {
                limit = { NOT = { has_doctrine = doctrine_gender_male_dominated } }
                add_doctrine = doctrine_gender_male_dominated
            }

            ## DOCTRINE_CLERICAL_GENDER
            if = {
                limit = { has_doctrine = doctrine_clerical_gender_female_only }
                remove_doctrine = doctrine_clerical_gender_female_only
            }
            else_if = {
                limit = { has_doctrine = doctrine_clerical_gender_either }
                remove_doctrine = doctrine_clerical_gender_either
            }

            if = {
                limit = { NOT = { has_doctrine = doctrine_clerical_gender_male_only } }
                add_doctrine = doctrine_clerical_gender_male_only
            }


            ## DOCTRINE_ADULTERY_MEN & DOCTRINE_ADULTERY_WOMEN
            # Remove accepted for women, add shunned
            # Add accepted for men, remove shunned
            if = {
                limit = {
                    has_doctrine = doctrine_adultery_men_shunned
                }
                remove_doctrine = doctrine_adultery_men_shunned
            }
            if = {
                limit = {
                    has_doctrine = doctrine_adultery_men_crime
                }
                remove_doctrine = doctrine_adultery_men_crime
            }
            if = {
                limit = {
                    NOT = {
                        has_doctrine = doctrine_adultery_men_accepted
                    }
                }
                add_doctrine = doctrine_adultery_men_accepted
            }
            if = {
                limit = {
                    has_doctrine = doctrine_adultery_women_accepted
                }
                remove_doctrine = doctrine_adultery_women_accepted
            }
            if = {
                limit = {
                    NOT = {
                        has_doctrine = doctrine_adultery_women_shunned
                    }
                }
                add_doctrine = doctrine_adultery_women_shunned
            }

            if = {
                limit = {
                    has_doctrine = doctrine_clerical_gender_male_only
                    religious_head ?= { is_female = yes }
                }
                religious_head = { depose = yes }
            }
        }

        if = {
            limit = {
                OR = {
                    has_realm_law = male_preference_law
                    has_realm_law = female_only_law
                    has_realm_law = female_preference_law
                    has_realm_law = equal_law
                }
            }
            add_realm_law = male_only_law
        }

        scope:player.culture = {
            if = {
                limit = {
                    OR = {
                        has_cultural_pillar = martial_custom_female_only
                        has_cultural_pillar = martial_custom_equal
                    }
                }
                set_culture_pillar = martial_custom_male_only
            }
        }
    }
}

# temporal head of faith
DI_ce_temporal_hof = {
    scope = character # Player

    effect = {
        save_scope_as = player

        scope:player.faith = {
            if = {
                limit = {
                    OR = {
                        has_doctrine = doctrine_clerical_succession_spiritual_fixed_appointment
                        has_doctrine = doctrine_clerical_succession_spiritual_appointment
                        has_doctrine = doctrine_clerical_succession_temporal_fixed_appointment
                    }
                }
                if = {
                    limit = {
                        has_doctrine = doctrine_clerical_succession_spiritual_fixed_appointment
                    }
                    remove_doctrine = doctrine_clerical_succession_spiritual_fixed_appointment
                }
                else_if = {
                    limit = {
                        has_doctrine = doctrine_clerical_succession_spiritual_appointment
                    }
                    remove_doctrine = doctrine_clerical_succession_spiritual_appointment
                }
                else_if = {
                    limit = {
                        has_doctrine = doctrine_clerical_succession_temporal_fixed_appointment
                    }
                    remove_doctrine = doctrine_clerical_succession_temporal_fixed_appointment
                }
                add_doctrine = doctrine_clerical_succession_temporal_appointment
            }

            if = {
                limit = {
                    has_doctrine = doctrine_theocracy_temporal
                }
                remove_doctrine = doctrine_theocracy_temporal
                add_doctrine = doctrine_theocracy_lay_clergy
            }

            if = {
                limit = {
                    OR = {
                        has_doctrine = doctrine_no_head
                        has_doctrine = doctrine_spiritual_head
                    }
                }
                if = {
                    limit = {
                        has_doctrine = doctrine_no_head
                    }
                    remove_doctrine = doctrine_no_head
                }
                else_if = {
                    limit = {
                        has_doctrine = doctrine_spiritual_head
                    }
                    remove_doctrine = doctrine_spiritual_head
                }
                add_doctrine = doctrine_temporal_head
            }

            if = {
                limit = {
                    has_doctrine = doctrine_temporal_head
                }

                set_religious_head_title = scope:player.primary_title
            }
        }
    }
}