## Written by WKIII - "Court AI"
title_decisions = {
	# Court AI switch:
	enable_court_ai = {
		only_playable = yes
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			NOT = { has_title_flag = court_ai_enabled }
		}
		allow = { always = yes }
		effect = {
			set_title_flag = court_ai_enabled
			set_title_flag = court_ai_disallowed_council_appointments
			set_title_flag = court_ai_disallowed_council_jobs
			#set_title_flag = court_ai_minor_titles
			#set_title_flag = court_ai_kids_education
			#set_title_flag = court_ai_kids_guardian
			#set_title_flag = court_ai_discourage_plotters
			#set_title_flag = court_ai_epidemic_capital_gate
			#set_title_flag = court_ai_chancellor
			#set_title_flag = court_ai_marshal
			#set_title_flag = court_ai_steward
			#set_title_flag = court_ai_spymaster
			#set_title_flag = court_ai_chaplain
		}
		ai_will_do = { factor = 0 }
	}
	disable_court_ai = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
		}
		allow = { always = yes }
		effect = {
			clr_title_flag = court_ai_enabled
		}
		ai_will_do = { factor = 0 }
	}
	
	# Council jobs:
	court_ai_allow_council_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			has_title_flag = court_ai_disallowed_council_jobs
		}
		allow = { always = yes }
		effect = {
			clr_title_flag = court_ai_disallowed_council_jobs
		}
		ai_will_do = { factor = 0 }
	}
	court_ai_disallow_council_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_disallowed_council_jobs }
		}
		allow = { always = yes }
		effect = {
			set_title_flag = court_ai_disallowed_council_jobs
		}
		ai_will_do = { factor = 0 }
	}
	court_ai_allow_council_jobs_2 = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_disallowed_council_jobs_2 }
			NOT = { has_title_flag = court_ai_disallowed_council_jobs }
		}
		allow = { always = yes }
		effect = {
			set_title_flag = court_ai_disallowed_council_jobs_2
			set_title_flag = court_ai_chancellor_jobs
			set_title_flag = court_ai_marshal_jobs
			set_title_flag = court_ai_treasurer_jobs
			set_title_flag = court_ai_spymaster_jobs
			set_title_flag = court_ai_spiritual_jobs
		}
		ai_will_do = { factor = 0 }
	}
	court_ai_disallow_council_jobs_2 = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			has_title_flag = court_ai_disallowed_council_jobs_2
			NOT = { has_title_flag = court_ai_disallowed_council_jobs }
		}
		allow = { always = yes }
		effect = {
			clr_title_flag = court_ai_disallowed_council_jobs_2
			clr_title_flag = court_ai_chancellor_jobs
			clr_title_flag = court_ai_marshal_jobs
			clr_title_flag = court_ai_treasurer_jobs
			clr_title_flag = court_ai_spymaster_jobs
			clr_title_flag = court_ai_spiritual_jobs
		}
		ai_will_do = { factor = 0 }
	}
	
	# Chancellor jobs:
	court_ai_enable_chancellor_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = {
				has_title_flag = court_ai_disallowed_council_jobs
				has_title_flag = court_ai_chancellor_jobs
			}
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_chancellor_jobs }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_chancellor_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_disallowed_council_jobs }
			has_title_flag = court_ai_chancellor_jobs
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_chancellor_jobs }
		ai_will_do = { factor = 0 }
	}

	# Marshal jobs:
	court_ai_enable_marshal_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = {
				has_title_flag = court_ai_disallowed_council_jobs
				has_title_flag = court_ai_marshal_jobs
			}
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_marshal_jobs }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_marshal_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_disallowed_council_jobs }
			has_title_flag = court_ai_marshal_jobs
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_marshal_jobs }
		ai_will_do = { factor = 0 }
	}

	# Steward jobs:
	court_ai_enable_steward_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = {
				has_title_flag = court_ai_disallowed_council_jobs
				has_title_flag = court_ai_treasurer_jobs
			}
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_treasurer_jobs }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_steward_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_disallowed_council_jobs }
			has_title_flag = court_ai_treasurer_jobs
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_treasurer_jobs }
		ai_will_do = { factor = 0 }
	}

	# Spymaster jobs:
	court_ai_enable_spymaster_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = {
				has_title_flag = court_ai_disallowed_council_jobs
				has_title_flag = court_ai_spymaster_jobs
			}
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_spymaster_jobs }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_spymaster_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_disallowed_council_jobs }
			has_title_flag = court_ai_spymaster_jobs
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_spymaster_jobs }
		ai_will_do = { factor = 0 }
	}

	# Chaplain jobs:
	court_ai_enable_chaplain_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = {
				has_title_flag = court_ai_disallowed_council_jobs
				has_title_flag = court_ai_spiritual_jobs
			}
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_spiritual_jobs }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_chaplain_jobs = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_disallowed_council_jobs }
			has_title_flag = court_ai_spiritual_jobs
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_spiritual_jobs }
		ai_will_do = { factor = 0 }
	}

	#Barre 1
	court_ai_barre_1 = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_disallowed_council_jobs }
		}
		allow = { always = yes }
		effect = {
		}
		ai_will_do = { factor = 0 }
	}
	
	# Active All:
	court_ai_active_all = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_active_all }
		}
		allow = { always = yes }
		effect = {
			set_title_flag = court_ai_active_all
			set_title_flag = court_ai_commander_appointments
			set_title_flag = court_ai_minor_titles
			set_title_flag = court_ai_kids_education
			set_title_flag = court_ai_discourage_plotters
			set_title_flag = court_ai_epidemic_capital_gate
			set_title_flag = court_ai_demands_religious_conversions
		}
		ai_will_do = { factor = 0 }
	}
	court_ai_desactive_all = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			has_title_flag = court_ai_active_all
		}
		allow = { always = yes }
		effect = {
			clr_title_flag = court_ai_active_all
			clr_title_flag = court_ai_commander_appointments
			clr_title_flag = court_ai_minor_titles
			clr_title_flag = court_ai_kids_education
			clr_title_flag = court_ai_discourage_plotters
			clr_title_flag = court_ai_epidemic_capital_gate
			clr_title_flag = court_ai_demands_religious_conversions
		}
		ai_will_do = { factor = 0 }
	}
	
	# Commander jobs:
	court_ai_enable_appoint_commanders = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_commander_appointments }
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_commander_appointments }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_appoint_commanders = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			has_title_flag = court_ai_commander_appointments
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_commander_appointments }
		ai_will_do = { factor = 0 }
	}

	# Minor titles:
	court_ai_enable_minor_titles = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_minor_titles }
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_minor_titles }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_minor_titles = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			has_title_flag = court_ai_minor_titles
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_minor_titles }
		ai_will_do = { factor = 0 }
	}

	# Educating kids:
	court_ai_enable_kids_education = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			#has_title_flag = court_ai_kids_education_2
			NOT = { has_title_flag = court_ai_kids_education }
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_kids_education }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_kids_education = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			#has_title_flag = court_ai_kids_education_2
			has_title_flag = court_ai_kids_education
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_kids_education }
		ai_will_do = { factor = 0 }
	}

	# Discourage plotters:
	court_ai_enable_discourage_plotters = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_discourage_plotters }
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_discourage_plotters }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_discourage_plotters = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			has_title_flag = court_ai_discourage_plotters
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_discourage_plotters }
		ai_will_do = { factor = 0 }
	}

	# Epidemic Capital Gate:
	court_ai_enable_epidemic_capital_gate = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_epidemic_capital_gate }
		}
		allow = { has_dlc = "Reapers" always = yes }
		effect = { set_title_flag = court_ai_epidemic_capital_gate }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_epidemic_capital_gate = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			has_title_flag = court_ai_epidemic_capital_gate
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_epidemic_capital_gate }
		ai_will_do = { factor = 0 }
	}
	
	# Demands religious conversions:
	court_ai_enable_demands_religious_conversions = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			NOT = { has_title_flag = court_ai_demands_religious_conversions }
		}
		allow = { always = yes }
		effect = { set_title_flag = court_ai_demands_religious_conversions }
		ai_will_do = { factor = 0 }
	}
	court_ai_disable_demands_religious_conversions = {
		filter = primary_title
		from_potential = { ai = no }
		potential = {
			owner = { character = FROM }
			has_title_flag = court_ai_enabled
			has_title_flag = court_ai_demands_religious_conversions
		}
		allow = { always = yes }
		effect = { clr_title_flag = court_ai_demands_religious_conversions }
		ai_will_do = { factor = 0 }
	}
}
