namespace = qyv_ai_gso

# Small realm offers protected vassalization to powerful neighbor / player
event qyv_ai_gso.1 {
    type = character_event
    hide_window = no
    is_triggered_only = yes

    trigger = {
        scope:small = { is_ai = yes NOT = { has_liege = yes } }
        scope:big   = { exists = yes }
        OR = {
            game_rule = { rule = qyv_ai_protected_vassalization option = on }
        }
    }

    immediate = {
        save_scope_as = small
        save_scope_as = big
    }

    title = qyv_e1_t
    desc  = qyv_e1_d
    picture = GFX_evt_council

    option = {
        name = qyv_e1_o1 # Accept — liege guarantees religion
        ai_chance = { base = 80 }
        effects = {
            big = { gain_vassal = small }
            small = { qyv_apply_religious_protection = yes }
        }
    }
    option = {
        name = qyv_e1_o2 # Decline
        ai_chance = { base = 20 }
        effects = { small = { add_opinion = { target = big modifier = qyv_received_subsidy years = 2 } } }
    }
}

# Yearly: AI seeks unification if badly outmatched
event qyv_ai_gso.2 {
    type = character_event
    hide_window = yes
    mean_time_to_happen = { months = 12 }

    trigger = {
        is_ai = yes
        qyv_should_seek_vassalization = yes
        any_neighbor_independent_ruler = {
            limit = { military_strength > root.military_strength * 1.5 }
            save_scope_as = stronger
        }
    }

    immediate = {
        if = {
            limit = { exists = stronger }
            trigger_event = { id = qyv_ai_gso.1 days = 1 scope:small = root scope:big = stronger }
        }
    }
}

# Greece region: small realms can spike development occasionally
event qyv_ai_gso.10 {
    type = character_event
    hide_window = yes
    mean_time_to_happen = { months = 36 }
    trigger = {
        is_ai = yes
        primary_title = { de_jure_liege = e_byzantium }
        realm_size < 20
    }
    immediate = {
        capital_province = {
            add_development = 1
        }
    }
}

# Confederation prompt among West/Latin cultures
event qyv_ai_gso.20 {
    type = character_event
    hide_window = no
    is_triggered_only = yes

    trigger = {
        game_rule = { rule = qyv_west_latinate_confed option = on }
        root = { is_ai = yes qyv_is_west_latinate = yes }
        any_neighbor_independent_ruler = {
            limit = { qyv_is_west_latinate = yes }
            save_scope_as = peer
        }
    }

    title = qyv_e20_t
    desc  = qyv_e20_d

    option = {
        name = qyv_e20_o1 # Form Defensive Pact
        effects = {
            root = { add_alliance = peer }
        }
    }
    option = {
        name = qyv_e20_o2 # Not now
    }
}