namespace = Plus

#reserved: Plus.300 to Plus.399

#######################################
# CK2Plus Maintenance Events
#######################################

character_event = { # AI plot check
	id = Plus.300
	is_triggered_only = yes
	hide_window = yes
	
	min_age = 16
	is_part_of_plot = yes
	capable_only = yes
	prisoner = no
	ai = yes

	trigger = {
		NOT = { has_character_flag = plot_check }
		has_plot = yes
	}

	weight_multiplier = {
		days = 1
	}

	immediate = {
		set_character_flag = plot_check
		plot_target_char = {
			any_courtier = {
				limit = {
					NOT = { is_plot_target_of = ROOT }
					NOT = { vassal_of = ROOT }
				}
				remove_opinion = {
					who = ROOT
					modifier = opinion_plot_help
				}
				opinion = {
					who = ROOT
					modifier = opinion_plot_help
					years = 5
				}
			}
		}
	}
}

character_event = { # Cancel AI plot if too few helpers and has taken too long
	id = Plus.301
	hide_window = yes
	is_triggered_only = yes

	ai = yes
	has_character_flag = plot_check
	
	trigger = {
		OR = {
			has_plot = no
			had_character_flag = { flag = plot_check days = 1095 }
		}
	}

	weight_multiplier = {
		days = 1
	}

	immediate = {
		if = {
			limit = { has_plot = no }
			clr_character_flag = plot_check
		}
		if = {
			limit = {
				OR = {
					NOT = { num_of_plot_backers = 1 }
					had_character_flag = { flag = plot_check days = 1095 }
				}
				OR = {
					NOT = { num_of_plot_backers = 2 }
					had_character_flag = { flag = plot_check days = 1825 }
				}
			}
			set_character_flag = abort_plot
		}
	}
}

character_event = { # Allow AI plotting
	id = Plus.302
	is_triggered_only = yes
	hide_window = yes
	
	min_age = 16
	prisoner = no
	capable_only = yes
	ai = yes

	trigger = {
		NOR = {
			is_inaccessible_trigger = yes
			has_plot = yes
			has_character_flag = allow_plotting
		}
	}

	weight_multiplier = {
		days = 1
		modifier = {
			factor = 0.5
			is_ruler = no
			is_councillor = no
		}
		modifier = {
			factor = 2
			is_ruler = yes
			tier = COUNT
		}
		modifier = {
			factor = 5
			is_ruler = yes
			tier = DUKE
		}
		modifier = {
			factor = 10
			is_ruler = yes
			higher_tier_than = DUKE
		}
		modifier = {
			factor = 3
			has_job_title = job_spymaster
		}
		modifier = {
			factor = 0.5
			NOT = { intrigue = 5 }
		}
		modifier = {
			factor = 0.75
			NOT = { intrigue = 10 }
		}
		modifier = {
			factor = 1.25
			trait = amateurish_plotter
		}
		modifier = {
			factor = 1.5
			trait = flamboyant_schemer
		}
		modifier = {
			factor = 2
			trait = intricate_webweaver
		}
		modifier = {
			factor = 3
			trait = elusive_shadow
		}
		modifier = {
			factor = 2
			intrigue = 10
		}
		modifier = {
			factor = 2
			intrigue = 15
		}
		modifier = {
			factor = 2
			intrigue = 20
		}
		modifier = {
			factor = 0.5
			OR = {
				trait = content
				trait = honest
				trait = kind
				trait = just
			}
		}
		modifier = {
			factor = 10
			OR = {
				trait = lunatic
				trait = possessed
			}
		}
	}

	immediate = {
		set_character_flag = allow_plotting
	}
}

character_event = { # Shatter Empire if too small
	id = Plus.303 #formerly 1000182859
	desc = "EVTDESC_Plus_303"
	picture = "GFX_evt_council"
	
	is_triggered_only = yes
	
	only_independent = yes #emperor has to be independent
	only_playable = yes
	war = no
	
	trigger = {
		is_ruler = yes
		is_nomadic = no
		tier = emperor
		NOT = { realm_size = 100 }
		NOT = { num_of_count_titles_in_realm = 35 }
		any_demesne_title = {
			tier = EMPEROR
			is_landless_type_title = no
			NOR = {
				title = e_timurids
				title = e_mexikha
				title = e_byzantium
				title = e_roman_empire
				title = e_latin_empire
				title = e_karling
			}
		}
	}

	option = {
		name = "EVTOPTA_Plus_303"
		prestige = -1000
		any_demesne_title = {
			limit = {
				tier = EMPEROR
				is_landless_type_title = no
				NOR = {
					title = e_timurids
					title = e_mexikha
					title = e_byzantium
					title = e_roman_empire
					title = e_latin_empire
					title = e_karling
				}
			}
			destroy_landed_title = THIS
		}
	}
}

character_event = { # Pass down lifetime appointments law to heir
	id = Plus.304
	
	is_triggered_only = yes
	hide_window = yes
	has_character_flag = lifetime_appointments
	
	trigger = {
		primary_title = {
			is_vice_royalty = no
			has_law = council_privileges_1
		}
		current_heir = {
			OR = {
				is_ruler = no
				lower_real_tier_than = ROOT
			}
		}
	}
	
	immediate = {
		current_heir = {
			set_character_flag = lifetime_appointments
			if = {
				limit = { is_ruler = yes }
				job_spymaster = { remove_title = job_spymaster remove_opinion = { who = PREV modifier = opinion_fired_from_council } }
				job_marshal = { remove_title = job_marshal remove_opinion = { who = PREV modifier = opinion_fired_from_council } }
				job_chancellor = { remove_title = job_chancellor remove_opinion = { who = PREV modifier = opinion_fired_from_council } }
				job_treasurer = { remove_title = job_treasurer remove_opinion = { who = PREV modifier = opinion_fired_from_council } }
				job_spiritual = { remove_title = job_spiritual remove_opinion = { who = PREV modifier = opinion_fired_from_council } }
			}
		}
	}
}

character_event = { # Remove Crowned by Pope or Crowned or Uncrowned if not a ruler
	id = Plus.305
	
	is_triggered_only = yes
	hide_window = yes
	
	war = no

	trigger = {
		OR = {
			AND = {
				OR = {
					trait = crowned
					trait = uncrowned
				}
				OR = {
					is_ruler = no
					lower_real_tier_than = KING
					primary_title = { is_vice_royalty = yes }
				}
			}
			AND = {
				trait = crowned_by_pope
				NOR = {
					has_landed_title = e_hre
					has_landed_title = e_karling
				}
			}
		}
	}

	weight_multiplier = {
		days = 1
	}

	immediate = {
		if = {
			limit = {
				trait = crowned_by_pope
				higher_real_tier_than = DUKE
			}
			remove_trait = crowned_by_pope
			add_trait = crowned
		}
		if = {
			limit = {
				trait = crowned_by_pope
				NOT = { higher_real_tier_than = DUKE }
			}
			remove_trait = crowned_by_pope
		}
		if = {
			limit = {
				trait = crowned
				OR = {
					is_ruler = no
					lower_real_tier_than = KING
					primary_title = { is_vice_royalty = yes }
				}
			}
			remove_trait = crowned
		}
		if = {
			limit = {
				trait = uncrowned
				OR = {
					is_ruler = no
					lower_real_tier_than = KING
					primary_title = { is_vice_royalty = yes }
				}
			}
			remove_trait = uncrowned
		}
	}
}

character_event = { # Inherit Half of Dishonourable and Tyrant
	id = Plus.306 #formerly 1000182861

	hide_window = yes
	is_triggered_only = yes
	ai = no
	
	trigger = {
		current_heir = { is_close_relative = ROOT }
		OR = {
			trait = dishonorable2
			trait = dishonorable3
			trait = dishonorable4
			trait = dishonorable5
			trait = dishonorable6
			trait = dishonorable7
			trait = dishonorable8
			trait = dishonorable9
			trait = dishonorable10
			trait = tyrant3
			trait = tyrant4
			trait = tyrant5
			trait = tyrant6
			trait = tyrant7
			trait = tyrant8
			trait = tyrant9
			trait = tyrant10
			trait = tyrant11
			trait = tyrant12
			trait = tyrant13
			trait = tyrant14
			trait = tyrant15
			trait = tyrant16
			trait = tyrant17
			trait = tyrant18
			trait = tyrant19
			trait = tyrant20
		}
	}
	
	immediate = {
		hidden_tooltip = {
			#tyrant
			if = {
				limit = {
					OR = {
						trait = tyrant3
						trait = tyrant4
						trait = tyrant5
						trait = tyrant6
						trait = tyrant7
						trait = tyrant8
						trait = tyrant9
						trait = tyrant10
						trait = tyrant11
						trait = tyrant12
						trait = tyrant13
						trait = tyrant14
						trait = tyrant15
						trait = tyrant16
						trait = tyrant17
						trait = tyrant18
						trait = tyrant19
						trait = tyrant20
					}
				}
				if = {
					limit = {
						trait = tyrant3
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 1 } }
				}
				if = {
					limit = {
						trait = tyrant4
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 2 } }
				}
				if = {
					limit = {
						trait = tyrant5
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 3 } }
				}
				if = {
					limit = {
						trait = tyrant6
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 4 } }
				}
				if = {
					limit = {
						trait = tyrant7
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 5 } }
				}
				if = {
					limit = {
						trait = tyrant8
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 6 } }
				}
				if = {
					limit = {
						trait = tyrant9
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 7 } }
				}
				if = {
					limit = {
						trait = tyrant10
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 8 } }
				}
				if = {
					limit = {
						trait = tyrant11
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 9 } }
				}
				if = {
					limit = {
						trait = tyrant12
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 10 } }
				}
				if = {
					limit = {
						trait = tyrant13
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 11 } }
				}
				if = {
					limit = {
						trait = tyrant14
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 12 } }
				}
				if = {
					limit = {
						trait = tyrant15
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 13 } }
				}
				if = {
					limit = {
						trait = tyrant16
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 14 } }
				}
				if = {
					limit = {
						trait = tyrant17
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 15 } }
				}
				if = {
					limit = {
						trait = tyrant18
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 16 } }
				}
				if = {
					limit = {
						trait = tyrant19
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 17 } }
				}
				if = {
					limit = {
						trait = tyrant20
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 18 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant1 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 1 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant2 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 2 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant3 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 3 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant4 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 4 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant5 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 5 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant6 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 6 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant7 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 7 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant8 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 8 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant9 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 9 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant10 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 10 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant11 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 11 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant12 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 12 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant13 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 13 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant14 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 14 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant15 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 15 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant16 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 16 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant17 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 17 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant18 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 18 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant19 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 19 } }
				}
				if = {
					limit = {
						current_heir = { trait = tyrant20 }
					}
					hidden_tooltip = { change_variable = { which = "tyrant" value = 20 } }
				}
				remove_trait = tyrant1
				remove_trait = tyrant2
				remove_trait = tyrant3
				remove_trait = tyrant4
				remove_trait = tyrant5
				remove_trait = tyrant6
				remove_trait = tyrant7
				remove_trait = tyrant8
				remove_trait = tyrant9
				remove_trait = tyrant10
				remove_trait = tyrant11
				remove_trait = tyrant12
				remove_trait = tyrant13
				remove_trait = tyrant14
				remove_trait = tyrant15
				remove_trait = tyrant16
				remove_trait = tyrant17
				remove_trait = tyrant18
				remove_trait = tyrant19
				remove_trait = tyrant20
				current_heir = {
					remove_trait = tyrant1
					remove_trait = tyrant2
					remove_trait = tyrant3
					remove_trait = tyrant4
					remove_trait = tyrant5
					remove_trait = tyrant6
					remove_trait = tyrant7
					remove_trait = tyrant8
					remove_trait = tyrant9
					remove_trait = tyrant10
					remove_trait = tyrant11
					remove_trait = tyrant12
					remove_trait = tyrant13
					remove_trait = tyrant14
					remove_trait = tyrant15
					remove_trait = tyrant16
					remove_trait = tyrant17
					remove_trait = tyrant18
					remove_trait = tyrant19
					remove_trait = tyrant20
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 0.9 }
						NOT = { check_variable = { which = "tyrant" value = 1.9 } }
					}
					current_heir = {
						add_trait = tyrant1
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 1.9 }
						NOT = { check_variable = { which = "tyrant" value = 2.9 } }
					}
					current_heir = {
						add_trait = tyrant2
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 2.9 }
						NOT = { check_variable = { which = "tyrant" value = 3.9 } }
					}
					current_heir = {
						add_trait = tyrant3
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 3.9 }
						NOT = { check_variable = { which = "tyrant" value = 4.9 } }
					}
					current_heir = {
						add_trait = tyrant4
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 4.9 }
						NOT = { check_variable = { which = "tyrant" value = 5.9 } }
					}
					current_heir = {
						add_trait = tyrant5
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 5.9 }
						NOT = { check_variable = { which = "tyrant" value = 6.9 } }
					}
					current_heir = {
						add_trait = tyrant6
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 6.9 }
						NOT = { check_variable = { which = "tyrant" value = 7.9 } }
					}
					current_heir = {
						add_trait = tyrant7
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 7.9 }
						NOT = { check_variable = { which = "tyrant" value = 8.9 } }
					}
					current_heir = {
						add_trait = tyrant8
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 8.9 }
						NOT = { check_variable = { which = "tyrant" value = 9.9 } }
					}
					current_heir = {
						add_trait = tyrant9
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 9.9 }
						NOT = { check_variable = { which = "tyrant" value = 10.9 } }
					}
					current_heir = {
						add_trait = tyrant10
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 10.9 }
						NOT = { check_variable = { which = "tyrant" value = 11.9 } }
					}
					current_heir = {
						add_trait = tyrant11
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 11.9 }
						NOT = { check_variable = { which = "tyrant" value = 12.9 } }
					}
					current_heir = {
						add_trait = tyrant12
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 12.9 }
						NOT = { check_variable = { which = "tyrant" value = 13.9 } }
					}
					current_heir = {
						add_trait = tyrant13
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 13.9 }
						NOT = { check_variable = { which = "tyrant" value = 14.9 } }
					}
					current_heir = {
						add_trait = tyrant14
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 14.9 }
						NOT = { check_variable = { which = "tyrant" value = 15.9 } }
					}
					current_heir = {
						add_trait = tyrant15
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 15.9 }
						NOT = { check_variable = { which = "tyrant" value = 16.9 } }
					}
					current_heir = {
						add_trait = tyrant16
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 16.9 }
						NOT = { check_variable = { which = "tyrant" value = 17.9 } }
					}
					current_heir = {
						add_trait = tyrant17
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 17.9 }
						NOT = { check_variable = { which = "tyrant" value = 18.9 } }
					}
					current_heir = {
						add_trait = tyrant18
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 18.9 }
						NOT = { check_variable = { which = "tyrant" value = 19.9 } }
					}
					current_heir = {
						add_trait = tyrant19
					}
				}
				if = {
					limit = {
						check_variable = { which = "tyrant" value = 19.9 }
					}
					current_heir = {
						add_trait = tyrant20
					}
				}
			}
			#dishonorable
			if = {
				limit = {
					OR = {
						trait = dishonorable2
						trait = dishonorable3
						trait = dishonorable4
						trait = dishonorable5
						trait = dishonorable6
						trait = dishonorable7
						trait = dishonorable8
						trait = dishonorable9
						trait = dishonorable10
					}
				}
				if = {
					limit = {
						trait = dishonorable2
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 1 } }
				}
				if = {
					limit = {
						trait = dishonorable3
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 2 } }
				}
				if = {
					limit = {
						trait = dishonorable4
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 3 } }
				}
				if = {
					limit = {
						trait = dishonorable5
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 4 } }
				}
				if = {
					limit = {
						trait = dishonorable6
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 5 } }
				}
				if = {
					limit = {
						trait = dishonorable7
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 6 } }
				}
				if = {
					limit = {
						trait = dishonorable8
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 7 } }
				}
				if = {
					limit = {
						trait = dishonorable9
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 8 } }
				}
				if = {
					limit = {
						trait = dishonorable10
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 9 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable1 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 1 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable2 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 2 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable3 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 3 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable4 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 4 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable5 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 5 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable6 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 6 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable7 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 7 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable8 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 8 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable9 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 9 } }
				}
				if = {
					limit = {
						current_heir = { trait = dishonorable10 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 10 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable1 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 1 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable2 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 2 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable3 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 3 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable4 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 4 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable5 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 5 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable6 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 6 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable7 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 7 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable8 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 8 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable9 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 9 } }
				}
				if = {
					limit = {
						current_heir = { trait = dyn_dishonorable10 }
					}
					hidden_tooltip = { change_variable = { which = "dishonorable" value = 10 } }
				}
				remove_trait = dishonorable1
				remove_trait = dishonorable2
				remove_trait = dishonorable3
				remove_trait = dishonorable4
				remove_trait = dishonorable5
				remove_trait = dishonorable6
				remove_trait = dishonorable7
				remove_trait = dishonorable8
				remove_trait = dishonorable9
				remove_trait = dishonorable10
				remove_trait = dyn_dishonorable1
				remove_trait = dyn_dishonorable2
				remove_trait = dyn_dishonorable3
				remove_trait = dyn_dishonorable4
				remove_trait = dyn_dishonorable5
				remove_trait = dyn_dishonorable6
				remove_trait = dyn_dishonorable7
				remove_trait = dyn_dishonorable8
				remove_trait = dyn_dishonorable9
				remove_trait = dyn_dishonorable10
				current_heir = {
					remove_trait = dishonorable1
					remove_trait = dishonorable2
					remove_trait = dishonorable3
					remove_trait = dishonorable4
					remove_trait = dishonorable5
					remove_trait = dishonorable6
					remove_trait = dishonorable7
					remove_trait = dishonorable8
					remove_trait = dishonorable9
					remove_trait = dishonorable10
					remove_trait = dyn_dishonorable1
					remove_trait = dyn_dishonorable2
					remove_trait = dyn_dishonorable3
					remove_trait = dyn_dishonorable4
					remove_trait = dyn_dishonorable5
					remove_trait = dyn_dishonorable6
					remove_trait = dyn_dishonorable7
					remove_trait = dyn_dishonorable8
					remove_trait = dyn_dishonorable9
					remove_trait = dyn_dishonorable10
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 0.9 }
						NOT = { check_variable = { which = "dishonorable" value = 1.9 } }
					}
					current_heir = {
						add_trait = dyn_dishonorable1
					}
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 1.9 }
						NOT = { check_variable = { which = "dishonorable" value = 2.9 } }
					}
					current_heir = {
						add_trait = dyn_dishonorable2
					}
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 2.9 }
						NOT = { check_variable = { which = "dishonorable" value = 3.9 } }
					}
					current_heir = {
						add_trait = dyn_dishonorable3
					}
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 3.9 }
						NOT = { check_variable = { which = "dishonorable" value = 4.9 } }
					}
					current_heir = {
						add_trait = dyn_dishonorable4
					}
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 4.9 }
						NOT = { check_variable = { which = "dishonorable" value = 5.9 } }
					}
					current_heir = {
						add_trait = dyn_dishonorable5
					}
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 5.9 }
						NOT = { check_variable = { which = "dishonorable" value = 6.9 } }
					}
					current_heir = {
						add_trait = dyn_dishonorable6
					}
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 6.9 }
						NOT = { check_variable = { which = "dishonorable" value = 7.9 } }
					}
					current_heir = {
						add_trait = dyn_dishonorable7
					}
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 7.9 }
						NOT = { check_variable = { which = "dishonorable" value = 8.9 } }
					}
					current_heir = {
						add_trait = dyn_dishonorable8
					}
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 8.9 }
						NOT = { check_variable = { which = "dishonorable" value = 9.9 } }
					}
					current_heir = {
						add_trait = dyn_dishonorable9
					}
				}
				if = {
					limit = {
						check_variable = { which = "dishonorable" value = 9.9 }
					}
					current_heir = {
						add_trait = dyn_dishonorable10
					}
				}
			}
		}
	}
}

character_event = { # Contingent Territory Check Part 1
	id = Plus.307

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		log = "Contingent Territory check begins"
		any_title = {
			limit = {
				is_primary_holder_title = yes
				holder_scope = {
					top_liege = { character = PREV }
					num_of_count_titles = 1
				}
			}
			holder_scope = {
				any_realm_province = {
					clr_province_flag = contingent_territory
					remove_province_modifier = province_isolated
				}
				capital_scope = { set_province_flag = contingent_territory }
				character_event = { id = Plus.308 }
 			}
		}
	}
}

character_event = { # Contingent Territory Check Part 2
	id = Plus.308

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		any_realm_province = {
			NOR = {
				has_province_flag = contingent_territory
				has_province_modifier = province_chaos
				has_province_modifier = province_isolated
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				any_realm_province = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						owner = { same_realm = ROOT }
						has_province_flag = contingent_territory
					}
				}
			}
			any_realm_province = {
				limit = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						owner = { same_realm = ROOT }
						has_province_flag = contingent_territory
					}
				}
				set_province_flag = contingent_territory
			}
		}
		if = {
			limit = {
				any_realm_province = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						owner = { same_realm = ROOT }
						has_province_flag = contingent_territory
					}
				}
			}
			any_realm_province = {
				limit = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						owner = { same_realm = ROOT }
						has_province_flag = contingent_territory
					}
				}
				set_province_flag = contingent_territory
			}
		}
		if = {
			limit = {
				any_realm_province = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						NOT = { is_land = yes }
						ROOT = {
							any_realm_province = {
								owner = { same_realm = ROOT }
								has_province_flag = contingent_territory
								any_neighbor_province = { province_id = PREVPREVPREV }
							}
						}
					}
				}
			}
			any_realm_province = {
				limit = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						NOT = { is_land = yes }
						ROOT = {
							any_realm_province = {
								owner = { same_realm = ROOT }
								has_province_flag = contingent_territory
								any_neighbor_province = { province_id = PREVPREVPREV }
							}
						}
					}
				}
				set_province_flag = contingent_territory
			}
		}
		if = {
			limit = {
				any_realm_province = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						NOT = { is_land = yes }
						ROOT = {
							any_realm_province = {
								owner = { same_realm = ROOT }
								has_province_flag = contingent_territory
								any_neighbor_province = { province_id = PREVPREVPREV }
							}
						}
					}
				}
			}
			any_realm_province = {
				limit = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						NOT = { is_land = yes }
						ROOT = {
							any_realm_province = {
								owner = { same_realm = ROOT }
								has_province_flag = contingent_territory
								any_neighbor_province = { province_id = PREVPREVPREV }
							}
						}
					}
				}
				set_province_flag = contingent_territory
			}
		}
		if = {
			limit = {
				any_realm_province = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						owner = { same_realm = ROOT }
						has_province_flag = contingent_territory
					}
				}
			}
			any_realm_province = {
				limit = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						owner = { same_realm = ROOT }
						has_province_flag = contingent_territory
					}
				}
				set_province_flag = contingent_territory
			}
		}
		if = {
			limit = {
				any_realm_province = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						owner = { same_realm = ROOT }
						has_province_flag = contingent_territory
					}
				}
			}
			any_realm_province = {
				limit = {
					NOT = { has_province_flag = contingent_territory }
					any_neighbor_province = {
						owner = { same_realm = ROOT }
						has_province_flag = contingent_territory
					}
				}
				set_province_flag = contingent_territory
			}
		}
		if = {
			limit = {
				NOR = {
					any_realm_province = {
						NOT = { has_province_flag = contingent_territory }
						any_neighbor_province = {
							owner = { same_realm = ROOT }
							has_province_flag = contingent_territory
						}
					}
					any_realm_province = {
						NOT = { has_province_flag = contingent_territory }
						any_neighbor_province = {
							NOT = { is_land = yes }
							ROOT = {
								any_realm_province = {
									owner = { same_realm = ROOT }
									has_province_flag = contingent_territory
									any_neighbor_province = { province_id = PREVPREVPREV }
								}
							}
						}
					}
				}
				any_realm_province = {
					NOR = {
						has_province_flag = contingent_territory
						has_province_modifier = province_chaos
						has_province_modifier = province_isolated
					}
				}
			}
			any_realm_province = {
				limit = {
					NOR = {
						has_province_flag = contingent_territory
						has_province_modifier = province_chaos
						has_province_modifier = province_isolated
					}
				}
				add_province_modifier = {
					name = province_isolated
					hidden = yes
					duration = -1
				}
			}
		}
		character_event = { id = Plus.308 }
	}
}

character_event = { # Remove Tyrant Trait on non-rulers
	id = Plus.309
	
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		is_ruler = no
		OR = {
			trait = tyrant1
			trait = tyrant2
			trait = tyrant3
			trait = tyrant4
			trait = tyrant5
			trait = tyrant6
			trait = tyrant7
			trait = tyrant8
			trait = tyrant9
			trait = tyrant10
			trait = tyrant11
			trait = tyrant12
			trait = tyrant13
			trait = tyrant14
			trait = tyrant15
			trait = tyrant16
			trait = tyrant17
			trait = tyrant18
			trait = tyrant19
			trait = tyrant20
		}
	}


	weight_multiplier = {
		days = 1
	}

	immediate = {
		remove_trait = tyrant1
		remove_trait = tyrant2
		remove_trait = tyrant3
		remove_trait = tyrant4
		remove_trait = tyrant5
		remove_trait = tyrant6
		remove_trait = tyrant7
		remove_trait = tyrant8
		remove_trait = tyrant9
		remove_trait = tyrant10
		remove_trait = tyrant11
		remove_trait = tyrant12
		remove_trait = tyrant13
		remove_trait = tyrant14
		remove_trait = tyrant15
		remove_trait = tyrant16
		remove_trait = tyrant17
		remove_trait = tyrant18
		remove_trait = tyrant19
		remove_trait = tyrant20
	}
}

character_event = { # Copies empire's Crown Laws to de jure kingdoms
	id = Plus.310
	desc = "EVTDESC_Plus_310"
	picture = "GFX_evt_council"

	is_triggered_only = yes
	
	only_independent = yes # emperor has to be independent
	only_playable = yes

	trigger = {	
		primary_title = { tier = EMPEROR }
		any_demesne_title = {
			tier = KING
			empire = { holder_scope = { character = ROOT } }
			OR = {
				AND = {
					empire = { has_law = investiture_law_0 }
					NOT = { has_law = investiture_law_0 }
				}
				AND = {
					empire = { has_law = investiture_law_1 }
					NOT = { has_law = investiture_law_1 }
				}
				AND = {
					empire = { has_law = crown_authority_0 }
					NOT = { has_law = crown_authority_0 }
				}
				AND = {
					empire = { has_law = crown_authority_1 }
					NOT = { has_law = crown_authority_1 }
				}
				AND = {
					empire = { has_law = crown_authority_2 }
					NOT = { has_law = crown_authority_2 }
				}
				AND = {
					empire = { has_law = crown_authority_3 }
					NOT = { has_law = crown_authority_3 }
				}
				AND = {
					empire = { has_law = crown_authority_4 }
					NOT = { has_law = crown_authority_4 }
				}
			}
		}
	}

	weight_multiplier = {
		days = 1
	}

	option = {
		name = "EXCELLENT"
		set_character_flag = centralize_without_penalties
		any_demesne_title = {
			limit = {
				tier = KING
				empire = { holder_scope = { character = ROOT } }
				OR = {
					AND = {
						empire = { has_law = investiture_law_0 }
						NOT = { has_law = investiture_law_0 }
					}
					AND = {
						empire = { has_law = investiture_law_1 }
						NOT = { has_law = investiture_law_1 }
					}
					AND = {
						empire = { has_law = crown_authority_0 }
						NOT = { has_law = crown_authority_0 }
					}
					AND = {
						empire = { has_law = crown_authority_1 }
						NOT = { has_law = crown_authority_1 }
					}
					AND = {
						empire = { has_law = crown_authority_2 }
						NOT = { has_law = crown_authority_2 }
					}
					AND = {
						empire = { has_law = crown_authority_3 }
						NOT = { has_law = crown_authority_3 }
					}
					AND = {
						empire = { has_law = crown_authority_4 }
						NOT = { has_law = crown_authority_4 }
					}
				}
			}
			if = {
				limit = {
					empire = { has_law = crown_authority_0 }
				}
				add_law = crown_authority_0
			}
			if = {
				limit = {
					empire = { has_law = crown_authority_1 }
				}
				add_law = crown_authority_1
			}
			if = {
				limit = {
					empire = { has_law = crown_authority_2 }
				}
				add_law = crown_authority_2
			}
			if = {
				limit = {
					empire = { has_law = crown_authority_3 }
				}
				add_law = crown_authority_3
			}
			if = {
				limit = {
					empire = { has_law = crown_authority_4 }
				}
				add_law = crown_authority_4
			}
			if = {
				limit = {
					empire = { has_law = investiture_law_0 }
				}
				add_law = investiture_law_0
			}
			if = {
				limit = {
					empire = { has_law = investiture_law_1 }
				}
				add_law = investiture_law_1
			}
		}
		clr_character_flag = centralize_without_penalties
	}
}

character_event = { # Destroy extra trade posts gained by non-merchant republics
	id = Plus.311
	
	is_triggered_only = yes
	hide_window = yes
	
	only_rulers = yes
	is_patrician = no
	
	trigger = {
		is_merchant_republic = no
		FROM = {
			tier = COUNT
			location = {
				has_trade_post = yes
				trade_post_owner = { character = ROOT }
			}
		}
		OR = {
			capital_scope = { NOT = { TECH_TRADE_PRACTICES = 1 } }
			AND = {
				capital_scope = { NOT = { TECH_TRADE_PRACTICES = 2 } }
				num_of_trade_posts = 2
			}
			AND = {
				capital_scope = { NOT = { TECH_TRADE_PRACTICES = 3 } }
				num_of_trade_posts = 4
			}
			AND = {
				capital_scope = { NOT = { TECH_TRADE_PRACTICES = 5 } }
				num_of_trade_posts = 5
			}
			AND = {
				capital_scope = { NOT = { TECH_TRADE_PRACTICES = 7 } }
				num_of_trade_posts = 6
			}
			num_of_trade_posts = 7
		}
	}
	
	immediate = {
		FROM = {
			location = {
				ROOT = { destroy_tradepost = PREV }
			}
		}
	}
}

character_event = { # AI Spouse finder
	id = Plus.312
	
	is_triggered_only = yes
	hide_window = yes
	
	min_age = 18
	max_age = 60
	capable_only = yes
	prisoner = no
	ai = yes

	trigger = {
		OR = {
			is_married = no
			AND = {
				has_polygamy = yes
				NOT = { num_of_spouses = 2 }
				real_tier = COUNT
			}
			AND = {
				has_polygamy = yes
				NOT = { num_of_spouses = 3 }
				OR = {
					real_tier = DUKE
					has_minor_title = title_prince
				}
			}
			AND = {
				has_polygamy = yes
				NOT = { num_of_spouses = 4 }
				higher_real_tier_than = DUKE
			}
		}
		is_ill = no
		mercenary = no
		is_betrothed = no
		is_pregnant = no
		can_marry = yes
		is_consort = no
		fertility = 0.01
		OR = {
			NOT = { age = 40 }
			is_female = no
		}
		OR = {
			is_female = no
			is_ruler = yes
			any_heir_title = { always = yes }
			any_pretender_title = { always = yes }
			AND = {
				is_councillor = yes
				liege = { ai = no }
			}
		}
		OR = {
			is_ruler = yes
			father_even_if_dead = { higher_tier_than = BARON }
			mother_even_if_dead = { higher_tier_than = BARON }
			any_close_relative = { higher_tier_than = COUNT }
			AND = {
				is_councillor = yes
				liege = { ai = no }
			}
		}
		OR = {
			is_ruler = yes
			liege = { ai = yes }
			liege = {
				NOT = { is_close_relative = ROOT }
				NOT = { dynasty = ROOT }
			}
		}
		OR = {
			is_ruler = no
			primary_title = {
				holy_order = no
				is_primary_type_title = no
				temporary = no
			}
		}
		OR = {
			is_ruler = no
			higher_tier_than = BARON
			is_feudal = yes
			is_tribal = yes
		}
		NOR = {
			trait = infirm
			is_inaccessible_trigger = yes
			has_character_modifier = do_not_disturb
			has_character_flag = ai_spouse_finder
		}
	}

	weight_multiplier = {
		factor = 1
		modifier = {
			factor = 0
			is_ruler = yes
			NOT = { ruled_years = 1 }
		}
		modifier = {
			factor = 1.5
			NOT = { age = 25 }
		}
		modifier = {
			factor = 1.5
			NOT = {
				any_child = {
					is_alive = yes
					is_female = no
					dynasty = ROOT
					NOR = {
						trait = bastard
						trait = incapable
						trait = inbred
						trait = imbecile
					}
				}
			}
		}
		modifier = {
			factor = 0.5
			any_child = {
				is_alive = yes
				is_female = no
				dynasty = ROOT
				NOR = {
					trait = bastard
					trait = incapable
					trait = inbred
					trait = imbecile
				}
			}
		}
		modifier = {
			factor = 0.5
			any_child = {
				count = 2
				is_alive = yes
				is_female = no
				dynasty = ROOT
				NOR = {
					trait = bastard
					trait = incapable
					trait = inbred
					trait = imbecile
				}
			}
		}
		modifier = {
			factor = 0.1
			any_child = {
				count = 3
				is_alive = yes
				is_female = no
				dynasty = ROOT
				NOR = {
					trait = bastard
					trait = incapable
					trait = inbred
					trait = imbecile
				}
			}
		}
		modifier = {
			factor = 10
			has_ambition = obj_get_married
		}
	}

	immediate = {
		set_character_flag = ai_spouse_finder
		clr_character_flag = checked_avuncular1
		clr_character_flag = checked_avuncular2
		clr_character_flag = checked_cousin
		clr_character_flag = checked_paternal_cousin
		clr_character_flag = checked_close_marriage
	}
}

character_event = { # Clear spouse finder flag
	id = Plus.313
	
	hide_window = yes
	has_character_flag = ai_spouse_finder
	
	trigger = {
		OR = {
			ai = no
			age = 60
			is_ill = yes
			prisoner = yes
			is_betrothed = yes
			is_pregnant = yes
			can_marry = no
			is_consort = yes
			trait = incapable
			trait = infirm
			is_inaccessible_trigger = yes
			has_character_modifier = do_not_disturb
			NOR = {
				is_married = no
				AND = {
					has_polygamy = yes
					NOT = { num_of_spouses = 2 }
					real_tier = COUNT
				}
				AND = {
					has_polygamy = yes
					NOT = { num_of_spouses = 3 }
					OR = {
						real_tier = DUKE
						has_minor_title = title_prince
					}
				}
				AND = {
					has_polygamy = yes
					NOT = { num_of_spouses = 4 }
					higher_real_tier_than = DUKE
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		clr_character_flag = ai_spouse_finder
		clr_character_flag = checked_avuncular1
		clr_character_flag = checked_avuncular2
		clr_character_flag = checked_cousin
		clr_character_flag = checked_paternal_cousin
		clr_character_flag = checked_close_marriage
	}
}

character_event = { # Triggers removal of Crowned by Pope or Crowned or Uncrowned held by old title owner
	id = Plus.314
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		higher_tier_than = DUKE
		FROMFROM = {
			is_alive = yes
			is_ruler = yes
			lower_tier_than = KING
			OR = {
				trait = crowned_by_pope
				trait = crowned
				trait = uncrowned
			}
		}
	}
	
	immediate = {
		FROMFROM = { character_event = { id = Plus.305 } }
	}
}

character_event = { # Independent baron opinion modifiers
	id = Plus.316

	is_triggered_only = yes
	hide_window = yes
	
	only_independent = yes
	is_patrician = no
	ai = yes

	trigger = {
		tier = baron
		is_ruler = yes
		controls_religion = no
		NOT = { rightful_religious_head = ROOT }
		mercenary = no
		primary_title = { holy_order = no }
		war = no
	}

	weight_multiplier = {
		days = 1
	}

	immediate = {
		primary_title = {
			location = {
				county = {
					holder_scope = {
						ROOT = {
							remove_opinion = {
								who = PREV
								modifier = opinion_independent
							}
							reverse_remove_opinion = {
								who = PREV
								modifier = opinion_independent
							}
							set_defacto_liege = PREV
						}
					}
				}
			}
		}
	}
}

character_event = { # AI Non-holy orders surrender baronies in different realms
	id = Plus.317
	
	is_triggered_only = yes
	hide_window = yes
	
	only_rulers = yes
	is_patrician = no
	ai = yes

	trigger = {
		is_ruler = yes
		controls_religion = no
		mercenary = no
		war = no
		NOT = { any_liege = { ai = no } }
		NOT = { rightful_religious_head = ROOT }
		primary_title = { holy_order = no }
		any_demesne_title = {
			tier = baron
			dejure_liege_title = {
				holder_scope = {
					NOT = { same_realm = ROOT }
				}
			}
		}
	}

	weight_multiplier = {
		days = 1
	}

	immediate = {
		any_demesne_title = {
			limit = {
				tier = baron
				dejure_liege_title = {
					holder_scope = {
						NOT = { same_realm = ROOT }
					}
				}
			}
			dejure_liege_title = {
				holder_scope = {
					set_character_flag = is_holder
					ROOT = {
						random_demesne_title = {
							limit = {
								tier = baron
								dejure_liege_title = {
									holder_scope = {
										has_character_flag = is_holder
									}
								}
							}
							gain_title = PREVPREV
						}
					}
					clr_character_flag = is_holder
				}
			}
		}
	}
}

character_event = { # Add Bloodlust trait
	id = Plus.319
	
	hide_window = yes
	is_triggered_only = yes

	only_independent = yes
	only_playable = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	ai = yes

	trigger = {
		NOT = { trait = bloodlust }
		OR = {
			AND = {
				culture = mongol
				religion = tengri_pagan
				primary_title = {
					OR = {
						title = e_golden_horde
						title = e_il-khanate
						title = e_mongol_empire
					}
				}
			}
			AND = {
				culture = nahuatl
				religion = aztec
				primary_title = { title = e_mexikha }
			}
			AND = {
				dynasty = 613 #Seljuk
				NOT = { realm_size = 200 }
				NOT = { year = 1200 }
				has_regent = no
			}
			AND = {
				dynasty = 800 #Timurids
				NOT = { realm_size = 200 }
				has_regent = no
			}
			AND = {
				NOR = {
					is_title_active = e_karling
					has_character_flag = former_carolingian_emperor
					e_hre = { has_title_flag = hre_formed }
				}
				higher_real_tier_than = DUKE
				has_regent = no
				capital_scope = { county = { de_jure_liege_or_above = e_hre } }
				OR = {
					trait = ambitious
					trait = zealous
					martial = 14
				}
				OR = {
					religion = catholic
					religion = chalcedonian
				}
				rightful_religious_head_scope = {
					NOT = { character = ROOT }
					has_landed_title = k_papal_chalcedon
				}
			}
		}
	}
	
	immediate = {
		set_character_flag = has_bloodlust_trait
		add_trait = bloodlust
	}	

	weight_multiplier = {
		days = 1
	}
}

character_event = { # Remove Bloodlust trait
	id = Plus.320

	hide_window = yes
	has_character_flag = has_bloodlust_trait
	
	trigger = {
		OR = {
			ai = no
			independent = no
			prisoner = yes
			trait = incapable
			NOT = { trait = bloodlust }
			NOR = {
				AND = {
					culture = mongol
					religion = tengri_pagan
					primary_title = {
						OR = {
							title = e_golden_horde
							title = e_il-khanate
							title = e_mongol_empire
						}
					}
				}
				AND = {
					culture = nahuatl
					religion = aztec
					primary_title = { title = e_mexikha }
				}
				AND = {
					dynasty = 613 #Seljuk
					NOT = { realm_size = 200 }
					NOT = { year = 1200 }
					has_regent = no
				}
				AND = {
					dynasty = 800 #Timurids
					NOT = { realm_size = 200 }
					has_regent = no
				}
				AND = {
					NOR = {
						is_title_active = e_karling
						has_character_flag = former_carolingian_emperor
						e_hre = { has_title_flag = hre_formed }
					}
					higher_real_tier_than = DUKE
					has_regent = no
					capital_scope = { county = { de_jure_liege_or_above = e_hre } }
					OR = {
						trait = ambitious
						trait = zealous
						martial = 14
					}
					OR = {
						religion = catholic
						religion = chalcedonian
					}
					rightful_religious_head_scope = {
						NOT = { character = ROOT }
						has_landed_title = k_papal_chalcedon
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		clr_character_flag = has_bloodlust_trait
		remove_trait = bloodlust
	}
}

character_event = { # Remove Favored Son trait on death
	id = Plus.321

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_child = { trait = favored_son }
	}

	immediate = {
		any_child = {
			if = {
				limit = {trait = favored_son}
				remove_trait = favored_son
			}
		}
	}
}

character_event = { # Initial Startup event
	id = Plus.322

	hide_window = yes
	is_triggered_only = yes
	
	ai = no

	trigger = {
		e_placeholder = { NOT = { has_title_flag = startup } }
	}

	weight_multiplier = {
		days = 1
	}

	immediate = {
		e_placeholder = { set_title_flag = startup }
		
		# Is the checksum correct? If not, then inform players
		#if = {
		#	limit = { supported_checksum = no }
		#	random_playable_ruler = {
		#		limit = { ai = no }
		#		narrative_event = { id = Plus.367 }
		#	}
		#}
		
		#turn off titular titles which have the same flag as their counterpart
		if = {
			limit = { has_dlc = "Charlemagne" }
			set_global_flag = titular_titles_turned_off
			turn_off_titles_effect = yes
		}

		# antinomad setup
		character_event = { id = emf_nomad.1000 }
		
		#fire the secondary setup events
		if = {
			limit = { e_placeholder = { NOT = { has_title_flag = secondary_startup } } }
			character_event = { id = Plus.347 }
		}
	}
}

character_event = { # Remove unwanted claims
	id = Plus.323 #formerly 1000182863

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			any_claim = {
				has_holder = no
				controls_religion = no
			}
			AND = {
				is_female = yes
				is_ruler = no
				any_claim = {
					has_law = agnatic_succession
					OR = {
						is_tribal = yes
						is_nomadic = yes
					}
				}
			}
		}
	}

	immediate = {
		any_claim = {
			limit = {
				has_holder = no
				controls_religion = no
			}
			remove_claim = ROOT
		}
		if = {
			limit = {
				is_female = yes
				is_ruler = no
			}
			any_claim = {
				limit = {
					has_law = agnatic_succession
					OR = {
						is_tribal = yes
						is_nomadic = yes
					}
				}
				remove_claim = ROOT
			}
		}
	}
}

character_event = { # Passes on various traits at birth
	id = Plus.324

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		NOT = { has_character_flag = genetics_check }
	}

	immediate = {
		set_character_flag = genetics_check
		set_character_flag = yehudi_check
		
		#chance for genius or quick
		if = {
			limit = {
				is_smart_trigger = no
				is_dumb_trigger = no
			}
			if = {
				limit = {
					OR = {
						mother_even_if_dead = { trait = genius }
						mother_even_if_dead = { trait = quick }
					}
					OR = {
						father_even_if_dead = { trait = genius }
						father_even_if_dead = { trait = quick }
					}
					NOR = {
						mother_even_if_dead = { trait = imbecile }
						mother_even_if_dead = { trait = slow }
						father_even_if_dead = { trait = imbecile}
						father_even_if_dead = { trait = slow }
					}
				}
				random_list = {
					70 = { }
					20 = { add_trait = quick }
					10 = { add_trait = genius }
				}
			}
			if = {
				limit = {
					OR = {
						mother_even_if_dead = { trait = genius }
						mother_even_if_dead = { trait = quick }
						father_even_if_dead = { trait = genius }
						father_even_if_dead = { trait = quick }
					}
					OR = {
						NOR = {
							mother_even_if_dead = { trait = genius }
							mother_even_if_dead = { trait = quick }
						}
						NOR = {
							father_even_if_dead = { trait = genius }
							father_even_if_dead = { trait = quick }
						}
					}
					NOR = {
						mother_even_if_dead = { trait = imbecile }
						mother_even_if_dead = { trait = slow }
						father_even_if_dead = { trait = imbecile}
						father_even_if_dead = { trait = slow }
					}
				}
				random_list = {
					85 = { }
					12 = { add_trait = quick }
					3 = { add_trait = genius }
				}
			}
		}

		#chance for slow or imbecile
		if = {
			limit = {
				is_smart_trigger = no
				is_dumb_trigger = no
			}
			if = {
				limit = {
					OR = {
						mother_even_if_dead = { trait = imbecile }
						mother_even_if_dead = { trait = slow }
					}
					OR = {
						father_even_if_dead = { trait = imbecile }
						father_even_if_dead = { trait = slow }
					}
					NOR = {
						mother_even_if_dead = { trait = genius }
						mother_even_if_dead = { trait = quick }
						father_even_if_dead = { trait = genius }
						father_even_if_dead = { trait = quick }
					}
				}
				random_list = {
					70 = { }
					20 = { add_trait = slow }
					10 = { add_trait = imbecile }
				}
			}
			if = {
				limit = {
					OR = {
						mother_even_if_dead = { trait = imbecile }
						mother_even_if_dead = { trait = slow }
						father_even_if_dead = { trait = imbecile }
						father_even_if_dead = { trait = slow }
					}
					OR = {
						NOR = {
							mother_even_if_dead = { trait = imbecile }
							mother_even_if_dead = { trait = slow }
						}
						NOR = {
							father_even_if_dead = { trait = imbecile }
							father_even_if_dead = { trait = slow }
						}
					}
					NOR = {
						mother_even_if_dead = { trait = genius }
						mother_even_if_dead = { trait = quick }
						father_even_if_dead = { trait = genius }
						father_even_if_dead = { trait = quick }
					}
				}
				random_list = {
					85 = { }
					12 = { add_trait = slow }
					3 = { add_trait = imbecile }
				}
			}
		}
		
		#pass on divine blood
		if = {
			limit = {
				NOT = { trait = divine_blood }
				father_even_if_dead = {
					dynasty = ROOT
					trait = divine_blood
				}
			}
			add_trait = divine_blood
		}
		if = {
			limit = {
				NOT = { trait = divine_blood }
				mother_even_if_dead = {
					dynasty = ROOT
					trait = divine_blood
				}
			}
			add_trait = divine_blood
		}
		
		#pass on yehudi trait
		if = {
			limit = {
				has_character_flag = start_of_game_character
				religion_group = jewish_group
			}
			add_trait = yehudi
		}
		if = {
			limit = { 
				mother_even_if_dead = { trait = yehudi }
			}
			add_trait = yehudi
		}
		
		#chance of being barren or infertile
		if = {
			limit = {
				NOT = { trait = fertile }
				NOT = { has_character_flag = start_of_game_character }
				trait = inbred
			}
			random_list = {
				20 = { }
				50 = {
					add_character_modifier = {
						name = infertile
						hidden = yes
						duration = -1
					}
				}
				30 = {
					add_character_modifier = {
						name = infertile
						hidden = yes
						duration = -1
					}
					set_character_flag = is_barren
				}
			}
		}
		if = {
			limit = {
				is_weak_trigger = yes
				NOT = { trait = fertile }
				NOT = { has_character_modifier = infertile }
				NOT = { has_character_modifier = barren }
				NOT = { has_character_flag = start_of_game_character }
			}
			random_list = {
				70 = { }
				25 = {
					add_character_modifier = {
						name = infertile
						hidden = yes
						duration = -1
					}
				}
				15 = {
					add_character_modifier = {
						name = infertile
						hidden = yes
						duration = -1
					}
					set_character_flag = is_barren
				}
			}
		}
		if = {
			limit = {
				NOT = { trait = fertile }
				NOT = { is_weak_trigger = yes }
				NOT = { is_strong_trigger = yes }
				NOT = { has_character_modifier = infertile }
				NOT = { has_character_modifier = barren }
				NOT = { has_character_flag = start_of_game_character }
			}
			random_list = {
				85 = { }
				12 = {
					add_character_modifier = {
						name = infertile
						hidden = yes
						duration = -1
					}
				}
				3 = {
					add_character_modifier = {
						name = infertile
						hidden = yes
						duration = -1
					}
					set_character_flag = is_barren
				}
			}
		}

		#add indian caste if they don't have one
		if = {
			limit = {
				religion_group = indian_group
				NOR = {
					trait = brahmin
					trait = kshatriya
					trait = vaishya
				}
			}
			if = {
				limit = {
					is_feudal = yes
				}
				add_trait = kshatriya
			}
			if = {
				limit = {
					is_feudal = no
					OR = {
						is_theocracy = yes
						is_priest = yes
					}
				}
				add_trait = brahmin
			}
			if = {
				limit = {
					is_feudal = no
					is_theocracy = no
					is_priest = no
				}
				add_trait = vaishya
			}
		}
		
		#add opinions for cousins
		if = {
			limit = {
				is_female = no
				has_character_flag = start_of_game_character
			}
			any_child = {
				ROOT = {
					any_sibling_even_if_dead = {
						any_child = {
							reverse_opinion = { who = PREVPREVPREV modifier = opinion_cousin years = 100 }
							opinion = { who = PREVPREVPREV modifier = opinion_cousin years = 100 }
						}
					}
				}
			}
		}
		
		#add opinion for cousins
		father_even_if_dead = {
			any_sibling_even_if_dead = {
				any_child = {
					limit = { NOT = { has_opinion_modifier = { who = ROOT modifier = opinion_cousin } } }
					reverse_opinion = { who = ROOT modifier = opinion_cousin years = 100 }
					opinion = { who = ROOT modifier = opinion_cousin years = 100 }
				}
			}
		}
		mother_even_if_dead = {
			any_sibling_even_if_dead = {
				any_child = {
					limit = { NOT = { has_opinion_modifier = { who = ROOT modifier = opinion_cousin } } }
					reverse_opinion = { who = ROOT modifier = opinion_cousin years = 100 }
					opinion = { who = ROOT modifier = opinion_cousin years = 100 }
				}
			}
		}
	}
}

character_event = { # Removes Just trait
	id = Plus.325 #formerly 1000182865
	desc = "EVTDESC_Plus_325"
	picture = "GFX_evt_emissary"
	
	is_triggered_only = yes

	trigger = {
		trait = just
	}

	immediate = {
		remove_trait = just
	}

	option = {
		name = "EVTOPTA_Plus_325"
		tooltip = { remove_trait = just }
	}
}

character_event = { # Byzantium is reclaimed by an Orthodox/Hellenic ruler
	id = Plus.326
	desc = "EVTDESC_Plus_326"
	picture = "GFX_evt_council"
	
	only_independent = yes
	only_rulers = yes
	culture_group = byzantine
	war = no

	trigger = {
		NOT = { has_global_flag = emf_nwo }
		OR = {
			religion = chalcedonian
			religion = orthodox
			religion = bogomilist
			religion = monothelite
			religion = iconoclast
			religion = hellenic_pagan
			religion = miaphysite
			religion = monophysite
			religion = apostolic
			religion = paulician
			religion = tondrakian
			religion = nestorian
			religion = messalian
		}
		c_byzantion = { holder_scope = { same_realm = ROOT } }
		OR = {
			NOT = { real_tier = emperor }
			primary_title = { is_titular = yes }
		}
		e_byzantium = {
			has_holder = no
			is_titular = no
		}
		e_roman_empire = { has_holder = no }
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = "EVTOPTA_Plus_326"
		set_character_flag = centralize_without_penalties
		e_byzantium = {
			hidden_tooltip = {
				revoke_law = investiture_law_0
				revoke_law = investiture_law_1
				add_law = crown_authority_2
				add_law = council_privileges_0
				add_law = succ_primogeniture
				add_law = cognatic_succession
			}
			gain_title = ROOT
		}
		any_demesne_title = {
			limit = {
				real_tier = EMPEROR
				is_titular = yes
			}
			destroy_landed_title = THIS
		}
		clr_character_flag = centralize_without_penalties
	}
}

character_event = { # Convert Latin Empire to Byzantine Empire if the holder is no longer Catholic
	id = Plus.327
	desc = "EVTDESC_Plus_327"
	picture = "GFX_evt_council"
	
	is_triggered_only = yes
	hide_from = yes
	
	only_independent = yes
	only_playable = yes

	trigger = {
		has_landed_title = e_latin_empire
		NOT = { 
			any_realm_title = {
				NOT = { title = e_latin_empire }
				tier = EMPEROR
			}
		}
		NOR = {
			religion = chalcedonian
			religion = catholic
			religion = cathar
			religion = fraticelli
			religion = waldensian
			religion = lollard
			religion = adoptionist
		}
		war = no
	}

	option = {
		name = "OK"
		if = {
			limit = {
				realm_size = 150
				NOT = { num_of_emperor_titles = 2 }
				OR = {
					e_byzantium = { has_holder = yes }
					NOR = {
						religion = chalcedonian
						religion = orthodox
						religion = bogomilist
						religion = monothelite
						religion = iconoclast
						religion = hellenic_pagan
						religion = miaphysite
						religion = monophysite
						religion = apostolic
						religion = paulician
						religion = tondrakian
						religion = nestorian
						religion = messalian
					}
				}
			}
			capital_scope = {
				kingdom = {
					if = {
						limit = { NOT = { has_title_flag = emergency_empire_title } }
						set_title_flag = emergency_empire_title
						create_title = {
							tier = EMPEROR
							landless = no
							temporary = no
							custom_created = yes
							culture = ROOT
							holder = ROOT
							base_title = THIS
						}
						new_title = {
							set_title_flag = custom_created_title
							copy_title_laws = e_latin_empire
							make_primary_title = yes
							copy_title_history = e_latin_empire
						}
					}
				}
			}
		}
		if = {
			limit = {
				OR = {
					religion = chalcedonian
					religion = orthodox
					religion = bogomilist
					religion = monothelite
					religion = iconoclast
					religion = hellenic_pagan
					religion = miaphysite
					religion = monophysite
					religion = apostolic
					religion = paulician
					religion = tondrakian
					religion = nestorian
					religion = messalian
				}
				e_byzantium = { has_holder = no }
			}
			set_character_flag = centralize_without_penalties
			e_byzantium = {
				hidden_tooltip = {
					copy_title_laws = e_latin_empire
					copy_title_history = e_latin_empire
				}
				gain_title = ROOT
			}
			clr_character_flag = centralize_without_penalties
			any_title = {
				limit = {
					rebel = no
					has_holder = yes
					is_primary_holder_title = yes
					holder_scope = { top_liege = { character = PREV } }
				}
				holder_scope = {
					if = {
						limit = { has_weak_claim = e_latin_empire }
						add_weak_pressed_claim = e_byzantium
						remove_claim = e_latin_empire
					}
					if = {
						limit = { has_strong_claim = e_latin_empire }
						add_pressed_claim = e_byzantium
						remove_claim = e_latin_empire
					}
					any_realm_character = {
						if = {
							limit = { has_weak_claim = e_latin_empire }
							add_weak_pressed_claim = e_byzantium
							remove_claim = e_latin_empire
						}
						if = {
							limit = { has_strong_claim = e_latin_empire }
							add_pressed_claim = e_byzantium
							remove_claim = e_latin_empire
						}
					}
				}
			}
		}
		e_latin_empire = {
			destroy_landed_title = yes
		}
		hidden_tooltip = {
			any_vassal = {
				limit = {
					NOT = { has_character_flag = considered_for_independence }
					primary_title = { de_jure_liege_or_above = e_latin_empire }
				}
				character_event = { id = Plus.430 days = 3 }
			}
		}
		ai_chance = {
			factor = 2
			modifier = {
				factor = 0
				trait = cynical
			}
			modifier = {
				factor = 0
				trait = ambitious
			}
		}
	}
	
	option = {
		name = "I_WILL_CONVERT" #Then I will convert!
		trigger = {
			NOT = { trait = zealous}
			OR = {
				religion_group = christian
				religion_group = pagan_group
			}
			completely_controls = c_byzantion
			c_byzantion = {
				location = {
					OR = {
						religion = chalcedonian
						religion = catholic
						religion = cathar
						religion = fraticelli
						religion = waldensian
						religion = lollard
						religion = adoptionist
					}
				}
			}
		}
		if = {
			limit = {
				religion_group = pagan_group
			}
			add_trait = sympathy_pagans
		}
		if = {
			limit = {
				religion_group = christian
			}
			add_trait = sympathy_christendom
		}
		c_byzantion = { location = { reverse_religion = ROOT } }
		add_character_modifier = { name = recently_converted duration = 730}
		ai_chance = {
			factor = 5
			modifier = {
				factor = 0
				trait = content
			}
		}
	}
}

character_event = { # Byzantium Auto-Destroy Mechanic. Destroys Byzantium if the title holder is not Orthodox or Hellenic
	id = Plus.328
	desc = "EVTDESC_Plus_328"
	picture = "GFX_evt_council"
	
	is_triggered_only = yes
	hide_from = yes
	
	only_independent = yes
	only_playable = yes

	trigger = {
		has_landed_title = e_byzantium
		NOT = { 
			any_realm_title = {
				NOT = { title = e_byzantium }
				tier = EMPEROR
			}
		}
		NOR = {
			religion = chalcedonian
			religion = orthodox
			religion = bogomilist
			religion = monothelite
			religion = iconoclast
			religion = hellenic_pagan
			religion = titan_pagan
			religion = promethean_pagan
			religion = miaphysite
			religion = monophysite
			religion = apostolic
			religion = paulician
			religion = tondrakian
			religion = nestorian
			religion = messalian
			AND = {
				e_latin_empire = { has_holder = yes }
				OR = {
					religion = catholic
					religion = cathar
					religion = fraticelli
					religion = waldensian
					religion = lollard
					religion = adoptionist
				}
			}
		}
		war = no
	}

	option = {
		name = "OK"
		if = {
			limit = {
				realm_size = 150
				NOT = { num_of_emperor_titles = 2 }
				OR = {
					e_latin_empire = { has_holder = yes }
					NOR = {
						religion = chalcedonian
						religion = catholic
						religion = cathar
						religion = fraticelli
						religion = waldensian
						religion = lollard
						religion = adoptionist
					}
				}
			}
			capital_scope = {
				kingdom = {
					if = {
						limit = { NOT = { has_title_flag = emergency_empire_title } }
						set_title_flag = emergency_empire_title
						create_title = {
							tier = EMPEROR
							landless = no
							temporary = no
							custom_created = yes
							culture = ROOT
							holder = ROOT
							base_title = THIS
						}
						new_title = {
							set_title_flag = custom_created_title
							copy_title_laws = e_byzantium
							revoke_law = kingdom_lockout_1
							revoke_law = kingdom_lockout_0
							add_law = feudal_administration
							make_primary_title = yes
							copy_title_history = e_byzantium
						}
					}
				}
			}
		}
		if = {
			limit = {
				OR = {
					religion = chalcedonian
					religion = catholic
					religion = cathar
					religion = fraticelli
					religion = waldensian
					religion = lollard
					religion = adoptionist
				}
				e_latin_empire = { has_holder = no }
			}
			set_character_flag = centralize_without_penalties
			e_latin_empire = {
				hidden_tooltip = {
					copy_title_laws = e_byzantium
					copy_title_history = e_byzantium
				}
				gain_title = ROOT
			}
			hidden_tooltip = {
				any_title = {
					limit = {
						rebel = no
						has_holder = yes
						is_primary_holder_title = yes
						holder_scope = { top_liege = { character = PREV } }
					}
					holder_scope = {
						if = {
							limit = { has_weak_claim = e_byzantium }
							add_weak_pressed_claim = e_latin_empire
							remove_claim = e_byzantium
						}
						if = {
							limit = { has_strong_claim = e_byzantium }
							add_pressed_claim = e_latin_empire
							remove_claim = e_byzantium
						}
						any_realm_character = {
							if = {
								limit = { has_weak_claim = e_byzantium }
								add_weak_pressed_claim = e_latin_empire
								remove_claim = e_byzantium
							}
							if = {
								limit = { has_strong_claim = e_byzantium }
								add_pressed_claim = e_latin_empire
								remove_claim = e_byzantium
							}
						}
					}
				}
			}
			clr_character_flag = centralize_without_penalties
		}
		e_byzantium = {
			destroy_landed_title = yes
		}
		hidden_tooltip = {
			any_vassal = {
				limit = {
					NOT = { has_character_flag = considered_for_independence }
					primary_title = { de_jure_liege_or_above = e_byzantium }
				}
				character_event = { id = Plus.430 days = 3 }
			}
		}
		ai_chance = {
			factor = 2
			modifier = {
				factor = 0
				trait = cynical
			}
			modifier = {
				factor = 0
				trait = ambitious
			}
		}
	}
	option = {
		name = "I_WILL_CONVERT" #Then I will convert!
		trigger = {
			NOT = { trait = zealous}
			OR = {
				religion_group = christian
				religion_group = pagan_group
			}
			completely_controls = c_byzantion
			c_byzantion = {
				location = {
					OR = {
						religion = chalcedonian
						religion = orthodox
						religion = bogomilist
						religion = monothelite
						religion = iconoclast
						religion = hellenic_pagan
						religion = titan_pagan
						religion = promethean_pagan
						religion = miaphysite
						religion = monophysite
						religion = apostolic
						religion = paulician
						religion = tondrakian
						religion = nestorian
						religion = messalian
					}
				}
			}
		}
		if = {
			limit = {
				religion_group = pagan_group
				NOR = {
					religion = hellenic_pagan
					religion = titan_pagan
					religion = promethean_pagan
				}
			}
			add_trait = sympathy_pagans
		}
		if = {
			limit = {
				religion_group = christian
				c_byzantion = {
					location = {
						OR = {
							religion = hellenic_pagan
							religion = titan_pagan
							religion = promethean_pagan
						}
					}
				}
			}
			add_trait = sympathy_christendom
		}
		c_byzantion = { location = { reverse_religion = ROOT } }
		add_character_modifier = { name = recently_converted duration = 730}
		ai_chance = {
			factor = 5
			modifier = {
				factor = 0
				trait = content
			}
		}
	}
}

character_event = { # Norman conquest of England cleanup - Victory: France loses claims
	id = Plus.329

	hide_window = yes
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		has_landed_title = k_france
		has_global_flag = bm_stamford
		has_global_flag = witan_abolished
		any_claim = {
			OR = {
				location = { region = custom_england }
				capital_scope = { region = custom_england }
				title = d_normandy
				de_jure_liege_or_above = d_normandy
			}
		}
	}
	
	weight_multiplier = {
		days = 1
	}
	
	immediate = {
		clr_global_flag = bm_stamford
		any_claim = {
			limit = {
				OR = {
					location = { region = custom_england }
					capital_scope = { region = custom_england }
					title = d_normandy
					de_jure_liege_or_above = d_normandy
				}
			}
			remove_claim = ROOT
		}
	}
}

character_event = { # Norman conquest of England cleanup - Loss: English provinces (back) to England
	id = Plus.330

	hide_window = yes
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		has_landed_title = d_normandy
		has_global_flag = bm_stamford
		k_england = { holder_scope = { culture = saxon } }
		war = no
		any_realm_title = {
			OR = {
				location = { region = custom_england }
				capital_scope = { region = custom_england }
			}
		}
		NOT = { has_global_flag = witan_abolished }
	}
	
	weight_multiplier = {
		days = 1
	}
	
	immediate = {
		clr_global_flag = bm_stamford
		k_england = {
			holder_scope = {
				k_england = {
					any_de_jure_vassal_title = {
						limit = {
							holder_scope = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
								}
							}
						}
						gain_title = PREVPREV
					}
				}
			}
		}
		if = {
			limit = { NOT = { has_claim = k_england } }
			add_claim = k_england
		}
	}
}

character_event = { # Fix changed CoA's on reload
	id = Plus.331
	
	hide_window = yes
	is_triggered_only = yes
	ai = no
	
	trigger = {
		NOT = { has_global_flag = fixed_coas }
		OR = {
			k_england = { has_title_flag = england_is_saxon }
			k_england = { has_title_flag = england_is_norman }
			k_england = { has_title_flag = england_is_norwegian }
			k_england = { has_title_flag = england_is_plantagenet }
			k_carpathia = { has_title_flag = carpathia_is_avaria }
			d_finland = { has_title_flag = finland_is_satakunta }
		}
	}
	
	immediate = {
		set_global_flag = fixed_coas
		if = {
			limit = { k_england = { has_title_flag = england_is_saxon } }
			k_england = { set_coa = k_england_saxon }
			d_canterbury = { set_coa = d_canterbury_saxon }
			d_cornwall = { set_coa = d_cornwall_saxon }
			d_gloucester = { set_coa = d_gloucester_saxon }
			d_hereford = { set_coa = d_hereford_saxon }
			d_lancaster = { set_coa = d_lancaster_saxon }
			d_norfolk = { set_coa = d_norfolk_saxon }
			d_oxford = { set_coa = d_oxford_saxon }
			d_somerset = { set_coa = d_somerset_saxon }
			d_york = { set_coa = d_york_saxon }
		}
		if = {
			limit = { k_england = { has_title_flag = england_is_norman } }
			k_england = { set_coa = k_england_norman }
			d_canterbury = { set_coa = d_canterbury_norman }
			d_cornwall = { set_coa = d_cornwall_norman }
			d_gloucester = { set_coa = d_gloucester_norman }
			d_hereford = { set_coa = d_hereford_norman }
			d_lancaster = { set_coa = d_lancaster_norman }
			d_norfolk = { set_coa = d_norfolk_norman }
			d_oxford = { set_coa = d_oxford_norman }
			d_somerset = { set_coa = d_somerset_norman }
			d_york = { set_coa = d_york_norman }
		}
		if = {
			limit = { k_england = { has_title_flag = england_is_norwegian } }
			k_england = { set_coa = k_englandnorwegian }
		}
		if = {
			limit = { k_england = { has_title_flag = england_is_plantaganet } }
			k_england = { set_coa = k_plantagenet }
		}
		if = {
			limit = { k_carpathia = { has_title_flag = carpathia_is_avaria } }
			k_carpathia = { set_coa = k_avaria }
		}
		if = {
			limit = { d_finland = { has_title_flag = finland_is_satakunta } }
			d_finland = { set_coa = d_satakunta }
		}
	}
}

province_event = { # Stops construction of the Third Temple if it is underway
	id = Plus.332
	
	hide_window = yes
	
	trigger = {
		province_id = 774
		has_province_flag = building_third_temple
		has_province_modifier = third_temple_builder
		OR = {
			NOT = { religion = jewish }
			owner = { top_liege = { NOT = { religion = jewish } } }
			owner = { top_liege = { NOT = { completely_controls = c_jerusalem } } }
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		clr_province_flag = building_third_temple
		remove_province_modifier = third_temple_builder
	}
}

province_event = { # Finishes construction of the Third Temple
	id = Plus.333
	
	hide_window = yes
	
	trigger = {
		religion = jewish
		province_id = 774
		has_province_flag = building_third_temple
		NOT = { has_province_modifier = third_temple_builder }
		owner = {
			war = no
			top_liege = {
				war = no
				religion = jewish
				completely_controls = c_jerusalem
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		clr_province_flag = building_third_temple
		set_province_flag = third_temple_built
		owner = {
			top_liege = { narrative_event = { id = SoA.101 } }
		}
	}
}

character_event = { # Adds the flag for the 'Civilize a Province' ambition
	id = Plus.334 #formerly 1000182009
	desc = EVTDESC_Plus_334
	picture = GFX_evt_throne_room

	is_triggered_only = yes
	hide_from = yes

	option = {
		name = EXCELLENT
		hidden_tooltip = {
			set_character_flag = civilized_province
		}
	}
}

character_event = { # Adds the Yehudi trait to Jews and children of Jews
	id = Plus.335
	
	hide_window = yes
	is_triggered_only = yes
	
	religion_group = jewish_group
	
	trigger = {
		NOT = { trait = yehudi }
		NOT = { has_character_flag = yehudi_check }
	}
	
	weight_multiplier = {
		days = 1
	}
	
	immediate = {
		set_character_flag = yehudi_check
		if = {
			limit = {
				is_ruler = yes
				primary_title = { is_theocracy = yes }
			}
			add_trait = yehudi
		}
		if = {
			limit = { 
				is_ruler = no
			}
			random = {
				chance = 70
				add_trait = yehudi
			}
		}
	}
}

character_event = { # Get rid of siege effects once war is done
	id = Plus.336

	hide_window = yes
	
	has_character_flag = has_siege_effect
	war = no
	
	trigger = {
		NOR = {
			war = yes
			liege = { war = yes }
		}
		in_siege = no
		OR = {
			has_character_modifier = stalwart_defender
			has_character_modifier = left_at_siege
			has_character_modifier = escaped_siege
			has_character_flag = defending_the_castle
			any_courtier = {
				OR = {
					has_character_modifier = stalwart_defender
					has_character_modifier = left_at_siege
					has_character_modifier = escaped_siege
					has_character_flag = defending_the_castle
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 30
	}
	
	immediate = {
		clr_character_flag = has_siege_effect
		clr_character_flag = defending_the_castle
		remove_character_modifier = stalwart_defender
		remove_character_modifier = left_at_siege
		remove_character_modifier = escaped_siege
		if = {
			limit = { is_ruler = yes }
			any_courtier = {
				limit = {
					has_character_flag = has_siege_effect
					NOR = {
						war = yes
						liege = { war = yes }
					}
					in_siege = no
				}
				clr_character_flag = has_siege_effect
				clr_character_flag = defending_the_castle
				remove_character_modifier = stalwart_defender
				remove_character_modifier = left_at_siege
				remove_character_modifier = escaped_siege
			}
		}
	}
}

character_event = { # Clear siege modifiers/hiding trait if imprisoned
	id = Plus.337
	
	hide_window = yes
	
	prisoner = yes
	
	trigger = {
		OR = {
			is_inaccessible_trigger = yes
			has_character_modifier = stalwart_defender
			has_character_modifier = left_at_siege
			has_character_modifier = escaped_siege
			has_character_flag = defending_the_castle
			has_character_flag = has_siege_effect
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		end_inaccessibility_effect = yes
		remove_character_modifier = stalwart_defender
		remove_character_modifier = left_at_siege
		remove_character_modifier = escaped_siege
		clr_character_flag = has_siege_effect
		clr_character_flag = defending_the_castle
		clr_character_flag = in_hiding_murder
		clr_character_flag = in_hiding_siege
	}
}

character_event = { # HRE Auto-Destroy Mechanic. Destroys the HRE if the ruler is no longer Catholic (or replacement heresy)
	id = Plus.338
	desc = "EVTDESC_Plus_338"
	picture = "GFX_evt_council"
	
	is_triggered_only = yes
	hide_from = yes
	
	only_independent = yes
	only_playable = yes

	trigger = {
		has_landed_title = e_hre
		NOT = { 
			any_realm_title = {
				NOT = { title = e_hre }
				tier = EMPEROR
			}
		}
		NOR = {
			religion = chalcedonian
			religion = catholic
			religion = cathar
			religion = fraticelli
			religion = waldensian
			religion = lollard
			religion = adoptionist
		}
		war = no
	}

	option = {
		name = "OK"
		if = {
			limit = { trait = crowned_by_pope }
			remove_trait = crowned_by_pope
			add_trait = crowned
		}
		if = {
			limit = {
				realm_size = 150
				NOT = { num_of_emperor_titles = 2 }
				OR = {
					e_germany = { has_holder = yes }
					NOT = { german_cultures_trigger = yes }
				}
			}
			capital_scope = {
				kingdom = {
					if = {
						limit = { NOT = { has_title_flag = emergency_empire_title } }
						set_title_flag = emergency_empire_title
						create_title = {
							tier = EMPEROR
							landless = no
							temporary = no
							custom_created = yes
							culture = ROOT
							holder = ROOT
							base_title = THIS
						}
						new_title = {
							set_title_flag = custom_created_title
							copy_title_laws = e_hre
							revoke_law = kingdom_lockout_1
							revoke_law = kingdom_lockout_0
							make_primary_title = yes
						}
					}
				}
			}
		}
		if = {
			limit = {
				german_cultures_trigger = yes
				e_germany = { has_holder = no }
			}
			if = {
				limit = { NOT = { is_title_active = e_germany } }
				activate_title = { title = e_germany status = yes }
			}
			set_character_flag = centralize_without_penalties
			e_germany = {
				hidden_tooltip = {
					copy_title_laws = e_hre
				}
				gain_title = ROOT
				make_primary_title = yes
			}
			hidden_tooltip = {
				any_title = {
					limit = {
						rebel = no
						has_holder = yes
						is_primary_holder_title = yes
						holder_scope = { top_liege = { character = PREV } }
					}
					holder_scope = {
						if = {
							limit = { has_weak_claim = e_hre }
							add_weak_pressed_claim = e_germany
							remove_claim = e_hre
						}
						if = {
							limit = { has_strong_claim = e_hre }
							add_pressed_claim = e_germany
							remove_claim = e_hre
						}
						any_realm_character = {
							if = {
								limit = { has_weak_claim = e_hre }
								add_weak_pressed_claim = e_germany
								remove_claim = e_hre
							}
							if = {
								limit = { has_strong_claim = e_hre }
								add_pressed_claim = e_germany
								remove_claim = e_hre
							}
						}
					}
				}
			}
			clr_character_flag = centralize_without_penalties
		}
		e_hre = {
			destroy_landed_title = yes
		}
		hidden_tooltip = {
			any_vassal = {
				limit = {
					NOT = { has_character_flag = considered_for_independence }
					primary_title = { de_jure_liege_or_above = e_hre }
				}
				character_event = { id = Plus.430 days = 3 }
			}
		}
		ai_chance = {
			factor = 2
			modifier = {
				factor = 0
				trait = cynical
			}
			modifier = {
				factor = 0
				trait = ambitious
			}
		}
	}
	
	option = {
		name = "I_WILL_CONVERT" #Then I will convert!
		trigger = {
			NOT = { trait = zealous}
			OR = {
				religion_group = christian
				religion_group = pagan_group
			}
			capital_scope = {
				OR = {
					region = custom_frisia
					region = custom_germany
					region = custom_lotharingia
					region = custom_pomerania
					region = custom_poland
					region = custom_bohemia
					region = custom_france
				}
				OR = {
					religion = chalcedonian
					religion = catholic
					religion = cathar
					religion = fraticelli
					religion = waldensian
					religion = lollard
					religion = adoptionist
				}
			}
		}
		if = {
			limit = {
				religion_group = pagan_group
			}
			add_trait = sympathy_pagans
		}
		if = {
			limit = {
				religion_group = christian
			}
			add_trait = sympathy_christendom
		}
		capital_scope = { reverse_religion = ROOT }
		add_character_modifier = { name = recently_converted duration = 730}
		ai_chance = {
			factor = 5
			modifier = {
				factor = 0
				trait = content
			}
		}
	}
}

character_event = { # Change scarred/beauty trait on females
	id = Plus.339
	
	hide_window = yes
	is_triggered_only = yes
	
	only_women = yes
	
	trigger = {
		OR = {
			trait = scarred
			AND = {
				trait = beauty
				age = 45
			}
		}
	}
	
	weight_multiplier = {
		days = 1
	}
	
	immediate = {
		if = {
			limit = { trait = scarred }
			remove_trait = scarred
			add_trait = scarred_female
		}
		if = {
			limit = {
				trait = beauty
				age = 45
			}
			remove_trait = beauty
		}
	}
}

character_event = { # Clean up 'children serving in holy orders' chains upon appropriate parent death
# called on_death (so succession has not yet resolved?)

	id = Plus.340
	
	hide_window = yes
	is_triggered_only = yes
	
	has_dlc = "The Old Gods"
	
	trigger = { 
		any_child = {
			is_alive = yes
			OR = {
				has_character_flag = wants_gwydion
				has_character_flag = serving_varangian
				has_character_flag = wants_fianna
				has_character_flag = serving_celtic_order
			}
			has_opinion_modifier = { who = ROOT modifier = allowed_to_serve_holy_order }			
		}
	}
	
	immediate = {
		any_child = {
			limit = {
				is_alive = yes
				is_heir = no
				OR = {
					has_character_flag = serving_celtic_order
					has_character_flag = wants_gwydion
					has_character_flag = wants_fianna
				}
				has_opinion_modifier = { who = ROOT modifier = allowed_to_serve_holy_order }
			}									
			if = {
				limit = {
					has_character_flag = serving_celtic_order
				}
				random_list = {
					120 = {
						modifier = {
							factor = 1.33
							trait = brave
						}
						modifier = {
							factor = 0.8
							trait = craven
						}
						modifier = {
							factor = 0
							trait = scarred
						}						
						character_event = { id = ancrel.124 }
					}
					75 = {
						modifier = {
							factor = 0
							is_maimed_trigger = yes
						}
						character_event = { id = ancrel.128 }
					}
					120 = {
						modifier = {
							factor = 0
							trait = brilliant_strategist
						}
						modifier = {
							factor = 0
							NOR = {
								trait = misguided_warrior
								trait = tough_soldier
								trait = skilled_tactician
							}
						}
						modifier = {
							factor = 2
							trait = genius
						}
						modifier = {
							factor = 1.33
							trait = diligent
						}
						modifier = {
							factor = 1.33
							OR = {
								trait = quick
								trait = shrewd
							}
						}
						modifier = {
							factor = 0.66
							is_dumb_trigger = yes
						}
						character_event = { id = ancrel.130 }
					}
					110 = {
						modifier = {
							factor = 0
							trait = depressed
						}
						modifier = {
							factor = 1.33
							trait = kind
						}
						modifier = {
							factor = 1.33
							trait = poet
						}
						modifier = {
							factor = 1.33
							trait = just
						}
						character_event = { id = ancrel.132 }
					}
					110 = {
						modifier = {
							factor = 1.33
							trait = lustful
						}
						character_event = { id = ancrel.134 }
					}
					120 = {
						modifier = {
							factor = 0.5
							trait = cynical
						}
						modifier = {
							factor = 0
							trait = zealous
						}
						character_event = { id = ancrel.136 }
					}
					140 = {
						modifier = {
							factor = 1.33
							trait = brave
						}
						modifier = {
							factor = 1.33
							is_strong_trigger = yes
						}
						modifier = {
							factor = 1.33
							OR = {
								trait = quick
								trait = shrewd
							}
						}
						modifier = {
							factor = 1.33
							trait = genius
						}
						modifier = {
							factor = 0.66
							trait = slothful
						}
						modifier = {
							factor = 0.66
							is_dumb_trigger = yes
						}
						character_event = { id = ancrel.138 }
					}
					100 = {
						modifier = {
							factor = 1.33
							trait = brave
						}
						modifier = {
							factor = 1.33
							trait = wroth
						}
						modifier = {
							factor = 1.33
							trait = head1
						}
						modifier = {
							factor = 1.33
							trait = head2
						}
						modifier = {
							factor = 1.33
							trait = head3
						}
						modifier = {
							factor = 1.33
							trait = head4
						}
						modifier = {
							factor = 1.33
							trait = head5
						}
						modifier = {
							factor = 0.8
							trait = craven
						}
						modifier = {
							factor = 1.33
							trait = drunkard
						}
						modifier = {
							factor = 1.33
							trait = has_tuberculosis
						}
						modifier = {
							factor = 1.33
							trait = has_typhoid_fever
						}
						modifier = {
							factor = 1.33
							trait = has_typhus
						}
						modifier = {
							factor = 1.33
							trait = has_bubonic_plague
						}
						modifier = {
							factor = 1.33
							trait = has_measles
						}		
						modifier = {
							factor = 1.33
							trait = has_small_pox
						}
						modifier = {
							factor = 1.33
							trait = wounded
						}
						modifier = {
							factor = 2
							trait = infirm
						}
						modifier = {
							factor = 2
							trait = incapable
						}
						character_event = { id = ancrel.140 }
					}
					120 = {
						modifier = {
							factor = 1.33
							trait = greedy
						}
						modifier = {
							factor = 1.33
							stewardship = 10
						}
						character_event = { id = ancrel.142 }
					}
					1000 = {
						#child stays with order, clean up flags
						clr_character_flag = serving_celtic_order
					}
				}
			}			
			if = {
				limit = {
					OR = {
						has_character_flag = wants_gwydion
						has_character_flag = wants_fianna
					}
				}
				#chance to stay with the order (and eventually gain their veteran trait) or leave without it
				random_list = {
					50 = { #stay
						modifier = {
							factor = 1.25
							trait = zealous
						}
						modifier = {
							factor = 1.25
							trait = brave
						}
					}
					50 = { #leave
						modifier = {
							factor = 1.25
							trait = ambitious
						}
						clr_character_flag = wants_gwydion
						clr_character_flag = wants_fianna
						move_character = ROOT
					}
				}				
			}
		}
		any_child = {
			limit = {
				is_alive = yes				
				has_opinion_modifier = { who = ROOT modifier = allowed_to_serve_holy_order }
				has_character_flag = serving_varangian
			}
			if = {
				limit = { any_heir_title = { holder = ROOT } }
				move_character = ROOT
				character_event = { id = TOG.3134 }
			}
			if = {
				limit = { NOT = { any_heir_title = { holder = ROOT } } }
				character_event = { id = TOG.3135 }
			}
		}
	}
}

character_event = { # Ultimatum to overthrown rulers who re-inherit the throne
	id = Plus.341		

	is_triggered_only = yes		
	
	hide_window = yes

	immediate = {
		character_event = { id = Plus.342 days = 3 }
	}	
}

character_event = { # Ultimatum to overthrown rulers who re-inherit the throne
	id = Plus.342
	desc = "EVTDESC_Plus_341"
	picture = "GFX_evt_council"

	is_triggered_only = yes
	
	trigger = {	
		FROMFROM = {			
			is_primary_holder_title_tier = yes
			any_vassal = {								
				has_opinion_modifier = { who = ROOT modifier = overthrown_ruler }
				relative_power = { who = ROOT power = 0.25 }
			}		
		}
	}	
	
	immediate = {
		#assess power of demanders
		hidden_tooltip = {
			set_variable = { which = "ultimatum_power" value = "0" }			
			any_vassal = {
				limit = {
					de_jure_liege = FROMFROM
					has_opinion_modifier = { who = ROOT modifier = overthrown_ruler }
				}
				if = {
					limit = {
						relative_power = { who = ROOT power = 0.25 }
						NOT = { relative_power = { who = ROOT power = 0.5 } }
					}
					ROOT = { change_variable = { which = "ultimatum_power" value = "0.25" } }
				}
				if = {
					limit = {
						relative_power = { who = ROOT power = 0.5 }
						NOT = { relative_power = { who = ROOT power = 0.75 } }
					}
					ROOT = { change_variable = { which = "ultimatum_power" value = "0.5" } }
				}
				if = {
					limit = {
						relative_power = { who = ROOT power = 0.75 }
						NOT = { relative_power = { who = ROOT power = 1 } }
					}
					ROOT = { change_variable = { which = "ultimatum_power" value = "0.75" } }
				}
				if = {
					limit = {
						relative_power = { who = ROOT power = 1 }							
					}
					ROOT = { change_variable = { which = "ultimatum_power" value = "1" } }
				}
			}
		}
	}

	option = {
		name = "EVTDEMANDYES"
		#abdicate to next in line		
		ai_chance = {
			factor = 50
			modifier = {
				factor = 1.25
				is_weak_trigger = yes
			}
			modifier = {
				factor = 1.25
				trait = craven
			}
			modifier = {
				factor = 1.25
				trait = humble
			}
			modifier = {
				factor = 1.25
				trait = kind
			}
			modifier = {
				factor = 1.25
				trait = charitable
			}
			modifier = {
				factor = 1.25
				trait = patient
			}
			modifier = {
				factor = 1.25
				trait = content
			}
		}
		current_heir = {
			ROOT = { transfer_scaled_wealth = { to = PREV value = all } }
		}
		abdicate = yes
	}
	
	option = {
		name = "EVTDEMANDNO" #reject demand		
		ai_chance = {
			factor = 50
			modifier = {
				factor = 1.25
				is_strong_trigger = yes
			}
			modifier = {
				factor = 1.25
				trait = brave
			}
			modifier = {
				factor = 1.25
				trait = proud
			}
			modifier = {
				factor = 1.25
				trait = envious
			}
			modifier = {
				factor = 1.25
				trait = greedy
			}
			modifier = {
				factor = 1.25
				trait = wroth
			}
			modifier = {
				factor = 1.25
				trait = ambitious
			}
			modifier = {
				factor = 5.0
				NOT = { check_variable = { which = "ultimatum_power" value = "1" } }
			}
			modifier = {
				factor = 0.75
				check_variable = { which = "ultimatum_power" value = "1" }
			}
		}
		#a direct-vassal demander with sufficient power declares war, other demanders follow suit		
		random_vassal = {
			limit = {
				de_jure_liege = FROMFROM
				has_opinion_modifier = { who = ROOT modifier = overthrown_ruler }
				relative_power = { who = ROOT power = 0.25 }
			}
			war = {
				target = ROOT
				casus_belli = overthrow_ruler
			}
			FROMFROM = {
				any_vassal = {
					limit = {													
						has_opinion_modifier = { who = ROOT modifier = overthrown_ruler }
					}
					join_attacker_wars = PREVPREV
				}
			}
		}
	}
}

character_event = { # Secondary Startup Event for RD rulers
	id = Plus.343
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		# properly set Agnatic-Cognatic succession default for female rulers
		if = {
			limit = {
				is_female = yes
				primary_title = { has_law = agnatic_succession }
			}
			primary_title = { add_law = cognatic_succession }
			recalc_succession = yes
		}
		
		# fire the Byzantium startup event
		if = {
			limit = { has_landed_title = e_byzantium }
			narrative_event = { id = Plus.1300 }
			narrative_event = { id = Plus.1301 }
			narrative_event = { id = Plus.1302 }
			narrative_event = { id = Plus.1303 }
		}
		
		# get rid of TOM's caused by councillors being fired
		any_vassal = {
			if = {
				limit = { has_opinion_modifier = { who = ROOT modifier = opinion_fired_from_council } }
				remove_opinion = { who = ROOT modifier = opinion_fired_from_council }
			}
			if = {
				limit = { has_opinion_modifier = { who = ROOT modifier = opinion_recently_fired } }
				remove_opinion = { who = ROOT modifier = opinion_recently_fired }
			}
		}
		any_courtier = {
			if = {
				limit = { has_opinion_modifier = { who = ROOT modifier = opinion_fired_from_council } }
				remove_opinion = { who = ROOT modifier = opinion_fired_from_council }
			}
			if = {
				limit = { has_opinion_modifier = { who = ROOT modifier = opinion_recently_fired } }
				remove_opinion = { who = ROOT modifier = opinion_recently_fired }
			}
		}
	}
}

character_event = { # Adds Uncrowned trait to all new independent kings and emperors
	id = Plus.344
	
	hide_window = yes
	
	only_playable = yes
	only_rulers = yes
	only_independent = yes
	war = no
	
	trigger = {
		is_feudal = yes
		higher_real_tier_than = DUKE
		has_horde_culture = no
		is_nomadic = no
		primary_title = { is_vice_royalty = no }
		NOR = {
			trait = crowned
			trait = uncrowned
			trait = crowned_by_pope
			trait = strong_basileus
			trait = weak_basileus
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		add_trait = uncrowned
	}
}

character_event = { # Removes In Hiding trait from characters who no longer have someone to remove it
	id = Plus.345
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_inaccessible_trigger = yes
		is_ruler = no
		in_siege = no
		liege = { war = no }
		NOR = {
			AND = {
				has_character_flag = in_hiding_murder
				liege = {
					OR = {
						any_spouse = { character = ROOT }
						any_child = { character = ROOT }
					}
				}
			}
			AND = {
				has_character_flag = in_hiding_siege
				liege = { is_close_relative = ROOT }
			}
		}
	}
	
	weight_multiplier = {
		days = 1
	}
	
	immediate = {
		end_inaccessibility_effect = yes
		clr_character_flag = in_hiding_murder
		clr_character_flag = in_hiding_siege
	}
}

character_event = { # Removes austerity modifier from non-AI characters
	id = Plus.346
	
	hide_window = yes
	is_triggered_only = yes
	ai = no
	
	trigger = {
		has_character_modifier = ai_austerity
	}
	
	weight_multiplier = {
		days = 1
	}
	
	immediate = {
		remove_character_modifier = ai_austerity
	}
}

character_event = { # Secondary Startup event
	id = Plus.347
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		# make changes for pre-schism bookmarks
		if = {
			limit = {
				NOT = { k_papal_state = { has_title_flag = schism_happened } }
				NOT = { has_global_flag = schism_happened }
				NOT = { e_placeholder = { has_title_flag = pre_schism_setup } }
				NOT = { e_placeholder = { has_title_flag = secondary_startup } }
				NOT = { has_global_flag = pre_schism_setup }
			}
			e_placeholder = { set_title_flag = pre_schism_setup }
			
			# advance tracker if Carolingian Empire already formed
			if = {
				limit = { e_karling = { NOT = { has_title_flag = carolingian_empire_formed } } }
				496 = { set_variable = { which = "schism_tracker" value = 0 } }
			}
			if = {
				limit = { e_karling = { has_title_flag = carolingian_empire_formed } }
				496 = { set_variable = { which = "schism_tracker" value = 1 } }
			}
			
			# advance tracker if using New Millenium bookmark
			if = {
				limit = { year = 999 }
				set_global_flag = filioque_adopted
				set_global_flag = eucharist_conflict
				496 = { change_variable = { which = "schism_tracker" value = 2 } }
			}
			
			# set catholic/orthodox heresies to chalcedonian
			set_parent_religion = { religion = cathar parent = chalcedonian }
			set_parent_religion = { religion = waldensian parent = chalcedonian }
			set_parent_religion = { religion = lollard parent = chalcedonian }
			set_parent_religion = { religion = adoptionist parent = chalcedonian }
			set_parent_religion = { religion = bogomilist parent = chalcedonian }
			set_parent_religion = { religion = monothelite parent = chalcedonian }
			set_parent_religion = { religion = iconoclast parent = chalcedonian }
			
			# get rid of the Pope and the Ecumenical Patriach
			any_title = {
				limit = {
					has_holder = yes
					OR = {
						title = k_papal_state
						title = k_orthodox
					}
				}
				unsafe_destroy_landed_title = THIS
				activate_title = { title = THIS status = no }
			}

			# switch any remaining characters
			any_character = {
				if = {
					limit = { religion = catholic }
					religion = chalcedonian
				}
				if = {
					limit = { religion = orthodox }
					religion = chalcedonian
				}
				if = {
					limit = {
						religion = chalcedonian
						independent = yes
					}
					character_event = { id = Plus.2289 }
				}
			}
		}
		
		# reset matrilineal marriage settings
		if = {
			limit = { NOT = { e_placeholder = { has_title_flag = secondary_startup } } }
			any_title = {
				limit = {
					has_holder = yes
					is_primary_holder_title = yes
				}
				if = {
					limit = {
						has_law = agnatic_succession
						NOT = { has_law = female_council_law_2 }
					}
					set_allows_matrilineal_marriage = no
				}
				if = {
					limit = {
						OR = {
							NOT = { has_law = agnatic_succession }
							has_law = female_council_law_2
						}
					}
					set_allows_matrilineal_marriage = yes
				}
			}
		}
		
		# remove undesireable claims and perform genetics check
		any_character = {
			limit = { NOT = { has_character_flag = start_of_game_character } }
			set_character_flag = start_of_game_character
			character_event = { id = Plus.323 } #remove undesirable claims
			if = {
				limit = { NOT = { has_character_flag = genetics_check } }
				character_event = { id = Plus.324 } # pass on traits they would have had at birth
			}
		}

		# add children, primarily daughters, for early bookmarks
		random_playable_ruler = {
			limit = {
				age = 32
				OR = {
					higher_tier_than = BARON
					is_patrician = yes
				}
				has_character_flag = start_of_game_character
				NOR = {
					holy_order = yes
					mercenary = yes
					is_theocracy = yes
					year = 1065
					any_child = { is_female = yes }
					has_character_flag = daughter_check
					e_placeholder = { has_title_flag = secondary_startup }
				}
				OR = {
					NOR = {
						has_law = cognatic_succession
						has_law = true_cognatic_succession
					}
					any_child = { NOT = { trait = bastard } age = 22 }
					AND = {
						has_law = cognatic_succession
						any_child = { NOT = { trait = bastard } is_female = no }
					}
				}
			}
			character_event = { id = Plus.358 }
		}
		
		# set appropriate succession laws where gavelkind is not wanted.
		# where multiple entries exist the lowest entry takes priority
		
		any_title = {
			limit = {
				is_primary_holder_title = yes
				temporary = no
				has_holder = yes
				higher_tier_than = BARON
				has_law = succ_gavelkind
				NOT = { # Override flag
					has_title_flag = pre_set_gavelkind
				}
				holder_scope = {
					NOR = { # All of these retain gavelkind
						AND = {
							religion_group = pagan_group
							NOT = {
								# Pagans who exceptionally DON'T get gavelkind
								elective_gavelkind_culture_trigger = yes
								seniority_culture_trigger = yes
								religion = celtic_pagan
							}
						}
						AND = {
							gavelkind_culture_trigger = yes
							NOT = { year = 1150 }
						}
					}
				}
			}
			
			holder_scope = { # Elective Gavelkind
				if = {
					limit = {
						NOT = { religion = celtic_pagan }
						OR = {
							is_feudal = yes
							is_tribal = yes
						}
						elective_gavelkind_culture_trigger = yes
					}
					PREV = { add_law = succ_elective_gavelkind }
				}
			}

			holder_scope = { # Seniority
				if = {
					limit = {
						OR = {
							is_republic = no
							is_patrician = yes
						}
						OR = {
							is_feudal = yes
							is_patrician = yes
						}
						seniority_culture_trigger = yes
					}
					PREV = { add_law = succ_seniority }
				}
			}
			
			holder_scope = { # Tanistry
				if = {
					limit = {
						OR = {
							is_feudal = yes
							is_tribal = yes
						}
						OR = {
							culture_group = celtic
							religion = celtic_pagan
						}
					}
					PREV = { add_law = succ_tanistry }
				}
			}
			holder_scope = { # Late Medieval Primogeniture
				if = {
					limit = {
						is_feudal = yes
						year = 1150
						has_law = succ_gavelkind
						capital_scope = { TECH_LEGALISM = 3 }
					}
					PREV = { add_law = succ_primogeniture }
				}
			}
			holder_scope = { # Late Medieval Elective
				if = {
					limit = {
						is_feudal = yes
						year = 1150
						has_law = succ_elective_gavelkind
						capital_scope = { TECH_LEGALISM = 3 }
					}
					PREV = { add_law = succ_feudal_elective }
				}
			}
		}
		
		# set appropriate demesne laws level
		any_title = {
			limit = {
				temporary = no
				has_holder = yes
				is_primary_holder_title = yes
				holder_scope = {
					is_landed = yes
					higher_tier_than = BARON
				}
			}
			if = {
				limit = {
					holder_scope = {
						capital_scope = {
							NOT = { TECH_LEGALISM = 2 }
						}
					}
					NOT = { has_law = demesne_laws_0 }
				}
				add_law = demesne_laws_0
			}
			if = {
				limit = {
					holder_scope = {
						capital_scope = {
							TECH_LEGALISM = 2
							NOT = { TECH_LEGALISM = 4 }
						}
					}
					NOT = { has_law = demesne_laws_1 }
				}
				add_law = demesne_laws_1
			}
			if = {
				limit = {
					holder_scope = {
						capital_scope = {
							TECH_LEGALISM = 4
							NOT = { TECH_LEGALISM = 6 }
						}
					}
					NOT = { has_law = demesne_laws_2 }
				}
				add_law = demesne_laws_2
			}
			if = {
				limit = {
					holder_scope = {
						capital_scope = {
							TECH_LEGALISM = 6
							NOT = { TECH_LEGALISM = 8 }
						}
					}
					NOT = { has_law = demesne_laws_3 }
				}
				add_law = demesne_laws_3
			}
			if = {
				limit = {
					holder_scope = {
						capital_scope = {
							TECH_LEGALISM = 8
						}
					}
					NOT = { has_law = demesne_laws_4 }
				}
				add_law = demesne_laws_4
			}
		}
		
		# set the king's peace to 0 if none are active
		any_title = {
			limit = {
				tier = KING
				NOR = {
					has_law = kings_peace_0
					has_law = kings_peace_1
					has_law = kings_peace_2
				}
			}
			add_law = kings_peace_0
		}	

		# set the culture conversion law to default if none are active
		any_title = {
			limit = {
				higher_tier_than = DUKE
				is_law_potential = culture_conversion_1
				NOR = {
					has_law = culture_conversion_0
					has_law = culture_conversion_1
					has_law = culture_conversion_2
				}
			}
			add_law = culture_conversion_1
		}
		
		# mark titles that start at CA 0 and should not be destroyed if reduced
		any_title = {
			limit = {
				has_holder = yes
				higher_tier_than = DUKE
				has_law = crown_authority_0
				NOT = { has_title_flag = do_not_destroy }
			}
			set_title_flag = do_not_destroy
		}

		# double-check governments in imperial realms
		if = {
			limit = { NOT = { e_placeholder = { has_title_flag = secondary_startup } } }
			any_character = {
				limit = {
					independent = yes
					is_feudal = yes
					has_imperial_government_trigger = no
					primary_title = {
						tier = EMPEROR
						has_law = imperial_administration
						has_title_flag = has_imperial_administration
					}
				}
				switch_to_imperial_effect = yes
			}
			any_character = {
				limit = {
					is_ruler = yes
					independent = yes
					has_imperial_government_trigger = yes
					NOT = {
						primary_title = {
							tier = EMPEROR
							has_law = imperial_administration
							has_title_flag = has_imperial_administration
						}
					}
				}
				switch_to_feudal_effect = yes
			}
			any_character = {
				limit = {
					is_ruler = yes
					independent = no
					has_imperial_government_trigger = yes
					NOT = { top_liege = { has_imperial_government_trigger = yes } }
				}
				switch_to_feudal_effect = yes
			}
			any_character = {
				limit = {
					is_ruler = yes
					independent = no
					is_feudal = yes
					top_liege = { has_imperial_government_trigger = yes }
				}
				if = {
					limit = {
						has_imperial_government_trigger = no
						NOT = { primary_title = { has_title_flag = viceroy_exemption } }
					}
					switch_to_imperial_effect = yes
				}
				if = {
					limit = {
						has_imperial_government_trigger = yes
						primary_title = { has_title_flag = viceroy_exemption }
					}
					switch_to_feudal_effect = yes
				}
			}
		}
		
		# give crowned trait to all existing kings and emperors
		any_character = {
			limit = {
				is_playable = yes
				higher_real_tier_than = DUKE
				is_adult = yes
				is_feudal = yes
				has_horde_culture = no
				is_nomadic = no
				primary_title = { is_vice_royalty = no }
				independent = yes
				NOR = {
					trait = crowned
					trait = uncrowned
					has_landed_title = e_hre
					has_landed_title = e_karling
					has_landed_title = e_byzantium
				}
			}
			add_trait = crowned
		}
		
		# give uncrowned trait to everyone else
		any_character = {
			limit = {
				is_playable = yes
				higher_real_tier_than = DUKE
				is_feudal = yes
				has_horde_culture = no
				is_nomadic = no
				independent = yes
				primary_title = { is_vice_royalty = no }
				NOR = {
					trait = crowned
					trait = uncrowned
					trait = crowned_by_pope
					trait = strong_basileus
					trait = weak_basileus
				}
			}
			add_trait = uncrowned
		}

		# fire appropriate startup event for Byzantium
		e_byzantium = {
			holder_scope = {
				narrative_event = { id = Plus.1300 }
				narrative_event = { id = Plus.1301 }
				narrative_event = { id = Plus.1302 }
				narrative_event = { id = Plus.1303 }
			}
		}
		
		# fire decadence modifier for other emperors
		any_character = {
			limit = {
				NOT = { e_placeholder = { has_title_flag = secondary_startup } }
				NOT = { has_landed_title = e_byzantium }
				NOT = { uses_decadence = yes }
				is_nomadic = no
				real_tier = EMPEROR
			}
			character_event = { id = Plus.1852 days = 1 }
		}
		
		# give more money to merchant republics
		if = {
			limit = { NOT = { e_placeholder = { has_title_flag = secondary_startup } } }
			any_character = {
				limit = { is_merchant_republic = yes }
				scaled_wealth = 2.0
				any_vassal = {
					limit = { is_patrician = yes }
					scaled_wealth = 1.0
				}
			}
		}

		# warning for ironman games
		if = {
			limit = {
				is_ironman = yes
				NOT = { e_placeholder = { has_title_flag = secondary_startup } }
			}
			any_character = {
				limit = { ai = no }
				character_event = { id = Plus.1752 }
			}
		}
		
		e_placeholder = { set_title_flag = secondary_startup }
	}
}

character_event = { # Viceroys will try to pass on wealth to a relative instead of their liege
	id = Plus.348
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		any_demesne_title = { is_vice_royalty = yes }
	}
	
	immediate = {
		any_demesne_title = {
			limit = { is_vice_royalty = yes }
			save_event_target_as = lose_strong
			ROOT = {
				any_child = {
					limit = {
						is_alive = yes
						NOT = { has_strong_claim = PREVPREV }
					}
					character_event = { id = Plus.355 days = 1 }
				}
			}
		}
		if = {
			limit = { primary_title = { is_vice_royalty = yes } }
			random_demesne_title = {
				limit = {
					OR = {
						AND = {
							tier = DUKE
							ROOT = { primary_title = { tier = KING } }
						}
						AND = {
							tier = COUNT
							ROOT = {
								primary_title = { tier = KING }
								NOT = {
									any_demesne_title = {
										tier = DUKE
										is_vice_royalty = no
									}
								}
							}
						}
						AND = {
							tier = COUNT
							ROOT = { primary_title = { tier = DUKE } }
						}
						is_vice_royalty = no
						current_heir = {
							NOT = { is_liege_of = ROOT }
						}
					}
				}
				current_heir = {
					save_event_target_as = viceroy_heir
				}
			}
			if = {
				limit = { NOT = { event_target:viceroy_heir = { is_alive = yes } } }
				clear_wealth = yes
				remove_character_modifier = loan_50
				remove_character_modifier = loan_50_hidden
				remove_character_modifier = loan_100
				remove_character_modifier = loan_100_hidden
				remove_character_modifier = loan_200
				remove_character_modifier = loan_200_hidden
				remove_character_modifier = loan_400
				remove_character_modifier = loan_400_hidden
				remove_character_modifier = loan_600
				remove_character_modifier = loan_600_hidden
				remove_character_modifier = loan_800
				remove_character_modifier = loan_800_hidden
				remove_character_modifier = loan_1000
				remove_character_modifier = loan_1000_hidden
				remove_character_modifier = loan_timer_jews
				remove_character_modifier = borrowed_from_jews
				break = yes
			}
			event_target:target_viceroy_heir = {
				ROOT = {
					transfer_scaled_wealth = {
						to = PREV
						value = all
					}
				}
			}
			if = {
				limit = { has_character_flag = loan_taken }
				if = {
					limit = { has_character_modifier = loan_50 }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_50
							duration = 730
							inherit = yes						
						}
					}
					remove_character_modifier = loan_50
				}
				if = {
					limit = { has_character_modifier = loan_50_hidden }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_50_hidden
							duration = -1
							inherit = yes
							hidden = yes
						}
					}
					remove_character_modifier = loan_50_hidden
				}
				if = {
					limit = { has_character_modifier = loan_100 }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_100
							duration = 730
							inherit = yes						
						}
					}
					remove_character_modifier = loan_100
				}
				if = {
					limit = { has_character_modifier = loan_100_hidden }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_100_hidden
							duration = -1
							inherit = yes
							hidden = yes
						}
					}
					remove_character_modifier = loan_100_hidden
				}
				if = {
					limit = { has_character_modifier = loan_200 }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_200
							duration = 730
							inherit = yes						
						}
					}
					remove_character_modifier = loan_200
				}
				if = {
					limit = { has_character_modifier = loan_200_hidden }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_200_hidden
							duration = -1
							inherit = yes
							hidden = yes
						}
					}
					remove_character_modifier = loan_200_hidden
				}
				if = {
					limit = { has_character_modifier = loan_400 }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_400
							duration = 730
							inherit = yes						
						}
					}
					remove_character_modifier = loan_400
				}
				if = {
					limit = { has_character_modifier = loan_400_hidden }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_400_hidden
							duration = -1
							inherit = yes
							hidden = yes
						}
					}
					remove_character_modifier = loan_400_hidden
				}
				if = {
					limit = { has_character_modifier = loan_600 }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_600
							duration = 730
							inherit = yes						
						}
					}
					remove_character_modifier = loan_600
				}
				if = {
					limit = { has_character_modifier = loan_600_hidden }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_600_hidden
							duration = -1
							inherit = yes
							hidden = yes
						}
					}
					remove_character_modifier = loan_600_hidden
				}
				if = {
					limit = { has_character_modifier = loan_800 }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_800
							duration = 730
							inherit = yes						
						}
					}
					remove_character_modifier = loan_800
				}
				if = {
					limit = { has_character_modifier = loan_800_hidden }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_800_hidden
							duration = -1
							inherit = yes
							hidden = yes
						}
					}
					remove_character_modifier = loan_800_hidden
				}
				if = {
					limit = { has_character_modifier = loan_1000 }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_1000
							duration = 730
							inherit = yes						
						}
					}
					remove_character_modifier = loan_1000
				}
				if = {
					limit = { has_character_modifier = loan_1000_hidden }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = loan_1000_hidden
							duration = -1
							inherit = yes
							hidden = yes
						}
					}
					remove_character_modifier = loan_1000_hidden
				}
				if = {
					limit = { has_character_modifier = loan_timer_jews }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = "loan_timer_jews"
							duration = 730
							inherit = yes
						}
					}
					remove_character_modifier = loan_timer_jews
				}
				if = {
					limit = { has_character_modifier = borrowed_from_jews }
					event_target:target_viceroy_heir = {
						add_character_modifier = {
							name = "borrowed_from_jews"
							duration = -1
							inherit = yes
							hidden = yes
						}
					}
					remove_character_modifier = borrowed_from_jews
				}
			}
		}
	}
}

character_event = { # Annual maintenance fixes
	id = Plus.349
	
	hide_window = yes
	is_triggered_only = yes
	
	only_rulers = yes
	
	immediate = {
		#remove tribute status on non-independent overlords/tributes
		if = {
			limit = {
				is_tributary = yes
				OR = {
					independent = no
					suzerain = { independent = no }
				}
			}
			suzerain = {
				log = "---> (Annual Maintenance) [This.GetBestName] was removed as suzerain of [Root.GetBestName], as one of them is not independent"
				remove_tributary = ROOT
			}
		}
		
		#track years_of_peace variable for the ambition
		if = {
			limit = { war = yes }
			set_variable = { which = "years_of_peace" value = 0 }
		}
		if = {
			limit = { war = no }
			change_variable = { which = "years_of_peace" value = 1 }
		}
		
		#fix primary titles that have become inactive
		if = {
			limit = {
				primary_title = { NOT = { is_title_active = THIS } }
			}
			primary_title = {
				log = "---> (Annual Maintenance) [This.GetFullName] was set to active, as it is currently held"
				activate_title = { title = THIS status = yes }
			}
		}
		
		#check matrilineal marriage status for players
		if = {
			limit = { ai = no }
			primary_title = {
				if = {
					limit = {
						has_law = agnatic_succession
						NOT = { has_law = female_council_law_2 }
					}
					set_allows_matrilineal_marriage = no
				}
				if = {
					limit = {
						OR = {
							NOT = { has_law = agnatic_succession }
							has_law = female_council_law_2
						}
					}
					set_allows_matrilineal_marriage = yes
				}
			}
		}
		
		#remove 'do not destroy' flag on titles that have raised crown authority
		any_demesne_title = {
			limit = {
				has_title_flag = do_not_destroy
				OR = {
					has_law = crown_authority_1
					has_law = crown_authority_2
					has_law = crown_authority_3
					has_law = crown_authority_4
				}
			}
			clr_title_flag = do_not_destroy
			log = "---> (Annual Maintenance) [This.GetFullName] had the do_not_destroy flag removed, as it has raised Crown Authority"
		}
		
		#remove 'destroy' flag on titles which were not destroyed
		any_demesne_title = {
			limit = { had_title_flag = { flag = destroy_title days = 7 } }
			clr_title_flag = destroy_title
		}
		
		#add crown law if they should have it
		any_demesne_title = {
			limit = {
				temporary = no
				higher_tier_than = DUKE
				NOR = {
					has_law = crown_authority_0
					has_law = crown_authority_1
					has_law = crown_authority_2
					has_law = crown_authority_3
					has_law = crown_authority_4
				}
				holder_scope = {
					in_revolt = no
					is_tribal = no
					is_nomadic = no
				}
			}
			add_law = crown_authority_0
			log = "---> (Annual Maintenance) [This.GetFullName] has had Crown Authority added, as it had none"
		}
		
		# set the king's peace to 0 if none are active
		any_demesne_title = {
			limit = {
				higher_tier_than = DUKE
				NOR = {
					has_law = kings_peace_0
					has_law = kings_peace_1
					has_law = kings_peace_2
				}
			}
			add_law = kings_peace_0
		}	

		# set the culture conversion law to default if none are active
		any_demesne_title = {
			limit = {
				higher_tier_than = DUKE
				is_law_potential = culture_conversion_1
				NOR = {
					has_law = culture_conversion_0
					has_law = culture_conversion_1
					has_law = culture_conversion_2
				}
			}
			add_law = culture_conversion_1
		}

		#fix patrician succession laws
		any_demesne_title = {
			limit = {
				is_primary_type_title = no
				holder_scope = { is_patrician = yes }
				OR = {
					NOT = { has_law = succ_seniority }
					NOT = { has_law = agnatic_succession }
				}
				OR = {
					is_primary_holder_title = no
					holder_scope = { is_merchant_republic = no }
				}
			}
			current_inheritance_laws_effect = yes
			if = {
				limit = { NOT = { has_law = succ_seniority } }
				log = "---> (Annual Maintenance) [This.GetID] changed to Seniority -- holder is patrician"
				succession = seniority
			}
			if = {
				limit = { NOT = { has_law = agnatic_succession } }
				log = "---> (Annual Maintenance) [This.GetID] changed to Agnatic -- holder is patrician"
				gender_succ = agnatic
			}
		}
		any_demesne_title = {
			limit = {
				holder_scope = {
					is_patrician = yes
					is_merchant_republic = yes
				}
				OR = {
					NOT = { has_law = succ_patrician_elective }
					NOT = { has_law = agnatic_succession }
				}
				is_primary_holder_title = yes
				is_primary_type_title = no
			}
			current_inheritance_laws_effect = yes
			if = {
				limit = { NOT = { has_law = succ_patrician_elective } }
				log = "---> (Annual Maintenance) [This.GetID] changed to Patrician Elective -- holder is merchant republic"
				succession = patrician_elective
			}
			if = {
				limit = { NOT = { has_law = agnatic_succession } }
				log = "---> (Annual Maintenance) [This.GetID] changed to Agnatic -- holder is merchant republic"
				gender_succ = agnatic
			}
		}
		
		#fix non-patrician succession laws
		any_demesne_title = {
			limit = {
				temporary = no
				holder_scope = { is_patrician = no }
				OR = {
					is_primary_holder_title = yes
					higher_tier_than = duke
				}
			}
			#fix unreadable succession laws
			if = {
				limit = { emf_laws_has_readable_succession_law_trigger = no }
				current_inheritance_laws_effect = yes
				log = "---> (Annual Maintenance) [This.GetID] has no readable succession law, attempting to fix"
				save_event_target_as = pf_new_title
				
				#first check for top-level defaults
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_patrician_elective
							NOT = { has_title_flag = fixed_succession_law }
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Patrician Elective succession"
						succession = patrician_elective
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_nomad_succession
							NOT = { has_title_flag = fixed_succession_law }
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Nomad succession"
						succession = nomad_succession
						set_title_flag = fixed_succession_law
					}
				}
				
				#then check for another title we can get the succession law from
				ROOT = {
					random_demesne_title = {
						limit = {
							is_primary_holder_title = no
							lower_tier_than = KING
							emf_laws_has_readable_succession_law_trigger = yes
						}
						log = "---> attempting to derive succession law from [This.GetID] (other held title)"
						if = {
							limit = {
								has_law = succ_gavelkind
								event_target:pf_new_title = {
									is_law_potential = succ_institute_gavelkind
									NOT = { has_title_flag = fixed_succession_law }
								}
							}
							event_target:pf_new_title = {
								log = "---> INFO: [This.GetID] has to be manually corrected to Gavelkind succession"
								succession = gavelkind
								set_title_flag = fixed_succession_law
							}
						}
						if = {
							limit = {
								has_law = succ_elective_gavelkind
								event_target:pf_new_title = {
									is_law_potential = succ_institute_elective_gavelkind
									NOT = { has_title_flag = fixed_succession_law }
								}
							}
							event_target:pf_new_title = {
								log = "---> INFO: [This.GetID] has to be manually corrected to Elective Gavelkind succession"
								succession = elective_gavelkind
								set_title_flag = fixed_succession_law
							}
						}
						if = {
							limit = {
								has_law = succ_seniority
								event_target:pf_new_title = {
									is_law_potential = succ_institute_seniority
									NOT = { has_title_flag = fixed_succession_law }
								}
							}
							event_target:pf_new_title = {
								log = "---> INFO: [This.GetID] has to be manually corrected to Seniority succession"
								succession = seniority
								set_title_flag = fixed_succession_law
							}
						}
						if = {
							limit = {
								has_law = succ_primogeniture
								event_target:pf_new_title = {
									is_law_potential = succ_institute_primogeniture
									NOT = { has_title_flag = fixed_succession_law }
								}
							}
							event_target:pf_new_title = {
								log = "---> INFO: [This.GetID] has to be manually corrected to Primogeniture succession"
								succession = primogeniture
								set_title_flag = fixed_succession_law
							}
						}
						if = {
							limit = {
								has_law = succ_feudal_elective
								event_target:pf_new_title = {
									is_law_potential = succ_institute_feudal_elective
									OR = {
										higher_tier_than = DUKE
										AND = {
											is_primary_holder_title = yes
											tier = DUKE
										}
									}
									NOT = { has_title_flag = fixed_succession_law }
								}
							}
							event_target:pf_new_title = {
								log = "---> INFO: [This.GetID] has to be manually corrected to Feudal Elective succession"
								succession = feudal_elective
								set_title_flag = fixed_succession_law
							}
						}
						if = {
							limit = {
								has_law = succ_tanistry
								event_target:pf_new_title = {
									is_law_potential = succ_institute_tanistry
									NOT = { has_title_flag = fixed_succession_law }
								}
							}
							event_target:pf_new_title = {
								log = "---> INFO: [This.GetID] has to be manually corrected to Tanistry succession"
								succession = tanistry
								set_title_flag = fixed_succession_law
							}
						}
						if = {
							limit = {
								has_law = succ_ultimogeniture
								event_target:pf_new_title = {
									is_law_potential = succ_institute_ultimogeniture
									NOT = { has_title_flag = fixed_succession_law }
								}
							}
							event_target:pf_new_title = {
								log = "---> INFO: [This.GetID] has to be manually corrected to Ultimogeniture succession"
								succession = ultimogeniture
								set_title_flag = fixed_succession_law
							}
						}
					}
				}
				
				# Failing that, use the default
				log = "---> no title from which to derive succession law (using default)"
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_institute_gavelkind
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = no
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Gavelkind succession"
						succession = gavelkind
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_institute_elective_gavelkind
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = no
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Elective Gavelkind succession"
						succession = elective_gavelkind
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_institute_seniority
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = no
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Seniority succession"
						succession = seniority
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_institute_primogeniture
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = no
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Primogeniture succession"
						succession = primogeniture
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_institute_feudal_elective
							OR = {
								higher_tier_than = DUKE
								AND = {
									is_primary_holder_title = yes
									tier = DUKE
								}
							}
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = no
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Feudal Elective succession"
						succession = feudal_elective
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_institute_tanistry
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = no
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Tanistry succession"
						succession = tanistry
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_institute_ultimogeniture
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = no
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Ultimogeniture succession"
						succession = ultimogeniture
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_turkish_succession
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = no
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Turkish succession"
						succession = turkish_succession
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_papal_succession
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = yes
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Papal succession"
						succession = papal_succession
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_appointment
							NOT = { has_title_flag = fixed_succession_law }
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Appointment succession"
						succession = appointment
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_open_elective
							NOT = { has_title_flag = fixed_succession_law }
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Open Elective succession"
						succession = open_elective
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							is_law_potential = succ_catholic_bishopric
							NOT = { has_title_flag = fixed_succession_law }
							is_theocracy = yes
						}
					}
					event_target:pf_new_title = {
						log = "---> INFO: [This.GetID] has to be manually corrected to Bishopric succession"
						succession = catholic_bishopric
						set_title_flag = fixed_succession_law
					}
				}
				if = {
					limit = {
						event_target:pf_new_title = {
							NOT = { has_title_flag = fixed_succession_law }
						}
					}
					log = "---> ASSERT: Failed to find appropriate succession law for [pf_new_title.GetFullName] ([pf_new_title.GetID])!"
				}
				event_target:pf_new_title = { clr_title_flag = fixed_succession_law }
				clear_event_target = pf_new_title
			}
			#nomads
			if = {
				limit = {
					is_primary_type_title = no
					holder_scope = {
						has_dlc = "Horse Lords"
						is_nomadic = yes
					}
					NOT = { has_law = succ_nomad_succession }
				}
				current_inheritance_laws_effect = yes
				log = "---> (Annual Maintenance) [This.GetID] changed to Nomadic -- holder is a nomad"
				succession = nomad_succession
			}
			#celtic pagans
			if = {
				limit = {
					emf_laws_succ_basic_potential_trigger = yes
					holder_scope = {
						OR = {
							is_feudal = yes
							is_tribal = yes
						}
						religion = celtic_pagan
					}
					NOT = { has_law = succ_tanistry }
				}
				current_inheritance_laws_effect = yes
				log = "---> (Annual Maintenance) [This.GetID] changed to Nomadic -- holder is unreformed Celtic Pagan"
				succession = tanistry
			}
			#tribal non-reformed pagans
			if = {
				limit = {
					emf_laws_succ_basic_potential_trigger = yes
					rebel = no
					holder_scope = {
						is_tribal = yes
						NOT = { religion = celtic_pagan }
						NOT = { culture = mongol }
						NOT = { has_global_flag = ancient_religions }
						religion_group = pagan_group
						is_reformed_religion = no
						in_revolt = no
					}
					NOT = { has_law = succ_gavelkind }
					NOT = { has_law = succ_elective_gavelkind }
					NOT = { has_law = succ_tanistry }
				}
				current_inheritance_laws_effect = yes
				log = "---> (Annual Maintenance) [This.GetID] changed to Gavelkind -- holder is unreformed tribal pagan"
				succession = gavelkind
			}
			#feudal non-muslim, non-unreformed pagans
			if = {
				limit = {
					holder_scope = {
						NOT = { religion_group = muslim }
						NOT = { religion = celtic_pagan }
						OR = {
							independent = yes
							NOT = { any_liege = { holy_order = yes } }
						}
						is_feudal = yes
						OR = {
							NOT = { religion_group = pagan_group }
							is_reformed_religion = yes
						}
					}
					OR = {
						is_landless_type_title = no
						is_tribal_type_title = yes
						temporary = yes
					}
					is_primary_type_title = no
					NOR = {
						has_law = succ_primogeniture
						has_law = succ_gavelkind
						has_law = succ_feudal_elective
						has_law = succ_seniority
						has_law = succ_tanistry
						has_law = succ_ultimogeniture
						has_law = succ_elective_gavelkind
					}
				}
				current_inheritance_laws_effect = yes
				log = "---> (Annual Maintenance) [This.GetID] changed to Primogeniture -- holder is feudal and not an unreformed pagan"
				succession = primogeniture
			}
			#feudal/tribal muslims
			if = {
				limit = {
					holder_scope = {
						religion_group = muslim
						is_republic = no
						is_merchant_republic = no
						is_nomadic = no
					}
					OR = {
						holder_scope = { any_demesne_title = { is_vice_royalty = yes } }
						AND = {
							holder_scope = {
								OR = {
									independent = yes
									NOT = { any_liege = { holy_order = yes } }
								}
							}
							OR = {
								is_landless_type_title = no
								is_tribal_type_title = yes
								temporary = yes
							}
							is_primary_type_title = no
						}
					}
					NOT = { has_law = succ_turkish_succession }
				}
				current_inheritance_laws_effect = yes
				log = "---> (Annual Maintenance) [This.GetID] changed to Turkish Succession -- holder is Muslim"
				succession = turkish_succession
			}
			#holy orders
			if = {
				limit = {
					holy_order = yes
					holder_scope = {
						is_theocracy = no
						is_patrician = no
						is_merchant_republic = no
						OR = {
							independent = yes
							is_feudal = no
							NOT = { any_liege = { holy_order = yes } }
						}
					}
					NOT = { has_law = succ_open_elective }
				}
				current_inheritance_laws_effect = yes
				log = "---> (Annual Maintenance) [This.GetID] changed to Open Elective -- holder is holy order"
				succession = open_elective
			}
			#manichean papal succession
			if = {
				limit = {
					OR = {
						title = k_papal_state
						title = k_chalcedonian
						title = d_celtic_pagan_reformed
						title = d_hellenic_pagan
						title = d_cathar
						title = d_bogomilist
						title = d_manichean
						title = d_fraticelli
					}
					NOT = { has_law = succ_papal_succession }
				}
				current_inheritance_laws_effect = yes
				log = "---> (Annual Maintenance) [This.GetID] changed to Papal Succession -- holder is religion head"
				succession = papal_succession
			}
			#catholic investiture
			if = {
				limit = {
					higher_tier_than = DUKE
					holder_scope = {
						religion_head = {
							primary_title = {
								OR = {
									title = k_papal_state
									title = k_chalcedonian
									title = d_celtic_pagan_reformed
									title = d_hellenic_pagan
									title = d_cathar
									title = d_bogomilist
									title = d_manichean
									title = d_fraticelli
								}
							}
						}
					}
					NOR = {
						has_law = investiture_law_0
						has_law = investiture_law_1
					}
				}
				log = "---> (Annual Maintenance) [This.GetFullName] has had Investiture 0 added, as the holder had neither law"
				add_law = investiture_law_0
			}
			#non-catholic no investiture
			if = {
				limit = {
					higher_tier_than = DUKE
					holder_scope = {
						NOT = {
							religion_head = {
								primary_title = {
									OR = {
										title = k_papal_state
										title = k_chalcedonian
										title = d_celtic_pagan_reformed
										title = d_hellenic_pagan
										title = d_cathar
										title = d_bogomilist
										title = d_manichean
										title = d_fraticelli
									}
								}
							}
						}
					}
					OR = {
						has_law = investiture_law_0
						has_law = investiture_law_1
					}
				}
				log = "---> (Annual Maintenance) [This.GetFullName] has had its Investiture law revoked, as it has no valid religion head"
				if = {
					limit = { has_law = investiture_law_0 }
					revoke_law = investiture_law_0
				}
				if = {
					limit = { has_law = investiture_law_1 }
					revoke_law = investiture_law_1
				}
			}
		}		
		
		#set appropriate demesne laws level
		if = {
			limit = { higher_real_tier_than = BARON }
			if = {
				limit = {
					capital_scope = {
						NOT = { TECH_LEGALISM = 2 }
					}
					primary_title = {
						NOT = { has_law = demesne_laws_0 }
					}
				}
				primary_title = { add_law = demesne_laws_0 }
			}
			if = {
				limit = {
					capital_scope = {
						TECH_LEGALISM = 2
						NOT = { TECH_LEGALISM = 4 }
					}
					primary_title = {
						NOT = { has_law = demesne_laws_1 }
					}
				}
				primary_title = { add_law = demesne_laws_1 }
			}
			if = {
				limit = {
					capital_scope = {
						TECH_LEGALISM = 4
						NOT = { TECH_LEGALISM = 6 }
					}
					primary_title = {
						NOT = { has_law = demesne_laws_2 }
					}
				}
				primary_title = { add_law = demesne_laws_2 }
			}
			if = {
				limit = {
					capital_scope = {
						TECH_LEGALISM = 6
						NOT = { TECH_LEGALISM = 8 }
					}
					primary_title = {
						NOT = { has_law = demesne_laws_3 }
					}
				}
				primary_title = { add_law = demesne_laws_3 }
			}
			if = {
				limit = {
					capital_scope = {
						TECH_LEGALISM = 8
					}
					primary_title = {
						NOT = { has_law = demesne_laws_4 }
					}
				}
				primary_title = { add_law = demesne_laws_4 }
			}
		}
		
		#set laws for secondary titles
		any_demesne_title = {
			limit = {
				higher_tier_than = baron
				is_primary_holder_title = no
				OR = {
					is_primary_holder_title_tier = yes
					higher_tier_than = duke
				}
			}
			#copy primary title's laws to the secondary titles
			if = {
				limit = {
					holder_scope = {
						primary_title = { has_law = council_privileges_0 }
					}
					NOT = { has_law = council_privileges_0 }
				}
				add_law = council_privileges_0
			}
			if = {
				limit = {
					holder_scope = {
						primary_title = { has_law = council_privileges_1 }
					}
					NOT = { has_law = council_privileges_1 }
				}
				add_law = council_privileges_1
			}
		}

		#fix kingdom lockout laws
		any_demesne_title = {
			limit = {
				OR = {
					title = e_byzantium
					title = e_roman_empire
					title = e_hre
				}
				NOT = { has_law = kingdom_lockout_1 }
				NOT = { has_law = kingdom_lockout_0 }
			}
			log = "---> (Annual Maintenance) [This.GetFullName] has had Kingdom Lockout 0 added"
			add_law = kingdom_lockout_0
		}
		any_demesne_title = {
			limit = {
				NOR = {
					title = e_byzantium
					title = e_roman_empire
					title = e_hre
				}
				OR = {
					has_law = kingdom_lockout_1
					has_law = kingdom_lockout_0
				}
			}
			log = "---> (Annual Maintenance) [This.GetFullName] has had the Kingdom Lockout laws revoked, as it is an invalid title for the law"
			revoke_law = kingdom_lockout_0
			revoke_law = kingdom_lockout_1
		}
		
		#check title flags
		any_demesne_title = {
			if = {
				limit = {
					has_title_flag = former_gavelkind
					has_law = succ_gavelkind
				}
				clr_title_flag = former_gavelkind
			}
			if = {
				limit = {
					has_title_flag = former_seniority
					has_law = succ_seniority
				}
				clr_title_flag = former_seniority
			}
			if = {
				limit = {
					has_title_flag = former_primogeniture
					has_law = succ_primogeniture
				}
				clr_title_flag = former_primogeniture
			}
			if = {
				limit = {
					has_title_flag = former_gavelkind
					has_law = succ_gavelkind
				}
				clr_title_flag = former_gavelkind
			}
			if = {
				limit = {
					has_title_flag = former_feudal_elective
					has_law = succ_feudal_elective
				}
				clr_title_flag = former_feudal_elective
			}
			if = {
				limit = {
					has_title_flag = former_tanistry
					has_law = succ_tanistry
				}
				clr_title_flag = former_tanistry
			}
			if = {
				limit = {
					has_title_flag = former_ultimogeniture
					has_law = succ_ultimogeniture
				}
				clr_title_flag = former_ultimogeniture
			}
			if = {
				limit = {
					has_title_flag = former_cognatic_succession
					has_law = cognatic_succession
				}
				clr_title_flag = former_cognatic_succession
			}
			if = {
				limit = {
					has_title_flag = former_agnatic_succession
					has_law = agnatic_succession
				}
				clr_title_flag = former_agnatic_succession
			}
			if = {
				limit = {
					has_title_flag = former_true_cognatic_succession
					has_law = true_cognatic_succession
				}
				clr_title_flag = former_true_cognatic_succession
			}
			if = {
				limit = {
					has_title_flag = has_imperial_administration
					NOT = { has_law = imperial_administration }
				}
				clr_title_flag = has_imperial_administration
			}
			if = {
				limit = {
					has_law = imperial_administration
					NOT = { has_title_flag = has_imperial_administration }
				}
				set_title_flag = has_imperial_administration
			}
		}
		
		#adjust flags and modifiers based on laws
		if = {
			limit = {
				primary_title = { has_law = council_privileges_0 }
				has_character_flag = lifetime_appointments
			}
			clr_character_flag = lifetime_appointments
		}
		if = {
			limit = {
				primary_title = { has_law = council_privileges_1 }
				NOT = { has_character_flag = lifetime_appointments }
			}
			set_character_flag = lifetime_appointments
		}

		#double-check imperial government status
		if = {
			limit = {
				any_demesne_title = { has_title_flag = viceroy_exemption }
				OR = {
					independent = yes
					top_liege = { has_imperial_government_trigger = no }
					is_feudal = no
				}
				in_revolt = no
				NOT = { any_liege = { in_revolt = yes } }
			}
			any_demesne_title = {
				limit = { has_title_flag = viceroy_exemption }
				clr_title_flag = viceroy_exemption
			}
		}
		if = {
			limit = {
				is_feudal = yes
				primary_title = { NOT = { has_title_flag = viceroy_exemption } }
				any_demesne_title = { has_title_flag = viceroy_exemption }
				top_liege = { has_imperial_government_trigger = yes }
				in_revolt = no
				NOT = { any_liege = { in_revolt = yes } }
				lower_real_tier_than = EMPEROR
			}
			log = "---> (Annual Maintenance) [Root.GetBestName] had [Root.PrimaryTitle.GetID] set to viceroy_exemption as a non-primary title had the flag set"
			any_demesne_title = { clr_title_flag = viceroy_exemption }
			primary_title = { set_title_flag = viceroy_exemption }
		}
		if = {
			limit = {
				is_feudal = yes
				primary_title = { NOT = { has_title_flag = viceroy_exemption } }
				any_demesne_title = { has_title_flag = viceroy_exemption }
				top_liege = { has_imperial_government_trigger = yes }
				in_revolt = no
				NOT = { any_liege = { in_revolt = yes } }
				tier = EMPEROR
			}
			log = "---> (Annual Maintenance) [Root.GetBestName] had demesne titles cleared from viceroy_exemption flag"
			any_demesne_title = { clr_title_flag = viceroy_exemption }
		}
		if = {
			limit = {
				has_imperial_government_trigger = yes
				in_revolt = no
				NOT = { any_liege = { in_revolt = yes } }
			}
			if = {
				limit = {
					independent = yes
					OR = {
						NOT = { primary_title = { has_law = imperial_administration } }
						lower_real_tier_than = EMPEROR
					}
				}
				log = "---> (Annual Maintenance) [Root.GetBestName] was switched to feudal government because [Root.PrimaryTitle.GetID] does not have Imperial Administration law"
				switch_to_feudal_effect = yes
				any_realm_lord = { character_event = { id = Plus.3299 } }
			}
			if = {
				limit = {
					independent = no
					OR = {
						top_liege = { has_imperial_government_trigger = no }
						primary_title = { has_title_flag = viceroy_exemption }
					}
				}
				if = {
					limit = { top_liege = { has_imperial_government_trigger = no } }
					log = "---> (Annual Maintenance) [Root.GetBestName] was switched to feudal government because [Root.TopLiege.GetBestName] does not have Imperial Government"
				}
				if = {
					limit = { primary_title = { has_title_flag = viceroy_exemption } }
					log = "---> (Annual Maintenance) [Root.GetBestName] was switched to feudal government because [Root.PrimaryTitle.GetID] has viceroy_exemption flag"
				}
				switch_to_feudal_effect = yes
			}
		}
		if = {
			limit = {
				is_feudal = yes
				has_imperial_government_trigger = no
				in_revolt = no
				NOT = { any_liege = { in_revolt = yes } }
			}
			if = {
				limit = {
					independent = yes
					tier = EMPEROR
					primary_title = { has_law = imperial_administration }
				}
				log = "---> (Annual Maintenance) [Root.GetBestName] was switched to imperial government because [Root.PrimaryTitle.GetID] has Imperial Administration law"
				switch_to_imperial_effect = yes
				any_realm_lord = {
					limit = {
						is_liege_or_above = ROOT
						is_feudal = yes
						has_imperial_government_trigger = no
						NAND = {
							controls_religion = yes
							NOT = { religion_group = muslim }
							NOT = { religion_group = pagan_group }
							NOT = { religion = paulician }
						}
						in_revolt = no
						NOT = { any_liege = { in_revolt = yes } }
					}
					any_demesne_title = { clr_title_flag = viceroy_exemption }
					primary_title = { set_title_flag = viceroy_exemption }
				}
			}
			if = {
				limit = {
					independent = no
					top_liege = { has_imperial_government_trigger = yes }
					NOT = { primary_title = { has_title_flag = viceroy_exemption } }
				}
				log = "---> (Annual Maintenance) [Root.GetBestName] was switched to imperial government because [Root.TopLiege.GetBestName] as imperial government and [Root.PrimaryTitle.GetID] does not have the viceroy_exemption flag"
				switch_to_imperial_effect = yes
			}
		}
		
		#the dishonorable reduction timer exists, and the character is not dishonorable, reset it
		if = {
			limit = {
				check_variable = { which = "dishonorable_reduction" value = 0.5 }
				NOR = {
					trait = dishonorable1
					trait = dishonorable2
					trait = dishonorable3
					trait = dishonorable4
					trait = dishonorable5
					trait = dishonorable6
					trait = dishonorable7
					trait = dishonorable8
					trait = dishonorable9
					trait = dishonorable10
					trait = dyn_dishonorable1
					trait = dyn_dishonorable2
					trait = dyn_dishonorable3
					trait = dyn_dishonorable4
					trait = dyn_dishonorable5
					trait = dyn_dishonorable6
					trait = dyn_dishonorable7
					trait = dyn_dishonorable8
					trait = dyn_dishonorable9
					trait = dyn_dishonorable10
				}
			}
			set_variable = { which = "dishonorable_reduction" value = 0 }
		}
		#advance the dishonorable reduction timer by +1
		if = {
			limit = {
				NOT = { check_variable = { which = "dishonorable_reduction" value = 19.5 } }
				OR = {
					trait = dishonorable1
					trait = dishonorable2
					trait = dishonorable3
					trait = dishonorable4
					trait = dishonorable5
					trait = dishonorable6
					trait = dishonorable7
					trait = dishonorable8
					trait = dishonorable9
					trait = dishonorable10
					trait = dyn_dishonorable1
					trait = dyn_dishonorable2
					trait = dyn_dishonorable3
					trait = dyn_dishonorable4
					trait = dyn_dishonorable5
					trait = dyn_dishonorable6
					trait = dyn_dishonorable7
					trait = dyn_dishonorable8
					trait = dyn_dishonorable9
					trait = dyn_dishonorable10
				}
			}
			change_variable = { which = "dishonorable_reduction" value = 1 }
		}
		#the dishonorable reduction timer has hit 20, reduce dishonorable by 1
		if = {
			limit = {
				check_variable = { which = "dishonorable_reduction" value = 19.5 }
				OR = {
					trait = dishonorable1
					trait = dishonorable2
					trait = dishonorable3
					trait = dishonorable4
					trait = dishonorable5
					trait = dishonorable6
					trait = dishonorable7
					trait = dishonorable8
					trait = dishonorable9
					trait = dishonorable10
					trait = dyn_dishonorable1
					trait = dyn_dishonorable2
					trait = dyn_dishonorable3
					trait = dyn_dishonorable4
					trait = dyn_dishonorable5
					trait = dyn_dishonorable6
					trait = dyn_dishonorable7
					trait = dyn_dishonorable8
					trait = dyn_dishonorable9
					trait = dyn_dishonorable10
				}
			}
			set_variable = { which = "dishonorable_reduction" value = 0 }
			if = {
				limit = {
					trait = dishonorable1
				}
				remove_trait = dishonorable1
			}
			if = {
				limit = {
					trait = dishonorable2
				}
				remove_trait = dishonorable2
				add_trait = dishonorable1
			}
			if = {
				limit = {
					trait = dishonorable3
				}
				remove_trait = dishonorable3
				add_trait = dishonorable2
			}
			if = {
				limit = {
					trait = dishonorable4
				}
				remove_trait = dishonorable4
				add_trait = dishonorable3
			}
			if = {
				limit = {
					trait = dishonorable5
				}
				remove_trait = dishonorable5
				add_trait = dishonorable4
			}
			if = {
				limit = {
					trait = dishonorable6
				}
				remove_trait = dishonorable6
				add_trait = dishonorable5
			}
			if = {
				limit = {
					trait = dishonorable7
				}
				remove_trait = dishonorable7
				add_trait = dishonorable6
			}
			if = {
				limit = {
					trait = dishonorable8
				}
				remove_trait = dishonorable8
				add_trait = dishonorable7
			}
			if = {
				limit = {
					trait = dishonorable9
				}
				remove_trait = dishonorable9
				add_trait = dishonorable8
			}
			if = {
				limit = {
					trait = dishonorable10
				}
				remove_trait = dishonorable10
				add_trait = dishonorable9
			}
			if = {
				limit = {
					trait = dyn_dishonorable1
				}
				remove_trait = dyn_dishonorable1
			}
			if = {
				limit = {
					trait = dyn_dishonorable2
				}
				remove_trait = dyn_dishonorable2
				add_trait = dyn_dishonorable1
			}
			if = {
				limit = {
					trait = dyn_dishonorable3
				}
				remove_trait = dyn_dishonorable3
				add_trait = dyn_dishonorable2
			}
			if = {
				limit = {
					trait = dyn_dishonorable4
				}
				remove_trait = dyn_dishonorable4
				add_trait = dyn_dishonorable3
			}
			if = {
				limit = {
					trait = dyn_dishonorable5
				}
				remove_trait = dyn_dishonorable5
				add_trait = dyn_dishonorable4
			}
			if = {
				limit = {
					trait = dyn_dishonorable6
				}
				remove_trait = dyn_dishonorable6
				add_trait = dyn_dishonorable5
			}
			if = {
				limit = {
					trait = dyn_dishonorable7
				}
				remove_trait = dyn_dishonorable7
				add_trait = dyn_dishonorable6
			}
			if = {
				limit = {
					trait = dyn_dishonorable8
				}
				remove_trait = dyn_dishonorable8
				add_trait = dyn_dishonorable7
			}
			if = {
				limit = {
					trait = dyn_dishonorable9
				}
				remove_trait = dyn_dishonorable9
				add_trait = dyn_dishonorable8
			}
			if = {
				limit = {
					trait = dyn_dishonorable10
				}
				remove_trait = dyn_dishonorable10
				add_trait = dyn_dishonorable9
			}
		}
		#the tyrany reduction timer exists, and the character is not a tyrant, reset it
		if = {
			limit = {
				check_variable = { which = "tyranny_reduction" value = 0.5 }
				NOR = {
					trait = tyrant1
					trait = tyrant2
					trait = tyrant3
					trait = tyrant4
					trait = tyrant5
					trait = tyrant6
					trait = tyrant7
					trait = tyrant8
					trait = tyrant9
					trait = tyrant10
					trait = tyrant11
					trait = tyrant12
					trait = tyrant13
					trait = tyrant14
					trait = tyrant15
					trait = tyrant16
					trait = tyrant17
					trait = tyrant18
					trait = tyrant19
					trait = tyrant20
				}
			}
			set_variable = { which = "tyranny_reduction" value = 0 }
		}
		#advance the tyranny reduction timer by +1
		if = {
			limit = {
				NOT = { check_variable = { which = "tyranny_reduction" value = 4.5 } }
				OR = {
					trait = tyrant1
					trait = tyrant2
					trait = tyrant3
					trait = tyrant4
					trait = tyrant5
					trait = tyrant6
					trait = tyrant7
					trait = tyrant8
					trait = tyrant9
					trait = tyrant10
					trait = tyrant11
					trait = tyrant12
					trait = tyrant13
					trait = tyrant14
					trait = tyrant15
					trait = tyrant16
					trait = tyrant17
					trait = tyrant18
					trait = tyrant19
					trait = tyrant20
				}
			}
			change_variable = { which = "tyranny_reduction" value = 1 }
		}
		#the tyranny reduction timer has hit 5, reduce tyrant by 1
		if = {
			limit = {
				check_variable = { which = "tyranny_reduction" value = 4.5 }
				OR = {
					trait = tyrant1
					trait = tyrant2
					trait = tyrant3
					trait = tyrant4
					trait = tyrant5
					trait = tyrant6
					trait = tyrant7
					trait = tyrant8
					trait = tyrant9
					trait = tyrant10
					trait = tyrant11
					trait = tyrant12
					trait = tyrant13
					trait = tyrant14
					trait = tyrant15
					trait = tyrant16
					trait = tyrant17
					trait = tyrant18
					trait = tyrant19
					trait = tyrant20
				}
			}
			set_variable = { which = "tyranny_reduction" value = 0 }
			if = {
				limit = {
					trait = tyrant1
				}
				remove_trait = tyrant1
			}
			if = {
				limit = {
					trait = tyrant2
				}
				remove_trait = tyrant2
				add_trait = tyrant1
			}
			if = {
				limit = {
					trait = tyrant3
				}
				remove_trait = tyrant3
				add_trait = tyrant2
			}
			if = {
				limit = {
					trait = tyrant4
				}
				remove_trait = tyrant4
				add_trait = tyrant3
			}
			if = {
				limit = {
					trait = tyrant5
				}
				remove_trait = tyrant5
				add_trait = tyrant4
			}
			if = {
				limit = {
					trait = tyrant6
				}
				remove_trait = tyrant6
				add_trait = tyrant5
			}
			if = {
				limit = {
					trait = tyrant7
				}
				remove_trait = tyrant7
				add_trait = tyrant6
			}
			if = {
				limit = {
					trait = tyrant8
				}
				remove_trait = tyrant8
				add_trait = tyrant7
			}
			if = {
				limit = {
					trait = tyrant9
				}
				remove_trait = tyrant9
				add_trait = tyrant8
			}
			if = {
				limit = {
					trait = tyrant10
				}
				remove_trait = tyrant10
				add_trait = tyrant9
			}
			if = {
				limit = {
					trait = tyrant11
				}
				remove_trait = tyrant11
				add_trait = tyrant10
			}
			if = {
				limit = {
					trait = tyrant12
				}
				remove_trait = tyrant12
				add_trait = tyrant11
			}
			if = {
				limit = {
					trait = tyrant13
				}
				remove_trait = tyrant13
				add_trait = tyrant12
			}
			if = {
				limit = {
					trait = tyrant14
				}
				remove_trait = tyrant14
				add_trait = tyrant13
			}
			if = {
				limit = {
					trait = tyrant15
				}
				remove_trait = tyrant15
				add_trait = tyrant14
			}
			if = {
				limit = {
					trait = tyrant16
				}
				remove_trait = tyrant16
				add_trait = tyrant15
			}
			if = {
				limit = {
					trait = tyrant17
				}
				remove_trait = tyrant17
				add_trait = tyrant16
			}
			if = {
				limit = {
					trait = tyrant18
				}
				remove_trait = tyrant18
				add_trait = tyrant17
			}
			if = {
				limit = {
					trait = tyrant19
				}
				remove_trait = tyrant19
				add_trait = tyrant18
			}
			if = {
				limit = {
					trait = tyrant20
				}
				remove_trait = tyrant20
				add_trait = tyrant19
			}
		}
	}
}

character_event = { # Fixing antipope removal
	id = Plus.350
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		remove_claim = k_papal_state
		remove_claim = d_fraticelli
	}
}

character_event = { # Prevents quick rebellions in newly-conquered provinces
	id = Plus.351
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = { tier = COUNT }
		OR = {
			has_character_modifier = victory_timer
			has_character_modifier = new_land_timer
		}
	}
	
	immediate = {
		FROM = {
			location = {
				if = {
					limit = { has_province_modifier = province_chaos }
					remove_province_modifier = province_chaos
				}
				add_province_modifier = {
					name = province_chaos
					duration = 730
				}
			}
		}
	}
}

character_event = { # refills levy holdings after switching to feudal
	id = Plus.352
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		any_demesne_title = {
			limit = { has_title_flag = refill_levy }
			clr_title_flag = refill_levy
			refill_holding_levy = yes
		}
	}
}

character_event = { # adds Away From Court modifier when leading armies away from the capital
	id = Plus.353
	
	hide_window = yes
	
	only_rulers = yes
	only_playable = yes
	min_age = 16
	capable_only = yes
	prisoner = no
	
	trigger = {
		in_command = yes
		higher_tier_than = BARON
		OR = {
			war = yes
			any_liege = { war = yes }
		}
		NOT = { has_character_modifier = away_from_court }
		capital_scope = {
			ROOT = {
				location = {
					NOT = { province_id = PREVPREV }
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		set_character_flag = away_from_court
		add_character_modifier = {
			name = away_from_court
			duration = -1
		}
	}
}

character_event = { # removes Away From Court modifier
	id = Plus.354
	
	hide_window = yes
	
	has_character_flag = away_from_court
	
	trigger = {
		has_character_modifier = away_from_court
		OR = {
			trait = incapable
			prisoner = yes
			is_playable = no
			NAND = {
				in_command = yes
				OR = {
					war = yes
					any_liege = { war = yes }
				}
				capital_scope = {
					ROOT = {
						location = {
							NOT = { province_id = PREVPREV }
						}
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		remove_character_modifier = away_from_court
		clr_character_flag = away_from_court
	}
}

character_event = { # removes child's strong claim to viceroyalty
	id = Plus.355
	desc = AI_EVENT
	picture = GFX_evt_council
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		event_target:lose_strong = {
			ROOT = { has_strong_claim = PREV }
		}
	}
	
	option = {
		name = OK
		event_target:lose_strong = {
			remove_claim = ROOT
			add_weak_pressed_claim = ROOT
		}
	}
}

character_event = { # removes claims for dead rulers
	id = Plus.356
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROMFROM = {
			has_claim = FROM
			is_alive = no
		}
	}
	
	immediate = {
		FROM = {
			remove_claim = FROMFROM
		}
	}
}

character_event = { # adds daughters to early bookmarks
	id = Plus.358
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		set_character_flag = daughter_check
		random = {
			chance = 25
			modifier = {
				factor = 2
				OR = {
					is_patrician = yes
					is_republic = yes
					higher_tier_than = COUNT
				}
			}
			modifier = {
				factor = 1.5
				OR = {
					higher_tier_than = DUKE
					religion_group = muslim
					religion_group = pagan_group
				}
			}
			random_list = {
				80 = { # Favour daughters since early BMs have almost no females
					generate_daughters_early_bm_effect = yes
				}
				20 = {
					generate_sons_early_bm_effect = yes
				}
			}
			new_character = {
				if = {
					limit = { ROOT = { is_female = no } }
					set_father = ROOT
				}
				if = {
					limit = { ROOT = { is_female = yes } }
					set_mother = ROOT
				}
				ROOT = {
					random_spouse = {
						limit = { age_diff = { who = PREVPREV years = 16 } }
						if = {
							limit = { is_female = no }
							new_character = { set_father = PREV }
						}
						if = {
							limit = { is_female = yes }
							new_character = { set_mother = PREV }
						}
					}
				}
				if = {
					limit = { religion_group = indian_group }
					add_trait = kshatriya
					character_event = { id = RoI.30121 }
				}
				set_character_flag = start_of_game_character
				character_event = { id = Plus.324 }
			}
			random = { # Generate an extra child?
				chance = 50
				random_list = { # This time an equal chance of male or female
					50 = { emf_nwo_generate_male_child = yes }
					50 = { emf_nwo_generate_female_child = yes }
				}
			}
			recalc_succession = yes
		}
		random_playable_ruler = { # add children, primarily daughters, for early bookmarks
			limit = {
				age = 32
				OR = {
					higher_tier_than = BARON
					is_patrician = yes
				}
				has_character_flag = start_of_game_character
				NOR = {
					holy_order = yes
					mercenary = yes
					is_theocracy = yes
					year = 1065
					any_child = { is_female = yes }
					has_character_flag = daughter_check
				}
				OR = {
					NOR = {
						has_law = cognatic_succession
						has_law = true_cognatic_succession
					}
					any_child = { NOT = { trait = bastard } age = 22 }
					AND = {
						has_law = cognatic_succession
						any_child = { NOT = { trait = bastard } is_female = no }
					}
				}
			}
			character_event = { id = Plus.358 }
		}
	}
}

character_event = { # Religion head title inherited by someone who isn't the right religion
	id = Plus.359
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = { wrong_religion_head_trigger = yes }
	}
	
	immediate = {
		any_demesne_title = {
			limit = { wrong_religion_head_trigger = yes }
			if = {
				limit = { FROMFROM = { is_alive = yes } }
				grant_title_no_opinion = FROMFROM
				break = yes
			}
			unsafe_destroy_landed_title = THIS
		}
	}
}

character_event = { # Religion head loses all claims as they gain the title
	id = Plus.360
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			controls_religion = yes
			is_primary_holder_title = yes
		}
		is_theocracy = yes
		num_of_claims = 1
	}
	
	immediate = {
		any_claim = { remove_claim = ROOT }
	}
}

character_event = { # Lowborn marries a Duke or above
	id = Plus.361
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		new_character = {
			dynasty = none
		}
		FROM = {
			higher_tier_than = COUNT
			ai = yes
		}
	}
	
	immediate = {
		new_character = {
			random_list = {
				25 = { dynasty = FROM }
				75 = { dynasty = father_bastard }
			}
		}
	}
}

character_event = { # Rebel/Adventurer imprisoned after loss
	id = Plus.362
	
	hide_window = yes
	is_triggered_only = yes
	war = yes
	
	trigger = {
		primary_title = { temporary = yes }
		NOT = { any_demesne_title = { temporary = no } }
	}
	
	immediate = {
		character_event = { id = Plus.363 days = 7 }
	}
}

character_event = {
	id = Plus.363
	
	hide_window = yes
	is_triggered_only = yes
	war = yes
	
	trigger = {
		primary_title = { temporary = yes }
		NOR = {
			any_demesne_title = { temporary = no }
			prisoner = yes
			is_at_sea = yes
			location = { is_land = yes }
		}
	}
	
	immediate = {
		log = "INFO: [Root.GetBestName] has lost all forces and is now imprisoned by [From.GetBestName]"
		any_war = {
			limit = { attacker = { character = ROOT } }
			defender = {
				ROOT = { imprison = PREV }
			}
		}
	}
}

character_event = {
	id = Plus.364

	# FROMFROM = character giving the title
	# FROM = the title being given
	# ROOT = the character receiving the title
	
	hide_window = yes
	is_triggered_only = yes
	
	ai = yes # Don't force a player to change inheritance rules
	
	trigger = {
		FROM = { is_primary_holder_title = yes }
		FROMFROM = {
			is_liege_of = ROOT
			is_alive = yes
		}
	}
	
	immediate = {
		FROMFROM = { primary_title = { save_event_target_as = liege_primary_title } }
		log = "---> INFO: Correcting laws for [From.GetID]"
		character_event = { id = Plus.365 days = 1 } # Needs to be delayed a day as this won't work on the first day of inheritance
	}
}

character_event = {
	id = Plus.365
	
	hide_window = yes
	is_triggered_only = yes

	immediate = { 
		primary_title = {
			
		}
		if = {
			limit = { higher_real_tier_than = count } # Don't want those below Duke getting the wrong succession types
			primary_title = { copy_title_laws = event_target:liege_primary_title }
		}
		if = {
			limit = { NOT = { higher_real_tier_than = count } } # Only copy the gender laws for lower than duke
			primary_title = { adjust_gender_law_effect = yes }
			recalc_succession = yes
		}
	}
}

# Restore original name if title with regnal names is inherited by secular ruler
# ROOT is the character, FROM is the title, FROMFROM is the old holder
character_event = {
	id = Plus.366
	
	hide_window = yes
	is_triggered_only = yes
	
	only_rulers = yes
	
	trigger = {
		is_theocracy = no
		FROM = {
			OR = {
				title = d_pentarch_rome
				title = d_pentarch_constantinople
				title = d_apostolic
				title = d_egyptian_pagan
				title = d_fraticelli
				title = d_iconoclast
				title = d_messalian
				title = d_miaphysite
				title = d_monophysite
				title = d_monothelite
				title = d_nestorian
				title = d_paulician
				title = k_orthodox
				title = k_papal_chalcedon
				title = k_interim_papacy
				title = k_papal_state
			}
		}
	}
	
	immediate = {
		set_name = ""
	}
}

# Inform player that he has an incorrect checksum
narrative_event = {
	id = Plus.367
	title = EVTNAME_Plus_367
	desc = EVTDESC_Plus_367
	picture = GFX_evt_bad_news

	is_triggered_only = yes
	hide_from = yes
	
	option = {
		name = OK
	}
}

# Deal with landed varangians
character_event = {
	id = Plus.368
	
	hide_window = yes
	is_triggered_only = yes
	
	ai = yes
	min_age = 16
	only_men = yes
	capable_only = yes
	prisoner = no
	culture_group = north_germanic
	has_character_flag = serving_varangian
	
	trigger = {
		has_dlc = "The Old Gods"
	}
	
	immediate = {
		random_list = {
			120 = {
				modifier = {
					factor = 0
					trait = scarred
				}
				character_event = {id = TOG.3114 } # Son returns scarred but seasoned
			}
			110 = {
				modifier = {
					factor = 0
					trait = homosexual
				}
				character_event = {id = TOG.3116 } # Son returns with notions of Greek love
			}
			75 = {
				modifier = {
					factor = 0
					OR = {
						trait = eunuch
						trait = blinded
					}
				}
				character_event = {id = TOG.3118 } # Son returns castrated and blinded
			}
			120 = {
				modifier = {
					factor = 0
					trait = brilliant_strategist
				}
				modifier = {
					factor = 0
					NOT = { 
						trait = misguided_warrior
						trait = tough_soldier
						trait = skilled_tactician
					}
				}
				character_event = {id = TOG.3120 } # Son returns as excellent strategist
			}
			110 = {
				modifier = {
					factor = 0
					trait = depressed
				}
				character_event = {id = TOG.3122 } # Son returns with PTSD
			}
			110 = {
				modifier = {
					factor = 0
					is_married = yes
				}
				character_event = {id = TOG.3124 } # Son returns home with Greek wife
			}
			120 = {
				modifier = {
					factor = 0
					NOT = { religion_group = pagan_group }
				}
				character_event = {id = TOG.3126 } # Son returns home as a Christian zealot
			}
			140 = {
				character_event = {id = TOG.3128 } # Son returns home as a seasoned warrior
			}
			120 = {
				character_event = {id = TOG.3132 } # Son returns with loot
			}
			500 = {
				clr_character_flag = serving_varangian # Nothing happens, just cleanup
			}
		}
	}
}