﻿# Common target gates for DDM's hostile marriage-acquisition system.

# Structural target gate used when an expedition is first planned. DDM kidnapping is an illegal
# acquisition tool, not a singles-only marriage shortcut: married, betrothed and concubine/consort
# targets are legal objectives, but their existing bonds create sharply higher cost, difficulty and
# consequences during expedition calculation.
ddm_kidnap_basic_target_trigger = {
    is_alive = yes
    is_landed = no
    is_imprisoned = no
    exists = liege
}

# Resolution gate deliberately ignores marriage/betrothal changes that may occur during the travel
# delay. Once the expedition has left, a sudden engagement does not magically cancel the raid.
ddm_kidnap_resolution_target_trigger = {
    is_alive = yes
    is_landed = no
    is_imprisoned = no
}

# Four successful expeditions are allowed per ruler-year. A failed expedition refunds one attempt,
# but no ruler may launch more than eight total attempts before the next yearly playable pulse.
ddm_kidnap_quota_available_trigger = {
    OR = {
        NOT = { has_variable = ddm_kidnap_successes_year }
        var:ddm_kidnap_successes_year < 4
    }
    OR = {
        NOT = { has_variable = ddm_kidnap_attempts_year }
        var:ddm_kidnap_attempts_year < 8
    }
    OR = {
        NOT = { has_variable = ddm_kidnap_attempt_allowance_year }
        AND = {
            has_variable = ddm_kidnap_attempts_year
            has_variable = ddm_kidnap_attempt_allowance_year
            var:ddm_kidnap_attempts_year < var:ddm_kidnap_attempt_allowance_year
        }
    }
}

# Structural pool gate for prospective additional brides. Quality is handled separately so the
# right-click principal target can still be anybody the player actually chose.
ddm_kidnap_bride_candidate_trigger = {
    ddm_kidnap_basic_target_trigger = yes
    is_female = yes
    in_diplomatic_range = scope:ddm_kidnap_actor
    NOT = { is_in_the_same_court_as_or_guest = scope:ddm_kidnap_actor }
}

# User-facing quality floor for automatically selected additional captives. The original 2.0 gate
# was so severe that most courts produced no real candidates and therefore hit the exact same three-person
# fallback on every raid. The sweep now recognizes either strong hereditary quality or genuinely exceptional
# demonstrated competence. Ages 36-40 are no longer accidentally excluded; older candidates remain fertility-gated.
ddm_kidnap_quality_bride_trigger = {
    ddm_kidnap_bride_candidate_trigger = yes
    exists = dynasty
    OR = {
        AND = { age >= 18 age <= 40 }
        AND = { age > 40 fertility >= 0.65 }
    }
    OR = {
        ddm_kidnap_tier1_marker_value >= 2
        ddm_kidnap_tier2_marker_value >= 1
        ddm_kidnap_tier3_marker_value >= 1
        diplomacy >= 18
        martial >= 18
        stewardship >= 18
        intrigue >= 18
        learning >= 18
        prowess >= 18
    }
    ddm_kidnap_good_personality_value >= 1
}

# The broad sweep uses the same strict quality floor; its difference is scale: it takes every qualifying
# noble woman in the target ruler's political sub-realm rather than only the best three.
ddm_kidnap_elite_stock_trigger = {
    ddm_kidnap_quality_bride_trigger = yes
    OR = {
        has_character_flag = ddm_generated_kidnap_bride
        prestige_level >= 2
        is_close_or_extended_family_of = scope:ddm_kidnap_local_ruler
        father = { is_landed = yes }
        mother = { is_landed = yes }
    }
}

# The right-click interaction intentionally has a broad *shown* state elsewhere. This trigger is the
# fully actionable state used after the menu has already exposed the interaction and its failure reasons.
ddm_kidnap_interaction_target_trigger = {
    ddm_kidnap_basic_target_trigger = yes
    in_diplomatic_range = scope:actor
    NOT = { is_in_the_same_court_as_or_guest = scope:actor }
    scope:recipient != scope:actor
}

# AI reciprocity is deliberately selective. Strategic rulers require either genuinely strong
# hereditary/skill value or direct political value to the local ruler; Aggressive AI accepts a
# noticeably lower quality floor but still does not abduct random low-value courtiers.
ddm_kidnap_ai_candidate_trigger = {
    ddm_kidnap_basic_target_trigger = yes
    in_diplomatic_range = scope:ddm_kidnap_actor
    NOT = { is_in_the_same_court_as_or_guest = scope:ddm_kidnap_actor }

    # AI may target attached characters too, but Strategic AI needs a genuinely extraordinary reason
    # to risk stealing another ruler's spouse/consort. Aggressive AI accepts a lower threshold.
    trigger_if = {
        limit = { OR = { is_married = yes is_betrothed = yes is_concubine = yes } }
        OR = {
            AND = { has_game_rule = ddm_kidnap_aggressive_ai ddm_kidnap_ai_target_value >= 360 }
            AND = { has_game_rule = ddm_kidnap_strategic_ai ddm_kidnap_ai_target_value >= 520 }
        }
    }
    trigger_else = {
        OR = {
            is_heir_of = scope:ddm_kidnap_local_ruler
            is_close_or_extended_family_of = scope:ddm_kidnap_local_ruler
            AND = { has_game_rule = ddm_kidnap_aggressive_ai ddm_kidnap_bride_quality_value >= 180 }
            AND = { has_game_rule = ddm_kidnap_strategic_ai ddm_kidnap_bride_quality_value >= 300 }
        }
    }
}

# Whether a marriage-planner recommendation can be targeted when the legal marriage button is blocked.
ddm_match_selected_kidnappable_trigger = {
    exists = var:ddm_match_planner_owner
    exists = var:ddm_match_sel
    var:ddm_match_planner_owner = { ddm_kidnap_quota_available_trigger = yes }
    var:ddm_match_sel = {
        ddm_kidnap_basic_target_trigger = yes
        in_diplomatic_range = var:ddm_match_planner_owner
        NOT = { is_in_the_same_court_as_or_guest = var:ddm_match_planner_owner }
    }
    NOT = { has_game_rule = ddm_kidnap_disabled }
}
