namespace = Plus

#reserved: Plus.2100 to Plus.2199

#######################################
# ORTHODOX HERESY EVENTS
# Adapted from Heretic Pride by Rylock
#######################################

### ICONOCLAST EVENTS

# Iconoclast ruler has an Orthodox province with acheiropoieta
character_event = {
	id = Plus.2100
	title = EVTNAME_Plus_2100
	desc = EVTDESC_Plus_2100
	picture = GFX_evt_icon
	
	only_playable = yes
	religion = iconoclast
	min_age = 16
	capable_only = yes
	prisoner = no
	war = no
	
	trigger = {
		controls_religion = no
		NOT = { rightful_religious_head = ROOT }
		d_iconoclast = { has_holder = yes }
		any_demesne_province = {
			OR = {
				religion = orthodox
				religion = chalcedonian
			}
			NOT = { has_province_flag = acheiropoieta_destroyed }
			NOT = { has_province_modifier = iconoclast_blowback }
		}
		OR = {
			NOT = { has_character_flag = acheiropoieta }
			had_character_flag = { flag = acheiropoieta days = 1825 }
		}
	}
	
	mean_time_to_happen = {
		years = 75
		modifier = {
			factor = 0.5
			trait = zealous
		}
		modifier = {
			factor = 2.0
			trait = cynical
		}
		modifier = {
			factor = 0.5
			trait = iconoclast_trait
		}
	}

	immediate = {
		set_character_flag = acheiropoieta
		random_demesne_province = {
			limit = {
				OR = {
					religion = orthodox
					religion = chalcedonian
				}
				NOT = { has_province_flag = acheiropoieta_destroyed }
				NOT = { has_province_modifier = iconoclast_blowback }
			}
			save_event_target_as = acheiropoieta_province
		}
		d_iconoclast = {
			holder_scope = {
				save_event_target_as = iconoclast_patriarch
			}
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2100 #Destroy it
		ai_chance = {
			factor = 75
			modifier = {
				factor = 2
				trait = zealous
			}
			modifier = {
				factor = 2
				trait = iconoclast_trait
			}
			modifier = {
				factor = 1.5
				trait = diligent
			}
			modifier = {
				factor = 1.5
				trait = wroth
			}
		}
		piety = 100
		if = {
			limit = { NOT = { trait = iconoclast_trait } }
			add_trait = iconoclast_trait
		}
		event_target:iconoclast_patriarch = {
			opinion = { who = ROOT modifier = opinion_pleased years = 5 }
		}
		event_target:acheiropoieta_province = {
			set_province_flag = acheiropoieta_destroyed
			add_province_modifier = {
				name = iconoclast_blowback
				duration = 3650
			}
			any_neighbor_province = {
				limit = {
					OR = {
						religion = orthodox
						religion = chalcedonian
					}
					NOT = { has_province_modifier = iconoclast_blowback }
				}
				add_province_modifier = {
					name = iconoclast_blowback
					duration = 1825
				}
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_2100 #Leave it be
		ai_chance = {
			factor = 25
			modifier = {
				factor = 0
				NOT = { piety = 0 }
				NOT = { trait = cynical }
			}
			modifier = {
				factor = 3
				trait = cynical
			}
			modifier = {
				factor = 2
				trait = charitable
			}
			modifier = {
				factor = 1.5
				trait = slothful
			}
			modifier = {
				factor = 1.5
				trait = patient
			}
		}
		piety = -50
		event_target:iconoclast_patriarch = {
			opinion = { who = ROOT modifier = opinion_disappointed multiplier = 2 years = 5 }
		}
		if = {
			limit = { trait = iconoclast_trait }
			remove_trait = iconoclast_trait
		}
	}
	option = {
		name = EVTOPTC_Plus_2100 #Keep it for myself
		trigger = { trait = greedy }
		ai_chance = {
			factor = 50
			modifier = {
				factor = 1.5
				intrigue = 10
			}
			modifier = {
				factor = 1.5
				trait = proud
			}
			modifier = {
				factor = 1.5
				trait = ambitious
			}
			modifier = {
				factor = 0.5
				trait = temperate
			}
			modifier = {
				factor = 0.5
				trait = humble
			}
			modifier = {
				factor = 0.5
				trait = content
			}
		}
		tooltip_info = greedy
		prestige = 25
		piety = 25
		hidden_tooltip = {
			event_target:acheiropoieta_province = { set_province_flag = acheiropoieta_destroyed }
			character_event = { id = Plus.2101 days = 1825 random = 3650 } #Chance of going crazy
		}
	}
}

# Iconoclast ruler who kept the acheiropoieta may go crazy
character_event = {
	id = Plus.2101
	desc = EVTDESC_Plus_2101
	picture = GFX_evt_icon

	is_triggered_only = yes
	
	only_rulers = yes
	religion = iconoclast
	prisoner = no
	
	trigger = {
		NOR = {
			trait = lunatic
			trait = possessed
			trait = incapable
		}
	}

	option = {
		name = EVTOPTA_Plus_2101
		random = {
			chance = 50
			add_trait = possessed
		}
		piety = -100
		if = {
			limit = { higher_tier_than = BARON }
			religion_authority = {
				modifier = ruler_converted_from
			}
		}
		abandon_heresy = yes
		set_character_flag = converted_religion
		if = {
			limit = { higher_tier_than = BARON }
			hidden_tooltip = {
				religion_authority = {
					modifier = ruler_converted_to
				}
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_2101
		random_list = {
			50 = { add_trait = lunatic }
			25 = {
				modifier = {
					factor = 0
					trait = zealous
				}
				modifier = {
					factor = 2
					trait = cynical
				}
				add_trait = zealous
			}
			25 = {
				modifier = {
					factor = 0
					trait = paranoid
				}
				modifier = {
					factor = 2
					trait = trusting
				}
				add_trait = paranoid
			}
			50 = {}
		}
	}
}

# Constantine's Return
narrative_event = {
	id = Plus.2102
	title = EVTNAME_Plus_2102
	desc = EVTDESC_Plus_2102
	picture = GFX_evt_icon
	border = GFX_event_narrative_frame_religion
	
	major = yes
	
	only_independent = yes
	only_playable = yes
	religion = chalcedonian
	min_age = 16
	capable_only = yes
	prisoner = no
	war = yes

	trigger = {
		has_landed_title = e_byzantium
		any_war = {
			OR = {
				using_cb = holy_war
				using_cb = crusade
				using_cb = invasion
				using_cb = tribal_invasion
				using_cb = manifest_destiny_invasion
			}
			OR = {
				attacker = {
					character = ROOT
					NOT = { war_score = -50 }
				}
				defender = {
					character = ROOT
					war_score = 50
				}
			}
		}
		NOR = {
			has_global_flag = constantines_return
			has_character_flag = renounced_iconoclasm
			has_character_flag = converted_religion
		}
	}
	
	major_trigger = {
		OR = {
			has_landed_title = e_byzantium
			any_liege = { has_landed_title = e_byzantium }
		}
	}
	
	mean_time_to_happen = {
		days = 3
	}

	immediate = {
		set_global_flag = constantines_return
	}
	
	option = {
		name = EVTOPTA_Plus_2102 #End the worship of icons
		trigger = { has_landed_title = e_byzantium }
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				trait = zealous
			}
			modifier = {
				factor = 2
				trait = cynical
			}
			modifier = {
				factor = 0.75
				year = 950
			}
			modifier = {
				factor = 0.75
				year = 1000
			}
			modifier = {
				factor = 0.5
				year = 1100
			}
		}
		set_character_flag = renounced_iconoclasm
		set_character_flag = converted_religion
		if = {
			limit = { higher_tier_than = BARON }
			religion_authority = {
				modifier = ruler_converted_from
			}
		}
		religion = iconoclast
		if = {
			limit = { higher_tier_than = BARON }
			hidden_tooltip = {
				religion_authority = {
					modifier = ruler_converted_to
				}
			}
		}
		add_trait = zealous
		if = {
			limit = { NOT = { is_title_active = d_iconoclast } }
			activate_title = { title = d_iconoclast status = yes }
		}
		hidden_tooltip = {
			if = {
				limit = {
					any_vassal = { has_landed_title = d_pentarch_constantinople }
				}
				d_pentarch_constantinople = {
					holder_scope = {
						d_iconoclast = {
							grant_title = PREV
						}
						unsafe_religion = iconoclast  # Use this effect with care
						set_defacto_liege = ROOT
						pf_liege_change_effect = yes
					}
				}
			}
			any_realm_province = {
				if = {
					limit = { religion = iconoclast }
					add_province_modifier = {
						name = appeased_religious
						months = 60
					}
				}
			}
			any_realm_character = {
				limit = {
					NOT = { character = ROOT }
					NOT = { has_landed_title = d_iconoclast }
				}
				character_event = { id = Plus.2103 days = 1 }
			}
		}
		capital_scope = {
			ROOT = {
				spawn_unit = {
					province = PREV
					home = PREV
					owner = THIS
					troops = {
						light_infantry = { 1426 1426 }
						heavy_infantry = { 275 275 }
						archers = { 425 425 }
					}
					attrition = 1.0
					maintenance_multiplier = 0
					cannot_inherit = yes
				}
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_2102 #That is not why we are losing
		trigger = { has_landed_title = e_byzantium }
		ai_chance = {
			factor = 70
		}
		piety = -100
		prestige = -250
		if = {
			limit = { trait = strong_basileus }
			remove_trait = strong_basileus
			add_trait = weak_basileus
		}
	}
	option = {
		name = EVTOPTC_Plus_2102 #That does not bode well...
		trigger = {
			NOT = { has_landed_title = e_byzantium }
		}
	}
}

# Byzantine subjects respond to the emperor's embracing of iconoclasm heresy
character_event = {
	id = Plus.2103
	desc = EVTDESC_Plus_2103
	picture = GFX_evt_icon
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	prisoner = no
	
	option = {
		name = EVTOPTA_Plus_2103 #Agree
		trigger = {
			religion_group = christian
			NOT = { religion = iconoclast }
			can_change_religion = yes
		}
		ai_chance = {
			factor = 3
			modifier = {
				factor = 2
				trait = cynical
			}
			modifier = {
				factor = 0.1
				NOT = { religion = orthodox }
				NOT = { religion = chalcedonian }
			}
		}
		if = {
			limit = { higher_tier_than = BARON }
			religion_authority = {
				modifier = ruler_converted_from
			}
		}
		religion = iconoclast
		set_character_flag = converted_religion	
		if = {
			limit = { higher_tier_than = BARON }
			hidden_tooltip = {
				religion_authority = {
					modifier = ruler_converted_to
				}
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_2103 #Refuse
		trigger = {
			religion_group = christian
			NOT = { religion = iconoclast }
			can_change_religion = yes
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 10
				trait = zealous
			}
			modifier = {
				factor = 3
				OR = {
					is_priest = yes
					capital_holding = { holding_type = temple }
				}
			}
		}
	}
	option = {
		name = EVTOPTC_Plus_2103
		trigger = { religion = iconoclast }
	}
	option = {
		name = EVTOPTB_Plus_2103
		trigger = {
			religion_group = christian
			NOT = { religion = iconoclast }
			can_change_religion = no
		}
	}
	option = {
		name = EVTOPTD_Plus_2103
		trigger = { NOT = { religion_group = christian } }
	}
}

### PAULICIAN EVENTS

# Paulicians spread in the Byzantine Empire due to effective patriarch
narrative_event = {
	id = Plus.2105
	title = EVTNAME_Plus_2105
	desc = EVTDESC_Plus_2105
	picture = GFX_evt_heretic
	border = GFX_event_narrative_frame_religion

	major = yes
	
	religion = paulician
	only_rulers = yes
	only_playable = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	war = no
	
	trigger = {
		has_landed_title = d_paulician
		year = 800
		calc_true_if = {
			amount = 2
			diplomacy = 10
			diplomacy = 15
			trait = zealous
		}
		e_byzantium = {
			holder_scope = {
				OR = {
					religion = orthodox
					religion = chalcedonian
				}
				war = no
				NOT = { religion_authority = 0.8 }
				any_realm_province = {
					OR = {
						province_id = 706
						AND = {
							culture = armenian
							region = custom_armenia
							OR = {
								religion = chalcedonian
								religion = orthodox
								religion = iconoclast
							}
						}
					}
				}
			}
		}
		NOT = {
			has_global_flag = sergius_tychus
		}
	}
	
	major_trigger = {
		OR = {
			has_landed_title = e_byzantium
			has_landed_title = d_paulician
			any_liege = { has_landed_title = e_byzantium }
			any_liege = { has_landed_title = d_paulician }
			religion = chalcedonian
			religion = orthodox
			religion = iconoclast
			religion = paulician
		}
	}
	
	mean_time_to_happen = {
		months = 1
		modifier = {
			factor = 0.1
			diplomacy = 15
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2105
		trigger = { has_landed_title = e_byzantium }
		set_global_flag = sergius_tychus
		piety = -100
		any_realm_province = {
			limit = {
				OR = {
					province_id = 706
					AND = {
						culture = armenian
						region = custom_armenia
						OR = {
							religion = chalcedonian
							religion = orthodox
							religion = iconoclast
						}
					}
				}
			}
			religion = paulician
		}
		hidden_tooltip = {
			random_realm_province = {
				limit = {
					OR = {
						culture = armenian
						province_id = 706
					}
					religion = paulician
				}
				add_province_modifier = {
					name = heretic_stronghold
					duration = 3650
				}
			}
		}
	}
	option = {
		name = I_SEE
		trigger = {
			NOT = { has_landed_title = e_byzantium }
			NOT = { has_landed_title = d_paulician }
		}
	}
	option = {
		name = OK
		trigger = { has_landed_title = d_paulician }
		piety = 500
		add_trait = zealous
		add_trait = ambitious
		change_diplomacy = 5
		religion_authority = {
			modifier = sergius_tychus
			years = 30
		}
	}
}

# Byzantine Emperor persecutes the Paulicians
character_event = {
	id = Plus.2106
	desc = EVTDESC_Plus_2106
	picture = GFX_evt_burning_house
	
	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		OR = {
			has_landed_title = e_byzantium
			has_landed_title = d_paulician
			any_liege = { has_landed_title = e_byzantium }
			religion = chalcedonian
			religion = orthodox
			religion = paulician
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2106 #Hopefully that will take care of it
		trigger = { has_landed_title = e_byzantium }
	}
	option = {
		name = EVTOPTB_Plus_2106 #A rather extreme measure...
		trigger = {
			any_liege = { has_landed_title = e_byzantium }
			NOT = { religion = paulician }
		}
		any_courtier = {
			limit = {
				is_ruler = no
				is_adult = yes
				prisoner = no
				religion = paulician
			}
			banish = yes
		}
	}
	option = {
		name = EVTOPTC_Plus_2106 #This is an outrage!
		trigger = {
			any_liege = { has_landed_title = e_byzantium }
			religion = paulician
		}
		opinion = { who = ROOT modifier = opinion_outraged years = 20 }
		reverse_opinion = { who = ROOT modifier = mad_heretic years = 20 }
	}
	option = {
		name = EVTOPTC_Plus_2106 #This is an outrage!
		trigger = { has_landed_title = d_paulician }
		opinion = { who = ROOT modifier = opinion_outraged years = 20 }
		reverse_opinion = { who = ROOT modifier = mad_heretic years = 20 }
		add_rival = ROOT
	}
	option = {
		name = I_SEE
		trigger = {
			NOR = {
				has_landed_title = e_byzantium
				has_landed_title = d_paulician
				any_liege = { has_landed_title = e_byzantium }
			}
		}
	}
}

# Paulician Patriarch appears
narrative_event = {
	id = Plus.2107
	title = EVTNAME_Plus_2107
	desc = EVTDESC_Plus_2107
	picture = GFX_evt_heretic
	border = GFX_event_narrative_frame_religion

	major = yes
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_2107
		trigger = { religion = paulician }
	}
	option = {
		name = EVTOPTB_Plus_2107
		trigger = {
			religion_group = christian
			NOT = { religion = paulician }
		}
	}
	option = {
		name = EVTOPTC_Plus_2107
		trigger = {
			NOT = { religion_group = christian }
		}
	}
}

### BOGOMILIST EVENTS

# Bogomil appears in Tyrnovo
narrative_event = {
	id = Plus.2110
	title = EVTNAME_Plus_2110
	desc = EVTDESC_Plus_2110
	picture = GFX_evt_heretic
	border = GFX_event_narrative_frame_religion
	
	only_rulers = yes
	only_playable = yes
	religion_group = christian
	major = yes
	
	trigger = {
		has_landed_title = k_bulgaria
		499 = {
			owner = { same_realm = ROOT }
			NOT = { culture = greek }
			NOT = { has_province_modifier = heretic_stronghold }
			OR = {
				religion = chalcedonian
				religion = orthodox
				religion = iconoclast
				religion = monothelite
			}
		}
		NOR = {
			year = 940
			religion = bogomilist
			has_global_flag = bogomil_lives
		}
	}
	
	major_trigger = {
		OR = {
			has_landed_title = k_bulgaria
			same_realm = ROOT
			religion = bogomilist
			religion = chalcedonian
			religion = orthodox
			religion = iconoclast
			religion = monothelite
			capital_scope = {
				NOT = {
					distance = {
						where = 499 # Tyrnovo
						value = 600	# Same part of the world
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		years = 25
	}
	
	immediate = {
		set_global_flag = bogomil_lives
		ROOT = {
			religion_authority = { modifier = bogomilism_spreading }
			create_character = {
				name = "Bogomil"
				random_traits = yes
				dynasty = none
				religion = bogomilist
				culture = bulgarian
				female = no
				age = 40
				trait = mastermind_theologian
				trait = possessed
				trait = zealous
				trait = gregarious
				trait = heresiarch
				trait = scholar
				trait = perfecti
				attributes = {
					learning = 12
					diplomacy = 10
				}
			}
			new_character = {
				religion_authority = { modifier = bogomil_appears }
			}
		}
		499 = {
			religion = bogomilist
			add_province_modifier = {
				name = heretic_stronghold
				duration = 3650
			}
			any_neighbor_province = {
				limit = {
					culture = PREV
					NOT = { has_province_modifier = heretic_stronghold }
					OR = {
						religion = chalcedonian
						religion = orthodox
						religion = iconoclast
						religion = monothelite
					}
				}
				random = {
					chance = 50
					religion = bogomilist
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2110 #Convert
		trigger = {
			has_landed_title = k_bulgaria
			controls_religion = no
			NOT = { rightful_religious_head = ROOT }
			mercenary = no
			holy_order = no
			prisoner = no
			is_adult = yes
			OR = {
				religion = chalcedonian
				religion = orthodox
				religion = iconoclast
				religion = monothelite
			}
			NOR = {
				trait = zealous
				trait = incapable
				culture = greek
				has_character_flag = converted_religion
			}
		}
		religion_authority = { modifier = ruler_converted_from }
		religion = bogomilist
		religion_authority = { modifier = ruler_converted_to }
		capital_scope = {
			if = {
				limit = {
					NOT = { has_province_modifier = heretic_stronghold }
					any_neighbor_province = { religion = bogomilist }
					OR = {
						religion = chalcedonian
						religion = orthodox
						religion = iconoclast
						religion = monothelite
					}
				}
			}
			religion = bogomilist
		}
		random_realm_province = {
			limit = {
				NOT = { has_province_modifier = heretic_stronghold }
				any_neighbor_province = { religion = bogomilist }
				OR = {
					religion = chalcedonian
					religion = orthodox
					religion = iconoclast
					religion = monothelite
				}
			}
			religion = bogomilist
		}
		random_realm_province = {
			limit = {
				NOT = { has_province_modifier = heretic_stronghold }
				any_neighbor_province = { religion = bogomilist }
				OR = {
					religion = chalcedonian
					religion = orthodox
					religion = iconoclast
					religion = monothelite
				}
			}
			religion = bogomilist
		}
		hidden_tooltip = {
			e_byzantium = {
				holder_scope = {
					if = {
						limit = {
							NOT = { has_landed_title = k_bulgaria }
							NOT = { has_claim = k_bulgaria }
							NOT = { trait = cynical }
							OR = {
								religion = chalcedonian
								religion = orthodox
								religion = iconoclast
								religion = monothelite
							}
						}
						add_claim = k_bulgaria
					}
				}
			}
			any_courtier = {
				limit = {
					is_adult = no
					is_ruler = no
					dynasty = ROOT
				}
				religion = ROOT
			}
			primary_title = { add_law = bogomilist_church_0 }
		}
	}
	option = {
		name = EVTOPTB_Plus_2110 #Don't Convert
		trigger = {
			has_landed_title = k_bulgaria
		}
	}
	option = {
		name = EVTOPTC_Plus_2110
		trigger = {
			NOT = { has_landed_title = k_bulgaria }
			religion = bogomilist
		}
	}
	option = {
		name = EVTOPTD_Plus_2110
		trigger = {
			NOT = { has_landed_title = k_bulgaria }
			NOT = { religion = bogomilist }
			religion_group = christian
		}
	}
	option = {
		name = I_SEE
		trigger = {
			NOT = { has_landed_title = k_bulgaria }
			NOT = { has_landed_title = e_byzantium }
			NOT = { religion_group = christian }
		}
	}
}

# Initialization event for Bogomilist laws
character_event = {
	id = Plus.2111
	hide_window = yes
	is_triggered_only = yes
	
	religion = bogomilist
	only_rulers = yes
	only_playable = yes
	
	trigger = {
		higher_tier_than = BARON
		OR = {
			AND = {
				is_title_active = d_bogomilist
				primary_title = { NOT = { has_law = bogomilist_church_4 } }
			}
			AND = {
				d_bogomilist = { has_title_flag = bogomilist_formalized }
				primary_title = {
					NOR = { 
						has_law = bogomilist_church_3
						has_law = bogomilist_church_4
					}
				}
			}
			AND = {
				d_bogomilist = { has_title_flag = bogomilist_organized }
				primary_title = {
					NOR = {
						has_law = bogomilist_church_2
						has_law = bogomilist_church_3
						has_law = bogomilist_church_4
					}
				}
			}
			AND = {
				any_demesne_title = { has_law = bogomilist_church_1 }
				primary_title = { has_law = bogomilist_church_0 }
			}
			AND = {
				any_liege = { has_law = bogomilist_church_1 }
				primary_title = { has_law = bogomilist_church_0 }
			}
			primary_title = {
				NOR = {
					has_law = bogomilist_church_0 
					has_law = bogomilist_church_1
					has_law = bogomilist_church_2
					has_law = bogomilist_church_3
					has_law = bogomilist_church_4
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				is_title_active = d_bogomilist
				primary_title = { NOT = { has_law = bogomilist_church_4 } }
			}
			primary_title = { add_law = bogomilist_church_4 }
			break = yes
		}
		if = {
			limit = {
				d_bogomilist = { has_title_flag = bogomilist_formalized }
				primary_title = {
					NOR = { 
						has_law = bogomilist_church_3
						has_law = bogomilist_church_4
					}
				}
			}
			primary_title = { add_law = bogomilist_church_3 }
			break = yes
		}
		if = {
			limit = {
				d_bogomilist = { has_title_flag = bogomilist_organized }
				primary_title = {
					NOR = {
						has_law = bogomilist_church_2
						has_law = bogomilist_church_3
						has_law = bogomilist_church_4
					}
				}
			}
			primary_title = { add_law = bogomilist_church_2 }
			break = yes
		}
		if = {
			limit = {
				any_demesne_title = { has_law = bogomilist_church_1 }
				primary_title = { has_law = bogomilist_church_0 }
			}
			primary_title = { add_law = bogomilist_church_1 }
			break = yes
		}
		if = {
			limit = {
				any_liege = { has_law = bogomilist_church_1 }
				primary_title = { has_law = bogomilist_church_0 }
			}
			primary_title = { add_law = bogomilist_church_1 }
			break = yes
		}
		if = {
			limit = {
				primary_title = {
					NOR = {
						has_law = bogomilist_church_0 
						has_law = bogomilist_church_1
						has_law = bogomilist_church_2
						has_law = bogomilist_church_3
						has_law = bogomilist_church_4
					}
				}
			}
			primary_title = { add_law = bogomilist_church_0 }
			break = yes
		}
	}
}

# Formalization of Bogomilism begins
character_event = {
	id = Plus.2112
	desc = EVTDESC_Plus_2112
	picture = GFX_evt_monastery_monks
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_2112
		custom_tooltip = {
			text = BOGO_BEGIN_FORMALIZATION
			hidden_tooltip = {
				d_bogomilist = { change_variable = { which = "bogomil_formalization" value = 1 } }
			}
		}
	}
}

# Formalization of Bogomilism ends
character_event = {
	id = Plus.2113
	picture = GFX_evt_monastery_monks
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	desc = {
		text = EVTDESC_Plus_2113_religion
		trigger = { NOT = { religion = bogomilist } }
	}
	desc = {
		text = EVTDESC_Plus_2113_rule
		trigger = { religion = bogomilist }
	}
	
	trigger = {
		has_character_modifier = formalizing_bogomilist
		OR = {
			NOT = { religion = bogomilist }
			is_ruler = no
			lower_tier_than = KING
		}
	}
	
	option = {
		name = OK
		remove_character_modifier = formalizing_bogomilist
	}
}

# Formalization: Support Common Liturgy
character_event = {
	id = Plus.2114
	desc = EVTDESC_Plus_2114
	picture = GFX_evt_monastery_monks
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist #this should've been a flag
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
			NOT = { has_title_flag = common_liturgy }
		}
	}
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EXCELLENT
		trigger = { character = ROOT }
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 3 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION4 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION3 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 1 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 2 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}		
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 0 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 1 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 0 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = 1 }
				set_title_flag = common_liturgy
			}
		}
		piety = 50
	}
	option = {
		name = I_SEE
		trigger = { NOT = { character = ROOT } }
	}
}

# Formalization: Canonicalize Bible
character_event = {
	id = Plus.2115
	desc = EVTDESC_Plus_2115
	picture = GFX_evt_book_carolingian_script
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
			NOT = { has_title_flag = bible_canon }
		}
	}
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EXCELLENT
		trigger = { character = ROOT }
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 3 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION4 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION3 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 1 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 2 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}		
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 0 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 1 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 0 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = 1 }
				set_title_flag = bible_canon
			}
		}
		piety = 100
		prestige = 100
		change_learning = 1
		set_dynasty_flag = bogomil_canon_bible
	}
	option = {
		name = I_SEE
		trigger = { NOT = { character = ROOT } }
	}
}

# Formalization: Church Councils
character_event = {
	id = Plus.2116
	desc = EVTDESC_Plus_2116
	picture = GFX_evt_monastery_monks
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		scaled_wealth = 1.0
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
			NOT = { has_title_flag = church_councils }
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2116
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 3 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION4 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION3 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 1 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 2 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}		
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 0 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 1 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 0 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = 1 }
				set_title_flag = church_councils
			}
		}
		scaled_wealth = -1.0
		piety = 100
		hidden_tooltip = {
			character_event = { id = Plus.2117 }
		}
	}
	option = {
		name = EVTOPTB_Plus_2116
		prestige = -50
	}
}

character_event = {
	id = Plus.2117
	desc = EVTDESC_Plus_2117
	picture = GFX_evt_monastery_monks
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EVTOPTA_Plus_2117
	}
}

# Formalization: Seminary Schools
character_event = {
	id = Plus.2118
	desc = EVTDESC_Plus_2118
	picture = GFX_evt_monastery_monks
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes

	only_rulers = yes
	only_playable = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		scaled_wealth = 0.5
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2118
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 3 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION4 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION3 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 1 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 2 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}		
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 0 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 1 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 0 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = 1 }
			}
		}
		scaled_wealth = -0.5
		piety = 50
		hidden_tooltip = {
			character_event = { id = Plus.2119 }
		}
	}
	option = {
		name = EVTOPTB_Plus_2118
		piety = -50
	}
}

character_event = {
	id = Plus.2119
	desc = EVTDESC_Plus_2119
	picture = GFX_evt_monastery_monks
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EVTOPTA_Plus_2117
	}
}

# Formalization: Endorsed by Priest
character_event = {
	id = Plus.2120
	desc = EVTDESC_Plus_2120
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		piety = 100
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
		}
	}
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EXCELLENT
		trigger = { character = ROOT }
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 3 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION4 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION3 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 1 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 2 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}		
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 0 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 1 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 0 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = 1 }
			}
		}
		piety = 25
		prestige = 25
	}
	option = {
		name = I_SEE
		trigger = { NOT = { character = ROOT } }
	}
}

# Formalization: Public Speech
character_event = {
	id = Plus.2121
	desc = EVTDESC_Plus_2121
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		diplomacy = 12
		has_regent = no
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
		}
	}
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EXCELLENT
		trigger = { character = ROOT }
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 3 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION4 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION3 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 1 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 2 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}		
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 0 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 1 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 0 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = 1 }
			}
		}
		piety = 25
		prestige = 25
	}
	option = {
		name = I_SEE
		trigger = { NOT = { character = ROOT } }
	}
}

# Formalization: Ruler Writes Text
character_event = {
	id = Plus.2122
	desc = EVTDESC_Plus_2122
	picture = GFX_evt_book_carolingian_script
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		learning = 12
		NOT = { trait = blinded }
		has_regent = no
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
		}
	}
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EXCELLENT
		trigger = { character = ROOT }
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 3 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION4 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION3 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 1 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 2 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}		
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 0 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 1 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 0 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = 1 }
			}
		}
		piety = 25
		prestige = 25
	}
	option = {
		name = I_SEE
		trigger = { NOT = { character = ROOT } }
	}
}

# Formalization: Troublemaker Sect
character_event = {
	id = Plus.2123
	desc = EVTDESC_Plus_2123
	picture = GFX_evt_monastery_monks
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
			check_variable = { which = "bogomil_formalization" value = 0.5 }
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2123
		if = {
			limit = { d_bogomilist = { check_variable = { which = "bogomil_formalization" value = 3 } } }
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 2 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = -1 }
			}
		}
		piety = 50
	}
	option = {
		name = EVTOPTB_Plus_2123
		prestige = -100
		piety = -100
	}
}

# Formalization: Traditionalist Revival
character_event = {
	id = Plus.2124
	desc = EVTDESC_Plus_2124
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		religion = bogomilist
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
			check_variable = { which = "bogomil_formalization" value = 0.5 }
		}
	}
	
	option = {
		name = CURSES
		if = {
			limit = { d_bogomilist = { check_variable = { which = "bogomil_formalization" value = 3 } } }
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 2 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = -1 }
			}
		}
		prestige = -50
	}
}

# Formalization: Demand For Reversal
character_event = {
	id = Plus.2125
	desc = EVTDESC_Plus_2125
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		any_realm_province = {
			religion = bogomilist
			NOT = { has_province_modifier = religious_unrest }
		}
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
			check_variable = { which = "bogomil_formalization" value = 0.5 }
		}
	}
	
	immediate = {
		random_realm_province = {
			limit = {
				religion = bogomilist
				NOT = { has_province_modifier = religious_unrest }
			}
			save_event_target_as = demand_province
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2125
		if = {
			limit = { d_bogomilist = { check_variable = { which = "bogomil_formalization" value = 3 } } }
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 2 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = -1 }
			}
		}
		prestige = -100
	}
	option = {
		name = EVTOPTB_Plus_2125
		event_target:demand_province = {
			add_province_modifier = {
				name = religious_unrest
				duration = 1095
			}
		}
	}
}

# Formalization: Blamed by Priest
character_event = {
	id = Plus.2126
	desc = EVTDESC_Plus_2126
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		NOT = { piety = 100 }
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
			check_variable = { which = "bogomil_formalization" value = 0.5 }
		}
	}
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = CURSES
		if = {
			limit = { d_bogomilist = { check_variable = { which = "bogomil_formalization" value = 3 } } }
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 2 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = -1 }
			}
		}
		prestige = -50
	}
}

# Formalization: Learned Priest Objects
character_event = {
	id = Plus.2127
	desc = EVTDESC_Plus_2127
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	only_rulers = yes
	religion = bogomilist
	
	trigger = {
		higher_tier_than = DUKE
		has_character_modifier = formalizing_bogomilist
		NOT = { learning = 12 }
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
			check_variable = { which = "bogomil_formalization" value = 0.5 }
		}
	}
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = CURSES
		if = {
			limit = { d_bogomilist = { check_variable = { which = "bogomil_formalization" value = 3 } } }
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 2 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = -1 }
			}
		}
		prestige = -50
		piety = -25
	}
}

# Formalization: Major Battle Won
character_event = {
	id = Plus.2128
	desc = EVTDESC_Plus_2128
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	religion = bogomilist
	major = yes
	
	trigger = {
		OR = {
			AND = {
				religion = bogomilist
				higher_tier_than = DUKE
				has_character_modifier = formalizing_bogomilist
			}
			any_liege = {
				religion = bogomilist
				higher_tier_than = DUKE
				has_character_modifier = formalizing_bogomilist
			}
		}
		OR = {
			any_war = {
				OR = {
					using_cb = crusade
					using_cb = holy_war
					using_cb = religious_revolt
				}
			}
			any_liege = {
				any_war = {
					OR = {
						using_cb = crusade
						using_cb = holy_war
						using_cb = religious_revolt
					}
				}
			}
		}
		d_bogomilist = {
			NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
		}
	}
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EXCELLENT
		trigger = {
			OR = {
				character = ROOT
				same_realm = ROOT
			}
			has_character_modifier = formalizing_bogomilist
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 3 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION4 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION3 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 1 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 2 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}		
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 0 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 1 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 0 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = 1 }
			}
		}
		piety = 50
	}
	option = {
		name = I_SEE
		trigger = {
			OR = {
				NOT = { has_character_modifier = formalizing_bogomilist }
				NOR = {
					character = ROOT
					same_realm = ROOT
				}
			}
		}
	}
}

# Formalization: Major Battle Lost
character_event = {
	id = Plus.2129
	desc = EVTDESC_Plus_2129
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	religion = bogomilist
	major = yes
	
	trigger = {
		OR = {
			AND = {
				religion = bogomilist
				higher_tier_than = DUKE
				has_character_modifier = formalizing_bogomilist
			}
			any_liege = {
				religion = bogomilist
				higher_tier_than = DUKE
				has_character_modifier = formalizing_bogomilist
			}
		}
		OR = {
			any_war = {
				OR = {
					using_cb = crusade
					using_cb = holy_war
					using_cb = religious_revolt
				}
			}
			any_liege = {
				any_war = {
					OR = {
						using_cb = crusade
						using_cb = holy_war
						using_cb = religious_revolt
					}
				}
			}
		}
		d_bogomilist = {
			NOT = { is_variable_equal = { which = "bogomil_formalization" value = 4 } }
			check_variable = { which = "bogomil_formalization" value = 0.5 }
		}
	}
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = CURSES
		trigger = {
			OR = {
				character = ROOT
				same_realm = ROOT
			}
			has_character_modifier = formalizing_bogomilist
		}
		if = {
			limit = { d_bogomilist = { check_variable = { which = "bogomil_formalization" value = 3 } } }
			custom_tooltip = { text = BOGO_FORMALIZATION2 }
		}
		if = {
			limit = {
				d_bogomilist = {
					check_variable = { which = "bogomil_formalization" value = 2 }
					NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
				}
			}
			custom_tooltip = { text = BOGO_FORMALIZATION1 }
		}
		if = {
			limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 2 } } } }
			custom_tooltip = { text = BOGO_FORMALIZATION0 }
		}
		hidden_tooltip = {
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = -1 }
			}
		}
		piety = 50
	}
	option = {
		name = I_SEE
		trigger = {
			OR = {
				NOT = { has_character_modifier = formalizing_bogomilist }
				NOR = {
					character = ROOT
					same_realm = ROOT
				}
			}
		}
	}
}
		
# Bogomilist Faith Organized
narrative_event = {
	id = Plus.2130
	title = EVTNAME_Plus_2130
	desc = EVTDESC_Plus_2130
	picture = GFX_evt_monastery_monks
	border = GFX_event_narrative_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EVTOPTA_Plus_2130
		trigger = { character = ROOT }
	}
	option = {
		name = I_SEE
		trigger = { NOT = { character = ROOT } }
		tooltip = { religion_authority = { modifier = bogomilism_organized } }
		if = {
			limit = {
				primary_title = { NOT = { has_law = bogomilist_church_2 } }
			}
			primary_title = { add_law = bogomilist_church_2 }
		}
		if = {
			limit = { ai = yes }
			random_list = {
				25 = {
					modifier = {
						factor = 0
						ROOT = { is_heretic = yes }
					}
					modifier = {
						factor = 0
						OR = {
							trait = zealous
							trait = perfecti
							trait = incapable
							is_adult = no
							prisoner = yes
							can_change_religion = no
						}
					}
					become_heretic = yes
				}
				25 = {
					modifier = {
						factor = 0
						ROOT = { is_heretic = no }
					}
					modifier = {
						factor = 0
						OR = {
							trait = zealous
							trait = perfecti
							trait = incapable
							is_adult = no
							prisoner = yes
							can_change_religion = no
						}
					}
					abandon_heresy = yes
				}
				50 = {
					modifier = {
						factor = 0.5
						trait = cynical
					}
					modifier = {
						factor = 0.5
						trait = wroth
					}
					modifier = {
						factor = 2
						trait = patient
					}
					modifier = {
						factor = 2
						is_priest = yes
					}
				}
			}	
		}
		random_demesne_province = {
			limit = {
				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
					}
				}
				75 = {}
			}
		}
	}
}

# Bogomilist Faith Formalized by force
narrative_event = {
	id = Plus.2131
	title = EVTNAME_Plus_2131
	desc = EVTDESC_Plus_2131
	picture = GFX_evt_monastery_monks
	border = GFX_event_narrative_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EVTOPTA_Plus_2131
		trigger = { character = ROOT }
	}
	option = {
		name = EVTOPTB_Plus_2131
		trigger = { NOT = { character = ROOT } }
		tooltip = { religion_authority = { modifier = bogomilism_formalized } }
		if = {
			limit = {
				primary_title = { NOT = { has_law = bogomilist_church_3 } }
			}
			primary_title = { add_law = bogomilist_church_3 }
		}
		if = {
			limit = { ai = yes }
			random_list = {
				50 = {
					modifier = {
						factor = 0
						ROOT = { is_heretic = yes }
					}
					modifier = {
						factor = 0
						OR = {
							trait = zealous
							trait = perfecti
							trait = incapable
							is_adult = no
							prisoner = yes
							can_change_religion = no
						}
					}
					become_heretic = yes
				}
				50 = {
					modifier = {
						factor = 0
						ROOT = { is_heretic = no }
					}
					modifier = {
						factor = 0
						OR = {
							trait = zealous
							trait = perfecti
							trait = incapable
							is_adult = no
							prisoner = yes
							can_change_religion = no
						}
					}
					abandon_heresy = yes
				}
				50 = {
					modifier = {
						factor = 0.5
						trait = cynical
					}
					modifier = {
						factor = 0.5
						trait = wroth
					}
					modifier = {
						factor = 2
						trait = patient
					}
					modifier = {
						factor = 2
						is_priest = yes
					}
					random = {
						chance = 20
						add_trait = cynical
					}
				}
			}	
		}
		random_demesne_province = {
			limit = {
				religion = bogomilist
				NOT = { has_province_modifier = religious_unrest }
			}
			random_list = {
				50 = {
					add_province_modifier = {
						name = religious_unrest
						duration = 730
					}
				}
				50 = {
					modifier = {
						factor = 0
						ROOT = { is_heretic = yes }
					}
					become_heretic = yes
					add_province_modifier = {
						name = religious_unrest
						duration = 730
					}
				}
				50 = {
					modifier = {
						factor = 0
						ROOT = { is_heretic = no }
					}
					abandon_heresy = yes
					add_province_modifier = {
						name = religious_unrest
						duration = 730
					}
				}
				50 = {}
			}
		}
	}
}

# Bogomilist Faith Formalized
narrative_event = {
	id = Plus.2132
	title = EVTNAME_Plus_2131
	desc = EVTDESC_Plus_2132
	picture = GFX_evt_monastery_monks
	border = GFX_event_narrative_frame_religion
	
	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		religion = bogomilist
	}
	
	option = {
		name = EVTOPTA_Plus_2130
		trigger = { character = ROOT }
	}
	option = {
		name = EVTOPTA_Plus_2130
		trigger = { NOT = { character = ROOT } }
		tooltip = { religion_authority = { modifier = bogomilism_formalized } }
		if = {
			limit = {
				primary_title = { NOT = { has_law = bogomilist_church_3 } }
			}
			primary_title = { add_law = bogomilist_church_3 }
		}
	}
}

# A Bogomilist Patriarch is elected (fired from decision)
character_event = {
	id = Plus.2133
	
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		random_realm_lord = {
			limit = {
				religion = bogomilist
				is_theocracy = yes
				prisoner = no
				trait = perfecti
				NOT = { trait = incapable }
			}
			d_bogomilist = { grant_title = PREV }
			ROOT = {
				random_realm_title = {
					limit = { is_holy_site = ROOT }
					gain_title = PREVPREV
				}
			}
			set_defacto_liege = ROOT
			pf_liege_change_effect = yes
			save_event_target_as = new_bogomilist_patriarch
			ROOT = { narrative_event = { id = Plus.2134 } }
			break = yes
		}
		random_realm_character = {
			limit = {
				religion = bogomilist
				is_ruler = no
				prisoner = no
				trait = perfecti
				learning = 12
				NOT = { trait = incapable }
			}
			d_bogomilist = { grant_title = PREV }
			ROOT = {
				random_realm_title = {
					limit = { is_holy_site = ROOT }
					gain_title = PREVPREV
				}
			}
			set_defacto_liege = ROOT
			pf_liege_change_effect = yes
			save_event_target_as = new_bogomilist_patriarch
			ROOT = { narrative_event = { id = Plus.2134 } }
			break = yes
		}
		create_random_priest = {
			random_traits = yes
			dynasty = random
			religion = bogomilist
			culture = ROOT
			age = 40
			health = 7
			trait = quick
			trait = zealous
			trait = perfecti
			trait = scholar
			trait = mastermind_theologian
			attributes = {
				learning = 5
				diplomacy = 5
				martial = 2
				stewardship = 5
				intrigue = 5
			}
		}
		new_character = {
			d_bogomilist = { grant_title = PREV }
			ROOT = {
				random_realm_title = {
					limit = { is_holy_site = ROOT }
					gain_title = PREVPREV
				}
			}
			set_defacto_liege = ROOT
			save_event_target_as = new_bogomilist_patriarch
		}
		narrative_event = { id = Plus.2134 }
	}
}

# The rest of the world is told about the new Bogomilist Patriarch
narrative_event = {
	id = Plus.2134
	title = EVTTITLE_Plus_2134
	desc = EVTDESC_Plus_2134
	picture = GFX_evt_icon
	border = GFX_event_narrative_frame_religion

	major = yes

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_2134
		trigger = {
			NOT = { religion = bogomilist }
			religion_group = christian
		}
	}
	option = {
		name = EVTOPTB_Plus_2134
		trigger = { NOT = { religion_group = christian } }
	}
	option = {
		name = EVTOPTA_Plus_2130
		trigger = { religion = bogomilist }
		if = {
			limit = {
				primary_title = { NOT = { has_law = bogomilist_church_4 } }
			}
			primary_title = { add_law = bogomilist_church_4 }
		}
	}
}

# Church of St. Bogomil Construction Begun
province_event = {
	id = Plus.2135
	desc = EVTDESC_Plus_2135
	picture = GFX_evt_castle_construction
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_2135
	}
}

province_event = {
	id = Plus.2136
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = {
				owner = { war = yes }
			}
			repeat_event = { id = Plus.2136 days = 60 random = 120 }
		}
		if = {
			limit = {
				owner = { NOT = { religion = bogomilist } }
			}
			remove_province_modifier = building_st_bogomil
		}
		if = {
			limit = { has_province_modifier = building_st_bogomil }
			set_province_flag = church_of_st_bogomil_built
			remove_province_modifier = building_st_bogomil
			owner = {
				narrative_event = { id = Plus.2137 }
			}
		}
	}
}

# Church of St. Bogomil Built
narrative_event = {
	id = Plus.2137
	title = EVTNAME_Plus_2137
	desc = EVTDESC_Plus_2137
	picture = GFX_evt_cathedral
	border = GFX_event_narrative_frame_religion
	major = yes
	
	is_triggered_only = yes
	
	hide_from = yes
	
	immediate = {
		499 = {
			if = {
				limit = { num_of_empty_holdings = 1 }
				build_holding = {
				   title = b_st_bogomil
				   type = temple
				   holder = ROOT
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA_Plus_2137
		trigger = { religion = bogomilist }
		if = {
			limit = { character = ROOT }
			prestige = 500
			piety = 500
			religion_authority = { modifier = church_st_bogomil_built }
		}
		if = {
			limit = {
				higher_tier_than = DUKE
				has_character_modifier = formalizing_bogomilist
				d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 4 } } }
			}
			if = {
				limit = {
					d_bogomilist = {
						check_variable = { which = "bogomil_formalization" value = 3 }
						NOT = { check_variable = { which = "bogomil_formalization" value = 4 } }
					}
				}
				custom_tooltip = { text = BOGO_FORMALIZATION4 }
			}
			if = {
				limit = {
					d_bogomilist = {
						check_variable = { which = "bogomil_formalization" value = 2 }
						NOT = { check_variable = { which = "bogomil_formalization" value = 3 } }
					}
				}
				custom_tooltip = { text = BOGO_FORMALIZATION3 }
			}
			if = {
				limit = {
					d_bogomilist = {
						check_variable = { which = "bogomil_formalization" value = 1 }
						NOT = { check_variable = { which = "bogomil_formalization" value = 2 } }
					}
				}
				custom_tooltip = { text = BOGO_FORMALIZATION2 }
			}		
			if = {
				limit = {
					d_bogomilist = {
						check_variable = { which = "bogomil_formalization" value = 0 }
						NOT = { check_variable = { which = "bogomil_formalization" value = 1 } }
					}
				}
				custom_tooltip = { text = BOGO_FORMALIZATION1 }
			}
			if = {
				limit = { d_bogomilist = { NOT = { check_variable = { which = "bogomil_formalization" value = 0 } } } }
				custom_tooltip = { text = BOGO_FORMALIZATION0 }
			}
			d_bogomilist = {
				change_variable = { which = "bogomil_formalization" value = 1 }
			}
		}
		if = {
			limit = { NOT = { character = ROOT } }
			tooltip = { religion_authority = { modifier = church_st_bogomil_built } }
		}
	}
	option = {
		name = OK
		trigger = { NOT = { religion = bogomilist } }
	}
}

# Bogomilist missionaries move into a neighboring realm
character_event = {
	id = Plus.2138
	
	hide_window = yes
	is_triggered_only = yes

	only_independent = yes
	religion = bogomilist
	
	trigger = {
		any_realm_province = {
			county = { is_occupied = no }
			religion = bogomilist
			any_neighbor_province = {
				county = { is_occupied = no }
				NOT = { religion = bogomilist }
				owner = {
					NOT = { war_with = ROOT }
					NOT = { reverse_has_truce = ROOT }
					NOT = { has_non_aggression_pact_with = ROOT }
					NOT = { same_realm = ROOT }
					NOT = { any_courtier = { has_character_flag = bogomilist_missionary } }
				}
			}
		}
	}
	
	weight_multiplier = {
		days = 1
		modifier = {
			factor = 0.75
			war = yes
		}
		modifier = {
			factor = 0.5
			has_law = bogomilist_church_0
		}
		modifier = {
			factor = 1.5
			has_law = bogomilist_church_2
		}
		modifier = {
			factor = 1.5
			has_law = bogomilist_church_3
		}
		modifier = {
			factor = 1.5
			has_law = bogomilist_church_4
		}
		modifier = {
			factor = 0.5
			lower_tier_than = DUKE
		}
		modifier = {
			factor = 1.5
			tier = EMPEROR
		}
	}
	
	immediate = {
		random_realm_province = {
			limit = {
				religion = bogomilist
				county = { is_occupied = no }
				any_neighbor_province = {
					county = { is_occupied = no }
					NOT = { religion = bogomilist }
					owner = {
						NOT = { war_with = ROOT }
						NOT = { reverse_has_truce = ROOT }
						NOT = { has_non_aggression_pact_with = ROOT }
						NOT = { same_realm = ROOT }
						NOT = { any_courtier = { has_character_flag = bogomilist_missionary } }
					}
				}
			}
			random_neighbor_province = {
				limit = {
					county = { is_occupied = no }
					NOT = { religion = bogomilist }
					owner = {
						NOT = { war_with = ROOT }
						NOT = { reverse_has_truce = ROOT }
						NOT = { has_non_aggression_pact_with = ROOT }
						NOT = { same_realm = ROOT }
						NOT = { any_courtier = { has_character_flag = bogomilist_missionary } }
					}
				}
				owner = {
					create_random_diplomat = {
						random_traits = yes
						dynasty = none
						religion = ROOT
						culture = PREVPREV
						female = no
						age = 40
						trait = zealous
						trait = gregarious
						trait = perfecti
						attributes = {
							learning = 5
							diplomacy = 5
						}
					}
					new_character = {
						set_character_flag = bogomilist_missionary
					}
				}	
			}
		}
	}
}

