﻿# Proscriptions — target validation and realm-security helpers.
# Kept separate from the office UI so interactions, mass orders and pulses all use the same rules.

ddm_is_proscription_faction_target_trigger = {
    is_alive = yes
    is_a_faction_member = yes
    joined_faction = { faction_target = scope:ddm_proscriber }
}

ddm_is_proscription_rebel_leader_trigger = {
    is_alive = yes
    is_at_war_with = scope:ddm_proscriber
    OR = {
        has_trait = peasant_leader
        AND = {
            is_a_faction_member = yes
            joined_faction = { faction_target = scope:ddm_proscriber }
        }
    }
}

ddm_is_valid_proscription_target_trigger = {
    is_alive = yes
    this != scope:ddm_proscriber
    # Defied the Writ is true writ immunity, not merely a relationship-bounty pause.
    NOT = { has_character_flag = ddm_bounty_hunter_immunity }
    # A manually withdrawn writ cannot be reissued immediately. The short lock lets every scheduled
    # proscription/hunter callback finish before this character can become a fresh quarry again.
    NOT = { has_character_flag = ddm_proscription_recently_revoked }
    OR = {
        ddm_is_proscription_faction_target_trigger = yes
        ddm_is_proscription_rebel_leader_trigger = yes
    }
}

ddm_is_eligible_proscription_hunter_trigger = {
    is_alive = yes
    is_imprisoned = no
    this != scope:ddm_proscriber
    this != scope:ddm_proscription_target
}


# Actor scope — UI gating so highlighted buttons mean an actual target exists.
ddm_has_eligible_faction_proscription_target_trigger = {
    # Traverse the factions themselves rather than guessing from the vassal hierarchy. This catches
    # brewing claimant/civil-war factions exactly as CK3 displays them while naturally ignoring
    # county-only populist factions that have no character members to proscribe.
    any_targeting_faction = {
        any_faction_member = {
            is_alive = yes
            NOT = { has_variable = ddm_proscribed_by }
            NOT = { has_character_flag = ddm_bounty_hunter_immunity }
            NOT = { has_character_flag = ddm_proscription_recently_revoked }
        }
    }
}

ddm_has_eligible_rebel_proscription_target_trigger = {
    any_primary_war_enemy = {
        is_alive = yes
        NOT = { has_variable = ddm_proscribed_by }
        NOT = { has_character_flag = ddm_bounty_hunter_immunity }
        NOT = { has_character_flag = ddm_proscription_recently_revoked }
        ddm_is_proscription_rebel_leader_trigger = yes
    }
}

# ---------------------------------------------------------------------------
# 2.5.0 — RELATIONSHIP PROSCRIPTIONS
# ---------------------------------------------------------------------------
# Recipient scope. Used after the actor/proscriber has been saved as ddm_love_proscriber.
ddm_is_unfaithful_lover_of_proscriber_trigger = {
    is_alive = yes
    this != scope:ddm_love_proscriber
    OR = {
        has_relation_lover = scope:ddm_love_proscriber
        has_relation_soulmate = scope:ddm_love_proscriber
    }
    OR = {
        any_relation = {
            type = lover
            is_alive = yes
            this != scope:ddm_love_proscriber
        }
        any_relation = {
            type = soulmate
            is_alive = yes
            this != scope:ddm_love_proscriber
        }
    }
}




# Recipient scope. Relationship writs now get one monthly opportunity. Human targets control the
# annual per-writ ceiling: Off 0, Light 4, Standard 8, High 12, Relentless 12. Relentless differs
# because it explicitly overrides the eight-defense Defied-the-Writ protection reward.
ddm_can_receive_love_bounty_hunter_trigger = {
    is_alive = yes
    is_imprisoned = no
    # Defied normally blocks dispatches; Relentless explicitly overrides that protection.
    OR = {
        NOT = { has_character_flag = ddm_bounty_hunter_immunity }
        AND = { is_ai = no has_variable = ddm_bounty_pressure var:ddm_bounty_pressure = 4 }
    }
    trigger_if = {
        limit = { is_ai = no }
        OR = {
            AND = {
                OR = { NOT = { has_variable = ddm_bounty_pressure } var:ddm_bounty_pressure = 3 }
                OR = { NOT = { has_variable = ddm_love_proscription_attempts_year } var:ddm_love_proscription_attempts_year < 12 }
            }
            AND = {
                has_variable = ddm_bounty_pressure
                var:ddm_bounty_pressure = 1
                OR = { NOT = { has_variable = ddm_love_proscription_attempts_year } var:ddm_love_proscription_attempts_year < 4 }
            }
            AND = {
                has_variable = ddm_bounty_pressure
                var:ddm_bounty_pressure = 2
                OR = { NOT = { has_variable = ddm_love_proscription_attempts_year } var:ddm_love_proscription_attempts_year < 8 }
            }
            AND = {
                has_variable = ddm_bounty_pressure
                var:ddm_bounty_pressure = 4
                OR = { NOT = { has_variable = ddm_love_proscription_attempts_year } var:ddm_love_proscription_attempts_year < 12 }
            }
        }
    }
    trigger_if = {
        limit = { is_ai = yes }
        OR = { NOT = { has_variable = ddm_love_proscription_attempts_year } var:ddm_love_proscription_attempts_year < 12 }
    }
}

# ---------------------------------------------------------------------------
# 2.5.5 — DISCRETIONARY / PERSONAL PROSCRIPTIONS
# ---------------------------------------------------------------------------
# Political faction/rebel writs remain uncapped. These triggers govern the ruler's separate
# discretionary allowance for proscribing any character simply by royal/imperial prerogative.
ddm_can_use_personal_proscriptions_trigger = {
    is_alive = yes
    is_landed = yes
    highest_held_title_tier >= tier_kingdom
}

ddm_personal_proscription_quota_available_trigger = {
    ddm_can_use_personal_proscriptions_trigger = yes
    OR = {
        AND = {
            highest_held_title_tier = tier_kingdom
            OR = {
                NOT = { has_variable = ddm_personal_proscriptions_year }
                var:ddm_personal_proscriptions_year < 6
            }
        }
        AND = {
            highest_held_title_tier = tier_empire
            OR = {
                NOT = { has_variable = ddm_personal_proscriptions_year }
                var:ddm_personal_proscriptions_year < 8
            }
        }
        AND = {
            highest_held_title_tier = tier_hegemony
            OR = {
                NOT = { has_variable = ddm_personal_proscriptions_year }
                var:ddm_personal_proscriptions_year < 12
            }
        }
    }
}

# Recipient scope; scope:ddm_proscriber must be saved.
ddm_is_valid_personal_proscription_target_trigger = {
    is_alive = yes
    is_imprisoned = no
    this != scope:ddm_proscriber
    NOT = { has_variable = ddm_proscribed_by }
    NOT = { has_character_flag = ddm_bounty_hunter_immunity }
    NOT = { has_character_flag = ddm_proscription_recently_revoked }
    scope:ddm_proscriber = { ddm_personal_proscription_quota_available_trigger = yes }
}

# Recipient scope; automation is intentionally selective. Manual Proscribe has no opinion requirement.
ddm_is_automatic_personal_proscription_candidate_trigger = {
    ddm_is_valid_personal_proscription_target_trigger = yes
}
