burgundian_inheritance_start_effect = {
	#Burgundian succession stuff
	if = {
		limit = {
			tag = BUR
			has_country_modifier = burgundian_succession_crisis
			NOT = { has_country_flag = burgundian_succession_has_already_fired }
			NOT = {
				BUR = {
					is_subject = yes
				}
			}
		}
		set_global_flag = burgundian_succession_crisis #Added by Uber. Used as a trigger for Charles V chain.
		set_country_flag = burgundian_succession_has_already_fired
		remove_country_modifier = burgundian_succession_crisis
		set_country_flag = charles_died
		if = {
			limit = {
				is_emperor = no
				OR = {
					AND = { #succession should not fire if Burgundy has a suitable male heir
						has_regency = yes
						OR = {
							has_heir = no
							NOT = {
								heir_age = 15
							}
							NOT = { heir_claim = 51 }
						}
					}
					NOT = { legitimacy = 40 } #medium to weak claimants should not be good enough
					has_ruler_flag = mary_is_heir
					has_heir_flag = mary_is_heir
				}
			}
			if = { #if Mary was defined as heir proper, she gains some legitimacy
				limit = {
					OR = {
						has_ruler_flag = mary_is_heir
						has_heir_flag = mary_is_heir
					}
				}
				add_legitimacy_equivalent = { amount = 10 republican_tradition = 5 }
			}
			else = { #if she was not named heir, she becomes ruler here
				define_ruler = {
					name = "Marie"
					dynasty = "de Bourgogne"
					age = 21
					adm = 4
					dip = 5
					mil = 3
					claim = 50
					female = yes
				}
				set_ruler_flag = mary_is_heir
			}
			country_event = {
				id = incidents_bur_inheritance.1
			}
		}
	}
	else_if = {
		limit = {
			tag = BUR
			has_regency = no
			has_ruler_flag = is_charles_of_burg_flag #this flag is assigned in the history file of Burgundy
			NOT = { has_country_modifier = burgundian_succession_crisis }
			NOT = { has_country_flag = burgundian_succession_has_already_fired }
		}
		clr_ruler_flag = is_charles_of_burg_flag
		add_country_modifier = { #country modifier used to weaken Charles's fertility, is also used as a trigger for the inheritance event above.
			name = burgundian_succession_crisis
			duration = -1
			hidden = yes
		}
	}
}