targeted_decisions = {
	lollard_revoke_temple = {
		is_high_prio = yes
		ai_check_interval = 12
		filter = sub_realm
		ai_target_filter = sub_realm
		only_rulers = yes
		
		from_potential = {
			is_ruler = yes
			religion = lollard
			is_not_busy_trigger = yes
		}
		potential = {
			is_ruler = yes
			holy_order = no
			vassal_of = FROM
			capital_holding = { holding_type = temple }
			OR = {
				NOT = { religion = lollard }
				trait = bad_priest_christian
				higher_tier_than = COUNT
			}
			NOR = {
				has_character_flag = lollard_revoking_titles
				any_demesne_title = { temporary = yes }
				reverse_has_truce = FROM
				has_non_aggression_pact_with = FROM
			}
		}
		allow = {
			ROOT = {
				war = no
			}
			FROM = {
				war = no
				has_regent = no
			}
		}
		effect = {
			hidden_tooltip = {
				FROM = { add_character_modifier = { name = do_not_disturb duration = 3 hidden = yes } }
				set_character_flag = lollard_revoking_titles
				letter_event = { id = Plus.2021 days = 3 }
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				FROM = {
					trait = cynical
					NOT = {
						trait = ambitious
						trait = greedy
						trait = envious
					}
				}
			}
			modifier = {
				factor = 0
				reverse_opinion = { who = FROM value = 0 }
			}
		}
	}

	messalian_castrate = {
		filter = self
		ai_target_filter = self
		ai_check_interval = 12
		potential = {
			is_female = no
			is_adult = yes
			prisoner = no
			religion = messalian
			OR = {
				trait = lunatic
				trait = possessed
				trait = depressed
			}
			NOT = {
				trait = eunuch
				trait = incapable
			}
		}
		allow = {
			OR = {
				trait = lunatic
				trait = possessed
				trait = depressed
			}
		}
		effect = {
			piety = 300
			add_trait = eunuch
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_ballless
			}
			if = {
				limit = { NOT = { religion_authority = 0.7 } }
				religion_authority = {
					modifier = apokopos
					years = 10
				}
			}
			
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.1
				always = yes
			}
			modifier = {
				factor = 10
				OR = {
					trait = zealous
					trait = lunatic
				}
			}
			modifier = {
				factor = 0
				OR = {
					trait = cynical
					trait = craven
				}
			}
		}
	}
}

decisions = {
	cathar_consolamentum = {
		ai_check_interval = 12
		potential = {
			OR = {
				religion = cathar
				religion = bogomilist
			}
			NOR = {
				trait = perfecti
				has_character_modifier = voice_of_satan
				has_character_flag = consolamentum_taken
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			piety = 0
			NOR = {
				trait = incapable
				trait = cynical
				trait = lustful
				trait = hedonist
				trait = seducer
				trait = seductress
			}
		}
		effect = {
			set_character_flag = consolamentum_taken
			add_trait = perfecti
			if = {
				limit = { NOT = { trait = zealous } }
				add_trait = zealous
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 10
				is_theocracy = yes
			}
			modifier = {
				factor = 5
				trait = zealous
			}
			modifier = {
				factor = 0.25
				OR = {
					trait = gluttonous
					trait = envious
					trait = greedy
				}
			}
			modifier = {
				factor = 0
				religion = bogomilist
				has_job_title = job_spiritual
				NOT = { trait = zealous }
				liege = {
					NOR = {
						has_law = bogomilist_church_3
						has_law = bogomilist_church_4
					}
				}
			}
			modifier = {
				factor = 0
				NOT = { age = 25 }
			}
			modifier = {
				factor = 0
				NOR = {
					trait = zealous
					trait = possessed
					trait = lunatic
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					is_theocracy = yes
				}
			}
		}
	}
	
	cathar_adoption = {
		only_playable = yes
		ai_check_interval = 12
        potential = {
			is_playable = yes
			OR = {
				religion = cathar
				religion = bogomilist
			}
			NOT = {
				any_child = {
					is_alive = yes
					NOT = { trait = bastard }
				}
			}
		}
		allow = {
			war = no
			has_regent = no
			any_realm_province = { religion = ROOT }
			OR = {
				trait = perfecti
				trait = celibate
				age = 45
				NOT = { fertility = 0.05 }
			}
		}
		effect = {
			character_event = { id = Plus.2006 tooltip = SEARCH_ADOPTED_CHILD }
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				current_heir = { dynasty = ROOT }
			}
		}
    }
	
	create_cathar_papacy = {
		is_high_prio = yes
		ai_check_interval = 24
		only_playable = yes
		potential = {
			is_playable = yes
			religion = cathar
			d_cathar = { has_holder = no }
			NOT = {
				any_demesne_title = { temporary = yes }
				has_global_flag = cathar_papacy_founded
			}
		}
		allow = {
			war = no
			has_regent = no
			independent = yes
			trait = perfecti
			piety = 1000
			higher_tier_than = DUKE
			any_realm_title = { is_holy_site = ROOT }
		}
		effect = {
			character_event = { id = Plus.2012 tooltip = CREATE_CATHAR_POPE }
			set_global_flag = cathar_papacy
		}
		ai_will_do = {
			factor = 1
		}
	}

	lollard_renounce_vows = {
		ai_check_interval = 12
		potential = {
			religion = lollard
			OR = {
				trait = monk
				trait = nun
				trait = celibate
			}
			is_adult = yes
			prisoner = no
			NOT = {
				trait = incapable
				has_character_modifier = lollard_former_monk
			}
		}
		allow = {
			piety = 10
		}
		effect = {
			piety = -50
			if = {
				limit = {
					OR = {
						trait = monk
						trait = nun
					}
				}
				add_character_modifier = {
					name = lollard_former_monk
					duration = -1
				}
			}
			if = {
				limit = { trait = monk }
				remove_trait = monk
			}
			if = {
				limit = { trait = nun }
				remove_trait = nun
			}
			if = {
				limit = { trait = celibate }
				remove_trait = celibate
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = zealous
					trait = content
					trait = humble
					trait = diligent
				}
				NOT = {
					trait = ambitious
					trait = cynical
				}
			}
		}
	}

	lollard_translate_bible = {
		is_high_prio = yes
		ai_check_interval = 12
		only_rulers = yes
		potential = {
			is_ruler = yes
			higher_tier_than = DUKE
			OR = {
				religion = lollard
				religion = waldensian
			}
			has_regent = no
			OR = {
				has_focus = focus_theology
				has_focus = focus_scholarship
			}
			NOT = {
				has_character_flag = bible_translation_begun
				has_global_flag = bible_translation_finished
			}
		}
		allow = {
			war = no
			realm_size = 100
			realm_learning = 25
			scaled_wealth = 3.0
			NOT = { trait = cynical }
		}
		effect = {
			set_character_flag = bible_translation_begun
			scaled_wealth = -3.0
			custom_tooltip = { text = BEGIN_TRANSLATING_BIBLE }
			random_list = {
				50 = {
					modifier = {
						factor = 1.1
						learning = 12
					}
					modifier = {
						factor = 1.1
						learning = 14
					}
					modifier = {
						factor = 1.2
						learning = 16
					}
					modifier = {
						factor = 1.2
						learning = 18
					}
					modifier = {
						factor = 1.2
						learning = 20
					}
					narrative_event = { id = Plus.2017 days = 300 random = 500 tooltip = BIBLE_TRANSLATION_GOOD }
				}
				50 = {
					modifier = {
						factor = 0.8
						NOT = { learning = 8 }
					}
					modifier = {
						factor = 0.8
						NOT = { learning = 6 }
					}
					modifier = {
						factor = 0.8
						NOT = { learning = 4 }
					}
					narrative_event = { id = Plus.2018 days = 300 random = 500 tooltip = BIBLE_TRANSLATION_POOR }
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					NOT = { scaled_wealth = 5.0 }
					has_character_modifier = ai_austerity
				}
			}
		}
	}

	waldensian_choose_path = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			is_adult = yes
			prisoner = no
			religion = waldensian
			NOT = {
				trait = incapable
				trait = sandaliati
				trait = novellani
				trait = doctores
				has_character_flag = wald_chose_path
			}
		}
		allow = {
			always = yes
		}
		effect = {
			set_character_flag = wald_chose_path
			character_event = { id = Plus.2031 }
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	waldensian_charity = {
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			religion = waldensian
			is_adult = yes
			is_ruler = yes
			any_realm_province = { religion = waldensian }
			NOT = { has_character_flag = voluntary_charity }
		}
		allow = {
			scaled_wealth = 1.0
			NOT = { trait = greedy }
		}
		effect = {
			set_character_flag = voluntary_charity
			if = {
				limit = { NOT = { trait = charitable } }
				add_trait = charitable
			}
			scaled_wealth = -1.0
			piety = 100
			if = {
				limit = {
					NOT = {
						any_demesne_province = {
							religion = waldensian
							NOT = { has_province_modifier = wald_charity }
						}
					}
				}
				random_realm_province = {
					limit = {
						religion = waldensian
						NOT = { has_province_modifier = wald_charity }
					}
					add_province_modifier = {
						name = wald_charity
						duration = 1000
					}
				}
			}
			if = {
				limit = {
					NOT = {
						capital_scope = {
							religion = waldensian
							NOT = { has_province_modifier = wald_charity }
						}
					}
					any_demesne_province = {
						religion = waldensian
						NOT = { has_province_modifier = wald_charity }
					}
				}
				random_demesne_province = {
					limit = {
						religion = waldensian
						NOT = { has_province_modifier = wald_charity }
					}
					add_province_modifier = {
						name = wald_charity
						duration = 1000
					}
				}
			}
			if = {
				limit = {
					capital_scope = {
						religion = waldensian
						NOT = { has_province_modifier = wald_charity }
					}
				}
				capital_scope = {
					add_province_modifier = {
						name = wald_charity
						duration = 1000
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					has_character_modifier = ai_austerity
					NOT = { scaled_wealth = 3.0 }
					piety = 50
				}
			}
		}
	}

	waldensian_hospital = {
		ai_check_interval = 12
		potential = {
			religion = waldensian
			higher_real_tier_than = DUKE
			has_focus = focus_rulership
			capital_scope = {
				NOT = { has_province_modifier = wald_hospital }
			}
		}
		allow = {
			war = no
			has_regent = no
			wealth = 500
		}
		effect = {
			wealth = -500
			piety = 100
			capital_scope = {
				if = {
					limit = { NOT = { religion = waldensian } }
					religion = waldensian
				}
				add_province_modifier = {
					name = wald_hospital
					duration = -1
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					has_character_modifier = ai_austerity
					NOT = { wealth = 1000 }
				}
			}
		}
	}

	messalian_abandon_prayers = {
		ai_check_interval = 12
		potential = {
			religion = messalian
			has_character_modifier = messalian_prayer
		}
		allow = {
			has_character_modifier = messalian_prayer
		}
		effect = {
			prestige = -50
			piety = -50
			remove_character_modifier = messalian_prayer
			clr_character_flag = driving_out_lust
			clr_character_flag = driving_out_gluttony
			clr_character_flag = driving_out_greed
			clr_character_flag = driving_out_sloth
			clr_character_flag = driving_out_wrath
			clr_character_flag = driving_out_envy
			clr_character_flag = driving_out_pride
			clr_character_flag = driving_out_cruelty
			clr_character_flag = driving_out_possession
			clr_character_flag = driving_out_lunacy
			clr_character_flag = messalian_temptation
			random = {
				chance = 25
				add_trait = depressed
			}
			add_character_modifier = {
				name = messalian_prayer_timer
				duration = 1095
				hidden = yes
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				religion = messalian
				NOT = { trait = cynical }
			}
		}
	}
	
	messalian_expel_daemon = {
		ai_check_interval = 12
		potential = {
			religion = messalian
			OR = {
				trait = lustful
				trait = hedonist
				trait = gluttonous
				trait = greedy
				trait = slothful
				trait = wroth
				trait = envious
				trait = proud
				trait = cruel
				trait = possessed
				trait = lunatic
			}
			NOT = {
				has_character_modifier = messalian_prayer
				trait = messalian_master
			}
		}
		allow = {
			piety = 50
			is_adult = yes
			prisoner = no
			is_ill = no
			in_command_trigger = no
			NOT = { trait = cynical }
			NOT = { trait = incapable }
			custom_tooltip = {
				text = NOT_STOPPED_PRAYER_LAST_3_YEARS
				hidden_tooltip = {
					NOT = { has_character_modifier = messalian_prayer_timer }
				}
			}
		}
		effect = {
			piety = -50
			add_character_modifier = {
				name = messalian_prayer
				duration = -1
			}
			character_event = { id = Plus.2041 tooltip = BEGIN_DRIVING_OUT_DAEMONS }
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 10
				trait = zealous
			}
			modifier = {
				factor = 10
				OR = {
					trait = possessed
					trait = lunatic
				}
			}
			modifier = {
				factor = 0.1
				trait = craven
			}
			modifier = {
				factor = 0.1
				trait = content
			}					
		}
	}

	messalian_choose_patron_saint = {
		only_playable = yes
		ai_check_interval = 12
		potential = {
			religion = messalian
			OR = {
				is_playable = yes
				capital_holding = { holding_type = temple }
				trait = detached_priest
				trait = martial_cleric
				trait = scholarly_theologian
				trait = mastermind_theologian
			}
			NOR = {
				has_character_modifier = patron_nestor
				has_character_modifier = patron_lucifer
				has_character_modifier = patron_addai
				has_character_modifier = patron_adelphius
			}
		}
		allow = {
			war = no
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
		}
		effect = {
			character_event = { id = Plus.2055 tooltip = choose_messalian_saint }
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 5
				trait = zealous
			}
			modifier = {
				factor = 0.5
				trait = cynical
			}
		}
	}

	messalian_become_master = {
		ai_check_interval = 12
		potential = {
			religion = messalian
			NOT = {
				trait = lustful
				trait = gluttonous
				trait = greedy
				trait = slothful
				trait = wroth
				trait = envious
				trait = proud
				trait = cruel
				trait = possessed
				trait = lunatic
				trait = cult_of_lucifer
			}
			NOT = {
				has_character_modifier = messalian_prayer
				trait = messalian_master
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			piety = 500
			religion_authority = 0.7
		}
		effect = {
			piety = -500
			religion_authority = {
				modifier = m_master
				years = 5
			}
			add_trait = messalian_master
			random_list = {
				20 = {
					modifier = {
						factor = 0
						trait = hedonist
					}
					add_trait = hedonist
				}
				10 = {
					modifier = {
						factor = 0
						trait = cruel
					}
					add_trait = cruel
				}
				10 = {
					modifier = {
						factor = 0
						trait = drunkard
					}
					add_trait = drunkard
				}
				10 = {
					modifier = {
						factor = 0
						trait = lustful
					}
					add_trait = lustful
				}
				10 = {
					modifier = {
						factor = 0
						trait = gluttonous
					}
					add_trait = gluttonous
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}

	messalian_join_cult_of_lucifer = {
		ai_check_interval = 24
		potential = {
			religion = messalian
			is_adult = yes
			prisoner = no
			NOT = {
				trait = incapable
				trait = cult_of_lucifer
				trait = messalian_master
			}
		}
		allow = {
			piety = 50
			intrigue = 10
			trait = proud
			OR = {
				has_character_modifier = patron_lucifer
				trait = zealous
				trait = paranoid
				trait = deceitful
				trait = mystic
				trait = theologian
			}
		}
		effect = {
			piety = 100
			prestige = 100
			tooltip = { add_trait = cult_of_lucifer }
			hidden_tooltip = {
				character_event = { id = Plus.2056 }
			}
	
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	organise_army_of_lucifer = {
		is_high_prio = yes
		ai_check_interval = 12
		only_rulers = yes
		potential = {
			is_ruler = yes
			higher_tier_than = count
			religion = messalian
			NOT = { is_title_active = d_army_lucifer }
		}
		allow = {
			has_regent = no
			higher_tier_than = duke
			prestige = 300
			wealth = 300
		}
		effect = {
			prestige = -300
			wealth = -300
			activate_title = { title = d_army_lucifer status = yes }
			hidden_tooltip = {
				narrative_event = { id = Plus.2057 }
				create_character = {
					random_traits = yes
					religion = ROOT
					culture = ROOT
					dynasty = NONE
					female = no
					age = 34
					trait = skilled_tactician
					trait = zealous
				}
				new_character = {
					d_army_lucifer = {
						grant_title = PREV
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					NOT = { prestige = 500 }
					NOT = { wealth = 500 }
				}
			}
		}
	}

	expel_army_of_lucifer = {
		only_independent = yes
		potential = {
			ai = no
			has_dlc = "Sons of Abraham"
			religion = messalian
			higher_tier_than = DUKE
			independent = yes
			is_title_active = d_army_lucifer
			NOT = { has_character_modifier = expelled_d_army_lucifer }		
			any_realm_province = {
				any_province_lord = {
					d_army_lucifer = {
						holder_scope = {
							OR = {
								character = PREVPREV
								is_vassal_or_below = PREVPREV
							}
						}
					}
				}
			}
		}
		allow = {
			piety = 1000
		}		
		effect = {
			set_character_flag = expel_army_of_lucifer_check
			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip_b
				hidden_tooltip = {
					character_event = { id = SoA.2990 }
				}
			}			
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	donate_money_to_army_of_lucifer = {
		ai_check_interval = 60
		potential = {
			has_dlc = "Sons of Abraham"
			religion = messalian
			is_title_active = d_army_lucifer
			NOR = { 
				has_character_modifier = expelled_d_army_lucifer 
				has_character_modifier = donated_to_holy_order
				has_landed_title = d_army_lucifer
			}
			d_army_lucifer = {
				holder_scope = {
					liege = {
						NOT = { character = ROOT }
					}
				}
			}
		}
		allow = {
			wealth = 300
		}
		effect = {
			wealth = -300
			piety = 300
			if = {
				limit = { 
					NOT = { has_character_modifier = donated_to_holy_order }
				}
				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}
			hidden_tooltip = {
				d_army_lucifer = {
					holder_scope = {
						character_event = {
							id = Plus.2058
						}
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = cynical
					trait = greedy
					piety = 1000
					NOT = { wealth = 1000 }
				}
			}
			modifier = {
				factor = 10
				trait = zealous
			}
			modifier = {
				factor = 10
				NOT = { piety = 100 }
			}
			modifier = {
				factor = 0.12 # Slow it down
			}
			modifier = {
				factor = 0
				has_character_modifier = ai_austerity
			}
		}
	}

	organize_bogomilist_church = {
		is_high_prio = yes
		ai_check_interval = 12
		only_rulers = yes
		
		potential = {
			religion = bogomilist
			is_ruler = yes
			NOR = {
				trait = incapable
				has_law = bogomilist_church_2
				has_law = bogomilist_church_3
				has_law = bogomilist_church_4
				d_bogomilist = { has_title_flag = bogomilist_organized }
				is_title_active = d_bogomilist
			}
		}
		allow = {
			war = no
			has_regent = no
			independent = yes
			num_of_holy_sites = 1
			has_law = bogomilist_church_1
			trait = perfecti
			higher_tier_than = DUKE
			piety = 500
		}
		effect = {
			d_bogomilist = { set_title_flag = bogomilist_organized }
			piety = -500
			religion_authority = { modifier = bogomilism_organized }
			primary_title = { add_law = bogomilist_church_2 }
			any_realm_province = {
				limit = {
					owner = { character = ROOT }
					religion = bogomilist
					NOT = { has_province_modifier = religious_unrest }
				}
				random_list = {
					50 = {
						add_province_modifier = {
							name = religious_unrest
							duration = 730
						}
					}
					25 = {
						modifier = {
							factor = 0
							ROOT = { is_heretic = yes }
						}
						become_heretic = yes
						add_province_modifier = {
							name = religious_unrest
							duration = 730
						}
					}
					25 = {
						modifier = {
							factor = 0
							ROOT = { is_heretic = no }
						}
						abandon_heresy = yes
						add_province_modifier = {
							name = religious_unrest
							duration = 730
						}
					}
					125 = {}
				}
			}
			hidden_tooltip = {
				narrative_event = { id = Plus.2130 }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	begin_formalize_bogomilist_church = {
		is_high_prio = yes
		ai_check_interval = 12
		only_rulers = yes
		
		potential = {
			religion = bogomilist
			is_ruler = yes
			NOR = {
				trait = incapable
				has_law = bogomilist_church_0
				has_law = bogomilist_church_1
				has_law = bogomilist_church_3
				has_law = bogomilist_church_4
				has_character_modifier = formalizing_bogomilist
				is_title_active = d_bogomilist
			}
			d_bogomilist = { has_title_flag = bogomilist_organized }
		}
		allow = {
			war = no
			has_regent = no
			independent = yes
			num_of_holy_sites = 1
			has_law = bogomilist_church_2
			trait = perfecti
			higher_tier_than = DUKE
			custom_tooltip = {
				text = BOGO_ORGANIZED_TEN_YEARS
				hidden_tooltip = {
					d_bogomilist = { had_title_flag = { flag = bogomilist_organized days = 3650 } }
				}
			}
		}
		effect = {
			add_character_modifier = {
				name = formalizing_bogomilist
				duration = -1
				inherit = yes
			}
			hidden_tooltip = {
				character_event = { id = Plus.2112 }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	formalize_bogomilist_church = {
		is_high_prio = yes
		ai_check_interval = 12
		only_rulers = yes
		
		potential = {
			religion = bogomilist
			is_ruler = yes
			NOR = {
				trait = incapable
				has_law = bogomilist_church_0
				has_law = bogomilist_church_1
				has_law = bogomilist_church_3
				has_law = bogomilist_church_4
				is_title_active = d_bogomilist
			}
			d_bogomilist = {
				has_title_flag = bogomilist_organized
				NOT = { has_title_flag = bogomilist_formalized }
				check_variable = { which = "bogomil_formalization" value = 0.5 }
			}
		}
		allow = {
			war = no
			has_regent = no
			independent = yes
			num_of_holy_sites = 1
			has_law = bogomilist_church_2
			piety = 500
			higher_tier_than = DUKE
			trait = perfecti
			has_character_modifier = formalizing_bogomilist
			custom_tooltip = {
				text = BOGO_READY_TO_FORMALIZE
				d_bogomilist = { check_variable = { which = "bogomil_formalization" value = 4 } }
			}
		}
		effect = {
			d_bogomilist = { set_title_flag = bogomilist_formalized }
			piety = -500
			religion_authority = { modifier = bogomilism_formalized }
			primary_title = { add_law = bogomilist_church_3 }
			hidden_tooltip = {
				remove_character_modifier = formalizing_bogomilist
				narrative_event = { id = Plus.2132 }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	force_formalize_bogomilist_church = {
		is_high_prio = no
		ai_check_interval = 12
		only_rulers = yes
		
		potential = {
			religion = bogomilist
			is_ruler = yes
			NOR = {
				trait = incapable
				has_law = bogomilist_church_0
				has_law = bogomilist_church_1
				has_law = bogomilist_church_3
				has_law = bogomilist_church_4
				is_title_active = d_bogomilist
			}
			d_bogomilist = {
				has_title_flag = bogomilist_organized
				NOT = { has_title_flag = bogomilist_formalized }
				check_variable = { which = "bogomil_formalization" value = 0.5 }
			}
		}
		allow = {
			war = no
			has_regent = no
			independent = yes
			num_of_holy_sites = 1
			has_law = bogomilist_church_2
			piety = 500
			higher_tier_than = DUKE
			trait = perfecti
			NOT = {
				custom_tooltip = {
					text = BOGO_READY_TO_FORMALIZE
					d_bogomilist = { check_variable = { which = "bogomil_formalization" value = 4 } }
				}
			}
		}
		effect = {
			d_bogomilist = { set_title_flag = bogomilist_formalized }
			piety = -500
			religion_authority = { modifier = bogomilism_formalized }
			primary_title = { add_law = bogomilist_church_3 }
			any_realm_province = {
				limit = {
					owner = { character = ROOT }
					religion = bogomilist
					NOT = { has_province_modifier = religious_unrest }
				}
				random_list = {
					50 = {
						add_province_modifier = {
							name = religious_unrest
							duration = 1095
						}
					}
					50 = {
						modifier = {
							factor = 0
							ROOT = { is_heretic = yes }
						}
						become_heretic = yes
						add_province_modifier = {
							name = religious_unrest
							duration = 1095
						}
					}
					50 = {
						modifier = {
							factor = 0
							ROOT = { is_heretic = no }
						}
						abandon_heresy = yes
						add_province_modifier = {
							name = religious_unrest
							duration = 1095
						}
					}
					100 = {}
				}
			}
			hidden_tooltip = {
				narrative_event = { id = Plus.2131 }
			}
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	create_bogomilist_patriarch = {
		is_high_prio = yes
		ai_check_interval = 12
		only_rulers = yes
		
		potential = {
			religion = bogomilist
			is_ruler = yes
			NOT = { is_title_active = d_bogomilist }
		}
		allow = {
			war = no
			has_regent = no
			independent = yes			
			higher_tier_than = DUKE
			has_law = bogomilist_church_3		
			wealth = 500
			piety = 1000
			prestige = 1000
		}
		effect = {
			piety = -1000
			prestige = -1000
			wealth = -500
			if = {
				limit = { is_heretic = yes }
				set_parent_religion = { religion = bogomilist parent = 0 }
			}
			primary_title = { add_law = bogomilist_church_4 }
			activate_title = { title = d_bogomilist status = yes }
			hidden_tooltip = {
				character_event = { id = Plus.2133 }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}	

	church_of_st_bogomil = {
		is_high_prio = yes
		ai_check_interval = 12
		only_rulers = yes
		
		potential = {
			religion = bogomilist
			is_ruler = yes
			OR = {
				has_law = bogomilist_church_2
				has_law = bogomilist_church_3
				has_law = bogomilist_church_4
			}
			499 = {
				NOT = { has_province_flag = church_of_st_bogomil_built }
				NOT = { has_province_modifier = building_st_bogomil }
			}
		}
		allow = {
			war = no
			has_regent = no
			completely_controls = c_tyrnovo
			499 = {
				religion = ROOT
				num_of_empty_holdings = 1
			}
			OR = {
				has_law = bogomilist_church_3
				has_law = bogomilist_church_4
			}
			wealth = 1000
		}
		effect = {
			499 = {
				hidden_tooltip = {
					province_event = { id = Plus.2135 } #begin construction
					province_event = { id = Plus.2136 days = 1460 random = 50 } #finish construction
				}
				add_province_modifier = {
					name = building_st_bogomil
					duration = -1
				}
			}
			wealth = -1000
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	bogomilist_quit_theocracy = {
		is_high_prio = yes
		ai_check_interval = 12
		icon_religion = bogomilist
		only_rulers = yes
		
		potential = {
			ai = yes
			religion = bogomilist
			government = theocracy_government
			is_ruler = yes
			NOT = { capital_holding = { holding_type = temple } }
			d_bogomilist = { NOT = { has_title_flag = bogomilist_formalized } }
		}
		allow = {
			war = no
			has_regent = no
		}
		effect = {
			if = {
				limit = {
					trait = perfecti
					independent = no
				}
				piety = 25
				liege = {
					ROOT = {
						any_demesne_title = {
							limit = { is_theocracy = yes }
							grant_title = PREV
						}
					}
				}
			}
			if = {
				limit = {
					OR = {
						NOT = { trait = perfecti }
						independent = yes
					}
				}
				set_government_type = bogomilist_government
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = cynical
					trait = bad_priest_christian
				}
			}
		}
	}
	
	bogomilist_join_theocracy = {
		is_high_prio = yes
		ai_check_interval = 12
		icon_religion = bogomilist
		only_rulers = yes
		
		potential = {
			ai = yes
			religion = bogomilist
			NOT = { government = theocracy_government }
			is_ruler = yes
			is_feudal = yes
			d_bogomilist = { has_title_flag = bogomilist_formalized }
		}
		allow = {
			war = no
			has_regent = no
		}
		effect = {
			set_government_type = theocracy_government
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 10
				OR = {
					trait = perfecti
					trait = zealous
				}
			}
			modifier = {
				factor = 0
				OR = {
					trait = cynical
					trait = ambitious
					independent = yes
				}
			}
			modifier = {
				factor = 0
				NOR = {
					trait = perfecti
					trait = zealous
					trait = humble
					trait = content
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
				}
			}
			modifier = {
				factor = 0.1
				higher_real_tier_than = COUNT
			}
			modifier = {
				factor = 0.1
				higher_real_tier_than = DUKE
			}
			modifier = {
				factor = 0.1
				tier = DUKE
				num_of_duke_titles = 2
			}
			modifier = {
				factor = 0
				higher_real_tier_than = KING
			}
		}
	}
	
	organise_knights_of_saint_mark = {
		is_high_prio = yes
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			is_ruler = yes
			higher_tier_than = count
			OR = {
				religion = miaphysite
				religion = monophysite
			}
			is_heretic = no
			NOT = { is_title_active = d_knights_saint_mark }
		}
		allow = {
			war = no
			completely_controls = d_alexandria
			has_regent = no
			higher_tier_than = duke
			piety = 500
			wealth = 250
		}
		effect = {
			piety = -500
			wealth = -250
			activate_title = { title = d_knights_saint_mark status = yes }
			hidden_tooltip = {
				narrative_event = { id = Plus.2064 }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}	

	expel_knights_of_saint_mark = {
		only_independent = yes
		potential = {
			ai = no
			has_dlc = "Sons of Abraham"
			OR = {
				religion = miaphysite
				religion = monophysite
			}
			is_heretic = no
			higher_tier_than = DUKE
			independent = yes
			is_title_active = d_knights_saint_mark
			NOT = { has_character_modifier = expelled_d_knights_saint_mark }		
			any_realm_province = {
				any_province_lord = {
					d_knights_saint_mark = {
						holder_scope = {
							OR = {
								character = PREVPREV
								is_vassal_or_below = PREVPREV
							}
						}
					}
				}
			}
		}
		allow = {
			piety = 1000
		}		
		effect = {
			set_character_flag = expel_knights_of_saint_mark_check
			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip_b
				hidden_tooltip = {
					character_event = { id = SoA.2990 }
				}
			}			
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	donate_money_to_knights_of_saint_mark = {
		ai_check_interval = 60
		potential = {
			has_dlc = "Sons of Abraham"
			OR = {
				religion = miaphysite
				religion = monophysite
			}
			is_heretic = no
			is_title_active = d_knights_saint_mark
			NOR = { 
				has_character_modifier = expelled_d_knights_saint_mark 
				has_character_modifier = donated_to_holy_order
				has_landed_title = d_knights_saint_mark
			}
			d_knights_saint_mark = {
				holder_scope = {
					liege = {
						NOT = { character = ROOT }
					}
				}
			}
		}
		allow = {
			wealth = 300
		}
		effect = {
			wealth = -300
			piety = 300
			if = {
				limit = { 
					NOT = { has_character_modifier = donated_to_holy_order }
				}
				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}
			hidden_tooltip = {
				d_knights_saint_mark = {
					holder_scope = {
						character_event = {
							id = Plus.2058
						}
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = cynical
					trait = greedy
					piety = 1000
					NOT = { wealth = 1000 }
				}
			}
			modifier = {
				factor = 10
				trait = zealous
			}
			modifier = {
				factor = 10
				NOT = { piety = 100 }
			}
			modifier = {
				factor = 0.12 # Slow it down
			}
			modifier = {
				factor = 0
				has_character_modifier = ai_austerity
			}
		}
	}

	expel_order_of_saint_blaise = {
		only_independent = yes
		potential = {
			ai = no
			has_dlc = "Sons of Abraham"
			OR = {
				religion = apostolic
				religion = paulician
				religion = tondrakian
			}
			is_heretic = no
			higher_tier_than = DUKE
			independent = yes
			is_title_active = d_saint_blaise
			NOT = { has_character_modifier = expelled_d_saint_blaise }		
			any_realm_province = {
				any_province_lord = {
					d_saint_blaise = {
						holder_scope = {
							OR = {
								character = PREVPREV
								is_vassal_or_below = PREVPREV
							}
						}
					}
				}
			}
		}
		allow = {
			piety = 1000
		}		
		effect = {
			set_character_flag = expel_order_of_saint_blaise_check
			custom_tooltip = {
				text = expelling_holy_order_decision_tooltip_b
				hidden_tooltip = {
					character_event = { id = SoA.2990 }
				}
			}			
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	donate_money_to_order_of_saint_blaise = {
		ai_check_interval = 60
		potential = {
			has_dlc = "Sons of Abraham"
			OR = {
				religion = apostolic
				religion = paulician
				religion = tondrakian
			}
			is_heretic = no
			is_title_active = d_saint_blaise
			NOR = { 
				has_character_modifier = expelled_d_saint_blaise 
				has_character_modifier = donated_to_holy_order
				has_landed_title = d_saint_blaise
			}
			d_saint_blaise = {
				holder_scope = {
					liege = {
						NOT = { character = ROOT }
					}
				}
			}
		}
		allow = {
			wealth = 300
		}
		effect = {
			wealth = -300
			piety = 300
			if = {
				limit = { 
					NOT = { has_character_modifier = donated_to_holy_order }
				}
				add_character_modifier = {
					name = donated_to_holy_order
					duration = -1
				}
			}
			hidden_tooltip = {
				d_saint_blaise = {
					holder_scope = {
						character_event = {
							id = Plus.2058
						}
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = cynical
					trait = greedy
					piety = 1000
					NOT = { wealth = 1000 }
				}
			}
			modifier = {
				factor = 10
				trait = zealous
			}
			modifier = {
				factor = 10
				NOT = { piety = 100 }
			}
			modifier = {
				factor = 0.12 # Slow it down
			}
			modifier = {
				factor = 0
				has_character_modifier = ai_austerity
			}
		}
	}
	
	miaphysite_desert_father = {
		ai_check_interval = 12
		potential = {
			is_adult = yes
			OR = {
				religion = miaphysite
				religion = monophysite
			}
			NOR = {
				rightful_religious_head = ROOT
				trait = desert_father
				trait = desert_mother
				trait = monk
				trait = nun
			}
			controls_religion = no
			is_nomadic = no
		}
		allow = {
			war = no
			is_ill = no
			prisoner = no
			is_pregnant = no
			NOR = {
				trait = ambitious
				trait = proud
				trait = cynical
				trait = incapable
				trait = infirm
				any_liege = { war = yes }
			}
		}
		effect = {
			any_spouse = { remove_spouse = ROOT }
			set_character_flag = is_desert_mother_father
			add_trait = chaste
			if = {
				limit = { is_female = no }
				change_learning = 1
				add_trait = desert_father
				set_character_flag = title_desert_father
				set_special_character_title = DESERT_FATHER_TITLE
			}
			if = {
				limit = { is_female = yes }
				change_learning = 1
				add_trait = desert_mother
				set_character_flag = title_desert_mother
				set_special_character_title = DESERT_MOTHER_TITLE
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.5
				always = yes
			}
			modifier = {
				factor = 10
				has_character_modifier = voice_of_jesus
			}
			modifier = {
				factor = 3
				trait = zealous
			}
			modifier = {
				factor = 0.5
				trait = detached_priest
			}
			modifier = {
				factor = 2
				trait = scholarly_theologian
			}
			modifier = {
				factor = 3
				trait = mastermind_theologian
			}
			modifier = {
				factor = 0.5
				trait = proud
			}
			modifier = {
				factor = 0.5
				trait = slothful
			}
			modifier = {
				factor = 1.5
				trait = humble
			}
			modifier = {
				factor = 1.5
				trait = content
			}
			modifier = {
				factor = 0.25
				OR = {
					father_even_if_dead = { higher_tier_than = COUNT }
					mother_even_if_dead = { higher_tier_than = COUNT }
				}
			}
			modifier = {
				factor = 0
				OR = {
					is_theocracy = yes
					is_councillor = yes
					trait = stressed
					trait = depressed
					trait = hedonist
					trait = sympathy_islam
					trait = sympathy_pagans
					trait = sympathy_zoroastrianism
					trait = sympathy_judaism
					trait = sympathy_indian
					any_liege = { holy_order = yes }
					any_liege = { mercenary = yes }
					any_spouse = {
						trait = pregnant
						father_of_unborn = { character = ROOT }
					}
					liege = {
						ai = no
						OR = {
							dynasty = ROOT
							is_close_relative = ROOT
						}
					}
					has_character_modifier = voice_of_satan
					has_character_modifier = planning_claimant_adventure
					has_character_flag = claimant_adventurer					
				}
			}
			modifier = {
				factor = 0
				NOR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
					AND = {
						trait = zealous
						trait = humble
					}
				}
			}
			modifier = {
				factor = 0.5
				NOR = {
					trait = detached_priest
					trait = martial_cleric
					trait = scholarly_theologian
					trait = mastermind_theologian
				}
			}
			modifier = {
				factor = 0
				any_heir_title = { always = yes }
				NAND = {
					calc_true_if = {
						amount = 2
						trait = zealous
						trait = humble
						trait = content
						trait = possessed
						has_character_modifier = voice_of_jesus
					}
					NOR = {
						trait = envious
						trait = greedy
					}
				}
			}
			modifier = {
				factor = 0
				any_pretender_title = { always = yes }
				NAND = {
					OR = {
						trait = zealous
						trait = humble
						trait = content
						trait = possessed
					}
					NOR = {
						trait = envious
						trait = greedy
					}
				}
			}
			modifier = {
				factor = 0
				is_married = yes
				NOR = {
					trait = zealous
					trait = lunatic
					trait = possessed
					has_called_crusade = yes
					NOT = { any_spouse = { reverse_opinion = { who = ROOT value = 0 } } }
				}
			}
		}
	}

	miaphysite_embrace_alexandrine = {
		only_rulers = yes
		ai_check_interval = 60
		potential = {
			is_ruler = yes
			learning = 8
			OR = {
				religion = miaphysite
				religion = monophysite
				religion = apostolic
				religion = paulician
				religion = nestorian
				religion = monothelite
			}
			NOR = {
				trait = alexandrine
				trait = antiochene
			}
		}		
		allow = {
			has_regent = no
			piety = 50
			NOT = { trait = zealous }
		}		
		effect = {
			if = {
				limit = {
					num_of_count_titles = 1
					demesne_size = 1
				}
				economy_techpoints = 25
				military_techpoints = 25
			}
			custom_tooltip = {
				text = ALEXANDRINE_TOOLTIP
				hidden_tooltip = { add_trait = alexandrine }
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.3
				always = yes
			}
			modifier = {
				factor = 10
				trait = cynical
			}
			modifier = {
				factor = 2
				learning = 10
			}
			modifier = {
				factor = 2
				learning = 12
			}
			modifier = {
				factor = 2
				learning = 14
			}
			modifier = {
				factor = 2
				learning = 16
			}
			modifier = {
				factor = 2
				learning = 18
			}
			modifier = {
				factor = 1.5
				liege = { trait = alexandrine }
			}
		}
	}

	miaphysite_embrace_antiochene = {
		only_rulers = yes
		ai_check_interval = 60
		potential = {	
			is_ruler = yes
			learning = 8
			OR = {
				religion = miaphysite
				religion = monophysite
				religion = apostolic
				religion = paulician
				religion = nestorian
				religion = monothelite
			}
			NOR = {
				trait = alexandrine
				trait = antiochene
			}
		}
		
		allow = {
			has_regent = no
			piety = 50
			NOT = { trait = cynical }
		}
		
		effect = {
			piety = 100
			if = {
				limit = {
					num_of_count_titles = 1
					demesne_size = 1
				}
				culture_techpoints = 25
			}
			custom_tooltip = {
				text = ANTIOCHIAN_TOOLTIP
				hidden_tooltip = { add_trait = antiochene }
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.3
				always = yes
			}
			modifier = {
				factor = 10
				trait = zealous
			}
			modifier = {
				factor = 2
				learning = 10
			}
			modifier = {
				factor = 2
				learning = 12
			}
			modifier = {
				factor = 2
				learning = 14
			}
			modifier = {
				factor = 2
				learning = 16
			}
			modifier = {
				factor = 2
				learning = 18
			}
			modifier = {
				factor = 1.5
				liege = { trait = antiochene }
			}
		}
	}
}

