
namespace = Plus

#reserved: Plus.100 to Plus.149
#reserved: Plus.1750 to Plus.1849

#######################################
# ESTATE EVENTS
#######################################

# Grant Estate - fired from the minor title
character_event = {
	id = Plus.105
	desc = "EVTDESC_Plus_105"
	picture = GFX_evt_emissary
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_105" #A minor estate
		trigger = {
			wealth = 50
			FROM = {
				NOT = { has_character_modifier = estates_5 }
			}
		}
		wealth = -50
		reverse_opinion = {
			modifier = opinion_granted_minor_estate
			who = FROM
			years = 100
		}
		FROM = {
			if = {
				limit = { has_character_modifier = estates_4 }
				remove_character_modifier = estates_4
				add_character_modifier = {
					name = "estates_5"
					duration = -1
				}
			}
			if = {
				limit = { has_character_modifier = estates_3 }
				remove_character_modifier = estates_3
				add_character_modifier = {
					name = "estates_4"
					duration = -1
				}
			}
			if = {
				limit = { has_character_modifier = estates_2 }
				remove_character_modifier = estates_2
				add_character_modifier = {
					name = "estates_3"
					duration = -1
				}
			}
			if = {
				limit = { has_character_modifier = estates_1 }
				remove_character_modifier = estates_1
				add_character_modifier = {
					name = "estates_2"
					duration = -1
				}
			}
			if = {
				limit = {
					NOR = {
						has_character_modifier = estates_1
						has_character_modifier = estates_2
						has_character_modifier = estates_3
						has_character_modifier = estates_4
						has_character_modifier = estates_5
					}
				}
				add_character_modifier = {
					name = "estates_1"
					duration = -1
				}
				hidden_tooltip = {
					give_minor_title = title_lord
				}
			}
		}
	}
	option = {
		name = "EVTOPTB_Plus_105" #A moderate estate
		trigger = {
			wealth = 150
			FROM = {
				NOR = {
					has_character_modifier = estates_3
					has_character_modifier = estates_4
					has_character_modifier = estates_5
				}
			}
		}
		wealth = -150
		reverse_opinion = {
			modifier = opinion_granted_minor_estate
			who = FROM
			years = 100
			multiplier = 3
		}
		FROM = {
			if = {
				limit = { has_character_modifier = estates_2 }
				remove_character_modifier = estates_2
				add_character_modifier = {
					name = "estates_5"
					duration = -1
				}
			}
			if = {
				limit = { has_character_modifier = estates_1 }
				remove_character_modifier = estates_1
				add_character_modifier = {
					name = "estates_4"
					duration = -1
				}
			}
			if = {
				limit = {
					NOR = {
						has_character_modifier = estates_1
						has_character_modifier = estates_2
						has_character_modifier = estates_3
						has_character_modifier = estates_4
						has_character_modifier = estates_5
					}
				}
				add_character_modifier = {
					name = "estates_3"
					duration = -1
				}
				hidden_tooltip = {
					give_minor_title = title_lord
				}
			}
		}
	}
	option = {
		name = "EVTOPTC_Plus_105" #A large estate
		trigger = {
			wealth = 250
			FROM = {
				NOR = {
					has_character_modifier = estates_1
					has_character_modifier = estates_2
					has_character_modifier = estates_3
					has_character_modifier = estates_4
					has_character_modifier = estates_5
				}
			}
		}
		wealth = -250
		reverse_opinion = {
			modifier = opinion_granted_minor_estate
			who = FROM
			years = 100
			multiplier = 5
		}
		FROM = {
			add_character_modifier = {
				name = "estates_5"
				duration = -1
			}
			hidden_tooltip = {
				give_minor_title = title_lord
			}
		}
	}
	option = {
		name = "EVTOPTD_Plus_105" #None at all!
	}
}

# Relative demands estates due to his ambition
character_event = {
	id = Plus.106
	desc = AI_EVENT
	picture = GFX_evt_emissary

	min_age = 20
	capable_only = yes
	prisoner = no

	trigger = {
		has_ambition = obj_gain_estates_1
		is_ruler = no
		NOT = { trait = eunuch }
		NOT = { trait = monk }
		NOT = { trait = nun }
		NOT = { has_minor_title = title_guru }
		NOT = { has_character_flag = flag_denied_estates }
		liege = {
			NOT = { spouse = { character = ROOT } }
			war = no
			OR = {
				is_close_relative = ROOT
				dynasty = ROOT
			}
			wealth = 50
		}
	}

	mean_time_to_happen = {
		months = 12

		modifier = {
			factor = 10.0
			liege = {
				NOT = { is_close_relative = ROOT }
			}
		}
		modifier = {
			factor = 0.5
			liege = {
				wealth = 250
			}
		}
		modifier = {
			factor = 0.5
			liege = {
				wealth = 500
			}
		}
		modifier = {
			factor = 0.5
			trait = greedy
		}
		modifier = {
			factor = 0.5
			trait = ambitious
		}
		modifier = {
			factor = 0.5
			trait = diligent
		}
		modifier = {
			factor = 5.0
			trait = slothful
		}
		modifier = {
			factor = 5.0
			trait = content
		}
		modifier = {
			factor = 5.0
			trait = charitable
		}
	}

	option = {
		name = OK # Ask liege for estates
		liege = { character_event = { id = Plus.107 days = 3 } }
	}
}

# Liege responds to the request
character_event = {
	id = Plus.107
	desc = EVTDESC_Plus_107
	picture = GFX_evt_emissary

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_107 # Give him what he wants
		trigger = {
			wealth = 50
		}
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0
				has_character_modifier = ai_austerity
			}
			modifier = {
				factor = 0.1
				trait = greedy
			}
			modifier = {
				factor = 10
				trait = charitable
			}
			modifier = {
				factor = 2
				wealth = 100
			}
			modifier = {
				factor = 2
				wealth = 200
			}
			modifier = {
				factor = 2
				wealth = 300
			}
			modifier = {
				factor = 2
				wealth = 400
			}
			modifier = {
				factor = 2
				wealth = 500
			}
			modifier = {
				factor = 5
				any_child = { character = FROM }
			}
			modifier = {
				factor = 10
				FROM = { is_primary_heir = yes }
			}
		}
		wealth = -50
		reverse_opinion = {
			modifier = opinion_granted_minor_estate
			who = FROM
			years = 100
		}
		FROM = {
			add_character_modifier = {
				name = estates_1
				duration = -1
			}
			hidden_tooltip = {
				give_minor_title = title_lord
			}
		}
	}

	option = {
		name = EVTOPTB_Plus_107 # Say you can't afford it
		ai_chance = {
			factor = 90
		}
		FROM = {
			opinion = {
				modifier = opinion_denied_estates
				who = ROOT
				months = 240
			}
			tooltip = { cancel_ambition = yes }
			set_character_flag = flag_denied_estates
		}
	}
}

# Character buys estates if they have the money (on-action bi-yearly pulse event)
character_event = {
	id = Plus.108
	desc = "AI_EVENT"
	picture = GFX_evt_council
	
	is_triggered_only = yes
	
	min_age = 16
	capable_only = yes
	prisoner = no
	ai = yes

	trigger = {
		liege = { is_nomadic = no }
		liege = { is_tribal = no }
		wealth = 50
		is_ruler = no
		OR = {
			is_female = no
			liege = {
				OR = {
					has_law = true_cognatic_succession
					has_law = enatic_cognatic_succession
					has_law = enatic_succession
				}
			}
			liege = {
				is_close_relative = ROOT
				has_law = cognatic_succession
			}
		}
		NOR = {
			trait = incapable
			spouse = { is_ruler = yes }
			trait = eunuch
			trait = blinded
			has_minor_title = title_guru
			trait = monk
			trait = nun
			has_character_modifier = estates_5
			has_character_modifier = planning_claimant_adventure
		}
	}

	weight_multiplier = {
		days = 1
	}

	option = {
		name = "OK"
		wealth = -50
		if = {
			limit = { has_character_modifier = estates_4 }
			remove_character_modifier = estates_4
			add_character_modifier = {
				name = "estates_5"
				duration = -1
			}
		}
		if = {
			limit = { has_character_modifier = estates_3 }
			remove_character_modifier = estates_3
			add_character_modifier = {
				name = "estates_4"
				duration = -1
			}
		}
		if = {
			limit = { has_character_modifier = estates_2 }
			remove_character_modifier = estates_2
			add_character_modifier = {
				name = "estates_3"
				duration = -1
			}
		}
		if = {
			limit = { has_character_modifier = estates_1 }
			remove_character_modifier = estates_1
			add_character_modifier = {
				name = "estates_2"
				duration = -1
			}
		}
		if = {
			limit = {
				NOR = {
					has_character_modifier = estates_1
					has_character_modifier = estates_2
					has_character_modifier = estates_3
					has_character_modifier = estates_4
					has_character_modifier = estates_5
				}
			}
			add_character_modifier = {
				name = "estates_1"
				duration = -1
			}
			give_minor_title = title_lord
		}
	}
}

# Ruler sells off estates (on-action bi-yearly pulse event)
character_event = {
	id = Plus.109
	desc = "EVTDESC_Plus_109"
	picture = "GFX_evt_council"
	
	is_triggered_only = yes
	
	only_rulers = yes

	trigger = {
		OR = {
			has_character_modifier = estates_1
			has_character_modifier = estates_2
			has_character_modifier = estates_3
			has_character_modifier = estates_4
			has_character_modifier = estates_5
		}
	}

	weight_multiplier = {
		days = 1
	}

	option = {
		name = "OK"
		if = {
			limit = { has_character_modifier = estates_1 }
			remove_character_modifier = estates_1
			wealth = 40
		}
		if = {
			limit = { has_character_modifier = estates_2 }
			remove_character_modifier = estates_2
			wealth = 80
		}
		if = {
			limit = { has_character_modifier = estates_3 }
			remove_character_modifier = estates_3
			wealth = 120
		}
		if = {
			limit = { has_character_modifier = estates_4 }
			remove_character_modifier = estates_4
			wealth = 160
		}
		if = {
			limit = { has_character_modifier = estates_5 }
			remove_character_modifier = estates_5
			wealth = 200
		}
	}
}

# Estates Removal Upon Exile (on-action event)
character_event = {
	id = Plus.110
	desc = "EVTDESC155"
	picture = GFX_evt_carriage

	is_triggered_only = yes

	immediate = {
		remove_character_modifier = estates_1
		remove_character_modifier = estates_2
		remove_character_modifier = estates_3
		remove_character_modifier = estates_4
		remove_character_modifier = estates_5
	}
	
	option = {
		name = OK
	}
}

# Estates Succession On Character Death (on-action event)
character_event = {
	id = Plus.111

	hide_window = yes
	is_triggered_only = yes
	
	ai = yes
	
	trigger = {
		is_ruler = no
		OR = {
			has_character_modifier = estates_1
			has_character_modifier = estates_2
			has_character_modifier = estates_3
			has_character_modifier = estates_4
			has_character_modifier = estates_5
		}
	}

	immediate = {
		# deal with first rank of estates
		if = {
			limit = {
				any_child = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
				}
			}
			random_child = {
				limit = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes							
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
					NOR = {
						trait = bastard
						has_character_flag = received_estate
						any_sibling = {
							is_older_than = PREV
							OR = {
								AND = {
									ROOT = { liege = { has_law = agnatic_succession } }
									is_female = no
								}
								AND = {
									ROOT = { liege = { has_law = cognatic_succession } }
									is_female = no
								}
								ROOT = { liege = { has_law = true_cognatic_succession } }
								AND = {
									ROOT = { liege = { has_law = enatic_cognatic_succession } }
									is_female = yes
								}
								AND = {
									ROOT = { liege = { has_law = enatic_succession } }
									is_female = yes
								}
							}
							NOR = {
								trait = bastard
								has_character_flag = received_estate
							}
						}
					}
				}
				set_character_flag = received_estate
				if = {
					limit = {
						OR = {
							is_ruler = yes
							has_character_modifier = estates_5
						}
					}
					wealth = 40
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_4
					}
					remove_character_modifier = estates_4
					add_character_modifier = { name = "estates_5" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_3
					}
					remove_character_modifier = estates_3
					add_character_modifier = { name = "estates_4" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_2
					}
					remove_character_modifier = estates_2
					add_character_modifier = { name = "estates_3" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_1
					}
					remove_character_modifier = estates_1
					add_character_modifier = { name = "estates_2" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						NOR = {
							has_character_modifier = estates_1
							has_character_modifier = estates_2
							has_character_modifier = estates_3
							has_character_modifier = estates_4
							has_character_modifier = estates_5
						}
					}
					add_character_modifier = { name = "estates_1" duration = -1 }
					hidden_tooltip = {
						give_minor_title = title_lord
					}
				}
			}
			ROOT = {
				if = {
					limit = { has_character_modifier = estates_1 }
					remove_character_modifier = estates_1
				}
				if = {
					limit = { has_character_modifier = estates_2 }
					remove_character_modifier = estates_2
					add_character_modifier = { name = "estates_1" duration = -1 }
				}
				if = {
					limit = { has_character_modifier = estates_3 }
					remove_character_modifier = estates_3
					add_character_modifier = { name = "estates_2" duration = -1 }
				}
				if = {
					limit = { has_character_modifier = estates_4 }
					remove_character_modifier = estates_4
					add_character_modifier = { name = "estates_3" duration = -1 }
				}
				if = {
					limit = { has_character_modifier = estates_5 }
					remove_character_modifier = estates_5
					add_character_modifier = { name = "estates_4" duration = -1 }
				}
			}
		}
		# deal with second rank of estates
		if = {
			limit = {
				OR = {
					has_character_modifier = estates_1
					has_character_modifier = estates_2
					has_character_modifier = estates_3
					has_character_modifier = estates_4
				}
				any_child = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no							
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes							
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
				}
			}
			random_child = {
				limit = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no							
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes							
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
					NOR = {
						trait = bastard
						has_character_flag = received_estate
						any_sibling = {
							is_older_than = PREV
							OR = {
								AND = {
									ROOT = { liege = { has_law = agnatic_succession } }
									is_female = no							
								}
								AND = {
									ROOT = { liege = { has_law = cognatic_succession } }
									is_female = no									
								}
								ROOT = { liege = { has_law = true_cognatic_succession } }
								AND = {
									ROOT = { liege = { has_law = enatic_cognatic_succession } }
									is_female = yes										
								}
								AND = {
									ROOT = { liege = { has_law = enatic_succession } }
									is_female = yes							
								}
							}
							NOR = {
								trait = bastard
								has_character_flag = received_estate
							}
						}
					}
				}
				set_character_flag = received_estate
				if = {
					limit = {
						OR = {
							is_ruler = yes
							has_character_modifier = estates_5
						}
					}
					wealth = 40
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_4
					}
					remove_character_modifier = estates_4
					add_character_modifier = { name = "estates_5" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_3
					}
					remove_character_modifier = estates_3
					add_character_modifier = { name = "estates_4" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_2
					}
					remove_character_modifier = estates_2
					add_character_modifier = { name = "estates_3" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_1
					}
					remove_character_modifier = estates_1
					add_character_modifier = { name = "estates_2" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						NOR = {
							has_character_modifier = estates_1
							has_character_modifier = estates_2
							has_character_modifier = estates_3
							has_character_modifier = estates_4
							has_character_modifier = estates_5
						}
					}
					add_character_modifier = { name = "estates_1" duration = -1 }
					hidden_tooltip = { give_minor_title = title_lord }
				}
			}
			ROOT = {
				if = {
					limit = { has_character_modifier = estates_1 }
					remove_character_modifier = estates_1
				}
				if = {
					limit = { has_character_modifier = estates_2 }
					remove_character_modifier = estates_2
					add_character_modifier = { name = "estates_1" duration = -1 }
				}
				if = {
					limit = { has_character_modifier = estates_3 }
					remove_character_modifier = estates_3
					add_character_modifier = { name = "estates_2" duration = -1 }
				}
				if = {
					limit = { has_character_modifier = estates_4 }
					remove_character_modifier = estates_4
					add_character_modifier = { name = "estates_3" duration = -1 }
				}
			}
		}
		# deal with third rank of estates
		if = {
			limit = {
				OR = {
					has_character_modifier = estates_1
					has_character_modifier = estates_2
					has_character_modifier = estates_3
				}
				any_child = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no							
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes							
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
				}
			}
			random_child = {
				limit = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no							
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes							
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
					NOR = {
						trait = bastard
						has_character_flag = received_estate
						any_sibling = {
							is_older_than = PREV
							OR = {
								AND = {
									ROOT = { liege = { has_law = agnatic_succession } }
									is_female = no							
								}
								AND = {
									ROOT = { liege = { has_law = cognatic_succession } }
									is_female = no									
								}
								ROOT = { liege = { has_law = true_cognatic_succession } }
								AND = {
									ROOT = { liege = { has_law = enatic_cognatic_succession } }
									is_female = yes										
								}
								AND = {
									ROOT = { liege = { has_law = enatic_succession } }
									is_female = yes							
								}
							}
							NOR = {
								trait = bastard
								has_character_flag = received_estate
							}
						}
					}
				}
				set_character_flag = received_estate
				if = {
					limit = {
						OR = {
							is_ruler = yes
							has_character_modifier = estates_5
						}
					}
					wealth = 40
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_4
					}
					remove_character_modifier = estates_4
					add_character_modifier = { name = "estates_5" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_3
					}
					remove_character_modifier = estates_3
					add_character_modifier = { name = "estates_4" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_2
					}
					remove_character_modifier = estates_2
					add_character_modifier = { name = "estates_3" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_1
					}
					remove_character_modifier = estates_1
					add_character_modifier = { name = "estates_2" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						NOR = {
							has_character_modifier = estates_1
							has_character_modifier = estates_2
							has_character_modifier = estates_3
							has_character_modifier = estates_4
							has_character_modifier = estates_5
						}
					}
					add_character_modifier = { name = "estates_1" duration = -1 }
					hidden_tooltip = { give_minor_title = title_lord }
				}
			}
			ROOT = {
				if = {
					limit = { has_character_modifier = estates_1 }
					remove_character_modifier = estates_1
				}
				if = {
					limit = { has_character_modifier = estates_2 }
					remove_character_modifier = estates_2
					add_character_modifier = { name = "estates_1" duration = -1 }
				}
				if = {
					limit = { has_character_modifier = estates_3 }
					remove_character_modifier = estates_3
					add_character_modifier = { name = "estates_2" duration = -1 }
				}
			}
		}
		# deal with fourth rank of estates
		if = {
			limit = {
				OR = {
					has_character_modifier = estates_1
					has_character_modifier = estates_2
				}
				any_child = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no							
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes							
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
				}
			}
			random_child = {
				limit = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no							
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes							
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
					NOR = {
						trait = bastard
						has_character_flag = received_estate
						any_sibling = {
							is_older_than = PREV
							OR = {
								AND = {
									ROOT = { liege = { has_law = agnatic_succession } }
									is_female = no							
								}
								AND = {
									ROOT = { liege = { has_law = cognatic_succession } }
									is_female = no									
								}
								ROOT = { liege = { has_law = true_cognatic_succession } }
								AND = {
									ROOT = { liege = { has_law = enatic_cognatic_succession } }
									is_female = yes										
								}
								AND = {
									ROOT = { liege = { has_law = enatic_succession } }
									is_female = yes							
								}
							}
							NOR = {
								trait = bastard
								has_character_flag = received_estate
							}
						}
					}
				}
				set_character_flag = received_estate
				if = {
					limit = {
						OR = {
							is_ruler = yes
							has_character_modifier = estates_5
						}
					}
					wealth = 40
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_4
					}
					remove_character_modifier = estates_4
					add_character_modifier = { name = "estates_5" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_3
					}
					remove_character_modifier = estates_3
					add_character_modifier = { name = "estates_4" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_2
					}
					remove_character_modifier = estates_2
					add_character_modifier = { name = "estates_3" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_1
					}
					remove_character_modifier = estates_1
					add_character_modifier = { name = "estates_2" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						NOR = {
							has_character_modifier = estates_1
							has_character_modifier = estates_2
							has_character_modifier = estates_3
							has_character_modifier = estates_4
							has_character_modifier = estates_5
						}
					}
					add_character_modifier = { name = "estates_1" duration = -1 }
					hidden_tooltip = { give_minor_title = title_lord }
				}
			}
			ROOT = {
				if = {
					limit = { has_character_modifier = estates_1 }
					remove_character_modifier = estates_1
				}
				if = {
					limit = { has_character_modifier = estates_2 }
					remove_character_modifier = estates_2
					add_character_modifier = { name = "estates_1" duration = -1 }
				}
			}
		}
		# deal with fifth rank of estates
		if = {
			limit = {
				has_character_modifier = estates_1
				any_child = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no							
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes							
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
				}
			}
			random_child = {
				limit = {
					OR = {
						AND = {
							ROOT = { liege = { has_law = agnatic_succession } }
							is_female = no							
						}
						ROOT = { liege = { has_law = cognatic_succession } }
						ROOT = { liege = { has_law = true_cognatic_succession } }
						ROOT = { liege = { has_law = enatic_cognatic_succession } }
						AND = {
							ROOT = { liege = { has_law = enatic_succession } }
							is_female = yes							
						}
					}
					NOT = { trait = bastard }
					NOT = { has_character_flag = received_estate }
					NOR = {
						trait = bastard
						has_character_flag = received_estate
						any_sibling = {
							OR = {
								AND = {
									ROOT = { liege = { has_law = agnatic_succession } }
									is_female = no							
								}
								AND = {
									ROOT = { liege = { has_law = cognatic_succession } }
									is_female = no									
								}
								ROOT = { liege = { has_law = true_cognatic_succession } }
								AND = {
									ROOT = { liege = { has_law = enatic_cognatic_succession } }
									is_female = yes										
								}
								AND = {
									ROOT = { liege = { has_law = enatic_succession } }
									is_female = yes							
								}
							}
							is_older_than = PREV
							NOR = {
								trait = bastard
								has_character_flag = received_estate
							}
						}
					}
				}
				set_character_flag = received_estate
				if = {
					limit = {
						OR = {
							is_ruler = yes
							has_character_modifier = estates_5
						}
					}
					wealth = 40
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_4
					}
					remove_character_modifier = estates_4
					add_character_modifier = { name = "estates_5" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_3
					}
					remove_character_modifier = estates_3
					add_character_modifier = { name = "estates_4" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_2
					}
					remove_character_modifier = estates_2
					add_character_modifier = { name = "estates_3" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						has_character_modifier = estates_1
					}
					remove_character_modifier = estates_1
					add_character_modifier = { name = "estates_2" duration = -1 }
				}
				if = {
					limit = {
						is_ruler = no
						NOR = {
							has_character_modifier = estates_1
							has_character_modifier = estates_2
							has_character_modifier = estates_3
							has_character_modifier = estates_4
							has_character_modifier = estates_5
						}
					}
					add_character_modifier = { name = "estates_1" duration = -1 }
					hidden_tooltip = { give_minor_title = title_lord }
				}
			}
			ROOT = {
				if = {
					limit = { has_character_modifier = estates_1 }
					remove_character_modifier = estates_1
				}
			}
		}
		# remove estate flags from children
		any_child = {
			limit = { has_character_flag = received_estate }
			clr_character_flag = received_estate
		}
		# sell off the remainder of the estates
		if = {
			limit = { has_character_modifier = estates_1 }
			remove_character_modifier = estates_1
			wealth = 40
		}
		if = {
			limit = { has_character_modifier = estates_2 }
			remove_character_modifier = estates_2
			wealth = 80
		}
		if = {
			limit = { has_character_modifier = estates_3 }
			remove_character_modifier = estates_3
			wealth = 120
		}
		if = {
			limit = { has_character_modifier = estates_4 }
			remove_character_modifier = estates_4
			wealth = 160
		}
		if = {
			limit = { has_character_modifier = estates_5 }
			remove_character_modifier = estates_5
			wealth = 200
		}
	}
}

#######################################
# GENERATE RANDOM CLAIMS
#######################################

# Generate random claim on a neighbour
character_event = {
	id = Plus.115 #formerly 1000182425
	desc = "EVTDESC_Plus_115"
	picture = GFX_evt_emissary
	
	is_triggered_only = yes
	
	only_rulers = yes
	war = no
	
	trigger = {
		OR = {
			is_feudal = yes
			is_tribal = yes
		}
		primary_title = { higher_tier_than = BARON }
		has_regent = no
		any_playable_ruler = {
			OR = {
				is_feudal = yes
				is_tribal = yes
			}
			any_demesne_title = {
				location = {
					duchy = { 
						OR = { 
							has_holder = no 
							holder_scope = { 
								religion_group = ROOT 
								OR = { 
									ROOT = { independent = yes } 
									same_realm = ROOT 
								} 
							} 
						} 
						NOR = { 
							holder_scope = { 
								OR = { 
									character = ROOT 
									is_liege_or_above = ROOT 
									is_vassal_or_below = ROOT 
								} 
							} 
							ROOT = { has_claim = PREV } 
						} 
					}
					county = { 
						OR = { 
							has_holder = no 
							holder_scope = { 
								religion_group = ROOT 
								OR = { 
									ROOT = { independent = yes }
									same_realm = ROOT 
								} 
							} 
						} 
						NOR = { 
							holder_scope = { 
								OR = { 
									character = ROOT 
									is_liege_or_above = ROOT 
									is_vassal_or_below = ROOT 
								} 
							} 
							ROOT = { has_claim = PREV } 
						} 
					}
					any_neighbor_province = {
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		random = {
			chance = 20
			set_character_flag = duchy_claim
		}
		set_character_flag = claim_by_event
	}

	weight_multiplier = {
		days = 1
		modifier = {
			factor = 0.5
			ai = no
		}
		modifier = {
			factor = 0.25
			is_pagan_religion = yes
			is_reformed_pagan_religion = no
			NOT = { has_ambition = obj_become_king }
		}
		modifier = {
			factor = 1.1
			ai = no
			has_ambition = obj_become_king
		}
		modifier = {
			factor = 1.2
			ai = yes
			has_ambition = obj_become_king
		}
		modifier = {
			factor = 2.5 # AI doesn't fabricate claims effectively
			ai = yes
		}
		modifier = {
			factor = 3.0 # Encourage AI independent counts and dukes to form Kingdoms
			ai = yes
			independent = yes
			OR = {
				tier = count
				tier = duke
			}
			NOT = { 
				num_of_duke_titles = 2
			}
		}
		modifier = {
			factor = 1.2
			independent = yes
			trait = ambitious
		}
		modifier = {
			factor = 0.5
			independent = yes
			trait = content
		}
		modifier = {
			factor = 0.5 # Discourage free claims for bigger AI
			ai = yes
			independent = yes
			tier = king
			realm_size = 35
		}
		modifier = {
			factor = 0.25 # Discourage free claims for bigger AI
			ai = yes
			independent = yes
			tier = emperor
			realm_size = 120
		}
		modifier = {
			factor = 0.25
			independent = no
		}
		modifier = {
			factor = 1.1
			realm_diplomacy = 20
		}
		modifier = {
			factor = 1.1
			realm_diplomacy = 30
		}
		modifier = {
			factor = 1.1
			realm_diplomacy = 40
		}
		modifier = {
			factor = 1.1
			realm_diplomacy = 50
		}
	}

	option = {
		name = "EXCELLENT"
		random_playable_ruler = {
			limit = {
				OR = {
					is_feudal = yes
					is_tribal = yes
				}
				any_demesne_title = {
					location = {
						duchy = { 
							OR = { 
								has_holder = no 
								holder_scope = {
									religion_group = ROOT 
									OR = { 
										ROOT = { independent = yes } 
										same_realm = ROOT 
									} 
								} 
							} 
							NOR = { 
								holder_scope = { 
									OR = { 
										character = ROOT 
										is_liege_or_above = ROOT 
										is_vassal_or_below = ROOT 
									} 
								} 
								ROOT = { has_claim = PREV } 
							} 
						}
						county = { 
							OR = { 
								has_holder = no 
								holder_scope = { 
									religion_group = ROOT 
									OR = { 
										ROOT = { independent = yes } 
										same_realm = ROOT 
									} 
								} 
							} 
							NOR = { 
								holder_scope = { 
									OR = { 
										character = ROOT 
										is_liege_or_above = ROOT 
										is_vassal_or_below = ROOT 
									} 
								} 
							ROOT = { has_claim = PREV } 
							} 
						}
						any_neighbor_province = {
							owner = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
								}
							}
						}
					}
				}
			}
			random_demesne_title = {
				limit = {
					location = {
						duchy = { 
							OR = { 
								has_holder = no 
								holder_scope = { 
									religion_group = ROOT 
									OR = { 
										ROOT = { independent = yes } 
										same_realm = ROOT 
									} 
								} 
							} 
							NOR = { 
								holder_scope = { 
									OR = { 
										character = ROOT 
										is_liege_or_above = ROOT 
										is_vassal_or_below = ROOT 
									} 
								} 
								ROOT = { has_claim = PREV } 
							} 
						}
						county = { 
							OR = { 
								has_holder = no 
								holder_scope = { 
									religion_group = ROOT 
									OR = { 
										ROOT = { independent = yes } 
										same_realm = ROOT 
									} 
								} 
							} 
							NOR = { 
								holder_scope = { 
									OR = { 
										character = ROOT 
										is_liege_or_above = ROOT 
										is_vassal_or_below = ROOT 
									} 
								} 
								ROOT = { has_claim = PREV } 
							} 
						}
						any_neighbor_province = {
							owner = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
								}
							}
						}
					}
				}
				location = {
					if = {
						limit = {
							OR = {
								ROOT = { NOT = { has_character_flag = duchy_claim } }
								duchy = { has_holder = no }
							}
						}
						county = {
							add_claim = ROOT
							hidden_tooltip = {
								holder_scope = { character_event = { id = Plus.116 } }
							}
						}
					}
					if = {
						limit = {
							ROOT = { has_character_flag = duchy_claim }
							duchy = { has_holder = yes }
						}
						duchy = {
							add_claim = ROOT
							hidden_tooltip = {
								holder_scope = { character_event = { id = Plus.116 } }
							}
						}
					}
				}
			}
		}
		clr_character_flag = duchy_claim
	}
}

# Neighbor is informed of the claim
character_event = {
	id = Plus.116
	picture = GFX_evt_emissary
	desc = "EVTDESC_Plus_116"

	ai = no

	is_triggered_only = yes

	option = {
		name = "EVTOPTA_Plus_116"
	}
}

#######################################
# ABDICATION
# Written by Rylock
#######################################

# Ruler considers Abdication
character_event = {
	id = Plus.120
	picture = "GFX_evt_recovery"
	desc = "EVTDESC_Plus_120"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_120" #Go ahead and abdicate
		ai_chance = {
			factor = 100
		}
		hidden_tooltip = {
			current_heir = {
				character_event = { id = Plus.121 days = 1 }
			}
		}
		if = {
			limit = { is_priest = yes }
			set_character_flag = was_priest
		}
		
		#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 } }
			}
			ROOT = { current_heir = { 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 }
		}
		
		abdicate = yes
		if = {
			limit = { NOT = { trait = content } }
			add_trait = content
		}
		if = {
			limit = {
				is_female = yes
				religion_group = christian
				OR = {
					trait = zealous
					trait = humble
					has_character_flag = was_priest
				}
			}
			add_trait = nun
		}
		if = {
			limit = {
				is_female = no
				religion_group = christian
				OR = {
					trait = zealous
					trait = humble
					has_character_flag = was_priest
				}
			}
			add_trait = monk
		}
		if = {
			limit = {
				OR = {
					NOT = { religion_group = christian }
					NOR = {
						trait = zealous
						trait = humble
						has_character_flag = was_priest
					}
				}
			}
			add_trait = abdicated
		}
		clr_character_flag = was_priest
	}
	
	option = {
		name = "EVTOPTB_Plus_120"  #Reconsider
		clr_character_flag = considering_abdication
		ai_chance = {
			factor = 0
		}
	}
}

# Notify heir of abdication
character_event = {
	id = Plus.121
	picture = GFX_evt_council
	desc = "EVTDESC_Plus_121"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_Plus_121"
		opinion = {
			who = FROM
			modifier = abdicated_for_me
			years = 100
		}
		hidden_tooltip = {
			FROM = {
				transfer_scaled_wealth = { to = ROOT value = all }
				any_artifact = {
					transfer_artifact = {
						from = PREV
						to = ROOT
					}
				}
				banish = ROOT
			}
		}
	}
}

#######################################
# INFERTILITY
# Written by Rylock
#######################################

# Women who get sick have a chance of having fertility affected long-term
character_event = {
	id = Plus.125
	
	hide_window = yes
	
	min_age = 16
	max_age = 45
	only_women = yes
	is_sick = yes
	
	trigger = {
		NOT = { has_character_modifier = barren }
		NOT = { has_character_flag = is_barren }
	}
	
	mean_time_to_happen = {
		months = 600
		modifier = {
			factor = 1.5
			is_strong_trigger = yes
		}
		modifier = {
			factor = 0.5
			OR = {
				is_weak_trigger = yes
				trait = inbred
				NOT = { health = 4.1 }
			}
		}
		modifier = {
			factor = 0.5
			has_epidemic = yes
		}
		modifier = {
			factor = 0.5
			OR = {
				trait = ill
				trait = pneumonic
				trait = syphilitic
				trait = wounded				
			}
		}
		modifier = {
			factor = 0.75
			age = 30
		}
		modifier = {
			factor = 0.75
			age = 35
		}
	}
	
	immediate = {
		random_list = {
			30 = { }
			30 = {
				if = {
					limit = {
						NOT = { trait = infertile }
						NOT = { has_character_modifier = barren }
					}
					add_character_modifier = { # Temp Infertility
						name = infertile
						duration = 1825
					}
				}
			}
			30 = {
				if = {
					limit = { trait = infertile }
					remove_trait = infertile
					set_character_flag = is_barren
					add_character_modifier = {
						name = barren
						duration = -1
					}
				}
				if = {
					limit = {
						NOT = { trait = infertile }
						NOT = { has_character_modifier = barren }
					}
					add_trait = infertile
				}
			}
			10 = {
				if = {
					limit = {
						NOT = { has_character_modifier = barren }
					}
					remove_trait = infertile
					set_character_flag = is_barren
					add_character_modifier = {
						name = barren
						duration = -1
					}
				}
			}
		}
	}
}

# Woman is married and suspects she might be barren
character_event = {
	id = Plus.126
	picture = GFX_evt_recovery
	desc = EVTDESC_Plus_126
	
	min_age = 16
	max_age = 45
	only_women = yes
	prisoner = no
	capable_only = yes
	has_character_flag = is_barren
	
	trigger = {
		has_character_modifier = barren
		OR = {
			is_married = yes
			is_consort = yes
		}
		NOR = {
			num_of_children = 1
			trait = celibate
		}
		NOT = { has_character_flag = knows_barren }
	}
	
	mean_time_to_happen = {
		months = 60
		modifier = {
			factor = 2
			NOT = { age = 20 }
		}
		modifier = {
			factor = 2
			NOT = { age = 25 }
		}
		modifier = {
			factor = 0.75
			age = 30
		}
		modifier = {
			factor = 0.5
			spouse = { is_lover = ROOT }
		}
		modifier = {
			factor = 0.5
			is_smart_trigger = yes
		}
		modifier = {
			factor = 2
			is_dumb_trigger = yes
		}
	}

	immediate = {
		set_character_flag = knows_barren
	}
	
	option = {
		name = EVTOPTA_Plus_126 #I don't care about the risk
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.5
				trait = craven
			}
			modifier = {
				factor = 0.5
				trait = paranoid
			}
			modifier = {
				factor = 1.5
				trait = brave
			}
			modifier = {
				factor = 2
				spouse = { is_lover = ROOT }
			}
			modifier = {
				factor = 1.5
				spouse = { reverse_opinion = { who = ROOT value = 25 } }
			}
			modifier = {
				factor = 1.5
				spouse = { reverse_opinion = { who = ROOT value = 50 } }
			}
			modifier = {
				factor = 1.5
				spouse = { reverse_opinion = { who = ROOT value = 75 } }
			}
		}
		random_list = {
			40 = {}
			10 = {
				custom_tooltip = {
					text = REMOVE_BARREN_SUCCESS
					hidden_tooltip = {
						clr_character_flag = is_barren
						remove_character_modifier = barren
					}
				}
			}
			30 = {
				custom_tooltip = {
					text = REMOVE_BARREN_BUT_INFERTILE
					hidden_tooltip = {
						clr_character_flag = is_barren
						remove_character_modifier = barren
						add_trait = infertile
					}
				}
			}
			13 = {
				if = {
					limit = {
						NOT = { trait = wounded }
						can_be_maimed_trigger = yes
					}
					add_trait = wounded
					hidden_tooltip = {
						character_event = { id = 38280 days = 1 }
					}
				}
			}
			5 = {
				if = {
					limit = {
						NOT = { trait = wounded }
						can_be_maimed_trigger = yes
					}
					add_maimed_trait_effect = yes
					hidden_tooltip = {
						character_event = { id = 38281 days = 1 }
					}
				}
			}
			2 = {
				death = { death_reason = death_accident }
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_126 #I will put my faith in God
		trigger = {
			NOT = { trait = cynical }
			piety = 0
		}
		ai_chance = {
			factor = 30
			modifier = {
				factor = 2
				trait = zealous
			}
			modifier = {
				factor = 2
				trait = humble
			}
		}
		piety = 10
		random_list = {
			80 = {}
			5 = {
				custom_tooltip = {
					text = REMOVE_BARREN_SUCCESS
					hidden_tooltip = {
						clr_character_flag = is_barren
						remove_character_modifier = barren
					}
				}
			}
			15 = {
				custom_tooltip = {
					text = REMOVE_BARREN_BUT_INFERTILE
					hidden_tooltip = {
						clr_character_flag = is_barren
						remove_character_modifier = barren
						add_trait = infertile
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTC_Plus_126 #He will get no child from me
		ai_chance = {
			factor = 20
			modifier = {
				factor = 0.5
				trait = honest
			}
			modifier = {
				factor = 2
				trait = deceitful
			}
			modifier = {
				factor = 2
				trait = slothful
			}
			modifier = {
				factor = 3
				spouse = { is_rival = ROOT }
			}
			modifier = {
				factor = 1.5
				spouse = { NOT = { reverse_opinion = { who = ROOT value = 0 } } }
			}
			modifier = {
				factor = 1.5
				spouse = { NOT = { reverse_opinion = { who = ROOT value = -25 } } }
			}
			modifier = {
				factor = 2
				spouse = { NOT = { reverse_opinion = { who = ROOT value = -50 } } }
			}
		}
		if = {
			limit = {
				NOT = { trait = honest }
				NOT = { trait = deceitful }
			}
			random = {
				chance = 30
				add_trait = deceitful
				hidden_tooltip = {
					character_event = { id = 38255 days = 1 }
				}
			}
		}
		if = {
			limit = { trait = honest }
			random = {
				chance = 30
				remove_trait = honest
				
			}
		}
	}
}

# Husband suspects wife is barren
character_event = {
	id = Plus.127
	picture = GFX_evt_recovery
	desc = EVTDESC_Plus_127
	
	only_men = yes
	prisoner = no
	capable_only = yes
	only_rulers = yes
	max_age = 75
	is_married = yes
	
	trigger = {
		fertility = 0.1
		NOR = {
			is_dumb_trigger = yes
			trait = celibate
			trait = eunuch
		}
		any_spouse = {
			has_character_modifier = barren
			NOT = { any_child = { is_child_of = ROOT } }
			NOT = { has_character_flag = husband_knows_barren }
		}
	}
	
	mean_time_to_happen = {
		months = 120
		modifier = {
			factor = 0.75
			age = 30
		}
		modifier = {
			factor = 0.5
			any_spouse = { has_character_flag = knows_barren }
		}
		modifier = {
			factor = 0.5
			any_spouse = {
				is_lover = ROOT
				has_character_modifier = barren
			}
		}
		modifier = {
			factor = 0.5
			OR = {
				learning = 12
				is_smart_trigger = yes
			}
		}
	}

	immediate = {
		random_spouse = {
			limit = {
				has_character_modifier = barren
				NOT = { any_child = { is_child_of = ROOT } }
				NOT = { has_character_flag = husband_knows_barren }
			}
			save_event_target_as = barren_wife
		}
	}
	
	option = {
		name = EVTOPTA_Plus_127
		random_spouse = {
			limit = {
				has_character_modifier = barren
				NOT = { any_child = { is_child_of = ROOT } }
				NOT = { has_character_flag = husband_knows_barren }
			}
			set_character_flag = husband_knows_barren
			if = {
				limit = { is_lover = ROOT }
				remove_lover = ROOT
			}
			reverse_opinion = {
				who = ROOT
				modifier = knows_barren
				years = -1
			}
		}
	}
}

# Add barren modifier
character_event = {
	id = Plus.128
	
	hide_window = yes
	
	min_age = 16
	has_character_flag = is_barren
	
	trigger = {
		NOT = { has_character_modifier = barren }
		is_pregnant = no
		OR = {
			is_married = yes
			is_consort = yes
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		remove_trait = infertile
		add_character_modifier = {
			name = barren
			hidden = yes
			duration = -1
		}
	}
}
		
#######################################
# VASSAL ASKS FOR KING TITLE
# Written by Rylock
#######################################

# liege holds too many king titles in an uncentralized realm
character_event = {
	id = Plus.130
	desc = EVTDESC_Plus_130
	picture = GFX_evt_council
	
	only_playable = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	war = no
	
	trigger = {
		independent = no
		is_feudal = yes
		OR = {
			real_tier = DUKE
			AND = {
				real_tier = COUNT
				num_of_count_titles = 3
			}
		}
		# liege is an uncrowned or incapable king/emperor with at least three king titles & two counties
		liege = {
			OR = {
				trait = uncrowned
				trait = incapable
				AND = {
					prisoner = yes
					host = { character = ROOT }
				}
			}
			higher_real_tier_than = DUKE
			num_of_king_titles = 3
			num_of_count_titles = 2
			war = no
			religion = ROOT
			is_feudal = yes
		}
		OR = {
			trait = ambitious
			trait = envious
			NOT = { opinion = { who = liege value = -50 } }
		}
		NOR = {
			trait = content
			trait = craven
			trait = humble
			is_dumb_trigger = yes
			any_heir_title = { higher_tier_than = DUKE }
			any_demesne_title = { temporary = yes }
		}
		# the liege has a spare king title which does not have his capital
		# but has the duke's capital, and has low crown authority
		liege = {
			any_demesne_title = {
				tier = KING
				is_titular = no
				can_be_given_away = yes
				OR = {
					has_law = crown_authority_0
					has_law = crown_authority_1
				}
				PREV = {
					capital_scope = {
						kingdom = { NOT = { title = PREVPREVPREV } }
					}
				}
				ROOT = {
					capital_scope = {
						kingdom = { title = PREVPREVPREV }
					}
				}
			}
			NOR = {
				AND = {
					reverse_opinion = { who = ROOT value = 0 }
					real_tier = KING
				}
				AND = {
					reverse_opinion = { who = ROOT value = 25 }
					real_tier = EMPEROR
				}
				reverse_has_truce = ROOT
				has_non_aggression_pact_with = ROOT
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_coerced_into_leaving_faction }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated }
				reverse_has_opinion_modifier = { who = ROOT modifier = opinion_subjugated_other_rel }
				has_character_flag = king_title_demanded
			}
		}
		NOT = { has_character_flag = demanded_king_title }
	}
	
	mean_time_to_happen = {
		months = 6
		modifier = {
			factor = 0.5
			trait = ambitious
		}
		modifier = {
			factor = 0.75
			trait = envious
		}
		modifier = {
			factor = 1.5
			trait = kind
		}
		modifier = {
			factor = 1.5
			trait = charitable
		}
		modifier = {
			factor = 3
			NOT = { prestige = 100 }
		}
		modifier = {
			factor = 0.75
			prestige = 1000
		}
		modifier = {
			factor = 1.5
			liege = { NOT = { culture = ROOT } }
		}
		modifier = {
			factor = 0.5
			OR = {
				leads_faction = yes
				in_faction = faction_court
			}
		}
		modifier = {
			factor = 5
			NOT = { relative_power_to_liege = 0.1 }
		}
		modifier = {
			factor = 0.5
			relative_power_to_liege = 0.5
		}
		modifier = {
			factor = 0.5
			relative_power_to_liege = 1.0
		}
		modifier = {
			factor = 0.5
			liege = { num_of_king_titles = 4 }
		}
	}

	immediate = {
		set_character_flag = demanded_king_title
	}
	
	option = {
		name = EVTOPTA_Plus_130 # Make the demand
		liege = {
			log = "[Root.GetBestName] has demanded that [This.GetBestName] surrender a king-tier title, as [This.GetSheHe] has too many."
			set_character_flag = king_title_demanded
			character_event = { id = Plus.131 tooltip = demand_kingdom_title }
		}
	}
	option = {
		name = EVTOPTB_Plus_130 # No, leave it be
		trigger = { ai = no }
		if = {
			limit = { NOT = { trait = content } }
			random = {
				chance = 30
				add_trait = content
			}
		}
	}
}

# liege receives the demand for a king title
character_event = {
	id = Plus.131
	desc = EVTDESC_Plus_131
	picture = GFX_evt_emissary
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_131 # Give it to him
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.75
				NOT = { opinion = { who = FROM value = -25 } }
			}
			modifier = {
				factor = 0.75
				NOT = { opinion = { who = FROM value = -50 } }
			}
			modifier = {
				factor = 0.75
				NOT = { opinion = { who = FROM value = -75 } }
			}
			modifier = {
				factor = 1.5
				opinion = { who = FROM value = 25 }
			}
			modifier = {
				factor = 1.5
				opinion = { who = FROM value = 50 }
			}
			modifier = {
				factor = 1.5
				dynasty = FROM
			}
			modifier = {
				factor = 0.75
				NOT = { culture = FROM }
			}
			modifier = {
				factor = 0.5
				NOT = { culture_group = FROM }
			}
			modifier = {
				factor = 2
				NOT = { relative_power = { who = FROM power = 1.0 } }
			}
			modifier = {
				factor = 1.5
				NOT = { relative_power = { who = FROM power = 0.5 } }
			}
		}
		reverse_opinion = { who = FROM modifier = opinion_granted_kingdom years = 200 }
		prestige = -200
		random_demesne_title = {
			limit = {
				tier = KING
				is_titular = no
				can_be_given_away = yes
				OR = {
					has_law = crown_authority_0
					has_law = crown_authority_1
				}
				ROOT = {
					capital_scope = {
						kingdom = { NOT = { title = PREVPREVPREV } }
					}
				}
				FROM = {
					capital_scope = {
						kingdom = { title = PREVPREVPREV }
					}
					NOT = {
						any_heir_title = { title = PREVPREV }
					}
				}
			}
			log = "[Root.GetBestName] has agreed to surrender [This.GetFullName] to [From.GetBestName]."
			grant_title = FROM
			hidden_tooltip = {
				remove_claim = ROOT
				add_weak_pressed_claim = ROOT
				if = {
					limit = { ROOT = { tier = EMPEROR } }
					FROM = {
						set_defacto_liege = ROOT
						pf_liege_change_effect = yes
					}
				}
			}
		}
		if = {
			limit = { any_vassal = { leads_faction = faction_court } }
			custom_tooltip = { text = COURTFACTIONMOODPLUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_court } set_variable = { which = "faction_mood_increase" value = 4 } }
			}
		}
		if = {
			limit = { any_vassal = { leads_faction = faction_glory } }
			custom_tooltip = { text = GLORYFACTIONMOODPLUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_glory } set_variable = { which = "faction_mood_increase" value = 2 } }
			}
		}
		hidden_tooltip = { character_event = { id = PlusFaction.200 days = 1 } }
	}
	option = {
		name = EVTOPTB_Plus_131 # Give it to one of my children instead
		trigger = {
			NOT = {
				AND = {
					prisoner = yes
					host = { character = FROM }
				}
			}
			any_realm_character = {
				is_child_of = ROOT
				is_adult = yes
				NOT = { real_tier = KING }
				NOT = { character = FROM }
				NOT = { is_primary_heir = ROOT }
				OR = {
					AND = {
						is_female = no
						ROOT = { NOT = { has_law = enatic_cognatic_succession } }
						ROOT = { NOT = { has_law = enatic_succession } }
					}
					AND = {
						is_female = yes
						ROOT = { NOT = { has_law = cognatic_succession } }
						ROOT = { NOT = { has_law = agnatic_succession } }
					}
				}
			}
		}
		ai_chance = {
			factor = 200
		}
		prestige = -100
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.133 days = 3 } }
		}
		random_realm_character = {
			limit = {
				is_child_of = ROOT
				is_adult = yes
				NOT = { real_tier = KING }
				NOT = { character = FROM }
				NOT = { is_primary_heir = ROOT }
				OR = {
					AND = {
						is_female = no
						ROOT = { NOT = { has_law = enatic_cognatic_succession } }
						ROOT = { NOT = { has_law = enatic_succession } }
					}
					AND = {
						is_female = yes
						ROOT = { NOT = { has_law = cognatic_succession } }
						ROOT = { NOT = { has_law = agnatic_succession } }
					}
				}
			}
			hidden_tooltip = {
				reverse_opinion = { who = FROM modifier = jealous years = 20 }
			}
			opinion = { who = ROOT modifier = opinion_granted_kingdom years = 200 }
			ROOT = {
				random_demesne_title = {
					limit = {
						tier = KING
						is_titular = no
						can_be_given_away = yes
						OR = {
							has_law = crown_authority_0
							has_law = crown_authority_1
						}
						ROOT = {
							capital_scope = {
								kingdom = { NOT = { title = PREVPREVPREV } }
							}
						}
						FROM = {
							capital_scope = {
								kingdom = { title = PREVPREVPREV }
							}
							NOT = {
								any_heir_title = { title = PREVPREV }
							}
						}
					}
					hidden_tooltip = {
						if = {
							limit = {
								FROM = { NOT = { has_claim = PREV } }
							}
							add_claim = FROM
						}
					}
					log = "[Root.GetBestName] has granted [This.GetFullName] to [PrevPrev.GetBestName] instead."
					grant_title = PREVPREV
					hidden_tooltip = {
						remove_claim = ROOT
						add_weak_pressed_claim = ROOT
					}
				}
			}
			if = {
				limit = { ROOT = { tier = EMPEROR } }
				set_defacto_liege = ROOT
				pf_liege_change_effect = yes
			}
		}
		if = {
			limit = { any_vassal = { leads_faction = faction_court } }
			custom_tooltip = { text = COURTFACTIONMOODPLUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_court } set_variable = { which = "faction_mood_increase" value = 2 } }
			}
		}
		if = {
			limit = { any_vassal = { leads_faction = faction_glory } }
			custom_tooltip = { text = GLORYFACTIONMOODPLUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_glory } set_variable = { which = "faction_mood_increase" value = 2 } }
			}
		}
		hidden_tooltip = { character_event = { id = PlusFaction.200 days = 1 } }
	}
	option = {
		name = EVTOPTC_Plus_131 # Give it to someone in line for the title
		trigger = {
			NOT = {
				AND = {
					prisoner = yes
					host = { character = FROM }
				}
			}
			any_demesne_title = {
				tier = KING
				is_titular = no
				can_be_given_away = yes
				OR = {
					has_law = crown_authority_0
					has_law = crown_authority_1
				}
				ROOT = {
					capital_scope = {
						kingdom = { NOT = { title = PREVPREVPREV } }
					}
				}
				FROM = {
					capital_scope = {
						kingdom = { title = PREVPREVPREV }
					}
					NOT = {
						any_heir_title = { title = PREVPREV }
					}
				}
				NOT = {
					any_claimant = {
						is_adult = yes
						same_realm = ROOT
						has_strong_claim = PREV
						NOR = {
							real_tier = KING
							is_child_of = ROOT
							character = FROM
							is_primary_heir = ROOT
						}
					}
				}
				ROOT = {
					any_realm_character = {
						is_adult = yes
						NOR = {
							real_tier = KING
							is_child_of = ROOT
							character = FROM
							is_primary_heir = ROOT
						}
						any_pretender_title = { title = PREVPREVPREV }
					}
				}
			}
		}
		ai_chance = {
			factor = 50
		}
		prestige = -200
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.133 days = 3 } }
		}
		random_realm_character = {
			limit = {
				is_adult = yes
				NOR = {
					real_tier = KING
					is_child_of = ROOT
					character = FROM
					is_primary_heir = ROOT
				}
				any_pretender_title = {
					holder = ROOT
					tier = KING
					is_titular = no
					can_be_given_away = yes
					OR = {
						has_law = crown_authority_0
						has_law = crown_authority_1
					}
					ROOT = {
						capital_scope = {
							kingdom = { NOT = { title = PREVPREVPREV } }
						}
					}
					FROM = {
						capital_scope = {
							kingdom = { title = PREVPREVPREV }
						}
						NOT = {
							any_heir_title = { title = PREVPREV }
						}
					}
					NOT = {
						any_claimant = {
							is_adult = yes
							same_realm = ROOT
							has_strong_claim = PREV
							NOR = {
								real_tier = KING
								is_child_of = ROOT
								character = FROM
								is_primary_heir = ROOT
							}
						}
					}
				}
			}
			hidden_tooltip = {
				reverse_opinion = { who = FROM modifier = jealous years = 20 }
			}
			opinion = { who = ROOT modifier = opinion_granted_kingdom years = 200 }
			ROOT = {
				random_demesne_title = {
					limit = {
						tier = KING
						is_titular = no
						can_be_given_away = yes
						OR = {
							has_law = crown_authority_0
							has_law = crown_authority_1
						}
						ROOT = {
							capital_scope = {
								kingdom = { NOT = { title = PREVPREVPREV } }
							}
						}
						FROM = {
							capital_scope = {
								kingdom = { title = PREVPREVPREV }
							}
							NOT = {
								any_heir_title = { title = PREVPREV }
							}
						}
					}
					hidden_tooltip = {
						if = {
							limit = {
								FROM = { NOT = { has_claim = PREV } }
							}
							add_claim = FROM
						}
					}
					log = "[Root.GetBestName] has granted [This.GetFullName] to [PrevPrev.GetBestName] instead."
					grant_title = PREVPREV
					hidden_tooltip = {
						remove_claim = ROOT
						add_weak_pressed_claim = ROOT
					}
				}
			}
			if = {
				limit = { ROOT = { tier = EMPEROR } }
				set_defacto_liege = ROOT
				pf_liege_change_effect = yes
			}
		}
		if = {
			limit = { any_vassal = { leads_faction = faction_court } }
			custom_tooltip = { text = COURTFACTIONMOODPLUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_court } set_variable = { which = "faction_mood_increase" value = 2 } }
			}
		}
		if = {
			limit = { any_vassal = { leads_faction = faction_glory } }
			custom_tooltip = { text = GLORYFACTIONMOODPLUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_glory } set_variable = { which = "faction_mood_increase" value = 2 } }
			}
		}
		hidden_tooltip = { character_event = { id = PlusFaction.200 days = 1 } }
	}
	option = {
		name = EVTOPTD_Plus_131 # Give it to a claimant
		trigger = {
			NOT = {
				AND = {
					prisoner = yes
					host = { character = FROM }
				}
			}
			any_demesne_title = {
				tier = KING
				is_titular = no
				can_be_given_away = yes
				OR = {
					has_law = crown_authority_0
					has_law = crown_authority_1
				}
				ROOT = {
					capital_scope = {
						kingdom = { NOT = { title = PREVPREVPREV } }
					}
				}
				FROM = {
					capital_scope = {
						kingdom = { title = PREVPREVPREV }
					}
					NOT = {
						any_heir_title = { title = PREVPREV }
					}
				}
				any_claimant = {
					is_adult = yes
					same_realm = ROOT
					has_strong_claim = PREV
					NOR = {
						real_tier = KING
						is_child_of = ROOT
						character = FROM
						is_primary_heir = ROOT
					}
				}
			}
		}
		ai_chance = {
			factor = 100
		}
		prestige = -200
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.133 days = 3 } }
		}
		random_realm_character = {
			limit = {
				is_adult = yes
				NOR = {
					real_tier = KING
					is_child_of = ROOT
					character = FROM
					is_primary_heir = ROOT
				}
				any_claim = {
					holder = ROOT
					tier = KING
					is_titular = no
					can_be_given_away = yes
					any_claimant = {
						character = PREVPREV
						has_strong_claim = PREV
					}
					OR = {
						has_law = crown_authority_0
						has_law = crown_authority_1
					}
					ROOT = {
						capital_scope = {
							kingdom = { NOT = { title = PREVPREVPREV } }
						}
					}
					FROM = {
						capital_scope = {
							kingdom = { title = PREVPREVPREV }
						}
						NOT = {
							any_heir_title = { title = PREVPREV }
						}
					}
				}
			}
			hidden_tooltip = {
				reverse_opinion = { who = FROM modifier = jealous years = 20 }
			}
			opinion = { who = ROOT modifier = opinion_granted_kingdom years = 200 }
			ROOT = {
				random_demesne_title = {
					limit = {
						tier = KING
						is_titular = no
						can_be_given_away = yes
						OR = {
							has_law = crown_authority_0
							has_law = crown_authority_1
						}
						ROOT = {
							capital_scope = {
								kingdom = { NOT = { title = PREVPREVPREV } }
							}
						}
						FROM = {
							capital_scope = {
								kingdom = { title = PREVPREVPREV }
							}
							NOT = {
								any_heir_title = { title = PREVPREV }
							}
						}
					}
					hidden_tooltip = {
						if = {
							limit = {
								FROM = { NOT = { has_claim = PREV } }
							}
							add_claim = FROM
						}
					}
					log = "[Root.GetBestName] has granted [This.GetFullName] to [PrevPrev.GetBestName] instead."
					grant_title = PREVPREV
					hidden_tooltip = {
						remove_claim = ROOT
						add_weak_pressed_claim = ROOT
					}
				}
			}
			if = {
				limit = { ROOT = { tier = EMPEROR } }
				set_defacto_liege = ROOT
				pf_liege_change_effect = yes
			}
		}
		if = {
			limit = { any_vassal = { leads_faction = faction_court } }
			custom_tooltip = { text = COURTFACTIONMOODPLUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_court } set_variable = { which = "faction_mood_increase" value = 2 } }
			}
		}
		if = {
			limit = { any_vassal = { leads_faction = faction_glory } }
			custom_tooltip = { text = GLORYFACTIONMOODPLUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_glory } set_variable = { which = "faction_mood_increase" value = 2 } }
			}
		}
		hidden_tooltip = { character_event = { id = PlusFaction.200 days = 1 } }
	}
	option = {
		name = EVTOPTE_Plus_131 # Never! The title is mine!
		trigger = {
			NOR = {
				trait = incapable
				AND = {
					prisoner = yes
					host = { character = FROM }
				}
			}
		}
		ai_chance = {
			factor = 100
			modifier = {
				factor = 4
				real_tier = KING
			}
			modifier = {
				factor = 0.5
				num_of_king_titles = 4
			}
			modifier = {
				factor = 0.5
				num_of_king_titles = 5
			}
			modifier = {
				factor = 10
				trait = ambitious
			}
			modifier = {
				factor = 5
				trait = greedy
			}
			modifier = {
				factor = 3
				trait = proud
			}
			modifier = {
				factor = 0.5
				trait = content
			}
			modifier = {
				factor = 0.5
				trait = humble
			}
			modifier = {
				factor = 0.5
				trait = charitable
			}
			modifier = {
				factor = 0.5
				trait = craven
			}
			modifier = {
				factor = 0
				has_regent = yes
			}
		}
		log = "[Root.GetBestName] has refused the demand from [From.GetBestName] for a kingdom."
		FROM = { letter_event = { id = Plus.132 days = 3 tooltip = refuse_kingdom_title } }
		if = {
			limit = { any_vassal = { leads_faction = faction_court } }
			custom_tooltip = { text = COURTFACTIONMOODMINUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_court } set_variable = { which = "faction_mood_decrease" value = 2 } }
			}
		}
		if = {
			limit = { any_vassal = { leads_faction = faction_glory } }
			custom_tooltip = { text = GLORYFACTIONMOODMINUS }
			hidden_tooltip = {
				random_vassal = { limit = { leads_faction = faction_glory } set_variable = { which = "faction_mood_decrease" value = 2 } }
			}
		}
		hidden_tooltip = { character_event = { id = PlusFaction.200 days = 1 } }
	}
}

# liege has refused to give up the title at all
letter_event = {
	id = Plus.132
	desc = EVTDESC_Plus_132
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_132
		opinion = {
			who = FROM
			modifier = opinion_denied_title
			years = 20
		}
		FROM = {
			random_demesne_title = {
				limit = {
					tier = KING
					is_titular = no
					can_be_given_away = yes
					OR = {
						has_law = crown_authority_0
						has_law = crown_authority_1
					}
					FROM = {
						capital_scope = {
							kingdom = { NOT = { title = PREVPREVPREV } }
						}
					}
					ROOT = {
						capital_scope = {
							kingdom = { title = PREVPREVPREV }
						}
						NOT = {
							any_heir_title = { title = PREVPREV }
						}
					}
				}
				add_pressed_claim = ROOT
			}
			any_vassal = {
				limit = {
					likes_better_than = { who = ROOT than = FROM }
					NOR = {
						character = ROOT
						is_primary_heir = FROM
						has_regent = yes
					}
				}
				opinion = {
					who = FROM
					modifier = refused_to_give_up_title
					months = 60
				}
				opinion = {
					who = ROOT
					modifier = sympathetic_to_cause
					months = 60
				}
			}
		}
	}
}

# liege gave the title to someone else
letter_event = {
	id = Plus.133
	desc = EVTDESC_Plus_133
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_133
		opinion = {
			who = FROM
			modifier = opinion_denied_title
			months = 60
		}
	}
}

#######################################
# ANTIPOPE EVENTS
# Written by Rylock
#######################################

# vassal reacts to the antipope
character_event = {
	id = Plus.135
	desc = EVTDESC_Plus_135
	picture = GFX_evt_pope_feast
	border = GFX_event_normal_frame_religion
	
	only_rulers = yes
	religion_group = christian
	min_age = 16
	capable_only = yes
	prisoner = no
	
	trigger = {
		independent = no
		OR = {
			religion = catholic
			religion = fraticelli
		}
		liege = {
			independent = yes
			religion = ROOT
			NOT = { character = ROOT }
			rightful_religious_head_scope = {
				is_liege_or_above = PREV
				NOT = { character = ROOT }
				OR = {
					has_claim = k_papal_state
					has_claim = d_fraticelli
				}
			}
		}
		religion_head = {
			religion = ROOT
		}
		NOT = {
			has_character_flag = took_sides_antipope
		}
	}
	
	mean_time_to_happen = {
		days = 10
	}
	
	immediate = {
		set_character_flag = took_sides_antipope
	}
	
	option = {
		name = EVTOPTA_Plus_135 # I support my liege
		trigger = {
			NOT = { in_faction = faction_antiking }
			NOT = { leads_faction = faction_antiking }
		}
		ai_chance = {
			factor = 40
			modifier = {
				factor = 0
				rightful_religious_head_scope = {
					ROOT = { excommunicated_for = PREV }
				}
			}
			modifier = {
				factor = 0
				religion_head = { is_friend = ROOT }
			}
			modifier = {
				factor = 0.1
				rightful_religious_head_scope = { is_rival = ROOT }
			}
			modifier = {
				factor = 0.5
				trait = cynical
			}
			modifier = {
				factor = 0.5
				trait = zealous
			}
			modifier = {
				factor = 0.5
				religion_head = {
					ROOT = {
						liege = {
							ROOT = {
								likes_better_than = { who = PREVPREVPREV than = PREV }
							}
						}
					}
				}
			}
			modifier = {
				factor = 2
				religion_head = {
					ROOT = {
						liege = {
							ROOT = {
								likes_better_than = { who = PREV than = PREVPREVPREV }
							}
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				religion_head = {
					ROOT = {
						opinion_diff = { first = liege second = PREV value = 25 }
					}
				}
			}
			modifier = {
				factor = 1.5
				religion_head = {
					ROOT = {
						opinion_diff = { first = liege second = PREV value = 50 }
					}
				}
			}
			modifier = {
				factor = 1.5
				religion_head = {
					ROOT = {
						opinion_diff = { first = liege second = PREV value = 75 }
					}
				}
			}
		}
		set_character_flag = supports_the_antipope
		religion_head = {
			opinion = {
				who = ROOT
				modifier = opinion_supports_antipope
				months = 240
			}
			reverse_opinion = {
				who = ROOT
				modifier = opinion_supports_antipope
				months = 240
			}
		}
		rightful_religious_head_scope = {
			opinion = {
				who = ROOT
				modifier = opinion_supports_me_antipope
				months = 240
			}
			reverse_opinion = {
				who = ROOT
				modifier = opinion_supports_me_antipope
				months = 240
			}
		}
		liege = {
			opinion = {
				who = ROOT
				modifier = opinion_supports_me_antipope
				months = 120
			}
			reverse_opinion = {
				who = ROOT
				modifier = opinion_supports_me_antipope
				months = 120
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_135 # I support the pope
		ai_chance = {
			factor = 40
			modifier = {
				factor = 0
				religion_head = { is_rival = ROOT }
			}
			modifier = {
				factor = 0.1
				rightful_religious_head_scope = { is_friend = ROOT }
			}
			modifier = {
				factor = 0
				religion_head = {
					ROOT = { excommunicated_for = PREV }
				}
			}
			modifier = {
				factor = 0.1
				liege = { current_heir = { character = ROOT } }
			}
			modifier = {
				factor = 0.5
				liege = { is_close_relative = ROOT }
			}
			modifier = {
				factor = 0.5
				trait = cynical
			}
			modifier = {
				factor = 2
				trait = zealous
			}
			modifier = {
				factor = 2
				religion_head = {
					ROOT = {
						liege = {
							ROOT = {
								likes_better_than = { who = PREVPREVPREV than = PREV }
							}
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				religion_head = {
					ROOT = {
						liege = {
							ROOT = {
								likes_better_than = { who = PREV than = PREVPREVPREV }
							}
						}
					}
				}
			}
			modifier = {
				factor = 1.5
				religion_head = {
					ROOT = {
						opinion_diff = { first = PREV second = liege value = 25 }
					}
				}
			}
			modifier = {
				factor = 1.5
				religion_head = {
					ROOT = {
						opinion_diff = { first = PREV second = liege value = 50 }
					}
				}
			}
			modifier = {
				factor = 1.5
				religion_head = {
					ROOT = {
						opinion_diff = { first = PREV second = liege value = 75 }
					}
				}
			}
		}
		set_character_flag = opposes_the_antipope
		religion_head = {
			opinion = {
				who = ROOT
				modifier = opinion_opposes_antipope
				months = 240
			}
			reverse_opinion = {
				who = ROOT
				modifier = opinion_opposes_antipope
				months = 240
			}
		}
		rightful_religious_head_scope = {
			opinion = {
				who = ROOT
				modifier = opinion_opposes_me_antipope
				months = 240
			}
			reverse_opinion = {
				who = ROOT
				modifier = opinion_opposes_me_antipope
				months = 240
			}
		}
		liege = {
			opinion = {
				who = ROOT
				modifier = opinion_opposes_me_antipope
				months = 120
			}
			reverse_opinion = {
				who = ROOT
				modifier = opinion_opposes_me_antipope
				months = 120
			}
		}
	}
	option = {
		name = EVTOPTC_Plus_135 # I have no interest in this conflict
		trigger = {
			NOT = { in_faction = faction_antiking }
			NOT = { leads_faction = faction_antiking }
		}
		ai_chance = {
			factor = 20
			modifier = {
				factor = 4
				trait = cynical
			}
			modifier = {
				factor = 2
				trait = content
			}
			modifier = {
				factor = 0.5
				trait = ambitious
			}
			modifier = {
				factor = 2
				OR = {
					is_patrician = yes
					is_republic = yes
					is_merchant_republic = yes
				}
			}
			modifier = {
				factor = 0
				OR = {
					trait = zealous
					is_priest = yes
					is_theocracy = yes
				}
			}
		}
		religion_head = {
			opinion = {
				who = ROOT
				modifier = opinion_neutral_antipope
				months = 240
			}
		}
	}
}

#######################################
# TANIST/FEUDAL ELECTIVE CLAIMS
# Written by Rylock
#######################################

# Ruler with Tanist succession dies without heir being a child
character_event = {
	id = Plus.136
	
	hide_window = yes
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		num_of_children = 1
		any_demesne_title = {
			has_law = succ_tanistry
			current_heir = { NOT = { is_child_of = ROOT } }
		}
	}
	
	immediate = {
		any_demesne_title = {
			limit = {
				has_law = succ_tanistry
				current_heir = { NOT = { is_child_of = ROOT } }
			}
			save_event_target_as = rightful_tanist_title
			if = {
				limit = {
					has_law = true_cognatic_succession
				}
				ROOT = {
					random_child = {
						limit = {
							NOT = { trait = bastard }
							NOT = {
								any_sibling = {
									NOT = { trait = bastard }
									is_older_than = PREV
								}
							}
						}
						character_event = { id = Plus.137 days = 3 }
					}
				}
			}
			if = {
				limit = {
					NOR = {
						has_law = enatic_succession
						has_law = enatic_cognatic_succession
						has_law = true_cognatic_succession
					}
				}
				ROOT = {
					random_child = {
						limit = {
							is_female = no
							NOT = { trait = bastard }
							NOT = {
								any_sibling = {
									is_female = no
									NOT = { trait = bastard }
									is_older_than = PREV
								}
							}
						}
						character_event = { id = Plus.137 days = 3 }
					}
				}
			}
			if = {
				limit = {
					OR = {
						has_law = enatic_succession
						has_law = enatic_cognatic_succession
					}
				}
				ROOT = {
					random_child = {
						limit = {
							is_female = yes
							NOT = { trait = bastard }
							NOT = {
								any_sibling = {
									is_female = yes
									NOT = { trait = bastard }
									is_older_than = PREV
								}
							}
						}
						character_event = { id = Plus.137 days = 3 }
					}
				}
			}
		}
	}
}

# Child gets a strong claim to Tanist titles
character_event = {
	id = Plus.137
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		set_character_flag = justified_claimant
		event_target:rightful_tanist_title = { add_pressed_claim = ROOT }
	}
}

# Ruler with Feudal Elective succession dies
character_event = {
	id = Plus.138
	
	hide_window = yes
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		any_demesne_title = {
			has_law = succ_feudal_elective
		}
	}
	
	immediate = {
		any_demesne_title = {
			limit = {
				has_law = succ_feudal_elective
				current_heir = { NOT = { is_child_of = ROOT } }
			}
			save_event_target_as = rightful_elective_title
			if = {
				limit = {
					has_law = true_cognatic_succession
				}
				ROOT = {
					random_child = {
						limit = {
							NOT = { trait = bastard }
							NOT = {
								any_sibling = {
									NOT = { trait = bastard }
									is_older_than = PREV
								}
							}
						}
						set_character_flag = justified_claimant
					}
				}
			}
			if = {
				limit = {
					NOR = {
						has_law = enatic_succession
						has_law = enatic_cognatic_succession
						has_law = true_cognatic_succession
					}
				}
				ROOT = {
					random_child = {
						limit = {
							is_female = no
							NOT = { trait = bastard }
							NOT = {
								any_sibling = {
									is_female = no
									NOT = { trait = bastard }
									is_older_than = PREV
								}
							}
						}
						set_character_flag = justified_claimant
					}
				}
			}
			if = {
				limit = {
					OR = {
						has_law = enatic_succession
						has_law = enatic_cognatic_succession
					}
				}
				ROOT = {
					random_child = {
						limit = {
							is_female = yes
							NOT = { trait = bastard }
							NOT = {
								any_sibling = {
									is_female = yes
									NOT = { trait = bastard }
									is_older_than = PREV
								}
							}
						}
						set_character_flag = justified_claimant
					}
				}
			}
		}
		any_demesne_title = {
			limit = {
				has_law = succ_feudal_elective
			}
			save_event_target_as = rightful_elective_title
			ROOT = {
				any_realm_character = {
					limit = { any_pretender_title = { title = event_target:rightful_elective_title } }
					character_event = { id = Plus.139 days = 3 }
				}
				any_independent_ruler = {
					limit = { NOT = { same_realm = ROOT } }
					if = {
						limit = { any_pretender_title = { title = event_target:rightful_elective_title } }
						character_event = { id = Plus.139 days = 3 }
					}
					any_realm_character = {
						limit = { any_pretender_title = { title = event_target:rightful_elective_title } }
						character_event = { id = Plus.139 days = 3 }
					}
				}
			}
		}
	}
}

# Pretenders get a weak non-inheritable claim to Feudal Elective titles
character_event = {
	id = Plus.139
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		set_character_flag = justified_claimant
		if = {
			limit = {
				event_target:rightful_elective_title = {
					ROOT = { NOT = { has_claim = PREV } }
				}
			}
			event_target:rightful_elective_title = {
				add_weak_claim = ROOT
			}
		}
	}
}

#######################################
# AI DIVORCE EVENTS
# Written by Rylock
#######################################

# Spouse informed of divorce
character_event = {
	id = Plus.140
	desc = EVTDESC_Plus_140
	picture = GFX_evt_quarrel
	
	is_triggered_only = yes
	
	immediate = {
		FROMFROM = { save_event_target_as = target_sender }
	}
	
	option = {
		name = {
			trigger = { FROMFROM = { is_female = yes } }
			text = EVTOPTA_Plus_140
		}
		name = {
			trigger = { FROMFROM = { is_female = no } }
			text = EVTOPTB_Plus_140
		}
		log = "[FromFrom.GetTitledName] divorces [Root.GetTitledName]."
		remove_spouse = FROMFROM
		prestige = -100
		opinion = {
			who = event_target:target_sender
			modifier = opinion_divorced
		}
		any_dynasty_member = {
			limit = {
				is_close_relative = ROOT
				NOT = { character = event_target:target_sender }
			}
			opinion = {
				who = event_target:target_sender
				modifier = opinion_divorced_relative
			}
			character_event = { id = Plus.141 days = 1 }
		}
		clear_event_target = target_sender 
	}
}

# Close Relatives informed of divorce
character_event = {
	id = Plus.141
	desc = EVTDESC_Plus_141
	picture = GFX_evt_quarrel
	
	is_triggered_only = yes

	option = {
		name = I_SEE
	}
}

#######################################
# CADET EVENTS
# Written by Rylock
#######################################

# Children informed of new cadet branch
character_event = {
	id = Plus.142
	desc = EVTDESC_Plus_142
	picture = GFX_evt_recieve_letter
	
	is_triggered_only = yes
	
	option = {
		name = OK
		hidden_tooltip = {
			if = {
				limit = { ai = no }
				chronicle = {
					entry = CHRONICLE_CADET_BRANCH_FORMED
					portrait = [FROM.GetID]
					picture = GFX_evt_coronation
				}
			}
		}
		dynasty = FROM
	}
}

# Dynasty members informed of new cadet branch
character_event = {
	id = Plus.143
	desc = EVTDESC_Plus_143
	picture = GFX_evt_recieve_letter
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { dynasty = FROM }
	}
	
	option = {
		name = OK
		if = {
			limit = {
				ai = no
				NOT = { has_character_flag = no_chronicle_update }
			}
			chronicle = {
				entry = CHRONICLE_CADET_BRANCH_FORMED
				portrait = [FROM.GetID]
				picture = GFX_evt_coronation
			}
		}
		if = {
			limit = { has_character_flag = no_chronicle_update }
			clr_character_flag = no_chronicle_update
		}
		opinion = {
			who = FROM
			modifier = opinion_abandoned_dynasty
			years = 20
		}
	}
}

# New cadet branch started
character_event = {
	id = Plus.144
	desc = EVTDESC_Plus_144
	picture = GFX_evt_coronation
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_144
	}
}

# New dynasty declared by Muslim, breaking away from decadent dynasty
character_event = {
	id = Plus.145
	desc = EVTDESC_Plus_145
	picture = GFX_evt_coronation
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_144
	}
}

# New dynasty declared by high ranking ruler
character_event = {
	id = Plus.146
	desc = EVTDESC_Plus_146
	picture = GFX_evt_coronation
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_144
	}
}

### Inherited kingdom is destroyed if no de jure land is controlled
character_event = {
	id = Plus.1750
	
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		FROM = {
			tier = KING
			is_titular = no
			is_primary_type_title = no
			is_landless_type_title = no
		}
		OR = {
			lower_tier_than = EMPEROR
			has_global_flag = vanilla_empires
		}
		has_game_rule = {
			name = de_jure_requirement
			value = required
		}
	}
	
	immediate = {
		character_event = { id = Plus.1751 days = 2 }
	}
}
	
character_event = {
	id = Plus.1751
	desc = EVTDESC_Plus_1751
	title = EVTNAME_Plus_1751
	picture = GFX_evt_coronation
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	major = yes	
	
	trigger = {
		pf_war_flag_trigger = no
		pf_war_trait_trigger = no
		has_landed_title = FROMFROM
		FROMFROM = { is_contested = no }
		NOT = {
			any_realm_title = {
				higher_tier_than = BARON
				de_jure_liege_or_above = FROMFROM
			}
		}
	}
	
	major_trigger = {
		OR = {
			character = ROOT
			is_close_relative = ROOT
			has_claim = FROMFROM
			any_realm_title = { de_jure_liege_or_above = FROMFROM }
			same_realm = ROOT
			NOT = { distance = { who = ROOT distance = 300 } }
		}
	}
	
	option = {
		name = EVTOPTA_Plus_1751
		log = "The [FromFrom.GetFullName] has been destroyed after being inherited by [Root.GetTitledName], who owns no land in [FromFrom.GetName]."
		trigger = { character = ROOT }
		FROMFROM = { destroy_landed_title = yes }
	}
	option = {
		name = OK
		trigger = { NOT = { character = ROOT } }
	}
}

### Warning event for ironman games
character_event = {
	id = Plus.1752
	title = EVTNAME_Plus_1752
	desc = EVTDESC_Plus_1752
	picture = GFX_evt_book_carolingian_script
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_1752
	}
}

#######################################
# ANTI-BORDER GORE EVENTS
# Written by Rylock
#######################################

# Ruler returned a county they should not have been granted
character_event = {
	id = Plus.1755
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		#grant the county to a neighbor, if possible
		event_target:new_title = {
			location = {
				random_neighbor_province = {
					limit = {
						owner = {
							in_revolt = no
							vassal_of = ROOT
							religion = ROOT
							culture_group = ROOT
							prisoner = no
							opinion = { who = ROOT value = -25 }
							reverse_opinion = { who = ROOT value = -25 }
							NOR = {
								relative_power = { who = ROOT power = 1.0 }
								is_rival = ROOT
								trait = incapable
							}
						}
					}
					owner = {
						save_event_target_as = new_owner
						log = "---> [new_title.GetFullName] granted to [new_owner.GetBestName], a neighboring province owner."
						event_target:new_title = { grant_title = event_target:new_owner }
						set_defacto_liege = ROOT
					}
					break = yes
				}
			}
		}
		#grant_title to an appropriate adult dynasty member, if possible
		top_liege = {
			random_realm_character = {
				limit = {
					is_ruler = no
					prisoner = no
					opinion = { who = ROOT value = -25 }
					reverse_opinion = { who = ROOT value = -25 }
					is_liege_or_above = ROOT
					NOR = {
						is_rival = ROOT
						trait = incapable
						age = 50
					}
					is_adult = yes
					OR = {
						dynasty = ROOT
						is_close_relative = ROOT
					}
					OR = {
						fertility = 0.1
						num_of_children = 1
					}
					OR = {
						event_target:new_title = { has_law = true_cognatic_succession }
						AND = {
							is_female = no
							event_target:new_title = {
								NOT = { has_law = enatic_succession }
								NOT = { has_law = enatic_cognatic_succession }
							}
						}
						AND = {
							is_female = yes
							event_target:new_title = {
								NOT = { has_law = agnatic_succession }
								NOT = { has_law = cognatic_succession }
							}
						}
					}
				}
				save_event_target_as = new_owner
				log = "---> [new_title.GetFullName] granted to [new_owner.GetBestName], an adult dynasty member."
				event_target:new_title = { grant_title = event_target:new_owner }
				set_defacto_liege = ROOT
				break = yes
			}
		}
		
		#grant_title to an appropriate child, if possible
		top_liege = {
			random_realm_character = {
				limit = {
					is_ruler = no
					prisoner = no
					opinion = { who = ROOT value = -25 }
					reverse_opinion = { who = ROOT value = -25 }
					is_liege_or_above = ROOT
					NOR = {
						is_rival = ROOT
						trait = incapable
						age = 50
					}
					OR = {
						is_child_of = ROOT
						father_even_if_dead = { is_child_of = ROOT }
						mother_even_if_dead = { is_child_of = ROOT }
					}
					OR = {
						fertility = 0.1
						num_of_children = 1
					}
					OR = {
						event_target:new_title = { has_law = true_cognatic_succession }
						AND = {
							is_female = no
							event_target:new_title = {
								NOT = { has_law = enatic_succession }
								NOT = { has_law = enatic_cognatic_succession }
							}
						}
						AND = {
							is_female = yes
							event_target:new_title = {
								NOT = { has_law = agnatic_succession }
								NOT = { has_law = cognatic_succession }
							}
						}
					}
				}
				save_event_target_as = new_owner
				log = "---> [new_title.GetFullName] granted to [new_owner.GetBestName], a child relative."
				event_target:new_title = { grant_title = event_target:new_owner }
				set_defacto_liege = ROOT
				break = yes
			}
		}
		
		#grant title to an appropriate courtier, if possible
		random_courtier = {
			limit = {
				is_ruler = no
				prisoner = no
				opinion = { who = ROOT value = 0 }
				reverse_opinion = { who = ROOT value = 0 }
				NOR = {
					is_rival = ROOT
					trait = incapable
				}
				OR = {
					is_councillor = yes
					martial = 8
					diplomacy = 8
					intrigue = 8
					stewardship = 8
				}
				OR = {
					fertility = 0.1
					num_of_children = 1
				}
				OR = {
					event_target:new_title = { has_law = true_cognatic_succession }
					AND = {
						is_female = no
						event_target:new_title = {
							NOT = { has_law = enatic_succession }
							NOT = { has_law = enatic_cognatic_succession }
						}
					}
					AND = {
						is_female = yes
						event_target:new_title = {
							NOT = { has_law = agnatic_succession }
							NOT = { has_law = cognatic_succession }
						}
					}
				}
			}
			save_event_target_as = new_owner
			log = "---> [new_title.GetFullName] granted to [new_owner.GetBestName], a capable courtier."
			event_target:new_title = { grant_title = event_target:new_owner }
			set_defacto_liege = ROOT
			break = yes
		}
		
		#create new character
		create_character = {
			random_traits = yes
			dynasty = random
			female = no
			religion = ROOT
			culture = ROOT
		}
		new_character = {
			save_event_target_as = new_owner
			log = "---> [new_title.GetFullName] granted to [new_owner.GetBestName], a new character."
			event_target:new_title = { grant_title = event_target:new_owner }
			set_defacto_liege = ROOT
		}
	}
}

# AI vassal has a vassal too far away
character_event = {
	id = Plus.1757
	
	is_triggered_only = yes
	hide_window = yes
	only_playable = yes
	only_rulers = yes
	ai = yes
	war = no
	
	trigger = {
		higher_real_tier_than = COUNT
		independent = no
		#both my liege and I can't be involved in a war or revolt
		pf_war_trait_trigger = no
		pf_war_flag_trigger = no
		liege = {
			ai = yes
			war = no
		}
		NOT = { any_liege = { pf_war_flag_trigger = yes } }
		NOT = { any_liege = { pf_war_trait_trigger = yes } }
		#has a vassal who holds a county too far away from mine and is not a de jure vassal of mine
		any_vassal = {
			num_of_count_titles = 1
			war = no
			pf_war_trait_trigger = no
			NOT = {
				any_demesne_title = {
					tier = COUNT
					location = {
						OR = {
							duchy = { holder = ROOT }
							kingdom = { holder = ROOT }
							any_neighbor_province = { owner = { character = ROOT } }
							ROOT = {
								any_demesne_title = {
									tier = COUNT
									location = {
										NOT = { distance = { where = PREVPREVPREV value = 100 } }
									}
								}
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		save_event_target_as = old_liege
		liege = { save_event_target_as = current_liege }
		random_vassal = {
			limit = {
				num_of_count_titles = 1
				war = no
				pf_war_trait_trigger = no
				NOT = {
					any_demesne_title = {
						tier = COUNT
						location = {
							OR = {
								duchy = { holder = ROOT }
								kingdom = { holder = ROOT }
								any_neighbor_province = { owner = { character = ROOT } }
								ROOT = {
									any_demesne_title = {
										tier = COUNT
										location = {
											NOT = { distance = { where = PREVPREVPREV value = 100 } }
										}
									}
								}
							}
						}
					}
				}
			}
			save_event_target_as = reassigned_vassal
			#temporarily assign the vassal back to my liege
			set_defacto_liege = event_target:current_liege
			event_target:current_liege = {
				reverse_remove_opinion = { who = ROOT modifier = opinion_vassal_transfer }
				character_event = { id = Plus.1758 }
			}
		}
	}
}

character_event = {
	id = Plus.1758
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		#keep the vassal if not over the vassal limit
		if = {
			limit = { NOT = { over_vassal_limit = 1 } }
			save_event_target_as = new_liege
			log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
		}
		#find a closer new liege if over the vassal limit
		if = {
			limit = { over_vassal_limit = 1 }
			#first look for a vassal who doesn't hate me, who is not too strong, and is the de jure liege or a neighbor
			random_vassal = {
				limit = {
					in_revolt = no
					NOT = { character = event_target:old_liege }
					NOT = { trait = pf_rebel }
					NOT = { relative_power = { who = ROOT power = 1.0 } }
					NOT = { in_faction = faction_separatist }
					opinion = { who = ROOT value = 0 }
					higher_tier_than = event_target:reassigned_vassal
					OR = {
						de_jure_vassal_or_below = event_target:reassigned_vassal
						any_demesne_title = {
							tier = COUNT
							location = {
								any_neighbor_province = { owner = { character = event_target:reassigned_vassal } }
							}
						}
					}
				}
				save_event_target_as = new_liege
				log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
				opinion = { who = ROOT modifier = opinion_vassal_transfer }
				event_target:reassigned_vassal = {
					set_defacto_liege = event_target:new_liege
					pf_liege_change_effect = yes
				}
				break = yes
			}
			#then look for a de jure liege or neighbor who doesn't hate me
			random_vassal = {
				limit = {
					in_revolt = no
					NOT = { character = event_target:old_liege }
					NOT = { trait = pf_rebel }
					opinion = { who = ROOT value = 0 }
					higher_tier_than = event_target:reassigned_vassal
					OR = {
						de_jure_vassal_or_below = event_target:reassigned_vassal
						any_demesne_title = {
							tier = COUNT
							location = {
								any_neighbor_province = { owner = { character = event_target:reassigned_vassal } }
							}
						}
					}
				}
				save_event_target_as = new_liege
				log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
				opinion = { who = ROOT modifier = opinion_vassal_transfer }
				event_target:reassigned_vassal = {
					set_defacto_liege = event_target:new_liege
					pf_liege_change_effect = yes
				}
				break = yes
			}
			#then look for any de jure liege or neighbor who isn't a rival
			random_vassal = {
				limit = {
					in_revolt = no
					NOT = { character = event_target:old_liege }
					NOT = { trait = pf_rebel }
					NOT = { is_rival = ROOT }
					higher_tier_than = event_target:reassigned_vassal
					OR = {
						de_jure_vassal_or_below = event_target:reassigned_vassal
						any_demesne_title = {
							tier = COUNT
							location = {
								any_neighbor_province = { owner = { character = event_target:reassigned_vassal } }
							}
						}
					}
				}
				save_event_target_as = new_liege
				log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
				opinion = { who = ROOT modifier = opinion_vassal_transfer }
				event_target:reassigned_vassal = {
					set_defacto_liege = event_target:new_liege
					pf_liege_change_effect = yes
				}
				break = yes
			}
			#then look for a vassal who isn't too far away, who doesn't hate me, and who isn't too strong
			random_vassal = {
				limit = {
					in_revolt = no
					NOT = { character = event_target:old_liege }
					NOT = { trait = pf_rebel }
					opinion = { who = ROOT value = 0 }
					NOT = { relative_power = { who = ROOT power = 1.0 } }
					NOT = { in_faction = faction_separatist }
					higher_tier_than = event_target:reassigned_vassal
					OR = {
						de_jure_vassal_or_below = event_target:reassigned_vassal
						any_demesne_title = {
							tier = COUNT
							location = {
								OR = {
									any_neighbor_province = { owner = { character = event_target:reassigned_vassal } }
									event_target:reassigned_vassal = {
										any_demesne_title = {
											tier = COUNT
											location = {
												NOT = { distance = { where = PREVPREVPREV value = 50 } }
											}
										}
									}
								}
							}
						}
					}
				}
				save_event_target_as = new_liege
				log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
				opinion = { who = ROOT modifier = opinion_vassal_transfer }
				event_target:reassigned_vassal = {
					set_defacto_liege = event_target:new_liege
					pf_liege_change_effect = yes
				}
				break = yes
			}
			#then look for a vassal who isn't too far away and who doesn't hate me
			random_vassal = {
				limit = {
					in_revolt = no
					NOT = { character = event_target:old_liege }
					NOT = { trait = pf_rebel }
					opinion = { who = ROOT value = 0 }
					higher_tier_than = event_target:reassigned_vassal
					OR = {
						de_jure_vassal_or_below = event_target:reassigned_vassal
						any_demesne_title = {
							tier = COUNT
							location = {
								OR = {
									any_neighbor_province = { owner = { character = event_target:reassigned_vassal } }
									event_target:reassigned_vassal = {
										any_demesne_title = {
											tier = COUNT
											location = {
												NOT = { distance = { where = PREVPREVPREV value = 50 } }
											}
										}
									}
								}
							}
						}
					}
				}
				save_event_target_as = new_liege
				log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
				opinion = { who = ROOT modifier = opinion_vassal_transfer }
				event_target:reassigned_vassal = {
					set_defacto_liege = event_target:new_liege
					pf_liege_change_effect = yes
				}
				break = yes
			}
			#then look for a vassal who isn't too far away who isn't a rival
			random_vassal = {
				limit = {
					in_revolt = no
					NOT = { character = event_target:old_liege }
					NOT = { trait = pf_rebel }
					NOT = { is_rival = ROOT }
					higher_tier_than = event_target:reassigned_vassal
					OR = {
						de_jure_vassal_or_below = event_target:reassigned_vassal
						any_demesne_title = {
							tier = COUNT
							location = {
								OR = {
									any_neighbor_province = { owner = { character = event_target:reassigned_vassal } }
									event_target:reassigned_vassal = {
										any_demesne_title = {
											tier = COUNT
											location = {
												NOT = { distance = { where = PREVPREVPREV value = 50 } }
											}
										}
									}
								}
							}
						}
					}
				}
				save_event_target_as = new_liege
				log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
				opinion = { who = ROOT modifier = opinion_vassal_transfer }
				event_target:reassigned_vassal = {
					set_defacto_liege = event_target:new_liege
					pf_liege_change_effect = yes
				}
				break = yes
			}
			#then look for a vassal who's a bit further away, who doesn't hate me, and who isn't too strong
			random_vassal = {
				limit = {
					in_revolt = no
					NOT = { character = event_target:old_liege }
					NOT = { trait = pf_rebel }
					opinion = { who = ROOT value = 0 }
					NOT = { relative_power = { who = ROOT power = 1.0 } }
					NOT = { in_faction = faction_separatist }
					higher_tier_than = event_target:reassigned_vassal
					OR = {
						de_jure_vassal_or_below = event_target:reassigned_vassal
						any_demesne_title = {
							tier = COUNT
							location = {
								OR = {
									any_neighbor_province = { owner = { character = event_target:reassigned_vassal } }
									event_target:reassigned_vassal = {
										any_demesne_title = {
											tier = COUNT
											location = {
												NOT = { distance = { where = PREVPREVPREV value = 100 } }
											}
										}
									}
								}
							}
						}
					}
				}
				save_event_target_as = new_liege
				log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
				opinion = { who = ROOT modifier = opinion_vassal_transfer }
				event_target:reassigned_vassal = {
					set_defacto_liege = event_target:new_liege
					pf_liege_change_effect = yes
				}
				break = yes
			}
			#then look for a vassal who's a bit further away and who doesn't hate me
			random_vassal = {
				limit = {
					in_revolt = no
					NOT = { character = event_target:old_liege }
					NOT = { trait = pf_rebel }
					opinion = { who = ROOT value = 0 }
					higher_tier_than = event_target:reassigned_vassal
					OR = {
						de_jure_vassal_or_below = event_target:reassigned_vassal
						any_demesne_title = {
							tier = COUNT
							location = {
								OR = {
									any_neighbor_province = { owner = { character = event_target:reassigned_vassal } }
									event_target:reassigned_vassal = {
										any_demesne_title = {
											tier = COUNT
											location = {
												NOT = { distance = { where = PREVPREVPREV value = 100 } }
											}
										}
									}
								}
							}
						}
					}
				}
				save_event_target_as = new_liege
				log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
				opinion = { who = ROOT modifier = opinion_vassal_transfer }
				event_target:reassigned_vassal = {
					set_defacto_liege = event_target:new_liege
					pf_liege_change_effect = yes
				}
				break = yes
			}
			#then look for a vassal who's a bit further away who isn't a rival
			random_vassal = {
				limit = {
					in_revolt = no
					NOT = { character = event_target:old_liege }
					NOT = { trait = pf_rebel }
					NOT = { is_rival = ROOT }
					higher_tier_than = event_target:reassigned_vassal
					OR = {
						de_jure_vassal_or_below = event_target:reassigned_vassal
						any_demesne_title = {
							tier = COUNT
							location = {
								OR = {
									any_neighbor_province = { owner = { character = event_target:reassigned_vassal } }
									event_target:reassigned_vassal = {
										any_demesne_title = {
											tier = COUNT
											location = {
												NOT = { distance = { where = PREVPREVPREV value = 100 } }
											}
										}
									}
								}
							}
						}
					}
				}
				save_event_target_as = new_liege
				log = "[reassigned_vassal.GetBestName] was too distant a vassal from [old_liege.GetBestName], and thus was re-assigned as vassal to [new_liege.GetBestName]"
				opinion = { who = ROOT modifier = opinion_vassal_transfer }
				event_target:reassigned_vassal = {
					set_defacto_liege = event_target:new_liege
					pf_liege_change_effect = yes
				}
			}
		}
	}
}

#######################################
# OLD TRIGGERED MODIFIERS
# Written by vukica
#######################################

# Small demesne modifier
character_event = {
	id = Plus.1759
	
	hide_window = yes
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		OR = {
			has_character_modifier = small_demesne_1
			has_character_modifier = small_demesne_2
			has_character_modifier = small_demesne_3
			AND = {
				is_nomadic = no
				OR = {
					is_patrician = yes
					higher_tier_than = baron
				}
				NOT = { demesne_size = 4 }
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				demesne_size = 2
				has_character_modifier = small_demesne_1
			}
			remove_character_modifier = small_demesne_1
		}
		if = {
			limit = {
				OR = {
					demesne_size = 3
					NOT = { demesne_size = 2 }
				}
				has_character_modifier = small_demesne_2
			}
			remove_character_modifier = small_demesne_2
		}
		if = {
			limit = {
				OR = {
					demesne_size = 4
					NOT = { demesne_size = 3 }
				}
				has_character_modifier = small_demesne_3
			}
			remove_character_modifier = small_demesne_3
		}
		if = {
			limit = {
				NOT = { demesne_size = 2 }
				NOR = {
					has_character_modifier = small_demesne_1
					has_character_modifier = small_demesne_2
					has_character_modifier = small_demesne_3
				}
			}
			add_character_modifier = { name = small_demesne_1 duration = -1 }
		}
		if = {
			limit = {
				demesne_size = 2
				NOT = { demesne_size = 3 }
				NOR = {
					has_character_modifier = small_demesne_1
					has_character_modifier = small_demesne_2
					has_character_modifier = small_demesne_3
				}
			}
			add_character_modifier = { name = small_demesne_2 duration = -1 }
		}
		if = {
			limit = {
				demesne_size = 3
				NOT = { demesne_size = 4 }
				NOR = {
					has_character_modifier = small_demesne_1
					has_character_modifier = small_demesne_2
					has_character_modifier = small_demesne_3
				}
			}
			add_character_modifier = { name = small_demesne_3 duration = -1 }
		}
	}
	
}

# Overextended republic
character_event = {
	id = Plus.1760
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		OR = {
			has_character_modifier = overextended_republic
			AND = {
				higher_tier_than = COUNT
				OR = {
					is_merchant_republic = yes
					is_patrician = yes
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				NOT = { has_character_modifier = overextended_republic }
				# Don't check other conditions, that's already done in the trigger.
				any_realm_title = {
					location = {
						port = yes
						ROOT = {
							capital_scope = {
								distance = {
									where = PREVPREV # Comparing the distance between ROOT's capital and the title in question
									value = 650	#  From  aprox.Venice to East Cyprus and from Venice to Gibraltar
								}
							}
						}
					}
					tier = BARON
					is_republic = yes # Cities only
				}
			}
			add_character_modifier = { name = overextended_republic duration = -1 }
		}
		if = {
			limit = {
				has_character_modifier = overextended_republic
				NOR = {
					is_ruler = yes
					is_merchant_republic = yes
					is_patrician = yes
				}
			}
			remove_character_modifier = overextended_republic
		}
		if = {
			limit = {
				has_character_modifier = overextended_republic
				# Don't check other conditions, that's already done in the trigger.
				NOT = {
					any_realm_title = {
						location = {
							port = yes
							ROOT = {
								capital_scope = {
									distance = {
										where = PREVPREV # Comparing the distance between ROOT's capital and the title in question
										value = 650	#  From  aprox.Venice to East Cyprus and from Venice to Gibraltar
									}
								}
							}
						}
						tier = BARON
						is_republic = yes # Cities only
					}
				}
			}
			remove_character_modifier = overextended_republic
		}
	}
	
}

#######################################
# NON-DYNASTY HEIRS
# Written by Rylock
#######################################

### Player dies with a non-dynasty heir
character_event = {
	id = Plus.1761
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		ai = no
		is_merchant_republic = no
		OR = {
			AND = {
				NOT = { has_law = succ_feudal_elective }
				current_heir = {
					NOT = { dynasty = ROOT }
				}
			}
			AND = {
				primary_title = {
					has_law = succ_feudal_elective 
					heir_under_primogeniture_law = {
						NOT = { dynasty = ROOT }
					}
				}
			}
			AND = {
				primary_title = {
					has_law = succ_feudal_elective 
					heir_under_seniority_law = {
						NOT = { dynasty = ROOT }
					}
				}
			}
		}
		has_game_rule = {
			name = non_dynastic_heirs
			value = yes
		}
	}
	
	immediate = {
		current_heir = {
			ROOT = {
				create_character = {
					culture = PREV
					religion = PREV
					dynasty = PREV
					female = no
					age = 20
					trait = immortal
				}
				new_character = {
					save_event_target_as = switch_dynasty
				}
			}
			dynasty = ROOT
			character_event = { id = Plus.1762 days = 1 }
		}
	}
}

### Give the heir back their original dynasty after 1 day
character_event = {
	id = Plus.1762
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		event_target:switch_dynasty = {
			ROOT = { dynasty = PREV }
			dynasty = father_bastard
			remove_trait = immortal
			death = { death_reason = death_accident }
		}
		recalc_succession = yes
	}
}

#######################################
# RE-EDUCATION EVENTS
# Written by vukica
#######################################

# Confirm you really want to re-educate
character_event = {
	id = Plus.1763
	desc = "EVTDESC_Plus_1763"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
	}
	
	option = { #Yes, I need different skills!
		name = EVTOPTA_Plus_1763
		hidden_tooltip = {
			character_event = { id = Plus.1764 }
		}
	}
	option = { #I want to be better!
		name = EVTOPTB_Plus_1763
		trigger = {
			has_top_tier_education_trait_trigger = no
		}
		set_character_flag = improving_education
		hidden_tooltip = {
			character_event = { id = Plus.1764 }
		}
	}
	option = {
		name = CANCEL
		hidden_tooltip = {
			remove_character_modifier = being_reeducated
		}
	}
	
}

#Select re-education focus
character_event = {
	id = Plus.1764
	desc = "EVTDESC_Plus_1764"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
	}
	
	option = { #Diplomacy is the key to the future
		name = EVTOPTA_Plus_1764
		trigger = {
			NOT = { has_character_flag = improving_education }
			has_education_diplomacy_trigger = no
			NOT = {
				any_courtier_or_vassal = {
					liege = { character = ROOT }
					is_court_educator_trigger = yes
					NOT = { character = ROOT }
				}
			}
		}
		hidden_tooltip = {
			set_character_flag = reeducates_to_diplomacy
			clr_character_flag = hiring_educator
		}
	}
	option = { #I must become a warrior
		name = EVTOPTB_Plus_1764
		trigger = {
			NOT = { has_character_flag = improving_education }
			has_education_martial_trigger = no
			NOT = {
				any_courtier_or_vassal = {
					liege = { character = ROOT }
					is_court_educator_trigger = yes
					NOT = { character = ROOT }
				}
			}
		}
		hidden_tooltip = {
			set_character_flag = reeducates_to_martial
			clr_character_flag = hiring_educator
		}
	}
	option = { #I will master the numbers
		name = EVTOPTC_Plus_1764
		trigger = {
			NOT = { has_character_flag = improving_education }
			has_education_stewardship_trigger = no
			NOT = {
				any_courtier_or_vassal = {
					liege = { character = ROOT }
					is_court_educator_trigger = yes
					NOT = { character = ROOT }
				}
			}
		}
		hidden_tooltip = {
			set_character_flag = reeducates_to_stewardship
			clr_character_flag = hiring_educator
		}
	}
	option = { #Learn to rule from the shadows
		name = EVTOPTD_Plus_1764
		trigger = {
			NOT = { has_character_flag = improving_education }
			has_education_intrigue_trigger = no
			NOT = {
				any_courtier_or_vassal = {
					liege = { character = ROOT }
					is_court_educator_trigger = yes
					NOT = { character = ROOT }
				}
			}
		}
		hidden_tooltip = {
			set_character_flag = reeducates_to_intrigue
			clr_character_flag = hiring_educator
		}
	}
	option = { #I must devote myself to faith
		name = EVTOPTE_Plus_1764
		trigger = {
			NOT = { has_character_flag = improving_education }
			has_education_learning_trigger = no
			NOT = {
				any_courtier_or_vassal = {
					liege = { character = ROOT }
					is_court_educator_trigger = yes
					NOT = { character = ROOT }
				}
			}
		}
		hidden_tooltip = {
			set_character_flag = reeducates_to_learning
			clr_character_flag = hiring_educator
		}
	}
	option = { #My court educator sets the path
		name = EVTOPTF_Plus_1764
		trigger = {
			any_realm_character = {
				liege = { character = ROOT }
				is_court_educator_trigger = yes
				NOT = { character = ROOT }
			}
		}
		hidden_tooltip = {
			if = {
				limit = {
					any_realm_character = {
						liege = { character = ROOT }
						is_court_educator_trigger = yes
						NOT = { character = ROOT }
						has_education_diplomacy_trigger = yes
					}
				}
				set_character_flag = reeducates_to_diplomacy
				clr_character_flag = hiring_educator
			}
			if = {
				limit = {
					any_realm_character = {
						liege = { character = ROOT }
						is_court_educator_trigger = yes
						NOT = { character = ROOT }
						has_education_martial_trigger = yes
					}
				}
				set_character_flag = reeducates_to_martial
				clr_character_flag = hiring_educator
			}
			if = {
				limit = {
					any_realm_character = {
						liege = { character = ROOT }
						is_court_educator_trigger = yes
						NOT = { character = ROOT }
						has_education_stewardship_trigger = yes
					}
				}
				set_character_flag = reeducates_to_stewardship
			}
			if = {
				limit = {
					any_realm_character = {
						liege = { character = ROOT }
						is_court_educator_trigger = yes
						NOT = { character = ROOT }
						has_education_intrigue_trigger = yes
					}
				}
				set_character_flag = reeducates_to_intrigue
				clr_character_flag = hiring_educator
			}
			if = {
				limit = {
					any_realm_character = {
						liege = { character = ROOT }
						is_court_educator_trigger = yes
						NOT = { character = ROOT }
						has_education_learning_trigger = yes
					}
				}
				set_character_flag = reeducates_to_learning
				clr_character_flag = hiring_educator
			}
		}
	}
	
	option = { #I want to hire a new educator!
		name = EVTOPTG_Plus_1764
		trigger = {
			any_courtier_or_vassal = {
				liege = { character = ROOT }
				is_court_educator_trigger = yes
				NOT = { character = ROOT }
			}
		}
		hidden_tooltip = {
			if = { 
				limit = {
					any_courtier_or_vassal = { 
						liege = { character = ROOT }
						is_court_educator_trigger = yes 
						NOT = { character = ROOT }
					}
				}
				any_courtier_or_vassal = {
					if = {
						limit = {
							liege = { character = ROOT}
							is_court_educator_trigger = yes 
							NOT = { character = ROOT }
						}
						remove_court_educator_effect = yes
					}					
				}
				set_character_flag = hiring_educator
			}
		}
	}
	
	after = {
		if = {
			limit = {
				has_character_flag = hiring_educator
				NOT = { has_character_flag = improving_education }
			}
			character_event = { id = Plus.1764 }
			break = yes
		}
		character_event = { id = Plus.1765 } 
	}
}

#Determine investment level
character_event = {
	id = Plus.1765
	desc = "EVTDESC_Plus_1765"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
	}
	
	option = { #I want the best education money can buy
		name = EVTOPTA_Plus_1765
		scaled_wealth = { value = -1 min = -150 max = -250 }
		trigger = {
			OR = {
				NOT = { has_character_flag = improving_education }
				AND = {
					has_character_flag = improving_education
					has_top_tier_education_trait_trigger = no
				}
			}
		}
		custom_tooltip = {
			text = BEST_EDUCATION #Can result with education level 3 or 4.
			hidden_tooltip = {
				set_character_flag = best_education
			}
		}
	}
	
	option = { #I will spend moderately
		name = EVTOPTB_Plus_1765
		scaled_wealth = { value = -0.5 min = -50 max = -150 }
		trigger = {
			OR = {
				NOT = { has_character_flag = improving_education }
				AND = {
					has_character_flag = improving_education
					has_top_tier_education_trait_trigger = no
					has_tier_3_education_trigger = no
				}
			}
		}
		custom_tooltip = {
			text = MEDIOCRE_EDUCATION #Can result with education levels 2 or 3
			hidden_tooltip = {
				set_character_flag = mediocre_education
			}
		}
	}
	
	option = { #Anything is better than what I have now.
		name = EVTOPTC_Plus_1765
		scaled_wealth = { value = -0.2 min = -20 max = -50 }
		trigger = {
			OR = {
				NOT = { has_character_flag = improving_education }
				AND = {
					has_character_flag = improving_education
					has_top_tier_education_trait_trigger = no
					has_tier_3_education_trigger = no
					has_tier_2_education_trigger = no
				}
			}
		}
		custom_tooltip = {
			text = POOR_EDUCATION #Can result with education levels 1 and 2
			hidden_tooltip = {
				set_character_flag = poor_education
			}
		}
	}
	
	after = {
		character_event = { id = Plus.1766 }
		hidden_tooltip = { set_variable = { which = learning_outcome value = 0 } }
	}
}

#Generate new court educator
character_event = {
	id = Plus.1766
	
	is_triggered_only = yes
	hide_window = yes
	
	only_rulers = yes
	
	trigger = {
		#Do this only if player has not assigned a court educator.
		NOT = {
			any_courtier_or_vassal = {
				liege = { character = ROOT }
				is_court_educator_trigger = yes
				NOT = { character = ROOT }
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				has_character_flag = best_education
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ROOT
				female = no
				attributes = {
					diplomacy = 2
					learning = 4
					stewardship = 2
					intrigue = 2
					martial = 2
				}
			}
			new_character = {
				will_not_marry_effect = yes
				remove_trait = slow
				remove_trait = imbecile
				remove_trait = dull
				remove_education_effect = yes

				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_diplomacy
								AND = { has_character_flag = improving_education has_education_diplomacy_trigger = yes }
							}
						}
					}
					change_diplomacy = 8
					add_trait = socializer
					add_trait = grey_eminence
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_martial
								AND = { has_character_flag = improving_education has_education_martial_trigger = yes }
							}
						}
					}
					change_martial = 8
					add_trait = strategist
					add_trait = brilliant_strategist
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_stewardship
								AND = { has_character_flag = improving_education has_education_stewardship_trigger = yes }
							}
						}
					}
					change_stewardship = 8
					add_trait = administrator
					add_trait = midas_touched
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_intrigue
								AND = { has_character_flag = improving_education has_education_intrigue_trigger = yes }
							}
						}
					}
					change_intrigue = 8
					add_trait = schemer
					add_trait = elusive_shadow
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_learning
								AND = { has_character_flag = improving_education has_education_learning_trigger = yes }
							}
						}
					}
					change_learning = 8
					add_trait = erudite
					add_trait = mastermind_theologian
				}
				set_character_flag = hired_educator
				make_court_educator_effect = yes
				save_event_target_as = new_educator
				ROOT = { character_event = { id = Plus.1768 days = 1 } } #Inform liege about new educator 
			}
		}
		if = {
			limit = {
				has_character_flag = mediocre_education
			}	
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ROOT
				female = no
				attributes = {
					diplomacy = 2
					learning = 4
					stewardship = 2
					intrigue = 2
					martial = 2
				}
			}
			new_character = {
				will_not_marry_effect = yes
				remove_trait = slow
				remove_trait = imbecile
				remove_trait = dull
				
				remove_education_effect = yes

				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_diplomacy
								AND = { has_character_flag = improving_education has_education_diplomacy_trigger = yes }
							}
						}
					}
					change_diplomacy = 6
					add_trait = charismatic_negotiator
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_martial
								AND = { has_character_flag = improving_education has_education_martial_trigger = yes }
							}
						}
					}
					change_martial = 6
					add_trait = skilled_tactician
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_stewardship
								AND = { has_character_flag = improving_education has_education_stewardship_trigger = yes }
							}
						}
					}
					change_stewardship = 6
					add_trait = fortune_builder
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_intrigue
								AND = { has_character_flag = improving_education has_education_intrigue_trigger = yes }
							}
						}
					}
					change_intrigue = 6
					add_trait = intricate_webweaver
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_learning
								AND = { has_character_flag = improving_education has_education_learning_trigger = yes }
							}
						}
					}
					change_learning = 6
					add_trait = scholarly_theologian
				}
				set_character_flag = hired_educator
				make_court_educator_effect = yes
				save_event_target_as = new_educator
				ROOT = { character_event = { id = Plus.1768 days = 1 } } #Inform liege about new educator 
			}
		}
		if = {
			limit = {
				has_character_flag = poor_education
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = ROOT
				culture = ROOT
				female = no
				attributes = {
					diplomacy = 2
					learning = 2
					stewardship = 2
					intrigue = 2
					martial = 2
				}
			}
			new_character = {
				will_not_marry_effect = yes
				remove_trait = slow
				remove_trait = imbecile
				remove_trait = dull
				
				remove_education_effect = yes
				
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_diplomacy
								AND = { has_character_flag = improving_education has_education_diplomacy_trigger = yes }
							}
						}
					}
					change_diplomacy = 4
					add_trait = underhanded_rogue
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_martial
								AND = { has_character_flag = improving_education has_education_martial_trigger = yes }
							}
						}
					}
					change_martial = 4
					add_trait = tough_soldier
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_stewardship
								AND = { has_character_flag = improving_education has_education_stewardship_trigger = yes }
							}
						}
					}
					change_stewardship = 4
					add_trait = thrifty_clerk
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_intrigue
								AND = { has_character_flag = improving_education has_education_intrigue_trigger = yes }
							}
						}
					}
					change_intrigue = 4
					add_trait = flamboyant_schemer
				}
				if = {
					limit = {
						ROOT = {
							OR = {
								has_character_flag = reeducates_to_learning
								AND = { has_character_flag = improving_education has_education_learning_trigger = yes }
							}
						}
					}
					change_learning = 4
					add_trait = martial_cleric
				}
				set_character_flag = hired_educator
				make_court_educator_effect = yes
				save_event_target_as = new_educator
				ROOT = { character_event = { id = Plus.1768 days = 1 } } #Inform liege about new educator
			}
		}
	}
}

# hired educator dies
character_event = {
	id = Plus.1767
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		is_court_educator_trigger = yes
		has_character_flag = hired_educator
	}
	
	immediate = {
		liege = { character_event = { id = Plus.1766 days = 1 } }
	}
}

#Notify liege about new educator
character_event = {
	id = Plus.1768
	desc = "EVTDESC_Plus_1768"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	hide_from = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
	}
	
	option = {
		name = OK
		clear_event_target = new_educator
	}
}

#Education pulse tombola event
#happens on_yearly_pulse for rulers only
character_event = {
	id = Plus.1771
	
	is_triggered_only = yes
	hide_window = yes
	
	only_rulers = yes
	
	trigger = {
		has_character_modifier = being_reeducated
		any_courtier_or_vassal = {
			liege = { character = ROOT }
			is_court_educator_trigger = yes
			NOT = { character = ROOT }
		}
	}
	
	immediate = {
		random_list = {
			20 = {
				modifier = {
					factor = 0
					NOR = {
						has_character_flag = generic_education_event_one
						has_character_flag = generic_education_event_two
						has_character_flag = generic_education_event_three
						has_character_flag = generic_education_event_four
						has_character_flag = generic_education_event_five
						has_character_flag = had_first_education_event
						has_character_flag = had_second_education_event
					}
				}
				character_event = { id = Plus.1772 days = 30 random = 30 }
			}
			80 = { #Education event
				random_list = {
					10 = {
						#Education event Generic 1
						modifier = {
							factor = 0
							has_character_flag = generic_education_event_one
						}
						set_character_flag = generic_education_event_one
						force_two_education_events_effect = yes
						character_event = { id = Plus.1773 days = 30 random = 30 }
					}
					10 = {
						#Education event Generic 2
						modifier = {
							factor = 0
							has_character_flag = generic_education_event_two
						}
						force_two_education_events_effect = yes
						set_character_flag = generic_education_event_two
						character_event = { id = Plus.1774 days = 30 random = 30 }
					}
					10 = {
						#Education event Generic 3
						modifier = {
							factor = 0
							has_character_flag = generic_education_event_three
						}
						force_two_education_events_effect = yes
						set_character_flag = generic_education_event_three
						character_event = { id = Plus.1775 days = 30 random = 30 }
					}
					10 = {
						#Education event Generic 4
						modifier = {
							factor = 0
							has_character_flag = generic_education_event_four
						}
						force_two_education_events_effect = yes
						set_character_flag = generic_education_event_four
						character_event = { id = Plus.1776 days = 30 random = 30 }
					}
					10 = {
						#Education event Generic 5
						modifier = {
							factor = 0
							has_character_flag = generic_education_event_five
						}
						modifier = {
							factor = 0
							NOT = { num_of_lovers = 1 }
						}
						force_two_education_events_effect = yes
						set_character_flag = generic_education_event_five
						character_event = { id = Plus.1777 days = 30 random = 30 }
					}
				}
			}
		}
	}
}

#Education done
character_event = {
	id = Plus.1772
	desc = "EVTDESC_Plus_1772"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	hide_from = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
		has_character_modifier = being_reeducated
		any_courtier_or_vassal = {
			liege = { character = ROOT }
			is_court_educator_trigger = yes
			NOT = { character = ROOT }
		}
	}
	
	immediate = {
		any_courtier_or_vassal = {
			limit = {
				liege = { character = ROOT }
				is_court_educator_trigger = yes
				NOT = { character = ROOT }
			}
			save_event_target_as = target_court_educator
		}
	}
	
	option = {
		name = OK
		
		random_list = {
			25 = { #tier 4
				# 		educator is level 4
				# 		educator is level 3
				#		learning_outcome positive
				modifier = {
					factor = 0
					has_character_flag = improving_education
				}
				modifier = {
					factor = 0
					NOR = {
						AND = {
							event_target:target_court_educator = {
								has_top_tier_education_trait_trigger = yes
							}
							check_variable = { which = "learning_outcome" value = 0 }
						}
						AND = {
							event_target:target_court_educator = {
								has_tier_3_education_trigger = yes
							}
							check_variable = { which = "learning_outcome" value = 0 }
						}
					}
				}
				
				modifier = {
					factor = 1.5
					check_variable = { which = "learning_outcome" value = 3 }
				}
				
				modifier = {
					factor = 1.1
					event_target:target_court_educator = {
						has_top_tier_education_trait_trigger = yes
					}
				}

				if = {
					limit = {
						event_target:target_court_educator = {
							has_top_tier_education_trait_trigger = yes
						}
						check_variable = { which = "learning_outcome" value = 3 }
					}
					upgrade_education_effect = yes
				}
				reeducate_to_tier_4_effect = yes
				
			}
			25 = { #tier 3
				# 		educator is level 4
				#		learning_outcome negative
				# 		educator is level 3
				#		learning_outcome positive
				# 		educator is level 2
				#		learning_outcome positive
				modifier = {
					factor = 0
					has_character_flag = improving_education
				}
				modifier = {
					factor = 0
					
					NOR = {
						AND = {
							event_target:target_court_educator = {
								has_top_tier_education_trait_trigger = yes
							}
							NOT = { check_variable = { which = "learning_outcome" value = 0 } }
						}
						AND = {
							event_target:target_court_educator = {
								has_tier_3_education_trigger = yes
							}
							check_variable = { which = "learning_outcome" value = 0 }
						}
						AND = {
							event_target:target_court_educator = {
								has_tier_2_education_trigger = yes
							}
							check_variable = { which = "learning_outcome" value = 0 }
						}
					}
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = {
						has_tier_3_education_trigger = yes
					}
				}
				modifier = {
					factor = 1.3
					check_variable = { which = "learning_outcome" value = 3 }
				}
				if = {
					limit = {
						event_target:target_court_educator = {
							has_top_tier_education_trait_trigger = yes
						}
						NOT = { check_variable = { which = "learning_outcome" value = -1 } } 
					}
					reduce_education_effect = yes
				}
				reeducate_to_tier_3_effect = yes
			}
			25 = { #tier 2
				# 		educator is level 3
				#		learning_outcome negative
				# 		educator is level 2
				#		learning_outcome positive
				# 		educator is level 1
				#		learning_outcome positive
				modifier = {
					factor = 0
					has_character_flag = improving_education
				}
				modifier = {
					factor = 0
					
					NOR = {
						AND = {
							event_target:target_court_educator = {
								has_tier_3_education_trigger = yes
							}
							NOT = { check_variable = { which = "learning_outcome" value = 0 } }
						}
						AND = {
							event_target:target_court_educator = {
								has_tier_2_education_trigger = yes
							}
							check_variable = { which = "learning_outcome" value = 0 }
						}
						AND = {
							event_target:target_court_educator = {
								has_tier_1_education_trigger = yes
							}
							check_variable = { which = "learning_outcome" value = 0 }
						}
					}
				}
				modifier = {
					factor = 1.1
					check_variable = { which = "learning_outcome" value = 3 }
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = {
						has_tier_2_education_trigger = yes
					}
				}
				if = {
					limit = {
						event_target:target_court_educator = {
							has_tier_3_education_trigger = yes
						}
						NOT = { check_variable = { which = "learning_outcome" value = -1 } } 
					}
					reduce_education_effect = yes
				}
				reeducate_to_tier_2_effect = yes
			}
			25 = { #tier 1
				# 		educator is level 2
				# 		educator is level 1
				#		learning_outcome negative
				modifier = {
					factor = 0
					has_character_flag = improving_education
				}
				modifier = {
					factor = 0
					
					NOR = {
						AND = {
							event_target:target_court_educator = {
								has_tier_2_education_trigger = yes
							}
							NOT = { check_variable = { which = "learning_outcome" value = 0 } }
						}
						AND = {
							event_target:target_court_educator = {
								has_tier_1_education_trigger = yes
							}
							NOT = { check_variable = { which = "learning_outcome" value = 0 } }
						}
					}
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = {
						has_tier_1_education_trigger = yes
					}
				}
				if = {
					limit = {
						event_target:target_court_educator = {
							has_tier_2_education_trigger = yes
						}
						NOT = { check_variable = { which = "learning_outcome" value = -1 } } 
					}
					reduce_education_effect = yes
				}
				reeducate_to_tier_1_effect = yes
			}
			25 = { #increase education by 3
				modifier = {
					factor = 0
					NOT = { has_character_flag = improving_education }
				}
				modifier = {
					factor = 3
					event_target:target_court_educator = {
						has_top_tier_education_trait_trigger = yes
					}
				}
				modifier = {
					factor = 3
					check_variable = { which = "learning_outcome" value = 3 }
				}
				custom_tooltip = { text = EDUCATION_INCREASED_BY_3_TT }
				hidden_tooltip = {
					upgrade_education_effect = yes
					upgrade_education_effect = yes
					upgrade_education_effect = yes
				}
			}
			25 = { #increase education by 2
				modifier = {
					factor = 0
					NOT = { has_character_flag = improving_education }
				}
				modifier = {
					factor = 2
					event_target:target_court_educator = {
						has_top_tier_education_trait_trigger = yes
					}
				}
				modifier = {
					factor = 2
					check_variable = { which = "learning_outcome" value = 3 }
				}
				custom_tooltip = { text = EDUCATION_INCREASED_BY_2_TT }
				hidden_tooltip = {
					upgrade_education_effect = yes
					upgrade_education_effect = yes
				}
			}
			25 = { #increase education by 1 
				modifier = {
					factor = 0
					NOT = { has_character_flag = improving_education }
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = {
						has_top_tier_education_trait_trigger = yes
					}
				}
				modifier = {
					factor = 2
					event_target:target_court_educator = {
						has_tier_3_education_trigger = yes
					}
				}
				modifier = {
					factor = 2
					check_variable = { which = "learning_outcome" value = 0 }
				}
				upgrade_education_effect = yes
			}
			25 = { #fail
				modifier = {
					factor = 0
					NOT = { has_character_flag = improving_education }
				}
				modifier = {
					factor = 0.3
					event_target:target_court_educator = {
						has_top_tier_education_trait_trigger = yes
					}
				}
				modifier = {
					factor = 2
					event_target:target_court_educator = {
						has_tier_2_education_trigger = yes
					}
				}
				modifier = {
					factor = 2
					NOT = { check_variable = { which = "learning_outcome" value = 0 } }
				}
				modifier = {
					factor = 4
					NOT = { check_variable = { which = "learning_outcome" value = -2 } }
				}
				custom_tooltip = {
					text = FAIL_IMPROVING_EDUCATION
				}
			}
		}

		
		hidden_tooltip = {
			remove_character_modifier = being_reeducated
			clr_character_flag = best_education
			clr_character_flag = mediocre_education
			clr_character_flag = poor_education
			clr_character_flag = reeducates_to_diplomacy
			clr_character_flag = reeducates_to_martial
			clr_character_flag = reeducates_to_stewardship
			clr_character_flag = reeducates_to_intrigue
			clr_character_flag = reeducates_to_learning
			clr_character_flag = generic_education_event_one
			clr_character_flag = generic_education_event_two
			clr_character_flag = generic_education_event_three
			clr_character_flag = generic_education_event_four
			clr_character_flag = generic_education_event_five
			set_character_flag = was_reeducated
			clear_event_target = target_court_educator
			clr_character_flag = had_first_education_event
			clr_character_flag = had_second_education_event
			clr_character_flag = improving_education
		}
	}
}

#Education event Generic 1 - has difficulty learning
character_event = {
	id = Plus.1773
	
	desc = "EVTDESC_Plus_1773"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	hide_from = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
		has_character_modifier = being_reeducated
		any_realm_character = {
			liege = { character = ROOT }
			is_court_educator_trigger = yes
			NOT = { character = ROOT }
		}
	}
	
	immediate = {
		random_realm_character = {
			limit = {
				liege = { character = ROOT }
				is_court_educator_trigger = yes
				NOT = { character = ROOT }
			}
			save_event_target_as = target_court_educator
		}
		set_character_flag = generic_education_event_one
		force_two_education_events_effect = yes
	}
	
	option = { #Persist
		name = EVTOPTA_Plus_1773
		random_list = {
			50 = {
				#diligent + learning_outcome +1
				modifier = {
					factor = 2
					has_character_flag = best_education
				}
				modifier = {
					factor = 1.2
					has_character_flag = mediocre_education
				}
				modifier = {
					factor = 0.8
					has_character_flag = poor_education
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = { has_character_flag = hired_educator }
				}
				modifier = {
					factor = 1.2
					event_target:target_court_educator = {
						trait = diligent
					}
				}
				#if character is neither diligent nor slothful try to add diligent
				add_trait_diligent_effect = yes
				#if character is slotful get rid of it.
				remove_trait_slothful_effect = yes
				custom_tooltip = {
					text = BETTER_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = 1 }
					}
				}
			}
			50 = {
				#stressed + learning_outcome -0.5
				#add stress if neither stressed nor depressed
				add_trait_stressed_effect = yes
				#if stress is already here and learning level is really low, activate depression
				if = {
					limit = {
						NOT = { check_variable = { which = "learning_outcome" value = -2 } }
					}
					add_trait_depressed_effect = yes
				}
				#if already depressed, deduct health
				if = {
					limit = {
						NOT = { check_variable = { which = "learning_outcome" value = -2 } }
						trait = depressed
					}
					health = -0.5
				}
				custom_tooltip = {
					text = WORSE_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = -0.5 }
					}
				}
			}
		}
	}
	
	option = { #Take it easy
		name = EVTOPTB_Plus_1773
		random_list = {
			50 = {
				#slothful + learning_outcome -1
				modifier = {
					factor = 1.2
					event_target:target_court_educator = {
						trait = slothful
					}
				}
				add_trait_slothful_effect = yes
				remove_trait_diligent_effect = yes
				custom_tooltip = {
					text = WORSE_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = -1 }
					}
				}
			}
			50 = {
				health = 0.5
				modifier = {
					factor = 2
					has_character_flag = best_education
				}
				modifier = {
					factor = 1.2
					has_character_flag = mediocre_education
				}
				modifier = {
					factor = 0.8
					has_character_flag = poor_education
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = { has_character_flag = hired_educator }
				}
				custom_tooltip = {
					text = BETTER_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = 0.5 }
					}
				}
				#health +0.5 + learning_outcome +0.5
			}
		}
	}
	
	after = {
		clear_event_target = target_court_educator
	}
}

#Education event Generic 2 - argument with educator
character_event = {
	id = Plus.1774
	
	desc = "EVTDESC_Plus_1774"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	hide_from = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
		has_character_modifier = being_reeducated
		any_courtier_or_vassal = {
			liege = { character = ROOT }
			is_court_educator_trigger = yes
			NOT = { character = ROOT }
		}
	}
	
	immediate = {
		any_courtier_or_vassal = {
			limit = {
				liege = { character = ROOT }
				is_court_educator_trigger = yes
				NOT = { character = ROOT }
			}
			save_event_target_as = target_court_educator
		}
		set_character_flag = generic_education_event_two
		force_two_education_events_effect = yes
	}
	
	option = { #Talk with them
		name = EVTOPTA_Plus_1774
		random_list = {
			50 = {
				#wroth (learning_outcome -0.5)
				modifier = {
					factor = 1.2
					event_target:target_court_educator = {
						trait = wroth
					}
				}
				add_trait_wroth_effect = yes
				remove_trait_patient_effect = yes
				custom_tooltip = {
					text = WORSE_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = -0.5 }
					}
				}
			}
			50 = {
				#gregarious (learning_outcome +1)
				modifier = {
					factor = 2
					has_character_flag = best_education
				}
				modifier = {
					factor = 1.2
					has_character_flag = mediocre_education
				}
				modifier = {
					factor = 0.8
					has_character_flag = poor_education
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = { has_character_flag = hired_educator }
				}
				modifier = {
					factor = 1.2
					event_target:target_court_educator = {
						trait = gregarious
					}
				}
				add_trait_gregarious_effect = yes
				remove_trait_shy_effect = yes
				custom_tooltip = {
					text = BETTER_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = 1 }
					}
				}
			}
		}
	}
	
	option = { #My word is final
		name = EVTOPTB_Plus_1774
		random_list = {
			50 = {
				#may get proud (learning outcome -1)
				add_trait_proud_effect = yes
				remove_trait_humble_effect = yes
				modifier = {
					factor = 1.2
					event_target:target_court_educator = {
						trait = proud
					}
				}
				custom_tooltip = {
					text = WORSE_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = -1 }
					}
				}
			}
			50 = {
				#some prestige(learning_outcome +0.5)
				modifier = {
					factor = 2
					has_character_flag = best_education
				}
				modifier = {
					factor = 1.2
					has_character_flag = mediocre_education
				}
				modifier = {
					factor = 0.8
					has_character_flag = poor_education
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = { has_character_flag = hired_educator }
				}
				scaled_prestige = { value = 0.2 min = 10 max = 200 }
				custom_tooltip = {
					text = BETTER_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = 0.5 }
					}
				}
			}
		}
	}
	
	after = {
		clear_event_target = target_court_educator
	}
}

#Education event Generic 3 - new book published
character_event = {
	id = Plus.1775
	
	desc = "EVTDESC_Plus_1775"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	hide_from = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
		has_character_modifier = being_reeducated
		any_courtier_or_vassal = {
			liege = { character = ROOT }
			is_court_educator_trigger = yes
			NOT = { character = ROOT }
		}
	}
	
	immediate = {
		any_courtier_or_vassal = {
			limit = {
				liege = { character = ROOT }
				is_court_educator_trigger = yes
				NOT = { character = ROOT }
			}
			save_event_target_as = target_court_educator
		}
		set_character_flag = generic_education_event_three
		force_two_education_events_effect = yes
	}
	
	option = { #Buy the book
		name = EVTOPTA_Plus_1775
		#buy the book - loose money, learning_outcome +1
		scaled_wealth = { value = -0.2 min = -20 }
		custom_tooltip = {
			text = BETTER_EDUCATION
			hidden_tooltip = {
				change_variable = { which = "learning_outcome" value = 1 }
			}
		}
	}
	
	option = { #I already have a book
		name = EVTOPTB_Plus_1775
		#keep money, (learning outcome -0.5)
		scaled_wealth = { value = 0.1 min = 10 max = 30 }
		custom_tooltip = {
			text = WORSE_EDUCATION
			hidden_tooltip = {
				change_variable = { which = "learning_outcome" value = -0.5 }
			}
		}

	}
	
	after = {
		clear_event_target = target_court_educator
	}
}

#Education event Generic 4 - opportunity to excel
character_event = {
	id = Plus.1776
	
	desc = "EVTDESC_Plus_1776"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	hide_from = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
		has_character_modifier = being_reeducated
		any_courtier_or_vassal = {
			liege = { character = ROOT }
			is_court_educator_trigger = yes
			NOT = { character = ROOT }
		}
	}
	
	immediate = {
		any_courtier_or_vassal = {
			limit = {
				liege = { character = ROOT }
				is_court_educator_trigger = yes
				NOT = { character = ROOT }
			}
			save_event_target_as = target_court_educator
		}
		set_character_flag = generic_education_event_four
		force_two_education_events_effect = yes
	}
	
	option = { #Spend the night studying
		name = EVTOPTA_Plus_1776
		random_list = {
			50 = {
				#may get ambitious(learning_outcome +1)
				modifier = {
					factor = 2
					has_character_flag = best_education
				}
				modifier = {
					factor = 1.2
					has_character_flag = mediocre_education
				}
				modifier = {
					factor = 0.8
					has_character_flag = poor_education
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = { has_character_flag = hired_educator }
				}
				modifier = {
					factor = 1.2
					event_target:target_court_educator = {
						trait = ambitious
					}
				}
				add_trait_ambitious_effect = yes
				remove_trait_content_effect = yes 
				custom_tooltip = {
					text = BETTER_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = 1 }
					}
				}
			}
			50 = {
				#lose 0.5 health(learning_outcome -0.5)
				health = -0.5
				custom_tooltip = {
					text = WORSE_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = -0.5 }
					}
				}
			}
		}
	}
	
	option = { #Go to sleep
		name = EVTOPTB_Plus_1776
		random_list = {
			50 = {
				#may get slotful(learning_outcome -1)
				modifier = {
					factor = 1.2
					event_target:target_court_educator = {
						trait = slothful
					}
				}
				add_trait_slothful_effect = yes
				remove_trait_diligent_effect = yes
				custom_tooltip = {
					text = WORSE_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = -1 }
					}
				}
			}
			50 = {
				#0.5 health(learning_outcome +0.5)
				modifier = {
					factor = 2
					has_character_flag = best_education
				}
				modifier = {
					factor = 1.2
					has_character_flag = mediocre_education
				}
				modifier = {
					factor = 0.8
					has_character_flag = poor_education
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = { has_character_flag = hired_educator }
				}
				health = 0.5
				custom_tooltip = {
					text = BETTER_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = 0.5 }
					}
				}
			}
		}
	}
	
	after = {
		clear_event_target = target_court_educator
	}
}

#Education event Generic 5 - has a lover
character_event = {
	id = Plus.1777
	
	desc = "EVTDESC_Plus_1777"
	picture = GFX_evt_library
	
	is_triggered_only = yes
	hide_from = yes
	
	only_rulers = yes
	
	trigger = {
		is_alive = yes
		has_character_modifier = being_reeducated
		any_courtier_or_vassal = {
			liege = { character = ROOT }
			is_court_educator_trigger = yes
			NOT = { character = ROOT }
		}
	}
	
	immediate = {
		any_courtier_or_vassal = {
			limit = {
				liege = { character = ROOT }
				is_court_educator_trigger = yes
				NOT = { character = ROOT }
			}
			save_event_target_as = target_court_educator
		}
		set_character_flag = generic_education_event_five
		force_two_education_events_effect = yes
	}
	
	option = { #Spend the night studying
		name = EVTOPTA_Plus_1777
		random_list = {
			50 = {
				modifier = {
					factor = 2
					has_character_flag = best_education
				}
				modifier = {
					factor = 1.2
					has_character_flag = mediocre_education
				}
				modifier = {
					factor = 0.8
					has_character_flag = poor_education
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = { has_character_flag = hired_educator }
				}
				modifier = {
					factor = 1.2
					event_target:target_court_educator = {
						trait = diligent
					}
				}
				add_trait_diligent_effect = yes
				remove_trait_slothful_effect = yes
				custom_tooltip = {
					text = BETTER_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = 1 }
					}
				}
			}
			50 = {
				random_lover = {
					remove_lover = ROOT
				}
				custom_tooltip = {
					text = WORSE_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = -0.5 }
					}
				}
			}
		}
	}
	
	option = { #spend the night with lover
		name = EVTOPTB_Plus_1777
		random_list = {
			50 = {
				modifier = {
					factor = 1.2
					event_target:target_court_educator = {
						trait = arbitrary
					}
				}
				add_trait_arbitrary_effect = yes
				remove_trait_just_effect = yes
				custom_tooltip = {
					text = WORSE_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = -1 }
					}
				}
			}
			50 = {
				modifier = {
					factor = 2
					has_character_flag = best_education
				}
				modifier = {
					factor = 1.2
					has_character_flag = mediocre_education
				}
				modifier = {
					factor = 0.8
					has_character_flag = poor_education
				}
				modifier = {
					factor = 1.1
					event_target:target_court_educator = { has_character_flag = hired_educator }
				}
				random_lover = {
					opinion = {
						modifier = opinion_infatuated
						who = ROOT
						years = 5
					}
				}
				custom_tooltip = {
					text = BETTER_EDUCATION
					hidden_tooltip = {
						change_variable = { which = "learning_outcome" value = 0.5 }
					}
				}
			}
		}
	}
	
	after = {
		clear_event_target = target_court_educator
	}
}

# Education event template
# 
# character_event = {
	# id = Plus.17XY
	
	# desc = "EVTDESC_Plus_17XY"
	# picture = GFX_evt_library
	
	# is_triggered_only = yes
	# hide_from = yes
	
	# only_rulers = yes
	
	# trigger = {
		# is_alive = yes
	# }
	
	# option = {
		# name = EVTOPTA_Plus_17XY
		# random_list = {
			# 50 = {
				# modifier = {
					# factor = 2
					# has_character_flag = best_education
				# }
				# modifier = {
					# factor = 1.2
					# has_character_flag = mediocre_education
				# }
				# modifier = {
					# factor = 0.8
					# has_character_flag = poor_education
				# }
				# custom_tooltip = {
					# text = BETTER_EDUCATION
					# hidden_tooltip = {
						# change_variable = { which = "learning_outcome" value = 1 }
					# }
				# }
			# }
			# 50 = {
				# custom_tooltip = {
					# text = WORSE_EDUCATION
					# hidden_tooltip = {
						# change_variable = { which = "learning_outcome" value = -0.5 }
					# }
				# }
			# }
		# }
	# }
	
	# option = {
		# name = EVTOPTB_Plus_17XY
		# random_list = {
			# 50 = {
				# custom_tooltip = {
					# text = WORSE_EDUCATION
					# hidden_tooltip = {
						# change_variable = { which = "learning_outcome" value = -1 }
					# }
				# }
			# }
			# 50 = {
				# modifier = {
					# factor = 2
					# has_character_flag = best_education
				# }
				# modifier = {
					# factor = 1.2
					# has_character_flag = mediocre_education
				# }
				# modifier = {
					# factor = 0.8
					# has_character_flag = poor_education
				# }
				# custom_tooltip = {
					# text = BETTER_EDUCATION
					# hidden_tooltip = {
						# change_variable = { which = "learning_outcome" value = 0.5 }
					# }
				# }
			# }
		# }
	# }
# }
#TODO:later
#triggered from education tombola event
#Education event Specific Diplomacy 1
#	lesser lords argue over a piece of land
#	optA "invite them both to court - get them to talk" - may gain diplomacy+1 and learning_outcome+1 OR may lose gregarious/become shy and have learning_outcome -0.5
#	optB "decide for yourself and order them to comply" may gain powerful_voice and learning_outcome+0.5 OR increase tyranny and learning_outcome -1
#Education event Specific Diplomacy 2
#	a rich merchant from a far away land arrives to your capital
#	optA "have a formal court reception" may gain gregarious/lose shy and learning outcome+1 OR embarrass yourself in front of court (bad_speech) and learning_outcome-0.5
#	optB "meet with the merchant informally" - may gain some money and learning_outcome+0.5 OR get merchants_unhappy modifier and learning_outcome-1
#Education event Specific Martial 1
#Education event Specific Martial 2
#Education event Specific Stewardship 1
#Education event Specific Stewardship 2
#Education event Specific Intrigue 1
#Education event Specific Intrigue 2
#Education event Specific Learning 1
#Education event Specific Learning 2

#Explain how to rename character
narrative_event = {
	id = Plus.1800
	
	title = EVTNAME_Plus_1800
	desc = EVTDESC_Plus_1800
	picture = GFX_evt_council
	border = GFX_event_narrative_frame_diplomacy
	
	is_triggered_only = yes
	
	immediate = {
		capital_scope = {
			create_title = {
				tier = DUKE
				holder = ROOT
				base_title = THIS
			}
			new_title = {
				set_name = "[Root.GetFirstName]"
				set_title_flag = rename_character_duchy
			}
		}
		character_event = { id = Plus.1801 days = 7 }
	}
	
	option = {
		name = OK
	}
}

character_event = {
	id = Plus.1801
	
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		clr_character_flag = renaming_character
		any_demesne_title = {
			limit = {
				has_title_flag = rename_character_duchy
			}
			unsafe_destroy_landed_title = THIS
		}
	}
}