﻿### Modifier management ###
### life_expectancy_modifier ###
DI_add_modifier_life_expectancy_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = life_expectancy_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = life_expectancy_modifier
    }
}
}
}

DI_remove_modifier_life_expectancy_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = life_expectancy_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = life_expectancy_modifier
    }
}
}
}

DI_add_modifier_life_expectancy_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = life_expectancy_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = life_expectancy_modifier_neg
    }
}
}
}

DI_remove_modifier_life_expectancy_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = life_expectancy_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = life_expectancy_modifier_neg
    }
}
}
}
### martial_per_piety_level ###
DI_add_modifier_martial_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = martial_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = martial_per_piety_level
    }
}
}
}

DI_remove_modifier_martial_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = martial_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = martial_per_piety_level
    }
}
}
}

DI_add_modifier_martial_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = martial_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = martial_per_piety_level_neg
    }
}
}
}

DI_remove_modifier_martial_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = martial_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = martial_per_piety_level_neg
    }
}
}
}
### diplomacy_per_piety_level ###
DI_add_modifier_diplomacy_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomacy_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomacy_per_piety_level
    }
}
}
}

DI_remove_modifier_diplomacy_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomacy_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomacy_per_piety_level
    }
}
}
}

DI_add_modifier_diplomacy_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomacy_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomacy_per_piety_level_neg
    }
}
}
}

DI_remove_modifier_diplomacy_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomacy_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomacy_per_piety_level_neg
    }
}
}
}
### stewardship_per_piety_level ###
DI_add_modifier_stewardship_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stewardship_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stewardship_per_piety_level
    }
}
}
}

DI_remove_modifier_stewardship_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stewardship_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stewardship_per_piety_level
    }
}
}
}

DI_add_modifier_stewardship_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stewardship_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stewardship_per_piety_level_neg
    }
}
}
}

DI_remove_modifier_stewardship_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stewardship_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stewardship_per_piety_level_neg
    }
}
}
}
### intrigue_per_piety_level ###
DI_add_modifier_intrigue_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intrigue_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intrigue_per_piety_level
    }
}
}
}

DI_remove_modifier_intrigue_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intrigue_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intrigue_per_piety_level
    }
}
}
}

DI_add_modifier_intrigue_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intrigue_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intrigue_per_piety_level_neg
    }
}
}
}

DI_remove_modifier_intrigue_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intrigue_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intrigue_per_piety_level_neg
    }
}
}
}
### learning_per_piety_level ###
DI_add_modifier_learning_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = learning_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = learning_per_piety_level
    }
}
}
}

DI_remove_modifier_learning_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = learning_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = learning_per_piety_level
    }
}
}
}

DI_add_modifier_learning_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = learning_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = learning_per_piety_level_neg
    }
}
}
}

DI_remove_modifier_learning_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = learning_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = learning_per_piety_level_neg
    }
}
}
}
### prowess_per_piety_level ###
DI_add_modifier_prowess_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prowess_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prowess_per_piety_level
    }
}
}
}

DI_remove_modifier_prowess_per_piety_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prowess_per_piety_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prowess_per_piety_level
    }
}
}
}

DI_add_modifier_prowess_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prowess_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prowess_per_piety_level_neg
    }
}
}
}

DI_remove_modifier_prowess_per_piety_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prowess_per_piety_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prowess_per_piety_level_neg
    }
}
}
}
### martial_per_prestige_level ###
DI_add_modifier_martial_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = martial_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = martial_per_prestige_level
    }
}
}
}

DI_remove_modifier_martial_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = martial_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = martial_per_prestige_level
    }
}
}
}

DI_add_modifier_martial_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = martial_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = martial_per_prestige_level_neg
    }
}
}
}

DI_remove_modifier_martial_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = martial_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = martial_per_prestige_level_neg
    }
}
}
}
### diplomacy_per_prestige_level ###
DI_add_modifier_diplomacy_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomacy_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomacy_per_prestige_level
    }
}
}
}

DI_remove_modifier_diplomacy_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomacy_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomacy_per_prestige_level
    }
}
}
}

DI_add_modifier_diplomacy_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomacy_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomacy_per_prestige_level_neg
    }
}
}
}

DI_remove_modifier_diplomacy_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomacy_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomacy_per_prestige_level_neg
    }
}
}
}
### stewardship_per_prestige_level ###
DI_add_modifier_stewardship_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stewardship_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stewardship_per_prestige_level
    }
}
}
}

DI_remove_modifier_stewardship_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stewardship_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stewardship_per_prestige_level
    }
}
}
}

DI_add_modifier_stewardship_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stewardship_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stewardship_per_prestige_level_neg
    }
}
}
}

DI_remove_modifier_stewardship_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stewardship_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stewardship_per_prestige_level_neg
    }
}
}
}
### intrigue_per_prestige_level ###
DI_add_modifier_intrigue_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intrigue_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intrigue_per_prestige_level
    }
}
}
}

DI_remove_modifier_intrigue_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intrigue_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intrigue_per_prestige_level
    }
}
}
}

DI_add_modifier_intrigue_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intrigue_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intrigue_per_prestige_level_neg
    }
}
}
}

DI_remove_modifier_intrigue_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intrigue_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intrigue_per_prestige_level_neg
    }
}
}
}
### learning_per_prestige_level ###
DI_add_modifier_learning_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = learning_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = learning_per_prestige_level
    }
}
}
}

DI_remove_modifier_learning_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = learning_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = learning_per_prestige_level
    }
}
}
}

DI_add_modifier_learning_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = learning_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = learning_per_prestige_level_neg
    }
}
}
}

DI_remove_modifier_learning_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = learning_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = learning_per_prestige_level_neg
    }
}
}
}
### prowess_per_prestige_level ###
DI_add_modifier_prowess_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prowess_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prowess_per_prestige_level
    }
}
}
}

DI_remove_modifier_prowess_per_prestige_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prowess_per_prestige_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prowess_per_prestige_level
    }
}
}
}

DI_add_modifier_prowess_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prowess_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prowess_per_prestige_level_neg
    }
}
}
}

DI_remove_modifier_prowess_per_prestige_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prowess_per_prestige_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prowess_per_prestige_level_neg
    }
}
}
}
### piety_level_impact_mult ###
DI_add_modifier_piety_level_impact_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = piety_level_impact_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = piety_level_impact_mult
    }
}
}
}

DI_remove_modifier_piety_level_impact_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = piety_level_impact_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = piety_level_impact_mult
    }
}
}
}

DI_add_modifier_piety_level_impact_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = piety_level_impact_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = piety_level_impact_mult_neg
    }
}
}
}

DI_remove_modifier_piety_level_impact_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = piety_level_impact_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = piety_level_impact_mult_neg
    }
}
}
}
### prestige_level_impact_mult ###
DI_add_modifier_prestige_level_impact_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prestige_level_impact_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prestige_level_impact_mult
    }
}
}
}

DI_remove_modifier_prestige_level_impact_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prestige_level_impact_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prestige_level_impact_mult
    }
}
}
}

DI_add_modifier_prestige_level_impact_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prestige_level_impact_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prestige_level_impact_mult_neg
    }
}
}
}

DI_remove_modifier_prestige_level_impact_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prestige_level_impact_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prestige_level_impact_mult_neg
    }
}
}
}
### martial_per_stress_level ###
DI_add_modifier_martial_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = martial_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = martial_per_stress_level
    }
}
}
}

DI_remove_modifier_martial_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = martial_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = martial_per_stress_level
    }
}
}
}

DI_add_modifier_martial_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = martial_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = martial_per_stress_level_neg
    }
}
}
}

DI_remove_modifier_martial_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = martial_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = martial_per_stress_level_neg
    }
}
}
}
### diplomacy_per_stress_level ###
DI_add_modifier_diplomacy_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomacy_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomacy_per_stress_level
    }
}
}
}

DI_remove_modifier_diplomacy_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomacy_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomacy_per_stress_level
    }
}
}
}

DI_add_modifier_diplomacy_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomacy_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomacy_per_stress_level_neg
    }
}
}
}

DI_remove_modifier_diplomacy_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomacy_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomacy_per_stress_level_neg
    }
}
}
}
### stewardship_per_stress_level ###
DI_add_modifier_stewardship_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stewardship_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stewardship_per_stress_level
    }
}
}
}

DI_remove_modifier_stewardship_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stewardship_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stewardship_per_stress_level
    }
}
}
}

DI_add_modifier_stewardship_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stewardship_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stewardship_per_stress_level_neg
    }
}
}
}

DI_remove_modifier_stewardship_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stewardship_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stewardship_per_stress_level_neg
    }
}
}
}
### intrigue_per_stress_level ###
DI_add_modifier_intrigue_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intrigue_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intrigue_per_stress_level
    }
}
}
}

DI_remove_modifier_intrigue_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intrigue_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intrigue_per_stress_level
    }
}
}
}

DI_add_modifier_intrigue_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intrigue_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intrigue_per_stress_level_neg
    }
}
}
}

DI_remove_modifier_intrigue_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intrigue_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intrigue_per_stress_level_neg
    }
}
}
}
### learning_per_stress_level ###
DI_add_modifier_learning_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = learning_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = learning_per_stress_level
    }
}
}
}

DI_remove_modifier_learning_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = learning_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = learning_per_stress_level
    }
}
}
}

DI_add_modifier_learning_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = learning_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = learning_per_stress_level_neg
    }
}
}
}

DI_remove_modifier_learning_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = learning_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = learning_per_stress_level_neg
    }
}
}
}
### prowess_per_stress_level ###
DI_add_modifier_prowess_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prowess_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prowess_per_stress_level
    }
}
}
}

DI_remove_modifier_prowess_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prowess_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prowess_per_stress_level
    }
}
}
}

DI_add_modifier_prowess_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prowess_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prowess_per_stress_level_neg
    }
}
}
}

DI_remove_modifier_prowess_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prowess_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prowess_per_stress_level_neg
    }
}
}
}
### fertility_modifier ###
DI_add_modifier_fertility_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = fertility_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = fertility_modifier
    }
}
}
}

DI_remove_modifier_fertility_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = fertility_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = fertility_modifier
    }
}
}
}

DI_add_modifier_fertility_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = fertility_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = fertility_modifier_neg
    }
}
}
}

DI_remove_modifier_fertility_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = fertility_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = fertility_modifier_neg
    }
}
}
}
### health_modifier ###
DI_add_modifier_health_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = health_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = health_modifier
    }
}
}
}

DI_remove_modifier_health_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = health_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = health_modifier
    }
}
}
}

DI_add_modifier_health_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = health_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = health_modifier_neg
    }
}
}
}

DI_remove_modifier_health_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = health_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = health_modifier_neg
    }
}
}
}
### negate_health_penalty ###
DI_add_modifier_negate_health_penalty = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = negate_health_penalty
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = negate_health_penalty
    }
}
}
}

DI_remove_modifier_negate_health_penalty = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = negate_health_penalty
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = negate_health_penalty
    }
}
}
}

DI_add_modifier_negate_health_penalty_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = negate_health_penalty_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = negate_health_penalty_neg
    }
}
}
}

DI_remove_modifier_negate_health_penalty_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = negate_health_penalty_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = negate_health_penalty_neg
    }
}
}
}
### negate_fertility_penalty ###
DI_add_modifier_negate_fertility_penalty = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = negate_fertility_penalty
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = negate_fertility_penalty
    }
}
}
}

DI_remove_modifier_negate_fertility_penalty = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = negate_fertility_penalty
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = negate_fertility_penalty
    }
}
}
}

DI_add_modifier_negate_fertility_penalty_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = negate_fertility_penalty_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = negate_fertility_penalty_neg
    }
}
}
}

DI_remove_modifier_negate_fertility_penalty_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = negate_fertility_penalty_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = negate_fertility_penalty_neg
    }
}
}
}
### monthly_income ###
DI_add_modifier_monthly_income = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_income
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_income
    }
}
}
}

DI_remove_modifier_monthly_income = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_income
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_income
    }
}
}
}

DI_add_modifier_monthly_income_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_income_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_income_neg
    }
}
}
}

DI_remove_modifier_monthly_income_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_income_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_income_neg
    }
}
}
}

DI_add_modifier_monthly_income_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_income_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_income_mult
    }
}
}
}

DI_remove_modifier_monthly_income_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_income_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_income_mult
    }
}
}
}

DI_add_modifier_monthly_income_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_income_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_income_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_income_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_income_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_income_mult_neg
    }
}
}
}
### monthly_war_income ###
DI_add_modifier_monthly_war_income = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_war_income
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_war_income
    }
}
}
}

DI_remove_modifier_monthly_war_income = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_war_income
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_war_income
    }
}
}
}

DI_add_modifier_monthly_war_income_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_war_income_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_war_income_neg
    }
}
}
}

DI_remove_modifier_monthly_war_income_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_war_income_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_war_income_neg
    }
}
}
}

DI_add_modifier_monthly_war_income_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_war_income_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_war_income_mult
    }
}
}
}

DI_remove_modifier_monthly_war_income_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_war_income_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_war_income_mult
    }
}
}
}

DI_add_modifier_monthly_war_income_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_war_income_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_war_income_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_war_income_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_war_income_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_war_income_mult_neg
    }
}
}
}
### monthly_income_per_stress_level ###
DI_add_modifier_monthly_income_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_income_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_income_per_stress_level
    }
}
}
}

DI_remove_modifier_monthly_income_per_stress_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_income_per_stress_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_income_per_stress_level
    }
}
}
}

DI_add_modifier_monthly_income_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_income_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_income_per_stress_level_neg
    }
}
}
}

DI_remove_modifier_monthly_income_per_stress_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_income_per_stress_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_income_per_stress_level_neg
    }
}
}
}

DI_add_modifier_monthly_income_per_stress_level_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_income_per_stress_level_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_income_per_stress_level_mult
    }
}
}
}

DI_remove_modifier_monthly_income_per_stress_level_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_income_per_stress_level_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_income_per_stress_level_mult
    }
}
}
}

DI_add_modifier_monthly_income_per_stress_level_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_income_per_stress_level_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_income_per_stress_level_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_income_per_stress_level_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_income_per_stress_level_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_income_per_stress_level_mult_neg
    }
}
}
}
### monthly_piety ###
DI_add_modifier_monthly_piety = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety
    }
}
}
}

DI_remove_modifier_monthly_piety = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety
    }
}
}
}

DI_add_modifier_monthly_piety_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_neg
    }
}
}
}

DI_remove_modifier_monthly_piety_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_neg
    }
}
}
}
### monthly_piety_gain_per_happy_powerful_vassal ###
DI_add_modifier_monthly_piety_gain_per_happy_powerful_vassal = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_happy_powerful_vassal
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_happy_powerful_vassal
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_happy_powerful_vassal = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_happy_powerful_vassal
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_happy_powerful_vassal
    }
}
}
}

DI_add_modifier_monthly_piety_gain_per_happy_powerful_vassal_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_neg
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_happy_powerful_vassal_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_neg
    }
}
}
}

DI_add_modifier_monthly_piety_gain_per_happy_powerful_vassal_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_mult
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_happy_powerful_vassal_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_mult
    }
}
}
}

DI_add_modifier_monthly_piety_gain_per_happy_powerful_vassal_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_happy_powerful_vassal_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_happy_powerful_vassal_mult_neg
    }
}
}
}
### monthly_piety_gain_per_dread ###
DI_add_modifier_monthly_piety_gain_per_dread = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_dread
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_dread
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_dread = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_dread
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_dread
    }
}
}
}

DI_add_modifier_monthly_piety_gain_per_dread_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_dread_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_dread_neg
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_dread_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_dread_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_dread_neg
    }
}
}
}

DI_add_modifier_monthly_piety_gain_per_dread_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_dread_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_dread_mult
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_dread_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_dread_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_dread_mult
    }
}
}
}

DI_add_modifier_monthly_piety_gain_per_dread_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_dread_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_dread_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_dread_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_dread_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_dread_mult_neg
    }
}
}
}
### monthly_piety_gain_per_knight ###
DI_add_modifier_monthly_piety_gain_per_knight = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_knight
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_knight
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_knight = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_knight
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_knight
    }
}
}
}

DI_add_modifier_monthly_piety_gain_per_knight_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_knight_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_knight_neg
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_knight_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_knight_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_knight_neg
    }
}
}
}

DI_add_modifier_monthly_piety_gain_per_knight_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_knight_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_knight_mult
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_knight_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_knight_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_knight_mult
    }
}
}
}

DI_add_modifier_monthly_piety_gain_per_knight_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_gain_per_knight_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_gain_per_knight_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_piety_gain_per_knight_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_gain_per_knight_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_gain_per_knight_mult_neg
    }
}
}
}
### monthly_prestige ###
DI_add_modifier_monthly_prestige = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige
    }
}
}
}

DI_remove_modifier_monthly_prestige = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige
    }
}
}
}

DI_add_modifier_monthly_prestige_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_neg
    }
}
}
}

DI_remove_modifier_monthly_prestige_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_neg
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_mult
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_mult
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_mult_neg
    }
}
}
}
### monthly_prestige_gain_per_happy_powerful_vassal ###
DI_add_modifier_monthly_prestige_gain_per_happy_powerful_vassal = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_happy_powerful_vassal = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_per_happy_powerful_vassal_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_neg
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_happy_powerful_vassal_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_neg
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_per_happy_powerful_vassal_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_mult
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_happy_powerful_vassal_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_mult
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_per_happy_powerful_vassal_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_happy_powerful_vassal_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_happy_powerful_vassal_mult_neg
    }
}
}
}
### monthly_prestige_gain_per_dread ###
DI_add_modifier_monthly_prestige_gain_per_dread = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_dread
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_dread
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_dread = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_dread
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_dread
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_per_dread_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_dread_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_dread_neg
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_dread_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_dread_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_dread_neg
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_per_dread_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_dread_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_dread_mult
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_dread_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_dread_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_dread_mult
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_per_dread_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_dread_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_dread_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_dread_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_dread_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_dread_mult_neg
    }
}
}
}
### monthly_prestige_gain_per_knight ###
DI_add_modifier_monthly_prestige_gain_per_knight = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_knight
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_knight
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_knight = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_knight
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_knight
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_per_knight_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_knight_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_knight_neg
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_knight_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_knight_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_knight_neg
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_per_knight_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_knight_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_knight_mult
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_knight_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_knight_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_knight_mult
    }
}
}
}

DI_add_modifier_monthly_prestige_gain_per_knight_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_gain_per_knight_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_gain_per_knight_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_prestige_gain_per_knight_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_gain_per_knight_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_gain_per_knight_mult_neg
    }
}
}
}
### monthly_piety_from_buildings_mult ###
DI_add_modifier_monthly_piety_from_buildings_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_from_buildings_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_from_buildings_mult
    }
}
}
}

DI_remove_modifier_monthly_piety_from_buildings_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_from_buildings_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_from_buildings_mult
    }
}
}
}

DI_add_modifier_monthly_piety_from_buildings_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_piety_from_buildings_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_piety_from_buildings_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_piety_from_buildings_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_piety_from_buildings_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_piety_from_buildings_mult_neg
    }
}
}
}
### monthly_prestige_from_buildings_mult ###
DI_add_modifier_monthly_prestige_from_buildings_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_from_buildings_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_from_buildings_mult
    }
}
}
}

DI_remove_modifier_monthly_prestige_from_buildings_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_from_buildings_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_from_buildings_mult
    }
}
}
}

DI_add_modifier_monthly_prestige_from_buildings_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_prestige_from_buildings_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_prestige_from_buildings_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_prestige_from_buildings_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_prestige_from_buildings_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_prestige_from_buildings_mult_neg
    }
}
}
}
### monthly_dynasty_prestige ###
DI_add_modifier_monthly_dynasty_prestige = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_dynasty_prestige
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_dynasty_prestige
    }
}
}
}

DI_remove_modifier_monthly_dynasty_prestige = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_dynasty_prestige
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_dynasty_prestige
    }
}
}
}

DI_add_modifier_monthly_dynasty_prestige_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_dynasty_prestige_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_dynasty_prestige_neg
    }
}
}
}

DI_remove_modifier_monthly_dynasty_prestige_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_dynasty_prestige_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_dynasty_prestige_neg
    }
}
}
}

DI_add_modifier_monthly_dynasty_prestige_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_dynasty_prestige_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_dynasty_prestige_mult
    }
}
}
}

DI_remove_modifier_monthly_dynasty_prestige_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_dynasty_prestige_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_dynasty_prestige_mult
    }
}
}
}

DI_add_modifier_monthly_dynasty_prestige_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_dynasty_prestige_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_dynasty_prestige_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_dynasty_prestige_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_dynasty_prestige_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_dynasty_prestige_mult_neg
    }
}
}
}
### stress_gain_mult ###
DI_add_modifier_stress_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stress_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stress_gain_mult
    }
}
}
}

DI_remove_modifier_stress_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stress_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stress_gain_mult
    }
}
}
}

DI_add_modifier_stress_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stress_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stress_gain_mult_neg
    }
}
}
}

DI_remove_modifier_stress_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stress_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stress_gain_mult_neg
    }
}
}
}
### stress_loss_mult ###
DI_add_modifier_stress_loss_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stress_loss_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stress_loss_mult
    }
}
}
}

DI_remove_modifier_stress_loss_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stress_loss_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stress_loss_mult
    }
}
}
}

DI_add_modifier_stress_loss_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stress_loss_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stress_loss_mult_neg
    }
}
}
}

DI_remove_modifier_stress_loss_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stress_loss_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stress_loss_mult_neg
    }
}
}
}
### monthly_dread ###
DI_add_modifier_monthly_dread = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_dread
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_dread
    }
}
}
}

DI_remove_modifier_monthly_dread = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_dread
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_dread
    }
}
}
}

DI_add_modifier_monthly_dread_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_dread_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_dread_neg
    }
}
}
}

DI_remove_modifier_monthly_dread_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_dread_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_dread_neg
    }
}
}
}
### dread_gain_mult ###
DI_add_modifier_dread_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_gain_mult
    }
}
}
}

DI_remove_modifier_dread_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_gain_mult
    }
}
}
}

DI_add_modifier_dread_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_gain_mult_neg
    }
}
}
}

DI_remove_modifier_dread_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_gain_mult_neg
    }
}
}
}
### dread_loss_mult ###
DI_add_modifier_dread_loss_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_loss_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_loss_mult
    }
}
}
}

DI_remove_modifier_dread_loss_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_loss_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_loss_mult
    }
}
}
}

DI_add_modifier_dread_loss_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_loss_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_loss_mult_neg
    }
}
}
}

DI_remove_modifier_dread_loss_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_loss_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_loss_mult_neg
    }
}
}
}
### tyranny_gain_mult ###
DI_add_modifier_tyranny_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tyranny_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tyranny_gain_mult
    }
}
}
}

DI_remove_modifier_tyranny_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tyranny_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tyranny_gain_mult
    }
}
}
}

DI_add_modifier_tyranny_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tyranny_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tyranny_gain_mult_neg
    }
}
}
}

DI_remove_modifier_tyranny_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tyranny_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tyranny_gain_mult_neg
    }
}
}
}
### tyranny_loss_mult ###
DI_add_modifier_tyranny_loss_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tyranny_loss_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tyranny_loss_mult
    }
}
}
}

DI_remove_modifier_tyranny_loss_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tyranny_loss_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tyranny_loss_mult
    }
}
}
}

DI_add_modifier_tyranny_loss_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tyranny_loss_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tyranny_loss_mult_neg
    }
}
}
}

DI_remove_modifier_tyranny_loss_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tyranny_loss_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tyranny_loss_mult_neg
    }
}
}
}
### monthly_tyranny ###
DI_add_modifier_monthly_tyranny = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_tyranny
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_tyranny
    }
}
}
}

DI_remove_modifier_monthly_tyranny = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_tyranny
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_tyranny
    }
}
}
}

DI_add_modifier_monthly_tyranny_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_tyranny_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_tyranny_neg
    }
}
}
}

DI_remove_modifier_monthly_tyranny_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_tyranny_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_tyranny_neg
    }
}
}
}
### dread_baseline ###
DI_add_modifier_dread_baseline = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_baseline
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_baseline
    }
}
}
}

DI_remove_modifier_dread_baseline = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_baseline
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_baseline
    }
}
}
}

DI_add_modifier_dread_baseline_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_baseline_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_baseline_neg
    }
}
}
}

DI_remove_modifier_dread_baseline_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_baseline_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_baseline_neg
    }
}
}
}
### dread_decay ###
DI_add_modifier_dread_decay = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_decay
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_decay
    }
}
}
}

DI_remove_modifier_dread_decay = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_decay
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_decay
    }
}
}
}

DI_add_modifier_dread_decay_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_decay_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_decay_neg
    }
}
}
}

DI_remove_modifier_dread_decay_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_decay_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_decay_neg
    }
}
}
}

DI_add_modifier_dread_decay_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_decay_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_decay_mult
    }
}
}
}

DI_remove_modifier_dread_decay_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_decay_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_decay_mult
    }
}
}
}

DI_add_modifier_dread_decay_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_decay_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_decay_mult_neg
    }
}
}
}

DI_remove_modifier_dread_decay_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_decay_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_decay_mult_neg
    }
}
}
}
### dread_per_tyranny ###
DI_add_modifier_dread_per_tyranny = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_per_tyranny
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_per_tyranny
    }
}
}
}

DI_remove_modifier_dread_per_tyranny = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_per_tyranny
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_per_tyranny
    }
}
}
}

DI_add_modifier_dread_per_tyranny_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_per_tyranny_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_per_tyranny_neg
    }
}
}
}

DI_remove_modifier_dread_per_tyranny_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_per_tyranny_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_per_tyranny_neg
    }
}
}
}

DI_add_modifier_dread_per_tyranny_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_per_tyranny_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_per_tyranny_mult
    }
}
}
}

DI_remove_modifier_dread_per_tyranny_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_per_tyranny_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_per_tyranny_mult
    }
}
}
}

DI_add_modifier_dread_per_tyranny_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dread_per_tyranny_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dread_per_tyranny_mult_neg
    }
}
}
}

DI_remove_modifier_dread_per_tyranny_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dread_per_tyranny_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dread_per_tyranny_mult_neg
    }
}
}
}
### domain_limit ###
DI_add_modifier_domain_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                if = {
                    limit = {
                        NOT = { government_has_flag = government_uses_domain_limit }
                    }
                    add_character_modifier = domain_limit_max
                }

                add_character_modifier = domain_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        if = {
            limit = {
                NOT = { government_has_flag = government_uses_domain_limit }
            }
            add_character_modifier = domain_limit_max
        }

        add_character_modifier = domain_limit
    }
}
}
}

DI_remove_modifier_domain_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_limit_max
                remove_character_modifier = domain_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_limit_max
        remove_character_modifier = domain_limit
    }
}
}
}

DI_add_modifier_domain_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                if = {
                    limit = {
                        NOT = { government_has_flag = government_uses_domain_limit }
                    }
                    add_character_modifier = domain_limit_max_neg
                }

                add_character_modifier = domain_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        if = {
            limit = {
                NOT = { government_has_flag = government_uses_domain_limit }
            }
            add_character_modifier = domain_limit_max_neg
        }

        add_character_modifier = domain_limit_neg
    }
}
}
}

DI_remove_modifier_domain_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_limit_max_neg
                remove_character_modifier = domain_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_limit_max_neg
        remove_character_modifier = domain_limit_neg
    }
}
}
}
### vassal_limit ###
DI_add_modifier_vassal_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_limit
    }
}
}
}

DI_remove_modifier_vassal_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_limit
    }
}
}
}

DI_add_modifier_vassal_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_limit_neg
    }
}
}
}

DI_remove_modifier_vassal_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_limit_neg
    }
}
}
}
### domain_tax_mult ###
DI_add_modifier_domain_tax_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_mult
    }
}
}
}

DI_remove_modifier_domain_tax_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_mult
    }
}
}
}

DI_add_modifier_domain_tax_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_mult_neg
    }
}
}
}

DI_remove_modifier_domain_tax_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_mult_neg
    }
}
}
}
### domain_tax_same_faith_mult ###
DI_add_modifier_domain_tax_same_faith_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_same_faith_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_same_faith_mult
    }
}
}
}

DI_remove_modifier_domain_tax_same_faith_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_same_faith_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_same_faith_mult
    }
}
}
}

DI_add_modifier_domain_tax_same_faith_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_same_faith_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_same_faith_mult_neg
    }
}
}
}

DI_remove_modifier_domain_tax_same_faith_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_same_faith_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_same_faith_mult_neg
    }
}
}
}
### domain_tax_different_faith_mult ###
DI_add_modifier_domain_tax_different_faith_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_different_faith_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_different_faith_mult
    }
}
}
}

DI_remove_modifier_domain_tax_different_faith_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_different_faith_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_different_faith_mult
    }
}
}
}

DI_add_modifier_domain_tax_different_faith_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_different_faith_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_different_faith_mult_neg
    }
}
}
}

DI_remove_modifier_domain_tax_different_faith_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_different_faith_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_different_faith_mult_neg
    }
}
}
}
### domain_tax_mult_even_if_baron ###
DI_add_modifier_domain_tax_mult_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_mult_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_mult_even_if_baron
    }
}
}
}

DI_remove_modifier_domain_tax_mult_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_mult_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_mult_even_if_baron
    }
}
}
}

DI_add_modifier_domain_tax_mult_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_mult_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_mult_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_domain_tax_mult_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_mult_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_mult_even_if_baron_neg
    }
}
}
}
### domain_tax_same_faith_mult_even_if_baron ###
DI_add_modifier_domain_tax_same_faith_mult_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_same_faith_mult_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_same_faith_mult_even_if_baron
    }
}
}
}

DI_remove_modifier_domain_tax_same_faith_mult_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_same_faith_mult_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_same_faith_mult_even_if_baron
    }
}
}
}

DI_add_modifier_domain_tax_same_faith_mult_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_same_faith_mult_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_same_faith_mult_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_domain_tax_same_faith_mult_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_same_faith_mult_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_same_faith_mult_even_if_baron_neg
    }
}
}
}
### domain_tax_different_faith_mult_even_if_baron ###
DI_add_modifier_domain_tax_different_faith_mult_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_different_faith_mult_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_different_faith_mult_even_if_baron
    }
}
}
}

DI_remove_modifier_domain_tax_different_faith_mult_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_different_faith_mult_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_different_faith_mult_even_if_baron
    }
}
}
}

DI_add_modifier_domain_tax_different_faith_mult_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = domain_tax_different_faith_mult_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = domain_tax_different_faith_mult_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_domain_tax_different_faith_mult_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = domain_tax_different_faith_mult_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = domain_tax_different_faith_mult_even_if_baron_neg
    }
}
}
}
### vassal_tax_mult ###
DI_add_modifier_vassal_tax_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_tax_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_tax_mult
    }
}
}
}

DI_remove_modifier_vassal_tax_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_tax_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_tax_mult
    }
}
}
}

DI_add_modifier_vassal_tax_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_tax_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_tax_mult_neg
    }
}
}
}

DI_remove_modifier_vassal_tax_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_tax_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_tax_mult_neg
    }
}
}
}
### men_at_arms_maintenance ###
DI_add_modifier_men_at_arms_maintenance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = men_at_arms_maintenance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = men_at_arms_maintenance
    }
}
}
}

DI_remove_modifier_men_at_arms_maintenance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = men_at_arms_maintenance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = men_at_arms_maintenance
    }
}
}
}

DI_add_modifier_men_at_arms_maintenance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = men_at_arms_maintenance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = men_at_arms_maintenance_neg
    }
}
}
}

DI_remove_modifier_men_at_arms_maintenance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = men_at_arms_maintenance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = men_at_arms_maintenance_neg
    }
}
}
}
### men_at_arms_maintenance_per_dread_mult ###
DI_add_modifier_men_at_arms_maintenance_per_dread_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = men_at_arms_maintenance_per_dread_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = men_at_arms_maintenance_per_dread_mult
    }
}
}
}

DI_remove_modifier_men_at_arms_maintenance_per_dread_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = men_at_arms_maintenance_per_dread_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = men_at_arms_maintenance_per_dread_mult
    }
}
}
}

DI_add_modifier_men_at_arms_maintenance_per_dread_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = men_at_arms_maintenance_per_dread_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = men_at_arms_maintenance_per_dread_mult_neg
    }
}
}
}

DI_remove_modifier_men_at_arms_maintenance_per_dread_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = men_at_arms_maintenance_per_dread_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = men_at_arms_maintenance_per_dread_mult_neg
    }
}
}
}
### army_maintenance_mult ###
DI_add_modifier_army_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = army_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = army_maintenance_mult
    }
}
}
}

DI_remove_modifier_army_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = army_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = army_maintenance_mult
    }
}
}
}

DI_add_modifier_army_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = army_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = army_maintenance_mult_neg
    }
}
}
}

DI_remove_modifier_army_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = army_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = army_maintenance_mult_neg
    }
}
}
}
### short_reign_duration_mult ###
DI_add_modifier_short_reign_duration_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = short_reign_duration_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = short_reign_duration_mult
    }
}
}
}

DI_remove_modifier_short_reign_duration_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = short_reign_duration_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = short_reign_duration_mult
    }
}
}
}

DI_add_modifier_short_reign_duration_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = short_reign_duration_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = short_reign_duration_mult_neg
    }
}
}
}

DI_remove_modifier_short_reign_duration_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = short_reign_duration_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = short_reign_duration_mult_neg
    }
}
}
}
### long_reign_bonus_mult ###
DI_add_modifier_long_reign_bonus_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = long_reign_bonus_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = long_reign_bonus_mult
    }
}
}
}

DI_remove_modifier_long_reign_bonus_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = long_reign_bonus_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = long_reign_bonus_mult
    }
}
}
}

DI_add_modifier_long_reign_bonus_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = long_reign_bonus_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = long_reign_bonus_mult_neg
    }
}
}
}

DI_remove_modifier_long_reign_bonus_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = long_reign_bonus_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = long_reign_bonus_mult_neg
    }
}
}
}
### diplomatic_range_mult ###
DI_add_modifier_diplomatic_range_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomatic_range_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomatic_range_mult
    }
}
}
}

DI_remove_modifier_diplomatic_range_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomatic_range_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomatic_range_mult
    }
}
}
}

DI_add_modifier_diplomatic_range_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomatic_range_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomatic_range_mult_neg
    }
}
}
}

DI_remove_modifier_diplomatic_range_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomatic_range_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomatic_range_mult_neg
    }
}
}
}
### inbreeding_chance ###
DI_add_modifier_inbreeding_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = inbreeding_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = inbreeding_chance
    }
}
}
}

DI_remove_modifier_inbreeding_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = inbreeding_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = inbreeding_chance
    }
}
}
}

DI_add_modifier_inbreeding_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = inbreeding_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = inbreeding_chance_neg
    }
}
}
}

DI_remove_modifier_inbreeding_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = inbreeding_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = inbreeding_chance_neg
    }
}
}
}
### positive_inactive_inheritance_chance ###
DI_add_modifier_positive_inactive_inheritance_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = positive_inactive_inheritance_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = positive_inactive_inheritance_chance
    }
}
}
}

DI_remove_modifier_positive_inactive_inheritance_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = positive_inactive_inheritance_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = positive_inactive_inheritance_chance
    }
}
}
}

DI_add_modifier_positive_inactive_inheritance_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = positive_inactive_inheritance_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = positive_inactive_inheritance_chance_neg
    }
}
}
}

DI_remove_modifier_positive_inactive_inheritance_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = positive_inactive_inheritance_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = positive_inactive_inheritance_chance_neg
    }
}
}
}
### negative_inactive_inheritance_chance ###
DI_add_modifier_negative_inactive_inheritance_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = negative_inactive_inheritance_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = negative_inactive_inheritance_chance
    }
}
}
}

DI_remove_modifier_negative_inactive_inheritance_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = negative_inactive_inheritance_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = negative_inactive_inheritance_chance
    }
}
}
}

DI_add_modifier_negative_inactive_inheritance_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = negative_inactive_inheritance_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = negative_inactive_inheritance_chance_neg
    }
}
}
}

DI_remove_modifier_negative_inactive_inheritance_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = negative_inactive_inheritance_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = negative_inactive_inheritance_chance_neg
    }
}
}
}
### positive_random_genetic_chance ###
DI_add_modifier_positive_random_genetic_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = positive_random_genetic_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = positive_random_genetic_chance
    }
}
}
}

DI_remove_modifier_positive_random_genetic_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = positive_random_genetic_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = positive_random_genetic_chance
    }
}
}
}

DI_add_modifier_positive_random_genetic_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = positive_random_genetic_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = positive_random_genetic_chance_neg
    }
}
}
}

DI_remove_modifier_positive_random_genetic_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = positive_random_genetic_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = positive_random_genetic_chance_neg
    }
}
}
}
### negative_random_genetic_chance ###
DI_add_modifier_negative_random_genetic_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = negative_random_genetic_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = negative_random_genetic_chance
    }
}
}
}

DI_remove_modifier_negative_random_genetic_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = negative_random_genetic_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = negative_random_genetic_chance
    }
}
}
}

DI_add_modifier_negative_random_genetic_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = negative_random_genetic_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = negative_random_genetic_chance_neg
    }
}
}
}

DI_remove_modifier_negative_random_genetic_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = negative_random_genetic_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = negative_random_genetic_chance_neg
    }
}
}
}
### genetic_trait_strengthen_chance ###
DI_add_modifier_genetic_trait_strengthen_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = genetic_trait_strengthen_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = genetic_trait_strengthen_chance
    }
}
}
}

DI_remove_modifier_genetic_trait_strengthen_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = genetic_trait_strengthen_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = genetic_trait_strengthen_chance
    }
}
}
}

DI_add_modifier_genetic_trait_strengthen_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = genetic_trait_strengthen_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = genetic_trait_strengthen_chance_neg
    }
}
}
}

DI_remove_modifier_genetic_trait_strengthen_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = genetic_trait_strengthen_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = genetic_trait_strengthen_chance_neg
    }
}
}
}
### years_of_fertility ###
DI_add_modifier_years_of_fertility = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = years_of_fertility
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = years_of_fertility
    }
}
}
}

DI_remove_modifier_years_of_fertility = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = years_of_fertility
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = years_of_fertility
    }
}
}
}

DI_add_modifier_years_of_fertility_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = years_of_fertility_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = years_of_fertility_neg
    }
}
}
}

DI_remove_modifier_years_of_fertility_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = years_of_fertility_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = years_of_fertility_neg
    }
}
}
}
### knight_limit ###
DI_add_modifier_knight_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = knight_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = knight_limit
    }
}
}
}

DI_remove_modifier_knight_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = knight_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = knight_limit
    }
}
}
}

DI_add_modifier_knight_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = knight_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = knight_limit_neg
    }
}
}
}

DI_remove_modifier_knight_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = knight_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = knight_limit_neg
    }
}
}
}
### knight_effectiveness_mult ###
DI_add_modifier_knight_effectiveness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = knight_effectiveness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = knight_effectiveness_mult
    }
}
}
}

DI_remove_modifier_knight_effectiveness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = knight_effectiveness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = knight_effectiveness_mult
    }
}
}
}

DI_add_modifier_knight_effectiveness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = knight_effectiveness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = knight_effectiveness_mult_neg
    }
}
}
}

DI_remove_modifier_knight_effectiveness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = knight_effectiveness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = knight_effectiveness_mult_neg
    }
}
}
}
### title_creation_cost ###
DI_add_modifier_title_creation_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = title_creation_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = title_creation_cost
    }
}
}
}

DI_remove_modifier_title_creation_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = title_creation_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = title_creation_cost
    }
}
}
}

DI_add_modifier_title_creation_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = title_creation_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = title_creation_cost_neg
    }
}
}
}

DI_remove_modifier_title_creation_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = title_creation_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = title_creation_cost_neg
    }
}
}
}

DI_add_modifier_title_creation_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = title_creation_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = title_creation_cost_mult
    }
}
}
}

DI_remove_modifier_title_creation_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = title_creation_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = title_creation_cost_mult
    }
}
}
}

DI_add_modifier_title_creation_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = title_creation_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = title_creation_cost_mult_neg
    }
}
}
}

DI_remove_modifier_title_creation_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = title_creation_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = title_creation_cost_mult_neg
    }
}
}
}
### monthly_lifestyle_xp_gain_mult ###
DI_add_modifier_monthly_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_lifestyle_xp_gain_mult
    }
}
}
}

DI_remove_modifier_monthly_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_lifestyle_xp_gain_mult
    }
}
}
}

DI_add_modifier_monthly_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_lifestyle_xp_gain_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_lifestyle_xp_gain_mult_neg
    }
}
}
}
### mercenary_hire_cost ###
DI_add_modifier_mercenary_hire_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = mercenary_hire_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = mercenary_hire_cost
    }
}
}
}

DI_remove_modifier_mercenary_hire_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = mercenary_hire_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = mercenary_hire_cost
    }
}
}
}

DI_add_modifier_mercenary_hire_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = mercenary_hire_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = mercenary_hire_cost_neg
    }
}
}
}

DI_remove_modifier_mercenary_hire_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = mercenary_hire_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = mercenary_hire_cost_neg
    }
}
}
}

DI_add_modifier_mercenary_hire_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = mercenary_hire_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = mercenary_hire_cost_mult
    }
}
}
}

DI_remove_modifier_mercenary_hire_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = mercenary_hire_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = mercenary_hire_cost_mult
    }
}
}
}

DI_add_modifier_mercenary_hire_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = mercenary_hire_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = mercenary_hire_cost_mult_neg
    }
}
}
}

DI_remove_modifier_mercenary_hire_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = mercenary_hire_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = mercenary_hire_cost_mult_neg
    }
}
}
}
### same_culture_mercenary_hire_cost ###
DI_add_modifier_same_culture_mercenary_hire_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_mercenary_hire_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_mercenary_hire_cost
    }
}
}
}

DI_remove_modifier_same_culture_mercenary_hire_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_mercenary_hire_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_mercenary_hire_cost
    }
}
}
}

DI_add_modifier_same_culture_mercenary_hire_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_mercenary_hire_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_mercenary_hire_cost_neg
    }
}
}
}

DI_remove_modifier_same_culture_mercenary_hire_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_mercenary_hire_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_mercenary_hire_cost_neg
    }
}
}
}

DI_add_modifier_same_culture_mercenary_hire_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_mercenary_hire_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_mercenary_hire_cost_mult
    }
}
}
}

DI_remove_modifier_same_culture_mercenary_hire_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_mercenary_hire_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_mercenary_hire_cost_mult
    }
}
}
}

DI_add_modifier_same_culture_mercenary_hire_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_mercenary_hire_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_mercenary_hire_cost_mult_neg
    }
}
}
}

DI_remove_modifier_same_culture_mercenary_hire_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_mercenary_hire_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_mercenary_hire_cost_mult_neg
    }
}
}
}
### holy_order_hire_cost ###
DI_add_modifier_holy_order_hire_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holy_order_hire_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holy_order_hire_cost
    }
}
}
}

DI_remove_modifier_holy_order_hire_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holy_order_hire_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holy_order_hire_cost
    }
}
}
}

DI_add_modifier_holy_order_hire_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holy_order_hire_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holy_order_hire_cost_neg
    }
}
}
}

DI_remove_modifier_holy_order_hire_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holy_order_hire_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holy_order_hire_cost_neg
    }
}
}
}

DI_add_modifier_holy_order_hire_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holy_order_hire_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holy_order_hire_cost_mult
    }
}
}
}

DI_remove_modifier_holy_order_hire_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holy_order_hire_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holy_order_hire_cost_mult
    }
}
}
}

DI_add_modifier_holy_order_hire_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holy_order_hire_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holy_order_hire_cost_mult_neg
    }
}
}
}

DI_remove_modifier_holy_order_hire_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holy_order_hire_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holy_order_hire_cost_mult_neg
    }
}
}
}
### same_culture_holy_order_hire_cost ###
DI_add_modifier_same_culture_holy_order_hire_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_holy_order_hire_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_holy_order_hire_cost
    }
}
}
}

DI_remove_modifier_same_culture_holy_order_hire_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_holy_order_hire_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_holy_order_hire_cost
    }
}
}
}

DI_add_modifier_same_culture_holy_order_hire_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_holy_order_hire_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_holy_order_hire_cost_neg
    }
}
}
}

DI_remove_modifier_same_culture_holy_order_hire_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_holy_order_hire_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_holy_order_hire_cost_neg
    }
}
}
}

DI_add_modifier_same_culture_holy_order_hire_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_holy_order_hire_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_holy_order_hire_cost_mult
    }
}
}
}

DI_remove_modifier_same_culture_holy_order_hire_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_holy_order_hire_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_holy_order_hire_cost_mult
    }
}
}
}

DI_add_modifier_same_culture_holy_order_hire_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_holy_order_hire_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_holy_order_hire_cost_mult_neg
    }
}
}
}

DI_remove_modifier_same_culture_holy_order_hire_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_holy_order_hire_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_holy_order_hire_cost_mult_neg
    }
}
}
}
### opinion_of_female_rulers ###
DI_add_modifier_opinion_of_female_rulers = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_female_rulers
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_female_rulers
    }
}
}
}

DI_remove_modifier_opinion_of_female_rulers = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_female_rulers
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_female_rulers
    }
}
}
}

DI_add_modifier_opinion_of_female_rulers_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_female_rulers_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_female_rulers_neg
    }
}
}
}

DI_remove_modifier_opinion_of_female_rulers_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_female_rulers_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_female_rulers_neg
    }
}
}
}
### opinion_of_male_rulers ###
DI_add_modifier_opinion_of_male_rulers = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_male_rulers
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_male_rulers
    }
}
}
}

DI_remove_modifier_opinion_of_male_rulers = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_male_rulers
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_male_rulers
    }
}
}
}

DI_add_modifier_opinion_of_male_rulers_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_male_rulers_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_male_rulers_neg
    }
}
}
}

DI_remove_modifier_opinion_of_male_rulers_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_male_rulers_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_male_rulers_neg
    }
}
}
}
### opinion_of_same_culture ###
DI_add_modifier_opinion_of_same_culture = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_same_culture
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_same_culture
    }
}
}
}

DI_remove_modifier_opinion_of_same_culture = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_same_culture
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_same_culture
    }
}
}
}

DI_add_modifier_opinion_of_same_culture_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_same_culture_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_same_culture_neg
    }
}
}
}

DI_remove_modifier_opinion_of_same_culture_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_same_culture_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_same_culture_neg
    }
}
}
}
### opinion_of_different_culture ###
DI_add_modifier_opinion_of_different_culture = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_different_culture
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_different_culture
    }
}
}
}

DI_remove_modifier_opinion_of_different_culture = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_different_culture
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_different_culture
    }
}
}
}

DI_add_modifier_opinion_of_different_culture_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_different_culture_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_different_culture_neg
    }
}
}
}

DI_remove_modifier_opinion_of_different_culture_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_different_culture_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_different_culture_neg
    }
}
}
}
### opinion_of_same_faith ###
DI_add_modifier_opinion_of_same_faith = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_same_faith
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_same_faith
    }
}
}
}

DI_remove_modifier_opinion_of_same_faith = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_same_faith
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_same_faith
    }
}
}
}

DI_add_modifier_opinion_of_same_faith_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_same_faith_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_same_faith_neg
    }
}
}
}

DI_remove_modifier_opinion_of_same_faith_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_same_faith_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_same_faith_neg
    }
}
}
}
### opinion_of_different_faith ###
DI_add_modifier_opinion_of_different_faith = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_different_faith
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_different_faith
    }
}
}
}

DI_remove_modifier_opinion_of_different_faith = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_different_faith
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_different_faith
    }
}
}
}

DI_add_modifier_opinion_of_different_faith_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_different_faith_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_different_faith_neg
    }
}
}
}

DI_remove_modifier_opinion_of_different_faith_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_different_faith_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_different_faith_neg
    }
}
}
}
### opinion_of_liege ###
DI_add_modifier_opinion_of_liege = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_liege
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_liege
    }
}
}
}

DI_remove_modifier_opinion_of_liege = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_liege
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_liege
    }
}
}
}

DI_add_modifier_opinion_of_liege_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_liege_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_liege_neg
    }
}
}
}

DI_remove_modifier_opinion_of_liege_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_liege_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_liege_neg
    }
}
}
}
### opinion_of_vassal ###
DI_add_modifier_opinion_of_vassal = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_vassal
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_vassal
    }
}
}
}

DI_remove_modifier_opinion_of_vassal = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_vassal
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_vassal
    }
}
}
}

DI_add_modifier_opinion_of_vassal_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_vassal_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_vassal_neg
    }
}
}
}

DI_remove_modifier_opinion_of_vassal_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_vassal_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_vassal_neg
    }
}
}
}
### opinion_of_different_faith_liege ###
DI_add_modifier_opinion_of_different_faith_liege = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_different_faith_liege
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_different_faith_liege
    }
}
}
}

DI_remove_modifier_opinion_of_different_faith_liege = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_different_faith_liege
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_different_faith_liege
    }
}
}
}

DI_add_modifier_opinion_of_different_faith_liege_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = opinion_of_different_faith_liege_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = opinion_of_different_faith_liege_neg
    }
}
}
}

DI_remove_modifier_opinion_of_different_faith_liege_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = opinion_of_different_faith_liege_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = opinion_of_different_faith_liege_neg
    }
}
}
}
### same_culture_opinion ###
DI_add_modifier_same_culture_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_opinion
    }
}
}
}

DI_remove_modifier_same_culture_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_opinion
    }
}
}
}

DI_add_modifier_same_culture_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_culture_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_culture_opinion_neg
    }
}
}
}

DI_remove_modifier_same_culture_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_culture_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_culture_opinion_neg
    }
}
}
}
### different_culture_opinion ###
DI_add_modifier_different_culture_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_culture_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_culture_opinion
    }
}
}
}

DI_remove_modifier_different_culture_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_culture_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_culture_opinion
    }
}
}
}

DI_add_modifier_different_culture_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_culture_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_culture_opinion_neg
    }
}
}
}

DI_remove_modifier_different_culture_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_culture_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_culture_opinion_neg
    }
}
}
}
### same_faith_opinion ###
DI_add_modifier_same_faith_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_faith_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_faith_opinion
    }
}
}
}

DI_remove_modifier_same_faith_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_faith_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_faith_opinion
    }
}
}
}

DI_add_modifier_same_faith_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = same_faith_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = same_faith_opinion_neg
    }
}
}
}

DI_remove_modifier_same_faith_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = same_faith_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = same_faith_opinion_neg
    }
}
}
}
### different_faith_opinion ###
DI_add_modifier_different_faith_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_faith_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_faith_opinion
    }
}
}
}

DI_remove_modifier_different_faith_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_faith_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_faith_opinion
    }
}
}
}

DI_add_modifier_different_faith_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_faith_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_faith_opinion_neg
    }
}
}
}

DI_remove_modifier_different_faith_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_faith_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_faith_opinion_neg
    }
}
}
}
### direct_vassal_opinion ###
DI_add_modifier_direct_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = direct_vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = direct_vassal_opinion
    }
}
}
}

DI_remove_modifier_direct_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = direct_vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = direct_vassal_opinion
    }
}
}
}

DI_add_modifier_direct_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = direct_vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = direct_vassal_opinion_neg
    }
}
}
}

DI_remove_modifier_direct_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = direct_vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = direct_vassal_opinion_neg
    }
}
}
}
### fellow_vassal_opinion ###
DI_add_modifier_fellow_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = fellow_vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = fellow_vassal_opinion
    }
}
}
}

DI_remove_modifier_fellow_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = fellow_vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = fellow_vassal_opinion
    }
}
}
}

DI_add_modifier_fellow_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = fellow_vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = fellow_vassal_opinion_neg
    }
}
}
}

DI_remove_modifier_fellow_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = fellow_vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = fellow_vassal_opinion_neg
    }
}
}
}
### independent_ruler_opinion ###
DI_add_modifier_independent_ruler_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = independent_ruler_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = independent_ruler_opinion
    }
}
}
}

DI_remove_modifier_independent_ruler_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = independent_ruler_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = independent_ruler_opinion
    }
}
}
}

DI_add_modifier_independent_ruler_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = independent_ruler_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = independent_ruler_opinion_neg
    }
}
}
}

DI_remove_modifier_independent_ruler_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = independent_ruler_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = independent_ruler_opinion_neg
    }
}
}
}
### general_opinion ###
DI_add_modifier_general_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = general_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = general_opinion
    }
}
}
}

DI_remove_modifier_general_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = general_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = general_opinion
    }
}
}
}

DI_add_modifier_general_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = general_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = general_opinion_neg
    }
}
}
}

DI_remove_modifier_general_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = general_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = general_opinion_neg
    }
}
}
}
### attraction_opinion ###
DI_add_modifier_attraction_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = attraction_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = attraction_opinion
    }
}
}
}

DI_remove_modifier_attraction_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = attraction_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = attraction_opinion
    }
}
}
}

DI_add_modifier_attraction_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = attraction_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = attraction_opinion_neg
    }
}
}
}

DI_remove_modifier_attraction_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = attraction_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = attraction_opinion_neg
    }
}
}
}
### religious_vassal_opinion ###
DI_add_modifier_religious_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = religious_vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = religious_vassal_opinion
    }
}
}
}

DI_remove_modifier_religious_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = religious_vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = religious_vassal_opinion
    }
}
}
}

DI_add_modifier_religious_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = religious_vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = religious_vassal_opinion_neg
    }
}
}
}

DI_remove_modifier_religious_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = religious_vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = religious_vassal_opinion_neg
    }
}
}
}
### religious_head_opinion ###
DI_add_modifier_religious_head_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = religious_head_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = religious_head_opinion
    }
}
}
}

DI_remove_modifier_religious_head_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = religious_head_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = religious_head_opinion
    }
}
}
}

DI_add_modifier_religious_head_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = religious_head_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = religious_head_opinion_neg
    }
}
}
}

DI_remove_modifier_religious_head_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = religious_head_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = religious_head_opinion_neg
    }
}
}
}
### spouse_opinion ###
DI_add_modifier_spouse_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = spouse_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = spouse_opinion
    }
}
}
}

DI_remove_modifier_spouse_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = spouse_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = spouse_opinion
    }
}
}
}

DI_add_modifier_spouse_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = spouse_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = spouse_opinion_neg
    }
}
}
}

DI_remove_modifier_spouse_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = spouse_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = spouse_opinion_neg
    }
}
}
}
### twin_opinion ###
DI_add_modifier_twin_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = twin_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = twin_opinion
    }
}
}
}

DI_remove_modifier_twin_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = twin_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = twin_opinion
    }
}
}
}

DI_add_modifier_twin_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = twin_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = twin_opinion_neg
    }
}
}
}

DI_remove_modifier_twin_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = twin_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = twin_opinion_neg
    }
}
}
}
### close_relative_opinion ###
DI_add_modifier_close_relative_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = close_relative_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = close_relative_opinion
    }
}
}
}

DI_remove_modifier_close_relative_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = close_relative_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = close_relative_opinion
    }
}
}
}

DI_add_modifier_close_relative_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = close_relative_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = close_relative_opinion_neg
    }
}
}
}

DI_remove_modifier_close_relative_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = close_relative_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = close_relative_opinion_neg
    }
}
}
}
### dynasty_house_opinion ###
DI_add_modifier_dynasty_house_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dynasty_house_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dynasty_house_opinion
    }
}
}
}

DI_remove_modifier_dynasty_house_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dynasty_house_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dynasty_house_opinion
    }
}
}
}

DI_add_modifier_dynasty_house_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dynasty_house_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dynasty_house_opinion_neg
    }
}
}
}

DI_remove_modifier_dynasty_house_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dynasty_house_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dynasty_house_opinion_neg
    }
}
}
}
### dynasty_opinion ###
DI_add_modifier_dynasty_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dynasty_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dynasty_opinion
    }
}
}
}

DI_remove_modifier_dynasty_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dynasty_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dynasty_opinion
    }
}
}
}

DI_add_modifier_dynasty_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = dynasty_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = dynasty_opinion_neg
    }
}
}
}

DI_remove_modifier_dynasty_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = dynasty_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = dynasty_opinion_neg
    }
}
}
}
### liege_opinion ###
DI_add_modifier_liege_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = liege_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = liege_opinion
    }
}
}
}

DI_remove_modifier_liege_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = liege_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = liege_opinion
    }
}
}
}

DI_add_modifier_liege_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = liege_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = liege_opinion_neg
    }
}
}
}

DI_remove_modifier_liege_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = liege_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = liege_opinion_neg
    }
}
}
}
### different_faith_liege_opinion ###
DI_add_modifier_different_faith_liege_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_faith_liege_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_faith_liege_opinion
    }
}
}
}

DI_remove_modifier_different_faith_liege_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_faith_liege_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_faith_liege_opinion
    }
}
}
}

DI_add_modifier_different_faith_liege_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_faith_liege_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_faith_liege_opinion_neg
    }
}
}
}

DI_remove_modifier_different_faith_liege_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_faith_liege_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_faith_liege_opinion_neg
    }
}
}
}
### vassal_opinion ###
DI_add_modifier_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_opinion
    }
}
}
}

DI_remove_modifier_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_opinion
    }
}
}
}

DI_add_modifier_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_opinion_neg
    }
}
}
}

DI_remove_modifier_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_opinion_neg
    }
}
}
}
### clergy_opinion ###
DI_add_modifier_clergy_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = clergy_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = clergy_opinion
    }
}
}
}

DI_remove_modifier_clergy_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = clergy_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = clergy_opinion
    }
}
}
}

DI_add_modifier_clergy_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = clergy_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = clergy_opinion_neg
    }
}
}
}

DI_remove_modifier_clergy_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = clergy_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = clergy_opinion_neg
    }
}
}
}
### councillor_opinion ###
DI_add_modifier_councillor_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = councillor_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = councillor_opinion
    }
}
}
}

DI_remove_modifier_councillor_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = councillor_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = councillor_opinion
    }
}
}
}

DI_add_modifier_councillor_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = councillor_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = councillor_opinion_neg
    }
}
}
}

DI_remove_modifier_councillor_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = councillor_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = councillor_opinion_neg
    }
}
}
}
### realm_priest_opinion ###
DI_add_modifier_realm_priest_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = realm_priest_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = realm_priest_opinion
    }
}
}
}

DI_remove_modifier_realm_priest_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = realm_priest_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = realm_priest_opinion
    }
}
}
}

DI_add_modifier_realm_priest_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = realm_priest_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = realm_priest_opinion_neg
    }
}
}
}

DI_remove_modifier_realm_priest_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = realm_priest_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = realm_priest_opinion_neg
    }
}
}
}
### powerful_vassal_opinion ###
DI_add_modifier_powerful_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = powerful_vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = powerful_vassal_opinion
    }
}
}
}

DI_remove_modifier_powerful_vassal_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = powerful_vassal_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = powerful_vassal_opinion
    }
}
}
}

DI_add_modifier_powerful_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = powerful_vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = powerful_vassal_opinion_neg
    }
}
}
}

DI_remove_modifier_powerful_vassal_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = powerful_vassal_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = powerful_vassal_opinion_neg
    }
}
}
}
### courtier_opinion ###
DI_add_modifier_courtier_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = courtier_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = courtier_opinion
    }
}
}
}

DI_remove_modifier_courtier_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = courtier_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = courtier_opinion
    }
}
}
}

DI_add_modifier_courtier_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = courtier_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = courtier_opinion_neg
    }
}
}
}

DI_remove_modifier_courtier_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = courtier_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = courtier_opinion_neg
    }
}
}
}
### guest_opinion ###
DI_add_modifier_guest_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = guest_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = guest_opinion
    }
}
}
}

DI_remove_modifier_guest_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = guest_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = guest_opinion
    }
}
}
}

DI_add_modifier_guest_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = guest_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = guest_opinion_neg
    }
}
}
}

DI_remove_modifier_guest_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = guest_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = guest_opinion_neg
    }
}
}
}
### courtier_and_guest_opinion ###
DI_add_modifier_courtier_and_guest_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = courtier_and_guest_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = courtier_and_guest_opinion
    }
}
}
}

DI_remove_modifier_courtier_and_guest_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = courtier_and_guest_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = courtier_and_guest_opinion
    }
}
}
}

DI_add_modifier_courtier_and_guest_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = courtier_and_guest_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = courtier_and_guest_opinion_neg
    }
}
}
}

DI_remove_modifier_courtier_and_guest_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = courtier_and_guest_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = courtier_and_guest_opinion_neg
    }
}
}
}
### prisoner_opinion ###
DI_add_modifier_prisoner_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prisoner_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prisoner_opinion
    }
}
}
}

DI_remove_modifier_prisoner_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prisoner_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prisoner_opinion
    }
}
}
}

DI_add_modifier_prisoner_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prisoner_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prisoner_opinion_neg
    }
}
}
}

DI_remove_modifier_prisoner_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prisoner_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prisoner_opinion_neg
    }
}
}
}
### player_heir_opinion ###
DI_add_modifier_player_heir_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = player_heir_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = player_heir_opinion
    }
}
}
}

DI_remove_modifier_player_heir_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = player_heir_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = player_heir_opinion
    }
}
}
}

DI_add_modifier_player_heir_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = player_heir_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = player_heir_opinion_neg
    }
}
}
}

DI_remove_modifier_player_heir_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = player_heir_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = player_heir_opinion_neg
    }
}
}
}
### child_opinion ###
DI_add_modifier_child_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = child_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = child_opinion
    }
}
}
}

DI_remove_modifier_child_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = child_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = child_opinion
    }
}
}
}

DI_add_modifier_child_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = child_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = child_opinion_neg
    }
}
}
}

DI_remove_modifier_child_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = child_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = child_opinion_neg
    }
}
}
}
### child_except_player_heir_opinion ###
DI_add_modifier_child_except_player_heir_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = child_except_player_heir_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = child_except_player_heir_opinion
    }
}
}
}

DI_remove_modifier_child_except_player_heir_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = child_except_player_heir_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = child_except_player_heir_opinion
    }
}
}
}

DI_add_modifier_child_except_player_heir_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = child_except_player_heir_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = child_except_player_heir_opinion_neg
    }
}
}
}

DI_remove_modifier_child_except_player_heir_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = child_except_player_heir_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = child_except_player_heir_opinion_neg
    }
}
}
}
### eligible_child_opinion ###
DI_add_modifier_eligible_child_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = eligible_child_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = eligible_child_opinion
    }
}
}
}

DI_remove_modifier_eligible_child_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = eligible_child_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = eligible_child_opinion
    }
}
}
}

DI_add_modifier_eligible_child_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = eligible_child_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = eligible_child_opinion_neg
    }
}
}
}

DI_remove_modifier_eligible_child_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = eligible_child_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = eligible_child_opinion_neg
    }
}
}
}
### eligible_child_except_player_heir_opinion ###
DI_add_modifier_eligible_child_except_player_heir_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = eligible_child_except_player_heir_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = eligible_child_except_player_heir_opinion
    }
}
}
}

DI_remove_modifier_eligible_child_except_player_heir_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = eligible_child_except_player_heir_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = eligible_child_except_player_heir_opinion
    }
}
}
}

DI_add_modifier_eligible_child_except_player_heir_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = eligible_child_except_player_heir_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = eligible_child_except_player_heir_opinion_neg
    }
}
}
}

DI_remove_modifier_eligible_child_except_player_heir_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = eligible_child_except_player_heir_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = eligible_child_except_player_heir_opinion_neg
    }
}
}
}
### pursue_efficiency ###
DI_add_modifier_pursue_efficiency = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pursue_efficiency
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pursue_efficiency
    }
}
}
}

DI_remove_modifier_pursue_efficiency = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pursue_efficiency
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pursue_efficiency
    }
}
}
}

DI_add_modifier_pursue_efficiency_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pursue_efficiency_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pursue_efficiency_neg
    }
}
}
}

DI_remove_modifier_pursue_efficiency_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pursue_efficiency_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pursue_efficiency_neg
    }
}
}
}
### counter_efficiency ###
DI_add_modifier_counter_efficiency = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = counter_efficiency
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = counter_efficiency
    }
}
}
}

DI_remove_modifier_counter_efficiency = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = counter_efficiency
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = counter_efficiency
    }
}
}
}

DI_add_modifier_counter_efficiency_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = counter_efficiency_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = counter_efficiency_neg
    }
}
}
}

DI_remove_modifier_counter_efficiency_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = counter_efficiency_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = counter_efficiency_neg
    }
}
}
}
### min_combat_roll ###
DI_add_modifier_min_combat_roll = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = min_combat_roll
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = min_combat_roll
    }
}
}
}

DI_remove_modifier_min_combat_roll = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = min_combat_roll
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = min_combat_roll
    }
}
}
}

DI_add_modifier_min_combat_roll_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = min_combat_roll_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = min_combat_roll_neg
    }
}
}
}

DI_remove_modifier_min_combat_roll_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = min_combat_roll_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = min_combat_roll_neg
    }
}
}
}
### max_combat_roll ###
DI_add_modifier_max_combat_roll = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = max_combat_roll
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = max_combat_roll
    }
}
}
}

DI_remove_modifier_max_combat_roll = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = max_combat_roll
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = max_combat_roll
    }
}
}
}

DI_add_modifier_max_combat_roll_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = max_combat_roll_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = max_combat_roll_neg
    }
}
}
}

DI_remove_modifier_max_combat_roll_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = max_combat_roll_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = max_combat_roll_neg
    }
}
}
}
### men_at_arms_limit ###
DI_add_modifier_men_at_arms_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = men_at_arms_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = men_at_arms_limit
    }
}
}
}

DI_remove_modifier_men_at_arms_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = men_at_arms_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = men_at_arms_limit
    }
}
}
}

DI_add_modifier_men_at_arms_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = men_at_arms_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = men_at_arms_limit_neg
    }
}
}
}

DI_remove_modifier_men_at_arms_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = men_at_arms_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = men_at_arms_limit_neg
    }
}
}
}
### men_at_arms_cap ###
DI_add_modifier_men_at_arms_cap = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = men_at_arms_cap
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = men_at_arms_cap
    }
}
}
}

DI_remove_modifier_men_at_arms_cap = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = men_at_arms_cap
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = men_at_arms_cap
    }
}
}
}

DI_add_modifier_men_at_arms_cap_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = men_at_arms_cap_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = men_at_arms_cap_neg
    }
}
}
}

DI_remove_modifier_men_at_arms_cap_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = men_at_arms_cap_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = men_at_arms_cap_neg
    }
}
}
}

### embarkation_cost_mult ###
DI_add_modifier_embarkation_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = embarkation_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = embarkation_cost_mult
    }
}
}
}

DI_remove_modifier_embarkation_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = embarkation_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = embarkation_cost_mult
    }
}
}
}

DI_add_modifier_embarkation_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = embarkation_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = embarkation_cost_mult_neg
    }
}
}
}

DI_remove_modifier_embarkation_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = embarkation_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = embarkation_cost_mult_neg
    }
}
}
}
### naval_movement_speed_mult ###
DI_add_modifier_naval_movement_speed_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = naval_movement_speed_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = naval_movement_speed_mult
    }
}
}
}

DI_remove_modifier_naval_movement_speed_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = naval_movement_speed_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = naval_movement_speed_mult
    }
}
}
}

DI_add_modifier_naval_movement_speed_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = naval_movement_speed_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = naval_movement_speed_mult_neg
    }
}
}
}

DI_remove_modifier_naval_movement_speed_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = naval_movement_speed_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = naval_movement_speed_mult_neg
    }
}
}
}
### siege_phase_time ###
DI_add_modifier_siege_phase_time = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_phase_time
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_phase_time
    }
}
}
}

DI_remove_modifier_siege_phase_time = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_phase_time
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_phase_time
    }
}
}
}

DI_add_modifier_siege_phase_time_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_phase_time_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_phase_time_neg
    }
}
}
}

DI_remove_modifier_siege_phase_time_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_phase_time_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_phase_time_neg
    }
}
}
}

### no_disembark_penalty ###
DI_add_modifier_no_disembark_penalty = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = no_disembark_penalty
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = no_disembark_penalty
    }
}
}
}

DI_remove_modifier_no_disembark_penalty = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = no_disembark_penalty
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = no_disembark_penalty
    }
}
}
}

### no_water_crossing_penalty ###
DI_add_modifier_no_water_crossing_penalty = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = no_water_crossing_penalty
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = no_water_crossing_penalty
    }
}
}
}

DI_remove_modifier_no_water_crossing_penalty = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = no_water_crossing_penalty
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = no_water_crossing_penalty
    }
}
}
}
### siege_morale_loss ###
DI_add_modifier_siege_morale_loss = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_morale_loss
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_morale_loss
    }
}
}
}

DI_remove_modifier_siege_morale_loss = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_morale_loss
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_morale_loss
    }
}
}
}

DI_add_modifier_siege_morale_loss_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_morale_loss_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_morale_loss_neg
    }
}
}
}

DI_remove_modifier_siege_morale_loss_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_morale_loss_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_morale_loss_neg
    }
}
}
}
### revolting_siege_morale_loss ###
DI_add_modifier_revolting_siege_morale_loss = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = revolting_siege_morale_loss
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = revolting_siege_morale_loss
    }
}
}
}

DI_remove_modifier_revolting_siege_morale_loss = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = revolting_siege_morale_loss
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = revolting_siege_morale_loss
    }
}
}
}

DI_add_modifier_revolting_siege_morale_loss_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = revolting_siege_morale_loss_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = revolting_siege_morale_loss_neg
    }
}
}
}

DI_remove_modifier_revolting_siege_morale_loss_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = revolting_siege_morale_loss_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = revolting_siege_morale_loss_neg
    }
}
}
}

DI_add_modifier_revolting_siege_morale_loss_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = revolting_siege_morale_loss_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = revolting_siege_morale_loss_mult
    }
}
}
}

DI_remove_modifier_revolting_siege_morale_loss_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = revolting_siege_morale_loss_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = revolting_siege_morale_loss_mult
    }
}
}
}

DI_add_modifier_revolting_siege_morale_loss_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = revolting_siege_morale_loss_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = revolting_siege_morale_loss_mult_neg
    }
}
}
}

DI_remove_modifier_revolting_siege_morale_loss_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = revolting_siege_morale_loss_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = revolting_siege_morale_loss_mult_neg
    }
}
}
}
### vassal_tax_contribution ###
DI_add_modifier_vassal_tax_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_tax_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_tax_contribution
    }
}
}
}

DI_remove_modifier_vassal_tax_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_tax_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_tax_contribution
    }
}
}
}

DI_add_modifier_vassal_tax_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_tax_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_tax_contribution_neg
    }
}
}
}

DI_remove_modifier_vassal_tax_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_tax_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_tax_contribution_neg
    }
}
}
}

DI_add_modifier_vassal_tax_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_tax_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_tax_contribution_mult
    }
}
}
}

DI_remove_modifier_vassal_tax_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_tax_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_tax_contribution_mult
    }
}
}
}

DI_add_modifier_vassal_tax_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_tax_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_tax_contribution_mult_neg
    }
}
}
}

DI_remove_modifier_vassal_tax_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_tax_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_tax_contribution_mult_neg
    }
}
}
}
### intimidated_vassal_tax_contribution ###
DI_add_modifier_intimidated_vassal_tax_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intimidated_vassal_tax_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intimidated_vassal_tax_contribution
    }
}
}
}

DI_remove_modifier_intimidated_vassal_tax_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intimidated_vassal_tax_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intimidated_vassal_tax_contribution
    }
}
}
}

DI_add_modifier_intimidated_vassal_tax_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intimidated_vassal_tax_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intimidated_vassal_tax_contribution_neg
    }
}
}
}

DI_remove_modifier_intimidated_vassal_tax_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intimidated_vassal_tax_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intimidated_vassal_tax_contribution_neg
    }
}
}
}

DI_add_modifier_intimidated_vassal_tax_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intimidated_vassal_tax_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intimidated_vassal_tax_contribution_mult
    }
}
}
}

DI_remove_modifier_intimidated_vassal_tax_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intimidated_vassal_tax_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intimidated_vassal_tax_contribution_mult
    }
}
}
}

DI_add_modifier_intimidated_vassal_tax_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intimidated_vassal_tax_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intimidated_vassal_tax_contribution_mult_neg
    }
}
}
}

DI_remove_modifier_intimidated_vassal_tax_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intimidated_vassal_tax_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intimidated_vassal_tax_contribution_mult_neg
    }
}
}
}
### cowed_vassal_tax_contribution ###
DI_add_modifier_cowed_vassal_tax_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cowed_vassal_tax_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cowed_vassal_tax_contribution
    }
}
}
}

DI_remove_modifier_cowed_vassal_tax_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cowed_vassal_tax_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cowed_vassal_tax_contribution
    }
}
}
}

DI_add_modifier_cowed_vassal_tax_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cowed_vassal_tax_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cowed_vassal_tax_contribution_neg
    }
}
}
}

DI_remove_modifier_cowed_vassal_tax_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cowed_vassal_tax_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cowed_vassal_tax_contribution_neg
    }
}
}
}

DI_add_modifier_cowed_vassal_tax_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cowed_vassal_tax_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cowed_vassal_tax_contribution_mult
    }
}
}
}

DI_remove_modifier_cowed_vassal_tax_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cowed_vassal_tax_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cowed_vassal_tax_contribution_mult
    }
}
}
}

DI_add_modifier_cowed_vassal_tax_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cowed_vassal_tax_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cowed_vassal_tax_contribution_mult_neg
    }
}
}
}

DI_remove_modifier_cowed_vassal_tax_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cowed_vassal_tax_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cowed_vassal_tax_contribution_mult_neg
    }
}
}
}
### vassal_levy_contribution ###
DI_add_modifier_vassal_levy_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_levy_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_levy_contribution
    }
}
}
}

DI_remove_modifier_vassal_levy_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_levy_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_levy_contribution
    }
}
}
}

DI_add_modifier_vassal_levy_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_levy_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_levy_contribution_neg
    }
}
}
}

DI_remove_modifier_vassal_levy_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_levy_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_levy_contribution_neg
    }
}
}
}

DI_add_modifier_vassal_levy_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_levy_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_levy_contribution_mult
    }
}
}
}

DI_remove_modifier_vassal_levy_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_levy_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_levy_contribution_mult
    }
}
}
}

DI_add_modifier_vassal_levy_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = vassal_levy_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = vassal_levy_contribution_mult_neg
    }
}
}
}

DI_remove_modifier_vassal_levy_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = vassal_levy_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = vassal_levy_contribution_mult_neg
    }
}
}
}
### intimidated_vassal_levy_contribution ###
DI_add_modifier_intimidated_vassal_levy_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intimidated_vassal_levy_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intimidated_vassal_levy_contribution
    }
}
}
}

DI_remove_modifier_intimidated_vassal_levy_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intimidated_vassal_levy_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intimidated_vassal_levy_contribution
    }
}
}
}

DI_add_modifier_intimidated_vassal_levy_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intimidated_vassal_levy_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intimidated_vassal_levy_contribution_neg
    }
}
}
}

DI_remove_modifier_intimidated_vassal_levy_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intimidated_vassal_levy_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intimidated_vassal_levy_contribution_neg
    }
}
}
}

DI_add_modifier_intimidated_vassal_levy_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intimidated_vassal_levy_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intimidated_vassal_levy_contribution_mult
    }
}
}
}

DI_remove_modifier_intimidated_vassal_levy_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intimidated_vassal_levy_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intimidated_vassal_levy_contribution_mult
    }
}
}
}

DI_add_modifier_intimidated_vassal_levy_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intimidated_vassal_levy_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intimidated_vassal_levy_contribution_mult_neg
    }
}
}
}

DI_remove_modifier_intimidated_vassal_levy_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intimidated_vassal_levy_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intimidated_vassal_levy_contribution_mult_neg
    }
}
}
}
### cowed_vassal_levy_contribution ###
DI_add_modifier_cowed_vassal_levy_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cowed_vassal_levy_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cowed_vassal_levy_contribution
    }
}
}
}

DI_remove_modifier_cowed_vassal_levy_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cowed_vassal_levy_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cowed_vassal_levy_contribution
    }
}
}
}

DI_add_modifier_cowed_vassal_levy_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cowed_vassal_levy_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cowed_vassal_levy_contribution_neg
    }
}
}
}

DI_remove_modifier_cowed_vassal_levy_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cowed_vassal_levy_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cowed_vassal_levy_contribution_neg
    }
}
}
}

DI_add_modifier_cowed_vassal_levy_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cowed_vassal_levy_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cowed_vassal_levy_contribution_mult
    }
}
}
}

DI_remove_modifier_cowed_vassal_levy_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cowed_vassal_levy_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cowed_vassal_levy_contribution_mult
    }
}
}
}

DI_add_modifier_cowed_vassal_levy_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cowed_vassal_levy_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cowed_vassal_levy_contribution_mult_neg
    }
}
}
}

DI_remove_modifier_cowed_vassal_levy_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cowed_vassal_levy_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cowed_vassal_levy_contribution_mult_neg
    }
}
}
}
### happy_powerful_vassal_tax_contribution ###
DI_add_modifier_happy_powerful_vassal_tax_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = happy_powerful_vassal_tax_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = happy_powerful_vassal_tax_contribution
    }
}
}
}

DI_remove_modifier_happy_powerful_vassal_tax_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = happy_powerful_vassal_tax_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = happy_powerful_vassal_tax_contribution
    }
}
}
}

DI_add_modifier_happy_powerful_vassal_tax_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = happy_powerful_vassal_tax_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = happy_powerful_vassal_tax_contribution_neg
    }
}
}
}

DI_remove_modifier_happy_powerful_vassal_tax_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = happy_powerful_vassal_tax_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = happy_powerful_vassal_tax_contribution_neg
    }
}
}
}

DI_add_modifier_happy_powerful_vassal_tax_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = happy_powerful_vassal_tax_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = happy_powerful_vassal_tax_contribution_mult
    }
}
}
}

DI_remove_modifier_happy_powerful_vassal_tax_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = happy_powerful_vassal_tax_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = happy_powerful_vassal_tax_contribution_mult
    }
}
}
}

DI_add_modifier_happy_powerful_vassal_tax_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = happy_powerful_vassal_tax_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = happy_powerful_vassal_tax_contribution_mult_neg
    }
}
}
}

DI_remove_modifier_happy_powerful_vassal_tax_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = happy_powerful_vassal_tax_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = happy_powerful_vassal_tax_contribution_mult_neg
    }
}
}
}
### happy_powerful_vassal_levy_contribution ###
DI_add_modifier_happy_powerful_vassal_levy_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = happy_powerful_vassal_levy_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = happy_powerful_vassal_levy_contribution
    }
}
}
}

DI_remove_modifier_happy_powerful_vassal_levy_contribution = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = happy_powerful_vassal_levy_contribution
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = happy_powerful_vassal_levy_contribution
    }
}
}
}

DI_add_modifier_happy_powerful_vassal_levy_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = happy_powerful_vassal_levy_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = happy_powerful_vassal_levy_contribution_neg
    }
}
}
}

DI_remove_modifier_happy_powerful_vassal_levy_contribution_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = happy_powerful_vassal_levy_contribution_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = happy_powerful_vassal_levy_contribution_neg
    }
}
}
}

DI_add_modifier_happy_powerful_vassal_levy_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = happy_powerful_vassal_levy_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = happy_powerful_vassal_levy_contribution_mult
    }
}
}
}

DI_remove_modifier_happy_powerful_vassal_levy_contribution_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = happy_powerful_vassal_levy_contribution_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = happy_powerful_vassal_levy_contribution_mult
    }
}
}
}

DI_add_modifier_happy_powerful_vassal_levy_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = happy_powerful_vassal_levy_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = happy_powerful_vassal_levy_contribution_mult_neg
    }
}
}
}

DI_remove_modifier_happy_powerful_vassal_levy_contribution_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = happy_powerful_vassal_levy_contribution_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = happy_powerful_vassal_levy_contribution_mult_neg
    }
}
}
}

## diplomacy_scheme_resistance ###
DI_add_modifier_diplomacy_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomacy_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomacy_scheme_resistance
    }
}
}
}

DI_remove_modifier_diplomacy_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomacy_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomacy_scheme_resistance
    }
}
}
}

DI_add_modifier_diplomacy_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = diplomacy_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = diplomacy_scheme_resistance_neg
    }
}
}
}

DI_remove_modifier_diplomacy_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = diplomacy_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = diplomacy_scheme_resistance_neg
    }
}
}
}
## intrigue_scheme_resistance ###
DI_add_modifier_intrigue_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intrigue_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intrigue_scheme_resistance
    }
}
}
}

DI_remove_modifier_intrigue_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intrigue_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intrigue_scheme_resistance
    }
}
}
}

DI_add_modifier_intrigue_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = intrigue_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = intrigue_scheme_resistance_neg
    }
}
}
}

DI_remove_modifier_intrigue_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = intrigue_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = intrigue_scheme_resistance_neg
    }
}
}
}
## stewardship_scheme_resistance ###
DI_add_modifier_stewardship_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stewardship_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stewardship_scheme_resistance
    }
}
}
}

DI_remove_modifier_stewardship_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stewardship_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stewardship_scheme_resistance
    }
}
}
}

DI_add_modifier_stewardship_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = stewardship_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = stewardship_scheme_resistance_neg
    }
}
}
}

DI_remove_modifier_stewardship_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = stewardship_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = stewardship_scheme_resistance_neg
    }
}
}
}
## martial_scheme_resistance ###
DI_add_modifier_martial_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = martial_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = martial_scheme_resistance
    }
}
}
}

DI_remove_modifier_martial_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = martial_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = martial_scheme_resistance
    }
}
}
}

DI_add_modifier_martial_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = martial_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = martial_scheme_resistance_neg
    }
}
}
}

DI_remove_modifier_martial_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = martial_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = martial_scheme_resistance_neg
    }
}
}
}
## prowess_scheme_resistance ###
DI_add_modifier_prowess_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prowess_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prowess_scheme_resistance
    }
}
}
}

DI_remove_modifier_prowess_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prowess_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prowess_scheme_resistance
    }
}
}
}

DI_add_modifier_prowess_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = prowess_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = prowess_scheme_resistance_neg
    }
}
}
}

DI_remove_modifier_prowess_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = prowess_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = prowess_scheme_resistance_neg
    }
}
}
}
## learning_scheme_resistance ###
DI_add_modifier_learning_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = learning_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = learning_scheme_resistance
    }
}
}
}

DI_remove_modifier_learning_scheme_resistance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = learning_scheme_resistance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = learning_scheme_resistance
    }
}
}
}

DI_add_modifier_learning_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = learning_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = learning_scheme_resistance_neg
    }
}
}
}

DI_remove_modifier_learning_scheme_resistance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = learning_scheme_resistance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = learning_scheme_resistance_neg
    }
}
}
}
## scheme_discovery_chance_mult ###
DI_add_modifier_scheme_discovery_chance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = scheme_discovery_chance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = scheme_discovery_chance_mult
    }
}
}
}

DI_remove_modifier_scheme_discovery_chance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = scheme_discovery_chance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = scheme_discovery_chance_mult
    }
}
}
}

DI_add_modifier_scheme_discovery_chance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = scheme_discovery_chance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = scheme_discovery_chance_mult_neg
    }
}
}
}

DI_remove_modifier_scheme_discovery_chance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = scheme_discovery_chance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = scheme_discovery_chance_mult_neg
    }
}
}
}
## max_personal_schemes ###
DI_add_modifier_max_personal_schemes = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = max_personal_schemes
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = max_personal_schemes
    }
}
}
}

DI_remove_modifier_max_personal_schemes = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = max_personal_schemes
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = max_personal_schemes
    }
}
}
}

DI_add_modifier_max_personal_schemes_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = max_personal_schemes_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = max_personal_schemes_neg
    }
}
}
}

DI_remove_modifier_max_personal_schemes_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = max_personal_schemes_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = max_personal_schemes_neg
    }
}
}
}
## max_hostile_schemes ###
DI_add_modifier_max_hostile_schemes = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = max_hostile_schemes
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = max_hostile_schemes
    }
}
}
}

DI_remove_modifier_max_hostile_schemes = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = max_hostile_schemes
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = max_hostile_schemes
    }
}
}
}

DI_add_modifier_max_hostile_schemes_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = max_hostile_schemes_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = max_hostile_schemes_neg
    }
}
}
}

DI_remove_modifier_max_hostile_schemes_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = max_hostile_schemes_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = max_hostile_schemes_neg
    }
}
}
}
## owned_hostile_scheme_success_chance ###
DI_add_modifier_owned_hostile_scheme_success_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = owned_hostile_scheme_success_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = owned_hostile_scheme_success_chance
    }
}
}
}

DI_remove_modifier_owned_hostile_scheme_success_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = owned_hostile_scheme_success_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = owned_hostile_scheme_success_chance
    }
}
}
}

DI_add_modifier_owned_hostile_scheme_success_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = owned_hostile_scheme_success_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = owned_hostile_scheme_success_chance_neg
    }
}
}
}

DI_remove_modifier_owned_hostile_scheme_success_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = owned_hostile_scheme_success_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = owned_hostile_scheme_success_chance_neg
    }
}
}
}
## owned_personal_scheme_success_chance ###
DI_add_modifier_owned_personal_scheme_success_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = owned_personal_scheme_success_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = owned_personal_scheme_success_chance
    }
}
}
}

DI_remove_modifier_owned_personal_scheme_success_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = owned_personal_scheme_success_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = owned_personal_scheme_success_chance
    }
}
}
}

DI_add_modifier_owned_personal_scheme_success_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = owned_personal_scheme_success_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = owned_personal_scheme_success_chance_neg
    }
}
}
}

DI_remove_modifier_owned_personal_scheme_success_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = owned_personal_scheme_success_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = owned_personal_scheme_success_chance_neg
    }
}
}
}
## enemy_hostile_scheme_success_chance ###
DI_add_modifier_enemy_hostile_scheme_success_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = enemy_hostile_scheme_success_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = enemy_hostile_scheme_success_chance
    }
}
}
}

DI_remove_modifier_enemy_hostile_scheme_success_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = enemy_hostile_scheme_success_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = enemy_hostile_scheme_success_chance
    }
}
}
}

DI_add_modifier_enemy_hostile_scheme_success_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = enemy_hostile_scheme_success_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = enemy_hostile_scheme_success_chance_neg
    }
}
}
}

DI_remove_modifier_enemy_hostile_scheme_success_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = enemy_hostile_scheme_success_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = enemy_hostile_scheme_success_chance_neg
    }
}
}
}
## enemy_personal_scheme_success_chance ###
DI_add_modifier_enemy_personal_scheme_success_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = enemy_personal_scheme_success_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = enemy_personal_scheme_success_chance
    }
}
}
}

DI_remove_modifier_enemy_personal_scheme_success_chance = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = enemy_personal_scheme_success_chance
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = enemy_personal_scheme_success_chance
    }
}
}
}

DI_add_modifier_enemy_personal_scheme_success_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = enemy_personal_scheme_success_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = enemy_personal_scheme_success_chance_neg
    }
}
}
}

DI_remove_modifier_enemy_personal_scheme_success_chance_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = enemy_personal_scheme_success_chance_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = enemy_personal_scheme_success_chance_neg
    }
}
}
}
## movement_speed ###
DI_add_modifier_movement_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = movement_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = movement_speed
    }
}
}
}

DI_remove_modifier_movement_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = movement_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = movement_speed
    }
}
}
}

DI_add_modifier_movement_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = movement_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = movement_speed_neg
    }
}
}
}

DI_remove_modifier_movement_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = movement_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = movement_speed_neg
    }
}
}
}
## retreat_losses ###
DI_add_modifier_retreat_losses = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = retreat_losses
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = retreat_losses
    }
}
}
}

DI_remove_modifier_retreat_losses = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = retreat_losses
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = retreat_losses
    }
}
}
}

DI_add_modifier_retreat_losses_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = retreat_losses_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = retreat_losses_neg
    }
}
}
}

DI_remove_modifier_retreat_losses_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = retreat_losses_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = retreat_losses_neg
    }
}
}
}
## hard_casualty_modifier ###
DI_add_modifier_hard_casualty_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = hard_casualty_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = hard_casualty_modifier
    }
}
}
}

DI_remove_modifier_hard_casualty_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = hard_casualty_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = hard_casualty_modifier
    }
}
}
}

DI_add_modifier_hard_casualty_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = hard_casualty_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = hard_casualty_modifier_neg
    }
}
}
}

DI_remove_modifier_hard_casualty_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = hard_casualty_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = hard_casualty_modifier_neg
    }
}
}
}
## enemy_hard_casualty_modifier ###
DI_add_modifier_enemy_hard_casualty_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = enemy_hard_casualty_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = enemy_hard_casualty_modifier
    }
}
}
}

DI_remove_modifier_enemy_hard_casualty_modifier = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = enemy_hard_casualty_modifier
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = enemy_hard_casualty_modifier
    }
}
}
}

DI_add_modifier_enemy_hard_casualty_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = enemy_hard_casualty_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = enemy_hard_casualty_modifier_neg
    }
}
}
}

DI_remove_modifier_enemy_hard_casualty_modifier_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = enemy_hard_casualty_modifier_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = enemy_hard_casualty_modifier_neg
    }
}
}
}
## advantage ###
DI_add_modifier_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = advantage
    }
}
}
}

DI_remove_modifier_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = advantage
    }
}
}
}

DI_add_modifier_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = advantage_neg
    }
}
}
}

DI_remove_modifier_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = advantage_neg
    }
}
}
}
## attacker_advantage ###
DI_add_modifier_attacker_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = attacker_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = attacker_advantage
    }
}
}
}

DI_remove_modifier_attacker_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = attacker_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = attacker_advantage
    }
}
}
}

DI_add_modifier_attacker_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = attacker_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = attacker_advantage_neg
    }
}
}
}

DI_remove_modifier_attacker_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = attacker_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = attacker_advantage_neg
    }
}
}
}
## defender_advantage ###
DI_add_modifier_defender_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = defender_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = defender_advantage
    }
}
}
}

DI_remove_modifier_defender_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = defender_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = defender_advantage
    }
}
}
}

DI_add_modifier_defender_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = defender_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = defender_advantage_neg
    }
}
}
}

DI_remove_modifier_defender_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = defender_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = defender_advantage_neg
    }
}
}
}
## enemy_terrain_advantage ###
DI_add_modifier_enemy_terrain_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = enemy_terrain_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = enemy_terrain_advantage
    }
}
}
}

DI_remove_modifier_enemy_terrain_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = enemy_terrain_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = enemy_terrain_advantage
    }
}
}
}

DI_add_modifier_enemy_terrain_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = enemy_terrain_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = enemy_terrain_advantage_neg
    }
}
}
}

DI_remove_modifier_enemy_terrain_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = enemy_terrain_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = enemy_terrain_advantage_neg
    }
}
}
}
## tolerance_advantage ###
DI_add_modifier_tolerance_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tolerance_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tolerance_advantage
    }
}
}
}

DI_remove_modifier_tolerance_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tolerance_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tolerance_advantage
    }
}
}
}

DI_add_modifier_tolerance_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tolerance_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tolerance_advantage_neg
    }
}
}
}

DI_remove_modifier_tolerance_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tolerance_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tolerance_advantage_neg
    }
}
}
}
## advantage_against_coreligionists ###
DI_add_modifier_advantage_against_coreligionists = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = advantage_against_coreligionists
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = advantage_against_coreligionists
    }
}
}
}

DI_remove_modifier_advantage_against_coreligionists = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = advantage_against_coreligionists
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = advantage_against_coreligionists
    }
}
}
}

DI_add_modifier_advantage_against_coreligionists_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = advantage_against_coreligionists_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = advantage_against_coreligionists_neg
    }
}
}
}

DI_remove_modifier_advantage_against_coreligionists_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = advantage_against_coreligionists_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = advantage_against_coreligionists_neg
    }
}
}
}
## controlled_province_advantage ###
DI_add_modifier_controlled_province_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = controlled_province_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = controlled_province_advantage
    }
}
}
}

DI_remove_modifier_controlled_province_advantage = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = controlled_province_advantage
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = controlled_province_advantage
    }
}
}
}

DI_add_modifier_controlled_province_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = controlled_province_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = controlled_province_advantage_neg
    }
}
}
}

DI_remove_modifier_controlled_province_advantage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = controlled_province_advantage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = controlled_province_advantage_neg
    }
}
}
}
## raid_speed ###
DI_add_modifier_raid_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = raid_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = raid_speed
    }
}
}
}

DI_remove_modifier_raid_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = raid_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = raid_speed
    }
}
}
}

DI_add_modifier_raid_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = raid_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = raid_speed_neg
    }
}
}
}

DI_remove_modifier_raid_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = raid_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = raid_speed_neg
    }
}
}
}
### hostile_county_attrition ###
DI_add_modifier_hostile_county_attrition = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = hostile_county_attrition
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = hostile_county_attrition
    }
}
}
}

DI_remove_modifier_hostile_county_attrition = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = hostile_county_attrition
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = hostile_county_attrition
    }
}
}
}

DI_add_modifier_hostile_county_attrition_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = hostile_county_attrition_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = hostile_county_attrition_neg
    }
}
}
}

DI_remove_modifier_hostile_county_attrition_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = hostile_county_attrition_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = hostile_county_attrition_neg
    }
}
}
}
### supply_duration ###
DI_add_modifier_supply_duration = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_duration
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_duration
    }
}
}
}

DI_remove_modifier_supply_duration = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_duration
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_duration
    }
}
}
}

DI_add_modifier_supply_duration_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_duration_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_duration_neg
    }
}
}
}

DI_remove_modifier_supply_duration_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_duration_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_duration_neg
    }
}
}
}
### supply_limit ###
DI_add_modifier_supply_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_limit
    }
}
}
}

DI_remove_modifier_supply_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_limit
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_limit
    }
}
}
}

DI_add_modifier_supply_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_limit_neg
    }
}
}
}

DI_remove_modifier_supply_limit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_limit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_limit_neg
    }
}
}
}

DI_add_modifier_supply_limit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_limit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_limit_mult
    }
}
}
}

DI_remove_modifier_supply_limit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_limit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_limit_mult
    }
}
}
}

DI_add_modifier_supply_limit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_limit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_limit_mult_neg
    }
}
}
}

DI_remove_modifier_supply_limit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_limit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_limit_mult_neg
    }
}
}
}
### fort_level ###
DI_add_modifier_fort_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = fort_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = fort_level
    }
}
}
}

DI_remove_modifier_fort_level = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = fort_level
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = fort_level
    }
}
}
}

DI_add_modifier_fort_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = fort_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = fort_level_neg
    }
}
}
}

DI_remove_modifier_fort_level_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = fort_level_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = fort_level_neg
    }
}
}
}
### supply_capacity ###
DI_add_modifier_supply_capacity = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_capacity
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_capacity
    }
}
}
}

DI_remove_modifier_supply_capacity = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_capacity
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_capacity
    }
}
}
}

DI_add_modifier_supply_capacity_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_capacity_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_capacity_neg
    }
}
}
}

DI_remove_modifier_supply_capacity_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_capacity_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_capacity_neg
    }
}
}
}

DI_add_modifier_supply_capacity_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_capacity_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_capacity_mult
    }
}
}
}

DI_remove_modifier_supply_capacity_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_capacity_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_capacity_mult
    }
}
}
}

DI_add_modifier_supply_capacity_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = supply_capacity_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = supply_capacity_mult_neg
    }
}
}
}

DI_remove_modifier_supply_capacity_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = supply_capacity_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = supply_capacity_mult_neg
    }
}
}
}
### hostile_raid_time ###
DI_add_modifier_hostile_raid_time = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = hostile_raid_time
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = hostile_raid_time
    }
}
}
}

DI_remove_modifier_hostile_raid_time = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = hostile_raid_time
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = hostile_raid_time
    }
}
}
}

DI_add_modifier_hostile_raid_time_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = hostile_raid_time_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = hostile_raid_time_neg
    }
}
}
}

DI_remove_modifier_hostile_raid_time_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = hostile_raid_time_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = hostile_raid_time_neg
    }
}
}
}
### levy_size ###
DI_add_modifier_levy_size = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_size
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_size
    }
}
}
}

DI_remove_modifier_levy_size = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_size
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_size
    }
}
}
}

DI_add_modifier_levy_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_size_neg
    }
}
}
}

DI_remove_modifier_levy_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_size_neg
    }
}
}
}
### garrison_size ###
DI_add_modifier_garrison_size = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = garrison_size
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = garrison_size
    }
}
}
}

DI_remove_modifier_garrison_size = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = garrison_size
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = garrison_size
    }
}
}
}

DI_add_modifier_garrison_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = garrison_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = garrison_size_neg
    }
}
}
}

DI_remove_modifier_garrison_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = garrison_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = garrison_size_neg
    }
}
}
}
### levy_reinforcement_rate ###
DI_add_modifier_levy_reinforcement_rate = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate
    }
}
}
}

DI_add_modifier_levy_reinforcement_rate_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_neg
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_neg
    }
}
}
}
### levy_reinforcement_rate_same_faith ###
DI_add_modifier_levy_reinforcement_rate_same_faith = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_same_faith
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_same_faith
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_same_faith = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_same_faith
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_same_faith
    }
}
}
}

DI_add_modifier_levy_reinforcement_rate_same_faith_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_same_faith_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_same_faith_neg
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_same_faith_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_same_faith_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_same_faith_neg
    }
}
}
}
### levy_reinforcement_rate_different_faith ###
DI_add_modifier_levy_reinforcement_rate_different_faith = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_different_faith
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_different_faith
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_different_faith = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_different_faith
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_different_faith
    }
}
}
}

DI_add_modifier_levy_reinforcement_rate_different_faith_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_different_faith_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_different_faith_neg
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_different_faith_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_different_faith_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_different_faith_neg
    }
}
}
}
### levy_reinforcement_rate_even_if_baron ###
DI_add_modifier_levy_reinforcement_rate_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_even_if_baron
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_even_if_baron
    }
}
}
}

DI_add_modifier_levy_reinforcement_rate_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_even_if_baron_neg
    }
}
}
}
### levy_reinforcement_rate_same_faith_even_if_baron ###
DI_add_modifier_levy_reinforcement_rate_same_faith_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_same_faith_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_same_faith_even_if_baron
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_same_faith_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_same_faith_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_same_faith_even_if_baron
    }
}
}
}

DI_add_modifier_levy_reinforcement_rate_same_faith_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_same_faith_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_same_faith_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_same_faith_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_same_faith_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_same_faith_even_if_baron_neg
    }
}
}
}
### levy_reinforcement_rate_different_faith_even_if_baron ###
DI_add_modifier_levy_reinforcement_rate_different_faith_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_different_faith_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_different_faith_even_if_baron
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_different_faith_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_different_faith_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_different_faith_even_if_baron
    }
}
}
}

DI_add_modifier_levy_reinforcement_rate_different_faith_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_different_faith_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_different_faith_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_different_faith_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_different_faith_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_different_faith_even_if_baron_neg
    }
}
}
}
### levy_reinforcement_rate_friendly_territory ###
DI_add_modifier_levy_reinforcement_rate_friendly_territory = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_friendly_territory
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_friendly_territory
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_friendly_territory = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_friendly_territory
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_friendly_territory
    }
}
}
}

DI_add_modifier_levy_reinforcement_rate_friendly_territory_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = levy_reinforcement_rate_friendly_territory_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = levy_reinforcement_rate_friendly_territory_neg
    }
}
}
}

DI_remove_modifier_levy_reinforcement_rate_friendly_territory_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = levy_reinforcement_rate_friendly_territory_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = levy_reinforcement_rate_friendly_territory_neg
    }
}
}
}
### build_speed ###
DI_add_modifier_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = build_speed
    }
}
}
}

DI_remove_modifier_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = build_speed
    }
}
}
}

DI_add_modifier_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = build_speed_neg
    }
}
}
}

DI_remove_modifier_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = build_speed_neg
    }
}
}
}
### build_gold_cost ###
DI_add_modifier_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = build_gold_cost
    }
}
}
}

DI_remove_modifier_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = build_gold_cost
    }
}
}
}

DI_add_modifier_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = build_gold_cost_neg
    }
}
}
}
### build_piety_cost ###
DI_add_modifier_build_piety_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = build_piety_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = build_piety_cost
    }
}
}
}

DI_remove_modifier_build_piety_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = build_piety_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = build_piety_cost
    }
}
}
}

DI_add_modifier_build_piety_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = build_piety_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = build_piety_cost_neg
    }
}
}
}

DI_remove_modifier_build_piety_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = build_piety_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = build_piety_cost_neg
    }
}
}
}
### build_prestige_cost ###
DI_add_modifier_build_prestige_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = build_prestige_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = build_prestige_cost
    }
}
}
}

DI_remove_modifier_build_prestige_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = build_prestige_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = build_prestige_cost
    }
}
}
}

DI_add_modifier_build_prestige_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = build_prestige_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = build_prestige_cost_neg
    }
}
}
}

DI_remove_modifier_build_prestige_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = build_prestige_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = build_prestige_cost_neg
    }
}
}
}
### holding_build_speed ###
DI_add_modifier_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holding_build_speed
    }
}
}
}

DI_remove_modifier_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holding_build_speed
    }
}
}
}

DI_add_modifier_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holding_build_speed_neg
    }
}
}
}

DI_remove_modifier_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holding_build_speed_neg
    }
}
}
}
### holding_build_gold_cost ###
DI_add_modifier_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holding_build_gold_cost
    }
}
}
}

DI_remove_modifier_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holding_build_gold_cost
    }
}
}
}

DI_add_modifier_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holding_build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holding_build_gold_cost_neg
    }
}
}
}
### holding_build_piety_cost ###
DI_add_modifier_holding_build_piety_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holding_build_piety_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holding_build_piety_cost
    }
}
}
}

DI_remove_modifier_holding_build_piety_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holding_build_piety_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holding_build_piety_cost
    }
}
}
}

DI_add_modifier_holding_build_piety_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holding_build_piety_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holding_build_piety_cost_neg
    }
}
}
}

DI_remove_modifier_holding_build_piety_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holding_build_piety_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holding_build_piety_cost_neg
    }
}
}
}
### holding_build_prestige_cost ###
DI_add_modifier_holding_build_prestige_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holding_build_prestige_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holding_build_prestige_cost
    }
}
}
}

DI_remove_modifier_holding_build_prestige_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holding_build_prestige_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holding_build_prestige_cost
    }
}
}
}

DI_add_modifier_holding_build_prestige_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = holding_build_prestige_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = holding_build_prestige_cost_neg
    }
}
}
}

DI_remove_modifier_holding_build_prestige_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = holding_build_prestige_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = holding_build_prestige_cost_neg
    }
}
}
}
### tax_mult ###
DI_add_modifier_tax_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tax_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tax_mult
    }
}
}
}

DI_remove_modifier_tax_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tax_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tax_mult
    }
}
}
}

DI_add_modifier_tax_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tax_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tax_mult_neg
    }
}
}
}

DI_remove_modifier_tax_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tax_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tax_mult_neg
    }
}
}
}
### development_growth_factor ###
DI_add_modifier_development_growth_factor = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = development_growth_factor
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = development_growth_factor
    }
}
}
}

DI_remove_modifier_development_growth_factor = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = development_growth_factor
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = development_growth_factor
    }
}
}
}

DI_add_modifier_development_growth_factor_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = development_growth_factor_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = development_growth_factor_neg
    }
}
}
}

DI_remove_modifier_development_growth_factor_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = development_growth_factor_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = development_growth_factor_neg
    }
}
}
}
### development_growth ###
DI_add_modifier_development_growth = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = development_growth
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = development_growth
    }
}
}
}

DI_remove_modifier_development_growth = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = development_growth
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = development_growth
    }
}
}
}

DI_add_modifier_development_growth_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = development_growth_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = development_growth_neg
    }
}
}
}

DI_remove_modifier_development_growth_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = development_growth_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = development_growth_neg
    }
}
}
}
### character_capital_county_monthly_development_growth ###
DI_add_modifier_character_capital_county_monthly_development_growth = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = character_capital_county_monthly_development_growth
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = character_capital_county_monthly_development_growth
    }
}
}
}

DI_remove_modifier_character_capital_county_monthly_development_growth = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = character_capital_county_monthly_development_growth
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = character_capital_county_monthly_development_growth
    }
}
}
}

DI_add_modifier_character_capital_county_monthly_development_growth_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = character_capital_county_monthly_development_growth_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = character_capital_county_monthly_development_growth_neg
    }
}
}
}

DI_remove_modifier_character_capital_county_monthly_development_growth_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = character_capital_county_monthly_development_growth_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = character_capital_county_monthly_development_growth_neg
    }
}
}
}
### monthly_county_control_change ###
DI_add_modifier_monthly_county_control_change = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_county_control_change
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_county_control_change
    }
}
}
}

DI_remove_modifier_monthly_county_control_change = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_county_control_change
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_county_control_change
    }
}
}
}

DI_add_modifier_monthly_county_control_change_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_county_control_change_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_county_control_change_neg
    }
}
}
}

DI_remove_modifier_monthly_county_control_change_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_county_control_change_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_county_control_change_neg
    }
}
}
}
### monthly_county_control_change_factor ###
DI_add_modifier_monthly_county_control_change_factor = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_county_control_change_factor
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_county_control_change_factor
    }
}
}
}

DI_remove_modifier_monthly_county_control_change_factor = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_county_control_change_factor
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_county_control_change_factor
    }
}
}
}

DI_add_modifier_monthly_county_control_change_factor_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_county_control_change_factor_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_county_control_change_factor_neg
    }
}
}
}

DI_remove_modifier_monthly_county_control_change_factor_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_county_control_change_factor_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_county_control_change_factor_neg
    }
}
}
}
### monthly_county_control_change_add_even_if_baron ###
DI_add_modifier_monthly_county_control_change_add_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_county_control_change_add_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_county_control_change_add_even_if_baron
    }
}
}
}

DI_remove_modifier_monthly_county_control_change_add_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_county_control_change_add_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_county_control_change_add_even_if_baron
    }
}
}
}

DI_add_modifier_monthly_county_control_change_add_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_county_control_change_add_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_county_control_change_add_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_monthly_county_control_change_add_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_county_control_change_add_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_county_control_change_add_even_if_baron_neg
    }
}
}
}
### monthly_county_control_change_factor_even_if_baron ###
DI_add_modifier_monthly_county_control_change_factor_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_county_control_change_factor_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_county_control_change_factor_even_if_baron
    }
}
}
}

DI_remove_modifier_monthly_county_control_change_factor_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_county_control_change_factor_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_county_control_change_factor_even_if_baron
    }
}
}
}

DI_add_modifier_monthly_county_control_change_factor_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_county_control_change_factor_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_county_control_change_factor_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_monthly_county_control_change_factor_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_county_control_change_factor_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_county_control_change_factor_even_if_baron_neg
    }
}
}
}
### county_opinion ###
DI_add_modifier_county_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = county_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = county_opinion
    }
}
}
}

DI_remove_modifier_county_opinion = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = county_opinion
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = county_opinion
    }
}
}
}

DI_add_modifier_county_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = county_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = county_opinion_neg
    }
}
}
}

DI_remove_modifier_county_opinion_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = county_opinion_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = county_opinion_neg
    }
}
}
}
### different_faith_county_opinion_mult ###
DI_add_modifier_different_faith_county_opinion_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_faith_county_opinion_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_faith_county_opinion_mult
    }
}
}
}

DI_remove_modifier_different_faith_county_opinion_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_faith_county_opinion_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_faith_county_opinion_mult
    }
}
}
}

DI_add_modifier_different_faith_county_opinion_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_faith_county_opinion_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_faith_county_opinion_mult_neg
    }
}
}
}

DI_remove_modifier_different_faith_county_opinion_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_faith_county_opinion_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_faith_county_opinion_mult_neg
    }
}
}
}
### county_opinion_add_even_if_baron ###
DI_add_modifier_county_opinion_add_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = county_opinion_add_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = county_opinion_add_even_if_baron
    }
}
}
}

DI_remove_modifier_county_opinion_add_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = county_opinion_add_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = county_opinion_add_even_if_baron
    }
}
}
}

DI_add_modifier_county_opinion_add_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = county_opinion_add_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = county_opinion_add_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_county_opinion_add_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = county_opinion_add_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = county_opinion_add_even_if_baron_neg
    }
}
}
}
### different_faith_county_opinion_mult_even_if_baron ###
DI_add_modifier_different_faith_county_opinion_mult_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_faith_county_opinion_mult_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_faith_county_opinion_mult_even_if_baron
    }
}
}
}

DI_remove_modifier_different_faith_county_opinion_mult_even_if_baron = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_faith_county_opinion_mult_even_if_baron
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_faith_county_opinion_mult_even_if_baron
    }
}
}
}

DI_add_modifier_different_faith_county_opinion_mult_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = different_faith_county_opinion_mult_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = different_faith_county_opinion_mult_even_if_baron_neg
    }
}
}
}

DI_remove_modifier_different_faith_county_opinion_mult_even_if_baron_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = different_faith_county_opinion_mult_even_if_baron_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = different_faith_county_opinion_mult_even_if_baron_neg
    }
}
}
}
### cultural_head_fascination ###
DI_add_modifier_cultural_head_fascination = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cultural_head_fascination
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cultural_head_fascination
    }
}
}
}

DI_remove_modifier_cultural_head_fascination = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cultural_head_fascination
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cultural_head_fascination
    }
}
}
}

DI_add_modifier_cultural_head_fascination_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cultural_head_fascination_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cultural_head_fascination_neg
    }
}
}
}

DI_remove_modifier_cultural_head_fascination_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cultural_head_fascination_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cultural_head_fascination_neg
    }
}
}
}

DI_add_modifier_cultural_head_fascination_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cultural_head_fascination_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cultural_head_fascination_mult
    }
}
}
}

DI_remove_modifier_cultural_head_fascination_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cultural_head_fascination_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cultural_head_fascination_mult
    }
}
}
}

DI_add_modifier_cultural_head_fascination_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = cultural_head_fascination_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = cultural_head_fascination_mult_neg
    }
}
}
}

DI_remove_modifier_cultural_head_fascination_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = cultural_head_fascination_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = cultural_head_fascination_mult_neg
    }
}
}
}
### faith_conversion_piety_cost ###
DI_add_modifier_faith_conversion_piety_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = faith_conversion_piety_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = faith_conversion_piety_cost
    }
}
}
}

DI_remove_modifier_faith_conversion_piety_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = faith_conversion_piety_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = faith_conversion_piety_cost
    }
}
}
}

DI_add_modifier_faith_conversion_piety_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = faith_conversion_piety_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = faith_conversion_piety_cost_neg
    }
}
}
}

DI_remove_modifier_faith_conversion_piety_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = faith_conversion_piety_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = faith_conversion_piety_cost_neg
    }
}
}
}

DI_add_modifier_faith_conversion_piety_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = faith_conversion_piety_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = faith_conversion_piety_cost_mult
    }
}
}
}

DI_remove_modifier_faith_conversion_piety_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = faith_conversion_piety_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = faith_conversion_piety_cost_mult
    }
}
}
}

DI_add_modifier_faith_conversion_piety_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = faith_conversion_piety_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = faith_conversion_piety_cost_mult_neg
    }
}
}
}

DI_remove_modifier_faith_conversion_piety_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = faith_conversion_piety_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = faith_conversion_piety_cost_mult_neg
    }
}
}
}
### castle_holding_build_speed ###
DI_add_modifier_castle_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = castle_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = castle_holding_build_speed
    }
}
}
}

DI_remove_modifier_castle_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = castle_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = castle_holding_build_speed
    }
}
}
}

DI_add_modifier_castle_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = castle_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = castle_holding_build_speed_neg
    }
}
}
}

DI_remove_modifier_castle_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = castle_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = castle_holding_build_speed_neg
    }
}
}
}
### castle_holding_build_gold_cost ###
DI_add_modifier_castle_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = castle_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = castle_holding_build_gold_cost
    }
}
}
}

DI_remove_modifier_castle_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = castle_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = castle_holding_build_gold_cost
    }
}
}
}

DI_add_modifier_castle_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = castle_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = castle_holding_build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_castle_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = castle_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = castle_holding_build_gold_cost_neg
    }
}
}
}
### castle_holding_holding_build_speed ###
DI_add_modifier_castle_holding_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = castle_holding_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = castle_holding_holding_build_speed
    }
}
}
}

DI_remove_modifier_castle_holding_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = castle_holding_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = castle_holding_holding_build_speed
    }
}
}
}

DI_add_modifier_castle_holding_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = castle_holding_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = castle_holding_holding_build_speed_neg
    }
}
}
}

DI_remove_modifier_castle_holding_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = castle_holding_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = castle_holding_holding_build_speed_neg
    }
}
}
}
### castle_holding_holding_build_gold_cost ###
DI_add_modifier_castle_holding_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = castle_holding_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = castle_holding_holding_build_gold_cost
    }
}
}
}

DI_remove_modifier_castle_holding_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = castle_holding_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = castle_holding_holding_build_gold_cost
    }
}
}
}

DI_add_modifier_castle_holding_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = castle_holding_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = castle_holding_holding_build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_castle_holding_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = castle_holding_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = castle_holding_holding_build_gold_cost_neg
    }
}
}
}
### tribal_holding_build_speed ###
DI_add_modifier_tribal_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tribal_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tribal_holding_build_speed
    }
}
}
}

DI_remove_modifier_tribal_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tribal_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tribal_holding_build_speed
    }
}
}
}

DI_add_modifier_tribal_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tribal_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tribal_holding_build_speed_neg
    }
}
}
}

DI_remove_modifier_tribal_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tribal_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tribal_holding_build_speed_neg
    }
}
}
}
### tribal_holding_build_gold_cost ###
DI_add_modifier_tribal_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tribal_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tribal_holding_build_gold_cost
    }
}
}
}

DI_remove_modifier_tribal_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tribal_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tribal_holding_build_gold_cost
    }
}
}
}

DI_add_modifier_tribal_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tribal_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tribal_holding_build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_tribal_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tribal_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tribal_holding_build_gold_cost_neg
    }
}
}
}
### tribal_holding_holding_build_speed ###
DI_add_modifier_tribal_holding_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tribal_holding_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tribal_holding_holding_build_speed
    }
}
}
}

DI_remove_modifier_tribal_holding_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tribal_holding_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tribal_holding_holding_build_speed
    }
}
}
}

DI_add_modifier_tribal_holding_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tribal_holding_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tribal_holding_holding_build_speed_neg
    }
}
}
}

DI_remove_modifier_tribal_holding_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tribal_holding_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tribal_holding_holding_build_speed_neg
    }
}
}
}
### tribal_holding_holding_build_gold_cost ###
DI_add_modifier_tribal_holding_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tribal_holding_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tribal_holding_holding_build_gold_cost
    }
}
}
}

DI_remove_modifier_tribal_holding_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tribal_holding_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tribal_holding_holding_build_gold_cost
    }
}
}
}

DI_add_modifier_tribal_holding_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = tribal_holding_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = tribal_holding_holding_build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_tribal_holding_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = tribal_holding_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = tribal_holding_holding_build_gold_cost_neg
    }
}
}
}
### city_holding_build_speed ###
DI_add_modifier_city_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = city_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = city_holding_build_speed
    }
}
}
}

DI_remove_modifier_city_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = city_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = city_holding_build_speed
    }
}
}
}

DI_add_modifier_city_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = city_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = city_holding_build_speed_neg
    }
}
}
}

DI_remove_modifier_city_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = city_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = city_holding_build_speed_neg
    }
}
}
}
### city_holding_build_gold_cost ###
DI_add_modifier_city_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = city_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = city_holding_build_gold_cost
    }
}
}
}

DI_remove_modifier_city_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = city_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = city_holding_build_gold_cost
    }
}
}
}

DI_add_modifier_city_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = city_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = city_holding_build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_city_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = city_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = city_holding_build_gold_cost_neg
    }
}
}
}
### city_holding_holding_build_speed ###
DI_add_modifier_city_holding_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = city_holding_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = city_holding_holding_build_speed
    }
}
}
}

DI_remove_modifier_city_holding_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = city_holding_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = city_holding_holding_build_speed
    }
}
}
}

DI_add_modifier_city_holding_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = city_holding_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = city_holding_holding_build_speed_neg
    }
}
}
}

DI_remove_modifier_city_holding_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = city_holding_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = city_holding_holding_build_speed_neg
    }
}
}
}
### city_holding_holding_build_gold_cost ###
DI_add_modifier_city_holding_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = city_holding_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = city_holding_holding_build_gold_cost
    }
}
}
}

DI_remove_modifier_city_holding_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = city_holding_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = city_holding_holding_build_gold_cost
    }
}
}
}

DI_add_modifier_city_holding_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = city_holding_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = city_holding_holding_build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_city_holding_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = city_holding_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = city_holding_holding_build_gold_cost_neg
    }
}
}
}
### church_holding_build_speed ###
DI_add_modifier_church_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = church_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = church_holding_build_speed
    }
}
}
}

DI_remove_modifier_church_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = church_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = church_holding_build_speed
    }
}
}
}

DI_add_modifier_church_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = church_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = church_holding_build_speed_neg
    }
}
}
}

DI_remove_modifier_church_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = church_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = church_holding_build_speed_neg
    }
}
}
}
### church_holding_build_gold_cost ###
DI_add_modifier_church_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = church_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = church_holding_build_gold_cost
    }
}
}
}

DI_remove_modifier_church_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = church_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = church_holding_build_gold_cost
    }
}
}
}

DI_add_modifier_church_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = church_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = church_holding_build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_church_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = church_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = church_holding_build_gold_cost_neg
    }
}
}
}
### church_holding_holding_build_speed ###
DI_add_modifier_church_holding_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = church_holding_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = church_holding_holding_build_speed
    }
}
}
}

DI_remove_modifier_church_holding_holding_build_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = church_holding_holding_build_speed
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = church_holding_holding_build_speed
    }
}
}
}

DI_add_modifier_church_holding_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = church_holding_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = church_holding_holding_build_speed_neg
    }
}
}
}

DI_remove_modifier_church_holding_holding_build_speed_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = church_holding_holding_build_speed_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = church_holding_holding_build_speed_neg
    }
}
}
}
### church_holding_holding_build_gold_cost ###
DI_add_modifier_church_holding_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = church_holding_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = church_holding_holding_build_gold_cost
    }
}
}
}

DI_remove_modifier_church_holding_holding_build_gold_cost = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = church_holding_holding_build_gold_cost
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = church_holding_holding_build_gold_cost
    }
}
}
}

DI_add_modifier_church_holding_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = church_holding_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = church_holding_holding_build_gold_cost_neg
    }
}
}
}

DI_remove_modifier_church_holding_holding_build_gold_cost_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = church_holding_holding_build_gold_cost_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = church_holding_holding_build_gold_cost_neg
    }
}
}
}
### monthly_diplomacy_lifestyle_xp_gain_mult ###
DI_add_modifier_monthly_diplomacy_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_diplomacy_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_diplomacy_lifestyle_xp_gain_mult
    }
}
}
}

DI_remove_modifier_monthly_diplomacy_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_diplomacy_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_diplomacy_lifestyle_xp_gain_mult
    }
}
}
}

DI_add_modifier_monthly_diplomacy_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_diplomacy_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_diplomacy_lifestyle_xp_gain_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_diplomacy_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_diplomacy_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_diplomacy_lifestyle_xp_gain_mult_neg
    }
}
}
}
### monthly_martial_lifestyle_xp_gain_mult ###
DI_add_modifier_monthly_martial_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_martial_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_martial_lifestyle_xp_gain_mult
    }
}
}
}

DI_remove_modifier_monthly_martial_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_martial_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_martial_lifestyle_xp_gain_mult
    }
}
}
}

DI_add_modifier_monthly_martial_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_martial_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_martial_lifestyle_xp_gain_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_martial_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_martial_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_martial_lifestyle_xp_gain_mult_neg
    }
}
}
}
### monthly_stewardship_lifestyle_xp_gain_mult ###
DI_add_modifier_monthly_stewardship_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_stewardship_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_stewardship_lifestyle_xp_gain_mult
    }
}
}
}

DI_remove_modifier_monthly_stewardship_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_stewardship_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_stewardship_lifestyle_xp_gain_mult
    }
}
}
}

DI_add_modifier_monthly_stewardship_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_stewardship_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_stewardship_lifestyle_xp_gain_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_stewardship_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_stewardship_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_stewardship_lifestyle_xp_gain_mult_neg
    }
}
}
}
### monthly_intrigue_lifestyle_xp_gain_mult ###
DI_add_modifier_monthly_intrigue_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_intrigue_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_intrigue_lifestyle_xp_gain_mult
    }
}
}
}

DI_remove_modifier_monthly_intrigue_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_intrigue_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_intrigue_lifestyle_xp_gain_mult
    }
}
}
}

DI_add_modifier_monthly_intrigue_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_intrigue_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_intrigue_lifestyle_xp_gain_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_intrigue_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_intrigue_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_intrigue_lifestyle_xp_gain_mult_neg
    }
}
}
}
### monthly_learning_lifestyle_xp_gain_mult ###
DI_add_modifier_monthly_learning_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_learning_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_learning_lifestyle_xp_gain_mult
    }
}
}
}

DI_remove_modifier_monthly_learning_lifestyle_xp_gain_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_learning_lifestyle_xp_gain_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_learning_lifestyle_xp_gain_mult
    }
}
}
}

DI_add_modifier_monthly_learning_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = monthly_learning_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = monthly_learning_lifestyle_xp_gain_mult_neg
    }
}
}
}

DI_remove_modifier_monthly_learning_lifestyle_xp_gain_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = monthly_learning_lifestyle_xp_gain_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = monthly_learning_lifestyle_xp_gain_mult_neg
    }
}
}
}

# Men at Arms Additions
# maa_siege_value_add
DI_add_modifier_maa_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_siege_value_add
    }
}
}
}

# maa_siege_value_remove
DI_remove_modifier_maa_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_siege_value_add
    }
}
}
}

# maa_siege_value_neg
DI_add_modifier_maa_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_siege_value_neg
    }
}
}
}

# maa_siege_value_neg_remove
DI_remove_modifier_maa_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_siege_value_neg
    }
}
}
}

# maa_siege_value_mult
DI_add_modifier_maa_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_siege_value_mult
    }
}
}
}

# maa_siege_value_mult_remove
DI_remove_modifier_maa_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_siege_value_mult
    }
}
}
}

# maa_siege_value_mult_neg
DI_add_modifier_maa_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_siege_value_mult_neg
    }
}
}
}

# maa_siege_value_mult_neg_remove
DI_remove_modifier_maa_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_siege_value_mult_neg
    }
}
}
}

# maa_damage_add
DI_add_modifier_maa_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_damage_add
    }
}
}
}

# maa_damage_remove
DI_remove_modifier_maa_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_damage_add
    }
}
}
}

# maa_damage_neg
DI_add_modifier_maa_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_damage_neg
    }
}
}
}

# maa_damage_neg_remove
DI_remove_modifier_maa_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_damage_neg
    }
}
}
}

# maa_damage_mult
DI_add_modifier_maa_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_damage_mult
    }
}
}
}

# maa_damage_mult_remove
DI_remove_modifier_maa_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_damage_mult
    }
}
}
}

# maa_damage_mult_neg
DI_add_modifier_maa_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_damage_mult_neg
    }
}
}
}

# maa_damage_mult_neg_remove
DI_remove_modifier_maa_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_damage_mult_neg
    }
}
}
}

# maa_toughness_add
DI_add_modifier_maa_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_toughness_add
    }
}
}
}

# maa_toughness_remove
DI_remove_modifier_maa_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_toughness_add
    }
}
}
}

# maa_toughness_neg
DI_add_modifier_maa_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_toughness_neg
    }
}
}
}

# maa_toughness_neg_remove
DI_remove_modifier_maa_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_toughness_neg
    }
}
}
}

# maa_toughness_mult
DI_add_modifier_maa_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_toughness_mult
    }
}
}
}

# maa_toughness_mult_remove
DI_remove_modifier_maa_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_toughness_mult
    }
}
}
}

# maa_toughness_mult_neg
DI_add_modifier_maa_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_toughness_mult_neg
    }
}
}
}

# maa_toughness_mult_neg_remove
DI_remove_modifier_maa_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_toughness_mult_neg
    }
}
}
}

# maa_pursuit_add
DI_add_modifier_maa_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_pursuit_add
    }
}
}
}

# maa_pursuit_remove
DI_remove_modifier_maa_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_pursuit_add
    }
}
}
}

# maa_pursuit_neg
DI_add_modifier_maa_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_pursuit_neg
    }
}
}
}

# maa_pursuit_neg_remove
DI_remove_modifier_maa_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_pursuit_neg
    }
}
}
}

# maa_pursuit_mult
DI_add_modifier_maa_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_pursuit_mult
    }
}
}
}

# maa_pursuit_mult_remove
DI_remove_modifier_maa_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_pursuit_mult
    }
}
}
}

# maa_pursuit_mult_neg
DI_add_modifier_maa_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_pursuit_mult_neg
    }
}
}
}

# maa_pursuit_mult_neg_remove
DI_remove_modifier_maa_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_pursuit_mult_neg
    }
}
}
}

# maa_screen_add
DI_add_modifier_maa_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_screen_add
    }
}
}
}

# maa_screen_remove
DI_remove_modifier_maa_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_screen_add
    }
}
}
}

# maa_screen_neg
DI_add_modifier_maa_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_screen_neg
    }
}
}
}

# maa_screen_neg_remove
DI_remove_modifier_maa_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_screen_neg
    }
}
}
}

# maa_screen_mult
DI_add_modifier_maa_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_screen_mult
    }
}
}
}

# maa_screen_mult_remove
DI_remove_modifier_maa_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_screen_mult
    }
}
}
}

# maa_screen_mult_neg
DI_add_modifier_maa_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = maa_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = maa_screen_mult_neg
    }
}
}
}

# maa_screen_mult_neg_remove
DI_remove_modifier_maa_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = maa_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = maa_screen_mult_neg
    }
}
}
}

# Skirmishers
# maintenance_mult
DI_add_modifier_skirmishers_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_maintenance_mult
    }
}
}
}

# maintenance_mult_remove
DI_remove_modifier_skirmishers_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_maintenance_mult
    }
}
}
}

# maintenance_mult_neg
DI_add_modifier_skirmishers_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_maintenance_mult_neg
    }
}
}
}

# maintenance_mult_neg_remove
DI_remove_modifier_skirmishers_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_maintenance_mult_neg
    }
}
}
}

# recruitment_cost_mult
DI_add_modifier_skirmishers_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_remove
DI_remove_modifier_skirmishers_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_neg
DI_add_modifier_skirmishers_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_recruitment_cost_mult_neg
    }
}
}
}

# recruitment_cost_mult_neg_remove
DI_remove_modifier_skirmishers_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_recruitment_cost_mult_neg
    }
}
}
}

# max_size
DI_add_modifier_skirmishers_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_max_size_add
    }
}
}
}

DI_remove_modifier_skirmishers_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_max_size_add
    }
}
}
}

DI_add_modifier_skirmishers_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_max_size_neg
    }
}
}
}

DI_remove_modifier_skirmishers_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_max_size_neg
    }
}
}
}

DI_add_modifier_skirmishers_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_max_size_mult
    }
}
}
}

DI_remove_modifier_skirmishers_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_max_size_mult
    }
}
}
}

DI_add_modifier_skirmishers_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_max_size_mult_neg
    }
}
}
}

DI_remove_modifier_skirmishers_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_max_size_mult_neg
    }
}
}
}

# siege_value
DI_add_modifier_skirmishers_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_siege_value_add
    }
}
}
}

DI_remove_modifier_skirmishers_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_siege_value_add
    }
}
}
}

DI_add_modifier_skirmishers_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_siege_value_neg
    }
}
}
}

DI_remove_modifier_skirmishers_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_siege_value_neg
    }
}
}
}

DI_add_modifier_skirmishers_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_siege_value_mult
    }
}
}
}

DI_remove_modifier_skirmishers_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_siege_value_mult
    }
}
}
}

DI_add_modifier_skirmishers_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_siege_value_mult_neg
    }
}
}
}

DI_remove_modifier_skirmishers_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_siege_value_mult_neg
    }
}
}
}

# damage
DI_add_modifier_skirmishers_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_damage_add
    }
}
}
}

DI_remove_modifier_skirmishers_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_damage_add
    }
}
}
}

# add
DI_add_modifier_skirmishers_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_damage_neg
    }
}
}
}

# remove
DI_remove_modifier_skirmishers_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_damage_neg
    }
}
}
}

DI_add_modifier_skirmishers_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_damage_mult
    }
}
}
}

DI_remove_modifier_skirmishers_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_damage_mult
    }
}
}
}

# skirmishers_damage_mult_neg
DI_add_modifier_skirmishers_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_damage_mult_neg
    }
}
}
}

DI_remove_modifier_skirmishers_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_damage_mult_neg
    }
}
}
}

# toughness
DI_add_modifier_skirmishers_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_toughness_add
    }
}
}
}

DI_remove_modifier_skirmishers_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_toughness_add
    }
}
}
}

# Add effect for skirmishers_toughness_neg
DI_add_modifier_skirmishers_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_toughness_neg
    }
}
}
}

# Remove effect for skirmishers_toughness_neg
DI_remove_modifier_skirmishers_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_toughness_neg
    }
}
}
}

DI_add_modifier_skirmishers_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_toughness_mult
    }
}
}
}

DI_remove_modifier_skirmishers_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_toughness_mult
    }
}
}
}

DI_add_modifier_skirmishers_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_toughness_mult_neg
    }
}
}
}

DI_remove_modifier_skirmishers_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_toughness_mult_neg
    }
}
}
}

# pursuit
DI_add_modifier_skirmishers_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_pursuit_add
    }
}
}
}

DI_remove_modifier_skirmishers_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_pursuit_add
    }
}
}
}

# Add effect for skirmishers_pursuit_neg
DI_add_modifier_skirmishers_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_pursuit_neg
    }
}
}
}

# Remove effect for skirmishers_pursuit_neg
DI_remove_modifier_skirmishers_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_pursuit_neg
    }
}
}
}

DI_add_modifier_skirmishers_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_pursuit_mult
    }
}
}
}

DI_remove_modifier_skirmishers_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_pursuit_mult
    }
}
}
}

DI_add_modifier_skirmishers_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_pursuit_mult_neg
    }
}
}
}

DI_remove_modifier_skirmishers_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_pursuit_mult_neg
    }
}
}
}

# screen
DI_add_modifier_skirmishers_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_screen_add
    }
}
}
}


DI_remove_modifier_skirmishers_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_screen_add
    }
}
}
}

# Add effect for skirmishers_screen_neg
DI_add_modifier_skirmishers_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_screen_neg
    }
}
}
}

# Remove effect for skirmishers_screen_neg
DI_remove_modifier_skirmishers_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_screen_neg
    }
}
}
}

DI_add_modifier_skirmishers_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_screen_mult
    }
}
}
}

DI_remove_modifier_skirmishers_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_screen_mult
    }
}
}
}

DI_add_modifier_skirmishers_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = skirmishers_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = skirmishers_screen_mult_neg
    }
}
}
}

DI_remove_modifier_skirmishers_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = skirmishers_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = skirmishers_screen_mult_neg
    }
}
}
}

# archers
# maintenance_mult
DI_add_modifier_archers_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_maintenance_mult
    }
}
}
}

# maintenance_mult_remove
DI_remove_modifier_archers_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_maintenance_mult
    }
}
}
}

# maintenance_mult_neg
DI_add_modifier_archers_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_maintenance_mult_neg
    }
}
}
}

# maintenance_mult_neg_remove
DI_remove_modifier_archers_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_maintenance_mult_neg
    }
}
}
}

# recruitment_cost_mult
DI_add_modifier_archers_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_remove
DI_remove_modifier_archers_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_neg
DI_add_modifier_archers_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_recruitment_cost_mult_neg
    }
}
}
}

# recruitment_cost_mult_neg_remove
DI_remove_modifier_archers_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_recruitment_cost_mult_neg
    }
}
}
}

# max_size
DI_add_modifier_archers_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_max_size_add
    }
}
}
}

DI_remove_modifier_archers_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_max_size_add
    }
}
}
}

DI_add_modifier_archers_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_max_size_neg
    }
}
}
}

DI_remove_modifier_archers_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_max_size_neg
    }
}
}
}

DI_add_modifier_archers_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_max_size_mult
    }
}
}
}

DI_remove_modifier_archers_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_max_size_mult
    }
}
}
}

DI_add_modifier_archers_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_max_size_mult_neg
    }
}
}
}

DI_remove_modifier_archers_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_max_size_mult_neg
    }
}
}
}

# siege_value
DI_add_modifier_archers_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_siege_value_add
    }
}
}
}

DI_remove_modifier_archers_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_siege_value_add
    }
}
}
}

DI_add_modifier_archers_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_siege_value_neg
    }
}
}
}

DI_remove_modifier_archers_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_siege_value_neg
    }
}
}
}

DI_add_modifier_archers_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_siege_value_mult
    }
}
}
}

DI_remove_modifier_archers_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_siege_value_mult
    }
}
}
}

DI_add_modifier_archers_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_siege_value_mult_neg
    }
}
}
}

DI_remove_modifier_archers_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_siege_value_mult_neg
    }
}
}
}

# damage
DI_add_modifier_archers_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_damage_add
    }
}
}
}

DI_remove_modifier_archers_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_damage_add
    }
}
}
}

# add
DI_add_modifier_archers_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_damage_neg
    }
}
}
}

# remove
DI_remove_modifier_archers_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_damage_neg
    }
}
}
}

DI_add_modifier_archers_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_damage_mult
    }
}
}
}

DI_remove_modifier_archers_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_damage_mult
    }
}
}
}

# archers_damage_mult_neg
DI_add_modifier_archers_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_damage_mult_neg
    }
}
}
}

DI_remove_modifier_archers_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_damage_mult_neg
    }
}
}
}

# toughness
DI_add_modifier_archers_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_toughness_add
    }
}
}
}

DI_remove_modifier_archers_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_toughness_add
    }
}
}
}

# Add effect for archers_toughness_neg
DI_add_modifier_archers_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_toughness_neg
    }
}
}
}

# Remove effect for archers_toughness_neg
DI_remove_modifier_archers_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_toughness_neg
    }
}
}
}

DI_add_modifier_archers_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_toughness_mult
    }
}
}
}

DI_remove_modifier_archers_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_toughness_mult
    }
}
}
}

DI_add_modifier_archers_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_toughness_mult_neg
    }
}
}
}

DI_remove_modifier_archers_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_toughness_mult_neg
    }
}
}
}

# pursuit
DI_add_modifier_archers_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_pursuit_add
    }
}
}
}

DI_remove_modifier_archers_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_pursuit_add
    }
}
}
}

# Add effect for archers_pursuit_neg
DI_add_modifier_archers_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_pursuit_neg
    }
}
}
}

# Remove effect for archers_pursuit_neg
DI_remove_modifier_archers_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_pursuit_neg
    }
}
}
}

DI_add_modifier_archers_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_pursuit_mult
    }
}
}
}

DI_remove_modifier_archers_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_pursuit_mult
    }
}
}
}

DI_add_modifier_archers_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_pursuit_mult_neg
    }
}
}
}

DI_remove_modifier_archers_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_pursuit_mult_neg
    }
}
}
}

# screen
DI_add_modifier_archers_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_screen_add
    }
}
}
}


DI_remove_modifier_archers_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_screen_add
    }
}
}
}

# Add effect for archers_screen_neg
DI_add_modifier_archers_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_screen_neg
    }
}
}
}

# Remove effect for archers_screen_neg
DI_remove_modifier_archers_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_screen_neg
    }
}
}
}

DI_add_modifier_archers_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_screen_mult
    }
}
}
}

DI_remove_modifier_archers_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_screen_mult
    }
}
}
}

DI_add_modifier_archers_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = archers_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = archers_screen_mult_neg
    }
}
}
}

DI_remove_modifier_archers_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = archers_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = archers_screen_mult_neg
    }
}
}
}

# light_cavalry
# maintenance_mult
DI_add_modifier_light_cavalry_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_maintenance_mult
    }
}
}
}

# maintenance_mult_remove
DI_remove_modifier_light_cavalry_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_maintenance_mult
    }
}
}
}

# maintenance_mult_neg
DI_add_modifier_light_cavalry_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_maintenance_mult_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_maintenance_mult_neg
    }
}
}
}

# recruitment_cost_mult
DI_add_modifier_light_cavalry_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_remove
DI_remove_modifier_light_cavalry_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_neg
DI_add_modifier_light_cavalry_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_recruitment_cost_mult_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_recruitment_cost_mult_neg
    }
}
}
}

# max_size
DI_add_modifier_light_cavalry_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_max_size_add
    }
}
}
}

DI_remove_modifier_light_cavalry_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_max_size_add
    }
}
}
}

DI_add_modifier_light_cavalry_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_max_size_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_max_size_neg
    }
}
}
}

DI_add_modifier_light_cavalry_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_max_size_mult
    }
}
}
}

DI_remove_modifier_light_cavalry_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_max_size_mult
    }
}
}
}

DI_add_modifier_light_cavalry_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_max_size_mult_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_max_size_mult_neg
    }
}
}
}

# siege_value
DI_add_modifier_light_cavalry_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_siege_value_add
    }
}
}
}

DI_remove_modifier_light_cavalry_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_siege_value_add
    }
}
}
}

DI_add_modifier_light_cavalry_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_siege_value_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_siege_value_neg
    }
}
}
}

DI_add_modifier_light_cavalry_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_siege_value_mult
    }
}
}
}

DI_remove_modifier_light_cavalry_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_siege_value_mult
    }
}
}
}

DI_add_modifier_light_cavalry_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_siege_value_mult_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_siege_value_mult_neg
    }
}
}
}

# damage
DI_add_modifier_light_cavalry_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_damage_add
    }
}
}
}

DI_remove_modifier_light_cavalry_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_damage_add
    }
}
}
}

# add
DI_add_modifier_light_cavalry_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_damage_neg
    }
}
}
}

# remove
DI_remove_modifier_light_cavalry_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_damage_neg
    }
}
}
}

DI_add_modifier_light_cavalry_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_damage_mult
    }
}
}
}

DI_remove_modifier_light_cavalry_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_damage_mult
    }
}
}
}

# light_cavalry_damage_mult_neg
DI_add_modifier_light_cavalry_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_damage_mult_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_damage_mult_neg
    }
}
}
}

# toughness
DI_add_modifier_light_cavalry_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_toughness_add
    }
}
}
}

DI_remove_modifier_light_cavalry_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_toughness_add
    }
}
}
}

# Add effect for light_cavalry_toughness_neg
DI_add_modifier_light_cavalry_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_toughness_neg
    }
}
}
}

# Remove effect for light_cavalry_toughness_neg
DI_remove_modifier_light_cavalry_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_toughness_neg
    }
}
}
}

DI_add_modifier_light_cavalry_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_toughness_mult
    }
}
}
}

DI_remove_modifier_light_cavalry_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_toughness_mult
    }
}
}
}

DI_add_modifier_light_cavalry_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_toughness_mult_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_toughness_mult_neg
    }
}
}
}

# pursuit
DI_add_modifier_light_cavalry_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_pursuit_add
    }
}
}
}

DI_remove_modifier_light_cavalry_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_pursuit_add
    }
}
}
}

# Add effect for light_cavalry_pursuit_neg
DI_add_modifier_light_cavalry_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_pursuit_neg
    }
}
}
}

# Remove effect for light_cavalry_pursuit_neg
DI_remove_modifier_light_cavalry_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_pursuit_neg
    }
}
}
}

DI_add_modifier_light_cavalry_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_pursuit_mult
    }
}
}
}

DI_remove_modifier_light_cavalry_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_pursuit_mult
    }
}
}
}

DI_add_modifier_light_cavalry_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_pursuit_mult_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_pursuit_mult_neg
    }
}
}
}

# screen
DI_add_modifier_light_cavalry_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_screen_add
    }
}
}
}


DI_remove_modifier_light_cavalry_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_screen_add
    }
}
}
}

# Add effect for light_cavalry_screen_neg
DI_add_modifier_light_cavalry_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_screen_neg
    }
}
}
}

# Remove effect for light_cavalry_screen_neg
DI_remove_modifier_light_cavalry_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_screen_neg
    }
}
}
}

DI_add_modifier_light_cavalry_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_screen_mult
    }
}
}
}

DI_remove_modifier_light_cavalry_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_screen_mult
    }
}
}
}

DI_add_modifier_light_cavalry_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = light_cavalry_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = light_cavalry_screen_mult_neg
    }
}
}
}

DI_remove_modifier_light_cavalry_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = light_cavalry_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = light_cavalry_screen_mult_neg
    }
}
}
}

# pikemen
# maintenance_mult
DI_add_modifier_pikemen_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_maintenance_mult
    }
}
}
}

# maintenance_mult_remove
DI_remove_modifier_pikemen_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_maintenance_mult
    }
}
}
}

# maintenance_mult_neg
DI_add_modifier_pikemen_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_maintenance_mult_neg
    }
}
}
}

DI_remove_modifier_pikemen_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_maintenance_mult_neg
    }
}
}
}

# recruitment_cost_mult
DI_add_modifier_pikemen_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_remove
DI_remove_modifier_pikemen_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_neg
DI_add_modifier_pikemen_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_recruitment_cost_mult_neg
    }
}
}
}

# recruitment_cost_mult_neg_remove
DI_remove_modifier_pikemen_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value

                remove_character_modifier = pikemen_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value

        remove_character_modifier = pikemen_recruitment_cost_mult_neg
    }
}
}
}

# max_size
DI_add_modifier_pikemen_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_max_size_add
    }
}
}
}

DI_remove_modifier_pikemen_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_max_size_add
    }
}
}
}

DI_add_modifier_pikemen_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_max_size_neg
    }
}
}
}

DI_remove_modifier_pikemen_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_max_size_neg
    }
}
}
}

DI_add_modifier_pikemen_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_max_size_mult
    }
}
}
}

DI_remove_modifier_pikemen_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_max_size_mult
    }
}
}
}

DI_add_modifier_pikemen_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_max_size_mult_neg
    }
}
}
}

DI_remove_modifier_pikemen_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_max_size_mult_neg
    }
}
}
}

# siege_value
DI_add_modifier_pikemen_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_siege_value_add
    }
}
}
}

DI_remove_modifier_pikemen_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_siege_value_add
    }
}
}
}

DI_add_modifier_pikemen_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_siege_value_neg
    }
}
}
}

DI_remove_modifier_pikemen_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_siege_value_neg
    }
}
}
}

DI_add_modifier_pikemen_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_siege_value_mult
    }
}
}
}

DI_remove_modifier_pikemen_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_siege_value_mult
    }
}
}
}

DI_add_modifier_pikemen_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_siege_value_mult_neg
    }
}
}
}

DI_remove_modifier_pikemen_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_siege_value_mult_neg
    }
}
}
}

# damage
DI_add_modifier_pikemen_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_damage_add
    }
}
}
}

DI_remove_modifier_pikemen_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_damage_add
    }
}
}
}

# add
DI_add_modifier_pikemen_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_damage_neg
    }
}
}
}

# remove
DI_remove_modifier_pikemen_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_damage_neg
    }
}
}
}

DI_add_modifier_pikemen_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_damage_mult
    }
}
}
}

DI_remove_modifier_pikemen_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_damage_mult
    }
}
}
}

# pikemen_damage_mult_neg
DI_add_modifier_pikemen_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_damage_mult_neg
    }
}
}
}

DI_remove_modifier_pikemen_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_damage_mult_neg
    }
}
}
}

# toughness
DI_add_modifier_pikemen_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_toughness_add
    }
}
}
}

DI_remove_modifier_pikemen_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_toughness_add
    }
}
}
}

# Add effect for pikemen_toughness_neg
DI_add_modifier_pikemen_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_toughness_neg
    }
}
}
}

# Remove effect for pikemen_toughness_neg
DI_remove_modifier_pikemen_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_toughness_neg
    }
}
}
}

DI_add_modifier_pikemen_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_toughness_mult
    }
}
}
}

DI_remove_modifier_pikemen_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_toughness_mult
    }
}
}
}

DI_add_modifier_pikemen_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_toughness_mult_neg
    }
}
}
}

DI_remove_modifier_pikemen_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_toughness_mult_neg
    }
}
}
}

# pursuit
DI_add_modifier_pikemen_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_pursuit_add
    }
}
}
}

DI_remove_modifier_pikemen_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_pursuit_add
    }
}
}
}

# Add effect for pikemen_pursuit_neg
DI_add_modifier_pikemen_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_pursuit_neg
    }
}
}
}

# Remove effect for pikemen_pursuit_neg
DI_remove_modifier_pikemen_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_pursuit_neg
    }
}
}
}

DI_add_modifier_pikemen_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_pursuit_mult
    }
}
}
}

DI_remove_modifier_pikemen_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_pursuit_mult
    }
}
}
}

DI_add_modifier_pikemen_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_pursuit_mult_neg
    }
}
}
}

DI_remove_modifier_pikemen_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_pursuit_mult_neg
    }
}
}
}

# screen
DI_add_modifier_pikemen_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_screen_add
    }
}
}
}


DI_remove_modifier_pikemen_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_screen_add
    }
}
}
}

# Add effect for pikemen_screen_neg
DI_add_modifier_pikemen_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_screen_neg
    }
}
}
}

# Remove effect for pikemen_screen_neg
DI_remove_modifier_pikemen_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_screen_neg
    }
}
}
}

DI_add_modifier_pikemen_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_screen_mult
    }
}
}
}

DI_remove_modifier_pikemen_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_screen_mult
    }
}
}
}

DI_add_modifier_pikemen_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = pikemen_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = pikemen_screen_mult_neg
    }
}
}
}

DI_remove_modifier_pikemen_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = pikemen_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = pikemen_screen_mult_neg
    }
}
}
}

# heavy infantry
# maintenance_mult
DI_add_modifier_heavy_infantry_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_maintenance_mult
    }
}
}
}

# maintenance_mult_remove
DI_remove_modifier_heavy_infantry_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_maintenance_mult
    }
}
}
}

# maintenance_mult_neg
DI_add_modifier_heavy_infantry_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_maintenance_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_maintenance_mult_neg
    }
}
}
}

# recruitment_cost_mult
DI_add_modifier_heavy_infantry_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_remove
DI_remove_modifier_heavy_infantry_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_neg
DI_add_modifier_heavy_infantry_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_recruitment_cost_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_recruitment_cost_mult_neg = {
    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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_recruitment_cost_mult_neg
    }
}
}
}

# max_size
DI_add_modifier_heavy_infantry_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_max_size_add
    }
}
}
}

DI_remove_modifier_heavy_infantry_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_max_size_add
    }
}
}
}

DI_add_modifier_heavy_infantry_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_max_size_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_max_size_neg
    }
}
}
}

DI_add_modifier_heavy_infantry_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_max_size_mult
    }
}
}
}

DI_remove_modifier_heavy_infantry_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_max_size_mult
    }
}
}
}

DI_add_modifier_heavy_infantry_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_max_size_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_max_size_mult_neg
    }
}
}
}

# siege_value
DI_add_modifier_heavy_infantry_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_siege_value_add
    }
}
}
}

DI_remove_modifier_heavy_infantry_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_siege_value_add
    }
}
}
}

DI_add_modifier_heavy_infantry_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_siege_value_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_siege_value_neg
    }
}
}
}

DI_add_modifier_heavy_infantry_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_siege_value_mult
    }
}
}
}

DI_remove_modifier_heavy_infantry_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_siege_value_mult
    }
}
}
}

DI_add_modifier_heavy_infantry_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_siege_value_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_siege_value_mult_neg
    }
}
}
}

# damage
DI_add_modifier_heavy_infantry_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_damage_add
    }
}
}
}

DI_remove_modifier_heavy_infantry_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_damage_add
    }
}
}
}

# add
DI_add_modifier_heavy_infantry_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_damage_neg
    }
}
}
}

# remove
DI_remove_modifier_heavy_infantry_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_damage_neg
    }
}
}
}

DI_add_modifier_heavy_infantry_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_damage_mult
    }
}
}
}

DI_remove_modifier_heavy_infantry_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_damage_mult
    }
}
}
}

# heavy_infantry_damage_mult_neg
DI_add_modifier_heavy_infantry_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_damage_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_damage_mult_neg
    }
}
}
}

# toughness
DI_add_modifier_heavy_infantry_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_toughness_add
    }
}
}
}

DI_remove_modifier_heavy_infantry_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_toughness_add
    }
}
}
}

# Add effect for heavy_infantry_toughness_neg
DI_add_modifier_heavy_infantry_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_toughness_neg
    }
}
}
}

# Remove effect for heavy_infantry_toughness_neg
DI_remove_modifier_heavy_infantry_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_toughness_neg
    }
}
}
}

DI_add_modifier_heavy_infantry_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_toughness_mult
    }
}
}
}

DI_remove_modifier_heavy_infantry_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_toughness_mult
    }
}
}
}

DI_add_modifier_heavy_infantry_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_toughness_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_toughness_mult_neg
    }
}
}
}

# pursuit
DI_add_modifier_heavy_infantry_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_pursuit_add
    }
}
}
}

DI_remove_modifier_heavy_infantry_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_pursuit_add
    }
}
}
}

# Add effect for heavy_infantry_pursuit_neg
DI_add_modifier_heavy_infantry_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_pursuit_neg
    }
}
}
}

# Remove effect for heavy_infantry_pursuit_neg
DI_remove_modifier_heavy_infantry_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_pursuit_neg
    }
}
}
}

DI_add_modifier_heavy_infantry_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_pursuit_mult
    }
}
}
}

DI_remove_modifier_heavy_infantry_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_pursuit_mult
    }
}
}
}

DI_add_modifier_heavy_infantry_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_pursuit_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_pursuit_mult_neg
    }
}
}
}

# screen
DI_add_modifier_heavy_infantry_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_screen_add
    }
}
}
}


DI_remove_modifier_heavy_infantry_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_screen_add
    }
}
}
}

# Add effect for heavy_infantry_screen_neg
DI_add_modifier_heavy_infantry_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_screen_neg
    }
}
}
}

# Remove effect for heavy_infantry_screen_neg
DI_remove_modifier_heavy_infantry_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_screen_neg
    }
}
}
}

DI_add_modifier_heavy_infantry_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_screen_mult
    }
}
}
}

DI_remove_modifier_heavy_infantry_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_screen_mult
    }
}
}
}

DI_add_modifier_heavy_infantry_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_infantry_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_infantry_screen_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_infantry_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_infantry_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_infantry_screen_mult_neg
    }
}
}
}

# siege weapon
# maintenance_mult
DI_add_modifier_siege_weapon_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_maintenance_mult
    }
}
}
}

# maintenance_mult_remove
DI_remove_modifier_siege_weapon_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_maintenance_mult
    }
}
}
}

# maintenance_mult_neg
DI_add_modifier_siege_weapon_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_maintenance_mult_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_maintenance_mult_neg
    }
}
}
}

# recruitment_cost_mult
DI_add_modifier_siege_weapon_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_remove
DI_remove_modifier_siege_weapon_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_neg
DI_add_modifier_siege_weapon_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_recruitment_cost_mult_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_recruitment_cost_mult_neg
    }
}
}
}

# max_size
DI_add_modifier_siege_weapon_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_max_size_add
    }
}
}
}

DI_remove_modifier_siege_weapon_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_max_size_add
    }
}
}
}

DI_add_modifier_siege_weapon_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_max_size_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_max_size_neg
    }
}
}
}

DI_add_modifier_siege_weapon_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_max_size_mult
    }
}
}
}

DI_remove_modifier_siege_weapon_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_max_size_mult
    }
}
}
}

DI_add_modifier_siege_weapon_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_max_size_mult_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_max_size_mult_neg
    }
}
}
}

# siege_value
DI_add_modifier_siege_weapon_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_siege_value_add
    }
}
}
}

DI_remove_modifier_siege_weapon_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_siege_value_add
    }
}
}
}

DI_add_modifier_siege_weapon_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_siege_value_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_siege_value_neg
    }
}
}
}

DI_add_modifier_siege_weapon_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_siege_value_mult
    }
}
}
}

DI_remove_modifier_siege_weapon_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_siege_value_mult
    }
}
}
}

DI_add_modifier_siege_weapon_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_siege_value_mult_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_siege_value_mult_neg
    }
}
}
}

# damage
DI_add_modifier_siege_weapon_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_damage_add
    }
}
}
}

DI_remove_modifier_siege_weapon_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_damage_add
    }
}
}
}

# add
DI_add_modifier_siege_weapon_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_damage_neg
    }
}
}
}

# remove
DI_remove_modifier_siege_weapon_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_damage_neg
    }
}
}
}

DI_add_modifier_siege_weapon_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_damage_mult
    }
}
}
}

DI_remove_modifier_siege_weapon_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_damage_mult
    }
}
}
}

# siege_weapon_damage_mult_neg
DI_add_modifier_siege_weapon_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_damage_mult_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_damage_mult_neg
    }
}
}
}

# toughness
DI_add_modifier_siege_weapon_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_toughness_add
    }
}
}
}

DI_remove_modifier_siege_weapon_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_toughness_add
    }
}
}
}

# Add effect for siege_weapon_toughness_neg
DI_add_modifier_siege_weapon_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_toughness_neg
    }
}
}
}

# Remove effect for siege_weapon_toughness_neg
DI_remove_modifier_siege_weapon_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_toughness_neg
    }
}
}
}

DI_add_modifier_siege_weapon_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_toughness_mult
    }
}
}
}

DI_remove_modifier_siege_weapon_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_toughness_mult
    }
}
}
}

DI_add_modifier_siege_weapon_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_toughness_mult_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_toughness_mult_neg
    }
}
}
}

# pursuit
DI_add_modifier_siege_weapon_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_pursuit_add
    }
}
}
}

DI_remove_modifier_siege_weapon_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_pursuit_add
    }
}
}
}

# Add effect for siege_weapon_pursuit_neg
DI_add_modifier_siege_weapon_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_pursuit_neg
    }
}
}
}

# Remove effect for siege_weapon_pursuit_neg
DI_remove_modifier_siege_weapon_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_pursuit_neg
    }
}
}
}

DI_add_modifier_siege_weapon_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_pursuit_mult
    }
}
}
}

DI_remove_modifier_siege_weapon_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_pursuit_mult
    }
}
}
}

DI_add_modifier_siege_weapon_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_pursuit_mult_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_pursuit_mult_neg
    }
}
}
}

# screen
DI_add_modifier_siege_weapon_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_screen_add
    }
}
}
}


DI_remove_modifier_siege_weapon_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_screen_add
    }
}
}
}

# Add effect for siege_weapon_screen_neg
DI_add_modifier_siege_weapon_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_screen_neg
    }
}
}
}

# Remove effect for siege_weapon_screen_neg
DI_remove_modifier_siege_weapon_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_screen_neg
    }
}
}
}

DI_add_modifier_siege_weapon_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_screen_mult
    }
}
}
}

DI_remove_modifier_siege_weapon_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_screen_mult
    }
}
}
}

DI_add_modifier_siege_weapon_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = siege_weapon_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = siege_weapon_screen_mult_neg
    }
}
}
}

DI_remove_modifier_siege_weapon_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = siege_weapon_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = siege_weapon_screen_mult_neg
    }
}
}
}

# heavy cavalry
# maintenance_mult
DI_add_modifier_heavy_cavalry_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_maintenance_mult
    }
}
}
}

# maintenance_mult_remove
DI_remove_modifier_heavy_cavalry_maintenance_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_maintenance_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_maintenance_mult
    }
}
}
}

# maintenance_mult_neg
DI_add_modifier_heavy_cavalry_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_maintenance_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_maintenance_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_maintenance_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_maintenance_mult_neg
    }
}
}
}

# recruitment_cost_mult
DI_add_modifier_heavy_cavalry_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_remove
DI_remove_modifier_heavy_cavalry_recruitment_cost_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_recruitment_cost_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_recruitment_cost_mult
    }
}
}
}

# recruitment_cost_mult_neg
DI_add_modifier_heavy_cavalry_recruitment_cost_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_recruitment_cost_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_recruitment_cost_mult_neg = {
    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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_recruitment_cost_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_recruitment_cost_mult_neg
    }
}
}
}

# max_size
DI_add_modifier_heavy_cavalry_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_max_size_add
    }
}
}
}

DI_remove_modifier_heavy_cavalry_max_size_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_max_size_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_max_size_add
    }
}
}
}

DI_add_modifier_heavy_cavalry_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_max_size_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_max_size_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_max_size_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_max_size_neg
    }
}
}
}

DI_add_modifier_heavy_cavalry_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_max_size_mult
    }
}
}
}

DI_remove_modifier_heavy_cavalry_max_size_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_max_size_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_max_size_mult
    }
}
}
}

DI_add_modifier_heavy_cavalry_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_max_size_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_max_size_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_max_size_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_max_size_mult_neg
    }
}
}
}

# siege_value
DI_add_modifier_heavy_cavalry_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_siege_value_add
    }
}
}
}

DI_remove_modifier_heavy_cavalry_siege_value_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_siege_value_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_siege_value_add
    }
}
}
}

DI_add_modifier_heavy_cavalry_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_siege_value_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_siege_value_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_siege_value_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_siege_value_neg
    }
}
}
}

DI_add_modifier_heavy_cavalry_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_siege_value_mult
    }
}
}
}

DI_remove_modifier_heavy_cavalry_siege_value_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_siege_value_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_siege_value_mult
    }
}
}
}

DI_add_modifier_heavy_cavalry_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_siege_value_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_siege_value_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_siege_value_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_siege_value_mult_neg
    }
}
}
}

# damage
DI_add_modifier_heavy_cavalry_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_damage_add
    }
}
}
}

DI_remove_modifier_heavy_cavalry_damage_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_damage_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_damage_add
    }
}
}
}

# add
DI_add_modifier_heavy_cavalry_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_damage_neg
    }
}
}
}

# remove
DI_remove_modifier_heavy_cavalry_damage_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_damage_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_damage_neg
    }
}
}
}

DI_add_modifier_heavy_cavalry_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_damage_mult
    }
}
}
}

DI_remove_modifier_heavy_cavalry_damage_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_damage_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_damage_mult
    }
}
}
}

# heavy_cavalry_damage_mult_neg
DI_add_modifier_heavy_cavalry_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_damage_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_damage_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_damage_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_damage_mult_neg
    }
}
}
}

# toughness
DI_add_modifier_heavy_cavalry_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_toughness_add
    }
}
}
}

DI_remove_modifier_heavy_cavalry_toughness_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_toughness_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_toughness_add
    }
}
}
}

# Add effect for heavy_cavalry_toughness_neg
DI_add_modifier_heavy_cavalry_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_toughness_neg
    }
}
}
}

# Remove effect for heavy_cavalry_toughness_neg
DI_remove_modifier_heavy_cavalry_toughness_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_toughness_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_toughness_neg
    }
}
}
}

DI_add_modifier_heavy_cavalry_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_toughness_mult
    }
}
}
}

DI_remove_modifier_heavy_cavalry_toughness_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_toughness_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_toughness_mult
    }
}
}
}

DI_add_modifier_heavy_cavalry_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_toughness_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_toughness_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }
                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_toughness_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_toughness_mult_neg
    }
}
}
}

# pursuit
DI_add_modifier_heavy_cavalry_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_pursuit_add
    }
}
}
}

DI_remove_modifier_heavy_cavalry_pursuit_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_pursuit_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_pursuit_add
    }
}
}
}

# Add effect for heavy_cavalry_pursuit_neg
DI_add_modifier_heavy_cavalry_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_pursuit_neg
    }
}
}
}

# Remove effect for heavy_cavalry_pursuit_neg
DI_remove_modifier_heavy_cavalry_pursuit_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_pursuit_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_pursuit_neg
    }
}
}
}

DI_add_modifier_heavy_cavalry_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_pursuit_mult
    }
}
}
}

DI_remove_modifier_heavy_cavalry_pursuit_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_pursuit_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_pursuit_mult
    }
}
}
}

DI_add_modifier_heavy_cavalry_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_pursuit_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_pursuit_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_pursuit_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_pursuit_mult_neg
    }
}
}
}

# screen
DI_add_modifier_heavy_cavalry_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_screen_add
    }
}
}
}


DI_remove_modifier_heavy_cavalry_screen_add = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_screen_add
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_screen_add
    }
}
}
}

# Add effect for heavy_cavalry_screen_neg
DI_add_modifier_heavy_cavalry_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_screen_neg
    }
}
}
}

# Remove effect for heavy_cavalry_screen_neg
DI_remove_modifier_heavy_cavalry_screen_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_screen_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_screen_neg
    }
}
}
}

DI_add_modifier_heavy_cavalry_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_screen_mult
    }
}
}
}

DI_remove_modifier_heavy_cavalry_screen_mult = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_screen_mult
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_screen_mult
    }
}
}
}

DI_add_modifier_heavy_cavalry_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                add_character_modifier = heavy_cavalry_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        add_character_modifier = heavy_cavalry_screen_mult_neg
    }
}
}
}

DI_remove_modifier_heavy_cavalry_screen_mult_neg = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                while = { count = scope:DI_story.var:DI_modifier_increment_value
                remove_character_modifier = heavy_cavalry_screen_mult_neg
            }
        }
    }
    else = {
        while = { count = scope:DI_story.var:DI_modifier_increment_value
        remove_character_modifier = heavy_cavalry_screen_mult_neg
    }
}
}
}

### Custom Modifiers ###
# DI_space_marines
DI_add_modifier_space_marines = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_space_marines
            }
        }
        else = {
            add_character_modifier = DI_space_marines
        }
    }
}

DI_remove_modifier_space_marines = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_space_marines
            }
        }
        else = {
            remove_character_modifier = DI_space_marines
        }
    }
}

# DI_immune_to_schemes
DI_add_modifier_immune_to_schemes = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_immune_to_schemes
            }
        }
        else = {
            add_character_modifier = DI_immune_to_schemes
        }
    }
}

DI_remove_modifier_immune_to_schemes = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_immune_to_schemes
            }
        }
        else = {
            remove_character_modifier = DI_immune_to_schemes
        }
    }
}

# DI_contraceptive
DI_add_modifier_contraceptive = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_contraceptive
            }
        }
        else = {
            add_character_modifier = DI_contraceptive
        }
    }
}

DI_remove_modifier_contraceptive = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_contraceptive
            }
        }
        else = {
            remove_character_modifier = DI_contraceptive
        }
    }
}

# DI_ultra_build
DI_add_modifier_ultra_build = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_ultra_build
            }
        }
        else = {
            add_character_modifier = DI_ultra_build
        }
    }
}

DI_remove_modifier_ultra_build = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_ultra_build
            }
        }
        else = {
            remove_character_modifier = DI_ultra_build
        }
    }
}

# DI_building_slots
DI_add_modifier_building_slots = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_building_slots
            }
        }
        else = {
            add_character_modifier = DI_building_slots
        }
    }
}

DI_remove_modifier_building_slots = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_building_slots
            }
        }
        else = {
            remove_character_modifier = DI_building_slots
        }
    }
}

# DI_one_building_slot
DI_add_modifier_one_building_slot = {
    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 = DI_one_building_slot
            }
        }
        else = {
            add_character_modifier = DI_one_building_slot
        }
    }
}

DI_remove_modifier_one_building_slot = {
    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 = DI_one_building_slot
            }
        }
        else = {
            remove_character_modifier = DI_one_building_slot
        }
    }
}

# DI_domain_limit
DI_add_modifier_DI_domain_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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 = {
                        NOT = { government_has_flag = government_uses_domain_limit }
                    }
                    add_character_modifier = DI_domain_limit_max
                }

                add_character_modifier = DI_domain_limit
            }
        }
        else = {
            if = {
                limit = {
                    NOT = { government_has_flag = government_uses_domain_limit }
                }
                add_character_modifier = DI_domain_limit_max
            }

            add_character_modifier = DI_domain_limit
        }
    }
}

DI_remove_modifier_DI_domain_limit = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_domain_limit_max
                remove_character_modifier = DI_domain_limit
            }
        }
        else = {
            remove_character_modifier = DI_domain_limit_max
            remove_character_modifier = DI_domain_limit
        }
    }
}

# DI_money_printer
DI_add_modifier_money_printer = {
    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 = DI_money_printer
            }
        }
        else = {
            add_character_modifier = DI_money_printer
        }
    }
}

DI_remove_modifier_money_printer = {
    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 = DI_money_printer
            }
        }
        else = {
            remove_character_modifier = DI_money_printer
        }
    }
}

### DI_trait_xp_boost ###
DI_add_modifier_DI_trait_xp_boost = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_trait_xp_boost
            }
        }
        else = {
            add_character_modifier = DI_trait_xp_boost
        }
    }
}

DI_remove_modifier_DI_trait_xp_boost = {
    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 = DI_trait_xp_boost
            }
        }
        else = {
            remove_character_modifier = DI_trait_xp_boost
        }
    }
}

###DI_commander_trait_xp_boost
DI_add_modifier_DI_commander_trait_xp_boost ={
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_commander_trait_xp_boost
            }
        }
        else = {
            add_character_modifier = DI_commander_trait_xp_boost
        }
    }
}

DI_remove_modifier_DI_commander_trait_xp_boost ={
    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 = DI_commander_trait_xp_boost
            }
        }
        else = {
            remove_character_modifier = DI_commander_trait_xp_boost
        }
    }
}

### DI_godlike_inheritance
DI_add_modifier_DI_godlike_inheritance = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_godlike_inheritance
            }
        }
        else = {
            add_character_modifier = DI_godlike_inheritance
        }
    }
}

DI_remove_modifier_DI_godlike_inheritance = {
    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 = DI_godlike_inheritance
            }
        }
        else = {
            remove_character_modifier = DI_godlike_inheritance
        }
    }
}

# DI_true_rulers
DI_add_modifier_DI_true_rulers = {
    scope = character

    effect = {
        save_scope_as = target
        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 = {
                        NOT = { government_has_flag = government_uses_domain_limit }
                    }
                    add_character_modifier = domain_limit_max
                }
                add_character_modifier = DI_true_rulers
            }
        }
        else = {
            if = {
                limit = {
                    NOT = { government_has_flag = government_uses_domain_limit }
                }
                add_character_modifier = domain_limit_max
            }
            add_character_modifier = DI_true_rulers
        }
    }
}

DI_remove_modifier_DI_true_rulers = {
    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 = domain_limit_max
                remove_character_modifier = DI_true_rulers
            }
        }
        else = {
            remove_character_modifier = domain_limit_max
            remove_character_modifier = DI_true_rulers
        }
    }
}

# DI_plague_doctor
DI_add_modifier_DI_plague_doctor = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_plague_doctor
            }
        }
        else = {
            add_character_modifier = DI_plague_doctor
        }
    }
}

DI_remove_modifier_DI_plague_doctor = {
    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 = DI_plague_doctor
            }
        }
        else = {
            remove_character_modifier = DI_plague_doctor
        }
    }
}

### DI_imperial_march
DI_add_modifier_DI_imperial_march = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_imperial_march
            }
        }
        else = {
            add_character_modifier = DI_imperial_march
        }
    }
}

DI_remove_modifier_DI_imperial_march = {
    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 = DI_imperial_march
            }
        }
        else = {
            remove_character_modifier = DI_imperial_march
        }
    }
}

### DI_dread_lord
DI_add_modifier_DI_dread_lord = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_dread_lord
                add_dread = 100
            }
        }
        else = {
            add_character_modifier = DI_dread_lord
            add_dread = 100
        }
    }
}

DI_remove_modifier_DI_dread_lord = {
    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 = DI_dread_lord
                add_dread = -100
            }
        }
        else = {
            remove_character_modifier = DI_dread_lord
            add_dread = -100
        }
    }
}

### DI_lifestyle_mastery
DI_add_modifier_DI_lifestyle_mastery = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_lifestyle_mastery
            }
        }
        else = {
            add_character_modifier = DI_lifestyle_mastery
        }
    }
}

DI_remove_modifier_DI_lifestyle_mastery = {
    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 = DI_lifestyle_mastery
            }
        }
        else = {
            remove_character_modifier = DI_lifestyle_mastery
        }
    }
}

### DI_travel_speed
DI_add_modifier_DI_travel_speed = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_travel_speed
            }
        }
        else = {
            add_character_modifier = DI_travel_speed
        }
    }
}

DI_remove_modifier_DI_travel_speed = {
    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 = DI_travel_speed
            }
        }
        else = {
            remove_character_modifier = DI_travel_speed
        }
    }
}

### DI_travel_safety
DI_add_modifier_DI_travel_safety = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_travel_safety
            }
        }
        else = {
            add_character_modifier = DI_travel_safety
        }
    }
}

DI_remove_modifier_DI_travel_safety = {
    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 = DI_travel_safety
            }
        }
        else = {
            remove_character_modifier = DI_travel_safety
        }
    }
}

### DI_legend_spread
DI_add_modifier_DI_legend_spread = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_legend_spread
            }
        }
        else = {
            add_character_modifier = DI_legend_spread
        }
    }
}

DI_remove_modifier_DI_legend_spread = {
    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 = DI_legend_spread
            }
        }
        else = {
            remove_character_modifier = DI_legend_spread
        }
    }
}

### DI Prestige Printer ###
DI_add_modifier_DI_prestige_printer = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_prestige_printer
            }
        }
        else = {
            add_character_modifier = DI_prestige_printer
        }
    }
}

DI_remove_modifier_DI_prestige_printer = {
    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 = DI_prestige_printer
            }
        }
        else = {
            remove_character_modifier = DI_prestige_printer
        }
    }
}

### DI Piety Printer ###
DI_add_modifier_DI_piety_printer = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_piety_printer
            }
        }
        else = {
            add_character_modifier = DI_piety_printer
        }
    }
}

DI_remove_modifier_DI_piety_printer = {
    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 = DI_piety_printer
            }
        }
        else = {
            remove_character_modifier = DI_piety_printer
        }
    }
}

### DI everybody loves me
DI_add_modifier_DI_everybody_loves_me = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_everybody_loves_me
            }
        }
        else = {
            add_character_modifier = DI_everybody_loves_me
        }
    }
}

DI_remove_modifier_DI_everybody_loves_me = {
    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 = DI_everybody_loves_me
            }
        }
        else = {
            remove_character_modifier = DI_everybody_loves_me
        }
    }
}

### DI full stomachs
DI_add_modifier_DI_full_stomachs = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_full_stomachs
            }
        }
        else = {
            add_character_modifier = DI_full_stomachs
        }
    }
}

DI_remove_modifier_DI_full_stomachs = {
    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 = DI_full_stomachs
            }
        }
        else = {
            remove_character_modifier = DI_full_stomachs
        }
    }
}

### Meritorious ###
DI_add_modifier_DI_meritorious = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_meritorious
            }
        }
        else = {
            add_character_modifier = DI_meritorious
        }
    }
}

DI_remove_modifier_DI_meritorious = {
    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 = DI_meritorious
            }
        }
        else = {
            remove_character_modifier = DI_meritorious
        }
    }
}

### Personal Tenet Slots ###
DI_add_modifier_DI_personal_tenet_slots = {
    scope = character

    effect = {
        save_scope_as = target
        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 = DI_personal_tenet_slots
            }
        }
        else = {
            add_character_modifier = DI_personal_tenet_slots
        }
    }
}

DI_remove_modifier_DI_personal_tenet_slots = {
    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 = DI_personal_tenet_slots
            }
        }
        else = {
            remove_character_modifier = DI_personal_tenet_slots
        }
    }
}

### No Legitimacy Change ###
DI_add_modifier_no_legitimacy_change = {
    scope = character

    effect = {
        save_scope_as = target
        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_legitimacy_change
            }
        }
        else = {
            add_character_modifier = no_legitimacy_change
        }
    }
}

DI_remove_modifier_no_legitimacy_change = {
    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_legitimacy_change
            }
        }
        else = {
            remove_character_modifier = no_legitimacy_change
        }
    }
}

### No Stress Change ###
DI_add_modifier_no_stress_change = {
    scope = character

    effect = {
        save_scope_as = target
        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_remove_modifier_no_stress_change = {
    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_add_modifier_no_tyranny_change = {
    scope = character

    effect = {
        save_scope_as = target
        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_remove_modifier_no_tyranny_change = {
    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_add_modifier_no_dread_change = {
    scope = character

    effect = {
        save_scope_as = target
        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_remove_modifier_no_dread_change = {
    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
        }
    }
}

# Moved Here To Keep Things Organized / better track and findabilty for future edits
# Japan has a lot of interafctions where you can have inter dynasty conflics and a lot more houses in a dynasty so i want to move this to a new menu for dynasty modifiers
# also want to add additional house and dynasty modifiers since they play such a big part in japan.

### Legacy of Piracy ###
DI_add_modifier_legacy_of_piracy = {
    scope = character

    effect = {
        save_scope_as = target
        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
                }

                dynasty = {
                    add_dynasty_modifier = fp1_legacy_of_piracy_modifier
                }
            }
        }
        else = {
            dynasty = {
                add_dynasty_modifier = fp1_legacy_of_piracy_modifier
            }
        }
    }
}

DI_remove_modifier_legacy_of_piracy = {
    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
                }

                dynasty = {
                    remove_dynasty_modifier = fp1_legacy_of_piracy_modifier
                }
            }
        }
        else = {
            dynasty = {
                remove_dynasty_modifier = fp1_legacy_of_piracy_modifier
            }
        }
    }
}

### Clear all Modifiers ###
DI_clear_modifiers = {
    scope = character

    effect = {
        save_scope_as = target
        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_all_character_modifiers_effect = yes
            }
        }
        else = {
            DI_remove_all_character_modifiers_effect = yes
        }
    }
}

### The End ###
