﻿COR_prepare_coronation_ceremony_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_found_kingdom.dds"
	}
	decision_group_type = major
	ai_check_interval = 8 #check only once every 8 months.
	desc = COR_prepare_coronation_ceremony_decision_desc

	is_shown = {
		OR = {
			is_ai = yes
			AND = {
				has_dlc_feature = tours_and_tournaments
				has_dlc_feature = advanced_activities
			}
		}
		has_variable = COR_years_reigned
		OR = {
			highest_held_title_tier >= tier_kingdom
			HRT_is_emperor_trigger = yes
		}
		faith = faith:catholic
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		OR = {
			AND = {
				HRT_is_emperor_trigger = no
				NOR = {
					has_trait = COR_crowned_by_priest
					has_trait = COR_crowned_by_bishop
					has_trait = COR_crowned_by_pope
					has_trait = COR_crowned_by_myself
				}
			}
			AND = {
				HRT_is_emperor_trigger = yes
				NOR = {
					has_trait = HRT_emperor
					has_trait = COR_crowned_by_myself
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available = yes
		custom_tooltip = {
			text = COR_preparing_coronation_tooltip
			NOT = { has_character_flag = COR_flag_preparing_coronation } 
		}
		custom_tooltip = {
			text = COR_coronation_request_cooldown_tooltip
			NOT = { has_variable = COR_coronation_request_cooldown } 
		}
	}

	is_valid = {
		#highest_held_title_tier >= tier_kingdom
		faith = faith:catholic
		custom_tooltip = {
			text = COR_court_chaplain_tooltip
			exists = cp:councillor_court_chaplain
		}
		age >= 11
		OR = {
			custom_tooltip = {
				text = COR_war_defender
				NOT = {
					any_character_war ?= {
						is_war_leader = root
						is_defender = root
					}
				}
			}
			custom_tooltip = {
				text = COR_maxed_uncrowned_tooltip
				var:COR_years_reigned = 30
			}
		}
		trigger_if = { #Either is not excommunicated, or is an emperor with free investiture
			limit = {
				exists = global_var:Trinity_is_loaded
			}
			OR = {
				NOT = { has_trait = excommunicated }
				AND = {
					highest_held_title_tier = tier_empire
					custom_description = {
						text = "COR_excommunicated_free_investiture_tooltip"
						has_realm_law_flag = free_enacted
					}
				}
			}
		}
		trigger_else = {
			NOT = { has_trait = excommunicated }
		}
		trigger_if = { #Either is an adult, or the child is liked by the regent and has assertive traits.
			limit = {
				is_adult = no
			}
			OR = {
				has_trait = bossy
				has_trait = ambitious
				has_trait = intellect_good
			}
			diarch ?= {
				opinion = {
					target = root
					value >= neutral_opinion
				}
			}
		}
	}

	effect = {
		custom_tooltip = { text = COR_begin_coronation_tooltip }

		#Events
		trigger_event = COR_ceremony.0001
		set_variable = {
			name = COR_coronation_request_cooldown
			months = 5
		}
	}

	cost = { }

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100

		modifier = {
			factor = 0.1
			OR = {
				AND = {
					highest_held_title_tier = tier_empire
					exists = global_var:Trinity_is_loaded
					has_realm_law_flag = papal_enacted
				}
			}
			faith:catholic.religious_head = {
				opinion = {
					target = root
					value < very_high_negative_opinion
				}
			}
		}
		modifier = {
			factor = 0.5
			OR = {
				AND = {
					highest_held_title_tier = tier_empire
					exists = global_var:Trinity_is_loaded
					has_realm_law_flag = papal_enacted
				}
			}
			faith:catholic.religious_head = {
				opinion = {
					target = root
					value < high_negative_opinion
				}
			}
		}
		modifier = {
			factor = 0.6
			OR = {
				#highest_held_title_tier = tier_empire
				AND = {
					highest_held_title_tier = tier_empire
					exists = global_var:Trinity_is_loaded
					has_realm_law_flag = papal_enacted
				}
			}
			faith:catholic.religious_head = {
				opinion = {
					target = root
					value > high_negative_opinion
					value <= medium_negative_opinion
				}
			}
		}
		modifier = {
			factor = 0.7
			OR = {
				#highest_held_title_tier = tier_empire
				AND = {
					highest_held_title_tier = tier_empire
					exists = global_var:Trinity_is_loaded
					has_realm_law_flag = papal_enacted
				}
			}
			faith:catholic.religious_head = {
				opinion = {
					target = root
					value > medium_negative_opinion
					value <= low_negative_opinion
				}
			}
		}
		modifier = {
			factor = 0.8
			OR = {
				#highest_held_title_tier = tier_empire
				AND = {
					highest_held_title_tier = tier_empire
					exists = global_var:Trinity_is_loaded
					has_realm_law_flag = papal_enacted
				}
			}
			faith:catholic.religious_head = {
				opinion = {
					target = root
					value > low_negative_opinion
					value <= neutral_opinion
				}
			}
		}
		modifier = {
			factor = 1.5
			OR = {
				highest_held_title_tier = tier_empire
				AND = {
					highest_held_title_tier = tier_empire
					exists = global_var:Trinity_is_loaded
					has_realm_law_flag = papal_enacted
				}
			}
			faith:catholic.religious_head = {
				opinion = {
					target = root
					value > neutral_opinion
					value <= high_positive_opinion
				}
			}
		}
		modifier = {
			factor = 2
			OR = {
				highest_held_title_tier = tier_empire
				AND = {
					highest_held_title_tier = tier_empire
					exists = global_var:Trinity_is_loaded
					has_realm_law_flag = papal_enacted
				}
			}
			faith:catholic.religious_head = {
				opinion = {
					target = root
					value > high_positive_opinion
					value <= very_high_positive_opinion
				}
			}
		}
		modifier = {
			factor = 5
			OR = {
				highest_held_title_tier = tier_empire
				AND = {
					highest_held_title_tier = tier_empire
					exists = global_var:Trinity_is_loaded
					has_realm_law_flag = papal_enacted
				}
			}
			faith:catholic.religious_head = {
				opinion = {
					target = root
					value > very_high_positive_opinion
				}
			}
		}
		modifier = {
			factor = 0.5
			piety < 0
		}
		modifier = {
			factor = 0.5
			piety < 0
		}
		modifier = {
			factor = 0.5
			piety_level < 0
		}
		modifier = {
			factor = 1.5
			piety > medium_piety_value
		}
		modifier = {
			factor = 1.75
			piety > major_piety_value
		}
		modifier = {
			factor = 2
			piety > massive_piety_value
		}
		modifier = {
			factor = 5
			faith:catholic.religious_head = {
				is_vassal_of = root
			}
		}
		modifier = {
			factor = 1.5
			has_trait = zealous
		}
		modifier = {
			factor = 1.5
			OR = {
				has_trait = faith_warrior
				has_trait = crusader_king
			}
		}
		modifier = {
			factor = 0.5
			has_trait = cynical
		}
		modifier = {
			factor = 5
			has_title = title:e_hre
		}
		modifier = {
			factor = 1.5
			dynasty = dynasty:25061 #The Karlings will be more likely to request it
		}
		modifier = {
			factor = 1.5
			var:COR_years_reigned > 0
		}
		modifier = {
			factor = 1.75
			var:COR_years_reigned > 8
		}
		modifier = {
			factor = 2
			var:COR_years_reigned > 12
		}
		modifier = {
			factor = 3
			var:COR_years_reigned > 16
		}
		modifier = {
			factor = 4
			var:COR_years_reigned > 25
		}
	}
}

# 2.4 Jewel of Byzantium
COR_byz_prepare_coronation_ceremony_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_decision_hold_triumph.dds"
	}
	decision_group_type = major
	ai_check_interval = 3 #check only once every 3 months.
	desc = COR_byz_prepare_coronation_ceremony_decision_desc

	is_shown = {
		NOT = { has_trait = COR_byz_crowned_by_patriarch }
		OR = {
			is_ai = yes
			AND = {
				has_dlc_feature = tours_and_tournaments
				has_dlc_feature = advanced_activities
			}
		}
		has_variable = COR_years_reigned
		OR = {
			has_primary_title = title:e_byzantium
			has_primary_title = title:e_roman_empire
		}
		faith = faith:orthodox
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		is_landed = yes
		# 1.13 Roads to Power Compat
		NOT = {
			any_memory = {
				has_memory_type = deposed_liege_memory
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available = yes
		custom_tooltip = {
			text = COR_preparing_coronation_tooltip
			NOT = { has_character_flag = COR_flag_preparing_coronation } 
		}
		custom_tooltip = {
			text = COR_coronation_request_cooldown_tooltip
			NOT = { has_variable = COR_coronation_request_cooldown } 
		}
	}

	is_valid = {
		faith = faith:orthodox
		exists = faith:orthodox.religious_head
		age >= 11
		NOT = { has_trait = excommunicated }
		OR = {
			custom_tooltip = {
				text = COR_war_defender
				NOT = {
					any_character_war ?= {
						is_war_leader = root
						is_defender = root
					}
				}
			}
			custom_tooltip = {
				text = COR_maxed_uncrowned_tooltip
				var:COR_years_reigned = 30
			}
		}
		trigger_if = { #Either is an adult, or the child is liked by the regent and has assertive traits.
			limit = {
				is_adult = no
			}
			OR = {
				has_trait = bossy
				has_trait = ambitious
				has_trait = intellect_good
			}
			diarch ?= {
				opinion = {
					target = root
					value >= neutral_opinion
				}
			}
		}
	}

	effect = {
		custom_tooltip = { text = COR_begin_coronation_tooltip }

		#Events
		trigger_event = COR_ceremony.7001
		set_variable = {
			name = COR_coronation_request_cooldown
			months = 5
		}
	}

	cost = { }

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100

		modifier = {
			factor = 5
			has_primary_title = title:e_byzantium
		}
		modifier = {
			factor = 1.5
			var:COR_years_reigned > 0
		}
		modifier = {
			factor = 1.75
			var:COR_years_reigned > 8
		}
		modifier = {
			factor = 2
			var:COR_years_reigned > 12
		}
		modifier = {
			factor = 3
			var:COR_years_reigned > 16
		}
		modifier = {
			factor = 4
			var:COR_years_reigned > 25
		}
	}
}