﻿# 2.6.20 — active AI enslavement through CSR-safe interactions.
# Prisoners remain on CSR's native Enslave path, but the AI checks them much more often, can act
# during wars, and is strongly encouraged to convert captives while its household is below target.
# A second AI-only interaction lets rulers use usable strong hooks to coerce unlanded AI characters
# into slavery. The hook route deliberately excludes the human player; player enslavement remains
# possible through actual imprisonment/capture, not an off-screen hook conversion.

carn_enslave_interaction = {
    category = interaction_category_prison
    desc = carn_enslave_interaction_desc
    interface_priority = 100
    common_interaction = yes
    icon = carnx_chain
    send_name = carn_enslave_interaction
    ai_min_reply_days = 0
    ai_max_reply_days = 0

    is_shown = {
        NOT = { has_game_rule = carn_slavery_content_disabled }
        scope:actor = {
            carnx_can_be_slave_owner_trigger = yes
            NOT = { has_relation_slave = scope:recipient }
        }
        scope:recipient = {
            is_imprisoned_by = scope:actor
            carnx_is_slave_trigger = no
            carnx_can_be_enslaved_trigger = yes
        }
    }

    is_valid_showing_failures_only = {
        scope:actor = { carnx_can_start_interaction_trigger = yes }
        scope:recipient = {
            NOT = { has_strong_hook = scope:actor }
            custom_description = {
                text = "currently_being_tortured"
                NOT = { has_character_flag = is_being_tortured }
            }
        }
    }

    auto_accept = yes

    on_accept = {
        if = {
            limit = {
                scope:actor = { is_ai = yes }
                scope:recipient = { is_ai = no }
            }
            scope:recipient = { trigger_event = carn_slave.0001 }
        }
        else = {
            carn_enslave_effect = {
                SLAVE = scope:recipient
                OWNER = scope:actor
                DRAMA = yes
            }
        }
    }

    ai_targets = { ai_recipients = prisoners }

    # Fast prisoner conversion without a global background scan. War captives should be acted on
    # while they are still prisoners instead of waiting half a year or until the war ends.
    ai_frequency_by_tier = {
        barony = 0
        county = 3
        duchy = 2
        kingdom = 1
        empire = 1
        hegemony = 1
    }

    is_available = {
        trigger_if = {
            limit = { is_ai = yes }
            NOR = {
                carnx_is_slavery_always_crime_trigger = yes
                carnx_is_slavery_always_forbidden_trigger = { ACTION = flag:enslave }
            }
        }
    }

    ai_will_do = {
        base = 0

        modifier = { add = carnx_enslave_ai_will_do_base }

        # Living Market 2.6.20: prisoners are a primary source of actual market supply.
        # CSR's doctrine, personality, family and execute-reason logic still modifies the choice.
        modifier = { add = 35 }

        # A ruler below the Living Market household target has a strong reason to keep useful
        # prisoners instead of releasing/ransoming every captive.
        modifier = {
            scope:actor = { domcom_csr_needs_household_procurement_trigger = yes }
            add = 65
        }

        # The human player can genuinely be enslaved after capture/imprisonment. This is the
        # player-facing danger route; hook-based enslavement below explicitly bars human targets.
        modifier = {
            scope:recipient = { is_ai = no }
            add = 65
        }

        # Characters who already chose a pro-slavery CSR attitude lean further into the system.
        # CSR's own attitude modifier remains below as well; this is an additional small nudge.
        modifier = {
            OR = {
                has_character_modifier = carnx_slavery_attitude_slaver_modifier
                has_character_modifier = carnx_slavery_attitude_trader_modifier
                has_character_modifier = carnx_slavery_attitude_employer_modifier
            }
            add = 15
        }

        # Opinion of prisoner (-25 to 25 depending on opinion)
        opinion_modifier = {
            trigger = { scope:actor != scope:recipient }
            opinion_target = scope:recipient
            multiplier = -0.25
        }

        # Compassion (-25 to 25 depending on compassion)
        ai_value_modifier = { ai_compassion = -0.25 }

        # Greed (0 to 50 depending on greed)
        modifier = {
            add = {
                value = ai_greed
                multiply = 0.01
                add = 1
                multiply = 25
            }
        }

        # Marked for enslavement — war/raid captives are a priority
        modifier = {
            scope:recipient = { has_character_modifier = carnx_marked_for_enslavement_modifier }
            add = 125
        }

        # Slavery crime or shunned by faith
        modifier = {
            carnx_is_slavery_crime_trigger = { CHARACTER = scope:recipient }
            add = carnx_ai_negative_crime_impact_value
        }
        modifier = {
            carnx_is_slavery_shunned_trigger = { CHARACTER = scope:recipient }
            add = carnx_ai_negative_shunned_impact_value
        }

        # Additional slavery impact (laws, culture, etc.)
        carnx_slavery_modifier = {
            SLAVE = scope:recipient
            ACTION = flag:enslave
        }

        # CSR slavery attitude logic retained.
        modifier = {
            OR = {
                has_character_modifier = carnx_slavery_attitude_slaver_modifier
                has_character_modifier = carnx_slavery_attitude_trader_modifier
                has_character_modifier = carnx_slavery_attitude_employer_modifier
            }
            add = carnx_ai_positive_attitude_impact_value
        }
        modifier = {
            has_character_modifier = carnx_slavery_attitude_liberator_modifier
            add = carnx_ai_negative_attitude_impact_value
        }

        # Family and relations: reluctant to enslave family and relations.
        carnx_family_and_relations_modifier = {
            RULER = scope:actor
            SLAVE = scope:recipient
            SCALE = -50
        }

        # Keep CSR's usefulness evaluation intact.
        carnx_lacking_councillors_modifier = {
            RULER = scope:actor
            SLAVE = scope:recipient
            SCALE = carnx_ai_positive_skill_impact_halved_value
        }
        carnx_lacking_court_positions_modifier = {
            RULER = scope:actor
            SLAVE = scope:recipient
            SCALE = carnx_ai_positive_aptitude_impact_halved_value
        }
        carnx_lacking_knights_modifier = {
            RULER = scope:actor
            SLAVE = scope:recipient
            SCALE = carnx_ai_positive_prowess_impact_halved_value
        }
        carnx_lacking_commanders_modifier = {
            RULER = scope:actor
            SLAVE = scope:recipient
            SCALE = carnx_ai_positive_cs_impact_halved_value
        }
        carnx_claims_modifier = {
            RULER = scope:actor
            SLAVE = scope:recipient
            SCALE = carnx_ai_positive_claims_impact_halved_value
        }
        carnx_attraction_modifier = {
            RULER = scope:actor
            SLAVE = scope:recipient
            SCALE = carnx_ai_positive_attraction_impact_halved_value
        }
        carnx_female_modifier = {
            SLAVE = scope:recipient
            SCALE = carnx_ai_positive_female_impact_halved_value
        }
        carnx_age_modifier = {
            SLAVE = scope:recipient
            SCALE = carnx_ai_negative_age_impact_halved_value
        }

        # Execute reason, rival, cheating spouse, or nemesis.
        carnx_execute_reason_modifier = {
            RULER = scope:actor
            SLAVE = scope:recipient
            SCALE = 75
        }

        # Preserve CSR's hard protection: if execution is the intended outcome and the
        # prisoner has been held less than two years, do not replace that with enslavement.
        modifier = {
            carnx_has_execute_reason_trigger = { CHARACTER = scope:recipient }
            scope:recipient = { time_in_prison = { years < 2 } }
            factor = 0
        }
    }
}

# AI-only strong-hook coercion. This is an interaction AI target, not a periodic world scan,
# so CK3 itself supplies the ruler's hooked-character target set. Human recipients are excluded.
domcom_csr_ai_strong_hook_enslave_interaction = {
    category = interaction_category_uncategorized
    common_interaction = yes
    interface_priority = 0
    icon = carnx_chain
    desc = domcom_csr_ai_strong_hook_enslave_interaction_desc
    send_name = domcom_csr_ai_strong_hook_enslave_interaction
    use_diplomatic_range = yes
    ai_min_reply_days = 0
    ai_max_reply_days = 0

    is_shown = {
        NOT = { has_game_rule = carn_slavery_content_disabled }
        scope:actor = {
            is_ai = yes
            carnx_can_be_slave_owner_trigger = yes
            has_strong_hook = scope:recipient
            has_usable_hook = scope:recipient
            NOR = {
                carnx_is_slavery_always_crime_trigger = yes
                carnx_is_slavery_always_forbidden_trigger = { ACTION = flag:enslave }
            }
        }
        scope:recipient = {
            is_ai = yes
            is_alive = yes
            is_ruler = no
            is_imprisoned = no
            carnx_is_slave_trigger = no
            carnx_can_be_enslaved_trigger = yes
            NOT = { has_strong_hook = scope:actor }
            in_diplomatic_range = scope:actor
        }
    }

    is_valid_showing_failures_only = {
        scope:actor = {
            has_strong_hook = scope:recipient
            has_usable_hook = scope:recipient
        }
    }

    auto_accept = yes

    on_accept = {
        scope:actor = {
            save_scope_as = new_owner
            use_hook = scope:recipient
        }
        scope:recipient = { save_scope_as = slave }
        carn_enslave_effect = {
            SLAVE = scope:recipient
            OWNER = scope:actor
            DRAMA = yes
        }
    }

    ai_targets = { ai_recipients = hooked_characters }

    ai_frequency_by_tier = {
        barony = 0
        county = 6
        duchy = 3
        kingdom = 2
        empire = 1
        hegemony = 1
    }

    ai_will_do = {
        base = 0
        modifier = {
            scope:actor = {
                has_strong_hook = scope:recipient
                has_usable_hook = scope:recipient
            }
            add = 100
        }
        modifier = {
            scope:actor = { domcom_csr_needs_household_procurement_trigger = yes }
            add = 100
        }
        modifier = {
            scope:actor = {
                OR = {
                    has_character_modifier = carnx_slavery_attitude_slaver_modifier
                    has_character_modifier = carnx_slavery_attitude_trader_modifier
                    has_character_modifier = carnx_slavery_attitude_employer_modifier
                }
            }
            add = 50
        }
        modifier = {
            scope:actor = { has_character_modifier = carnx_slavery_attitude_liberator_modifier }
            factor = 0
        }
    }
}
