###########################################
#
# Holy Order Decisions for Sons of Abraham
#
###########################################
# Written by Henrik Fhraeus
###########################################

# Holy Order Decisions are listed for each existing holy order of the right religion

decisions = {

	borrow_money_knights_templar = {
		ai_check_interval = 120

		only_playable = yes

		potential = {
			always = no # Disabled in CK2Plus
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_templar
			religion = d_knights_templar
			is_nomadic = no

			trigger_if = {
				limit = { ai = yes }

				independent = yes
				higher_real_tier_than = COUNT
			}

			NOR = {
				has_character_modifier = borrowed_from_knights_templar
				has_character_modifier = expelled_d_knights_templar
				government = order_government
				is_liege_of = d_knights_templar
			}
		}

		allow = {
			d_knights_templar = {
				holder_scope = {
					wealth >= 300
				}
			}

			NOT = { trait = excommunicated }
			piety >= 100

			custom_tooltip = {
				text = knights_templar_loan_money_TT

				reverse_opinion = {
					who = d_knights_templar
					value >= 25
				}
			}
		}

		effect = {
			wealth = 300
			piety = -100

			add_character_modifier = {
				name = borrowed_from_knights_templar
				duration = -1
				inherit = yes
			}

			d_knights_templar = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					wealth = -300
					save_event_target_as = target_grandmaster
				}
			}

			letter_event = { id = SoA.1011 }
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				wealth < 0
			}
		}
	}

	expel_the_knights_templar = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_templar
			religion = d_knights_templar
			NOT = { has_character_modifier = expelled_d_knights_templar }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_knights_templar
						is_vassal_or_below_of = d_knights_templar
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_the_knights_templar_check }
			}
		}

		effect = {
			set_character_flag = expel_the_knights_templar_check

			d_knights_templar = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	expel_the_knights_hospitaller = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_hospitaller
			religion = d_knights_hospitaller
			NOT = { has_character_modifier = expelled_d_knights_hospitaller }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_knights_hospitaller
						is_vassal_or_below_of = d_knights_hospitaller
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_the_knights_hospitaller_check }
			}
		}

		effect = {
			set_character_flag = expel_the_knights_hospitaller_check

			d_knights_hospitaller = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	expel_the_teutonic_order = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"

			trigger_if = {
				limit = { is_title_active = d_teutonic_order }

				religion = d_teutonic_order
				NOT = { has_character_modifier = expelled_d_teutonic_order }

				any_realm_province = {
					held_under_PREV = yes

					any_province_lord = {
						OR = {
							character = d_teutonic_order
							is_vassal_or_below_of = d_teutonic_order
						}
					}
				}
			}
			trigger_else = {
				is_title_active = k_teutonic_state
				religion = k_teutonic_state
				NOT = { has_character_modifier = expelled_k_teutonic_state }

				any_realm_province = {
					held_under_PREV = yes

					any_province_lord = {
						OR = {
							character = k_teutonic_state
							is_vassal_or_below_of = k_teutonic_state
						}
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_the_teutonic_order_check }
			}
		}

		effect = {
			if = {
				limit = { is_title_active = d_teutonic_order }

				set_character_flag = expel_the_teutonic_order_check

				d_teutonic_order = {
					save_event_target_as = target_holy_order

					holder_scope = {
						save_event_target_as = target_grandmaster
					}
				}
			}
			else = {
				set_character_flag = expel_the_teutonic_state_check

				k_teutonic_state = {
					save_event_target_as = target_holy_order

					holder_scope = {
						save_event_target_as = target_grandmaster
					}
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	expel_the_jomsvikings = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_jomsvikings
			religion = d_jomsvikings
			NOT = { has_character_modifier = expelled_d_jomsvikings }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_jomsvikings
						is_vassal_or_below_of = d_jomsvikings
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_the_jomsvikings_check }
			}
		}

		effect = {
			set_character_flag = expel_the_jomsvikings_check

			d_jomsvikings = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	expel_the_assassins = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_fedayeen
			religion = d_fedayeen

			NOR = {
				has_character_modifier = expelled_d_fedayeen
				society_member_of = the_assassins
			}

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_fedayeen
						is_vassal_or_below_of = d_fedayeen
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_the_assassins_check }
			}
		}

		effect = {
			set_character_flag = expel_the_assassins_check

			d_fedayeen = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_knights_templar = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_templar
			religion = d_knights_templar

			d_knights_templar = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_knights_templar
				is_liege_of = d_knights_templar
				has_landed_title = d_knights_templar
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_knights_templar = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				piety < 1000
				wealth >= 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	donate_money_to_knights_hospitaller = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_hospitaller
			religion = d_knights_hospitaller

			d_knights_hospitaller = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_knights_hospitaller
				is_liege_of = d_knights_hospitaller
				has_landed_title = d_knights_hospitaller
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_knights_hospitaller = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				piety < 1000
				wealth >= 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	donate_money_to_teutonic_order = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"

			trigger_if = {
				limit = { is_title_active = d_teutonic_order }

				religion = d_teutonic_order

				d_teutonic_order = {
					holder_scope = {
						is_within_diplo_range = ROOT
					}
				}
			}
			trigger_else = {
				is_title_active = k_teutonic_state

				religion = k_teutonic_state

				k_teutonic_state = {
					holder_scope = {
						is_within_diplo_range = ROOT
					}
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_teutonic_order
				has_character_modifier = expelled_k_teutonic_state
				is_liege_of = d_teutonic_order
				is_liege_of = k_teutonic_state
				has_landed_title = d_teutonic_order
				has_landed_title = k_teutonic_state
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_teutonic_order = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				piety < 1000
				wealth >= 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	donate_money_to_jomsvikings = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_jomsvikings

			OR = {
				religion = d_jomsvikings
				is_heresy_of = d_jomsvikings
			}

			d_jomsvikings = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_jomsvikings
				is_liege_of = d_jomsvikings
				has_landed_title = d_jomsvikings
			}
		}

		allow = {
			wealth >= 300
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_jomsvikings = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				piety < 1000
				wealth >= 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	borrow_money_assassins = {
		ai_check_interval = 120

		only_playable = yes

		potential = {
			always = no # Disabled in CK2Plus
			has_dlc = "Sons of Abraham"
			is_title_active = d_fedayeen
			religion = d_fedayeen
			is_nomadic = no

			trigger_if = {
				limit = { ai = yes }

				independent = yes
				higher_real_tier_than = COUNT
			}

			NOR = {
				has_character_modifier = borrowed_from_assassins
				has_character_modifier = expelled_d_fedayeen
				has_character_modifier = assassins_debt_modifier # From MNM.6001
				society_member_of = the_assassins
				government = order_government
				is_liege_of = d_fedayeen
			}
		}

		allow = {
			d_fedayeen = {
				holder_scope = {
					wealth >= 300
				}
			}

			piety >= 100

			custom_tooltip = {
				text = hashshashin_loan_money_TT

				reverse_opinion = {
					who = d_fedayeen
					value >= 25
				}
			}
		}

		effect = {
			wealth = 300
			piety = -100

			add_character_modifier = {
				name = borrowed_from_assassins
				duration = -1
				inherit = yes
			}

			hidden_effect = {
				if = {
					limit = { has_dlc = "Mystics" }

					set_variable = {
						which = assassins_debt
						value = 300
					}
				}
			}

			d_fedayeen = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					wealth = -300
					save_event_target_as = target_grandmaster
				}
			}

			letter_event = { id = SoA.1011 }
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				wealth < 0
			}
		}
	}

	donate_money_to_assassins = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_fedayeen
			religion = d_fedayeen

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_fedayeen
				society_member_of = the_assassins
				is_liege_of = d_fedayeen
				has_landed_title = d_fedayeen
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_fedayeen = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				piety < 1000
				wealth >= 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	borrow_money_bektashi = {
		ai_check_interval = 120

		only_playable = yes

		potential = {
			always = no # Disabled in CK2Plus
			has_dlc = "Sons of Abraham"
			is_title_active = d_bektashi
			religion = d_bektashi
			is_nomadic = no

			trigger_if = {
				limit = { ai = yes }

				independent = yes
				higher_real_tier_than = COUNT
			}

			NOR = {
				has_character_modifier = borrowed_from_bektashi
				has_character_modifier = expelled_d_bektashi
				government = order_government
				is_liege_of = d_bektashi
			}
		}

		allow = {
			d_bektashi = {
				holder_scope = {
					wealth >= 300
				}
			}

			piety >= 100

			custom_tooltip = {
				text = bektashi_loan_money_TT

				reverse_opinion = {
					who = d_bektashi
					value >= 25
				}
			}
		}

		effect = {
			wealth = 300
			piety = -100

			add_character_modifier = {
				name = borrowed_from_bektashi
				duration = -1
				inherit = yes
			}

			d_bektashi = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					wealth = -300
					save_event_target_as = target_grandmaster
				}
			}

			letter_event = { id = SoA.1011 }
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				wealth < 0
			}
		}
	}

	donate_money_to_bektashi = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_bektashi
			religion = d_bektashi

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_bektashi
				is_liege_of = d_bektashi
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_bektashi = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				piety < 1000
				wealth >= 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	expel_the_bektashi = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_bektashi
			religion = d_bektashi
			NOT = { has_character_modifier = expelled_d_bektashi }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_bektashi
						is_vassal_or_below_of = d_bektashi
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_the_bektashi_check }
			}
		}

		effect = {
			set_character_flag = expel_the_bektashi_check

			d_bektashi = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	borrow_money_haruriyyah = {
		ai_check_interval = 120

		only_playable = yes

		potential = {
			always = no # Disabled in CK2Plus
			has_dlc = "Charlemagne"
			is_title_active = d_haruriyyah
			religion = d_haruriyyah
			is_nomadic = no

			trigger_if = {
				limit = { ai = yes }

				independent = yes
				higher_real_tier_than = COUNT
			}

			NOR = {
				has_character_modifier = borrowed_from_haruriyyah
				has_character_modifier = expelled_d_haruriyyah
				government = order_government
				is_liege_of = d_haruriyyah
			}
		}

		allow = {
			d_haruriyyah = {
				holder_scope = {
					wealth >= 300
				}
			}

			piety >= 100

			custom_tooltip = {
				text = haruriyyah_loan_money_TT

				reverse_opinion = {
					who = d_haruriyyah
					value >= 25
				}
			}
		}

		effect = {
			wealth = 300
			piety = -100

			add_character_modifier = {
				name = borrowed_from_haruriyyah
				duration = -1
				inherit = yes
			}

			d_haruriyyah = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					wealth = -300
					save_event_target_as = target_grandmaster
				}
			}

			letter_event = { id = SoA.1011 }
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				wealth < 0
			}
		}
	}

	donate_money_to_haruriyyah = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Charlemagne"
			is_title_active = d_haruriyyah
			religion  = d_haruriyyah

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_haruriyyah
				is_liege_of = d_haruriyyah
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_haruriyyah = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				piety < 1000
				wealth >= 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	expel_the_haruriyyah = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Charlemagne"
			is_title_active = d_haruriyyah
			religion = d_haruriyyah
			NOT = { has_character_modifier = expelled_d_haruriyyah }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_haruriyyah
						is_vassal_or_below_of = d_haruriyyah
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_the_haruriyyah_check }
			}
		}

		effect = {
			set_character_flag = expel_the_haruriyyah_check

			d_haruriyyah = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	vassalize_knights_templar = {
		ai_check_interval = 60

		is_high_prio = yes

		only_playable = yes

		potential = {
			has_landed_title = k_jerusalem
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_templar
			religion = d_knights_templar

			NOR = {
				has_character_modifier = expelled_d_knights_templar

				reverse_has_opinion_modifier = {
					name = opinion_unfit_ruler
					who = d_knights_templar
				}

				has_alternate_start_parameter = {
					key = religion_names
					value = random
				}
			}

			d_knights_templar = {
				is_primary_holder_title = yes

				holder_scope = {
					independent = yes
					num_of_count_titles < 3
					lower_real_tier_than = KING
					ai = yes

					NOR = {
						vassal_of = ROOT
						has_truce = ROOT
						reverse_has_truce = ROOT
						has_non_aggression_pact_with = ROOT
					}
				}
			}
		}

		allow = {
			independent = yes
			NOT = { trait = excommunicated }
			wealth >= 500
			has_regent = no

			trigger_if = {
				trigger = {
					reverse_opinion = {
						who = d_knights_templar
						value = 25
					}
				}

				custom_tooltip = {
					text = vassalize_knights_templar_opinion_TT

					always = no
				}
			}

			custom_tooltip = {
				text = only_one_vassalized_holy_order_TT

				NOT = {
					any_realm_lord = {
						holy_order = yes
					}
				}
			}
		}

		effect = {
			wealth = -500

			d_knights_templar = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					wealth = 500
					save_event_target_as = target_grandmaster
					set_defacto_liege = ROOT
				}
			}

			letter_event = { id = SoA.1016 }
		}

		ai_will_do = {
			factor = 1
		}
	}

	vassalize_knights_hospitaller = {
		ai_check_interval = 60

		is_high_prio = yes

		only_playable = yes

		potential = {
			has_landed_title = k_jerusalem
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_hospitaller
			religion = d_knights_hospitaller

			NOR = {
				has_character_modifier = expelled_d_knights_hospitaller

				reverse_has_opinion_modifier = {
					name = opinion_unfit_ruler
					who = d_knights_hospitaller
				}

				has_alternate_start_parameter = {
					key = religion_names
					value = random
				}
			}

			d_knights_hospitaller = {
				is_primary_holder_title = yes

				holder_scope = {
					independent = yes
					num_of_count_titles < 3
					lower_real_tier_than = KING
					ai = yes

					NOR = {
						has_truce = ROOT
						reverse_has_truce = ROOT
						vassal_of = ROOT
						has_non_aggression_pact_with = ROOT
					}
				}
			}
		}

		allow = {
			independent = yes
			NOT = { trait = excommunicated }
			wealth >= 500
			has_regent = no

			trigger_if = {
				limit = {
					reverse_opinion = {
						who = d_knights_hospitaller
						value < 25
					}
				}

				custom_tooltip = {
					text = vassalize_knights_hospitaller_opinion_TT

					always = no
				}
			}

			custom_tooltip = {
				text = only_one_vassalized_holy_order_TT

				NOT = {
					any_realm_lord = {
						holy_order = yes
					}
				}
			}
		}

		effect = {
			wealth = -500

			d_knights_hospitaller = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					wealth = 500
					save_event_target_as = target_grandmaster
					set_defacto_liege = ROOT
				}
			}

			letter_event = { id = SoA.1016 }
		}

		ai_will_do = {
			factor = 1
		}
	}

	expel_the_holy_sepulchre = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_holy_sepulchre
			religion = d_holy_sepulchre
			NOT = { has_character_modifier = expelled_d_holy_sepulchre }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_holy_sepulchre
						is_vassal_or_below_of = d_holy_sepulchre
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_the_holy_sepulchre_check }
			}
		}

		effect = {
			set_character_flag = expel_the_holy_sepulchre_check

			d_holy_sepulchre = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_holy_sepulchre = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_holy_sepulchre
			religion = d_holy_sepulchre

			d_holy_sepulchre = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_holy_sepulchre
				is_liege_of = d_holy_sepulchre
				has_landed_title = d_holy_sepulchre
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_holy_sepulchre = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				wealth >= 1000
				piety < 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	expel_saint_anthony = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_saint_anthony
			religion = d_saint_anthony
			NOT = { has_character_modifier = expelled_d_saint_anthony }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_saint_anthony
						is_vassal_or_below_of = d_saint_anthony
					}
				}
			}

		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_saint_anthony_check }
			}
		}

		effect = {
			set_character_flag = expel_saint_anthony_check

			d_saint_anthony = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_saint_anthony = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_saint_anthony
			religion = d_saint_anthony

			d_saint_anthony = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			trigger_if = {
				limit = { ai = yes }

				wealth >= 1000
				piety < 50
				NOT = { trait = cynical }
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_saint_anthony
				is_liege_of = d_saint_anthony
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_saint_anthony = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				wealth >= 1000
				piety < 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	expel_immortals = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_immortals
			religion = d_immortals
			NOT = { has_character_modifier = expelled_d_immortals }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_immortals
						is_vassal_or_below_of = d_immortals
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_immortals_check }
			}
		}

		effect = {
			set_character_flag = expel_immortals_check

			d_immortals = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_the_immortals = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_immortals
			religion = d_immortals

			d_immortals = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_immortals
				is_liege_of = d_immortals
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_immortals = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				wealth >= 1000
				piety < 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	expel_zealots = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_zealots
			religion = d_zealots
			NOT = { has_character_modifier = expelled_d_zealots }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_zealots
						is_vassal_or_below_of = d_zealots
					}
				}
			}
		}

		allow = {
			piety > 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_zealots_check }
			}
		}

		effect = {
			set_character_flag = expel_zealots_check

			d_zealots = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_the_zealots = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_zealots
			religion = d_zealots

			d_zealots = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_zealots
				is_liege_of = d_zealots
				has_landed_title = d_zealots
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 100

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_zealots = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.1
		}
	}

	expel_sky_lords = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_sky_lords
			religion = d_sky_lords
			NOT = { has_character_modifier = expelled_d_sky_lords }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_sky_lords
						is_vassal_or_below_of = d_sky_lords
					}
				}
			}

		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_sky_lords_check }
			}
		}

		effect = {
			set_character_flag = expel_sky_lords_check

			d_sky_lords = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_sky_lords = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_sky_lords
			religion = d_sky_lords

			d_sky_lords = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_sky_lords
				is_liege_of = d_sky_lords
				has_landed_title = d_sky_lords
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}
				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_sky_lords = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.1
		}
	}

	expel_spirit_guardians = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_spirit_guardians
			religion = d_spirit_guardians
			NOT = { has_character_modifier = expelled_d_spirit_guardians }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_spirit_guardians
						is_vassal_or_below_of = d_spirit_guardians
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_spirit_guardians_check }
			}
		}

		effect = {
			set_character_flag = expel_spirit_guardians_check

			d_spirit_guardians = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_spirit_guardians = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_spirit_guardians
			religion = d_spirit_guardians

			d_spirit_guardians = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_spirit_guardians
				is_liege_of = d_spirit_guardians
				has_landed_title = d_spirit_guardians
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_spirit_guardians = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.1
		}
	}

	expel_warriors_perun = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_warriors_perun
			religion = d_warriors_perun
			NOT = { has_character_modifier = expelled_d_warriors_perun }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_warriors_perun
						is_vassal_or_below_of = d_warriors_perun
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_warriors_perun_check }
			}
		}

		effect = {
			set_character_flag = expel_warriors_perun_check

			d_warriors_perun = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_warriors_perun = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_warriors_perun
			religion = d_warriors_perun

			d_warriors_perun = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_warriors_perun
				is_liege_of = d_warriors_perun
				has_landed_title = d_warriors_perun
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 100

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_warriors_perun = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.1
		}
	}

	expel_chosen_perkunas = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_chosen_perkunas
			religion = d_chosen_perkunas
			NOT = { has_character_modifier = expelled_d_chosen_perkunas }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_chosen_perkunas
						is_vassal_or_below_of = d_chosen_perkunas
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_chosen_perkunas_check }
			}
		}

		effect = {
			set_character_flag = expel_chosen_perkunas_check

			d_chosen_perkunas = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_chosen_perkunas = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_chosen_perkunas
			religion = d_chosen_perkunas

			d_chosen_perkunas = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_chosen_perkunas
				is_liege_of = d_chosen_perkunas
				has_landed_title = d_chosen_perkunas
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_chosen_perkunas = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.1
		}
	}

	expel_sons_kaleva = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_sons_kaleva
			religion = d_sons_kaleva
			NOT = { has_character_modifier = expelled_d_sons_kaleva }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_sons_kaleva
						is_vassal_or_below_of = d_sons_kaleva
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_sons_kaleva_check }
			}
		}

		effect = {
			set_character_flag = expel_sons_kaleva_check

			d_sons_kaleva = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_sons_kaleva = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_sons_kaleva
			religion = d_sons_kaleva

			d_sons_kaleva = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_sons_kaleva
				is_liege_of = d_sons_kaleva
				has_landed_title = d_sons_kaleva
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 100

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_sons_kaleva = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.1
		}
	}

	expel_huitzilopochtli = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_huitzilopochtli
			religion = d_huitzilopochtli
			NOT = { has_character_modifier = expelled_d_huitzilopochtli }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_huitzilopochtli
						is_vassal_or_below_of = d_huitzilopochtli
					}
				}
			}

		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_huitzilopochtli_check }
			}
		}

		effect = {
			set_character_flag = expel_huitzilopochtli_check

			d_huitzilopochtli = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_huitzilopochtli = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_huitzilopochtli
			religion = d_huitzilopochtli

			d_huitzilopochtli = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_huitzilopochtli
				is_liege_of = d_huitzilopochtli
				has_landed_title = d_huitzilopochtli
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_huitzilopochtli = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				wealth >= 1000
				piety < 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	expel_knights_santiago = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_santiago
			religion = d_knights_santiago
			NOT = { has_character_modifier = expelled_d_knights_santiago }

			any_realm_province = {
				held_under_PREV = yes
				any_province_lord = {
					OR = {
						character = d_knights_santiago
						is_vassal_or_below_of = d_knights_santiago
					}
				}
			}

		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_knights_santiago_check }
			}
		}

		effect = {
			set_character_flag = expel_knights_santiago_check

			d_knights_santiago = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_knights_santiago = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_santiago
			religion = d_knights_santiago

			d_knights_santiago = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_knights_santiago
				is_liege_of = d_knights_santiago
				has_landed_title = d_knights_santiago
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 100

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_knights_santiago = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.1
		}
	}

	expel_knights_calatrava = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_calatrava
			religion = d_knights_calatrava
			NOT = { has_character_modifier = expelled_d_knights_calatrava }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_knights_calatrava
						is_vassal_or_below_of = d_knights_calatrava
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_knights_calatrava_check }
			}
		}

		effect = {
			set_character_flag = expel_knights_calatrava_check

			d_knights_calatrava = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_knights_calatrava = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_knights_calatrava
			religion = d_knights_calatrava

			d_knights_calatrava = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_knights_calatrava
				is_liege_of = d_knights_calatrava
				has_landed_title = d_knights_calatrava
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_knights_calatrava = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				wealth >= 1000
				piety < 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	expel_order_of_addai = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Sons of Abraham"
			is_title_active = d_saint_addai
			religion = d_saint_addai
			NOT = { has_character_modifier = expelled_d_saint_addai }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_saint_addai
						is_vassal_or_below_of = d_saint_addai
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_order_of_addai_check }
			}
		}

		effect = {
			set_character_flag = expel_order_of_addai_check

			d_saint_addai = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_order_of_addai = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			is_title_active = d_saint_addai
			religion = d_saint_addai

			d_saint_addai = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_saint_addai
				is_liege_of = d_saint_addai
				has_landed_title = d_saint_addai
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_saint_addai = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				wealth >= 1000
				piety < 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	expel_zun_warriors = {
		ai = no

		potential = {
			independent = yes
			higher_real_tier_than = DUKE
			has_dlc = "Charlemagne"
			is_title_active = d_zun_warriors
			religion = d_zun_warriors
			NOT = { has_character_modifier = expelled_d_zun_warriors }

			any_realm_province = {
				held_under_PREV = yes

				any_province_lord = {
					OR = {
						character = d_zun_warriors
						is_vassal_or_below_of = d_zun_warriors
					}
				}
			}
		}

		allow = {
			piety >= 1000

			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip
				NOT = { has_character_flag = expel_zun_warriors_check }
			}
		}

		effect = {
			set_character_flag = expel_zun_warriors_check

			d_zun_warriors = {
				save_event_target_as = target_holy_order

				holder_scope = {
					save_event_target_as = target_grandmaster
				}
			}

			character_event = {
				id = SoA.2990
				tooltip = expelling_holy_order_decision_tooltip_b
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	donate_money_to_zun_warriors = {
		ai_check_interval = 80

		only_playable = yes

		potential = {
			has_dlc = "Charlemagne"
			is_title_active = d_zun_warriors
			religion = d_zun_warriors

			d_zun_warriors = {
				holder_scope = {
					is_within_diplo_range = ROOT
				}
			}

			NOR = {
				government = order_government
				has_character_modifier = expelled_d_zun_warriors
				is_liege_of = d_zun_warriors
				has_landed_title = d_zun_warriors
			}
		}

		allow = {
			wealth >= 300

			custom_tooltip = {
				text = holy_order_donate_cooldown_tt
				NOT = { has_character_modifier = donate_to_holy_order_cooldown }
			}
		}

		effect = {
			wealth = -300
			piety = 150

			if = {
				limit = {
					NOT = { has_character_modifier = donated_to_holy_order }
				}

				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}

			add_character_modifier = {
				name = donate_to_holy_order_cooldown
				years = 1
				hidden = yes
			}

			d_zun_warriors = {
				show_scope_change = no

				save_event_target_as = target_holy_order

				holder_scope = {
					show_scope_change = no

					save_event_target_as = target_grandmaster
					wealth = 300
				}
			}

			letter_event = { id = SoA.1141 }
		}

		ai_will_do = {
			factor = 0.12

			trigger = {
				controls_religion = yes
				wealth >= 1000
				piety < 1000
				NOT = { has_character_modifier = ai_austerity }
			}
		}
	}

	form_st_anthony = {
		ai_check_interval = 60

		is_high_prio = yes

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			religion = miaphysite
			is_heretic = no
			NOT = { is_title_active = d_saint_anthony }

			OR = {
				# Prevent Army from being created at start
				has_global_flag = christian_crusades_unlocked
				has_global_flag = pagan_ghws_unlocked
				has_global_flag = muslim_jihads_unlocked
			}

			NOT = {
				has_alternate_start_parameter = {
					key = religion_names
					value = random
				}
			}
		}

		allow = {
			num_of_holy_sites >= 1
			religion_authority >= 0.50
			piety >= 1000
			wealth >= 500
		}
		effect = {
			piety = -1000
			wealth = -500

			narrative_event = {
				id = 39810
				tooltip = evt_39810_TT
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	form_st_addai = {
		ai_check_interval = 60

		is_high_prio = yes

		only_playable = yes

		potential = {
			has_dlc = "Sons of Abraham"
			religion = nestorian
			is_heretic = no
			NOT = { is_title_active = d_saint_addai }

			OR = {
				# Prevent Army from being created at start
				has_global_flag = christian_crusades_unlocked
				has_global_flag = pagan_ghws_unlocked
				has_global_flag = muslim_jihads_unlocked
			}

			NOT = {
				has_alternate_start_parameter = {
					key = religion_names
					value = random
				}
			}
		}

		allow = {
			num_of_holy_sites >= 1
			religion_authority >= 0.50
			piety >= 1000
			wealth >= 500
		}

		effect = {
			piety = -1000
			wealth = -500

			narrative_event = {
				id = 39811
				tooltip = evt_39811_TT
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	organize_army_light = {
		ai_check_interval = 60

		is_high_prio = yes

		only_playable = yes

		potential = {
			religion = manichaean
			is_female = no
			is_adult = yes
			prisoner = no

			OR = {
				# Prevent Army from being created at start
				has_global_flag = christian_crusades_unlocked
				has_global_flag = pagan_ghws_unlocked
				has_global_flag = muslim_jihads_unlocked
			}

			NOR = {
				has_global_flag = army_light_founded

				has_alternate_start_parameter = {
					key = religion_names
					value = random
				}
			}
		}

		allow = {
			num_of_holy_sites >= 1
			religion_authority >= 0.50
			piety >= 1000
			wealth >= 500
		}

		effect = {
			prestige = -300
			wealth = -300

			activate_title = {
				title = d_army_light
				status = yes
			}

			hidden_effect = {
				set_global_flag = army_light_founded

				create_character = {
					random_traits = yes
					religion = manichaean
					culture = ROOT
					dynasty = NONE
					female = no
					age = 34
					add_trait = skilled_tactician
				}

				new_character = {
					grant_title = d_army_light
					set_defacto_liege = ROOT
				}
			}
		}

		ai_will_do = {
			factor = 1
		}
	}
}