decisions = {
	prepare_coronation_ceremony = {
		ai_check_interval = 8

		is_high_prio = yes

		only_playable = yes

		potential = {
			has_dlc = "Holy Fury"
			real_tier = KING

			OR = {
				religion = catholic
				religion = fraticelli
			}

			is_feudal = yes
			is_landed = yes
			age >= 11
			is_vice_royalty = no

			NOR = {
				trait = crowned_by_priest
				trait = crowned_by_bishop
				trait = crowned_by_pope
				trait = crowned_by_myself
				trait = crowned_by_priest_rd
				trait = crowned_by_bishop_rd
				trait = crowned_by_pope_rd
				trait = crowned_by_relhead
				trait = crowned_by_vip
				trait = crowned
				government = order_government
				has_landed_title = e_byzantium
				has_landed_title = e_hre
				has_landed_title = e_karling
			}
		}

		allow = {
			prisoner = no
			is_incapable = no

			trigger_if = {
				limit = { war = yes }

				custom_tooltip = {
					text = tooltip_maxed_uncrowned

					has_instances_of_character_modifier = {
						name = uncrowned_modifier
						amount >= 30
					}
				}
			}

			trigger_if = {
				limit = {
					real_tier = EMPEROR
					trait = excommunicated
					has_law = investiture_law_0
				}

				OR = {
					NOT = { trait = excommunicated }
					has_law = investiture_law_1
				}
			}

			trigger_if = {
				limit = { is_inaccessible_trigger = yes }

				custom_tooltip = {
					text = inaccessible_tooltip
					always = no
				}
			}

			trigger_if = {
				trigger = { is_adult = no }

				# Either is an adult, or the child is liked by the regent and has assertive traits
				OR = {
					is_adult = yes

					AND = {
						age >= 11

						custom_tooltip = {
							text = TT_CHILD_IS_ASSERTIVE

							OR = {
								trait = ambitious
								trait = quick
								trait = genius
								trait = willful
							}
						}

						trigger_if = {
							limit = { has_regent = yes }

							custom_tooltip = {
								text = TT_REGENT_LIKES_CHILD

								regent = {
									opinion = {
										who = liege
										value >= 0
									}
								}
							}
						}
					}
				}
			}

			trigger_if = {
				limit = { has_character_flag = do_not_disturb }

				custom_tooltip = {
					text = TT_NOT_OTHERWISE_OCCUPIED
					always = no
				}
			}

			trigger_if = {
				limit = { has_character_flag = flag_preparing_coronation }

				custom_tooltip = {
					text = TT_NOT_PREPARING_CORONATION
					always = no
				}
			}

			trigger_if = {
				limit = { has_character_modifier = coronation_request_cooldown }

				custom_tooltip = {
					text = TT_NOT_RECENTLY_ASKED_CORONATION
					always = no
				}
			}

			# In a war against an Excommunicated ruler/liege of an Antipope as part of a deal to be crowned
			custom_tooltip = {
				text = TT_NOT_FULFILLING_WAR_CORONATION

				NOR = {
					has_character_flag = flag_antipope_for_coronation
					has_character_flag = flag_excommunicated_for_coronation
					has_character_flag = flag_pepin_for_coronation
				}
			}

			# Either Pope exists, Fraticelli Pope exists, Any Bishop is your vassal, or you have a theocratic vassal
			OR = {
				custom_tooltip = {
					text = TT_CORONATION_RELIGIOUS_HEAD_POPE

					rightful_religious_head_scope = {
						controls_religion = yes
						block_general_event_trigger = no
					}
				}

				trigger_if = {
					limit = { real_tier = EMPEROR }

					has_law = investiture_law_1

					custom_tooltip = {
						text = TT_CORONATION_VASSAL_PRIEST

						any_realm_lord = {
							is_theocracy = yes
							religion = ROOT
							block_general_event_trigger = no
						}
					}
				}
				trigger_else = {
					custom_tooltip = {
						text = TT_CORONATION_VASSAL_PRIEST

						any_realm_lord = {
							is_theocracy = yes
							religion = ROOT
							block_general_event_trigger = no
						}
					}
				}
			}
		}

		effect = {
			custom_tooltip = {
				text = begin_coronation_tooltip

				character_event = { id = HF.20200 } # Who to be crowned by?

				add_character_modifier = {
					name = coronation_request_cooldown
					months = 5
					hidden = yes
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				trigger_if = {
					limit = {
						has_game_rule = {
							name = charlemagne_story
							value = on
						}
					}

					# Have their own event chain
					NOR = {
						has_character_flag = is_charlemagne
						has_character_flag = is_carloman
					}
				}
			}

			mult_modifier = {
				factor = 0.1

				real_tier = EMPEROR
				has_law = investiture_law_0

				religion_head = {
					opinion = {
						who = ROOT
						value < -80
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				real_tier = EMPEROR
				has_law = investiture_law_0

				religion_head = {
					opinion = {
						who = ROOT
						value < -60
					}
				}
			}

			mult_modifier = {
				factor = 0.6

				real_tier = EMPEROR
				has_law = investiture_law_0

				religion_head = {
					opinion = {
						who = ROOT
						value < -40
					}
				}
			}

			mult_modifier = {
				factor = 0.7

				real_tier = EMPEROR
				has_law = investiture_law_0

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

			mult_modifier = {
				factor = 0.8

				real_tier = EMPEROR
				has_law = investiture_law_0

				religion_head = {
					opinion = {
						who = ROOT
						value < 0
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				real_tier = EMPEROR
				has_law = investiture_law_0

				religion_head = {
					opinion = {
						who = ROOT
						value >= 20
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				real_tier = EMPEROR
				has_law = investiture_law_0

				religion_head = {
					opinion = {
						who = ROOT
						value >= 40
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				real_tier = EMPEROR
				has_law = investiture_law_0

				religion_head = {
					opinion = {
						who = ROOT
						value >= 60
					}
				}
			}

			mult_modifier = {
				factor = 2

				real_tier = EMPEROR
				has_law = investiture_law_0

				religion_head = {
					opinion = {
						who = ROOT
						value >= 80
					}
				}
			}

			mult_modifier = {
				factor = 5

				real_tier = EMPEROR
				has_law = investiture_law_0

				religion_head = {
					opinion = {
						who = ROOT
						value >= 100
					}
				}
			}

			mult_modifier = {
				factor = 0.5
				piety < 100
			}

			mult_modifier = {
				factor = 0.5
				piety < 0
			}

			mult_modifier = {
				factor = 1.5
				piety >= 250
			}

			mult_modifier = {
				factor = 1.5
				piety >= 500
			}

			mult_modifier = {
				factor = 1.75
				piety >= 750
			}

			mult_modifier = {
				factor = 2
				piety >= 1000
			}

			mult_modifier = {
				factor = 2
				piety >= 2000
			}

			mult_modifier = {
				factor = 5
				religion_head = { vassal_of = ROOT }
			}

			mult_modifier = {
				factor = 1.5
				trait = zealous
			}

			mult_modifier = {
				factor = 1.5
				trait = crusader
			}

			mult_modifier = {
				factor = 0.5
				trait = cynical
			}

			mult_modifier = {
				factor = 5
				has_landed_title = e_hre
			}

			mult_modifier = {
				factor = 1.5
				dynasty = 25061 # Karlings will be more likely to request it
			}

			mult_modifier = {
				factor = 1.5
				ruled_years >= 2
			}

			mult_modifier = {
				factor = 1.5
				ruled_years >= 4
			}

			mult_modifier = {
				factor = 1.5
				ruled_years >= 6
			}

			mult_modifier = {
				factor = 1.5
				ruled_years >= 8
			}

			mult_modifier = {
				factor = 1.75
				ruled_years >= 10
			}

			mult_modifier = {
				factor = 1.75
				ruled_years >= 12
			}

			mult_modifier = {
				factor = 2
				ruled_years >= 14
			}

			mult_modifier = {
				factor = 2
				ruled_years >= 16
			}

			mult_modifier = {
				factor = 3
				ruled_years >= 18
			}

			mult_modifier = {
				factor = 3
				ruled_years = 20
			}

			mult_modifier = {
				factor = 3
				ruled_years = 25
			}

			mult_modifier = {
				factor = 4
				ruled_years = 30
			}
		}
	}
}