﻿##############################################
# Player decisions: Automatic Title Automanagement
# Provides enable/disable decisions for auto-create/grant duchies and kingdoms.
# Enable decisions shown when flag is off; disable when on.
##############################################

riseandfall_enable_auto_create_duchies = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 10
    ai_check_interval = 0
    desc = riseandfall_enable_auto_create_duchies_desc
    selection_tooltip = riseandfall_enable_auto_create_duchies_tooltip
    decision_group_type = riseandfall

    is_shown = { always = yes NOT = { exists = global_var:riseandfall_hide_other_decisions } }

    is_valid = { is_landed = yes }

    effect = { riseandfall_player_create_duchies_se = yes }

    ai_potential = {}
    ai_will_do = { base = 0 }
}

 
riseandfall_enable_auto_create_kingdoms = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 12
    ai_check_interval = 0
    desc = riseandfall_enable_auto_create_kingdoms_desc
    selection_tooltip = riseandfall_enable_auto_create_kingdoms_tooltip
    decision_group_type = riseandfall

    is_shown = { always = yes NOT = { exists = global_var:riseandfall_hide_other_decisions } }

    is_valid = { is_landed = yes }

    effect = { riseandfall_player_create_kingdoms_se = yes }

    ai_potential = {}
    ai_will_do = { base = 0 }
}

 
riseandfall_grant_duchies = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 14
    ai_check_interval = 0
    desc = riseandfall_grant_duchies_desc
    selection_tooltip = riseandfall_grant_duchies_tooltip
    decision_group_type = riseandfall

    # Same-rank duchy grants create an independent ruler, so require a higher rank.
    is_shown = {
        is_landed = yes
        primary_title.tier > tier_duchy
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }

    is_valid = { is_landed = yes primary_title.tier > tier_duchy }

    # Manual grant: run the player duchy grant scripted effect immediately
    effect = { riseandfall_player_grant_duchies_se = yes }

    ai_potential = {}
    ai_will_do = { base = 0 }
}


riseandfall_grant_kingdoms = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 16
    ai_check_interval = 0
    desc = riseandfall_grant_kingdoms_desc
    selection_tooltip = riseandfall_grant_kingdoms_tooltip
    decision_group_type = riseandfall

    # Same-rank kingdom grants create an independent ruler, so require a higher rank.
    is_shown = {
        is_landed = yes
        primary_title.tier > tier_kingdom
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }

    is_valid = { is_landed = yes primary_title.tier > tier_kingdom }

    # Manual grant: run the player kingdom grant scripted effect immediately
    effect = { riseandfall_player_grant_kingdoms_se = yes }

    ai_potential = {}
    ai_will_do = { base = 0 }
}


riseandfall_grant_empires = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 18
    ai_check_interval = 0
    desc = riseandfall_grant_empires_desc
    selection_tooltip = riseandfall_grant_empires_tooltip
    decision_group_type = riseandfall

    # Empire grants are only safe for a hegemony-tier ruler; otherwise the
    # empire recipient would become independent at the same rank.
    is_shown = {
        is_landed = yes
        primary_title.tier > tier_empire
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }

    is_valid = { is_landed = yes primary_title.tier > tier_empire }

    # Manual grant: run the player empire grant scripted effect immediately.
    effect = { riseandfall_player_grant_empires_se = yes }

    ai_potential = {}
    ai_will_do = { base = 0 }
}



riseandfall_grant_counties = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 20
    ai_check_interval = 12
    desc = riseandfall_grant_counties_desc
    selection_tooltip = riseandfall_grant_counties_desc
    decision_group_type = riseandfall

    # County rulers cannot safely create a subordinate county vassal.
    is_shown = {
        is_landed = yes
        primary_title.tier >= tier_duchy
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }

    is_valid = { is_landed = yes primary_title.tier >= tier_duchy }

    # Manual grant: run the counties grant scripted effect immediately
    effect = { riseandfall_grant_counties_se = yes }

    # AI: only consider this decision if AI and they're over the domain limit
    # domain_limit_available is negative when above the limit; this AI check wants strongly over the limit
    ai_potential = { domain_limit_available < -20 }

    # Make AI very likely to pick this when ai_potential is true
    ai_will_do = { base = 100 }
}


riseandfall_transfer_rightful_vassals = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 22
    ai_check_interval = 0
    desc = riseandfall_transfer_rightful_vassals_desc
    selection_tooltip = riseandfall_transfer_rightful_vassals_tooltip
    decision_group_type = riseandfall

    is_shown = { is_landed = yes NOT = { exists = global_var:riseandfall_hide_other_decisions } }

    is_valid = { is_landed = yes }

    effect = { riseandfall_player_transfer_rightful_vassals_se = yes }

    ai_potential = {}
    ai_will_do = { base = 0 }
}


# Court recruitment needs a title-holding ruler, including landless religious heads
# and adventurer camp leaders; county/barony ownership is not required.
# Player: toggle guardian assignment for house children in the ruler's court.
riseandfall_automate_house_child_guardians = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 24
    ai_check_interval = 0
    desc = riseandfall_automate_house_child_guardians_desc
    selection_tooltip = riseandfall_automate_house_child_guardians_tooltip
    decision_group_type = courtier_automation

    is_shown = {
        is_ruler = yes
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
        exists = house
        NOT = { has_character_flag = riseandfall_auto_house_child_guardians_enabled }
    }

    is_valid = { is_ruler = yes }

    effect = {
        add_character_flag = { flag = riseandfall_auto_house_child_guardians_enabled }
        # Give the player immediate feedback; future passes happen yearly.
        riseandfall_player_automate_house_child_guardians_se = yes
    }

    ai_potential = {}
    ai_will_do = { base = 0 }
}

riseandfall_disable_automate_house_child_guardians = {
    picture = { reference = "gfx/interface/illustrations/decision_misc.dds" }
    sort_order = 25
    ai_check_interval = 0
    desc = riseandfall_disable_automate_house_child_guardians_desc
    selection_tooltip = riseandfall_disable_automate_house_child_guardians_tooltip
    decision_group_type = courtier_automation

    is_shown = {
        is_ruler = yes
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
        exists = house
        has_character_flag = riseandfall_auto_house_child_guardians_enabled
    }

    is_valid = { is_ruler = yes }

    effect = { remove_character_flag = riseandfall_auto_house_child_guardians_enabled }

    ai_potential = {}
    ai_will_do = { base = 0 }
}

riseandfall_enable_auto_invite_knights = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 1
    ai_check_interval = 0
    desc = riseandfall_enable_auto_invite_knights_desc
    selection_tooltip = riseandfall_enable_auto_invite_knights_tooltip
    decision_group_type = courtier_automation

    is_shown = {
        is_ruler = yes
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }
    # Search only after clicking; availability checks here scan courts on menu refresh.
    is_valid = { is_ruler = yes }
    effect = { trigger_event = { id = riseandfall_courtier_browser.0014 } }
    ai_potential = {}
    ai_will_do = { base = 0 }
}

riseandfall_disable_auto_invite_knights = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 2
    ai_check_interval = 0
    desc = riseandfall_disable_auto_invite_knights_desc
    selection_tooltip = riseandfall_disable_auto_invite_knights_tooltip
    decision_group_type = courtier_automation

    is_shown = {
        is_ruler = yes
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }
    # Search only after clicking; availability checks here scan courts on menu refresh.
    is_valid = { is_ruler = yes }
    effect = { trigger_event = { id = riseandfall_courtier_browser.0016 } }
    ai_potential = {}
    ai_will_do = { base = 0 }
}

riseandfall_invite_best_free_courtier = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 3
    ai_check_interval = 0
    desc = riseandfall_invite_best_free_courtier_desc
    selection_tooltip = riseandfall_invite_best_free_courtier_tooltip
    decision_group_type = courtier_automation

    is_shown = {
        is_ruler = yes
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }
    # Search only after clicking; availability checks here scan courts on menu refresh.
    is_valid = { is_ruler = yes }
    effect = { trigger_event = { id = riseandfall_courtier_browser.0010 } }
    ai_potential = {}
    ai_will_do = { base = 0 }
}

riseandfall_recruit_best_paid_courtier = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 4
    ai_check_interval = 0
    desc = riseandfall_recruit_best_paid_courtier_desc
    selection_tooltip = riseandfall_recruit_best_paid_courtier_tooltip
    decision_group_type = courtier_automation

    is_shown = {
        is_ruler = yes
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }
    # Search only after clicking; availability checks here scan courts on menu refresh.
    is_valid = { is_ruler = yes }
    effect = { trigger_event = { id = riseandfall_courtier_browser.0011 } }
    ai_potential = {}
    ai_will_do = { base = 0 }
}

riseandfall_enable_auto_invite_guardians = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 5
    ai_check_interval = 0
    desc = riseandfall_enable_auto_invite_guardians_desc
    selection_tooltip = riseandfall_enable_auto_invite_guardians_tooltip
    decision_group_type = courtier_automation

    is_shown = {
        is_ruler = yes
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }
    # Search only after clicking; availability checks here scan courts on menu refresh.
    is_valid = { is_ruler = yes }
    effect = { trigger_event = { id = riseandfall_courtier_browser.0012 } }
    ai_potential = {}
    ai_will_do = { base = 0 }
}

riseandfall_disable_auto_invite_guardians = {
    picture = { reference = "gfx/interface/illustrations/decisions/decision_misc.dds" }
    sort_order = 6
    ai_check_interval = 0
    desc = riseandfall_disable_auto_invite_guardians_desc
    selection_tooltip = riseandfall_disable_auto_invite_guardians_tooltip
    decision_group_type = courtier_automation

    is_shown = {
        is_ruler = yes
        NOT = { exists = global_var:riseandfall_hide_other_decisions }
    }
    # Search only after clicking; availability checks here scan courts on menu refresh.
    is_valid = { is_ruler = yes }
    effect = { trigger_event = { id = riseandfall_courtier_browser.0013 } }
    ai_potential = {}
    ai_will_do = { base = 0 }
}
