###################################
#
# Events for Religion
#
# Id 39000 - 39999 is reserved
#
###################################

# Written by Henrik Fhraeus, Johan Andersson & Niklas Strid

########################################
# HERESIES
########################################

# Heresy appears out of "nowhere"
province_event = {
	id = 39000
	desc = EVTDESC39000
	picture = GFX_evt_stone_church
	border = GFX_event_normal_frame_religion

	lacks_dlc = "Sons of Abraham"

	trigger = {
		is_heretic = no
		has_heresies = yes

		NOR = {
			province_id = c_roma
			province_id = c_thrake
			province_id = c_mecca
		}
	}

	mean_time_to_happen = {
		years = 800

		mult_modifier = {
			factor = 2

			has_game_rule = {
				name = religious_conversion
				value = slower
			}
		}

		mult_modifier = {
			factor = 2.0
			religion_authority >= 0.6
		}

		mult_modifier = {
			factor = 2.0
			religion_authority >= 0.8
		}

		mult_modifier = {
			factor = 0.75
			NOT = { religion_authority >= 0.2 }
		}

		mult_modifier = {
			factor = 0.75
			NOT = { religion_authority >= 0.4 }
		}
	}

	immediate = {
		become_heretic = yes

		add_province_modifier = {
			name = religious_unrest
			years = 2
		}

		owner = {
			if = {
				limit = { ai = no }

				chronicle = {
					entry = CHRONICLE_HERESY_SPREAD
					picture = GFX_evt_heretic
				}
			}

			if = {
				limit = { independent = no }

				any_liege = {
					limit = { ai = no }

					chronicle = {
						entry = CHRONICLE_HERESY_SPREAD
						picture = GFX_evt_heretic
					}
				}
			}
		}
	}

	option = {
		name = {
			text = EVTOPTA39000
			trigger = {
				NOT = { religion = owner }
			}
		}
		name = {
			text = EVTOPTB39000
			trigger = { religion = owner }
		}

		owner = {
			show_scope_change = no

			if = {
				limit = { is_parent_religion = ROOT }
				piety = -10
			}
		}

		if = {
			limit = {
				owner = {
					top_liege = {
						NOT = {
							any_realm_province = {
								religion = ROOT
								has_province_modifier = heretic_stronghold
							}
						}
					}
				}
			}

			add_province_modifier = {
				name = heretic_stronghold
				years = 10
			}
		}

		# News spread
		owner = {
			top_liege = {
				if = {
					limit = {
						NOT = { character = PREV }
					}

					character_event = {
						id = 39400
						days = 2
					}
				}

				any_vassal = {
					limit = {
						OR = {
							is_parent_religion = ROOT
							religion = ROOT
						}
					}

					character_event = {
						id = 39400
						days = 2
					}
				}
			}
		}

		# Pope gets angry if you don't convert the heretics
		province_event = {
			id = 39399
			years = 2
			random = 60
		}
	}
}

# News spread in realm
character_event = {
	id = 39400
	desc = EVTDESC39400
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion
	portrait = event_target:heretic_province_owner # CleanSlate: So that it doesn't display the devil worshipper that caused it. (MNM.20050)

	is_triggered_only = yes

	ai = no

	immediate = {
		FROM = {
			owner = { save_event_target_as = heretic_province_owner }
		}
	}

	option = {
		name = {
			text = EXCELLENT
			trigger = { religion = FROM }
		}
		name = {
			text = EVTOPTA39400
			trigger = {
				religion_group = FROM
				NOT = { religion = FROM }
			}
		}
		name = {
			text = EVTOPTB39400
			trigger = {
				NOT = { religion_group = FROM }
			}
		}
	}
}

province_event = {
	id = 39399

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		religion_group = christian
		is_heretic = yes
		NOT = { has_province_modifier = religious_unrest }

		owner = {
			rightful_religious_head_scope = { always = yes }

			job_spiritual = {
				NAND = {
					has_job_action = action_inquisition
					at_location = ROOT
				}
			}
		}
	}

	immediate = {
		owner = {
			rightful_religious_head_scope = {
				character_event = { id = 39401 }
			}
		}
	}
}

# Pope disappointed about allowing heresy
character_event = {
	id = 39401
	desc = EVTDESC39401
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39401

		FROM = {
			owner = {
				character_event = { id = 39402 }
			}
		}
	}
}

# Message from the Pope
character_event = {
	id = 39402
	desc = EVTDESC39402
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39402

		reverse_opinion = {
			name = pope_disappointed_over_heretic_province
			who = FROM
			years = 5
		}
	}
}

# Pope urges to root out heresy in province - Setup
character_event = {
	id = 39405

	is_triggered_only = yes # on_yearly_pulse
	hide_window = yes

	lacks_dlc = "Sons of Abraham"
	only_playable = yes
	religion_group = christian
	min_age = 16

	trigger = {
		is_catholic_branch = yes
		rightful_religious_head_scope = { always = yes }

		any_demesne_province = {
			religion_group = christian
			is_heretic = yes

			owner = {
				job_spiritual = {
					NAND = {
						has_job_action = action_inquisition
						at_location = PREVPREV
					}
				}
			}
		}
	}

	immediate = {
		rightful_religious_head_scope = {
			character_event = { id = 39403 }
		}
	}
}

# Pope urges to root out heresy in province
character_event = {
	id = 39403
	desc = EVTDESC39403
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39403

		FROM = {
			random_demesne_province = {
				limit = {
					religion_group = christian
					is_heretic = yes

					owner = {
						job_spiritual = {
							NAND = {
								has_job_action = action_inquisition
								at_location = PREVPREV
							}
						}
					}
				}

				province_event = {
					id = 39404
					days = 1
				}
			}
		}
	}
}

# Message from the Pope
province_event = {
	id = 39404
	desc = EVTDESC39404
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39404

		add_province_modifier = {
			name = force_converting
			years = 1
		}

		owner = {
			show_scope_change = no

			piety = 10
		}
	}

	option = {
		name = EVTOPTB39404

		owner = {
			show_scope_change = no

			piety = -50
		}
	}
}

# Pope learns that a catholic ruler has a heretic advisor
character_event = {
	id = 39410
	desc = EVTDESC39410
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA39410
	}
}

# Letter from the pope about a heretic advisor
letter_event = {
	id = 39441
	desc = EVTDESC39441
	border = GFX_event_letter_frame_religion
	portrait = event_target:the_pope

	is_triggered_only = yes # on_yearly_pulse, random_events, heretic_advisor

	lacks_dlc = "Sons of Abraham"
	only_playable = yes
	religion_group = christian

	trigger = {
		is_catholic_branch = yes

		rightful_religious_head_scope = {
			is_incapable = no
			prisoner = no
			war = no
		}

		any_voter = {
			is_heretic = yes
			religion_group = christian
			prisoner = no
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 4
			rightful_religious_head_scope = { trait = zealous }
		}
	}

	immediate = {
		rightful_religious_head_scope = {
			save_event_target_as = the_pope

			character_event = { id = 39410 }
		}

		random_voter = {
			limit = {
				is_heretic = yes
				religion_group = christian
				prisoner = no
			}

			save_event_target_as = heretic_to_target
		}
	}

	option = {
		name = EVTOPTA39441 # Imprison

		reverse_imprison = event_target:heretic_to_target

		if = {
			limit = {
				NOT = {
					reverse_has_opinion_modifier = {
						name = pope_heretic_removal_approve
						who = event_target:the_pope
					}
				}
			}

			reverse_opinion = {
				name = pope_heretic_removal_approve
				who = event_target:the_pope
				years = 3
			}
		}

		ai_chance = { factor = 90 }
	}

	option = {
		name = EVTOPTB39441 # Ignore Pope

		reverse_opinion = {
			name = pope_heretic_removal_disapprove
			who = event_target:the_pope
			years = 3
		}

		reverse_opinion = {
			name = opinion_defended_me
			who = event_target:heretic_to_target
			years = 5
		}

		piety = -50

		ai_chance = {
			factor = 10

			trigger = {
				OR = {
					trait = cynical
					trait = excommunicated
				}
			}
		}
	}
}

# Vassal disappointed in liege having heretic advisor - Setup
character_event = {
	id = 39444

	is_triggered_only = yes # on_yearly_pulse, random_events, heretic_advisor
	hide_window = yes

	lacks_dlc = "Sons of Abraham"
	only_playable = yes
	religion_group = christian

	trigger = {
		is_heretic = no

		any_voter = {
			is_heretic = yes
			religion_group = christian
			prisoner = no
		}

		any_vassal = {
			religion = ROOT
			is_adult = yes
			is_incapable = no
			prisoner = no

			NOT = {
				has_opinion_modifier = {
					name = opinion_disappointed
					who = ROOT
				}
			}
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				religion = ROOT
				is_adult = yes
				is_incapable = no
				prisoner = no

				NOT = {
					has_opinion_modifier = {
						name = opinion_disappointed
						who = ROOT
					}
				}
			}

			preferred_limit = { trait = zealous }
			preferred_limit = { NOT = {trait = cynical } }

			character_event = { id = 39445 }
		}
	}
}

# Vassal disappointed in liege having heretic advisor
character_event = {
	id = 39445
	desc = EVTDESC39445
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39445

		liege = {
			letter_event = { id = 39446 }
		}
	}

	option = {
		name = EVTOPTB39445
	}
}

# Vassal lets the liege know about his disappointment
letter_event = {
	id = 39446
	desc = EVTDESC39446
	border = GFX_event_letter_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39446

		reverse_opinion = {
			name = opinion_disappointed
			who = FROM
			years = 5
		}
	}
}

# Heresy spreads to a neighboring province
province_event = {
	id = 39001
	desc = EVTDESC39001
	picture = GFX_evt_stone_church
	border = GFX_event_normal_frame_religion

	lacks_dlc = "Sons of Abraham"

	trigger = {
		is_heretic = no
		has_heresies = yes
		owner = { is_heretic = no }

		NOR = {
			province_id = c_roma
			province_id = c_thrake
			province_id = c_mecca
		}

		any_neighbor_province = {
			has_owner = yes
			is_heresy_of = ROOT
		}
	}

	mean_time_to_happen = {
		years = 100

		mult_modifier = {
			factor = 2

			has_game_rule = {
				name = religious_conversion
				value = slower
			}
		}

		mult_modifier = {
			factor = 2.0
			religion_authority >= 0.6
		}

		mult_modifier = {
			factor = 2.0
			religion_authority >= 0.8
		}

		mult_modifier = {
			factor = 0.75
			NOT = { religion_authority >= 0.2 }
		}

		mult_modifier = {
			factor = 0.75
			NOT = { religion_authority >= 0.4 }
		}

		mult_modifier = {
			factor = 0.75

			any_neighbor_province = {
				has_owner = yes
				is_heresy_of = ROOT

				ROOT = {
					any_neighbor_province = {
						has_owner = yes
						is_heresy_of = ROOT
						NOT = { province_id = PREVPREV }
					}
				}
			}
		}

		mult_modifier = {
			factor = 0.5

			any_neighbor_province = {
				has_owner = yes
				is_heresy_of = ROOT
				has_province_modifier = heretic_stronghold
			}
		}
	}

	immediate = {
		random_neighbor_province = {
			limit = { is_heresy_of = ROOT }
			reverse_religion = ROOT
		}
	}

	option = {
		name = EVTOPTA39001

		owner = {
			show_scope_change = no

			if = {
				limit = { is_parent_religion = ROOT }
				piety = -10
			}
		}
	}
}

# Character picks up the provincial heresy
character_event = {
	id = 39010
	desc = EVTDESC39010
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # on_yearly_pulse, random_events, convert_heresy

	lacks_dlc = "Sons of Abraham"
	min_age = 16
	only_capable = yes
	prisoner = no

	trigger = {
		is_parent_religion = location
		is_heretic = no

		trigger_if = {
			limit = { is_ruler = yes }
			is_theocracy = no
		}

		can_change_religion = yes
		is_inaccessible_trigger = no
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 4
			trait = cynical
		}

		mult_modifier = {
			factor = 0.2
			trait = zealous
		}

		mult_modifier = {
			factor = 0.5
			religion_authority >= 0.6
		}

		mult_modifier = {
			factor = 0.5
			religion_authority >= 0.8
		}

		mult_modifier = {
			factor = 1.33
			NOT = { religion_authority >= 0.2 }
		}

		mult_modifier = {
			factor = 1.33
			NOT = { religion_authority >= 0.4 }
		}
	}

	option = {
		name = EVTOPTA39010

		religion = location
	}

	option = {
		name = EVTOPTB39010

		ai_chance = { factor = 0 }
	}
}

# Heretic character attempts to spread the faith
character_event = {
	id = 39020
	desc = EVTDESC39020
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # on_yearly_pulse, random_events, courtier_conversion

	lacks_dlc = "Sons of Abraham"
	min_age = 16
	only_capable = yes
	prisoner = no

	trigger = {
		is_ruler = no
		is_heretic = yes

		employer = {
			NOT = { religion = ROOT }
		}

		any_courtier = {
			is_adult = yes
			is_parent_religion = ROOT
			is_heretic = no
			is_incapable = no
			prisoner = no

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

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 0.1
			trait = cynical
		}

		mult_modifier = {
			factor = 4
			trait = zealous
		}

		mult_modifier = {
			factor = 2
			trait = diligent
		}

		mult_modifier = {
			factor = 0.33
			trait = slothful
		}

		mult_modifier = {
			factor = 0.5
			NOT = { religion_authority >= 0.2 }
		}

		mult_modifier = {
			factor = 0.5
			NOT = { religion_authority >= 0.4 }
		}

		mult_modifier = {
			factor = 1.33
			religion_authority >= 0.6
		}

		mult_modifier = {
			factor = 1.33
			religion_authority >= 0.8
		}
	}

	option = {
		name = EVTOPTA39020

		random_courtier = {
			limit = {
				is_adult = yes
				is_parent_religion = ROOT
				is_heretic = no
				is_incapable = no
				prisoner = no

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

			character_event = {
				id = 39021
				tooltip = EVTTOOLTIP39021
			}
		}
	}
}

# A heretic character approaches me
character_event = {
	id = 39021
	desc = EVTDESC39021
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39021 # Embrace the heresy

		FROM = {
			character_event = {
				id = 39022
				days = 4
			}

			# Workaround for automatic usurption of theocratic characters
			religion_scope = {
				save_event_target_as = target_religion
			}
		}

		convert_religion_failsafe_effect = yes

		ai_chance = {
			factor = 25

			mult_modifier = {
				factor = 0.5
				independent = yes
			}

			mult_modifier = {
				factor = 0.25
				higher_real_tier_than = DUKE
			}

			mult_modifier = {
				factor = 0.25
				real_tier = EMPEROR
			}
		}
	}

	option = {
		name = EVTOPTB39021 # Demand abandonment of heresy
		tooltip_info = diplomacy

		trigger = {
			is_liege_of = FROM
			diplomacy >= 6
		}

		FROM = {
			character_event = {
				id = 39023
				days = 3
			}
		}

		ai_chance = { factor = 25 }
	}

	option = {
		name = EVTOPTC39021 # Have the heretic jailed!

		trigger = {
			is_liege_of = FROM

			OR = {
				trait = wroth
				trait = zealous
				trait = lunatic
			}

			trigger_if = {
				limit = { is_close_relative = FROM }
				trait = lunatic
			}
		}

		piety = 10

		FROM = {
			character_event = {
				id = 39024
				days = 2
			}
		}

		ai_chance = {
			factor = 25

			mult_modifier = {
				factor = 10
				trait = zealous
			}
		}
	}

	option = {
		name = EVTOPTD39021 # Just say no

		FROM = {
			character_event = {
				id = 39025
				days = 4
			}
		}

		ai_chance = { factor = 25 }
	}
}

# The heretic succeeded
character_event = {
	id = 39022
	desc = EVTDESC39022
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39022 # Good news!

		piety = 10

		opinion = {
			name = opinion_successful_conversion
			who = FROM
			years = 5
		}
	}
}

# The heretic is asked to abandon the heresy
character_event = {
	id = 39023
	desc = EVTDESC39023
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39023 # Never!

		FROM = {
			character_event = {
				id = 39025
				days = 4
			}
		}
	}

	option = {
		name = EVTOPTB39023 # Very well

		religion = FROM

		FROM = {
			character_event = {
				id = 39026
				days = 4
			}
		}
	}
}

# Guards come to arrest the heretic
character_event = {
	id = 39024
	desc = EVTDESC39024
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39024 # Accept judgement

		opinion = {
			name = opinion_betrayed
			who = FROM
			years = 10
		}

		imprison = FROM
	}

	option = {
		name = EVTOPTB39024 # Attempt to escape
		tooltip_info = intrigue

		trigger = { intrigue >= 6 }

		opinion = {
			name = opinion_betrayed
			who = FROM
			years = 10
		}

		random_list = {
			67 = { imprison = FROM }
			33 = { banish = yes }
		}
	}
}

# One character failed to convert the other
character_event = {
	id = 39025
	desc = EVTDESC39025
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39025

		opinion = {
			name = opinion_failed_conversion
			who = FROM
			years = 2
		}
	}
}

# The heretic accepts reconversion
character_event = {
	id = 39026
	desc = EVTDESC39026
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39026

		piety = 10

		opinion = {
			name = opinion_successful_conversion
			who = FROM
			years = 5
		}
	}
}

########################################
# Formation of the Orders
########################################

# Formation of the Knights of St John
narrative_event = {
	id = 39100
	title = EVTNAME39100
	desc = EVTDESC39100
	picture = GFX_evt_crusaders
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	hide_from = yes

	only_playable = yes
	has_global_flag = christian_crusades_unlocked
	religion_group = christian

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

		is_catholic_branch = yes
		is_heretic = no
		NOT = { is_title_active = d_knights_hospitaller }

		trigger_if = {
			limit = { year < 1113 } # Historical

			OR = {
				c_provence = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_toulouse = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_paris = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_koln = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_braunschweig = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				e_byzantium = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_constantinopolis = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_ancyra = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_roma = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				AND = {
					c_atheniai = {
						holder_scope = {
							NOT = { religion_group = christian }
						}
					}

					c_korinthos = {
						holder_scope = {
							NOT = { religion_group = christian }
						}
					}
				}
			}
		}
	}

	major_trigger = { ai = no }

	immediate = {
		activate_title = {
			title = d_knights_hospitaller
			status = yes
		}

		create_random_soldier = {
			dynasty = none
			random_traits = yes
			religion = ROOT
		}

		new_character = {
			d_knights_hospitaller = {
				religion = PREV
				grant_title = PREV
			}

			set_defacto_liege = THIS
			wealth = 500
			set_government_type = order_government
		}

		religion_authority = {
			name = religious_order_formed
			years = 10
		}
	}

	option = {
		name = {
			text = EVTOPTA39100
			trigger = { religion = ROOT }
		}
		name = {
			text = EVTOPTB39100
			trigger = {
				NOT = { religion_group = christian }
			}
		}
		name = {
			text = EVTOPTC39100
			trigger = {
				religion_group = christian
				NOT = { religion = ROOT }
			}
		}
	}
}

# Formation of the Knights Templar
narrative_event = {
	id = 39101
	title = EVTNAME39101
	desc = EVTDESC39101
	picture = GFX_evt_crusaders
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	hide_from = yes

	only_playable = yes
	has_global_flag = christian_crusades_unlocked
	religion_group = christian

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

		is_catholic_branch = yes
		is_heretic = no
		NOT = { is_title_active = d_knights_templar }
		year < 1312

		trigger_if = {
			limit = { year < 1118 } # Historical

			OR = {
				e_byzantium = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_constantinopolis = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_ancyra = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_roma = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				AND = {
					c_atheniai = {
						holder_scope = {
							NOT = { religion_group = christian }
						}
					}

					c_korinthos = {
						holder_scope = {
							NOT = { religion_group = christian }
						}
					}
				}
			}
		}
	}

	major_trigger = { ai = no }

	immediate = {
		activate_title = {
			title = d_knights_templar
			status = yes
		}

		create_random_soldier = {
			dynasty = none
			random_traits = yes
			religion = ROOT
		}

		new_character = {
			d_knights_templar = {
				religion = PREV
				grant_title = PREV
			}

			set_defacto_liege = THIS
			wealth = 600
			set_government_type = order_government
		}

		religion_authority = {
			name = religious_order_formed
			years = 10
		}
	}

	option = {
		name = {
			text = EVTOPTA39101
			trigger = { religion = ROOT }
		}
		name = {
			text = EVTOPTB39101
			trigger = {
				NOT = { religion_group = christian }
			}
		}
		name = {
			text = EVTOPTC39100
			trigger = {
				religion_group = christian
				NOT = { religion = ROOT }
			}
		}
	}
}

# Formation of the Teutonic Order
narrative_event = {
	id = 39102
	title = EVTNAME39102
	desc = EVTDESC39102
	picture = GFX_evt_crusaders
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	hide_from = yes

	only_playable = yes
	has_global_flag = christian_crusades_unlocked
	religion_group = christian

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

		is_catholic_branch = yes
		is_heretic = no

		NOR = {
			is_title_active = d_teutonic_order
			is_title_active = k_teutonic_state
		}

		trigger_if = {
			limit = { year < 1192 } # Historical

			OR = {
				c_provence = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_toulouse = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_paris = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_koln = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}

				c_braunschweig = {
					holder_scope = {
						NOT = { religion_group = christian }
					}
				}
			}
		}
	}

	major_trigger = { ai = no }

	immediate = {
		activate_title = {
			title = d_teutonic_order
			status = yes
		}

		create_random_soldier = {
			dynasty = none
			random_traits = yes
			religion = ROOT
		}

		new_character = {
			d_teutonic_order = {
				religion = PREV
				grant_title = PREV
			}

			set_defacto_liege = THIS
			wealth = 500
			set_government_type = order_government
		}

		religion_authority = {
			name = religious_order_formed
			years = 10
		}
	}

	option = {
		name = {
			text = EVTOPTA39102
			trigger = { religion = ROOT }
		}
		name = {
			text = EVTOPTB39102
			trigger = {
				NOT = { religion_group = christian }
			}
		}
		name = {
			text = EVTOPTC39100
			trigger = {
				religion_group = christian
				NOT = { religion = ROOT }
			}
		}
	}
}

########################################
# PAPAL EVENTS
########################################

# The Pope gives money to someone fighting the Infidel
character_event = {
	id = 39200
	desc = EVTDESC39200
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_religion
	portrait = event_target:target_ruler

	is_triggered_only = yes # on_yearly_pulse, random_events, pope_events

	only_playable = yes
	religion_group = christian
	min_age = 16
	war = no

	trigger = {
		controls_religion = yes
		is_catholic_branch = yes
		wealth >= 500

		any_playable_ruler = {
			religion = ROOT
			wealth < 500
			rightful_religious_head = ROOT

			NOR = {
				excommunicated_for = ROOT
				war_with = ROOT
			}

			any_current_enemy = {
				NOT = { religion_group = PREV }
			}

			reverse_opinion = {
				who = ROOT
				value >= 0
			}

			trigger_if = {
				limit = { has_character_flag = money_from_the_pope }

				OR = {
					had_character_flag = {
						flag = money_from_the_pope
						years >= 2
					}

					AND = {
						ai = yes

						had_character_flag = {
							flag = money_from_the_pope
							years >= 1
						}

						any_war = {
							using_cb = religious

							OR = {
								attacker = {
									character = PREVPREV
									war_score < -15
								}

								defender = {
									character = PREVPREV
									war_score >= 15
								}
							}
						}
					}
				}
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 2
			wealth >= 1000
		}

		mult_modifier = {
			factor = 2
			wealth >= 2000
		}
	}

	immediate = {
		random_playable_ruler = {
			limit = {
				religion = ROOT
				wealth < 500
				rightful_religious_head = ROOT

				NOR = {
					excommunicated_for = ROOT
					war_with = ROOT
				}

				any_current_enemy = {
					NOT = { religion_group = PREV }
				}

				reverse_opinion = {
					who = ROOT
					value >= 0
				}

				trigger_if = {
					limit = { has_character_flag = money_from_the_pope }

					OR = {
						had_character_flag = {
							flag = money_from_the_pope
							years >= 2
						}

						AND = {
							ai = yes

							had_character_flag = {
								flag = money_from_the_pope
								years >= 1
							}

							any_war = {
								using_cb = religious

								OR = {
									attacker = {
										character = PREVPREV
										war_score < -15
									}

									defender = {
										character = PREVPREV
										war_score >= 15
									}
								}
							}
						}
					}
				}
			}

			save_event_target_as = target_ruler
		}
	}

	option = {
		name = EVTOPTA39200

		event_target:target_ruler = {
			show_scope_change = no

			tooltip = {
				transfer_scaled_wealth = {
					from = ROOT
					value = 1
					min = 200
					max = 200
				}
			}

			letter_event = {
				id = 39201
				tooltip = EVTTOOLTIP39201
			}
		}
	}

	option = {
		name = EVTOPTB39200

		ai_chance = { factor = 0 }
	}
}

letter_event = {
	id = 39201
	desc = EVTDESC39201
	border = GFX_event_letter_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39201

		transfer_scaled_wealth = {
			from = FROM
			value = 1
			min = 200
			max = 200
		}

		set_character_flag = money_from_the_pope
	}
}

# Pope offers absolution for Kinslaying - Setup
character_event = {
	id = 39209

	is_triggered_only = yes # on_bi_yearly_pulse
	hide_window = yes

	only_playable = yes
	religion_group = christian

	trigger = {
		is_catholic_branch = yes
		is_any_kinslayer_trigger = yes
		piety >= 100

		NOR = {
			trait = tribal_kinslayer
			has_character_flag = kinslaying_offered
		}

		rightful_religious_head_scope = {
			NOT = { has_character_modifier = pope_kinslaying_timer }
			is_incapable = no
			prisoner = no
			war = no

			reverse_opinion = {
				who = ROOT
				value >= 0
			}
		}
	}

	immediate = {
		rightful_religious_head_scope = {
			add_character_modifier = {
				name = pope_kinslaying_timer
				years = 2
				hidden = yes
			}

			character_event = { id = 39210 }
		}
	}
}

# Pope offers absolution for Kinslaying
character_event = {
	id = 39210
	desc = EVTDESC39210
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39210

		FROM = {
			show_scope_change = no

			set_character_flag = kinslaying_offered

			character_event = {
				id = 39211
				tooltip = EVTTOOLTIP39211
			}
		}
	}

	option = {
		name = EVTOPTB39210 # In case someone plays the pope.. players will mod it in, so might as well give them a fun option here..

		ai_chance = { factor = 0 }
	}
}

character_event = {
	id = 39211
	desc = EVTDESC39211
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39211

		trigger_switch = {
			on_trigger = trait

			kinslayer = {
				piety = -100
				wealth = -50
				remove_trait = kinslayer
			}

			familial_kinslayer = {
				piety  = -50
				wealth = -25
				remove_trait = familial_kinslayer
			}

			dynastic_kinslayer = {
				piety  = -25
				wealth = -12
				remove_trait = dynastic_kinslayer
			}
		}

		FROM = {
			show_scope_change = no

			character_event = {
				id = 39212
				days = 1
				tooltip = EVTTOOLTIP39212
			}
		}
	}

	option = {
		name = EVTOPTB39211

		add_trait_fully_silently_cynical_effect = yes

		FROM = {
			show_scope_change = no

			character_event = {
				id = 39213
				days = 1
				tooltip = EVTTOOLTIP39213
			}
		}

		ai_chance = { factor = 0 }
	}
}

character_event = {
	id = 39212
	desc = EVTDESC39212
	picture = GFX_evt_knight_kneeling
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = GLORY_TO_HIGHGOD

		prestige = 10
	}
}

character_event = {
	id = 39213
	desc = EVTDESC39213
	picture = GFX_evt_torture
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39213

		prestige = -10
	}
}

########################################
# Bishops don't like being in prison events...
########################################

# Catholic Chain - Setup
character_event = {
	id = 39219

	is_triggered_only = yes # on_become_imprisoned_any_reason
	hide_window = yes

	only_playable = yes
	religion_group = christian

	trigger = {
		is_catholic_branch = yes
		is_theocracy = yes
		is_antipope = no
		controls_religion = no
		NOT = { has_character_flag = nag_pope_to_help_me }

		host = {
			religion = ROOT

			rightful_religious_head_scope = {
				controls_religion = yes
			}
		}

		# Don't grovel if we dont like the Pope
		religion_head = {
			reverse_opinion = {
				who = ROOT
				value >= 25
			}
		}
	}

	immediate = {
		if = {
			limit = {
				calc_true_if = {
					amount >= 2

					trait = zealous
					piety >= 25

					religion_head = {
						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}
				}
			}

			character_event = {
				id = 39220
				days = 14
				random = 60
			}
		}
		else_if = {
			limit = {
				OR = {
					trait = zealous
					piety >= 25

					religion_head = {
						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}
				}
			}

			character_event = {
				id = 39220
				months = 1
				random = 90
			}
		}
		else = {
			character_event = {
				id = 39220
				months = 3
				random = 180
			}
		}
	}
}

# Bishop in prison whines to pope..
character_event = {
	id = 39220
	desc = EVTDESC39220
	picture = GFX_evt_into_the_dungeon
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	only_playable = yes
	religion_group = christian
	prisoner = yes

	trigger = {
		is_catholic_branch = yes
		is_theocracy = yes
		is_antipope = no
		controls_religion = no

		host = {
			religion = ROOT

			rightful_religious_head_scope = {
				controls_religion = yes
			}
		}

		NOT = { has_character_flag = nag_pope_to_help_me }
	}

	immediate = {
		set_character_flag = nag_pope_to_help_me
	}

	option = {
		name = EVTOPTA39220 # Write a letter to the Pope

		religion_head = {
			show_scope_change = no

			character_event = {
				id = 39221
				days = 5
				random = 10
				tooltip = EVTTOOLTIP39221
			}
		}

		host = {
			show_scope_change = no

			if = {
				limit = { realm_intrigue >= 15 }

				random = {
					chance = 25

					character_event = {
						id = 39222
						days = 3
						tooltip = EVTTOOLTIP39222
					}
				}
			}
		}
	}

	option = {
		name = EVTOPTB39220 # Pray for Divine Help

		piety = 10

		host = {
			character_event = {
				id = 39223
				days = 5
			}
		}
	}
}

# Pope gets letter
character_event = {
	id = 39221
	desc = EVTDESC39221
	picture = GFX_evt_into_the_dungeon
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39221 # Try to help bishop

		FROM = {
			show_scope_change = no

			character_event = {
				id = 39224
				days = 5
				random = 10
				tooltip = EVTTOOLTIP39224
			}
		}

		prestige = 5
	}

	option = {
		name = EVTOPTB39221 # Not my problem

		FROM = {
			show_scope_change = no

			tooltip = {
				opinion = {
					name = opinion_disappointed
					who = ROOT
					years = 2
				}
			}

			character_event = {
				id = 39225
				days = 5
				random = 10
				tooltip = EVTTOOLTIP39225
			}
		}

		religion_authority = {
			name = head_of_religion_neglect
			years = 10
		}

		prestige = -5

		ai_chance = { factor = 0 }
	}
}

# We discover bishop writing to Pope
character_event = {
	id = 39222
	desc = EVTDESC39222
	picture = GFX_evt_recieve_letter
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39222 # Kill

		trigger = {
			OR = {
				trait = cruel
				trait = impaler
				trait = wroth
			}
		}

		piety = -50

		FROM = {
			show_scope_change = no

			death = {
				death_reason = death_execution
				killer = ROOT
			}
		}
	}

	option = {
		name = EVTOPTB39222 # This is bad news

		trigger = {
			NOR = {
				trait = cruel
				trait = impaler
				trait = wroth
			}
		}

		piety = -5
	}
}

# Pious bishop praying for it..
character_event = {
	id = 39223
	desc = EVTDESC39223
	picture = GFX_evt_into_the_dungeon
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39223 # Kind and release him

		trigger = {
			NOR = {
				trait = cruel
				trait = impaler
				trait = wroth
				trait = cynical
			}
		}

		piety = 10

		FROM = {
			show_scope_change = no

			imprison = no
			clr_character_flag = nag_pope_to_help_me
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 100
				trait = kind
			}
		}
	}

	option = {
		name = EVTOPTB39223 # Nopes

		piety = -5

		ai_chance = { factor = 10 }
	}
}

# Bishop hears pope is helping him
character_event = {
	id = 39224
	desc = EVTDESC39224
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		host = {
			show_scope_change = no

			character_event = {
				id = 39226
				days = 1
				random = 2
				tooltip = EVTTOOLTIP39226
			}
		}
	}

	option = {
		name = EVTOPTA39224 # Good news

		piety = 1
	}
}

# Bad news, pope tells you no
character_event = {
	id = 39225
	desc = EVTDESC39225
	picture = GFX_evt_knight_kneeling
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39225 # Bad news

		piety = -5

		opinion = {
			name = opinion_disappointed
			who = FROM
			years = 2
		}
	}
}

# Deal with papal demands
character_event = {
	id = 39226
	desc = EVTDESC39226
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39226 # Let him go

		FROM = {
			show_scope_change = no

			imprison = no
			clr_character_flag = nag_pope_to_help_me
		}

		piety = 10

		religion_authority = {
			name = ruler_bowed_to_pope
			years = 10
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 100
				trait = kind
			}
		}
	}

	option = {
		name = EVTOPTB39226 # No

		trigger = {
			NOT = { trait = zealous }
		}

		piety = -25

		religion_authority = {
			name = ruler_defied_pope
			years = 10
		}

		religion_head = {
			show_scope_change = no

			opinion = {
				name = opinion_ignore_papal_demands
				who = ROOT
				years = 2
			}
		}

		ai_chance = {
			factor = 2

			mult_modifier = {
				factor = 20

				opinion = {
					who = FROM
					value < 20
				}
			}
		}
	}
}

# Orthodox Chain - Setup
character_event = {
	id = 39229

	is_triggered_only = yes # on_become_imprisoned_any_reason
	hide_window = yes

	only_rulers = yes
	religion_group = christian

	trigger = {
		is_theocracy = yes
		is_orthodox_branch = yes
		religion_authority >= 0.02

		host = {
			religion = ROOT
			rightful_religious_head_scope = { always = yes }
		}
	}

	immediate = {
		clear_delayed_event = { id = 39230 }

		host = {
			if = {
				limit = {
					calc_true_if = {
						amount >= 2

						trait = just
						trait = zealous
						religion_authority >= 0.25
						religion_authority >= 0.50
					}
				}

				character_event = {
					id = 39230
					days = 100
					random = 30
				}
			}
			else_if = {
				limit = {
					OR = {
						trait = just
						trait = zealous
						religion_authority >= 0.25
					}
				}

				character_event = {
					id = 39230
					days = 100
					random = 90
				}
			}
			else = {
				character_event = {
					id = 39230
					days = 100
					random = 180
				}
			}
		}
	}
}

# Orthodox & We got a bishop in jail.
character_event = {
	id = 39230
	desc = EVTDESC39230
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # on_yearly_pulse, random_events

	only_playable = yes
	religion_group = christian

	trigger = {
		is_orthodox_branch = yes
		religion_authority >= 0.02
		rightful_religious_head_scope = { always = yes }

		FROM = {
			prisoner = yes
			religion = ROOT
			is_theocracy = yes
			is_ruler = yes
			host = { character = ROOT }
		}
	}

	option = {
		name = EVTOPTA39230 # Let him go

		FROM = {
			show_scope_change = no

			imprison = no
		}

		religion_authority = {
			name = ruler_bowed_to_patriarch
			years = 10
		}

		piety = 10
	}

	option = {
		name = EVTOPTB39230 # Refuse

		piety = -25
		prestige = -25

		religion_authority = {
			name = ruler_defied_patriarch
			years = 10
		}
	}
}

########################################################################
# Religious Head does not like it when you have heathens in your employ
########################################################################

# CleanSlate: Orthodox variant merged with Catholic variant
# Pope/Patriarch demands that a ruler not have heathens employed. - Setup
character_event = {
	id = 39239

	is_triggered_only = yes # on_yearly_pulse, random_events, heretic_advisor
	hide_window = yes

	only_playable = yes
	religion_group = christian

	trigger = {
		religion_authority >= 0.20
		NOT = { has_character_flag = pope_dislikes_heathen_employed }

		OR = {
			is_catholic_branch = yes
			is_orthodox_branch = yes
		}

		rightful_religious_head_scope = {
			is_incapable = no
			prisoner = no
			war = no
		}

		any_voter = {
			prisoner = no
			NOT = { religion_group = christian }
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 4
			rightful_religious_head_scope = { trait = zealous }
		}
	}

	immediate = {
		rightful_religious_head_scope = {
			character_event = { id = 39240 }
		}
	}
}

# Pope/Patriarch demands that a ruler not have heathens employed.
character_event = {
	id = 39240
	desc = EVTDESC39240
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = { # Ask them
		name = {
			text = EVTOPTA39240
			trigger = { is_catholic_branch = yes }
		}
		name = {
			text = EVTOPTA39260
			trigger = { is_orthodox_branch = yes }
		}

		FROM = {
			show_scope_change = no

			set_character_flag = pope_dislikes_heathen_employed

			if = {
				limit = { is_catholic_branch = yes }
				custom_tooltip = { text = EVTTOOLTIP39241 }
			}
			else = {
				custom_tooltip = { text = EVTTOOLTIP39261 }
			}

			character_event = {
				id = 39241
				days = 14
			}
		}
	}

	option = {
		name = EVTOPTB39240 # Ignore it

		religion_authority = {
			name = head_of_religion_neglect
			years = 10
		}

		ai_chance = { factor = 0 }
	}
}

# Demands is coming on us about
character_event = {
	id = 39241
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion

	desc = {
		text = EVTDESC39241
		trigger = { is_catholic_branch = yes }
	}
	desc = {
		text = EVTDESC39261
		trigger = { is_orthodox_branch = yes }
	}

	is_triggered_only = yes

	immediate = {
		random_voter = {
			limit = {
				NOT = { religion_group = christian }
			}

			save_event_target_as = heathen_to_target
		}
	}

	option = {
		name = EVTOPTA39241 # Banish

		clr_character_flag = pope_dislikes_heathen_employed

		reverse_banish = event_target:heathen_to_target

		FROM = {
			show_scope_change = no

			opinion = {
				name = pope_heathen_removal_approve
				who = ROOT
				years = 5
			}

			character_event = {
				id = 39242
				days = 1
			}
		}

		ai_chance = { factor = 2 }
	}

	option = {
		name = EVTOPTB39241 # Imprison
		tooltip_info = intrigue

		trigger = { realm_intrigue >= 15 }

		clr_character_flag = pope_dislikes_heathen_employed

		reverse_imprison = event_target:heathen_to_target

		FROM = {
			show_scope_change = no

			opinion = {
				name = pope_heathen_removal_approve_2
				who = ROOT
				years = 3
			}

			character_event = {
				id = 39243
				days = 1
			}
		}
	}

	option = {
		name = EVTOPTC39241 # Ignore Pope/Patriarch

		FROM = {
			show_scope_change = no

			if = {
				limit = { is_catholic_branch = yes }

				opinion = {
					name = opinion_ignore_papal_demands
					who = ROOT
					years = 5
				}
			}
			else = {
				opinion = {
					name = opinion_ignore_patriarch_request
					who = ROOT
					years = 5
				}
			}

			character_event = {
				id = 39244
				days = 1
			}
		}

		reverse_opinion = {
			name = opinion_defended_me
			who = event_target:heathen_to_target
			years = 5
		}

		piety = -50

		ai_chance = {
			factor = 1

			trigger = {
				OR = {
					trait = cynical
					trait = excommunicated
				}
			}
		}
	}
}

# They banished the heathen
character_event = {
	id = 39242
	desc = EVTDESC39242
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = GLORY_TO_HIGHGOD

		prestige = 10
	}
}

# They imprisoned the heathen
character_event = {
	id = 39243
	desc = EVTDESC39243
	picture = GFX_evt_into_the_dungeon
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = GLORY_TO_HIGHGOD

		prestige = 5
	}
}

# They ignored us
character_event = {
	id = 39244
	desc = EVTDESC39244
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39244

		prestige = -10
	}
}

###############################################################
# Interactions from decisions
###############################################################

# Character purchases indulgence
character_event = {
	id = 39250
	desc = EVTDESC39250
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # buy_indulgence_for_sins, realm_decisions.txt

	option = {
		name = EVTOPTA39250

		FROM = {
			show_scope_change = no

			character_event = {
				id = 39251
				days = 3
				random = 7
				tooltip = EVTTOOLTIP39251
			}
		}
	}
}

# Character gets approval
character_event = {
	id = 39251
	desc = EVTDESC39251
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = GLORY_TO_HIGHGOD

		if = {
			limit = { yearly_income > 25 }

			if = {
				limit = {
					reverse_opinion = {
						who = FROM
						value >= 75
					}
				}

				if = {
					limit = { piety >= 400 }
					scaled_wealth = -0.9
				}
				else = {
					scaled_wealth = -1.0
				}
			}
			else_if = {
				limit = {
					reverse_opinion = {
						who = FROM
						value >= 0
					}
				}

				if = {
					limit = { piety >= 400 }
					scaled_wealth = -1.15
				}
				else = {
					scaled_wealth = -1.25
				}
			}
			else_if = {
				limit = {
					reverse_opinion = {
						who = FROM
						value >= -75
					}
				}

				if = {
					limit = { piety >= 400 }
					scaled_wealth = -1.4
				}
				else = {
					scaled_wealth = -1.5
				}
			}
			else = {
				if = {
					limit = { piety >= 400 }
					scaled_wealth = -1.65
				}
				else = {
					scaled_wealth = -1.75
				}
			}
		}
		else = {
			wealth = -25
		}

		piety = 50

		reverse_opinion = {
			name = bought_indulgences
			who = FROM
			years = 5
		}
	}

	option = {
		name = EVTOPTB39251

		reverse_opinion = {
			name = refused_indulgences
			who = FROM
			years = 5
		}

		clr_character_flag = ask_for_indulgence

		ai_chance = { factor = 0 }
	}
}

# Character purchases lift of excommunication
# character_event = {
# 	id = 39252
# 	desc = EVTDESC39252
# 	picture = GFX_evt_emissary
# 	border = GFX_event_normal_frame_religion
#
# 	is_triggered_only = yes
#
# 	option = {
# 		name = EVTOPTA39252
#
# 		FROM = {
#			show_scope_change = no
#
# 			character_event = {
#				id = 39253
#				days = 3
#				random = 7
#				tooltip = EVTTOOLTIP39253
#			}
# 		}
# 	}
# }

# Character gets approval
# character_event = {
# 	id = 39253
# 	desc = EVTDESC39253
# 	picture = GFX_evt_pope
# 	border = GFX_event_normal_frame_religion
#
# 	is_triggered_only = yes
#
# 	option = {
# 		name = GLORY_TO_HIGHGOD
#
#		if = {
#			limit = {
#				reverse_opinion = {
#					who = FROM
#					value >= 75
#				}
#			}
#
#			if = {
#				limit = { piety >= 500 }
#				scaled_wealth = -1.9
#			}
#			else = {
#				scaled_wealth = -2.0
#			}
#		}
#		else_if = {
#			limit = {
#				reverse_opinion = {
#					who = FROM
#					value >= 0
#				}
#			}
#
#			if = {
#				limit = { piety >= 400 }
#				scaled_wealth = -2.15
#			}
#			else = {
#				scaled_wealth = -2.25
#			}
#		}
#		else_if = {
#			limit = {
#				reverse_opinion = {
#					who = FROM
#					value >= -75
#				}
#			}
#
#			if = {
#				limit = { piety >= 400 }
#				scaled_wealth = -2.4
#			}
#			else = {
#				scaled_wealth = -2.5
#			}
#		}
#		else = {
#			if = {
#				limit = { piety >= 400 }
#				scaled_wealth = -2.65
#			}
#			else = {
#				scaled_wealth = -2.75
#			}
#		}
#
# 		excommunicate = no
#
# 		FROM = {
#			show_scope_change = no
#
# 			opinion = {
# 				name = opinion_repented_sins
# 				who = ROOT
# 				years = 10
# 			}
# 		}
# 	}
#
# 	option = {
# 		name = EVTOPTB39253
#
# 		ai_chance = { factor = 0 }
#
# 		FROM = {
#			show_scope_change = no
#
# 			opinion = {
# 				name = refused_making_repentance
# 				who = ROOT
# 				years = 5
# 			}
# 		}
#	}
#
#	after = {
# 		clr_character_flag = ask_for_repentance
# 	}
# }

#####################################################################################
# You have a bishop as your vassal, and the the vassal likes you more than the pope.
#####################################################################################

character_event = {
	id = 39270
	desc = EVTDESC39270
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	portrait = event_target:target_ruler

	is_triggered_only = yes # on_yearly_pulse, random_events, pope_events

	only_playable = yes
	religion_group = christian
	min_age = 16
	only_capable = yes
	prisoner = no
	war = no

	trigger = {
		controls_religion = yes
		is_catholic_branch = yes
		religion_authority >= 0.30
		prestige >= 20

		any_playable_ruler = {
			religion = ROOT
			rightful_religious_head = ROOT

			OR = {
				is_feudal = yes
				is_tribal = yes
				is_nomadic = yes
			}

			any_vassal = {
				is_theocracy = yes
				religion = ROOT

				opinion = {
					who = liege
					value >= 50
				}

				opinion = {
					who = ROOT
					value < 20
				}
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 3
			trait = zealous
		}
	}

	immediate = {
		hidden_effect = {
			random_playable_ruler = {
				limit = {
					religion = ROOT
					rightful_religious_head = ROOT

					OR = {
						is_feudal = yes
						is_tribal = yes
						is_nomadic = yes
					}

					any_vassal = {
						is_theocracy = yes
						religion = ROOT

						opinion = {
							who = liege
							value >= 50
						}

						opinion = {
							who = ROOT
							value < 20
						}
					}
				}

				save_event_target_as = target_ruler
			}
		}
	}

	option = {
		name = EVTOPTA39270 # Ask them

		event_target:target_ruler = {
			show_scope_change = no

			character_event = {
				id = 39271
				tooltip = EVTTOOLTIP39271
			}
		}
	}

	option = {
		name = EVTOPTB39270 # Ignore it

		religion_authority = {
			name = head_of_religion_neglect
			years = 10
		}

		ai_chance = { factor = 0 }
	}
}

# Demands is coming on us about
character_event = {
	id = 39271
	desc = EVTDESC39271
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		random_vassal = {
			limit = {
				is_theocracy = yes
				religion = ROOT

				opinion = {
					who = liege
					value >= 50
				}

				opinion = {
					who = FROM
					value < 20
				}
			}

			save_event_target_as = loyal_bishop
		}

		# Added by CleanSlate, to replace horrendous mess in subsequent events
		FROM = {
			# Pope sends a new bishop, of his own culture, stays in Rome if ruler rejects demand
			create_random_priest = {
				random_traits = yes
				female = no
				dynasty = none
			}

			new_character = {
				# Some housekeeping
				remove_trait = lustful
				remove_trait = cynical
				remove_trait = greedy
				remove_trait = slothful
				remove_trait = wroth
				remove_trait = envious
				remove_trait = proud
				remove_trait = gluttonous

				remove_trait = slow
				remove_trait = imbecile
				remove_trait = dull
				remove_trait = mystic
				remove_trait = socializer
				remove_trait = game_master
				remove_trait = hedonist
				remove_trait = duelist
				remove_trait = hunter
				remove_trait = strategist
				remove_trait = administrator
				remove_trait = architect
				remove_trait = gardener
				remove_trait = master_schemer
				remove_trait = master_seducer
				remove_trait = master_seductress

				add_trait = celibate

				save_event_target_as = new_bishop
			}
		}
	}

	option = {
		name = EVTOPTA39271 # Replace him

		show_portrait = event_target:new_bishop

		event_target:loyal_bishop = {
			show_scope_change = no

			abdicate_to = event_target:new_bishop
		}

		piety = 50

		FROM = {
			character_event = {
				id = 39272
				days = 13
			}
		}

		ai_chance = {
			factor = 1

			trigger = {
				event_target:loyal_bishop = {
					demesne_size < 2
					real_tier = BARON
				}
			}

			mult_modifier = {
				factor = 2
				trait = zealous
			}
		}
	}

	option = {
		name = EVTOPTB39271 # Ignore the demand

		piety = -50

		FROM = {
			character_event = {
				id = 39273
				days = 13
			}
		}
	}
}

# This was good
character_event = {
	id = 39272
	desc = EVTDESC39272
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39272

		prestige = 5
	}
}

# This was bad
character_event = {
	id = 39273
	desc = EVTDESC39273
	picture = GFX_evt_spymaster
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39273

		prestige = -20
	}
}

###############################################################
# Orthodox flavour: Icons!
###############################################################

character_event = {
	id = 39300
	picture = GFX_evt_icon
	border = GFX_event_normal_frame_religion

	desc = {
		text = EVTDESC39300
		trigger = { has_character_flag = commisioned_icon_mary }
	}
	desc = {
		text = EVTDESC39301
		trigger = { has_character_flag = commisioned_icon_christ }
	}
	desc = {
		text = EVTDESC39302
		trigger = { has_character_flag = commisioned_icon_peter }
	}
	desc = {
		text = EVTDESC39303
		trigger = { has_character_flag = commisioned_icon_john }
	}
	desc = {
		text = EVTDESC39304
		trigger = { has_character_flag = commisioned_icon_george }
	}

	is_triggered_only = yes # on_yearly_pulse, random_events, orthodox_icons

	only_playable = yes
	religion = orthodox
	min_age = 16
	prisoner = no
	only_capable = yes

	trigger = {
		is_heretic = no

		NOR = {
			trait = cynical
			has_character_flag = commisioned_icon
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 1.25
			trait = zealous
		}

		mult_modifier = {
			factor = 1.25
			piety >= 100
		}

		mult_modifier = {
			factor = 1.25
			trait = kind
		}
	}

	immediate = {
		random_list = {
			20 = { set_character_flag = commisioned_icon_mary }   # Icon of Mary, Mother of God
			20 = { set_character_flag = commisioned_icon_christ } # Icon of Christ Pantocrator
			20 = { set_character_flag = commisioned_icon_peter }  # Icon of St.Peter
			20 = { set_character_flag = commisioned_icon_john }   # Icon of John the Baptist
			20 = { set_character_flag = commisioned_icon_george } # Icon of Saint George
		}
	}

	option = { # Yes Please
		name = {
			text = EVTOPTA39300
			trigger = { has_character_flag = commisioned_icon_mary }
		}
		name = {
			text = EVTOPTA39301
			trigger = { has_character_flag = commisioned_icon_christ }
		}
		name = {
			text = EVTOPTA39302
			trigger = { has_character_flag = commisioned_icon_peter }
		}
		name = {
			text = EVTOPTA39303
			trigger = { has_character_flag = commisioned_icon_john }
		}
		name = {
			text = EVTOPTA39304
			trigger = { has_character_flag = commisioned_icon_george }
		}

		scaled_wealth = -0.25
		change_intrigue = 1
		set_character_flag = commisioned_icon
	}

	option = {
		name = EVTOPTB39300 # No

		piety = -25
		remove_trait_silently_zealous_effect = yes
	}
}

########################################
# A True Knight of Christendom
########################################

# True Knight
character_event = {
	id = 39310
	desc = EVTDESC39310
	picture = GFX_evt_melee
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # on_yearly_pulse, random_events, true_christian_knight

	religion_group = christian
	only_men = yes
	min_age = 16
	only_capable = yes

	trigger = {
		is_wicked = no
		is_heretic = no
		martial >= 8
		piety >= 25
		trait = humble
		trait = diligent
		trait = brave

		NOR = {
			trait = cynical
			trait = cruel
			has_character_modifier = true_christian_knight
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 1.33
			trait = zealous
		}

		mult_modifier = {
			factor = 1.33
			trait = crusader
		}

		mult_modifier = {
			factor = 1.33
			piety >= 100
		}
	}

	option = {
		name = EVTOPTA39310

		add_character_modifier = {
			name = true_christian_knight
			duration = -1
		}

		set_character_flag = true_christian_knight

		prestige = 50
	}
}

# Losing status
character_event = {
	id = 39311
	desc = EVTDESC39311
	picture = GFX_evt_knight_kneeling
	border = GFX_event_normal_frame_religion

	has_character_flag = true_christian_knight
	only_men = yes
	min_age = 16

	trigger = {
		has_character_modifier = true_christian_knight

		OR = {
			NOT = { religion_group = christian }
			is_heretic = yes
			has_vice_trigger = yes
			trait = cynical
			trait = cruel
			trait = craven
		}
	}

	mean_time_to_happen = {
		days = 5
	}

	option = {
		name = EVTOPTA39311

		remove_character_modifier = true_christian_knight
		clr_character_flag = true_christian_knight
		prestige = -50
	}
}

# County population converts to Islam
province_event = {
	id = 39500
	desc = EVTDESC39500
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	trigger = {
		NOT = { religion_group = muslim }

		owner = {
			religion_group = muslim
			religion_group = top_liege
		}
	}

	mean_time_to_happen = {
		years = 300

		mult_modifier = {
			factor = 0.8
			religion_authority >= 0.6
		}

		mult_modifier = {
			factor = 0.8
			religion_authority >= 0.7
		}

		mult_modifier = {
			factor = 0.8
			religion_authority >= 0.8
		}

		mult_modifier = {
			factor = 0.8
			religion_authority >= 0.9
		}

		mult_modifier = {
			factor = 1.25
			NOT = { religion_authority >= 0.5 }
		}

		mult_modifier = {
			factor = 1.25
			NOT = { religion_authority >= 0.4 }
		}

		mult_modifier = {
			factor = 1.25
			NOT = { religion_authority >= 0.3 }
		}

		mult_modifier = {
			factor = 1.25
			NOT = { religion_authority >= 0.2 }
		}

		mult_modifier = {
			factor = 0.5
			owner = { trait = zealous }
		}

		mult_modifier = {
			factor = 2.0
			owner = { trait = cynical }
		}

		mult_modifier = {
			factor = 2.0

			NOT = {
				any_neighbor_province = {
					has_owner = yes
					religion = ROOT
				}
			}
		}

		mult_modifier = {
			factor = 3

			has_game_rule = {
				name = religious_conversion
				value = slower
			}
		}
	}

	immediate = {
		religion = owner
	}

	option = {
		name = EVTOPTA39500

		owner = {
			show_scope_change = no

			piety = 10

			if = {
				limit = { independent = no }

				top_liege = {
					character_event = {
						id = 39501
						days = 1
					}

					any_vassal = {
						limit = {
							NOT = { character = PREVPREV }
							is_playable = yes
						}

						character_event = {
							id = 39501
							days = 1
						}
					}
				}
			}
		}
	}
}

# News of the conversion spreads in realm
character_event = {
	id = 39501
	desc = EVTDESC39501
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	notification = yes

	ai = no

	option = {
		name = {
			text = EVTOPTA39501
			trigger = {
				NOT = { religion = FROM }
			}
		}
		name = {
			text = EVTOPTA39500
			trigger = {
				religion = FROM
			}
		}
	}
}

##########################
### Proselytize Events ###
##########################

# Preacher Arrives
character_event = {
	id = 39600
	desc = EVTDESC39600
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # event 39650, base_job_lord_spiritual.txt

	trigger = {
		NOR = {
			has_character_flag = flag_converting_baptism
			has_character_modifier = baptism_request_cooldown
		}

		# Don't allow players to game over
		trigger_if = {
			limit = {
				ai = no
				is_nomadic = no
			}

			FROM = { has_safe_religion = yes }
		}
	}

	fail_trigger_effect = {
		FROM = { clr_character_flag = preacher_arrives }
	}

	option = {
		name = EVTOPTA39600 # Throw the preacher in jail

		FROM = {
			show_scope_change = no

			imprison = ROOT

			liege = {
				show_scope_change = no

				set_character_flag = ai_failed_mission # AI flag - used in the code

				opinion = {
					name = opinion_imprisoned_missionary
					who = ROOT
				}

				hidden_effect = {
					reverse_opinion = {
						name = opinion_sent_preacher
						who = ROOT
					}
				}

				character_event = {
					id = 39605
					days = 1
				}
			}
		}

		custom_tooltip = { text = preacher_imprisoned }

		ai_chance = {
			factor = 2

			# Always allow them if you already like that religion
			trigger = {
				trigger_if = {
					limit = { FROM = { religion_group = christian } }
					NOT = { trait = sympathy_christendom }
				}
				trigger_else_if = {
					limit = { FROM = { religion_group = muslim } }
					NOT = { trait = sympathy_islam }
				}
				trigger_else_if = {
					limit = { FROM = { religion_group = jewish_group } }
					NOT = { trait = sympathy_judaism }
				}
				trigger_else_if = {
					limit = { FROM = { religion_group = zoroastrian_group } }
					NOT = { trait = sympathy_zoroastrianism }
				}
				trigger_else_if = {
					limit = { FROM = { religion_group = indian_group } }
					NOT = { trait = sympathy_indian }
				}
			}
		}
	}

	option = {
		name = EVTOPTB39600 # Allow them to preach

		FROM = {
			show_scope_change = no

			liege = {
				show_scope_change = no

				opinion = {
					name = opinion_allowed_missionary
					who = ROOT
				}

				custom_tooltip = {
					text = preacher_allowed

					letter_event = {
						id = 39604
						days = 1
					}
				}
			}
		}

		ai_chance = {
			factor = 1

			# Traits
			mult_modifier = {
				factor = 0.3
				trait = zealous
			}

			mult_modifier = {
				factor = 3
				trait = cynical
			}

			mult_modifier = {
				factor = 2
				trait = arbitrary
			}

			# Personal
			mult_modifier = {
				factor = 0.3
				is_rival = FROM
			}

			mult_modifier = {
				factor = 1.5

				OR = {
					any_spouse = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}

					any_consort = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}

					any_lover = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}

					any_child = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}
				}
			}

			# Political
			mult_modifier = {
				factor = 0.2

				any_vassal = {
					controls_religion = yes
					religion = ROOT
				}
			}

			mult_modifier = {
				factor = 0.1

				any_war = {
					using_cb = religious

					attacker = {
						character = ROOT
					}
				}
			}

			mult_modifier = {
				factor = 0.1

				any_war = {
					using_cb = pagan_holy_war

					attacker = {
						character = ROOT
					}
				}
			}

			mult_modifier = {
				factor = 0.1

				any_war = {
					using_cb = viking_invasion

					attacker = {
						character = ROOT
					}
				}
			}

			mult_modifier = {
				factor = 4

				any_war = {
					using_cb = religious

					defender = {
						character = ROOT
					}
				}
			}

			mult_modifier = {
				factor = 4

				any_war = {
					OR = {
						using_cb = crusade
						using_cb = new_crusade
					}

					defender = {
						character = ROOT
					}
				}
			}

			mult_modifier = {
				factor = 2

				any_realm_province = {
					religion = FROM
				}
			}

			# Historical
			mult_modifier = {
				factor = 2

				# We're already adopting civilized ways...
				is_nomadic = no
				is_tribal = no
			}

			mult_modifier = {
				factor = 0.2

				OR = {
					culture = saxon
					culture_group = baltic
					culture_group = finno_ugric  # The most stubborn pagans
				}
			}

			mult_modifier = {
				factor = 0.2

				FROM = {
					religion_group = muslim
				}

				OR = {
					culture_group = east_slavic # Like alcohol
					culture_group = north_germanic # Vikings do like their alcohol
				}
			}

			# Pragmatism
			mult_modifier = {
				factor = 3 # Powerful rulers want a modern religion

				real_tier = KING
				realm_size >= 12
			}

			mult_modifier = {
				factor = 5

				is_unreformed_pagan_trigger = yes		### ACR ###
				has_law = tribal_organization_4 # Need it to reform government

				capital_holding = {
					OR = {
						holding_type = castle

						AND = {
							holding_type = tribal
							has_building = tb_hillfort_4
						}

						AND = {
							location = {
								is_coastal = yes
							}

							OR = {
								holding_type = city

								AND = {
									holding_type = tribal
									has_building = tb_market_town_4
								}
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.2

				is_unreformed_pagan_trigger = yes		### ACR ###

				# Close to reforming own religion instead
				trigger_if = {
					limit = { num_of_holy_sites >= 3 }
					religion_authority >= 0.40
				}
				# Just very high authority, doing well
				trigger_else = {
					religion_authority >= 0.65
				}
			}

			mult_modifier = {
				factor = 2

				any_neighbor_independent_ruler = {
					religion = FROM

					# Powerful neighbor of that religion
					relative_power = {
						who = ROOT
						power >= 2.0
					}
				}
			}

			mult_modifier = {
				factor = 0.2

				NOR = {
					religion = tengri_pagan
					religion = aztec_pagan

					any_neighbor_independent_ruler = {
						is_not_unreformed_pagan_trigger = yes		### ACR ###

						# More cocky when pagan homeland attrition effect is active against neighbors
						any_realm_province = {
							TECH_RECRUITMENT >= 4
						}
					}
				}
			}
		}
	}
}

# Convert?
character_event = {
	id = 39601
	desc = EVTDESC39601
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

 	trigger = {
		trigger_if = {
			limit = {
				ai = no
				is_nomadic = no
			}

			FROM = { has_safe_religion = yes }
		}
	}

	is_triggered_only = yes

	option = {
		name = EVTOPTA39601

		#### Holy Fury - Mass Baptism clause

		if = {
			limit = {
				independent = yes
				has_dlc = "Holy Fury"
				is_unreformed_pagan_trigger = yes
				higher_real_tier_than = COUNT
				is_tribal = yes
				is_incapable = no
				NOT = { has_character_flag = flag_converting_baptism }

				FROM = {
					liege = {
						independent = yes
						higher_real_tier_than = DUKE
						is_not_unreformed_pagan_trigger = yes
						is_tribal = no
						is_nomadic = no

						NOR = {
							religion = ROOT
							pays_tribute_to = ROOT
							has_character_flag = flag_sponsoring_baptism
						}
					}
				}
			}

			custom_tooltip = {
				text = send_baptism_request

				FROM = {
					liege = {
						letter_event = { id = HF.20024 }
					}
				}
			}
		}
		else = {
			if = {
				limit = {
					practical_age >= 12

					NOR = {
						trait = zealous
						trait = sympathy_pagans
					}
				}

				random = {
					chance = 50

					mult_modifier = {
						factor = 1.2 # 60%
						trait = cynical
					}

					add_trait = sympathy_pagans
				}
			}

			# Workaround for automatic usurption of theocratic characters
			FROM = {
				religion_scope = {
					save_event_target_as = target_religion
				}
			}

			convert_religion_failsafe_effect = yes
			prestige = -500
			piety = 250

			if = {
				limit = { ai = yes }
				reverse_religion = capital_scope
			}

			any_courtier = {
				limit = { is_close_relative = ROOT }

				# Workaround for automatic usurption of theocratic characters
				ROOT = {
					religion_scope = {
						save_event_target_as = target_religion
					}
				}

				convert_religion_failsafe_effect = yes
			}

			any_spouse = {
				limit = { is_consort = no }

				# Workaround for automatic usurption of theocratic characters
				ROOT = {
					religion_scope = {
						save_event_target_as = target_religion
					}
				}

				convert_religion_failsafe_effect = yes
			}

			if = {
				limit = {
					religion_allows_male_temple_holders = yes
					religion_allows_female_temple_holders = yes
				}

				create_random_priest = {
					random_traits = yes
					dynasty = none
					culture = ROOT
					religion = ROOT
					female = 50
					age = 32

					attributes = {
						learning = 7
						diplomacy = 5
					}
				}
			}
			else_if = {
				limit = { religion_allows_male_temple_holders = yes }

				create_random_priest = {
					random_traits = yes
					dynasty = none
					culture = ROOT
					religion = ROOT
					female = no
					age = 32

					attributes = {
						learning = 7
						diplomacy = 5
					}
				}
			}
			else = {
				create_random_priest = {
					random_traits = yes
					dynasty = none
					culture = ROOT
					religion = ROOT
					female = yes
					age = 32

					attributes = {
						learning = 7
						diplomacy = 5
					}
				}
			}

			new_character = {
				give_job_title = job_spiritual
				save_event_target_as = convert_lord_spiritual
			}

			custom_tooltip = {
				text = preacher_convert

				if = {
					limit = { ai = yes }

					any_vassal = {
						limit = {
							NOT = { religion = ROOT }
						}

						letter_event = { id = 39617 } # Send out letter to vassals
					}
				}

				FROM = {
					liege = {
						letter_event = {
							id = 39606 # Notify
							days = 1
						}
					}
				}
			}
		}

		ai_chance = {
			factor = 1

			trigger = { is_unreformed_pagan_trigger = yes }

			# Traits
			mult_modifier = {
				factor = 0.3
				trait = zealous
			}

			mult_modifier = {
				factor = 3
				trait = cynical
			}

			mult_modifier = {
				factor = 2
				trait = arbitrary
			}

			mult_modifier = {
				factor = 3

				trigger_if = {
					limit = { FROM = { religion_group = christian } }
					trait = sympathy_christendom
				}
				trigger_else_if = {
					limit = { FROM = { religion_group = muslim } }
					trait = sympathy_islam
				}
				trigger_else_if = {
					limit = { FROM = { religion_group = jewish_group } }
					trait = sympathy_judaism
				}
				trigger_else_if = {
					limit = { FROM = { religion_group = zoroastrian_group } }
					NOT = { trait = sympathy_zoroastrianism }
				}
				trigger_else = {
					FROM = { religion_group = indian_group }
					trait = sympathy_indian
				}
			}

			# Personal
			mult_modifier = {
				factor = 0.3
				is_rival = FROM
			}

			mult_modifier = {
				factor = 1.5

				OR = {
					any_spouse = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}

					any_consort = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}

					any_lover = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}

					any_child = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}
				}
			}

			# Political
			mult_modifier = {
				factor = 0.2

				any_vassal = {
					controls_religion = yes
					religion = ROOT
				}
			}

			mult_modifier = {
				factor = 0.1

				any_war = {
					using_cb = religious

					attacker = {
						character = ROOT
					}
				}
			}

			mult_modifier = {
				factor = 0.1

				any_war = {
					using_cb = pagan_holy_war

					attacker = {
						character = ROOT
					}
				}
			}

			mult_modifier = {
				factor = 0.1

				any_war = {
					using_cb = viking_invasion

					attacker = {
						character = ROOT
					}
				}
			}

			mult_modifier = {
				factor = 4

				any_war = {
					using_cb = religious
					war_score < 50

					defender = {
						character = ROOT
					}
				}
			}

			mult_modifier = {
				factor = 4

				any_war = {
					OR = {
						using_cb = crusade
						using_cb = new_crusade
					}

					war_score < 50

					defender = {
						character = ROOT
					}
				}
			}

			# Historical
			mult_modifier = {
				factor = 2

				# We're already adopting civilized ways...
				is_nomadic = no
				is_tribal = no
			}

			mult_modifier = {
				factor = 0.2

				OR = {
					culture = saxon
					culture_group = baltic
					culture_group = finno_ugric # The most stubborn pagans
				}
			}

			mult_modifier = {
				factor = 0.2

				FROM = {
					religion_group = muslim
				}

				OR = {
					culture_group = east_slavic # Like alcohol
					culture_group = north_germanic # Vikings do like their alcohol
				}
			}

			mult_modifier = {
				factor = 0.2
				religion_openly_bon_or_reformed_trigger = yes
			}

			# Pragmatism
			mult_modifier = {
				factor = 3 # Powerful rulers want a modern religion

				real_tier = KING
				realm_size >= 12
			}

			mult_modifier = {
				factor = 5

				has_law = tribal_organization_4 # Need it to reform government

				capital_holding = {
					OR = {
						holding_type = castle

						AND = {
							holding_type = tribal
							has_building = tb_hillfort_4
						}

						AND = {
							location = {
								is_coastal = yes
							}

							OR = {
								holding_type = city

								AND = {
									holding_type = tribal
									has_building = tb_market_town_4
								}
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.3

				# Close to reforming own religion instead
				trigger_if = {
					limit = { num_of_holy_sites >= 3 }
					religion_authority >= 0.40
				}
				# Just very high authority, doing well
				trigger_else = {
					religion_authority >= 0.65
				}
			}

			mult_modifier = {
				factor = 2

				any_neighbor_independent_ruler = {
					religion = FROM

					# Powerful neighbor of that religion
					relative_power = {
						who = ROOT
						power >= 2.0
					}
				}
			}

			mult_modifier = {
				factor = 0.2

				NOR = {
					religion = tengri_pagan
					religion = aztec_pagan

					any_neighbor_independent_ruler = {
						is_not_unreformed_pagan_trigger = yes

						any_realm_province = {
							TECH_RECRUITMENT >= 4 # More cocky when pagan homeland attrition effect is active against neighbors
						}
					}
				}
			}

			# Realm stability
			mult_modifier = {
				factor = 10

				num_of_vassals >= 3

				NOT = {
					any_vassal = {
						NOT = { religion = FROM }
					}
				}
			}

			mult_modifier = {
				factor = 10

				NOT = {
					any_realm_province = {
						NOT = { religion = FROM }
					}
				}
			}

			mult_modifier = {
				factor = 0.3

				NOT = {
					any_realm_province = {
						religion = FROM
					}
				}
			}

			mult_modifier = {
				factor = 0.3

				any_vassal = {
					NOT = { religion = FROM }

					opinion = {
						who = ROOT
						value < 25
					}
				}
			}

			# Not losing religious wars
			mult_modifier = {
				factor = 0.3

				NOT = {
					any_war = {
						defender = { character = ROOT }
						war_score >= 50

						OR = {
							using_cb = religious
							using_cb = crusade
							using_cb = new_crusade
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.3

				NOT = {
					any_war = {
						defender = { character = ROOT }
						war_score >= 10

						OR = {
							using_cb = religious
							using_cb = crusade
							using_cb = new_crusade
						}
					}
				}
			}
		}
	}

	option = {
		name = EVTOPTB39601

		FROM = {
			show_scope_change = no

			liege = {
				show_scope_change = no

				opinion = {
					name = opinion_banished_missionary
					who = ROOT
				}

				custom_tooltip = {
					text = preacher_banished

					reverse_opinion = {
						name = opinion_sent_preacher
						who = ROOT
					}

					letter_event = {
						id = 39607
						days = 1
					}
				}
			}
		}
	}
}

# Vassals receive letter
letter_event = {
	id = 39617
	desc = EVTDESC_39617
	border = GFX_event_letter_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_39617 # Convert

		# Workaround for automatic usurption of theocratic characters
		FROM = {
			religion_scope = {
				save_event_target_as = target_religion
			}
		}

		convert_religion_failsafe_effect = yes
		prestige = -250

		any_courtier = {
			limit = { is_close_relative = ROOT }

			# Workaround for automatic usurption of theocratic characters
			ROOT = {
				religion_scope = {
					save_event_target_as = target_religion
				}
			}

			convert_religion_failsafe_effect = yes
		}

		any_spouse = {
			limit = { is_consort = no }

			# Workaround for automatic usurption of theocratic characters
			ROOT = {
				religion_scope = {
					save_event_target_as = target_religion
				}
			}

			convert_religion_failsafe_effect = yes
		}

		if = {
			limit = {
				religion_allows_male_temple_holders = yes
				religion_allows_female_temple_holders = yes
			}

			create_random_priest = {
				random_traits = yes
				dynasty = none
				culture = ROOT
				religion = ROOT
				female = 50

				attributes = {
					learning = 20
					diplomacy = 10
				}
			}
		}
		else_if = {
			limit = { religion_allows_male_temple_holders = yes }

			create_random_priest = {
				random_traits = yes
				dynasty = none
				culture = ROOT
				religion = ROOT
				female = no

				attributes = {
					learning = 20
					diplomacy = 10
				}
			}
		}
		else = {
			create_random_priest = {
				random_traits = yes
				dynasty = none
				culture = ROOT
				religion = ROOT
				female = yes

				attributes = {
					learning = 20
					diplomacy = 10
				}
			}
		}

		new_character = {
			give_job_title = job_spiritual
		}

		ai_chance = {
			factor = 1

			trigger = {
				# Very powerful vassal who is also zealous NEVER accepts
				trigger_if = {
					limit = { trait = zealous }

					relative_power = {
						who = FROM
						power < 1.0
					}
				}
			}

			# Traits
			mult_modifier = {
				factor = 0.3
				trait = zealous
			}

			mult_modifier = {
				factor = 3
				trait = cynical
			}

			mult_modifier = {
				factor = 2
				trait = arbitrary
			}

			# Personal

			mult_modifier = {
				factor = 0.3
				is_rival = FROM
			}

			mult_modifier = {
				factor = 1.5

				OR = {
					any_spouse = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}

					any_consort = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}

					any_lover = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}

					any_child = {
						religion = FROM

						reverse_opinion = {
							who = ROOT
							value >= 50
						}
					}
				}
			}

			# Historical
			mult_modifier = {
				factor = 2

				# We're already adopting civilized ways...
				is_nomadic = no
				is_tribal = no
			}

			mult_modifier = {
				factor = 0.2

				OR = {
					culture = saxon
					culture_group = baltic
					culture_group = finno_ugric # The most stubborn pagans
				}
			}

			mult_modifier = {
				factor = 0.2

				FROM = {
					religion_group = muslim
				}

				OR = {
					culture_group = east_slavic # Like alcohol
					culture_group = north_germanic # Vikings do like their alcohol
				}
			}
		}
	}

	option = {
		name = EVTOPTB_39617 # Don't convert

		piety = 100
	}

	option = {
		name = EVTOPTC_39617 # Respond with anger

		prestige = 100
		piety = 100

		reverse_opinion = {
			name = opinion_angry
			who = FROM
			years = 5
		}

		ai_chance = { factor = 0 }
	}
}

# Courtier converts (hidden)
character_event = {
	id = 39610

	hide_window = yes
	is_triggered_only = yes # event 39652, base_job_lord_spiritual_events.txt

	immediate = {
		if = {
			limit = {
				practical_age >= 12

				NOR = {
					trait = zealous
					trait = sympathy_pagans
				}
			}

			random = {
				chance = 50

				mult_modifier = {
					factor = 1.2 # 60%
					trait = cynical
				}

				add_trait = sympathy_pagans
			}
		}


		# Workaround for automatic usurption of theocratic characters
		FROM = {
			religion_scope = {
				save_event_target_as = target_religion
			}
		}

		convert_religion_failsafe_effect = yes

		liege = {
			character_event = { id = 39602 }
		}
	}
}

# Courtier Converts - notify liege
character_event = {
	id = 39602
	desc = EVTDESC39602
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39602

		FROMFROM = { # The proselytizing chaplain
			show_scope_change = no

			imprison = ROOT

			liege = {
				show_scope_change = no

				opinion = {
					name = opinion_imprisoned_missionary
					who = ROOT
				}

				custom_tooltip = {
					text = preacher_imprisoned

					reverse_opinion = {
						name = opinion_sent_preacher
						who = ROOT
					}

					character_event = {
						id = 39608
						days = 1
					}
				}
			}
		}
	}

	option = {
		name = EVTOPTB39602

		custom_tooltip = { text = preacher_allowed }
	}
}

# Preachers Squabbling
character_event = {
	id = 39603
	desc = EVTDESC39603
	picture = GFX_evt_child_sword
	border = GFX_event_normal_frame_religion

	hide_from = yes
	is_triggered_only = yes

	option = {
		name = EVTOPTA39603

		FROMFROM = {
			show_scope_change = no

			save_event_target_as = banished_preacher

			liege = {
				show_scope_change = no

				opinion = {
					name = opinion_banished_missionary
					who = ROOT
				}

				hidden_effect = {
					reverse_opinion = {
						name = opinion_sent_preacher
						who = ROOT
					}
				}

				letter_event = {
					id = 39609
					days = 1
				}
			}
		}

		FROM = {
			show_scope_change = no

			save_event_target_as = supported_preacher

			liege = {
				show_scope_change = no

				opinion = {
					name = opinion_supported_preacher
					who = ROOT
				}
			}
		}
	}

	option = {
		name = EVTOPTB39603

		FROM = {
			show_scope_change = no

			save_event_target_as = banished_preacher

			liege = {
				opinion = {
					name = opinion_banished_missionary
					who = ROOT
				}

				hidden_effect = {
					reverse_opinion = {
						name = opinion_sent_preacher
						who = ROOT
					}
				}

				letter_event = {
					id = 39609
					days = 1
				}
			}
		}

		FROMFROM = {
			show_scope_change = no

			save_event_target_as = supported_preacher

			liege = {
				show_scope_change = no

				opinion = {
					name = opinion_supported_preacher
					who = ROOT
				}
			}
		}
	}

	option = {
		name = EVTOPTC39603

		FROM = {
			show_scope_change = no

			liege = {
				show_scope_change = no

				opinion = {
					name = opinion_did_not_support_preacher
					who = ROOT
				}
			}
		}

		FROMFROM = {
			show_scope_change = no

			liege = {
				show_scope_change = no

				opinion = {
					name = opinion_did_not_support_preacher
					who = ROOT
				}
			}
		}
	}
}

# Liege informed of Chaplain's arrival
letter_event = {
	id = 39604
	desc = EVTDESC39604
	border = GFX_event_letter_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39604

		piety = 20
	}
}

# Liege informed Chaplain imprisoned on arrival
character_event = {
	id = 39605
	desc = EVTDESC39605
	picture = GFX_evt_torture
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39605

		opinion = {
			name = opinion_imprisoned_missionary
			who = FROM
		}
	}
}

# Liege informed of Chaplain's success
letter_event = {
	id = 39606
	desc = EVTDESC39606
	border = GFX_event_letter_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39606

		tooltip = {
			FROM = {
				show_scope_change = no

				religion = ROOT_FROMFROM
			}
		}

		FROMFROM = {
			show_scope_change = no

			cancel_job_action = action_inquisition
		}

		piety = 200
	}
}

# Liege informed of Chaplain's failure
letter_event = {
	id = 39607
	desc = EVTDESC39607
	border = GFX_event_letter_frame_religion
	portrait = FROMFROM

	is_triggered_only = yes

	option = {
		name = EVTOPTA39607

		FROM = {
			show_scope_change = no

			cancel_job_action = action_inquisition
		}
	}
}

# Liege informed Chaplain imprisoned after converting courtier
character_event = {
	id = 39608
	desc = EVTDESC39608
	picture = GFX_evt_torture
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA39608
	}
}

# Liege informed Chaplain banished after quarrel
letter_event = {
	id = 39609
	desc = EVTDESC39609
	border = GFX_event_letter_frame_religion
	portrait = event_target:banished_preacher

	is_triggered_only = yes

	option = {
		name = EVTOPTA39609

		event_target:banished_preacher = {
			show_scope_change = no

			cancel_job_action = action_inquisition
		}
	}
}

# Chaplain fights with other Chaplain
character_event = {
	id = 39611
	desc = EVTDESC39653
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # event 39653, base_job_lord_spiritual.txt

	option = {
		name = EVTOPTA39653

		location = {
			owner = {
				character_event = {
					id = 39603
					days = 1
				}
			}
		}
	}
}

# Chaplain arrives (hidden) - removed by CleanSlate

# Liege informed of Chaplain's failure (hidden) - removed by CleanSlate

# Liege informed of Chaplain's success (hidden) - removed by CleanSlate

# Liege informed Chaplain imprisoned after converting courtier (hidden) - removed by CleanSlate

# Liege informed Chaplain banished after quarrel (hidden) - removed by CleanSlate

# RISE OF THE SHI'A CALIPHATE
narrative_event = {
	id = 39640
	title = EVTNAME39640
	desc = EVTDESC39640
	picture = GFX_evt_bishop
	border = GFX_event_narrative_frame_religion
	portrait = event_target:shia_caliphate_pretender

	is_triggered_only = yes # on_five_year_pulse, random_events, shia_caliphate

	major = yes
	show_root = yes
	hide_new = yes

	only_independent = yes
	religion_group = muslim

	trigger = {
		higher_real_tier_than = DUKE
		uses_decadence = yes
		is_landed = yes

		NOR = {
			religion = shiite
			has_global_flag = shia_caliphate_revolt_ongoing

			has_alternate_start_parameter = {
				key = religion_names
				value = random
			}
		}

		d_shiite = {
			has_holder = no
		}

		decadence >= 10

		any_realm_province = {
			kingdom = {
				trigger_if = {
					limit = { has_holder = yes }
					holder = ROOT
				}

				num_title_realm_provs = {
					who = ROOT
					value >= 6
				}
			}

			trigger_if = {
				limit = { ROOT = { capital_scope = { province = PREVPREV } } }
				ROOT = { ai = yes }
			}
		}
	}

	major_trigger = {
		ai = no
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 4

			OR = {
				c_cairo = {
					holder_scope = {
						same_realm = ROOT
					}
				}

				c_damascus = {
					holder_scope = {
						same_realm = ROOT
					}
				}

				c_tunis = {
					holder_scope = {
						same_realm = ROOT
					}
				}
			}
		}

		mult_modifier = {
			factor = 2
			decadence >= 90
		}

		mult_modifier = {
			factor = 0.25
			decadence < 25
		}

		mult_modifier = {
			factor = 0.5
			year >= 1100
		}

		mult_modifier = {
			factor = 0.5
			year >= 1200
		}

		mult_modifier = {
			factor = 0.5
			year >= 1300
		}

		mult_modifier = {
			factor = 0.25
			year >= 1400
		}

		mult_modifier = {
			factor = 0.5
			NOT = { religion = sunni }
		}

		mult_modifier = {
			factor = 0.1
			ai = no
		}
	}

	immediate = {
		set_character_flag = shia_caliphate_revolt
		set_global_flag = shia_caliphate_revolt_ongoing

		decadence = -30 # Do not want to be hit with a decadence revolt as well!

		random_realm_province = {
			limit = {
				kingdom = {
					trigger_if = {
						limit = { has_holder = yes }
						holder = ROOT
					}

					num_title_realm_provs = {
						who = ROOT
						value >= 6
					}
				}

				trigger_if = {
					limit = { ROOT = { capital_scope = { province = PREVPREV } } }
					ROOT = { ai = yes }
				}
			}

			preferred_limit = {
				ROOT = {
					capital_scope = { province = PREVPREV }
				}

				kingdom = {
					trigger_if = {
						limit = { has_holder = yes }
						holder = ROOT
					}
				}
			}

			preferred_limit = {
				kingdom = {
					trigger_if = {
						limit = { has_holder = yes }
						holder = ROOT
					}

					num_title_realm_provs = {
						who = ROOT
						value >= 10
					}
				}
			}

			preferred_limit = {
				kingdom = {
					trigger_if = {
						limit = { has_holder = yes }
						holder = ROOT
					}

					num_title_realm_provs = {
						who = ROOT
						value >= 6
					}
				}
			}

			save_event_target_as = spawn_province
			kingdom = { save_event_target_as = spawn_kingdom }

			if = {
				limit = {
					religion_group = muslim
					NOT = { religion = shiite }
				}
				religion = shiite
			}
		}

		create_character = {
			dynasty = random
			religion = shiite
			culture = ROOT
			female = no
			age = 3
			health = 6.5
			fertility = 0.6
			flag = shia_caliphate_pretender

			attributes = {
				learning = 1
				diplomacy = 2
				martial = 1
				stewardship = 1
				intrigue = 1
			}

			add_trait = sayyid
			add_trait = quick
			add_trait = attractive
		}

		new_character = {
			save_event_target_as = shia_caliphate_pretender
			### Generic Kinich ###
			if = {
				limit = { NOT = { has_character_flag = shia_caliphate_pretender } }
				set_character_flag = shia_caliphate_pretender
			}
			if = {
				limit = {
					has_character_flag = shia_caliphate_pretender
					NOT = { has_character_flag = kinich_shia_pretender_was_protected }
				}
				set_character_flag = kinich_shia_pretender_was_protected
				add_character_modifier = {
					name = kinich_protectshiacaliph
					years = 25
				}
			}
			### KWF ###
			if = {
				limit = { has_global_flag = kinich_no_waifus }
				ke_historical_waifu_effect = yes
			}

			if = {
				limit = { ROOT = { ai = yes } }
				wealth = 1000
			}
			else = {
				wealth = 250
			}

			create_title = {
				tier = DUKE
				landless = yes
				temporary = yes
				culture = ROOT
				name = SHIA_CALIPHATE_REVOLT
				holder = THIS
			}

			while = {
				count = 6

				if = {
					limit = { ROOT = { ai = yes } }

					spawn_unit = {
						province = event_target:spawn_province
						home = event_target:spawn_province
						owner = THIS
						match_character = ROOT
						match_mult = 0.25
						attrition = 0.5
						cannot_inherit = yes
						reinforces = yes
						reinforce_rate_multiplier = 0.33
					}
				}
				else = {
					spawn_unit = {
						province = event_target:spawn_province
						home = event_target:spawn_province
						owner = THIS
						match_character = ROOT
						match_mult = 0.15
						attrition = 0.5
						cannot_inherit = yes
						reinforces = yes
						reinforce_rate_multiplier = 0.25
					}
				}
			}

			while = {
				count = 3

				spawn_unit = {
					province = event_target:spawn_province
					home = event_target:spawn_province
					owner = THIS
					match_character = ROOT
					match_mult = 0.2
					attrition = 0.0
					cannot_inherit = yes
					disband_on_peace = yes
					reinforces = yes
					reinforce_rate_multiplier = 0.25
				}
			}

			while = {
				count = 9

				create_random_soldier = {
					random_traits = yes
					dynasty = none
					religion = THIS
					culture = THIS
					female = no
					min_age = 23
					max_age = 32
				}

				new_character = {
					clear_education_trait = yes

					random_list = {
						67 = { add_trait = skilled_tactician }
						33 = { add_trait = brilliant_strategist }
					}
				}
			}

			war = {
				target = ROOT
				casus_belli = shia_caliphate_rising
				thirdparty_title = event_target:spawn_kingdom
			}
		}
	}

	option = {
		name = EVTOPTA39640

		trigger = { has_character_flag = shia_caliphate_revolt }

		clr_character_flag = shia_caliphate_revolt
	}

	option = {
		name = {
			text = EVTOPTB39640
			trigger = { religion = shiite }
		}
		name = {
			text = EVTOPTC39640
			trigger = {
				religion_group = muslim
				NOT = { religion = shiite }
			}
		}
		name = {
			text = EVTOPTD39640
			trigger = {
				NOT = { religion_group = muslim }
			}
		}

		trigger = {
			NOT = { has_character_flag = shia_caliphate_revolt }
		}
	}
}

# THE START OF THE CHRISTIAN CRUSADES - 1090 AND JERUSALEM NOT CHRISTIAN
narrative_event = {
	id = 39660
	title = EVTNAME39660
	desc = EVTDESC39660
	picture = GFX_evt_jerusalem
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_decade_pulse

	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	religion = catholic
	min_age = 16

	trigger = {
		controls_religion = yes
		year >= 1090

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

			has_global_flag = christian_crusades_unlocked
		}

		c_jerusalem = {
			holder_scope = {
				top_liege = {
					NOT = { religion_group = christian }
				}
			}
		}
	}

	major_trigger = {
		ai = no
	}

	immediate = {
		set_global_flag = christian_crusades_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39660
			trigger = { religion_group = christian }
		}
		name = {
			text = EVTOPTB39660
			trigger = {
				NOT = { religion_group = christian }
			}
		}
	}
}

# THE START OF THE CHRISTIAN CRUSADES - BYZANTIUM FAILING
narrative_event = {
	id = 39661
	title = EVTNAME39660
	desc = EVTDESC39661
	picture = GFX_evt_hagia_sofia
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	religion = catholic
	min_age = 16

	trigger = {
		controls_religion = yes
		year >= 900

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

			has_global_flag = christian_crusades_unlocked
		}

		OR = {
			e_byzantium = {
				holder_scope = {
					NOT = { religion_group = christian }
				}
			}

			c_constantinopolis = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = christian }
					}
				}
			}

			c_ancyra = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = christian }
					}
				}
			}

			AND = {
				c_atheniai = {
					holder_scope = {
						top_liege = {
							NOT = { religion_group = christian }
						}
					}
				}

				c_korinthos = {
					holder_scope = {
						top_liege = {
							NOT = { religion_group = christian }
						}
					}
				}
			}
		}
	}

	major_trigger = {
		ai = no
	}

	immediate = {
		set_global_flag = christian_crusades_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39660
			trigger = { religion_group = christian }
		}
		name = {
			text = EVTOPTB39660
			trigger = {
				NOT = { religion_group = christian }
			}
		}
	}
}

# THE START OF THE CHRISTIAN CRUSADES - ROME HAS FALLEN
narrative_event = {
	id = 39662
	title = EVTNAME39660
	desc = EVTDESC39662
	picture = GFX_evt_pope
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	religion = catholic
	min_age = 16

	trigger = {
		controls_religion = yes
		year >= 900

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

			has_global_flag = christian_crusades_unlocked
		}

		c_roma = {
			holder_scope= {
				top_liege = {
					OR = {
						NOT = { religion_group = christian }
						is_heretic = yes
					}
				}
			}
		}
	}

	major_trigger = {
		ai = no
	}

	immediate = {
		set_global_flag = christian_crusades_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39660
			trigger = { religion_group = christian }
		}
		name = {
			text = EVTOPTB39660
			trigger = {
				NOT = { religion_group = christian }
			}
		}
	}
}

# THE START OF THE CHRISTIAN CRUSADES - EUROPE
narrative_event = {
	id = 39663
	title = EVTNAME39660
	desc = EVTDESC39663
	picture = GFX_evt_crusaders
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	religion = catholic
	min_age = 16

	trigger = {
		controls_religion = yes
		year >= 900

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

			has_global_flag = christian_crusades_unlocked
		}

		OR = {
			c_provence = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = christian }
					}
				}
			}

			c_toulouse = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = christian }
					}
				}
			}

			c_paris = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = christian }
					}
				}
			}

			c_koln = {
				location = { religion_group = christian }

				holder_scope = {
					top_liege = {
						NOT = { religion_group = christian }
					}
				}
			}

			c_braunschweig = {
				location = { religion_group = christian }

				holder_scope = {
					top_liege = {
						NOT = { religion_group = christian }
					}
				}
			}
		}
	}

	immediate = {
		set_global_flag = christian_crusades_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39660
			trigger = { religion_group = christian }
		}
		name = {
			text = EVTOPTB39660
			trigger = {
				NOT = { religion_group = christian }
			}
		}
	}
}

# THE START OF MUSLIM JIHADS - 1187 IF THERE IS STILL A CALIPH
narrative_event = {
	id = 39670
	title = EVTNAME39670
	desc = EVTDESC39670
	picture = GFX_evt_bishop_muslim
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_decade_pulse
	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	religion_group = muslim
	min_age = 16

	trigger = {
		controls_religion = yes
		year >= 1187

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

			has_global_flag = muslim_jihads_unlocked
		}
	}

	major_trigger = {
		ai = no
	}

	immediate = {
		set_global_flag = muslim_jihads_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39670
			trigger = { religion_group = muslim }
		}
		name = {
			text = EVTOPTB39670
			trigger = {
				NOT = { religion_group = muslim }
			}
		}
	}
}

# THE START OF MUSLIM JIHADS - JERUSALEM HAS FALLEN
narrative_event = {
	id = 39671
	title = EVTNAME39670
	desc = EVTDESC39671
	picture = GFX_evt_jerusalem_captured_muslims
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	religion_group = muslim
	min_age = 16

	trigger = {
		controls_religion = yes
		year >= 900

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

			has_global_flag = muslim_jihads_unlocked
		}

		c_jerusalem = {
			holder_scope = {
				top_liege = {
					NOT = { religion_group = muslim }
				}
			}
		}
	}

	major_trigger = {
		ai = no
	}

	immediate = {
		set_global_flag = muslim_jihads_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39670
			trigger = { religion_group = muslim }
		}
		name = {
			text = EVTOPTB39670
			trigger = {
				NOT = { religion_group = muslim }
			}
		}
	}
}

# THE START OF MUSLIM JIHADS - MECCA HAS FALLEN
narrative_event = {
	id = 39672
	title = EVTNAME39670
	desc = EVTDESC39672
	picture = GFX_evt_mecca_falls_soa
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	religion_group = muslim
	min_age = 16

	trigger = {
		controls_religion = yes
		year >= 900

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

			has_global_flag = muslim_jihads_unlocked
		}

		c_mecca = {
			holder_scope = {
				top_liege = {
					NOT = { religion_group = muslim }
				}
			}
		}
	}

	major_trigger = {
		ai = no
	}

	immediate = {
		set_global_flag = muslim_jihads_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39670
			trigger = { religion_group = muslim }
		}
		name = {
			text = EVTOPTB39670
			trigger = {
				NOT = { religion_group = muslim }
			}
		}
	}
}

# THE START OF MUSLIM JIHADS - THE CENTER CANNOT HOLD
narrative_event = {
	id = 39673
	title = EVTNAME39670
	desc = EVTDESC39673
	picture = GFX_evt_moors
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	religion_group = muslim
	min_age = 16

	trigger = {
		controls_religion = yes
		year >= 900

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

			has_global_flag = muslim_jihads_unlocked
		}

		OR = {
			c_baghdad = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = muslim }
					}
				}
			}

			c_damascus = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = muslim }
					}
				}
			}

			c_cairo = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = muslim }
					}
				}
			}
		}
	}

	major_trigger = {
		ai = no
	}

	immediate = {
		set_global_flag = muslim_jihads_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39670
			trigger = { religion_group = muslim }
		}
		name = {
			text = EVTOPTB39670
			trigger = {
				NOT = { religion_group = muslim }
			}
		}
	}
}

# THE START OF MUSLIM JIHADS - AFRICA UNDER THREAT
narrative_event = {
	id = 39674
	title = EVTNAME39670
	desc = EVTDESC39674
	picture = GFX_evt_desert
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_yearly_pulse
	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	religion_group = muslim
	min_age = 16

	trigger = {
		controls_religion = yes
		year >= 1000

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

			has_global_flag = muslim_jihads_unlocked
		}

		OR = {
			c_marrakech = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = muslim }
					}
				}
			}

			c_tunis = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = muslim }
					}
				}
			}

			c_al_djazair = {
				holder_scope = {
					top_liege = {
						NOT = { religion_group = muslim }
					}
				}
			}
		}
	}

	major_trigger = {
		ai = no
	}

	immediate = {
		set_global_flag = muslim_jihads_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39670
			trigger = { religion_group = muslim }
		}
		name = {
			text = EVTOPTB39670
			trigger = {
				NOT = { religion_group = muslim }
			}
		}
	}
}

# THE START OF PAGAN GREAT HOLY WARS - AFTER THE ABRAHAMICS
narrative_event = {
	id = 39680
	title = EVTNAME39680
	desc = EVTDESC39680
	picture = GFX_evt_midwinter_blot_oldgods
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes # on_decade_pulse

	major = yes
	show_root = yes
	hide_new = yes

	only_playable = yes
	min_age = 16
	religion_group = pagan_group

	trigger = {
		controls_religion = yes

		OR = {
			has_global_flag = muslim_jihads_unlocked
			has_global_flag = christian_crusades_unlocked
		}

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

			has_global_flag = pagan_ghws_unlocked
		}
	}

	major_trigger = {
		ai = no
	}

	immediate = {
		set_global_flag = pagan_ghws_unlocked
	}

	option = {
		name = {
			text = EVTOPTA39680
			trigger = { religion = ROOT }
		}
		name = {
			text = EVTOPTB39680
			trigger = {
				religion_group = pagan_group
				NOT = { religion = ROOT }
			}
		}
		name = {
			text = EVTOPTC39680
			trigger = {
				NOT = { religion_group = pagan_group }
			}
		}
	}
}

# Vassal accepts religious conversion demand.
# Fired from 'on_vassal_accepts_religious_conversion'
# FROMFROM is the demander.
# FROM is the target vassal.
# ROOT is the current character.
# Fires for the target and each of his/her courtiers and direct vassals (but not for characters below the target's vassals).
character_event = {
	id = 39700

	hide_window = yes
	is_triggered_only = yes # on_vassal_accepts_religious_conversion

	trigger = {
		NOT = { religion = FROMFROM }

		OR = {
			character = FROM

			AND = {
				is_ruler = no
				NOT = { trait = zealous }
				religion = FROM # Will not change religion if already different from the vassal's
			}
		}
	}

	immediate = {
		if = {
			limit = { character = FROM }

			# FROM gets chance to secretly keep old religion, see event MNM.3949 below
			# Saves (public) religionm overwriting existing old_religion
			save_persistent_event_target = {
				name = old_religion
				scope = religion_scope
			}

			opinion = {
				name = opinion_demanded_conversion
				who = FROMFROM
			}

			if = {
				limit = {
					prisoner = yes
					host = { character = FROMFROM }
				}

				imprison = no
			}
		}

		if = {
			limit = {
				practical_age >= 12
				NOT = { trait = zealous }
			}

			# Chance of sympathy for the old religion
			random_list = {
				100 = { }

				100 = {
					mult_modifier = {
						factor = 10
						trait = cynical
					}

					trigger_switch = {
						on_trigger = religion_group

						christian         = { add_trait = sympathy_christendom }
						muslim            = { add_trait = sympathy_islam }
						pagan_group       = { add_trait = sympathy_pagans }
						zoroastrian_group = { add_trait = sympathy_zoroastrianism }
						jewish_group      = { add_trait = sympathy_judaism }
						indian_group      = { add_trait = sympathy_indian }
					}
				}
			}
		}

		# Workaround for automatic usurption of theocratic characters
		FROMFROM = {
			religion_scope = {
				save_event_target_as = target_religion
			}
		}

		convert_religion_failsafe_effect = yes

		if = {
			limit = { religion_group = indian_group }
			character_event = { id = RoI.120 } # Assign Indian religion branch
		}

		if = {
			limit = { character = FROM }

			character_event = {
				id = MNM.3949 # Option to secretly keep old religion
				days = 3
				random = 10
			}
		}
	}
}

# Catholic antipope immediately loses claim if he or liege is no longer catholic
character_event = {
	id = 39701

	hide_window = yes
	is_triggered_only = yes # on_character_convert_religion

	only_playable = yes

	trigger = {
		OR = {
			has_claim = k_papacy

			k_papacy = {
				any_claimant = {
					is_vassal_or_below_of = ROOT
				}
			}
		}
	}

	immediate = {
		k_papacy = {
			any_claimant = {
				limit = {
					NAND = {
						religion = catholic
						liege = { religion = catholic }
					}
				}
				remove_claim = k_papacy
			}
		}
	}
}

# Fraticelli antipope immediately loses claim if he or liege is no longer Fraticelli
character_event = {
	id = 39702

	hide_window = yes
	is_triggered_only = yes # on_character_convert_religion

	only_playable = yes

	trigger = {
		OR = {
			has_claim = d_fraticelli

			d_fraticelli = {
				any_claimant = {
					is_vassal_or_below_of = ROOT
				}
			}
		}
	}

	immediate = {
		d_fraticelli = {
			any_claimant = {
				limit = {
					NAND = {
						religion = fraticelli
						liege = { religion = fraticelli }
					}
				}
				remove_claim = d_fraticelli
			}
		}
	}
}

# Establishing the Fraticelli Papacy
character_event = {
	id = 39703
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	desc = {
		text = evt_CK2_39703_desc_a
		trigger = { character = FROM }
	}
	desc = {
		text = evt_CK2_39703_desc_b
		trigger = {
			NOT = { character = FROM }
		}
	}

	major = yes
	is_triggered_only = yes # create_fraticelli_papacy, religious_decisions.txt

	only_playable = yes

	major_trigger = {
		ai = no
		religion_group = christian
	}

	option = {
		name = {
			text = EVTOPTA_SOA_4200
			trigger = { religion = fraticelli }
		}
		name = {
			text = EVTOPTB_SOA_4200
			trigger = { religion = catholic }
		}
		name = {
			text = EVTOPTC_SOA_4200
			trigger = {
				NOR = {
					religion = fraticelli
					religion = catholic
				}
			}
		}
	}
}

# Establishing the Iconoclast Patriarchy
long_character_event = {
	id = 39704
	picture = GFX_evt_bishop
	border = GFX_event_long_frame_religion

	desc = {
		text = evt_CK2_39704_desc_a
		trigger = { character = FROM }
	}
	desc = {
		text = evt_CK2_39704_desc_b
		trigger = {
			NOT = { character = FROM }
		}
	}

	major = yes
	is_triggered_only = yes # create_iconoclast_patriarchy, religious_decisions.txt

	only_playable = yes

	major_trigger = {
		ai = no
		religion_group = christian
	}

	option = {
		name = {
			text = EVTOPTA_SOA_4200
			trigger = { religion = iconoclast }
		}
		name = {
			text = EVTOPTB_SOA_4200
			trigger = { religion = orthodox }
		}
		name = {
			text = EVTOPTC_SOA_4200
			trigger = {
				NOR = {
					religion = iconoclast
					religion = orthodox
				}
			}
		}
	}
}

# Restore the Pope in Rome
character_event = {
	id = 39705
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	desc = {
		text = evt_CK2_39705_desc_a
		trigger = {
			character = FROM
			religion = fraticelli
		}
	}
	desc = {
		text = evt_CK2_39705_desc_b
		trigger = {
			NOT = { character = FROM }

			event_target:restored_pope = {
				religion = fraticelli
			}
		}
	}
	desc = {
		text = EVTDESC39705C
		trigger = {
			character = FROM
			religion = catholic
		}
	}
	desc = {
		text = EVTDESC39705D
		trigger = {
			NOT = { character = FROM }

			event_target:restored_pope = {
				religion = catholic
			}
		}
	}

	is_triggered_only = yes # restore_pope_in_rome, religious_decisions.txt
	major = yes

	major_trigger = {
		ai = no
		religion_group = christian
	}

	only_playable = yes

	option = {
		name = {
			text = EVTOPTA_SOA_4200
			trigger = { religion = fraticelli }
		}
		name = {
			text = EVTOPTB_SOA_4200
			trigger = { religion = catholic }
		}
		name = {
			text = EVTOPTC_SOA_4200
			trigger = {
				NOR = {
					religion = fraticelli
					religion = catholic
				}
			}
		}
	}
}

# Restore the Ecumenical Patriarchy
long_character_event = {
	id = 39706
	picture = GFX_evt_bishop
	border = GFX_event_long_frame_religion

	desc = {
		text = evt_CK2_39706_desc_a
		trigger = { character = FROM }
	}
	desc = {
		text = evt_CK2_39706_desc_b
		trigger = {
			NOT = { character = FROM }
		}
	}

	is_triggered_only = yes # restore_ecumenical_patriarchate, religious_decisions.txt
	major = yes

	only_playable = yes

	major_trigger = {
		ai = no
		religion_group = christian
	}

	option = {
		name = {
			text = EVTOPTA_SOA_4200
			trigger = { religion = orthodox }
		}
		name = {
			text = EVTOPTB_SOA_4200
			trigger = { religion = iconoclast }
		}
		name = {
			text = EVTOPTC_SOA_4200
			trigger = {
				NOR = {
					religion = iconoclast
					religion = orthodox
				}
			}
		}
	}
}

################################
# Jade Dragon religious events
################################

# KHURMAZTA
# Fired from Decision 'patrons_khu'
character_event = {
	id = 39800
	desc = EVTDESC39800
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # patrons_khu, jd_zoroastrian_decisions.txt

	option = {
		name = EVTOPTA_39800

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_desi
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTB_39800

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_parn
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTC_39800

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_nanaiya
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTD_39800

		character_event = { id = 39801 }
	}
}

character_event = {
	id = 39801
	desc = EVTDESC39801
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_39801

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_weshparkar
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTB_39801

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_wishaghn
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTC_39801

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_zurvan
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTD_39801

		character_event = { id = 39800 }
	}
}

# BON
# Fired from Decision 'patrons_bon'
character_event = {
	id = 39802
	desc = EVTDESC39802
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # patrons_bon, jd_bon_decisions.txt

	option = {
		name = EVTOPTA_39802

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_damchen
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTB_39802

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_shenla_okar
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTC_39802

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_shinje
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTD_39802

		character_event = { id = 39803 }
	}
}

character_event = {
	id = 39803
	desc = EVTDESC39803
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_39803

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_kula_kari
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTB_39803

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_lamlha
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTC_39803

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = patron_sangpo_bumtri
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = EVTOPTD_39803

		character_event = { id = 39802 }
	}
}

# Taoist school
# Fired from Decision 'school_tao'
character_event = {
	id = 39807
	desc = school_tao_1_desc
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # school_tao, jd_taoist_decisions.txt

	option = {
		name = school_tao_1_a

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = school_zhengyi
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = school_tao_1_b

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = school_quanzhen
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}

	option = {
		name = school_tao_1_c

		set_character_flag = patron_chosen

		add_character_modifier = {
			name = school_shangqing
			duration = -1
		}

		clr_character_flag = selecting_patron_deity
	}
}

# Remove main deity in case of religious conversion
# FROM is old religion scope

character_event = {
	id = 39804

	is_triggered_only = yes # on_character_convert_religion
	hide_window = yes

	trigger = {
		FROM = { religion_openly_bon_or_reformed_trigger = yes }
		religion_openly_bon_or_reformed_trigger = no
	}

	immediate = {
		remove_character_modifier = patron_damchen
		remove_character_modifier = patron_shenla_okar
		remove_character_modifier = patron_shinje
		remove_character_modifier = patron_kula_kari
		remove_character_modifier = patron_lamlha
		remove_character_modifier = patron_sangpo_bumtri
	}
}

character_event = {
	id = 39805

	is_triggered_only = yes # on_character_convert_religion
	hide_window = yes

	trigger = {
		FROM = { religion = khurmazta }
	}

	immediate = {
		remove_character_modifier = patron_desi
		remove_character_modifier = patron_parn
		remove_character_modifier = patron_nanaiya
		remove_character_modifier = patron_weshparkar
		remove_character_modifier = patron_wishaghn
		remove_character_modifier = patron_zurvan
	}
}

character_event = {
	id = 39806

	is_triggered_only = yes # on_character_convert_religion
	hide_window = yes

	trigger = {
		FROM = { religion = taoist }
	}

	immediate = {
		remove_character_modifier = school_quanzhen
		remove_character_modifier = school_shangqing
		remove_character_modifier = school_zhengyi
	}
}


# The birth of the Order of St Anthony (Alternate)
narrative_event = {
	id = 39810
	title = EVTTITLE39810
	desc = EVTDESC39810
	picture = GFX_evt_knight_kneeling

	is_triggered_only = yes # form_st_anthony, holy_order_decisions.txt
	major = yes

	major_trigger = {
		ai = no
	}

	immediate = {
		religion_scope = {
			save_event_target_as = holy_order_religion
		}

		activate_title = {
			title = d_saint_anthony
			status = yes
		}

		create_character = {
			random_traits = no
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 31
			add_trait = brilliant_strategist
			add_trait = zealous
			add_trait = humble
			add_trait = ambitious
			add_trait = strategist
			add_trait = holy_warrior
		}

		new_character = {
			d_saint_anthony = {
				religion = PREV
				grant_title = PREV

				save_persistent_event_target = {
					name = holy_order_religion
					scope = event_target:holy_order_religion
				}
			}

			set_defacto_liege = THIS
			wealth = 500
			set_government_type = order_government

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = armenian
				female = no
				age = 16
			}

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ethiopian
				female = no
				age = 18
			}

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ethiopian
				female = no
				age = 18
			}

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = armenian
				female = no
				age = 20
			}

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = greek
				female = no
				age = 25
			}

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = armenian
				female = no
				age = 26
			}

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ROOT
				female = no
				age = 28
			}

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ROOT
				female = yes
				age = 16
			}

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ROOT
				female = yes
				age = 17
			}
		}
	}

	option = {
		name = {
			text = EVTOPTA_SOA_2809
			trigger = { religion = ROOT }
		}
		name = {
			text = EVTOPTB_SOA_2809
			trigger = {
				NOT = { religion = ROOT	}
			}
		}
	}
}

# The birth of the Order of St Addai (Alternate)
narrative_event = {
	id = 39811
	desc = EVTDESC39811
	title = EVTTITLE39811
	picture = GFX_evt_knight_kneeling

	is_triggered_only = yes # form_st_addai, holy_order_decisions.txt
	major = yes

	major_trigger = {
		ai = no
	}

	immediate = {
		religion_scope = {
			save_event_target_as = holy_order_religion
		}

		activate_title = {
			title = d_saint_addai
			status = yes
		}

		create_character = {
			random_traits = no
			dynasty = random
			religion = ROOT
			culture = assyrian
			female = no
			age = 31
			add_trait = brilliant_strategist
			add_trait = zealous
			add_trait = humble
			add_trait = ambitious
			add_trait = strategist
			add_trait = holy_warrior
		}

		new_character = {
			d_saint_addai = {
				religion = PREV
				grant_title = PREV

				save_persistent_event_target = {
					name = holy_order_religion
					scope = event_target:holy_order_religion
				}
			}

			wealth = 500
			set_government_type = order_government

			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = persian
				female = no
				age = 16
			}

			while = {
				count = 6

				create_character = {
					random_traits = yes
					dynasty = random
					religion = ROOT
					culture = assyrian
					female = no
					min_age = 18
					max_age = 28
				}
			}

			while = {
				count = 2

				create_character = {
					random_traits = yes
					dynasty = random
					religion = ROOT
					culture = assyrian
					female = yes
					min_age = 16
					max_age = 17
				}
			}
		}
	}

	option = {
		name = {
			text = EVTOPTA_SOA_2809
			trigger = { religion = ROOT }
		}
		name = {
			text = EVTOPTB_SOA_2809
			trigger = {
				NOT = { religion = ROOT	}
			}
		}
	}
}

### Bema festival

# Invitation Sent
character_event = {
	id = 39812
	desc = EVTDESC39812
	picture = GFX_evt_religious_exultation
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # celebrate_bema, minor_decisions.txt

	option = {
		name = EVTOPTA39812

		custom_tooltip = {
			text = bema_invitations_sent

			any_vassal = {
				limit = {
					religion = manichaean
					is_adult = yes
					prisoner = no
					war = no
					is_incapable = no
				}

				character_event = {
					id = 39813
					days = 2
				#	tooltip = EVTTOOLTIP_39813
				}
			}

			character_event = {
				id = 39815 # Festival begins
				days = 10
			}

			character_event = {
				id = 39816 # Festival ends
				days = 12
			}
		}
	}
}

# Invitation Received
character_event = {
	id = 39813
	desc = EVTDESC39813
	picture = GFX_evt_religious_exultation
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	trigger = { is_inaccessible_trigger = no }

	option = {
		name = EVTOPTA39813

		custom_tooltip = {
			text = passover_accepted

			set_character_flag = attending_bema
			set_character_flag = do_not_disturb

			character_event = {
				id = 39815 # Festial begins
				days = 8
			}

			character_event = {
				id = 39818 # Safety catch flag clearing
				days = 20
			}
		}

		ai_chance = {
			factor = 80

			trigger = {
				opinion = {
					who = FROM
					value >= -20
				}
			}
		}
	}

	option = {
		name = EVTOPTB39813

		FROM = {
			show_scope_change = no

			opinion = {
				name = opinion_refused_bema
				who = ROOT
			}

			character_event = {
				id = 39814
				tooltip = passover_declined
			}
		}

		ai_chance = { factor = 20 }
	}
}

# Invitation Refused
character_event = {
	id = 39814
	desc = EVTDESC39814
	picture = GFX_evt_religious_exultation
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	ai = no

	option = {
		name = I_SEE

		tooltip = {
			opinion = {
				name = opinion_refused_bema
				who = FROM
			}
		}
	}
}

# Bema Begins
character_event = {
	id = 39815
	desc = EVTDESC39815
	picture = GFX_evt_religious_exultation
	border = GFX_event_normal_frame_religion

	hide_from = yes
	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA39815
	}
}

# Bema Ends (Host)
character_event = {
	id = 39816
	desc = EVTDESC39816
	picture = GFX_evt_religious_exultation
	border = GFX_event_normal_frame_religion

	hide_from = yes
	is_triggered_only = yes

	option = {
		name = EVTOPTA39816

		any_vassal = {
			show_scope_change = no

			limit = { has_character_flag = attending_bema }

			opinion = {
				name = opinion_held_bema
				who = ROOT
			}

			character_event = { id = 39817 }
		}

		add_character_modifier = {
			name = held_bema_timer
			years = 5
			hidden = yes
		}

		prestige = 100
		piety = 100

		clr_character_flag = holding_bema
		clr_character_flag = do_not_disturb
	}
}

# Bema Ends (Guest)
character_event = {
	id = 39817
	desc = EVTDESC39817
	picture = GFX_evt_religious_exultation
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39816

		clr_character_flag = attending_bema
		clr_character_flag = do_not_disturb
	}
}

# Safety catch - clears character flags and modifiers
character_event = {
	id = 39818

	hide_window = yes
	is_triggered_only = yes

	immediate = {
		clr_character_flag = do_not_disturb
		clr_character_flag = holding_bema
		clr_character_flag = attending_bema
	}
}

### Zoroastrian Jashan-e Sadah

# Invitations Sent (Liege)
character_event = {
	id = 39820
	desc = EVTDESC39820
	picture = GFX_evt_marriage_zoroastrian_group
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # celebrate_jashan_e_sadah, minor_decisions.txt
	hide_from = yes

	option = {
		name = EVTOPTA39820

		custom_tooltip = {
			text = sadeh_invitations_sent

			any_vassal = {
				limit = {
					is_adult = yes
					prisoner = no
					war = no
					is_incapable = no
				}

				character_event = {
					id = 39821
				#	tooltip = EVTTOOLTIP_39821
				}
			}

			character_event = {
				id = 39823
				days = 10
			}
		}
	}
}

# Invitations Received (Vassals)
character_event = {
	id = 39821
	desc = EVTDESC39821
	picture = GFX_evt_feast
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39821

		trigger = {
			religion_group = zoroastrian_group

			NOR = {
				religion = manichaean
				religion = mazdaki
			}
		}

		end_inaccessibility_effect = yes
		set_character_flag = attending_sadah
		set_character_flag = do_not_disturb
	}

	option = {
		name = EVTOPTB39821

		trigger = {
			trigger_if = {
				limit = { religion_group = zoroastrian_group }

				OR = {
					religion = manichaean
					religion = mazdaki
				}
			}
		}

		FROM = {
			show_scope_change = no

			character_event = {
				id = 39822
				days = 5
				tooltip = DIPLOWINDOW_REJECT
			}

			opinion = {
				name = opinion_refused_sadah
				who = ROOT
			}
		}
	}
}

# Invitation Refused (Liege)
character_event = {
	id = 39822
	desc = EVTDESC39822
	picture = GFX_evt_rival_rulers
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA39822

		tooltip = {
			opinion = {
				name = opinion_refused_sadah
				who = FROM
			}
		}
	}
}

# Celebration Begins (Liege)
character_event = {
	id = 39823
	desc = EVTDESC39823
	picture = GFX_evt_prospering_province
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA39823

		custom_tooltip = {
			text = sadah_begins1

			any_vassal = {
				limit = { has_character_flag = attending_sadah }

				character_event = { id = 39824 }
			}

			character_event = { id = 39830 days = 2 }
		}
	}
}

# Celebration Begins (Vassals)
character_event = {
	id = 39824
	desc = EVTDESC39824
	picture = GFX_evt_jewish_market
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39824

		character_event = {
			id = 39831
			days = 2
			tooltip = sadah_begins1
		}
	}
}

# Feast Begins (Liege)
character_event = {
	id = 39825
	desc = EVTDESC39825
	picture = GFX_evt_feast
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	hide_from = yes

	option = {
		name = EVTOPTA39825

		character_event = {
			id = 39827 # Feast ends
			days = 25
		}
	}
}

# Feast Begins (Vassals)
character_event = {
	id = 39826
	desc = EVTDESC39826
	picture = GFX_evt_feast
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA39825

		set_character_flag = sadah_feast_vassal
	}
}

# Feast Ends (Liege)
character_event = {
	id = 39827
	desc = EVTDESC39827
	picture = GFX_evt_powerful_ruler
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA39827

		any_vassal = {
			show_scope_change = no

			limit = { has_character_flag = attending_sadah }

			opinion = {
				name = opinion_held_sadah
				who = ROOT
			}

			clr_character_flag = attending_sadah
			clr_character_flag = sadah_feast_vassal
			clr_character_flag = feast_drunkard
			clr_character_flag = feast_gluttonous
			clr_character_flag = feast_lunatic
			clr_character_flag = feast_lustful
			clr_character_flag = feast_friendship
			clr_character_flag = feast_homosexual
			clr_character_flag = do_not_disturb
			character_event = { id = 39828 } # Feast ends
		}

		add_character_modifier = {
			name = jd_held_sadah_timer
			years = 5
		}

		prestige = 200
		piety = 100
		clr_character_flag = holding_sadah_feast
		clr_character_flag = feast_drunkard
		clr_character_flag = feast_gluttonous
		clr_character_flag = feast_lunatic
		clr_character_flag = feast_lustful
		clr_character_flag = feast_homosexual
		clr_character_flag = do_not_disturb
	}
}

# Feast Ends (Vassals)
character_event = {
	id = 39828
	desc = EVTDESC39828
	picture = GFX_evt_feast
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA39827
	}
}

# Fire prayer (Liege)
character_event = {
	id = 39830
	desc = EVTDESC39830
	picture = GFX_evt_religious_exultation
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA39823

		trigger = {
			has_fair_trait_trigger = no

			NOR = {
				trait = zealous
				trait = cynical
				trait = charitable
				trait = theologian
				trait = slothful
				trait = administrator
				trait = stressed
				trait = proud
				trait = lunatic
				trait = lustful
				trait = poet
				trait = tough_soldier
				trait = skilled_tactician
				trait = brilliant_strategist
				trait = detached_priest
				trait = dutiful_cleric
				trait = possessed
				trait = arbitrary
				trait = master_seducer
				trait = master_seductress
				trait = depressed
				trait = humble
				trait = content
				trait = gardener
				trait = gregarious
				trait = charismatic_negotiator
				trait = midas_touched
				trait = grey_eminence
			}
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_SCHOLAR
		tooltip_info_custom = EVTOPT39830_SCHOLAR_TT

		trigger = {
			OR = {
				trait = scholarly_theologian
				trait = mastermind_theologian
			}
		}

		add_character_modifier = {
			name = green_fingers
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_SOLDIER
		tooltip_info_custom = EVTOPT39830_SOLDIER_TT

		trigger = {
			OR = {
				trait = tough_soldier
				trait = skilled_tactician
				trait = brilliant_strategist
			}
		}

		add_character_modifier = {
			name = diligent_liege_morale
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_HUMBLE
		tooltip_info_custom = EVTOPT39830_HUMBLE_TT

		trigger = {
			OR = {
				trait = humble
				trait = content
				trait = gardener
			}
		}

		add_character_modifier = {
			name = green_fingers
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_GREG
		tooltip_info_custom = EVTOPT39830_GREG_TT

		trigger = {
			OR = {
				trait = gregarious
				has_fair_trait_trigger = yes
				trait = charismatic_negotiator
				trait = midas_touched
				trait = grey_eminence
			}
		}

		add_character_modifier = {
			name = popular_ruler
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_GLUTTON
		tooltip_info_custom = EVTOPT39830_GLUTTON_TT

		trigger = {
			OR = {
				trait = gluttonous
				trait = drunkard
				trait = hedonist
			}
		}

		add_character_modifier = {
			name = the_reveller
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_POET
		tooltip_info = poet

		trigger = { trait = poet }

		add_character_modifier = {
			name = aspiring_poet
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_LUNATIC
		tooltip_info = lunatic

		trigger = { trait = lunatic }

		add_character_modifier = {
			name = foolish_behavior
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_LUST
		tooltip_info_custom = EVTOPT39830_LUST_TT

		trigger = {
			OR = {
				trait = lustful
				trait = master_seducer
				trait = master_seductress
			}
		}

		add_character_modifier = {
			name = seizing_the_day
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_PROUD
		tooltip_info = proud

		trigger = { trait = proud }

		add_character_modifier = {
			name = the_pompous
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_STRESSED
		tooltip_info_custom = EVTOPT39830_STRESSED_TT

		trigger = {
			OR = {
				trait = stressed
				trait = depressed
			}
		}

		add_character_modifier = {
			name = blessing_of_health
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_ADMIN
		tooltip_info = administrator

		trigger = { trait = administrator }

		add_character_modifier = {
			name = inspired_peasantry
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_THEO
		tooltip_info_custom = EVTOPT39830_THEO_TT

		trigger = {
			OR = {
				trait = theologian
				trait = detached_priest
				trait = dutiful_cleric
			}
		}

		add_character_modifier = {
			name = renewed_faith
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_POSS
		tooltip_info = possessed

		trigger = { trait = possessed }

		add_character_modifier = {
			name = peasant_crisis
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_CHAR
		tooltip_info = charitable

		trigger = { trait = charitable }

		add_character_modifier = {
			name = recently_donated_to_charity
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_ZEAL
		tooltip_info = zealous

		trigger = { trait = zealous }

		add_character_modifier = {
			name = inspired_warriors
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_CYNIC
		tooltip_info_custom = EVTOPT39830_CYNIC_TT

		trigger = {
			OR = {
				trait = cynical
				trait = slothful
				trait = arbitrary
			}
		}

		add_character_modifier = {
			name = annoyed_religious
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	after = {
		character_event = {
			id = 39825
			days = 10
		}
	}
}

# Fire prayer (vassal)
character_event = {
	id = 39831
	desc = EVTDESC39831
	picture = GFX_evt_religious_exultation
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EVTOPTA39823

		trigger = {
			NOR = {
				trait = cynical
				trait = theologian
				trait = slothful
				trait = stressed
				trait = lustful
				trait = detached_priest
				trait = dutiful_cleric
				trait = arbitrary
				trait = master_seducer
				trait = master_seductress
				trait = depressed
				trait = gregarious
				trait = underhanded_rogue
				trait = charismatic_negotiator
			}
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39831_HEDONIST
		tooltip_info_custom = EVTOPT39831_HEDONIST_TT

		trigger = {
			OR = {
				trait = hedonist
				trait = drunkard
				trait = gluttonous
				trait = lustful
				trait = master_seducer
				trait = master_seductress
			}
		}

		add_character_modifier = {
			name = invigorated
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39831_CYNIC
		tooltip_info_custom = EVTOPT39831_CYNIC_TT

		trigger = {
			OR = {
				trait = cynical
				trait = arbitrary
			}
		}

		add_character_modifier = {
			name = church_unfunny
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39830_SCHOLAR
		tooltip_info_custom = EVTOPT39831_SCHOLAR_TT

		trigger = {
			OR = {
				trait = theologian
				trait = detached_priest
				trait = dutiful_cleric
				trait = scholarly_theologian
				trait = mastermind_theologian
			}
		}

		add_character_modifier = {
			name = discussed_scripture
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39831_GREG
		tooltip_info_custom = EVTOPT39831_GREG_TT

		trigger = {
			OR = {
				trait = gregarious
				trait = charismatic_negotiator
				trait = underhanded_rogue
			}
		}

		add_character_modifier = {
			name = took_stroll_small_talk
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	option = {
		name = EVTOPT39831_STRESSED
		tooltip_info_custom = EVTOPT39830_STRESSED_TT

		trigger = {
			OR = {
				trait = stressed
				trait = depressed
			}
		}

		add_character_modifier = {
			name = blessing_of_health
			years = 5
		}

		custom_tooltip = { text = sadah_begins }
	}

	after = {
		character_event = {
			id = 39826
			days = 10
		}
	}
}