namespace = Plus

#reserved: Plus.600 to Plus.619
#reserved: Plus.1600 to Plus.1649

#################################
# VOTING ON SUCCESSION LAW CHANGES
# Written by Wiz
# Updated by Rylock
#################################

### VOTES ON CHANGES TO FEUDAL ELECTIVE OR TANISTRY

# Liege calls de jure vassals to vote on changing the succession law
character_event = {
	id = Plus.600 #formerly 1000182996
	desc = "EVTDESC_Plus_600"
	picture = GFX_evt_council

	is_triggered_only = yes
	
	immediate = {
		random_demesne_title = {
			limit = { has_title_flag = emf_succ_title }
			clr_title_flag = emf_succ_title
			save_event_target_as = changed_title
		}
	}

	option = {
		name = "OK"
		if = {
			limit = { has_character_flag = vote_is_for_gavelkind }
			event_target:changed_title = {
				any_de_jure_vassal = {
					if = {
						limit = {
							OR = {
								AND = {
									PREV = { tier = COUNT }
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = KING
								}
							}
							OR = {
								same_realm = ROOT
								PREV = { has_law = succ_feudal_elective }
							}
							OR = {
								same_realm = ROOT
								religion = ROOT
							}
							NOT = { has_landed_title = PREV }
						}
						set_character_flag = voted_on_gavelkind
						letter_event = { id = Plus.601 days = 3 tooltip = CUSTOMTOOLTIP10 }
					}
				}
			}
		}
		if = {
			limit = { has_character_flag = vote_is_for_seniority }
			event_target:changed_title = {
				any_de_jure_vassal = {
					if = {
						limit = {
							OR = {
								AND = {
									PREV = { tier = COUNT }
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = KING
								}
							}
							OR = {
								same_realm = ROOT
								PREV = { has_law = succ_feudal_elective }
							}
							OR = {
								same_realm = ROOT
								religion = ROOT
							}
							NOT = { has_landed_title = PREV }
						}
						set_character_flag = voted_on_seniority
						letter_event = { id = Plus.603 days = 3 tooltip = CUSTOMTOOLTIP10 }
					}
				}
			}
		}
		if = {
			limit = { has_character_flag = vote_is_for_primogeniture }
			event_target:changed_title = {
				any_de_jure_vassal = {
					if = {
						limit = {
							OR = {
								AND = {
									PREV = { tier = COUNT }
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = KING
								}
							}
							OR = {
								same_realm = ROOT
								PREV = { has_law = succ_feudal_elective }
							}
							OR = {
								same_realm = ROOT
								religion = ROOT
							}
							NOT = { has_landed_title = PREV }
						}
						set_character_flag = voted_on_primogeniture
						letter_event = { id = Plus.602 days = 3 tooltip = CUSTOMTOOLTIP10 }
					}
				}
			}
		}
		if = {
			limit = { has_character_flag = vote_is_for_tanistry }
			event_target:changed_title = {
				any_de_jure_vassal = {
					if = {
						limit = {
							OR = {
								AND = {
									PREV = { tier = COUNT }
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = KING
								}
							}
							OR = {
								same_realm = ROOT
								PREV = { has_law = succ_feudal_elective }
							}
							OR = {
								same_realm = ROOT
								religion = ROOT
							}
							NOT = { has_landed_title = PREV }
						}
						set_character_flag = voted_on_tanistry
						letter_event = { id = Plus.615 days = 3 tooltip = CUSTOMTOOLTIP10 }
					}
				}
			}
		}
		if = {
			limit = { has_character_flag = vote_is_for_feudal_elective }
			event_target:changed_title = {
				any_de_jure_vassal = {
					if = {
						limit = {
							OR = {
								AND = {
									PREV = { tier = COUNT }
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = BARON
								}
								AND = {
									PREV = { tier = DUKE }
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									PREV = {
										OR = {
											has_law = succ_tanistry
											has_law = succ_elective_gavelkind
										}
									}
									tier = COUNT
								}
								AND = {
									PREV = { tier = KING }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = DUKE
								}
								AND = {
									PREV = { tier = EMPEROR }
									tier = KING
								}
							}
							OR = {
								same_realm = ROOT
								PREV = { has_law = succ_feudal_elective }
							}
							OR = {
								same_realm = ROOT
								religion = ROOT
							}
							NOT = { has_landed_title = PREV }
						}
						set_character_flag = voted_on_feudal_elective
						letter_event = { id = Plus.616 days = 3 tooltip = CUSTOMTOOLTIP10 }
					}
				}
			}
		}
		hidden_tooltip = {
			character_event = {
				id = Plus.610
				days = 14
			}
		}
	}
}

# Vassals vote to approve or disapprove Gavelkind
letter_event = {
	id = Plus.601 #formerly 1000182997
	desc = "EVTDESC_Plus_601"

	is_triggered_only = yes

	option = {
		name = "EVTOPTA_Plus_601" #Approve
		ai_chance = {
			factor = 100
			modifier = {
				factor = 10.0
				FROM = {
					reverse_opinion = { who = ROOT value = 99 }
				}
			}
			modifier = {
				factor = 5.0
				FROM = {
					reverse_opinion = { who = ROOT value = 75 }
				}
			}
			modifier = {
				factor = 2.0
				FROM = {
					reverse_opinion = { who = ROOT value = 50 }
				}
			}
			modifier = {
				factor = 0.5
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 25 }
					}
				}
			}
			modifier = {
				factor = 0.01
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 0 }
					}
				}
			}
			modifier = {
				factor = 0.01
				event_target:changed_title = {
					current_heir = {
						character = ROOT
						NOT = { is_child_of = FROM }
					}
				}
			}
			modifier = {
				factor = 0.5
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.5
				NOT = { same_realm = FROM }
			}
			modifier = {
				factor = 0.25
				event_target:changed_title = { has_law = succ_feudal_elective }
				NOT = { dynasty = FROM }
			}
			modifier = {
				factor = 2.0
				event_target:changed_title = { has_law = succ_feudal_elective }
				OR = {
					dynasty = FROM
					is_married = FROM
				}
			}
			modifier = {
				factor = 2.0
				event_target:changed_title = { has_law = succ_elective_gavelkind }
			}
			modifier = {
				factor = 10.0
				OR = {
					is_child_of = FROM
					father = { is_child_of = FROM }
				}
			}
			modifier = {
				factor = 0.1
				is_child_of = FROM
				OR = {
					AND = {
						event_target:changed_title = {
							OR = {
								has_law = agnatic_succession
								has_law = cognatic_succession
							}
						}
						is_female = no
						any_sibling = {
							NOT = { trait = bastard }
							is_female = no
							NOT = { is_older_than = ROOT }
						}
					}
					AND = {
						event_target:changed_title = {
							OR = {
								has_law = enatic_succession
								has_law = enatic_cognatic_succession
							}
						}
						is_female = yes
						any_sibling = {
							NOT = { trait = bastard }
							is_female = yes
							NOT = { is_older_than = ROOT }
						}
					}
					AND = {
						event_target:changed_title = { has_law = true_cognatic_succession }
						any_sibling = {
							NOT = { trait = bastard }
							NOT = { is_older_than = ROOT }
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_0
							has_law = tribal_organization_0
						}
					}
				}
			}
			modifier = {
				factor = 0.75
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_1
							has_law = tribal_organization_1
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_3
							has_law = tribal_organization_3
						}
					}
				}
			}
			modifier = {
				factor = 2.0
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_4
							has_law = tribal_organization_4
						}
					}
				}
			}
		}
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = 1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_approved_succession_law
				who = ROOT
				months = 120
			}
		}
	}

	option = {
		name = "EVTOPTB_Plus_601" #Ignore
		ai_chance = { factor = 100 }
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = -1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_ignored_succession_law
				who = ROOT
				months = 120
			}
		}
	}
}

# Vassals vote to approve or disapprove Primogeniture
letter_event = {
	id = Plus.602 #formerly 1000182998
	desc = "EVTDESC_Plus_602"

	is_triggered_only = yes

	option = {
		name = "EVTOPTA_Plus_601" #Approve
		ai_chance = {
			factor = 75
			modifier = {
				factor = 10.0
				FROM = {
					reverse_opinion = { who = ROOT value = 99 }
				}
			}
			modifier = {
				factor = 5.0
				FROM = {
					reverse_opinion = { who = ROOT value = 75 }
				}
			}
			modifier = {
				factor = 2.0
				FROM = {
					reverse_opinion = { who = ROOT value = 50 }
				}
			}
			modifier = {
				factor = 0.5
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 25 }
					}
				}
			}
			modifier = {
				factor = 0.01
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 0 }
					}
				}
			}
			modifier = {
				factor = 0.01
				event_target:changed_title = {
					current_heir = {
						character = ROOT
						NOT = { is_child_of = FROM }
					}
				}
			}
			modifier = {
				factor = 0.5
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.1
				is_child_of = FROM
				OR = {
					AND = {
						event_target:changed_title = {
							OR = {
								has_law = agnatic_succession
								has_law = cognatic_succession
							}
						}
						any_sibling = {
							NOT = { trait = bastard }
							is_female = no
							is_older_than = ROOT
						}
					}
					AND = {
						event_target:changed_title = {
							OR = {
								has_law = enatic_succession
								has_law = enatic_cognatic_succession
							}
						}
						any_sibling = {
							NOT = { trait = bastard }
							is_female = yes
							is_older_than = ROOT
						}
					}
					AND = {
						event_target:changed_title = { has_law = true_cognatic_succession }
						any_sibling = {
							NOT = { trait = bastard }
							is_older_than = ROOT
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				NOT = { same_realm = FROM }
			}
			modifier = {
				factor = 0.25
				event_target:changed_title = { has_law = succ_feudal_elective }
				NOT = { dynasty = FROM }
			}
			modifier = {
				factor = 0.5
				NOT = { event_target:changed_title = { has_law = succ_feudal_elective } }
				NOT = { dynasty = FROM }
			}
			modifier = {
				factor = 5.0
				event_target:changed_title = { has_law = succ_feudal_elective }
				NOT = { is_child_of = FROM }
				OR = {
					is_married = FROM
					father = { is_child_of = FROM }
				}
			}
			modifier = {
				factor = 10.0
				is_child_of = FROM
				NOR = {
					AND = {
						event_target:changed_title = {
							OR = {
								has_law = agnatic_succession
								has_law = cognatic_succession
							}
						}
						any_sibling = {
							NOT = { trait = bastard }
							is_female = no
							is_older_than = ROOT
						}
					}
					AND = {
						event_target:changed_title = {
							OR = {
								has_law = enatic_succession
								has_law = enatic_cognatic_succession
							}
						}
						any_sibling = {
							NOT = { trait = bastard }
							is_female = yes
							is_older_than = ROOT
						}
					}
					AND = {
						event_target:changed_title = { has_law = true_cognatic_succession }
						any_sibling = {
							NOT = { trait = bastard }
							is_older_than = ROOT
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_0
							has_law = tribal_organization_0
						}
					}
				}
			}
			modifier = {
				factor = 0.75
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_1
							has_law = tribal_organization_1
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_3
							has_law = tribal_organization_3
						}
					}
				}
			}
			modifier = {
				factor = 2.0
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_4
							has_law = tribal_organization_4
						}
					}
				}
			}
		}
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = 1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_approved_succession_law
				who = ROOT
				months = 120
			}
		}
	}

	option = {
		name = "EVTOPTB_Plus_601" #Ignore
		ai_chance = { factor = 100 }
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = -1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_ignored_succession_law
				who = ROOT
				months = 120
			}
		}
	}
}

# Vassals vote to approve or disapprove Seniority
letter_event = {
	id = Plus.603 #formerly 1000182999
	desc = "EVTDESC_Plus_603"

	is_triggered_only = yes

	option = {
		name = "EVTOPTA_Plus_601" #Approve
		ai_chance = {
			factor = 100
			modifier = {
				factor = 10.0
				FROM = {
					reverse_opinion = { who = ROOT value = 99 }
				}
			}
			modifier = {
				factor = 5.0
				FROM = {
					reverse_opinion = { who = ROOT value = 75 }
				}
			}
			modifier = {
				factor = 2.0
				FROM = {
					reverse_opinion = { who = ROOT value = 50 }
				}
			}
			modifier = {
				factor = 0.5
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 25 }
					}
				}
			}
			modifier = {
				factor = 0.01
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 0 }
					}
				}
			}
			modifier = {
				factor = 0.01
				event_target:changed_title = {
					current_heir = {
						character = ROOT
						NOT = { dynasty = FROM }
					}
				}
			}
			modifier = {
				factor = 0.5
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.5
				NOT = { same_realm = FROM }
			}
			modifier = {
				factor = 0.25
				event_target:changed_title = { has_law = succ_feudal_elective }
				NOT = { dynasty = FROM }
			}
			modifier = {
				factor = 2.0
				OR = {
					culture_group = east_slavic
					culture_group = west_slavic
					culture_group = south_slavic
					culture = hungarian
				}
			}
			modifier = {
				factor = 10.0
				dynasty = FROM
			}
			modifier = {
				factor = 0.5
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_0
							has_law = tribal_organization_0
						}
					}
				}
			}
			modifier = {
				factor = 0.75
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_1
							has_law = tribal_organization_1
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_3
							has_law = tribal_organization_3
						}
					}
				}
			}
			modifier = {
				factor = 2.0
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_4
							has_law = tribal_organization_4
						}
					}
				}
			}
		}
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = 1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_approved_succession_law
				who = ROOT
				months = 120
			}
		}
	}

	option = {
		name = "EVTOPTB_Plus_601" #Ignore
		ai_chance = { factor = 100 }
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = -1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_ignored_succession_law
				who = ROOT
				months = 120
			}
		}
	}
}

# Vassals vote to approve or disapprove Tanistry
letter_event = {
	id = Plus.615
	desc = "EVTDESC_Plus_615"

	is_triggered_only = yes

	option = {
		name = "EVTOPTA_Plus_601" #Approve
		ai_chance = {
			factor = 100
			modifier = {
				factor = 10.0
				FROM = {
					reverse_opinion = { who = ROOT value = 99 }
				}
			}
			modifier = {
				factor = 5.0
				FROM = {
					reverse_opinion = { who = ROOT value = 75 }
				}
			}
			modifier = {
				factor = 2.0
				FROM = {
					reverse_opinion = { who = ROOT value = 50 }
				}
			}
			modifier = {
				factor = 0.5
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 25 }
					}
				}
			}
			modifier = {
				factor = 0.01
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 0 }
					}
				}
			}
			modifier = {
				factor = 0.01
				event_target:changed_title = {
					current_heir = {
						character = ROOT
						NOT = { dynasty = FROM }
					}
				}
			}
			modifier = {
				factor = 0.5
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.5
				NOT = { same_realm = FROM }
			}
			modifier = {
				factor = 0.25
				event_target:changed_title = { has_law = succ_feudal_elective }
				NOT = { dynasty = FROM }
			}
			modifier = {
				factor = 2.0
				OR = {
					culture_group = celtic
					culture = scottish
					religion = celtic_pagan
				}
			}
			modifier = {
				factor = 10.0
				dynasty = FROM
			}
			modifier = {
				factor = 0.5
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_0
							has_law = tribal_organization_0
						}
					}
				}
			}
			modifier = {
				factor = 0.75
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_1
							has_law = tribal_organization_1
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_3
							has_law = tribal_organization_3
						}
					}
				}
			}
			modifier = {
				factor = 2.0
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_4
							has_law = tribal_organization_4
						}
					}
				}
			}
		}
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = 1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_approved_succession_law
				who = ROOT
				months = 120
			}
		}
	}

	option = {
		name = "EVTOPTB_Plus_601" #Ignore
		ai_chance = { factor = 100 }
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = -1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_ignored_succession_law
				who = ROOT
				months = 120
			}
		}
	}
}

# Vassals vote to approve or disapprove Feudal Elective
letter_event = {
	id = Plus.616
	desc = "EVTDESC_Plus_616"

	is_triggered_only = yes

	option = {
		name = "EVTOPTA_Plus_601" #Approve
		ai_chance = {
			factor = 100
			modifier = {
				factor = 10.0
				FROM = {
					reverse_opinion = { who = ROOT value = 99 }
				}
			}
			modifier = {
				factor = 5.0
				FROM = {
					reverse_opinion = { who = ROOT value = 75 }
				}
			}
			modifier = {
				factor = 2.0
				FROM = {
					reverse_opinion = { who = ROOT value = 50 }
				}
			}
			modifier = {
				factor = 0.75
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 25 }
					}
				}
			}
			modifier = {
				factor = 0.5
				NOT = {
					FROM = {
						reverse_opinion = { who = ROOT value = 0 }
					}
				}
			}
			modifier = {
				factor = 0.01
				event_target:changed_title = {
					NOT = { has_law = succ_elective_gavelkind }
					current_heir = { character = ROOT }
				}
			}
			modifier = {
				factor = 0.5
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.5
				NOT = { same_realm = FROM }
			}
			modifier = {
				factor = 0.5
				dynasty = FROM
			}
			modifier = {
				factor = 2.5
				NOT = { dynasty = FROM }
			}
			modifier = {
				factor = 2.0
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_0
							has_law = tribal_organization_0
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				event_target:changed_title = {
					crownlaw_title = {
						OR = {
							has_law = crown_authority_1
							has_law = tribal_organization_1
						}
					}
				}
			}
		}
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = 1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_approved_succession_law
				who = ROOT
				months = 120
			}
		}
	}

	option = {
		name = "EVTOPTB_Plus_601" #Ignore
		ai_chance = { factor = 100 }
		FROM = {
			hidden_tooltip = { change_variable = { which = "succession_law_vote" value = -1 } }
			hidden_tooltip = {
				remove_opinion = {
					modifier = opinion_approved_succession_law
					who = ROOT
				}
				remove_opinion = {
					modifier = opinion_ignored_succession_law
					who = ROOT
				}
			}
			opinion = {
				modifier = opinion_ignored_succession_law
				who = ROOT
				months = 120
			}
		}
	}
}

# The law passes or is defeated
character_event = {
	id = Plus.610
	desc = "EVTDESC_Plus_610"
	picture = GFX_evt_council

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				check_variable = { which = "succession_law_vote" value = -0.5 }
				has_character_flag = vote_is_for_gavelkind
			}
			clr_character_flag = vote_is_for_gavelkind
			event_target:changed_title = {
				pf_save_old_succ_law_effect = yes
				save_event_target_as = emf_succ_title
				holder_scope = { save_event_target_as = emf_succ_changer }
				
				log = "---> [emf_succ_changer.GetTitledFirstName] (ID: [emf_succ_changer.GetID]) succeded with vote to change law for [emf_succ_title.GetID] to Gavelkind"
				
				# Mark current heir and pretenders so that they may be tracked after law change
				emf_laws_change_succ_save_contenders_effect = yes
				
				# Actually change the law now
				add_law = succ_gavelkind
				
				current_heir = { save_event_target_as = emf_heir }

				holder_scope = {
					# Vassals are slightly upset
					any_vassal = {
						limit = {
							emf_laws_change_succ_affected_vassal_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_mild_reaction_effect = yes
					}
					# Legitimate children are happy
					any_child = {
						limit = {
							can_inherit_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_good_reaction_effect = yes
					}
					# Current heir is slightly upset if they were the previous heir (they have to share)
					event_target:emf_heir = {
						if = {
							limit = { character = event_target:emf_former_heir }
							emf_laws_change_succ_mild_reaction_effect = yes
						}
					}
				}
				
				# Specfic, event-driven succession law change reactions for the new heir, the former heir,
				# the former pretenders, and the new pretenders.
				set_title_flag = emf_succ_title
				holder_scope = { character_event = { id = Plus.604 } }
				
				emf_laws_change_succ_cleanup_effect = yes
				
				any_de_jure_vassal_title = {
					limit = {
						holder_scope = { has_character_flag = vote_is_for_gavelkind }
					}
					holder_scope = {
						if = {
							limit = { has_character_flag = voted_on_gavelkind }
							character_event = { id = Plus.611 }
						}
						clr_character_flag = succession_vote
						clr_character_flag = voted_on_gavelkind
						clr_character_flag = vote_is_for_gavelkind
					}
				}
			}
			break = yes
		}
		if = {
			limit = {
				check_variable = { which = "succession_law_vote" value = -0.5 }
				has_character_flag = vote_is_for_primogeniture
			}			
			clr_character_flag = vote_is_for_primogeniture
			event_target:changed_title = {
				pf_save_old_succ_law_effect = yes
				save_event_target_as = emf_succ_title
				holder_scope = { save_event_target_as = emf_succ_changer }
				
				log = "---> [emf_succ_changer.GetTitledFirstName] (ID: [emf_succ_changer.GetID]) succeded with vote to change law for [emf_succ_title.GetID] to Primogeniture"
				
				emf_laws_change_succ_save_contenders_effect = yes
				add_law = succ_primogeniture
				current_heir = { save_event_target_as = emf_heir }

				holder_scope = {
					# Vassals are slightly upset
					any_vassal = {
						limit = {
							emf_laws_change_succ_affected_vassal_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_mild_reaction_effect = yes
					}
					# Dynasty members are slightly upset
					any_dynasty_member = {
						limit = {
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_mild_reaction_effect = yes
					}
					# Legitimate children are angry
					any_child = {
						limit = {
							can_inherit_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_bad_reaction_effect = yes
					}
					# Heir is happy
					event_target:emf_heir = { emf_laws_change_succ_good_reaction_effect = yes }
				}
				
				set_title_flag = emf_succ_title
				holder_scope = { character_event = { id = Plus.604 } }
				emf_laws_change_succ_cleanup_effect = yes
				
				any_de_jure_vassal = {
					limit = { has_character_flag = voted_on_primogeniture }
					character_event = { id = Plus.611 }
					clr_character_flag = succession_vote
					clr_character_flag = voted_on_primogeniture
				}
			}
			break = yes
		}
		if = {
			limit = {
				check_variable = { which = "succession_law_vote" value = -0.5 }
				has_character_flag = vote_is_for_seniority
			}			
			clr_character_flag = vote_is_for_seniority
			event_target:changed_title = {
				pf_save_old_succ_law_effect = yes
				save_event_target_as = emf_succ_title
				holder_scope = { save_event_target_as = emf_succ_changer }
				
				log = "---> [emf_succ_changer.GetTitledFirstName] (ID: [emf_succ_changer.GetID]) succeded with vote to change law for [emf_succ_title.GetID] to Seniority"
				
				emf_laws_change_succ_save_contenders_effect = yes
				add_law = succ_seniority
				current_heir = { save_event_target_as = emf_heir }

				holder_scope = {
					# Vassals are slightly upset
					any_vassal = {
						limit = {
							emf_laws_change_succ_affected_vassal_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_mild_reaction_effect = yes
					}
					# Dynasty members are happy
					any_dynasty_member = {
						limit = {
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_good_reaction_effect = yes
					}
					# Children that can inherit are angry
					any_child = {
						limit = {
							can_inherit_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_bad_reaction_effect = yes
					}
				}
				
				# Specfic, event-driven succession law change reactions for the new heir, the former heir,
				# the former pretenders, and the new pretenders.
				set_title_flag = emf_succ_title
				holder_scope = { character_event = { id = Plus.604 } }
				
				emf_laws_change_succ_cleanup_effect = yes
				
				any_de_jure_vassal = {
					limit = { has_character_flag = voted_on_seniority }
					character_event = { id = Plus.611 }
					clr_character_flag = succession_vote
					clr_character_flag = voted_on_seniority
				}
			}
			break = yes
		}
		if = {
			limit = {
				check_variable = { which = "succession_law_vote" value = -0.5 }
				has_character_flag = vote_is_for_tanistry
			}			
			clr_character_flag = vote_is_for_tanistry
			event_target:changed_title = {
				pf_save_old_succ_law_effect = yes
				save_event_target_as = emf_succ_title
				holder_scope = { save_event_target_as = emf_succ_changer }
				
				log = "---> [emf_succ_changer.GetTitledFirstName] (ID: [emf_succ_changer.GetID]) succeded with vote to change law for [emf_succ_title.GetID] to Tanistry"
				
				emf_laws_change_succ_save_contenders_effect = yes
				add_law = succ_tanistry
				current_heir = { save_event_target_as = emf_heir }

				# FIXME: I'm just guessing about Tanistry's behavior from the little, imprecise, and likely
				# inaccurate info on the CKII Wiki.

				holder_scope = {
					# Vassals are slightly upset
					any_vassal = {
						limit = {
							emf_laws_change_succ_affected_vassal_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_mild_reaction_effect = yes
					}
					# Elector vassals are happy.
					# Regarding Tanistry, my assumptions are that empire-tier titles have king- and
					# duke-tier electors, king-tier titles have duke- and count-tier electors, duke-tier
					# titles have count- and baron-tier electors, and count-tier titles have baron-tier
					# electors.
					any_vassal = {
						limit = {
							emf_laws_change_succ_vip_trigger = no
							OR = {
								AND = {
									event_target:emf_succ_title = { tier = EMPEROR }
									higher_real_tier_than = COUNT
									OR = {
										event_target:emf_succ_title = { is_titular = yes }
										any_demesne_title = {
											higher_tier_than = COUNT
											de_jure_liege_or_above = event_target:emf_succ_title
										}
									}
								}
								AND = {
									event_target:emf_succ_title = { tier = KING }
									higher_real_tier_than = BARON
									OR = {
										event_target:emf_succ_title = { is_titular = yes }
										any_demesne_title = {
											higher_tier_than = BARON
											de_jure_liege_or_above = event_target:emf_succ_title
										}
									}
								}
								AND = {
									event_target:emf_succ_title = { tier = DUKE }
									OR = {
										event_target:emf_succ_title = { is_titular = yes }
										any_demesne_title = {
											de_jure_liege_or_above = event_target:emf_succ_title
										}
									}
								}
								AND = {
									event_target:emf_succ_title = { tier = COUNT }
									any_demesne_title = {
										de_jure_liege = event_target:emf_succ_title
									}
								}
							}
						}
						emf_laws_change_succ_good_reaction_effect = yes
					}
					# Dynasty members are happy
					any_dynasty_member = {
						limit = { 
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_good_reaction_effect = yes
					}
					# Legitimate children are angry
					any_child = {
						limit = {
							can_inherit_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_bad_reaction_effect = yes
					}
					# The former pretenders are upset if not of the ruler's dynasty
					any_opinion_modifier_target = {
						limit = {
							is_alive = yes
							reverse_has_opinion_modifier = { who = PREV modifier = opinion_succ_former_pretender }
							NOT = { dynasty = event_target:emf_succ_changer }
						}
						emf_laws_change_succ_bad_reaction_effect = yes
						event_target:emf_succ_title = {
							if = {
								limit = { NOT = { claimed_by = PREV } }
								add_weak_claim = PREV
							}
						}
						any_spouse = {
							limit = {
								emf_laws_change_succ_vip_trigger = no
								NOT = { dynasty = event_target:emf_succ_changer }
							}
							emf_laws_change_succ_bad_reaction_effect = yes
						}
						any_child = {
							limit = {
								can_inherit_trigger = yes
								emf_laws_change_succ_vip_trigger = no
								NOT = { dynasty = event_target:emf_succ_changer }
							}
							emf_laws_change_succ_bad_reaction_effect = yes
						}
					}
					# The former heir is upset if not of the ruler's dynasty
					event_target:emf_former_heir = {
						if = {
							limit = { NOT = { dynasty = event_target:emf_succ_changer } }
							event_target:emf_succ_title = { add_claim = PREV }
							emf_laws_change_succ_terrible_reaction_effect = yes
							any_spouse = {
								limit = {
									emf_laws_change_succ_vip_trigger = no
									NOT = { dynasty = event_target:emf_succ_changer }
								}
								emf_laws_change_succ_terrible_reaction_effect = yes
							}
							any_child = {
								limit = {
									can_inherit_trigger = yes
									emf_laws_change_succ_vip_trigger = no
									NOT = { dynasty = event_target:emf_succ_changer }
								}
								emf_laws_change_succ_terrible_reaction_effect = yes
							}
						}
					}
				}
				
				emf_laws_change_succ_cleanup_effect = yes
				
				any_de_jure_vassal = {
					limit = { has_character_flag = voted_on_tanistry }
					character_event = { id = Plus.611 }
					clr_character_flag = succession_vote
					clr_character_flag = voted_on_tanistry
				}
			}
			break = yes
		}
		if = {
			limit = {
				check_variable = { which = "succession_law_vote" value = -0.5 }
				has_character_flag = vote_is_for_feudal_elective
			}			
			clr_character_flag = vote_is_for_feudal_elective
			event_target:changed_title = {
				pf_save_old_succ_law_effect = yes
				save_event_target_as = emf_succ_title
				holder_scope = { save_event_target_as = emf_succ_changer }
				
				log = "---> [emf_succ_changer.GetTitledFirstName] (ID: [emf_succ_changer.GetID]) succeded with vote to change law for [emf_succ_title.GetID] to Feudal Elective"
				
				emf_laws_change_succ_save_contenders_effect = yes
				add_law = succ_feudal_elective
				current_heir = { save_event_target_as = emf_heir }

				holder_scope = {
					# Vassals are slightly upset
					any_vassal = {
						limit = {
							emf_laws_change_succ_affected_vassal_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_mild_reaction_effect = yes
					}
					# Electors are happy
					any_vassal = {
						limit = {
							emf_laws_change_succ_vip_trigger = no
							OR = {
								AND = {
									event_target:emf_succ_title = { tier = EMPEROR }
									higher_real_tier_than = COUNT
									OR = {
										event_target:emf_succ_title = { is_titular = yes }
										any_demesne_title = {
											higher_tier_than = COUNT
											de_jure_liege_or_above = event_target:emf_succ_title
										}
									}
								}
								AND = {
									event_target:emf_succ_title = { tier = KING }
									real_tier = DUKE
									OR = {
										event_target:emf_succ_title = { is_titular = yes }
										any_demesne_title = {
											tier = DUKE
											de_jure_liege = event_target:emf_succ_title
										}
									}
								}
								AND = {
									event_target:emf_succ_title = { tier = DUKE }
									real_tier = COUNT
									OR = {
										event_target:emf_succ_title = { is_titular = yes }
										any_demesne_title = {
											tier = COUNT
											de_jure_liege = event_target:emf_succ_title
										}
									}
								}
								AND = {
									event_target:emf_succ_title = { tier = COUNT }
									real_tier = BARON
									any_demesne_title = {
										de_jure_liege = event_target:emf_succ_title
									}
								}
							}
						}
						emf_laws_change_succ_good_reaction_effect = yes
					}
					# Dynasty members are slightly upset
					any_dynasty_member = {
						limit = {
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_mild_reaction_effect = yes
					}
					# Legitimate children are angry
					any_child = {
						limit = {
							can_inherit_trigger = yes
							emf_laws_change_succ_vip_trigger = no
						}
						emf_laws_change_succ_bad_reaction_effect = yes
					}
					# The former pretenders are upset
					any_opinion_modifier_target = {
						limit = {
							is_alive = yes
							reverse_has_opinion_modifier = { who = PREV modifier = opinion_succ_former_pretender }
						}
						emf_laws_change_succ_bad_reaction_effect = yes
						event_target:emf_succ_title = {
							if = {
								limit = { NOT = { claimed_by = PREV } }
								add_weak_claim = PREV
							}
						}
						any_spouse = {
							limit = { emf_laws_change_succ_vip_trigger = no }
							emf_laws_change_succ_bad_reaction_effect = yes
						}
						any_child = {
							limit = {
								can_inherit_trigger = yes
								emf_laws_change_succ_vip_trigger = no
							}
							emf_laws_change_succ_bad_reaction_effect = yes
						}
					}
					# The former heir is upset
					event_target:emf_former_heir = {
						emf_laws_change_succ_bad_reaction_effect = yes
						event_target:emf_succ_title = { add_claim = PREV }
						any_spouse = {
							limit = { emf_laws_change_succ_vip_trigger = no }
							emf_laws_change_succ_bad_reaction_effect = yes
						}
						any_child = {
							limit = {
								can_inherit_trigger = yes
								emf_laws_change_succ_vip_trigger = no
							}
							emf_laws_change_succ_bad_reaction_effect = yes
						}
					}
				}
				
				emf_laws_change_succ_cleanup_effect = yes

				any_de_jure_vassal = {
					limit = { has_character_flag = voted_on_feudal_elective }
					character_event = { id = Plus.611 }
					clr_character_flag = succession_vote
					clr_character_flag = voted_on_feudal_elective
				}
			}
			break = yes
		}
		if = {
			limit = { has_character_flag = vote_is_for_gavelkind }
			clr_character_flag = vote_is_for_gavelkind
			event_target:changed_title = {
				any_de_jure_vassal = {
					limit = { has_character_flag = voted_on_gavelkind }
					character_event = { id = Plus.612 }
					clr_character_flag = succession_vote
					clr_character_flag = voted_on_gavelkind
				}
			}
			break = yes
		}
		if = {
			limit = { has_character_flag = vote_is_for_primogeniture }
			clr_character_flag = vote_is_for_primogeniture
			event_target:changed_title = {
				any_de_jure_vassal = {
					limit = { has_character_flag = voted_on_primogeniture }
					character_event = { id = Plus.612 }
					clr_character_flag = succession_vote
					clr_character_flag = voted_on_primogeniture
				}
			}
			break = yes
		}
		if = {
			limit = { has_character_flag = vote_is_for_seniority }
			clr_character_flag = vote_is_for_seniority
			event_target:changed_title = {
				any_de_jure_vassal = {
					limit = { has_character_flag = voted_on_seniority }
					character_event = { id = Plus.612 }
					clr_character_flag = succession_vote
					clr_character_flag = voted_on_seniority
				}
			}
			break = yes
		}
		if = {
			limit = { has_character_flag = vote_is_for_tanistry }
			clr_character_flag = vote_is_for_tanistry
			event_target:changed_title = {
				any_de_jure_vassal = {
					limit = { has_character_flag = voted_on_tanistry }
					character_event = { id = Plus.612 }
					clr_character_flag = succession_vote
					clr_character_flag = voted_on_tanistry
				}
			}
			break = yes
		}
		if = {
			limit = { has_character_flag = vote_is_for_feudal_elective }
			clr_character_flag = vote_is_for_feudal_elective
			event_target:changed_title = {
				any_de_jure_vassal = {
					limit = { has_character_flag = voted_on_feudal_elective }
					character_event = { id = Plus.612 }
					clr_character_flag = succession_vote
					clr_character_flag = voted_on_feudal_elective
				}
			}
			break = yes
		}
	}

	option = {
		name = "EVTOPTA_Plus_610" #Approved
		trigger = {
			check_variable = { which = "succession_law_vote" value = -0.5 }
		}
		hidden_tooltip = {
			set_variable = { which = "succession_law_vote" value = 0 }
		}
		ROOT = {
			custom_tooltip = { text = CUSTOMTOOLTIP8 }
		}
		event_target:changed_title = {
			any_de_jure_vassal = {
				limit = {
					reverse_has_opinion_modifier = {
						who = ROOT
						modifier = opinion_approved_succession_law
					}
				}
				custom_tooltip = { text = CUSTOMTOOLTIP8 }
			}
		}
		event_target:changed_title = {
			any_de_jure_vassal = {
				limit = {
					reverse_has_opinion_modifier = {
						who = ROOT
						modifier = opinion_ignored_succession_law
					}
				}
				custom_tooltip = { text = CUSTOMTOOLTIP9 }
			}
		}
		clr_character_flag = voting_on_succession_law
	}

	option = {
		name = "EVTOPTB_Plus_610" #Rejected
		trigger = {
			NOT = { check_variable = { which = "succession_law_vote" value = -0.5 } }
		}
		hidden_tooltip = {
			set_variable = { which = "succession_law_vote" value = 0 }
		}
		ROOT = {
			custom_tooltip = { text = CUSTOMTOOLTIP8 }
		}
		event_target:changed_title = {
			any_de_jure_vassal = {
				limit = {
					reverse_has_opinion_modifier = {
						who = ROOT
						modifier = opinion_approved_succession_law
					}
				}
				custom_tooltip = { text = CUSTOMTOOLTIP8 }
			}
		}
		event_target:changed_title = {
			any_de_jure_vassal = {
				limit = {
					reverse_has_opinion_modifier = {
						who = ROOT
						modifier = opinion_ignored_succession_law
					}
				}
				custom_tooltip = { text = CUSTOMTOOLTIP9 }
			}
		}
		if = {
			limit = { event_target:changed_title = { tier = BARON } }
			prestige = 65
		}
		if = {
			limit = { event_target:changed_title = { tier = COUNT } }
			prestige = 125
		}
		if = {
			limit = { event_target:changed_title = { tier = DUKE } }
			prestige = 250
		}
		if = {
			limit = { event_target:changed_title = { tier = KING } }
			prestige = 375
		}
		if = {
			limit = { event_target:changed_title = { tier = EMPEROR } }
			prestige = 50
		}
		clr_character_flag = voting_on_succession_law
	}
}

# Notification - success
character_event = {
	id = Plus.611
	desc = "EVTDESC_Plus_611"
	picture = GFX_evt_council

	is_triggered_only = yes

	ai = no

	option = {
		name = "OK"
		FROM = {
			custom_tooltip = { text = CUSTOMTOOLTIP8 }
		}
		event_target:changed_title = {
			any_de_jure_vassal = {
				limit = {
					reverse_has_opinion_modifier = {
						who = FROM
						modifier = opinion_approved_succession_law
					}
				}
				custom_tooltip = { text = CUSTOMTOOLTIP8 }
			}
		}
		event_target:changed_title = {
			any_de_jure_vassal = {
				limit = {
					reverse_has_opinion_modifier = {
						who = FROM
						modifier = opinion_ignored_succession_law
					}
				}
				custom_tooltip = { text = CUSTOMTOOLTIP9 }
			}
		}
	}
}

# Notification - failure
character_event = {
	id = Plus.612
	desc = "EVTDESC_Plus_612"
	picture = GFX_evt_council

	is_triggered_only = yes

	ai = no

	option = {
		name = "OK"
		FROM = {
			custom_tooltip = { text = CUSTOMTOOLTIP8 }
		}
		event_target:changed_title = {
			any_de_jure_vassal = {
				limit = {
					reverse_has_opinion_modifier = {
						who = FROM
						modifier = opinion_approved_succession_law
					}
				}
				custom_tooltip = { text = CUSTOMTOOLTIP8 }
			}
		}
		event_target:changed_title = {
			any_de_jure_vassal = {
				limit = {
					reverse_has_opinion_modifier = {
						who = FROM
						modifier = opinion_ignored_succession_law
					}
				}
				custom_tooltip = { text = CUSTOMTOOLTIP9 }
			}
		}
	}
}

#######################################
# REACTIONS TO SUCCESSION LAW CHANGES
# Written by Rylock & zijistark
#######################################

# Base event fired on the ruler after changing a law
#
# Context (which should all be manually cleared when we're done):
# - Succession law title has flag emf_succ_title
# - opinion_succ_former_heir points to the former heir
# - opinion_succ_former_pretender points to the former pretenders

character_event = {
	id = Plus.604
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_alive = yes
	}
	
	immediate = {
		save_event_target_as = emf_succ_changer
		
		random_demesne_title = { # Save our title...
			limit = { has_title_flag = emf_succ_title }
			clr_title_flag = emf_succ_title
			save_event_target_as = emf_succ_title
		}
		
		if = {
			limit = { NOT = { event_target:emf_succ_title = { always = yes } } }
			log = "ERROR: Succession law change title (emf_succ_title) not found in demesne of [Root.GetTitledName] (ID: [Root.GetID]); aborting!"
			break = yes
		}
		
		log = "DEBUG: Plus.604: Processing succession law change reactions for the [emf_succ_title.GetFullBaseName] held by [Root.GetTitledFirstName] (ID: [Root.GetID])..."
		
		event_target:emf_succ_title = { current_heir = { save_event_target_as = emf_heir } } # ... and its new heir
		
		if = {
			limit = { event_target:emf_heir = { always = yes } }
			log = "---> New Heir: [emf_heir.GetTitledName] (emf_heir.GetID)"
		}
		
		if = {
			limit = { NOT = { event_target:emf_heir = { always = yes } } }
			log = "---> Succession law change for the [emf_succ_title.GetFullBaseName] resulted in no known successor."
		}
		
		random_opinion_modifier_target = { # Save our former heir...
			limit = { reverse_has_opinion_modifier = { who = PREV modifier = opinion_succ_former_heir } }
			save_event_target_as = emf_former_heir
		}
		
		if = {
			limit = { event_target:emf_former_heir = { always = yes } }
			log = "---> Former Heir: [emf_former_heir.GetTitledName] (emf_former_heir.GetID)"
		}
		
		if = {
			limit = { NOT = { event_target:emf_former_heir = { always = yes } } }
			log = "---> No former heir for the [emf_succ_title.GetFullBaseName]."
		}		

		# Should the former heir have died or somehow not existed, emf_former_heir will be undefined, but that should
		# work just fine for all of the uses below.		
		
		event_target:emf_former_heir = {
			 # Former heir is now neither heir nor pretender
			if = {
				limit = {
					NOT = { character = event_target:emf_heir }
					NOT = { any_pretender_title = { title = event_target:emf_succ_title } }
				}
				character_event = { id = Plus.605 }
			}
			
			# Former heir is now pretender
			if = {
				limit = {
					NOT = { character = event_target:emf_heir }
					any_pretender_title = { title = event_target:emf_succ_title }
				}
				character_event = { id = Plus.606 }
			}
		}		
		
		# Former pretenders that are now neither heir nor pretender
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = opinion_succ_former_pretender }
				NOT = { character = event_target:emf_heir }
				NOT = { any_pretender_title = { title = event_target:emf_succ_title } }
			}
			character_event = { id = Plus.607 }
		}		
		
		# The new heir
		event_target:emf_heir = {
			if = {
				limit = { NOT = { character = event_target:emf_former_heir } }
				character_event = { id = Plus.608 }
			}
		}
		
		# The new pretenders
		any_character = {
			limit = {
				any_pretender_title = { title = event_target:emf_succ_title }
				NOR = {
					character = event_target:emf_former_heir
					character = event_target:emf_heir
					reverse_has_opinion_modifier = {
						who = ROOT
						modifier = opinion_succ_former_pretender
					}
				}
			}
			character_event = { id = Plus.609 }
		}
	}
}

# A former heir is now neither the heir nor a pretender
character_event = {
	id = Plus.605
	picture = "GFX_evt_scandal"
	desc = "EVTDESC_Plus_605"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_605" #So be it
		trigger = {
			NOR = {
				trait = lunatic
				trait = possessed
			}
		}
		ai_chance = {
			factor = 30
			modifier = {
				factor = 3
				trait = content
			}
			modifier = {
				factor = 2
				trait = humble
			}
			modifier = {
				factor = 1.5
				trait = charitable
			}
			modifier = {
				factor = 1.5
				trait = patient
			}
			modifier = {
				factor = 1.5
				trait = trusting
			}
			modifier = {
				factor = 0.5
				trait = proud
			}
			modifier = {
				factor = 0.25
				trait = ambitious
			}
		}
		log = "---> Former heir [Root.GetTitledName] (ID: [Root.GetID]) is now neither heir nor pretender (gracefully accepts)"

		emf_laws_change_succ_bad_reaction_effect = yes
		opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 2 months = 240 }

		custom_tooltip = { text = emf_laws_ctt_succ_change_reaction_to_pretenders }
		any_character = {
			limit = { any_pretender_title = { title = event_target:emf_succ_title } }
			reverse_opinion = { who = ROOT modifier = opinion_resentful months = 240 }
		}
		if = {
			limit = {
				any_spouse = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_spouse_reactions }
		}
		any_spouse = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
			}
			emf_laws_change_succ_bad_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 2 months = 240 }
		}
		if = {
			limit = {
				any_child = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
					NOT = { any_spouse = { character = event_target:emf_heir } }
					can_inherit_trigger = yes
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_child_reactions }
		}
		any_child = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
				NOT = { any_spouse = { character = event_target:emf_heir } }
				can_inherit_trigger = yes
			}
			emf_laws_change_succ_bad_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 2 months = 240 }
		}
	}
	option = {
		name = "EVTOPTB_Plus_605" #This is an outrage!
		ai_chance = {
			factor = 70
			modifier = {
				factor = 3
				trait = ambitious
			}
			modifier = {
				factor = 2
				trait = proud
			}
			modifier = {
				factor = 1.5
				trait = envious
			}
			modifier = {
				factor = 1.5
				trait = greedy
			}
			modifier = {
				factor = 1.5
				trait = wroth
			}
			modifier = {
				factor = 1.5
				trait = paranoid
			}
			modifier = {
				factor = 0.5
				trait = humble
			}
			modifier = {
				factor = 0.25
				trait = content
			}
		}
		log = "---> Former heir [Root.GetTitledName] (ID: [Root.GetID]) is now neither heir nor pretender (outraged)"

		set_character_flag = justified_claimant
		opinion = { who = FROM modifier = succ_law_disinherit months = 360 }
		opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 5 months = 240 }
		event_target:emf_succ_title = { add_claim = ROOT }		
		
		custom_tooltip = { text = emf_laws_ctt_succ_change_reaction_to_pretenders }
		any_character = {
			limit = { any_pretender_title = { title = event_target:emf_succ_title } }
			reverse_opinion = { who = ROOT modifier = opinion_resentful multiplier = 2 months = 240 }
		}
		if = {
			limit = {
				any_spouse = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_spouse_reactions }
		}
		any_spouse = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
			}
			emf_laws_change_succ_terrible_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 5 months = 240 }
		}
		if = {
			limit = {
				any_child = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
					NOT = { any_spouse = { character = event_target:emf_heir } }
					can_inherit_trigger = yes
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_child_reactions }
		}
		any_child = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
				NOT = { any_spouse = { character = event_target:emf_heir } }
				can_inherit_trigger = yes
			}
			emf_laws_change_succ_terrible_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 5 months = 240 }
		}
	}
}

# A former heir is now pretender
character_event = {
	id = Plus.606
	picture = "GFX_evt_scandal"
	desc = "EVTDESC_Plus_606"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_605" #So be it
		trigger = {
			NOR = {
				trait = lunatic
				trait = possessed
			}
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 3
				trait = content
			}
			modifier = {
				factor = 2
				trait = humble
			}
			modifier = {
				factor = 1.5
				trait = charitable
			}
			modifier = {
				factor = 1.5
				trait = patient
			}
			modifier = {
				factor = 1.5
				trait = trusting
			}
			modifier = {
				factor = 0.5
				trait = proud
			}
			modifier = {
				factor = 0.25
				trait = ambitious
			}
		}
		log = "---> Former heir [Root.GetTitledName] (ID: [Root.GetID]) is now merely a pretender (gracefully accepts)"

		emf_laws_change_succ_bad_reaction_effect = yes
		opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 2 months = 120 }

		if = {
			limit = {
				any_spouse = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_spouse_reactions }
		}
		any_spouse = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
			}
			emf_laws_change_succ_bad_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 2 months = 240 }
		}
		if = {
			limit = {
				any_child = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
					NOT = { any_spouse = { character = event_target:emf_heir } }
					can_inherit_trigger = yes
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_child_reactions }
		}
		any_child = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
				NOT = { any_spouse = { character = event_target:emf_heir } }
				can_inherit_trigger = yes
			}
			emf_laws_change_succ_bad_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 2 months = 240 }
		}
	}
	option = {
		name = "EVTOPTB_Plus_605" #This is an outrage!
		ai_chance = {
			factor = 50
			modifier = {
				factor = 3
				trait = ambitious
			}
			modifier = {
				factor = 2
				trait = proud
			}
			modifier = {
				factor = 1.5
				trait = envious
			}
			modifier = {
				factor = 1.5
				trait = greedy
			}
			modifier = {
				factor = 1.5
				trait = wroth
			}
			modifier = {
				factor = 1.5
				trait = paranoid
			}
			modifier = {
				factor = 0.5
				trait = humble
			}
			modifier = {
				factor = 0.25
				trait = content
			}
		}
		log = "---> Former heir [Root.GetTitledName] (ID: [Root.GetID]) is now merely a pretender (outraged)"
		
		set_character_flag = justified_claimant
		emf_laws_change_succ_terrible_reaction_effect = yes
		opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 5 months = 240 }
		event_target:emf_succ_title = { add_claim = ROOT }		

		if = {
			limit = {
				any_spouse = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_spouse_reactions }
		}
		any_spouse = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
			}
			emf_laws_change_succ_terrible_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 5 months = 240 }
		}
		if = {
			limit = {
				any_child = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
					NOT = { any_spouse = { character = event_target:emf_heir } }
					can_inherit_trigger = yes
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_child_reactions }
		}
		any_child = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
				NOT = { any_spouse = { character = event_target:emf_heir } }
				can_inherit_trigger = yes
			}
			emf_laws_change_succ_terrible_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 5 months = 240 }
		}
	}
}

# A former pretender is now neither the heir nor a pretender
character_event = {
	id = Plus.607
	picture = "GFX_evt_scandal"
	desc = "EVTDESC_Plus_607"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_605" #So be it
		trigger = {
			NOR = {
				trait = lunatic
				trait = possessed
			}
		}
		ai_chance = {
			factor = 70
			modifier = {
				factor = 3
				trait = content
			}
			modifier = {
				factor = 2
				trait = humble
			}
			modifier = {
				factor = 1.5
				trait = charitable
			}
			modifier = {
				factor = 1.5
				trait = patient
			}
			modifier = {
				factor = 1.5
				trait = trusting
			}
			modifier = {
				factor = 0.5
				trait = proud
			}
			modifier = {
				factor = 0.25
				trait = ambitious
			}
		}
		log = "---> Former pretender [Root.GetTitledName] (ID: [Root.GetID]) is now neither heir nor pretender (gracefully accepts)"
		emf_laws_change_succ_bad_reaction_effect = yes

		if = {
			limit = {
				any_spouse = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_spouse_reactions }
		}
		any_spouse = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
			}
			emf_laws_change_succ_bad_reaction_effect = yes
		}
		if = {
			limit = {
				any_child = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
					NOT = { any_spouse = { character = event_target:emf_heir } }
					can_inherit_trigger = yes
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_child_reactions }
		}
		any_child = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
				NOT = { any_spouse = { character = event_target:emf_heir } }
				can_inherit_trigger = yes
			}
			emf_laws_change_succ_bad_reaction_effect = yes
		}
	}
	option = {
		name = "EVTOPTB_Plus_605" #This is an outrage!
		ai_chance = {
			factor = 30
			modifier = {
				factor = 3
				trait = ambitious
			}
			modifier = {
				factor = 2
				trait = proud
			}
			modifier = {
				factor = 1.5
				trait = envious
			}
			modifier = {
				factor = 1.5
				trait = greedy
			}
			modifier = {
				factor = 1.5
				trait = wroth
			}
			modifier = {
				factor = 1.5
				trait = paranoid
			}
			modifier = {
				factor = 0.5
				trait = humble
			}
			modifier = {
				factor = 0.25
				trait = content
			}
		}
		log = "---> Former pretender [Root.GetTitledName] (ID: [Root.GetID]) is now neither heir nor pretender (outraged)"

		set_character_flag = justified_claimant
		emf_laws_change_succ_terrible_reaction_effect = yes
		event_target:emf_succ_title = { add_weak_claim = ROOT }
		opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 2 months = 240 }

		custom_tooltip = { text = emf_laws_ctt_succ_change_reaction_to_pretenders }
		any_character = {
			limit = { any_pretender_title = { title = event_target:emf_succ_title } }
			reverse_opinion = { who = ROOT modifier = opinion_resentful months = 240 }
		}
		if = {
			limit = {
				any_spouse = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_spouse_reactions }
		}
		any_spouse = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
			}
			emf_laws_change_succ_terrible_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 2 months = 240 }
		}
		if = {
			limit = {
				any_child = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
					NOT = { any_spouse = { character = event_target:emf_heir } }
					can_inherit_trigger = yes
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_child_reactions }
		}
		any_child = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
				NOT = { any_spouse = { character = event_target:emf_heir } }
				can_inherit_trigger = yes
			}
			emf_laws_change_succ_terrible_reaction_effect = yes
			opinion = { who = event_target:emf_heir modifier = opinion_resentful multiplier = 2 months = 240 }
		}
	}
}

# The new heir is informed
character_event = {
	id = Plus.608
	picture = "GFX_evt_emissary"
	desc = "EVTDESC_Plus_608"
	
	is_triggered_only = yes
	
	option = {
		name = EXCELLENT
		log = "---> New heir [Root.GetTitledName] (ID: [Root.GetID]) is pleased"
		emf_laws_change_succ_good_reaction_effect = yes
		
		if = {
			limit = {
				any_spouse = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_spouse_reactions }
		}
		any_spouse = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
			}
			emf_laws_change_succ_good_reaction_effect = yes
		}
		if = {
			limit = {
				any_child = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
					NOT = { any_spouse = { character = event_target:emf_heir } }
					can_inherit_trigger = yes
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_child_reactions }
		}
		any_child = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
				NOT = { any_spouse = { character = event_target:emf_heir } }
				can_inherit_trigger = yes
			}
			emf_laws_change_succ_good_reaction_effect = yes
		}
	}
}

# The new pretenders are informed
character_event = {
	id = Plus.609
	picture = "GFX_evt_emissary"
	desc = "EVTDESC_Plus_609"
	
	is_triggered_only = yes
	
	option = {
		name = EXCELLENT
		log = "---> New pretender [Root.GetTitledName] (ID: [Root.GetID]) is pleased"
		emf_laws_change_succ_good_reaction_effect = yes
		
		if = {
			limit = {
				any_spouse = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_spouse_reactions }
		}
		any_spouse = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
			}
			emf_laws_change_succ_good_reaction_effect = yes
		}
		if = {
			limit = {
				any_child = {
					NOT = { character = FROM }
					NOT = { any_child = { character = event_target:emf_heir } }
					NOT = { any_spouse = { character = event_target:emf_heir } }
					can_inherit_trigger = yes
				}
			}
			custom_tooltip = { text = emf_laws_ctt_succ_change_child_reactions }
		}
		any_child = {
			limit = {
				NOT = { character = FROM }
				NOT = { any_child = { character = event_target:emf_heir } }
				NOT = { any_spouse = { character = event_target:emf_heir } }
				can_inherit_trigger = yes
			}
			emf_laws_change_succ_good_reaction_effect = yes
		}
	}
}

######################################
# ASKING VASSALS TO SUPPORT YOUR HEIR
# Written by Rylock
######################################

# Vassal is asked to support the current heir
character_event = {
	id = Plus.1600
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		FROMFROM = { current_heir = { save_event_target_as = liege_heir } }
		log = "[Root.GetTitledName] has been asked by [FromFrom.GetTitledName] to support [FromFrom.GetHerHis] heir, [liege.heir.GetTitledName]."
		opinion = { who = FROMFROM modifier = asked_to_support_heir years = 20 }
		random_list = {
			50 = {
				modifier = {
					factor = 1.5
					FROMFROM = { primary_title = { has_law = crown_authority_4 } }
				}
				modifier = {
					factor = 1.5
					is_friend = FROMFROM
				}
				modifier = {
					factor = 1.2
					opinion = { who = FROMFROM value = 90 }
				}
				modifier = {
					factor = 1.2
					FROMFROM = { diplomacy = 16 }
				}
				modifier = {
					factor = 1.2
					FROMFROM = { diplomacy = 20 }
				}
				modifier = {
					factor = 1.5
					is_friend = event_target:liege_heir
				}
				modifier = {
					factor = 1.5
					is_close_relative = event_target:liege_heir
				}
				modifier = {
					factor = 1.2
					event_target:liege_heir = { is_ruler = yes }
				}
				modifier = {
					factor = 1.1
					opinion = { who = event_target:liege_heir value = 20 }
				}
				modifier = {
					factor = 1.1
					opinion = { who = event_target:liege_heir value = 40 }
				}
				modifier = {
					factor = 1.1
					opinion = { who = event_target:liege_heir value = 60 }
				}
				modifier = {
					factor = 1.1
					opinion = { who = event_target:liege_heir value = 80 }
				}
				modifier = {
					factor = 1.2
					trait = trusting
				}
				modifier = {
					factor = 1.5
					trait = content
				}
				modifier = {
					factor = 1.2
					trait = humble
				}
				modifier = {
					factor = 1.2
					trait = kind
				}
				FROMFROM = { letter_event = { id = Plus.1601 days = 15 } } # Agree
			}
			50 = {
				modifier = {
					factor = 0.5
					FROMFROM = { primary_title = { has_law = crown_authority_4 } }
				}
				modifier = {
					factor = 1.2
					FROMFROM = { NOT = { diplomacy = 8 } }
				}
				modifier = {
					factor = 1.2
					FROMFROM = { NOT = { diplomacy = 4 } }
				}
				modifier = {
					factor = 1.2
					NOT = { opinion = { who = FROMFROM value = 70 } }
				}
				modifier = {
					factor = 1.2
					NOT = { opinion = { who = event_target:liege_heir value = 0 } }
				}
				modifier = {
					factor = 1.5
					NOT = { opinion = { who = event_target:liege_heir value = -25 } }
				}
				modifier = {
					factor = 1.5
					NOT = { opinion = { who = event_target:liege_heir value = -50 } }
				}
				modifier = {
					factor = 1.5
					event_target:liege_heir = { is_female = yes }
					FROMFROM = {
						primary_title = {
							OR = {
								has_law = agnatic_succession
								has_law = cognatic_succession
							}
						}
					}
				}
				modifier = {
					factor = 1.5
					event_target:liege_heir = { is_female = no }
					FROMFROM = {
						primary_title = {
							OR = {
								has_law = enatic_succession
								has_law = enatic_cognatic_succession
							}
						}
					}
				}
				modifier = {
					factor = 1.5
					event_target:liege_heir = {
						OR = {
							trait = imbecile
							trait = lunatic
							trait = possessed
							trait = incapable
						}
					}
				}
				modifier = {
					factor = 1.5
					NOR = {
						religion = event_target:liege_heir
						culture = event_target:liege_heir
					}
				}
				modifier = {
					factor = 1.2
					trait = paranoid
				}
				modifier = {
					factor = 1.5
					trait = ambitious
				}
				modifier = {
					factor = 1.2
					trait = proud
				}
				modifier = {
					factor = 1.2
					trait = envious
				}
				modifier = {
					factor = 1.2
					trait = cruel
				}
				FROMFROM = { letter_event = { id = Plus.1602 days = 15 } } # Refuse
			}
		}
	}
}

# Vassal agrees to support heir
letter_event = {
	id = Plus.1601
	desc = EVTDESC_Plus_1601
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes
	
	trigger = {
		current_heir = { character = event_target:liege_heir }
		FROM = { vassal_of = ROOT }
	}
	
	option = {
		name = EXCELLENT
		FROM = {
			opinion = { who = event_target:liege_heir modifier = sworn_to_support_heir years = 20 }
			reverse_opinion = { who = ROOT modifier = opinion_pleased years = 5 }
		}
	}
}

# Vassal refuses to support heir
letter_event = {
	id = Plus.1602
	desc = EVTDESC_Plus_1602
	border = GFX_event_letter_frame_diplomacy
	
	is_triggered_only = yes
	
	trigger = {
		current_heir = { character = event_target:liege_heir }
		FROM = { vassal_of = ROOT }
	}
	
	option = {
		name = CURSES
		opinion = { who = FROM modifier = refused_to_support_heir years = 10 }
		if = {
			limit = { FROM = { tier = COUNT } }
			prestige = 50
		}
		if = {
			limit = { FROM = { tier = DUKE } }
			prestige = 125
		}
		if = {
			limit = { FROM = { tier = KING } }
			prestige = 250
		}
	}
}

# Maintenance event: remove support for heir if he is neither heir nor liege
character_event = {
	id = Plus.1603
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		any_opinion_modifier_target = {
			is_alive = yes
			reverse_has_opinion_modifier = {
				who = ROOT
				modifier = sworn_to_support_heir
			}
			NOR = {
				is_liege_or_above = ROOT
				any_heir_title = {
					is_primary_holder_title = yes
					holder_scope = { is_vassal_or_below = ROOT }
				}
			}
		}
	}
	
	weight_multiplier = {
		days = 1
	}
	
	immediate = {
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = {
					who = ROOT
					modifier = sworn_to_support_heir
				}
				NOR = {
					is_liege_or_above = ROOT
					any_heir_title = {
						is_primary_holder_title = yes
						holder_scope = { is_vassal_or_below = ROOT }
					}
				}
			}
			reverse_remove_opinion = {
				who = ROOT
				modifier = sworn_to_support_heir
			}
		}
	}
}

######################################
# SUCCESSION CRISIS EVENTS
# Written by Rylock
######################################

# King/Emperor dies at low CA with possibly unsuitable heir
character_event = {
	id = Plus.1610
	
	hide_window = yes
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		is_feudal = yes
		has_game_rule = {
			name = succession_crisis
			value = yes
		}
		primary_title = {
			higher_tier_than = DUKE
			temporary = no
			#low crown authority
			OR = {
				has_law = crown_authority_0
				has_law = crown_authority_1
			}
			#only applies to certain succession laws
			OR = {
				has_law = succ_seniority
				has_law = succ_primogeniture
				has_law = succ_ultimogeniture
				has_law = succ_feudal_elective
				has_law = succ_tanistry
			}
			#current heir is female or unsuitable
			OR = {
				AND = {
					OR = {
						has_law = cognatic_succession
						has_law = true_cognatic_succession
					}
					current_heir = { is_female = yes }
					ROOT = { 
						is_female = no 
						is_feminist_trigger = no
					}
				}
				current_heir = {
					OR = {
						NOT = { age = 13 }
						trait = incapable
						trait = imbecile
						trait = inbred
						trait = lunatic
					}
				}
			}
		}
		#at least three vassals who can vote
		any_vassal = {
			has_regent = no
			higher_real_tier_than = COUNT
			count = 3
		}
		#there is another suitable male heir available
		any_dynasty_member = {
			is_alive = yes
			OR = {
				is_female = no
				ROOT = {
					is_feminist_trigger = yes
				}
			}
			is_theocracy = no
			is_republic = no
			mercenary = no
			holy_order = no
			age = 13
			NOR = {
				is_primary_heir = ROOT
				character = ROOT
				trait = incapable
				trait = imbecile
				trait = inbred
				trait = lunatic
				trait = possessed
				trait = eunuch
				trait = monk
				trait = nun
				trait = abdicated
				trait = disinherited
				trait = druid
				trait = bad_druid
				trait = retired_vestalis
				trait = vestalis
				any_liege = {
					OR = {
						holy_order = yes
						mercenary = yes
					}
				}
			}
		}
	}
	
	immediate = {
		set_variable = { which = "succ_candidates" value = 0 }
		current_heir = { save_event_target_as = next_in_line }
		
		#check whether we should be accepting female candidates
		if = {
			limit = {
				is_female = no
				is_feminist_trigger = no
				current_heir = {
					is_female = yes
					age = 13
					NOR = {
						trait = incapable
						trait = imbecile
						trait = inbred
						trait = lunatic
					}
				}
			}
			set_character_flag = no_female_candidates
		}
		
		#find candidates for non-voting succession laws
		if = {
			limit = {
				primary_title = {
					OR = {
						has_law = succ_seniority
						has_law = succ_primogeniture
						has_law = succ_ultimogeniture
					}
				}
			}
			#save current laws
			primary_title = {
				if = {
					limit = { has_law = succ_seniority }
					set_title_flag = revert_seniority
				}
				if = {
					limit = { has_law = succ_primogeniture }
					set_title_flag = revert_primogeniture
				}
				if = {
					limit = { has_law = succ_ultimogeniture }
					set_title_flag = revert_ultimogeniture
				}
				if = {
					limit = { has_law = cognatic_succession }
					set_title_flag = revert_cognatic
				}
				if = {
					limit = { has_law = true_cognatic_succession }
					set_title_flag = revert_true_cognatic
				}
				if = {
					limit = { has_law = agnatic_succession }
					set_title_flag = revert_agnatic
				}
				if = {
					limit = { has_law = enatic_succession }
					set_title_flag = revert_enatic
				}
				if = {
					limit = { has_law = enatic_cognatic_succession }
					set_title_flag = revert_enatic_cognatic
				}
			}
			
			#first the actual pretender
			current_heir = { 
				add_trait = disinherited 
				ROOT = {
					recalc_succession = yes
					current_heir = { 
						if = {
							limit = {
								OR = {
									is_female = no
									ROOT = { NOT = { has_character_flag = no_female_candidates } }
								}
								age = 13
								NOR = {
									character = event_target:next_in_line
									trait = incapable
									trait = imbecile
									trait = inbred
									trait = lunatic
								}
							}
							save_event_target_as = candidate_second_heir
							ROOT = { change_variable = { which = "succ_candidates" value = 1 } }
						}
					}
				}
				remove_trait = disinherited 
			}
			recalc_succession = yes
			
			#then the male candidate
			if = {
				limit = {
					current_heir = { is_female = yes }
				}
				primary_title = { gender_succ = agnatic }
				recalc_succession = yes
				current_heir = { 
					if = {
						limit = {
							age = 13
							NOR = {
								character = event_target:next_in_line
								character = event_target:candidate_second_heir
								trait = incapable
								trait = imbecile
								trait = inbred
								trait = lunatic
							}
						}
						save_event_target_as = candidate_male
						ROOT = { change_variable = { which = "succ_candidates" value = 1 } }
					}	
				}
			}
			
			#then an older female candidate
			if = {
				limit = {
					current_heir = { is_female = no }
					ROOT = { NOT = { has_character_flag = no_female_candidates } }
				}
				primary_title = { gender_succ = true_cognatic }
				recalc_succession = yes
				current_heir = { 
					if = {
						limit = {
							age = 13
							NOR = {
								character = event_target:next_in_line
								character = event_target:candidate_second_heir
								character = event_target:candidate_male
								trait = incapable
								trait = imbecile
								trait = inbred
								trait = lunatic
							}
						}
						save_event_target_as = candidate_female
						ROOT = { change_variable = { which = "succ_candidates" value = 1 } }
					}	
				}
			}
			
			#restore gender law
			primary_title = {
				if = {
					limit = { has_title_flag = revert_agnatic }
					clr_title_flag = revert_agnatic
					gender_succ = agnatic
				}
				if = {
					limit = { has_title_flag = revert_cognatic }
					clr_title_flag = revert_cognatic
					gender_succ = cognatic
				}
				if = {
					limit = { has_title_flag = revert_true_cognatic }
					clr_title_flag = revert_true_cognatic
					gender_succ = true_cognatic
				}
				if = {
					limit = { has_title_flag = revert_enatic }
					clr_title_flag = revert_enatic
					gender_succ = enatic
				}
				if = {
					limit = { has_title_flag = revert_enatic_cognatic }
					clr_title_flag = revert_enatic_cognatic
					gender_succ = enatic_cognatic
				}
			}
			
			#then the primogeniture candidate
			if = {
				limit = {
					primary_title = { NOT = { has_title_flag = revert_primogeniture } }
					NOT = { check_variable = { which = "succ_candidates" value = 2.5 } }
				}
				primary_title = {
					add_law = {
						law = succ_primogeniture
						cooldown = no
						opinion_effect = no
					}
				}
				recalc_succession = yes
				current_heir = { 
					if = {
						limit = {
							OR = {
								is_female = no
								ROOT = { NOT = { has_character_flag = no_female_candidates } }
							}
							age = 13
							NOR = {
								character = event_target:next_in_line
								character = event_target:candidate_second_heir
								character = event_target:candidate_male
								character = event_target:candidate_female
								trait = incapable
								trait = imbecile
								trait = inbred
								trait = lunatic
							}
						}
						save_event_target_as = candidate_primo
						ROOT = { change_variable = { which = "succ_candidates" value = 1 } }
					}	
				}
			}
			
			#then the seniority candidate
			if = {
				limit = {
					primary_title = { NOT = { has_title_flag = revert_seniority } }
					NOT = { check_variable = { which = "succ_candidates" value = 2.5 } }
				}
				primary_title = {
					add_law = {
						law = succ_seniority
						cooldown = no
						opinion_effect = no
					}
				}
				recalc_succession = yes
				current_heir = { 
					if = {
						limit = {
							OR = {
								is_female = no
								ROOT = { NOT = { has_character_flag = no_female_candidates } }
							}
							age = 13
							NOR = {
								character = event_target:next_in_line
								character = event_target:candidate_second_heir
								character = event_target:candidate_male
								character = event_target:candidate_female
								character = event_target:candidate_primo
								trait = incapable
								trait = imbecile
								trait = inbred
								trait = lunatic
							}
						}
						save_event_target_as = candidate_senior
						ROOT = { change_variable = { which = "succ_candidates" value = 1 } }
					}
				}
			}
			
			#restore succession law
			primary_title = {
				if = {
					limit = { has_title_flag = revert_primogeniture }
					clr_title_flag = revert_primogeniture
						add_law = {
						law = succ_primogeniture
						cooldown = no
						opinion_effect = no
					}
				}
				if = {
					limit = { has_title_flag = revert_seniority }
					clr_title_flag = revert_seniority
					add_law = {
						law = succ_seniority
						cooldown = no
						opinion_effect = no
					}
				}
				if = {
					limit = { has_title_flag = revert_ultimogeniture }
					clr_title_flag = revert_ultimogeniture
					add_law = {
						law = succ_ultimogeniture
						cooldown = no
						opinion_effect = no
					}
				}
			}
			recalc_succession = yes
			clear_event_target = next_in_line
		}
		
		#find candidates for voting succession laws
		if = {
			limit = {
				primary_title = {
					OR = {
						has_law = succ_feudal_elective
						has_law = succ_tanistry
					}
				}
			}
			#first find the actual pretenders
			top_liege = {
				random_realm_character = {
					limit = {
						any_pretender_title = {
							is_primary_holder_title = yes
							holder_scope = { character = ROOT }
						}
						OR = {
							is_female = no
							ROOT = { NOT = { has_character_flag = no_female_candidates } }
						}
						age = 13
						NOR = {
							character = event_target:next_in_line
							trait = incapable
							trait = imbecile
							trait = inbred
							trait = lunatic
						}
					}
					save_event_target_as = candidate_second_heir
					ROOT = { change_variable = { which = "succ_candidates" value = 1 } }
				}
				random_realm_character = {
					limit = {
						any_pretender_title = {
							is_primary_holder_title = yes
							holder_scope = { character = ROOT }
						}
						OR = {
							is_female = no
							ROOT = { NOT = { has_character_flag = no_female_candidates } }
						}
						age = 13
						NOT = {
							character = event_target:next_in_line
							character = event_target:candidate_second_heir
							trait = incapable
							trait = imbecile
							trait = inbred
							trait = lunatic
						}
					}
					save_event_target_as = candidate_primo
					ROOT = { change_variable = { which = "succ_candidates" value = 1 } }
				}
			}
			#then pick the eldest valid child
			random_child = {
				limit = {
					is_alive = yes
					OR = {
						dynasty = ROOT
						calc_true_if = {
							amount = 2
							diplomacy = 15
							diplomacy = 21
							martial = 15
							stewardship = 15
							trait = genius
							higher_tier_than = COUNT
						}
					}
					OR = {
						is_female = no
						ROOT = { NOT = { has_character_flag = no_female_candidates } }
					}
					age = 13
					NOR = {
						character = event_target:next_in_line
						character = event_target:candidate_second_heir
						character = event_target:candidate_male
						trait = incapable
						trait = imbecile
						trait = inbred
						trait = lunatic
						trait = eunuch
						trait = monk
						trait = nun
						trait = abdicated
						trait = disinherited
						trait = druid
						trait = bad_druid
						trait = retired_vestalis
						trait = vestalis
						any_liege = {
							OR = {
								holy_order = yes
								mercenary = yes
							}
						}
						any_sibling = {
							is_older_than = PREV
							OR = {
								dynasty = ROOT
								calc_true_if = {
									amount = 2
									diplomacy = 15
									diplomacy = 21
									martial = 15
									stewardship = 15
									trait = genius
									higher_tier_than = COUNT
								}
							}
							OR = {
								is_female = no
								ROOT = { NOT = { has_character_flag = no_female_candidates } }
							}
							NOR = {
								trait = incapable
								trait = imbecile
								trait = inbred
								trait = lunatic
								trait = eunuch
								trait = monk
								trait = nun
								trait = abdicated
								trait = disinherited
								trait = druid
								trait = bad_druid
								trait = retired_vestalis
								trait = vestalis
								any_liege = {
									OR = {
										holy_order = yes
										mercenary = yes
									}
								}
							}
						}
					}
				}
				save_event_target_as = candidate_primo
				ROOT = { change_variable = { which = "succ_candidates" value = 1 } }
			}
		}
		
		#then the ability candidate, if there is one
		if = {
			limit = {
				NOT = { check_variable = { which = "succ_candidates" value = 2.5 } }
			}
			random_dynasty_member = {
				limit = {
					OR = {
						is_female = no
						ROOT = { NOT = { has_character_flag = no_female_candidates } }
					}
					is_alive = yes
					is_theocracy = no
					is_republic = no
					mercenary = no
					holy_order = no
					is_adult = yes
					same_realm = ROOT
					calc_true_if = {
						amount = 2
						diplomacy = 15
						diplomacy = 21
						martial = 15
						stewardship = 15
						trait = genius
						higher_tier_than = COUNT
						any_pretender_title = {
							holder_scope = { character = ROOT }
							is_primary_holder_title = yes
						}
					}
					NOR = {
						character = event_target:next_in_line
						character = event_target:candidate_second_heir
						character = event_target:candidate_male
						character = event_target:candidate_female
						character = event_target:candidate_primo
						character = event_target:candidate_senior
						is_primary_heir = ROOT
						character = ROOT
						trait = incapable
						trait = imbecile
						trait = inbred
						trait = lunatic
						trait = possessed
						trait = eunuch
						trait = monk
						trait = nun
						trait = abdicated
						trait = disinherited
						trait = druid
						trait = bad_druid
						trait = retired_vestalis
						trait = vestalis
						any_liege = {
							OR = {
								holy_order = yes
								mercenary = yes
							}
						}
					}
				}
				save_event_target_as = candidate_ability
				ROOT = { change_variable = { which = "succ_candidates" value = 1 } }
			}
		}
		
		#is there still a succession crisis?
		if = {
			limit = { check_variable = { which = "succ_candidates" value = 0.5 } }
			current_heir = {
				if = {
					limit = { NOT = { age = 13 } }
					set_character_flag = crisis_too_young
				}
				if = {
					limit = {
						age = 13
						OR = {
							trait = incapable
							trait = imbecile
							trait = inbred
							trait = lunatic
						}
					}
					set_character_flag = crisis_unsuitable
				}
				if = {
					limit = {
						age = 13
						NOR = {
							trait = incapable
							trait = imbecile
							trait = inbred
							trait = lunatic
						}
						is_female = yes
					}
					set_character_flag = crisis_female
				}				
				ROOT = {
					any_demesne_title = {
						limit = { current_heir = { character = PREVPREVPREV } }
						set_title_flag = will_be_inherited
					}
				}
				narrative_event = { id = Plus.1611 days = 1 }
				character_event = { id = Plus.1617 days = 1 }
			}
		}
	}
}

# The succession crisis is raised
narrative_event = {
	id = Plus.1611
	title = EVTNAME_Plus_1611
	picture = GFX_evt_coronation
	
	desc = {
		text = EVTDESC_Plus_1611A
		trigger = { has_character_flag = crisis_too_young }
	}
	desc = {
		text = EVTDESC_Plus_1611B
		trigger = { has_character_flag = crisis_unsuitable }
	}
	desc = {
		text = EVTDESC_Plus_1611C
		trigger = { has_character_flag = crisis_female }
	}
	
	is_triggered_only = yes
	
	trigger = {
		in_revolt = no
		pf_war_trait_trigger = no
		pf_war_flag_trigger = no
		NOR = {
			any_demesne_title = { is_contested = yes }
			any_demesne_title = { temporary = yes }
		}
	}
	
	immediate = {
		log = "The [Root.PrimaryTitle.GetFullName] has a succession crisis!"
		add_character_modifier = {
			name = succession_crisis
			duration = 8
		}
		set_variable = { which = "votes_for_heir" value = 0 }
		set_variable = { which = "votes_against_heir" value = 0 }
		set_variable = { which = "votes_for_second_heir" value = 0 }
		set_variable = { which = "votes_for_male" value = 0 }
		set_variable = { which = "votes_for_female" value = 0 }
		set_variable = { which = "votes_for_primo" value = 0 }
		set_variable = { which = "votes_for_senior" value = 0 }
		set_variable = { which = "votes_for_ability" value = 0 }
	}

	option = {
		name = EVTOPTA_Plus_1611
		event_target:candidate_second_heir = { custom_tooltip = { text = IS_SUCCESSION_CANDIDATE } }
		event_target:candidate_male = { custom_tooltip = { text = IS_SUCCESSION_CANDIDATE } }
		event_target:candidate_female = { custom_tooltip = { text = IS_SUCCESSION_CANDIDATE } }
		event_target:candidate_primo = { custom_tooltip = { text = IS_SUCCESSION_CANDIDATE } }
		event_target:candidate_senior = { custom_tooltip = { text = IS_SUCCESSION_CANDIDATE } }
		event_target:candidate_ability = { custom_tooltip = { text = IS_SUCCESSION_CANDIDATE } }
		hidden_tooltip = {
			if = {
				limit = { independent = no }
				top_liege = { narrative_event = { id = Plus.1612 days = 3 } }
			}
			top_liege = {
				any_realm_character = {
					limit = { is_playable = yes }
					narrative_event = { id = Plus.1612 days = 3 }
				}
			}
			any_dynasty_member = {
				limit = {
					NOT = { same_realm = ROOT }
					ai = no
				}
				narrative_event = { id = Plus.1612 days = 3 }
			}
			character_event = { id = Plus.1613 days = 7 }
			character_event = { id = Plus.1617 days = 7 }
		}
	}
}

# Vassals vote on whether to depose the ruler
narrative_event = {
	id = Plus.1612
	title = EVTNAME_Plus_1611
	picture = GFX_evt_coronation
	
	desc = {
		text = EVTDESC_Plus_1612A
		trigger = { FROM = { has_character_flag = crisis_too_young } }
	}
	desc = {
		text = EVTDESC_Plus_1612B
		trigger = { FROM = { has_character_flag = crisis_unsuitable } }
	}
	desc = {
		text = EVTDESC_Plus_1612C
		trigger = { FROM = { has_character_flag = crisis_female } }
	}
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_1612 #Support current ruler
		trigger = {
			vassal_of = FROM
			higher_tier_than = COUNT
			has_regent = no
		}
		ai_chance = {
			factor = 100
			modifier = {
				factor = 2.0
				FROM = { primary_title = { has_law = crown_authority_1 } }
			}
			modifier = {
				factor = 0.5
				FROM = { is_adult = no }
			}
			modifier = {
				factor = 0.75
				is_female = no
				is_feminist_trigger = no
				FROM = {
					is_female = yes
					primary_title = {
						OR = {
							has_law = cognatic_succession
							has_law = true_cognatic_succession
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				is_female = no
				is_feminist_trigger = no
				FROM = {
					is_female = yes
					primary_title = {
						NOR = {
							has_law = cognatic_succession
							has_law = true_cognatic_succession
						}
					}
				}
			}
			modifier = {
				factor = 0.25
				FROM = {
					OR = {
						trait = incapable
						trait = imbecile
						trait = inbred
					}
				}
			}
			modifier = {
				factor = 0.5
				FROM = { trait = lunatic }
			}
			modifier = {
				factor = 0
				OR = {
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_primo
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
				NOR = {
					trait = content
					trait = humble
				}
			}		
			modifier = {
				factor = 0.5
				NOT = { dynasty = FROM }
			}
			modifier = {
				factor = 1.5
				is_close_relative = FROM
			}
			modifier = {
				factor = 2.0
				OR = {
					is_child_of = FROM
					is_father = FROM
					is_mother = FROM
				}
			}
			modifier = {
				factor = 0.5
				NOT = { religion = FROM }
			}
			modifier = {
				factor = 0.75
				NOT = { culture = FROM }
			}
			modifier = {
				factor = 0.75
				NOT = { culture_group = FROM }
			}
			modifier = {
				factor = 1.5
				FROM = {
					primary_title = {
						OR = {
							title = e_roman_empire
							title = e_byzantium
						}
					}
					trait = born_in_the_purple
				}
			}
		}
		hidden_tooltip = {
			FROM = { change_variable = { which = "votes_for_heir" value = 1 } }
		}
		FROM = {
			custom_tooltip = { text = ENDORSE_FOR_SUCCESSION }
		}
		opinion = { who = FROM modifier = supported_in_succession years = 5 }
		reverse_opinion = { who = FROM modifier = supported_in_succession years = 5 }
	}
	option = {
		name = EVTOPTB_Plus_1612 #Support second heir
		trigger = {
			event_target:candidate_second_heir = { is_alive = yes }
			vassal_of = FROM
			higher_tier_than = COUNT
			has_regent = no
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.5
				event_target:candidate_second_heir = {
					NOT = { same_realm = FROM }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_second_heir = { is_adult = no }
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.75
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_second_heir = {
					is_female = yes
					FROM = {
						primary_title = {
							OR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_second_heir = {
					is_female = yes
					FROM = {
						primary_title = {
							NOR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0
				OR = {
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
				NOR = {
					trait = content
					trait = humble
				}
			}
			modifier = {
				factor = 0.5
				NOT = { dynasty = event_target:candidate_second_heir }
			}
			modifier = {
				factor = 1.5
				is_close_relative = event_target:candidate_second_heir
			}
			modifier = {
				factor = 2.0
				OR = {
					is_child_of = event_target:candidate_second_heir
					is_father = event_target:candidate_second_heir
					is_mother = event_target:candidate_second_heir
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_second_heir = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_second_heir = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 30 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_second_heir = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 40 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_second_heir = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 50 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_second_heir = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 10 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_second_heir = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				NOT = { religion = event_target:candidate_second_heir }
			}
			modifier = {
				factor = 0.75
				NOT = { culture = event_target:candidate_second_heir }
			}
			modifier = {
				factor = 0.75
				NOT = { culture_group = event_target:candidate_second_heir }
			}
			modifier = {
				factor = 1.2
				event_target:candidate_second_heir = {
					attribute_diff = { character = FROM attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_second_heir = {
					attribute_diff = { character = FROM attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_second_heir = {
					attribute_diff = { character = FROM attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_second_heir = {
					attribute_diff = { character = FROM attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_second_heir attribute = diplomacy value = 1 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_second_heir attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_second_heir attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_second_heir attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_second_heir attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_second_heir = {
					attribute_diff = { character = FROM attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_second_heir = {
					attribute_diff = { character = FROM attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_second_heir attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_second_heir attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_second_heir = {
					attribute_diff = { character = FROM attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_second_heir = {
					attribute_diff = { character = FROM attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_second_heir attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_second_heir attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_court
					in_faction = faction_court
				}
				event_target:candidate_second_heir = {
					OR = {
						leads_faction = faction_court
						in_faction = faction_court
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_glory
					in_faction = faction_glory
				}
				event_target:candidate_second_heir = {
					OR = {
						leads_faction = faction_glory
						in_faction = faction_glory
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_prosperity
					in_faction = faction_prosperity
				}
				event_target:candidate_second_heir = {
					OR = {
						leads_faction = faction_prosperity
						in_faction = faction_prosperity
					}
				}
			}
			modifier = {
				factor = 1.5
				FROM = {
					primary_title = {
						OR = {
							title = e_roman_empire
							title = e_byzantium
						}
					}
				}
				event_target:candidate_second_heir = {
					trait = born_in_the_purple
				}
			}
		}
		hidden_tooltip = {
			FROM = {
				change_variable = { which = "votes_for_second_heir" value = 1 }
				change_variable = { which = "votes_against_heir" value = 1 }
			}
		}
		event_target:candidate_second_heir = {
			custom_tooltip = { text = ENDORSE_FOR_SUCCESSION }
		}
		if = {
			limit = { NOT = { character = event_target:candidate_second_heir } }
			opinion = { who = event_target:candidate_second_heir modifier = supported_in_succession years = 5 }
			reverse_opinion = { who = event_target:candidate_second_heir modifier = supported_in_succession multiplier = 2 years = 5 }
		}
	}
	option = {
		name = EVTOPTC_Plus_1612 #Support male candidate
		trigger = {
			event_target:candidate_male = { is_alive = yes }
			vassal_of = FROM
			higher_tier_than = COUNT
			has_regent = no
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.5
				event_target:candidate_male = {
					NOT = { same_realm = FROM }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_male = { is_adult = no }
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.75
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_male = {
					is_female = yes
					FROM = {
						primary_title = {
							OR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_male = {
					is_female = yes
					FROM = {
						primary_title = {
							NOR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0
				OR = {
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
				NOR = {
					trait = content
					trait = humble
				}
			}
			modifier = {
				factor = 0.5
				NOT = { dynasty = event_target:candidate_male }
			}
			modifier = {
				factor = 1.5
				is_close_relative = event_target:candidate_male
			}
			modifier = {
				factor = 2.0
				OR = {
					is_child_of = event_target:candidate_male
					is_father = event_target:candidate_male
					is_mother = event_target:candidate_male
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_male = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_male = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 30 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_male = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 40 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_male = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 50 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_male = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 10 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_male = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				NOT = { religion = event_target:candidate_male }
			}
			modifier = {
				factor = 0.75
				NOT = { culture = event_target:candidate_male }
			}
			modifier = {
				factor = 0.75
				NOT = { culture_group = event_target:candidate_male }
			}
			modifier = {
				factor = 1.2
				event_target:candidate_male = {
					attribute_diff = { character = FROM attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_male = {
					attribute_diff = { character = FROM attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_male = {
					attribute_diff = { character = FROM attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_male = {
					attribute_diff = { character = FROM attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_male attribute = diplomacy value = 1 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_male attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_male attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_male attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_male attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_male = {
					attribute_diff = { character = FROM attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_male = {
					attribute_diff = { character = FROM attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_male attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_male attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_male = {
					attribute_diff = { character = FROM attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_male = {
					attribute_diff = { character = FROM attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_male attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_male attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_court
					in_faction = faction_court
				}
				event_target:candidate_male = {
					OR = {
						leads_faction = faction_court
						in_faction = faction_court
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_glory
					in_faction = faction_glory
				}
				event_target:candidate_male = {
					OR = {
						leads_faction = faction_glory
						in_faction = faction_glory
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_prosperity
					in_faction = faction_prosperity
				}
				event_target:candidate_male = {
					OR = {
						leads_faction = faction_prosperity
						in_faction = faction_prosperity
					}
				}
			}
			modifier = {
				factor = 1.5
				FROM = {
					primary_title = {
						OR = {
							title = e_roman_empire
							title = e_byzantium
						}
					}
				}
				event_target:candidate_male = {
					trait = born_in_the_purple
				}
			}
		}
		hidden_tooltip = {
			FROM = {
				change_variable = { which = "votes_for_male" value = 1 }
				change_variable = { which = "votes_against_heir" value = 1 }
			}
		}
		event_target:candidate_male = {
			custom_tooltip = { text = ENDORSE_FOR_SUCCESSION }
		}
		if = {
			limit = { NOT = { character = event_target:candidate_male } }
			opinion = { who = event_target:candidate_male modifier = supported_in_succession years = 5 }
			reverse_opinion = { who = event_target:candidate_male modifier = supported_in_succession multiplier = 2 years = 5 }
		}
	}
	option = {
		name = EVTOPTD_Plus_1612 #Support female candidate
		trigger = {
			event_target:candidate_female = { is_alive = yes }
			vassal_of = FROM
			higher_tier_than = COUNT
			has_regent = no
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.5
				event_target:candidate_female = {
					NOT = { same_realm = FROM }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_female = { is_adult = no }
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.75
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_female = {
					is_female = yes
					FROM = {
						primary_title = {
							OR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_female = {
					is_female = yes
					FROM = {
						primary_title = {
							NOR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0
				OR = {
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
				NOR = {
					trait = content
					trait = humble
				}
			}
			modifier = {
				factor = 0.5
				NOT = { dynasty = event_target:candidate_female }
			}
			modifier = {
				factor = 1.5
				is_close_relative = event_target:candidate_female
			}
			modifier = {
				factor = 2.0
				OR = {
					is_child_of = event_target:candidate_female
					is_father = event_target:candidate_female
					is_mother = event_target:candidate_female
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_female = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_female = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 30 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_female = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 40 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_female = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 50 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_female = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 10 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_female = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				NOT = { religion = event_target:candidate_female }
			}
			modifier = {
				factor = 0.75
				NOT = { culture = event_target:candidate_female }
			}
			modifier = {
				factor = 0.75
				NOT = { culture_group = event_target:candidate_female }
			}
			modifier = {
				factor = 1.2
				event_target:candidate_female = {
					attribute_diff = { character = FROM attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_female = {
					attribute_diff = { character = FROM attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_female = {
					attribute_diff = { character = FROM attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_female = {
					attribute_diff = { character = FROM attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_female attribute = diplomacy value = 1 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_female attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_female attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_female attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_female attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_female = {
					attribute_diff = { character = FROM attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_female = {
					attribute_diff = { character = FROM attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_female attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_female attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_female = {
					attribute_diff = { character = FROM attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_female = {
					attribute_diff = { character = FROM attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_female attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_female attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_court
					in_faction = faction_court
				}
				event_target:candidate_female = {
					OR = {
						leads_faction = faction_court
						in_faction = faction_court
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_glory
					in_faction = faction_glory
				}
				event_target:candidate_female = {
					OR = {
						leads_faction = faction_glory
						in_faction = faction_glory
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_prosperity
					in_faction = faction_prosperity
				}
				event_target:candidate_female = {
					OR = {
						leads_faction = faction_prosperity
						in_faction = faction_prosperity
					}
				}
			}
			modifier = {
				factor = 1.5
				FROM = {
					primary_title = {
						OR = {
							title = e_roman_empire
							title = e_byzantium
						}
					}
				}
				event_target:candidate_female = {
					trait = born_in_the_purple
				}
			}
		}
		hidden_tooltip = {
			FROM = {
				change_variable = { which = "votes_for_female" value = 1 }
				change_variable = { which = "votes_against_heir" value = 1 }
			}
		}
		event_target:candidate_female = {
			custom_tooltip = { text = ENDORSE_FOR_SUCCESSION }
		}
		if = {
			limit = { NOT = { character = event_target:candidate_female } }
			opinion = { who = event_target:candidate_female modifier = supported_in_succession years = 5 }
			reverse_opinion = { who = event_target:candidate_female modifier = supported_in_succession multiplier = 2 years = 5 }
		}
	}
	option = {
		name = EVTOPTE_Plus_1612 #Support primo candidate
		trigger = {
			event_target:candidate_primo = { is_alive = yes }
			vassal_of = FROM
			higher_tier_than = COUNT
			has_regent = no
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.5
				event_target:candidate_primo = {
					NOT = { same_realm = FROM }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_primo = { is_adult = no }
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.75
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_primo = {
					is_female = yes
					FROM = {
						primary_title = {
							OR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_primo = {
					is_female = yes
					FROM = {
						primary_title = {
							NOR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0
				OR = {
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
				NOR = {
					trait = content
					trait = humble
				}
			}
			modifier = {
				factor = 0.5
				NOT = { dynasty = event_target:candidate_primo }
			}
			modifier = {
				factor = 1.5
				is_close_relative = event_target:candidate_primo
			}
			modifier = {
				factor = 2.0
				OR = {
					is_child_of = event_target:candidate_primo
					is_father = event_target:candidate_primo
					is_mother = event_target:candidate_primo
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_primo = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_primo = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 30 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_primo = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 40 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_primo = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 50 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_primo = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 10 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_primo = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				NOT = { religion = event_target:candidate_primo }
			}
			modifier = {
				factor = 0.75
				NOT = { culture = event_target:candidate_primo }
			}
			modifier = {
				factor = 0.75
				NOT = { culture_group = event_target:candidate_primo }
			}
			modifier = {
				factor = 1.2
				event_target:candidate_primo = {
					attribute_diff = { character = FROM attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_primo = {
					attribute_diff = { character = FROM attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_primo = {
					attribute_diff = { character = FROM attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_primo = {
					attribute_diff = { character = FROM attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_primo attribute = diplomacy value = 1 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_primo attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_primo attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_primo attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_primo attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_primo = {
					attribute_diff = { character = FROM attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_primo = {
					attribute_diff = { character = FROM attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_primo attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_primo attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_primo = {
					attribute_diff = { character = FROM attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_primo = {
					attribute_diff = { character = FROM attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_primo attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_primo attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_court
					in_faction = faction_court
				}
				event_target:candidate_primo = {
					OR = {
						leads_faction = faction_court
						in_faction = faction_court
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_glory
					in_faction = faction_glory
				}
				event_target:candidate_primo = {
					OR = {
						leads_faction = faction_glory
						in_faction = faction_glory
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_prosperity
					in_faction = faction_prosperity
				}
				event_target:candidate_primo = {
					OR = {
						leads_faction = faction_prosperity
						in_faction = faction_prosperity
					}
				}
			}
			modifier = {
				factor = 1.5
				FROM = {
					primary_title = {
						OR = {
							title = e_roman_empire
							title = e_byzantium
						}
					}
				}
				event_target:candidate_primo = {
					trait = born_in_the_purple
				}
			}
		}
		hidden_tooltip = {
			FROM = {
				change_variable = { which = "votes_for_primo" value = 1 }
				change_variable = { which = "votes_against_heir" value = 1 }
			}
		}
		event_target:candidate_primo = {
			custom_tooltip = { text = ENDORSE_FOR_SUCCESSION }
		}
		if = {
			limit = { NOT = { character = event_target:candidate_primo } }
			opinion = { who = event_target:candidate_primo modifier = supported_in_succession years = 5 }
			reverse_opinion = { who = event_target:candidate_primo modifier = supported_in_succession multiplier = 2 years = 5 }
		}
	}
	option = {
		name = EVTOPTF_Plus_1612 #Support senior candidate
		trigger = {
			event_target:candidate_senior = { is_alive = yes }
			vassal_of = FROM
			higher_tier_than = COUNT
			has_regent = no
		}
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.5
				event_target:candidate_senior = {
					NOT = { same_realm = FROM }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_senior = { is_adult = no }
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.75
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_senior = {
					is_female = yes
					FROM = {
						primary_title = {
							OR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_senior = {
					is_female = yes
					FROM = {
						primary_title = {
							NOR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0
				OR = {
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
				NOR = {
					trait = content
					trait = humble
				}
			}
			modifier = {
				factor = 0.5
				NOT = { dynasty = event_target:candidate_senior }
			}
			modifier = {
				factor = 1.5
				is_close_relative = event_target:candidate_senior
			}
			modifier = {
				factor = 2.0
				OR = {
					is_child_of = event_target:candidate_senior
					is_father = event_target:candidate_senior
					is_mother = event_target:candidate_senior
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_senior = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_senior = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 30 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_senior = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 40 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_senior = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 50 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_senior = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 10 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_senior = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				NOT = { religion = event_target:candidate_senior }
			}
			modifier = {
				factor = 0.75
				NOT = { culture = event_target:candidate_senior }
			}
			modifier = {
				factor = 0.75
				NOT = { culture_group = event_target:candidate_senior }
			}
			modifier = {
				factor = 1.2
				event_target:candidate_senior = {
					attribute_diff = { character = FROM attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_senior = {
					attribute_diff = { character = FROM attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_senior = {
					attribute_diff = { character = FROM attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_senior = {
					attribute_diff = { character = FROM attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_senior attribute = diplomacy value = 1 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_senior attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_senior attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_senior attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_senior attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_senior = {
					attribute_diff = { character = FROM attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_senior = {
					attribute_diff = { character = FROM attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_senior attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_senior attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_senior = {
					attribute_diff = { character = FROM attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_senior = {
					attribute_diff = { character = FROM attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_senior attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_senior attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_court
					in_faction = faction_court
				}
				event_target:candidate_senior = {
					OR = {
						leads_faction = faction_court
						in_faction = faction_court
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_glory
					in_faction = faction_glory
				}
				event_target:candidate_senior = {
					OR = {
						leads_faction = faction_glory
						in_faction = faction_glory
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_prosperity
					in_faction = faction_prosperity
				}
				event_target:candidate_senior = {
					OR = {
						leads_faction = faction_prosperity
						in_faction = faction_prosperity
					}
				}
			}
			modifier = {
				factor = 1.5
				FROM = {
					primary_title = {
						OR = {
							title = e_roman_empire
							title = e_byzantium
						}
					}
				}
				event_target:candidate_senior = {
					trait = born_in_the_purple
				}
			}
		}
		hidden_tooltip = {
			FROM = {
				change_variable = { which = "votes_for_senior" value = 1 }
				change_variable = { which = "votes_against_heir" value = 1 }
			}
		}
		event_target:candidate_senior = {
			custom_tooltip = { text = ENDORSE_FOR_SUCCESSION }
		}
		if = {
			limit = { NOT = { character = event_target:candidate_senior } }
			opinion = { who = event_target:candidate_senior modifier = supported_in_succession years = 5 }
			reverse_opinion = { who = event_target:candidate_senior modifier = supported_in_succession multiplier = 2 years = 5 }
		}
	}
	option = {
		name = EVTOPTG_Plus_1612 #Support ability candidate
		trigger = {
			event_target:candidate_ability = { is_alive = yes }
			vassal_of = FROM
			higher_tier_than = COUNT
			has_regent = no
		}
		ai_chance = {
			factor = 25
			modifier = {
				factor = 0.5
				event_target:candidate_ability = {
					NOT = { same_realm = FROM }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_ability = { is_adult = no }
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_tradition
					in_faction = faction_tradition
				}
			}
			modifier = {
				factor = 0.75
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_ability = {
					is_female = yes
					FROM = {
						primary_title = {
							OR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				is_female = no
				is_feminist_trigger = no
				event_target:candidate_ability = {
					is_female = yes
					FROM = {
						primary_title = {
							NOR = {
								has_law = cognatic_succession
								has_law = true_cognatic_succession
							}
						}
					}
				}
			}
			modifier = {
				factor = 0
				OR = {
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
				NOR = {
					trait = content
					trait = humble
				}
			}
			modifier = {
				factor = 0.5
				NOT = { dynasty = event_target:candidate_ability }
			}
			modifier = {
				factor = 1.5
				is_close_relative = event_target:candidate_ability
			}
			modifier = {
				factor = 2.0
				OR = {
					is_child_of = event_target:candidate_ability
					is_father = event_target:candidate_ability
					is_mother = event_target:candidate_ability
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_ability = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_ability = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 30 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_ability = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 40 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_ability = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = PREV second = FROM value = 50 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_ability = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 10 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				event_target:candidate_ability = {
					NOT = { character = ROOT }
					ROOT = { opinion_diff = { first = FROM second = PREV value = 20 as_if_liege = yes } }
				}
			}
			modifier = {
				factor = 0.5
				NOT = { religion = event_target:candidate_ability }
			}
			modifier = {
				factor = 0.75
				NOT = { culture = event_target:candidate_ability }
			}
			modifier = {
				factor = 0.75
				NOT = { culture_group = event_target:candidate_ability }
			}
			modifier = {
				factor = 1.2
				event_target:candidate_ability = {
					attribute_diff = { character = FROM attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_ability = {
					attribute_diff = { character = FROM attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_ability = {
					attribute_diff = { character = FROM attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 1.2
				event_target:candidate_ability = {
					attribute_diff = { character = FROM attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_ability attribute = diplomacy value = 1 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_ability attribute = diplomacy value = 3 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_ability attribute = diplomacy value = 5 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_ability attribute = diplomacy value = 7 }
				}
			}
			modifier = {
				factor = 0.8
				FROM = {
					attribute_diff = { character = event_target:candidate_ability attribute = diplomacy value = 9 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_ability = {
					attribute_diff = { character = FROM attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_ability = {
					attribute_diff = { character = FROM attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_ability attribute = martial value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_ability attribute = martial value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_ability = {
					attribute_diff = { character = FROM attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 1.25
				event_target:candidate_ability = {
					attribute_diff = { character = FROM attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_ability attribute = stewardship value = 5 }
				}
			}
			modifier = {
				factor = 0.75
				FROM = {
					attribute_diff = { character = event_target:candidate_ability attribute = stewardship value = 10 }
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_court
					in_faction = faction_court
				}
				event_target:candidate_ability = {
					OR = {
						leads_faction = faction_court
						in_faction = faction_court
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_glory
					in_faction = faction_glory
				}
				event_target:candidate_ability = {
					OR = {
						leads_faction = faction_glory
						in_faction = faction_glory
					}
				}
			}
			modifier = {
				factor = 1.25
				OR = {
					leads_faction = faction_prosperity
					in_faction = faction_prosperity
				}
				event_target:candidate_ability = {
					OR = {
						leads_faction = faction_prosperity
						in_faction = faction_prosperity
					}
				}
			}
			modifier = {
				factor = 1.5
				FROM = {
					primary_title = {
						OR = {
							title = e_roman_empire
							title = e_byzantium
						}
					}
				}
				event_target:candidate_ability = {
					trait = born_in_the_purple
				}
			}
		}
		hidden_tooltip = {
			FROM = {
				change_variable = { which = "votes_for_ability" value = 1 }
				change_variable = { which = "votes_against_heir" value = 1 }
			}
		}
		event_target:candidate_ability = {
			custom_tooltip = { text = ENDORSE_FOR_SUCCESSION }
		}
		if = {
			limit = { NOT = { character = event_target:candidate_ability } }
			opinion = { who = event_target:candidate_ability modifier = supported_in_succession years = 5 }
			reverse_opinion = { who = event_target:candidate_ability modifier = supported_in_succession multiplier = 2 years = 5 }
		}
	}
	option = {
		name = EVTOPTH_Plus_1612
		trigger = {
			NOT = {
				AND = {
					vassal_of = FROM
					higher_tier_than = COUNT
					has_regent = no
				}
			}
		}
	}
}

# Bounce event to check if the ruler won or not
character_event = {
	id = Plus.1613
	
	hide_window = yes
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		primary_title = {
			higher_tier_than = DUKE
			has_title_flag = will_be_inherited
		}
		NOR = {
			trait = pf_rebel
			any_demesne_title = { is_contested = yes }
			any_demesne_title = { temporary = yes }
			has_character_flag = faction_court_war
			has_character_flag = faction_prosperity_war
			has_character_flag = faction_glory_war
			has_character_flag = faction_tradition_war
			has_character_flag = faction_separatist_war
			has_character_flag = faction_pretender_war
			has_character_flag = faction_religious_war
			has_character_flag = faction_succession_war
		}
	}
	
	immediate = {
		#see if the ruler won
		if = {
			limit = {
				NOT = { check_variable = { which = "votes_against_heir" which = "votes_for_heir" } }
				check_variable = { which = "votes_for_heir" which = "votes_for_second_heir" }
				check_variable = { which = "votes_for_heir" which = "votes_for_male" }
				check_variable = { which = "votes_for_heir" which = "votes_for_female" }
				check_variable = { which = "votes_for_heir" which = "votes_for_primo" }
				check_variable = { which = "votes_for_heir" which = "votes_for_senior" }
				check_variable = { which = "votes_for_heir" which = "votes_for_ability" }
			}
			narrative_event = { id = Plus.1614 }
			break = yes
		}
		#see if the second_heir won
		if = {
			limit = {
				check_variable = { which = "votes_for_second_heir" which = "votes_for_heir" }
				check_variable = { which = "votes_for_second_heir" which = "votes_for_male" }
				check_variable = { which = "votes_for_second_heir" which = "votes_for_female" }
				check_variable = { which = "votes_for_second_heir" which = "votes_for_primo" }
				check_variable = { which = "votes_for_second_heir" which = "votes_for_senior" }
				check_variable = { which = "votes_for_second_heir" which = "votes_for_ability" }
			}
			event_target:candidate_second_heir = { save_event_target_as = succession_winner }
			narrative_event = { id = Plus.1615 }
			break = yes
		}
		#see if the male candidate won
		if = {
			limit = {
				check_variable = { which = "votes_for_male" which = "votes_for_heir" }
				check_variable = { which = "votes_for_male" which = "votes_for_second_heir" }
				check_variable = { which = "votes_for_male" which = "votes_for_female" }
				check_variable = { which = "votes_for_male" which = "votes_for_primo" }
				check_variable = { which = "votes_for_male" which = "votes_for_senior" }
				check_variable = { which = "votes_for_male" which = "votes_for_ability" }
			}
			event_target:candidate_male = { save_event_target_as = succession_winner }
			narrative_event = { id = Plus.1615 }
			break = yes
		}
		#see if the female candidate won
		if = {
			limit = {
				check_variable = { which = "votes_for_female" which = "votes_for_heir" }
				check_variable = { which = "votes_for_female" which = "votes_for_second_heir" }
				check_variable = { which = "votes_for_female" which = "votes_for_male" }
				check_variable = { which = "votes_for_female" which = "votes_for_primo" }
				check_variable = { which = "votes_for_female" which = "votes_for_senior" }
				check_variable = { which = "votes_for_female" which = "votes_for_ability" }
			}
			event_target:candidate_female = { save_event_target_as = succession_winner }
			narrative_event = { id = Plus.1615 }
			break = yes
		}
		#see if the primo candidate won
		if = {
			limit = {
				check_variable = { which = "votes_for_primo" which = "votes_for_heir" }
				check_variable = { which = "votes_for_primo" which = "votes_for_second_heir" }
				check_variable = { which = "votes_for_primo" which = "votes_for_male" }
				check_variable = { which = "votes_for_primo" which = "votes_for_female" }
				check_variable = { which = "votes_for_primo" which = "votes_for_senior" }
				check_variable = { which = "votes_for_primo" which = "votes_for_ability" }
			}
			event_target:candidate_primo = { save_event_target_as = succession_winner }
			narrative_event = { id = Plus.1615 }
			break = yes
		}
		#see if seniority candidate won
		if = {
			limit = {
				check_variable = { which = "votes_for_senior" which = "votes_for_heir" }
				check_variable = { which = "votes_for_senior" which = "votes_for_second_heir" }
				check_variable = { which = "votes_for_senior" which = "votes_for_male" }
				check_variable = { which = "votes_for_senior" which = "votes_for_female" }
				check_variable = { which = "votes_for_senior" which = "votes_for_primo" }
				check_variable = { which = "votes_for_senior" which = "votes_for_ability" }
			}
			event_target:candidate_senior = { save_event_target_as = succession_winner }
			narrative_event = { id = Plus.1615 }
			break = yes
		}
		#see if ability candidate won
		if = {
			limit = {
				check_variable = { which = "votes_for_ability" which = "votes_for_heir" }
				check_variable = { which = "votes_for_ability" which = "votes_for_second_heir" }
				check_variable = { which = "votes_for_ability" which = "votes_for_male" }
				check_variable = { which = "votes_for_ability" which = "votes_for_female" }
				check_variable = { which = "votes_for_ability" which = "votes_for_primo" }
				check_variable = { which = "votes_for_ability" which = "votes_for_senior" }
			}
			event_target:candidate_ability = { save_event_target_as = succession_winner }
			narrative_event = { id = Plus.1615 }
			break = yes
		}
		#otherwise there is a stalemate
		narrative_event = { id = Plus.1616 }
	}
}

# The original heir wins decisively
narrative_event = {
	id = Plus.1614
	title = EVTNAME_Plus_1611
	desc = EVTDESC_Plus_1614
	picture = GFX_evt_coronation

	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		OR = {
			character = ROOT
			same_realm = ROOT
			dynasty = ROOT
		}
	}
	
	option = {
		name = EXCELLENT
		trigger = {
			character = ROOT
		}
		prestige = 100
		add_character_modifier = {
			name = won_succession
			duration = 730
		}
		any_vassal = {
			limit = {
				OR = {
					has_any_opinion_modifier = supported_in_succession
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_primo
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
			}
			if = {
				limit = { has_opinion_modifier = { who = ROOT modifier = supported_in_succession } }
				custom_tooltip = { text = SUPPORTED_HEIR }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_second_heir modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_second_heir
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_SECOND_HEIR }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_male modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_male
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_MALE }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_female modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_female
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_FEMALE }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_primo modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_primo
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_PRIMO }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_senior modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_senior
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_SENIOR }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_ability modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_ability
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_ABILITY }
			}
		}
		hidden_tooltip = {
			any_demesne_title = {
				limit = { has_title_flag = will_be_inherited }
				clr_title_flag = will_be_inherited
			}
		}
	}
	option = {
		name = CURSES
		trigger = {
			OR = {
				character = event_target:candidate_second_heir
				character = event_target:candidate_male
				character = event_target:candidate_female
				character = event_target:candidate_primo
				character = event_target:candidate_senior
				character = event_target:candidate_ability
			}
		}
		ROOT = {
			any_vassal = {
				limit = {
					OR = {
						has_any_opinion_modifier = supported_in_succession
						character = event_target:candidate_second_heir
						character = event_target:candidate_male
						character = event_target:candidate_female
						character = event_target:candidate_primo
						character = event_target:candidate_senior
						character = event_target:candidate_ability
					}
				}
				if = {
					limit = { has_opinion_modifier = { who = ROOT modifier = supported_in_succession } }
					custom_tooltip = { text = SUPPORTED_HEIR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_second_heir modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_second_heir
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_SECOND_HEIR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_male modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_male
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_MALE }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_female modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_female
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_FEMALE }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_primo modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_primo
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_PRIMO }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_senior modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_senior
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_SENIOR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_ability modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_ability
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_ABILITY }
				}
			}
		}
	}
	option = {
		name = OK
		trigger = {
			NOR = {
				character = ROOT
				character = event_target:candidate_second_heir
				character = event_target:candidate_male
				character = event_target:candidate_female
				character = event_target:candidate_primo
				character = event_target:candidate_senior
				character = event_target:candidate_ability
			}
		}
	}
}

# The original heir loses
narrative_event = {
	id = Plus.1615
	title = EVTNAME_Plus_1611
	desc = EVTDESC_Plus_1615
	picture = GFX_evt_coronation

	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		OR = {
			character = ROOT
			same_realm = ROOT
			dynasty = ROOT
		}
	}
	
	option = {
		name = CURSES
		trigger = {
			character = ROOT
		}
		set_character_flag = justified_claimant
		prestige = -250
		tooltip = {
			event_target:succession_winner = {
				ROOT = {
					primary_title = {
						usurp_title_plus_barony_if_unlanded = PREVPREV
					}
				}
			}
		}
		
		#renew tributes automatically
		any_independent_ruler = {
			limit = {
				pays_tribute_to = ROOT
				NOT = { is_tributary = { type = imperial suzerain = ROOT } }
				NOT = { is_tributary = { type = permanent suzerain = ROOT } }
				NOT = { is_tributary = { type = offmap suzerain = ROOT } }
				NOT = { is_tributary = { type = nomadic suzerain = ROOT } }
			}
			event_target:succession_winner = { save_event_target_as = abdicate_heir }
			if = {
				limit = {
					OR = {
						is_tributary = {
							type = voluntary
							suzerain = ROOT
						}
						is_tributary = {
							type = default
							suzerain = ROOT
						}
					}
				}
				set_character_flag = is_voluntary_tributary
			}
			if = {
				limit = {
					is_tributary = {
						type = forced
						suzerain = ROOT
					}
				}
				set_character_flag = is_forced_tributary
			}
			if = {
				limit = {
					is_tributary = {
						type = protectorate
						suzerain = ROOT
					}
				}
				set_character_flag = is_protectorate
			}
			character_event = { id = Plus.420 days = 1 }
		}
		
		any_vassal = {
			limit = {
				OR = {
					has_any_opinion_modifier = supported_in_succession
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_primo
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
			}
			if = {
				limit = { has_opinion_modifier = { who = ROOT modifier = supported_in_succession } }
				custom_tooltip = { text = SUPPORTED_HEIR }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_second_heir modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_second_heir
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_SECOND_HEIR }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_male modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_male
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_MALE }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_female modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_female
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_FEMALE }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_primo modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_primo
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_PRIMO }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_senior modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_senior
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_SENIOR }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_ability modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_ability
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_ABILITY }
			}
		}
		hidden_tooltip = {
			if = {
				limit = { independent = no }
				liege = { save_event_target_as = former_liege }
			}
			if = {
				limit = {
					event_target:succession_winner = {
						independent = no
						is_ruler = yes
						higher_real_tier_than = DUKE
						liege = { NOT = { character = event_target:former_liege } }
					}
				}
				event_target:succession_winner = { liege = { save_event_target_as = winner_former_liege } }
			}
			if = {
				limit = {
					event_target:succession_winner = {
						is_ruler = yes
						OR = {
							is_theocracy = yes
							is_republic = yes
						}
					}
					ROOT = {
						primary_title = { higher_tier_than = event_target:succession_winner }
					}
				}
				event_target:succession_winner = { abdicate = yes }
			}
			event_target:succession_winner = {
				prestige = 100
				add_character_modifier = {
					name = won_succession
					duration = 730
				}
				ROOT = {
					if = {
						limit = {
							event_target:succession_winner = { is_ruler = yes }
							any_demesne_title = {
								has_title_flag = will_be_inherited
								higher_tier_than = DUKE
								has_law = succ_feudal_elective
							}
						}
						any_demesne_title = {
							limit = {
								has_title_flag = will_be_inherited
								higher_tier_than = DUKE
							}
							clr_title_flag = will_be_inherited
							usurp_title_plus_barony_if_unlanded = { target = PREVPREV type = faction_demand }
						}
						any_demesne_title = {
							limit = { has_title_flag = will_be_inherited }
							clr_title_flag = will_be_inherited
						}
					}
					if = {
						limit = {
							OR = {
								event_target:succession_winner = { is_ruler = no }
								NOT = {
									any_demesne_title = {
										has_title_flag = will_be_inherited
										higher_tier_than = DUKE
										has_law = succ_feudal_elective
									}
								}
							}
						}
						any_demesne_title = {
							limit = { has_title_flag = will_be_inherited }
							clr_title_flag = will_be_inherited
							usurp_title_plus_barony_if_unlanded = { target = PREVPREV type = faction_demand }
						}
					}
					set_defacto_liege = PREV
					pf_liege_change_effect = yes
					any_vassal = {
						limit = { NOT = { primary_title = { de_jure_liege_or_above = PREVPREV } } }
						set_defacto_liege = PREVPREV 
						pf_liege_change_effect = yes
					}
					if = {
						limit = { is_ruler = no }
						event_target:succession_winner = { wealth = ROOT }
						clear_wealth = yes
					}
				}
			}
			if = {
				limit = {
					event_target:former_liege = { always = yes }
				}
				event_target:former_liege = {
					event_target:succession_winner = {
						set_defacto_liege = PREV
						pf_liege_change_effect = yes
					}
				}
			}
			if = {
				limit = {
					event_target:winner_former_liege = { always = yes }
				}
				event_target:winner_former_liege = {
					event_target:succession_winner = {
						set_defacto_liege = PREV
						pf_liege_change_effect = yes
					}
				}
			}
			if = {
				limit = {
					event_target:candidate_second_heir = { NOT = { character = event_target:succession_winner } }
					check_variable = { which = "votes_for_second_heir" value = 1.5 }
				}
				event_target:candidate_second_heir = { set_character_flag = justified_claimant }
			}
			if = {
				limit = {
					event_target:candidate_male = { NOT = { character = event_target:succession_winner } }
					check_variable = { which = "votes_for_male" value = 1.5 }
				}
				event_target:candidate_male = { set_character_flag = justified_claimant }
			}
			if = {
				limit = {
					event_target:candidate_female = { NOT = { character = event_target:succession_winner } }
					check_variable = { which = "votes_for_female" value = 1.5 }
				}
				event_target:candidate_female = { set_character_flag = justified_claimant }
			}
			if = {
				limit = {
					event_target:candidate_primo = { NOT = { character = event_target:succession_winner } }
					check_variable = { which = "votes_for_primo" value = 1.5 }
				}
				event_target:candidate_primo = { set_character_flag = justified_claimant }
			}
			if = {
				limit = {
					event_target:candidate_senior = { NOT = { character = event_target:succession_winner } }
					check_variable = { which = "votes_for_senior" value = 1.5 }
				}
				event_target:candidate_senior = { set_character_flag = justified_claimant }
			}
			if = {
				limit = {
					event_target:candidate_ability = { NOT = { character = event_target:succession_winner } }
					check_variable = { which = "votes_for_ability" value = 1.5 }
				}
				event_target:candidate_ability = { set_character_flag = justified_claimant }
			}
		}
	}
	option = {
		name = EXCELLENT
		trigger = {
			character = event_target:succession_winner
		}
		ROOT = {
			any_vassal = {
				limit = {
					OR = {
						has_any_opinion_modifier = supported_in_succession
						character = event_target:candidate_second_heir
						character = event_target:candidate_male
						character = event_target:candidate_female
						character = event_target:candidate_primo
						character = event_target:candidate_senior
						character = event_target:candidate_ability
					}
				}
				if = {
					limit = { has_opinion_modifier = { who = ROOT modifier = supported_in_succession } }
					custom_tooltip = { text = SUPPORTED_HEIR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_second_heir modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_second_heir
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_SECOND_HEIR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_male modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_male
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_MALE }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_female modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_female
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_FEMALE }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_primo modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_primo
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_PRIMO }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_senior modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_senior
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_SENIOR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_ability modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_ability
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_ABILITY }
				}
			}
		}
	}
	option = {
		name = CURSES
		trigger = {
			NOT = { character = event_target:succession_winner }
			OR = {
				character = event_target:candidate_second_heir
				character = event_target:candidate_male
				character = event_target:candidate_female
				character = event_target:candidate_primo
				character = event_target:candidate_senior
				character = event_target:candidate_ability
			}
		}
		ROOT = {
			any_vassal = {
				limit = {
					OR = {
						has_any_opinion_modifier = supported_in_succession
						character = event_target:candidate_second_heir
						character = event_target:candidate_male
						character = event_target:candidate_female
						character = event_target:candidate_primo
						character = event_target:candidate_senior
						character = event_target:candidate_ability
					}
				}
				if = {
					limit = { has_opinion_modifier = { who = ROOT modifier = supported_in_succession } }
					custom_tooltip = { text = SUPPORTED_HEIR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_second_heir modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_second_heir
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_SECOND_HEIR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_male modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_male
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_MALE }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_female modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_female
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_FEMALE }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_primo modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_primo
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_PRIMO }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_senior modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_senior
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_SENIOR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_ability modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_ability
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_ABILITY }
				}
			}
		}
	}
	option = {
		name = OK
		trigger = {
			NOR = {
				character = ROOT
				character = event_target:candidate_second_heir
				character = event_target:candidate_male
				character = event_target:candidate_female
				character = event_target:candidate_primo
				character = event_target:candidate_senior
				character = event_target:candidate_ability
			}
		}
	}
}

# Nobody wins the crisis -- it stalls
narrative_event = {
	id = Plus.1616
	title = EVTNAME_Plus_1611
	desc = EVTDESC_Plus_1616
	picture = GFX_evt_coronation

	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		OR = {
			character = ROOT
			same_realm = ROOT
			dynasty = ROOT
		}
	}
	
	option = {
		name = OK
		trigger = {
			character = ROOT
		}
		prestige = -100
		hidden_tooltip = {
			any_demesne_title = {
				limit = { has_title_flag = will_be_inherited }
				clr_title_flag = will_be_inherited
			}
			event_target:candidate_second_heir = { set_character_flag = justified_claimant }
			event_target:candidate_male = { set_character_flag = justified_claimant }
			event_target:candidate_female = { set_character_flag = justified_claimant }
			event_target:candidate_primo = { set_character_flag = justified_claimant }
			event_target:candidate_senior = { set_character_flag = justified_claimant }
			event_target:candidate_ability = { set_character_flag = justified_claimant }
		}
		any_vassal = {
			limit = {
				OR = {
					has_any_opinion_modifier = supported_in_succession
					character = event_target:candidate_second_heir
					character = event_target:candidate_male
					character = event_target:candidate_female
					character = event_target:candidate_primo
					character = event_target:candidate_senior
					character = event_target:candidate_ability
				}
			}
			if = {
				limit = { has_opinion_modifier = { who = ROOT modifier = supported_in_succession } }
				custom_tooltip = { text = SUPPORTED_HEIR }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_second_heir modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_second_heir
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_SECOND_HEIR }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_male modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_male
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_MALE }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_female modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_female
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_FEMALE }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_primo modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_primo
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_PRIMO }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_senior modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_senior
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_SENIOR }
			}
			if = {
				limit = {
					OR = {
						has_opinion_modifier = { who = event_target:candidate_ability modifier = supported_in_succession }
						AND = {
							character = event_target:candidate_ability
							NOT = { has_any_opinion_modifier = supported_in_succession }
						}
					}
				}
				custom_tooltip = { text = SUPPORTED_ABILITY }
			}
		}
	}
	option = {
		name = CURSES
		trigger = {
			OR = {
				character = event_target:candidate_second_heir
				character = event_target:candidate_male
				character = event_target:candidate_female
				character = event_target:candidate_primo
				character = event_target:candidate_senior
				character = event_target:candidate_ability
			}
		}
		ROOT = {
			any_vassal = {
				limit = {
					OR = {
						has_any_opinion_modifier = supported_in_succession
						character = event_target:candidate_second_heir
						character = event_target:candidate_male
						character = event_target:candidate_female
						character = event_target:candidate_primo
						character = event_target:candidate_senior
						character = event_target:candidate_ability
					}
				}
				if = {
					limit = { has_opinion_modifier = { who = ROOT modifier = supported_in_succession } }
					custom_tooltip = { text = SUPPORTED_HEIR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_second_heir modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_second_heir
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_SECOND_HEIR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_male modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_male
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_MALE }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_female modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_female
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_FEMALE }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_primo modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_primo
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_PRIMO }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_senior modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_senior
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_SENIOR }
				}
				if = {
					limit = {
						OR = {
							has_opinion_modifier = { who = event_target:candidate_ability modifier = supported_in_succession }
							AND = {
								character = event_target:candidate_ability
								NOT = { has_any_opinion_modifier = supported_in_succession }
							}
						}
					}
					custom_tooltip = { text = SUPPORTED_ABILITY }
				}
			}
		}
	}
	option = {
		name = OK
		trigger = {
			NOR = {
				character = ROOT
				character = event_target:candidate_second_heir
				character = event_target:candidate_male
				character = event_target:candidate_female
				character = event_target:candidate_primo
				character = event_target:candidate_senior
				character = event_target:candidate_ability
			}
		}
	}
}

# The succession crisis is averted due to war
character_event = {
	id = Plus.1617
	desc = EVTDESC_Plus_1617
	picture = GFX_evt_coronation
	
	is_triggered_only = yes
	major = yes
	
	major_trigger = {
		OR = {
			character = ROOT
			same_realm = ROOT
			dynasty = ROOT
		}
	}
	
	trigger = {
		OR = {
			trait = pf_rebel
			any_demesne_title = { is_contested = yes }
			any_demesne_title = { temporary = yes }
			has_character_flag = faction_court_war
			has_character_flag = faction_prosperity_war
			has_character_flag = faction_glory_war
			has_character_flag = faction_tradition_war
			has_character_flag = faction_separatist_war
			has_character_flag = faction_pretender_war
			has_character_flag = faction_religious_war
			has_character_flag = faction_succession_war
		}
	}
	
	option = {
		name = EVTOPTA_Plus_1617
		trigger = { character = ROOT }
		hidden_tooltip = {
			any_demesne_title = {
				limit = { has_title_flag = will_be_inherited }
				clr_title_flag = will_be_inherited
			}
			event_target:candidate_second_heir = { set_character_flag = justified_claimant }
			event_target:candidate_male = { set_character_flag = justified_claimant }
			event_target:candidate_female = { set_character_flag = justified_claimant }
			event_target:candidate_primo = { set_character_flag = justified_claimant }
			event_target:candidate_senior = { set_character_flag = justified_claimant }
			event_target:candidate_ability = { set_character_flag = justified_claimant }
		}
	}
	option = {
		name = OK
		trigger = { NOT = { character = ROOT } }
	}
}

######################################
# TITLE DESTRUCTION EVENTS
# Written by Rylock
######################################

# Crown is under threat of destruction following revolt
character_event = {
	id = Plus.1620
	title = EVTNAME_Plus_1620
	desc = EVTDESC_Plus_1620
	picture = GFX_evt_royal_court
	
	is_triggered_only = yes
	hide_from = yes
	
	trigger = {
		primary_title = { has_title_flag = destroy_title }
		OR = {
			has_game_rule = {
				name = low_ca_instability
				value = yes
			}
			AND = {
				ai = no
				has_game_rule = {
					name = low_ca_instability
					value = player
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				is_theocracy = yes
			}
			primary_title = { clr_title_flag = destroy_title }
			set_character_flag = free_pass
		}
		primary_title = {
			save_event_target_as = threatened_title
			clr_title_flag = destroy_title
		}
		if = {
			limit = {
				tier = EMPEROR
			}
			set_variable = { which = "approves_succesion" value = 5 }
		}
		if = {
			limit = {
				tier = KING
			}
			set_variable = { which = "approves_succesion" value = 4 }
		}		
		set_variable = { which = "reject_succesion" value = 0 }
		set_variable = { which = "dontcare_succesion" value = 0 }
		any_vassal = {
			#Vassals approving succesion
			if = {
				limit = {
					OR = {
						opinion = { who = ROOT value = 15 }
						dynasty = ROOT
					}
					tier = KING
				}
				ROOT = { change_variable = { which = "approves_succesion" value = 4 } }
			}
			if = {
				limit = {
					OR = {
						opinion = { who = ROOT value = 15 }
						dynasty = ROOT
					}
					tier = DUKE
				}
				ROOT = { change_variable = { which = "approves_succesion" value = 3 } }
			}
			if = {
				limit = {
					OR = {
						opinion = { who = ROOT value = 15 }
						dynasty = ROOT
					}
					tier = COUNT
				}
				ROOT = { change_variable = { which = "approves_succesion" value = 2 } }
			}
			if = {
				limit = {
					OR = {
						opinion = { who = ROOT value = 15 }
						dynasty = ROOT
					}
					tier = BARON
				}
				ROOT = { change_variable = { which = "dontcare_succesion" value = 1 } }
			}
			
			#Vassals don't really care
			if = {
				limit = {
					NOT = { opinion = { who = ROOT value = 15 } }
					opinion = { who = ROOT value = -25 }
					tier = KING
				}
				ROOT = { change_variable = { which = "dontcare_succesion" value = 4 } }
			}
			if = {
				limit = {
					NOT = { opinion = { who = ROOT value = 15 } }
					opinion = { who = ROOT value = -25 }
					tier = DUKE
				}
				ROOT = { change_variable = { which = "dontcare_succesion" value = 3 } }
			}
			if = {
				limit = {
					NOT = { opinion = { who = ROOT value = 15 } }
					opinion = { who = ROOT value = -25 }
					tier = COUNT
				}
				ROOT = { change_variable = { which = "dontcare_succesion" value = 2 } }
			}
			if = {
				limit = {
					NOT = { opinion = { who = ROOT value = 15 } }
					opinion = { who = ROOT value = -25 }
					tier = BARON
				}
				ROOT = { change_variable = { which = "dontcare_succesion" value = 1 } }
			}
		
			#Vassals reject succession
			if = {
				limit = {
					NOT = { opinion = { who = ROOT value = -25 } }
					tier = KING
				}
				ROOT = { change_variable = { which = "reject_succesion" value = 4 } }
			}
			if = {
				limit = {
					NOT = { opinion = { who = ROOT value = -25 } }
					tier = DUKE
				}
				ROOT = { change_variable = { which = "reject_succesion" value = 3 } }
			}
			if = {
				limit = {
					NOT = { opinion = { who = ROOT value = -25 } }
					tier = COUNT
				}
				ROOT = { change_variable = { which = "reject_succesion" value = 2 } }
			}
			if = {
				limit = {
					NOT = { opinion = { who = ROOT value = -25 } }
					tier = BARON
				}
				ROOT = { change_variable = { which = "reject_succesion" value = 1 } }
			}
		}
		set_variable = { which = "total_votes" which = "approves_succesion" }
		change_variable = { which = "total_votes" which = "dontcare_succesion" }
		change_variable = { which = "total_votes" which = "reject_succesion" }
		
		divide_variable = { which = "dontcare_succesion" which = "total_votes" }
		
		if = {
			limit = {
				#Approval
				check_variable = { which = "approves_succesion" which = "reject_succesion"}
				#At lest half the people voted
				NOT = { check_variable = { which = "dontcare_succesion" value = 0.5 } }
			}
			set_character_flag = succession_vassal_support
		}
		set_variable = { which = "reject_succesion" value = 0 }
		set_variable = { which = "dontcare_succesion" value = 0 }
		set_variable = { which = "approves_succesion" value = 0 }
		set_variable = { which = "total_votes" value = 0 }
	}
	
	option = {
		name = EVTOPTA_Plus_1620 # Save the title
		trigger = {
			OR = {
				AND = {
					prestige = 0
					wealth = 0
				}
				has_character_flag = free_pass
			}
			OR = {
				AND = {
					event_target:threatened_title = { tier = KING }
					wealth = 150
					prestige = 250
				}
				AND = {
					event_target:threatened_title = { tier = EMPEROR }
					wealth = 250
					prestige = 500
				}
				has_landed_title = e_hre
				has_character_flag = succession_vassal_support
				has_character_flag = free_pass
			}
		}
		ai_chance = {
			factor = 100
		}
		log = "The [Root.PrimaryTitle.GetFullName] was threatened with destruction, but was rescued by [Root.GetTitledName]"		
		if = {
			limit = {
				has_character_flag = free_pass
			}
			clr_character_flag = free_pass
			break = yes
		}
		if = {
			limit = {
				event_target:threatened_title = { tier = KING }
				has_character_flag = succession_vassal_support
			}
			wealth = -75
			prestige = -125
		}
		if = {
			limit = {
				event_target:threatened_title = { tier = KING }
				NOT = { has_character_flag = succession_vassal_support }
			}
			wealth = -150
			prestige = -250
		}
		if = {
			limit = {
				event_target:threatened_title = { tier = EMPEROR }
				has_character_flag = succession_vassal_support
			}
			wealth = -125
			prestige = -250
		}
		if = {
			limit = {
				event_target:threatened_title = { tier = EMPEROR }
				NOT = { has_character_flag = succession_vassal_support }
			}
			wealth = -250
			prestige = -500
		}
	}
	option = {
		name = EVTOPTB_Plus_1620 #take a loan: historic titles
		trigger = {			
			event_target:threatened_title = { is_historic_title_trigger = yes }
			OR = {
				AND = {
					ai = no
					NOT = { has_character_flag = loan_taken }
					NOT = { has_character_flag = offended_moneylenders }
				}
				ai = yes
			}
			NOT = { has_character_flag = free_pass }
		}
		ai_chance = {
			factor = 100
			modifier = {
				factor = 0
				event_target:threatened_title = { tier = KING }
				wealth = 150
				prestige = 250
			}
			modifier = {
				factor = 0
				event_target:threatened_title = { tier = EMPEROR }
				wealth = 250
				prestige = 500
			}
			modifier = {
				factor = 0
				check_variable = { which = "loan_amount" value = 49.5 }
			}
			modifier = {
				factor = 0
				prestige = 0
				wealth = 0
				has_character_flag = succession_vassal_support
			}
			modifier = {
				factor = 0
				prestige = 0
				wealth = 0
				has_landed_title = e_hre
			}
		}
		log = "The [Root.PrimaryTitle.GetFullName] was threatened with destruction, but was rescued by [Root.GetTitledName] with moneylenders' support."
		custom_tooltip = {
			text = take_loan_desc
			take_loan_effect = yes
		}
		if = {
			limit = {
				event_target:threatened_title = { tier = KING }
				has_character_flag = succession_vassal_support
			}
			wealth = -75
			prestige = -125
		}
		if = {
			limit = {
				event_target:threatened_title = { tier = KING }
				NOT = { has_character_flag = succession_vassal_support }
			}
			wealth = -150
			prestige = -250
		}
		if = {
			limit = {
				event_target:threatened_title = { tier = EMPEROR }
				has_character_flag = succession_vassal_support
			}
			wealth = -125
			prestige = -250
		}
		if = {
			limit = {
				event_target:threatened_title = { tier = EMPEROR }
				NOT = { has_character_flag = succession_vassal_support }
			}
			wealth = -250
			prestige = -500
		}
	}
	option = {
		name = EVTOPTC_Plus_1620 #if major vassal is foreign/NDJ, release all foreign/NDJ vassals
		trigger = {			
			event_target:threatened_title = { major_vassal_is_foreign_trigger = yes }
			NOT = { has_character_flag = free_pass }
		}
		ai_chance = {
			factor = 100
			modifier = {
				factor = 0
				event_target:threatened_title = { tier = KING }
				wealth = 150
				prestige = 250
			}
			modifier = {
				factor = 0
				event_target:threatened_title = { tier = EMPEROR }
				wealth = 250
				prestige = 500
			}
			modifier = {
				factor = 0
				prestige = 0
				wealth = 0
				has_character_flag = succession_vassal_support
			}
			modifier = {
				factor = 0
				prestige = 0
				wealth = 0
				has_landed_title = e_hre
			}
			modifier = {
				factor = 0
				event_target:threatened_title = { is_historic_title_trigger = yes }
				NOT = { check_variable = { which = "loan_amount" value = 49.5 } }
			}
		}
		custom_tooltip = {
			text = EVTTOOLTIPC_Plus_1620
			log = "The [Root.PrimaryTitle.GetFullName] was threatened with destruction, but was rescued by [Root.GetTitledName] at the cost of its foreign vassals."
			any_vassal = {
				limit = {
					NOR = { 
						liege = { culture = PREV }
						de_jure_liege_or_above = PREV
					}
				}
				set_defacto_liege = THIS
				reverse_opinion = {
					who = ROOT
					modifier = opinion_rightful_vassal
					months = 60
				}
				#Notification event: do we think this is necessary?
				ROOT = {
					character_event = { id = 63101 days = 4 }
				}
			}
		}
	}
	option = {
		trigger = {
			NOT = { has_character_flag = free_pass }
		}
		name = EVTOPTD_Plus_1620 # There is nothing I can do
		ai_chance = {
			factor = 0
		}
		log = "The [Root.PrimaryTitle.GetFullName] has been destroyed after its Crown Authority fell too low"
		tooltip = {
			event_target:threatened_title = { destroy_landed_title = THIS }
		}
		hidden_tooltip = {
			#If Carolingian Empire is the threatened title, 
			#trigger the existing Fall of the Carolingian Empire event instead
			if = {
				limit = {
					event_target:threatened_title = { title = e_karling }
				}
				narrative_event = { id = Plus.1162 }
				break = yes
			}
			narrative_event = { id = Plus.1621 }
		}
	}
}

# Primary title is destroyed due to loss of crown authority
narrative_event = {
	id = Plus.1621
	title = EVTNAME_Plus_1620
	desc = EVTDESC_Plus_1621
	picture = GFX_evt_royal_court	

	is_triggered_only = yes
	major = yes
	hide_from = yes
	show_ROOT = yes
	
	major_trigger = {
		OR = {
			character = ROOT
			same_realm = ROOT
			has_claim = event_target:threatened_title
			capital_scope = {
				ROOT = {
					capital_scope = {
						NOT = {
							distance = {
								where = PREVPREV
								value = 600	# Same part of the world
							}
						}
					}
				}
			}
		}
	}
	
	option = {
		name = CURSES
		trigger = { character = ROOT }
		if = {
			limit = {
				any_demesne_title = {
					NOT = { title = event_target:threatened_title }
					tier = KING
				}
			}
			any_vassal = {
				limit = { higher_tier_than = DUKE }
				primary_title = { add_pressed_claim = ROOT }
			}
		}
		if = {
			limit = {
				NOT = {
					any_demesne_title = {
						NOT = { title = event_target:threatened_title }
						tier = KING
					}
				}
				any_demesne_title = {
					NOT = { title = event_target:threatened_title }
					tier = DUKE
				}
			}
			any_vassal = {
				limit = { higher_tier_than = COUNT }
				primary_title = { add_pressed_claim = ROOT }
			}
		}
		if = {
			limit = {
				NOT = {
					any_demesne_title = {
						NOT = { title = event_target:threatened_title }
						higher_tier_than = COUNT
					}
				}
			}
			any_vassal = {
				limit = { higher_tier_than = BARON }
				primary_title = { add_pressed_claim = ROOT }
			}
		}
		hidden_tooltip = {
			event_target:threatened_title = { destroy_landed_title = THIS }
		}
	}
	option = {
		name = I_SEE
		trigger = {
			NOT = { character = ROOT }
			religion_group = ROOT
		}
	}
	option = {
		name = EVTOPTA_Plus_1621
		trigger = {
			NOT = { character = ROOT }
			NOT = { religion_group = ROOT }
		}
	}
}
	
