namespace = elections

# Election!
country_event = {
	id = 700
	title = "EVTNAME700"
	picture = ELECTION_REPUBLICAN_eventPicture
	
	desc = {
		trigger = {
			NOT = { has_ruler_flag = leader_has_been_pushed_out }
			NOT = { has_country_flag = caretaker_revolutionary_government }
			OR = {
				NOT = { has_government_attribute = has_limited_terms }
				check_variable = {
					which = max_election_term
					which = election_term
				}
			}
		}
		desc = EVTDESC700
	}
	
	desc = {
		trigger = { has_ruler_flag = leader_has_been_pushed_out }
		desc = elections.700.d
	}
	desc = {
		trigger = { has_country_flag = caretaker_revolutionary_government }
		desc = elections.700.caretaker
	}
	desc = {
		trigger = {
			NOT = { has_ruler_flag = leader_has_been_pushed_out }
			NOT = { has_country_flag = caretaker_revolutionary_government }
			has_government_attribute = has_limited_terms
			NOT = {
				check_variable = {
					which = max_election_term
					which = election_term
				}
			}
		}
		desc = elections.700.limitedterm
	}
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { has_states_general_mechanic = yes }
		NOT = { has_government_attribute = lottery_election }
		NOT = { has_government_attribute = is_pirate_republic_reform }
		NOT = { has_reform = american_government }
		NOT = { has_reform = military_dictatorship_reform }
		NOT = { has_reform = admiralty_reform }
		NOT = { has_reform = prussian_republic_reform }
		NOT = { has_disaster =  bonfire_of_the_vanities_disaster }
		if = {
			limit = {
				has_country_flag = caretaker_revolutionary_government
			}
			republican_tradition = 50
		}
	}

	immediate = {
		hidden_effect = {
			pre_select_possible_ruler_focus = yes
			if = {
				limit = { has_government_attribute = has_limited_terms }
				export_to_variable = {
					which = max_election_term
					value = modifier:max_terms
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					OR = {
						has_government_attribute = enable_factional_elections
						has_government_attribute = enables_veche_parties
					}
				}
				pre_election_set_factional_veche = yes
			}
			if = {
				limit = {
					has_government_attribute = enables_sforza
				}
				pre_election_set_sforza = yes
			}
		}
	}

	after = {
		clr_country_flag = caretaker_revolutionary_government
		post_ruler_focus_clearance = yes
		post_election_clear_GE = yes
	}

	option = {
		name = "EVTOPTA700"	# Current ruler stays
		trigger = {
			has_regency = no
			NOT = { has_ruler_flag = leader_has_been_pushed_out }
			OR = {
				NOT = { has_government_attribute = has_limited_terms }
				check_variable = {
					which = max_election_term
					which = election_term
				}
			}
		}
		ai_chance = { 
			factor = 60
			modifier = {
				factor = 0
				NOT = { republican_tradition = 25 }
			}	
			modifier = {
				factor = 0.5
				NOT = { republican_tradition = 50 }
			}				
			modifier = {
				factor = 0.5
				NOT = { republican_tradition = 75 }
			}	
			modifier = {
				factor = 2.0
				republican_tradition = 90
			}		
		}
		custom_tooltip = remains_ruler
		if = {
			limit = { has_government_attribute = has_limited_terms }
			custom_tooltip = current_term_tt
		}
		change_adm = 1
		change_dip = 1
		change_mil = 1
		if = {
			limit = {
				has_government_attribute = enables_absolute_reelection
			}
			add_absolutism = 2
		}
		if = {
			limit = {
				is_tribal = no 
				government = republic
				NOT = { republican_tradition = 20 }				
				NOT = { is_revolutionary_republic_trigger = yes }
				has_dlc = "Res Publica"
				NOT = { has_government_attribute = cannot_become_dictatorship }
			}
			add_government_reform = presidential_despot_reform	
		}
		else_if = {
			limit = {
				government = republic
				NOT = { republican_tradition = 20 }	
				is_revolutionary_republic_trigger = yes
			}
			change_government = monarchy
			add_government_reform = revolutionary_empire_reform
		}
		if = {
			limit = {
				is_tribal = no  
				government = republic
				NOT = { republican_tradition = 20 }
				NOT = { has_dlc = "Res Publica" }
				NOT = { has_government_attribute = cannot_become_dictatorship }
			}
			change_government = monarchy
			#set_legacy_government = despotic_monarchy
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			election_effect_factional_re_elections = yes
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			election_effect_veche_parties_re = yes
		}
		if = {
			limit = {
				has_country_flag = strengthened_signoria_flag
			}
			custom_tooltip = strengthened_signoria_election_tt
			clr_country_flag = strengthened_signoria_flag
		}
		else = {
			if = {
				limit = {
					has_country_flag = increased_election_cost
				}
				add_scaled_republican_tradition = -15
				clr_country_flag = increased_election_cost
			}
			else = {
				add_scaled_republican_tradition = -10
			}
		}
		random_list = {
			10 = {
				add_adm_power = 50
			}
			10 = {
				add_dip_power = 50
			}
			10 = {
				add_mil_power = 50
			}
		}
		if = {
			limit = {
				has_government_attribute = reelection_depowers_estates
			}
			add_estate_influence_modifier = {
				estate = all
				influence = -10
				duration = 1460
				desc = REELCTION_DEPOWER_ESTATES
			}
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty = {
				estate = all
				loyalty = 5
			}
		}
		if = {
			limit = { has_government_attribute = reelection_increases_absolutism }
			tooltip = {
				add_absolutism = 10
			}
			custom_tooltip = ADD_ABSOLUTISM_BASED_ON_ELECTION_TERM
			hidden_effect = {
				for_variable_amount = {
					variable = election_term
					effect = "
						add_absolutism = 10
					"
				}
			}
			hidden_effect = {
				change_variable = {
					which = election_term
					value = 1
				}
			}
		}
		if = {
			limit = { has_government_attribute = elections_increase_factions_influence }
			add_influence_to_random_faction = {
				influence = 20
			}
		}
		add_karma = -5
		if = {
			limit = {
				has_government_attribute = has_limited_terms
			}
			hidden_effect = {
				change_variable = {
					which = election_term
					value = 1
				}
			}
		}
	}
	option = {
		name = "EVTOPTB700"	# An administrator type
		ai_chance = { factor = 20 }
		trigger = {
			NOT = { has_government_attribute = enables_caucasus_candidates }
		}
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			define_ruler = {
				change_mil = -1
				change_adm = 1
				change_dip = -1
				min_age = 40
				max_age = 60
			}
		}
		else_if = {
			limit = { republic_with_female_rulers_trigger = yes }
			define_ruler = {
				mil = 1
				adm = 4
				dip = 1
				random_gender = yes # Allows random gender for republics
			}
		}
		else = {
			define_ruler = {
				mil = 1
				adm = 4
				dip = 1
			}
		}
		if = {
			limit = {
				has_government_attribute = enables_princes_of_novogorod
			}
			define_advisor = {
				type = army_organiser
				skill = 2
				cost_multiplier = 0.50
			}
		}
		if = {
			limit = { has_government_attribute = elections_increase_factions_influence }
			add_influence_to_adm_faction = {
				influence = 20
			}
		}
		add_karma = 10
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				adm_advisor = {
					add_ruler_modifier = {
						name = "Adm_Advisor"
						duration = -1
					}
				}
				adm_stabcost = {
					add_ruler_modifier = {
						name = "Adm_Stabcost"
						duration = -1
					}
				}
				adm_pope = {
					add_papal_influence = 10
					add_church_power = 15
					add_fervor = 20
				}
			}
			set_ruler_flag = adm_ruler
		}
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			trigger_switch = {
				on_trigger = has_country_flag
				adm_advisor = {
					add_ruler_modifier = {
						name = "VP_Tax"
						duration = -1
					}
				}
				adm_stabcost = {
					add_ruler_modifier = {
						name = "VP_Pious"
						duration = -1
					}
				}
				adm_pope = {
					add_patriarch_authority = 0.05
				}
			}
			set_ruler_flag = adm_ruler
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty_by_class_adm = {
				loyalty = 10
			}
		}
		if = {
			limit = {
				has_government_attribute = has_limited_terms
			}
			hidden_effect = {
				set_variable = {
					which = election_term
					value = 1
				}
			}
		}
		if = {
			limit = { has_government_attribute = has_candidate_bonus }
			assign_ruler_focus = {
				type = adm
			}
		}
	}
	option = {
		name = "EVTOPTC700"	# A diplomat
		ai_chance = { factor = 20 }
		trigger = {
			NOT = { has_government_attribute = enables_caucasus_candidates }
		}
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			define_ruler = {
				change_mil = -1
				change_adm = -1
				change_dip = 1
				min_age = 40
				max_age = 60
			}
		}
		else_if = {
			limit = { republic_with_female_rulers_trigger = yes }
			define_ruler = {
				dip = 4
				adm = 1
				mil = 1
				random_gender = yes # Allows random gender for republics
			}
		}
		else = {
			define_ruler = {
				dip = 4
				adm = 1
				mil = 1
			}
		}
		if = {
			limit = {
				has_government_attribute = enables_princes_of_novogorod
			}
			create_admiral = { tradition = 50 }
		}
		if = {
			limit = { has_government_attribute = elections_increase_factions_influence }
			add_influence_to_dip_faction = {
				influence = 20
			}
		}
		add_karma = 10
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				dip_trade = {
					add_ruler_modifier = {
						name = "Dip_Trade"
						duration = -1
					}
				}
				dip_gold = {
					add_years_of_income = 0.4
				}
				dip_invest = {
					add_ruler_modifier = {
						name = "Dip_Invest"
						duration = -1
					}
				}
			}
			set_ruler_flag = dip_ruler
		}
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			trigger_switch = {
				on_trigger = has_country_flag
				dip_trade = {
					add_ruler_modifier = {
						name = "VP_Production"
						duration = -1
					}
				}
				dip_gold = {
					add_ruler_modifier = {
						name = "VP_Trade"
						duration = -1
					}
				}
				dip_invest = {
					add_ruler_modifier = {
						name = "VP_Diprep"
						duration = -1
					}
				}
			}
			set_ruler_flag = dip_ruler
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty_by_class_dip = {
				loyalty = 10
			}
		}
		if = {
			limit = {
				has_government_attribute = has_limited_terms
			}
			hidden_effect = {
				set_variable = {
					which = election_term
					value = 1
				}
			}
		}
		if = {
			limit = { has_government_attribute = has_candidate_bonus }
			assign_ruler_focus = {
				type = dip
			}
		}
	}
	option = {
		name = "EVTOPTD700"	# A military man
		ai_chance = { factor = 20 }
		trigger = {
			NOT = { has_government_attribute = enables_caucasus_candidates }
		}
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			define_ruler = {
				change_mil = 1
				change_adm = -1
				change_dip = -1
				min_age = 40
				max_age = 60
			}
		}
		else_if = {
			limit = { republic_with_female_rulers_trigger = yes }
			define_ruler = {
				mil = 4
				adm = 1
				dip = 1
				random_gender = yes # Allows random gender for republics
			}
		}
		else = {
			define_ruler = {
				mil = 4
				adm = 1
				dip = 1
			}
		}
		if = {
			limit = {
				has_government_attribute = enables_princes_of_novogorod
			}
			create_general = { tradition = 50 }
		}
		if = {
			limit = { has_government_attribute = elections_increase_factions_influence }
			add_influence_to_mil_faction = {
				influence = 20
			}
		}
		add_karma = 10
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				mil_army = {
					add_ruler_modifier = {
						name = "Mil_Tradition"
						duration = -1
					}
				}
				mil_republic = {
					add_republican_tradition = 3
				}
				mil_infantry = {
					add_ruler_modifier = {
						name = "Mil_Infantry"
						duration = -1
					}
				}
			}
			set_ruler_flag = mil_ruler
		}
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			trigger_switch = {
				on_trigger = has_country_flag
				mil_army = {
					add_ruler_modifier = {
						name = "VP_Claims"
						duration = -1
					}
				}
				mil_republic = {
					add_ruler_modifier = {
						name = "VP_Boyar"
						duration = -1
					}
				}
				mil_infantry = {
					add_ruler_modifier = {
						name = "VP_Endurance"
						duration = -1
					}
				}
			}
			set_ruler_flag = mil_ruler
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty_by_class_mil = {
				loyalty = 10
			}
		}
		if = {
			limit = {
				has_government_attribute = has_limited_terms
			}
			hidden_effect = {
				set_variable = {
					which = election_term
					value = 1
				}
			}
		}
		if = {
			limit = { has_government_attribute = has_candidate_bonus }
			assign_ruler_focus = {
				type = mil
			}
		}
	}

	option = { # Nepotism choice, re-electing within dynasty
		name = "EVTOPTE700"
		trigger = {
			has_government_attribute = enables_nepotism
			NOT = { has_government_attribute = enables_demedici }
		}
		ai_chance = { factor = 10 }
		if = {
			limit = {
				has_country_flag = strengthened_signoria_flag
			}
			custom_tooltip = strengthened_signoria_election_tt
			clr_country_flag = strengthened_signoria_flag
		}
		else = {
			add_scaled_republican_tradition = -4
		}
		if = {
			limit = { 
				republic_with_female_rulers_trigger = yes
				NOT = { has_reform = signoria_reform }
			}
			define_ruler = {
				change_mil = -2
				change_adm = -2
				change_dip = -2
				min_age = 30
				max_age = 50
				name = "lastname"
				random_gender = yes # Allows random gender for republics
			}
		}
		else_if = {
			limit = { 
				republic_with_female_rulers_trigger = yes
				has_reform = signoria_reform
			}
			define_ruler = {
				min_age = 30
				max_age = 50
				name = "lastname"
				random_gender = yes # Allows random gender for republics
			}
		}
		else_if = {
			limit = { has_reform = signoria_reform }
			define_ruler = {
				min_age = 30
				max_age = 50
				name = "lastname"
			}
		}
		else = {
			define_ruler = {
				change_mil = -2
				change_adm = -2
				change_dip = -2
				min_age = 30
				max_age = 50
				name = "lastname"
			}
		}
		if = {
			limit = {
				has_government_attribute = enables_princes_of_novogorod
			}
			create_general = { tradition = 50 }
		}
		if = {
			limit = { 
				has_faction = mr_aristocrats 
			}
			add_faction_influence = {
				faction = mr_aristocrats
				influence = 10
			}				
		}
		hidden_effect = {
			if = {
				limit = {
					OR = {
						has_government_attribute = enable_factional_elections
						 has_government_attribute = enables_veche_parties
					}
				}
				random_list = {
					10 = { set_ruler_flag = adm_ruler }
					10 = { set_ruler_flag = dip_ruler }
					10 = { set_ruler_flag = mil_ruler }
				}
			}
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty = {
				estate = all
				loyalty = 10
			}
		}
		if = {
			limit = {
				has_government_attribute = has_limited_terms
			}
			hidden_effect = {
				set_variable = {
					which = election_term
					value = 1
				}
			}
		}
		if = {
			limit = { has_government_attribute = has_candidate_bonus }
			assign_ruler_focus = {
				type = rng
			}
		}
	}
	option = { # Nepotism choice, de'Medici
		name = "EVTOPTF700"
		trigger = {
			has_government_attribute = enables_demedici
		}
		ai_chance = { factor = 10 }
		add_scaled_republican_tradition = -5

		define_ruler = {
			change_dip = 1
			min_age = 40
			max_age = 50
			dynasty = "de' Medici"
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				adm_advisor = {
					add_ruler_modifier = {
						name = "Dip_Trade"
						duration = -1
					}
				}
				adm_stabcost = {
					add_ruler_modifier = {
						name = "Dip_Invest"
						duration = -1
					}
				}
				adm_pope = {
					add_ruler_modifier = {
						name = "Adm_Advisor"
						duration = -1
					}
				}
			}
		}
		hidden_effect = {
			if = {
				limit = { has_government_attribute = enable_factional_elections }
				random_list = {
					10 = { set_ruler_flag = adm_ruler }
					10 = { set_ruler_flag = dip_ruler }
					10 = { set_ruler_flag = mil_ruler }
				}
			}
		}
	}

	option = { # dictator #Sforza
		name = "EVTOPTG700"
		trigger = {
			has_government_attribute = enables_sforza
		}
		ai_chance = { factor = 100 }
		add_republican_tradition = -25

		define_ruler = {
			change_mil = 2
			min_age = 30
			max_age = 50
		}
		add_ruler_modifier = {
			name = "Sforza_Lifetime"
			duration = -1
		}
		if = {
			limit = {
				has_country_flag = sforza_1
			}
			define_ruler_to_general = {
				fire = 3
				shock = 4
				manuever = 3
				siege = 1
			}
		}
		if = {
			limit = {
				has_country_flag = sforza_2
			}
			define_ruler_to_general = {
				fire = 4
				shock = 2
				manuever = 1
				siege = 3
			}
		}
		if = {
			limit = {
				has_country_flag = sforza_3
			}
			define_ruler_to_general = {
				fire = 2
				shock = 2
				manuever = 6
				siege = 2
			}
		}
		if = {
			limit = {
				has_country_flag = sforza_4
			}
			define_ruler_to_general = {
				fire = 5
				shock = 3
				manuever = 1
				siege = 1
			}
		}
		if = {
			limit = {
				has_country_flag = sforza_5
			}
			define_ruler_to_general = {
				fire = 5
				shock = 4
				manuever = 1
				siege = 1
			}
		}
	}


	option = { #Caucasus Elections
		name = "EVTOPTH700"
		trigger = {
			has_government_attribute = enables_caucasus_candidates
		}
		ai_chance = { factor = 10 }

		define_ruler = {
			min_age = 30
			max_age = 50
			ADM = 3
			DIP = 3
			MIL = 3
			culture = georgian
		}
		add_ruler_modifier = {
			name = "Georgian_Ruler" #-25% State Maintenance, +1 Diprep
			duration = -1
		}
		hidden_effect = {
			if = {
				limit = { has_government_attribute = enable_factional_elections }
				random_list = {
					10 = { set_ruler_flag = adm_ruler }
					10 = { set_ruler_flag = dip_ruler }
					10 = { set_ruler_flag = mil_ruler }
				}
			}
		}
	}

	option = { #Caucasus Elections
		name = "EVTOPTI700"
		trigger = {
			has_government_attribute = enables_caucasus_candidates
		}
		ai_chance = { factor = 10 }

		define_ruler = {
			min_age = 30
			max_age = 50
			ADM = 2
			DIP = 5
			MIL = 2
			culture = circassian
		}
		add_ruler_modifier = {
			name = "Circassian_Ruler" #25% Improve Relations
			duration = -1
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				dip_trade = {
					add_ruler_modifier = {
						name = "Dip_Trade"
						duration = -1
					}
				}
				dip_gold = {
					add_years_of_income = 0.4
				}
				dip_invest = {
					add_ruler_modifier = {
						name = "Dip_Invest"
						duration = -1
					}
				}
			}
			set_ruler_flag = dip_ruler
		}
	}

	option = { #Caucasus Elections
		name = "EVTOPTJ700"
		trigger = {
			has_government_attribute = enables_caucasus_candidates
		}
		ai_chance = { factor = 10 }

		define_ruler = {
			min_age = 30
			max_age = 50
			ADM = 2
			DIP = 2
			MIL = 5
			culture = dagestani
		}
		add_ruler_modifier = {
			name = "Dagestani_Ruler" #20% Force Limit
			duration = -1
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				mil_army = {
					add_ruler_modifier = {
						name = "Mil_Tradition"
						duration = -1
					}
				}
				mil_republic = {
					add_republican_tradition = 3
				}
				mil_infantry = {
					add_ruler_modifier = {
						name = "Mil_Infantry"
						duration = -1
					}
				}
			}
			set_ruler_flag = mil_ruler
		}
	}

	option = { #Caucasus Elections
		name = "EVTOPTK700"
		trigger = {
			has_government_attribute = enables_caucasus_candidates
		}
		ai_chance = { factor = 10 }

		define_ruler = {
			min_age = 30
			max_age = 50
			ADM = 5
			DIP = 2
			MIL = 2
			culture = armenian
		}
		if = {
			limit = { religion_group = christian }
			add_ruler_modifier = {
				name = "Armenian_Zealous_Ruler" #+1 Tolerance of the True Faith
				duration = -1
			}
		}
		if = {
			limit = { NOT = { religion_group = christian } }
			add_ruler_modifier = {
				name = "Armenian_Tolerant_Ruler" #+1 Tolerance of Heretics and Heathens
				duration = -1
			}
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				adm_advisor = {
					add_ruler_modifier = {
						name = "Adm_Advisor"
						duration = -1
					}
				}
				adm_stabcost = {
					add_ruler_modifier = {
						name = "Adm_Stabcost"
						duration = -1
					}
				}
				adm_pope = {
					add_papal_influence = 10
					add_church_power = 15
					add_fervor = 20
				}
			}
			set_ruler_flag = adm_ruler
		}
	}
}

# Election!
country_event = {
	id = 701
	title = "EVTNAME700"
	desc = "EVTDESC701"
	picture = ELECTION_REPUBLICAN_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { has_states_general_mechanic = yes }
		NOT = { has_government_attribute = lottery_election }
		NOT = { has_government_attribute = is_pirate_republic_reform }
		NOT = { has_reform = american_government }
		NOT = { has_reform = military_dictatorship_reform }
		NOT = { has_reform = admiralty_reform }
		NOT = { has_reform = prussian_republic_reform }
		NOT = { has_disaster =  bonfire_of_the_vanities_disaster }
		NOT = { has_country_modifier = just_had_revolution_bringing_someone_to_power_timer }
		if = {
			limit = {
				has_reform = junior_revolutionary_republic_reform
				has_country_flag = caretaker_revolutionary_government
			}
			republican_tradition = 50
		}
	}

	immediate = {
		hidden_effect = {
			pre_select_possible_ruler_focus = yes
			pre_election_set_factional_veche = yes
			pre_election_set_sforza = yes
		}
	}
	after = {
		post_ruler_focus_clearance = yes
		post_election_clear_GE = yes
	}
	
	option = {
		name = "EVTOPTB700"	# An administrator type
		trigger = {
			NOT = { has_government_attribute = enables_caucasus_candidates }
		}
		ai_chance = { factor = 40 }
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			define_ruler = {
				change_mil = -1
				change_adm = 1
				change_dip = -1
				min_age = 40
				max_age = 60
			}
		}
		else_if = {
			limit = { republic_with_female_rulers_trigger = yes }
			define_ruler = {
				mil = 1
				adm = 4
				dip = 1
				random_gender = yes # Allows random gender for republics
			}
		}
		else = {
			define_ruler = {
				mil = 1
				adm = 4
				dip = 1
			}
		}
		if = {
			limit = { has_government_attribute = elections_increase_factions_influence }
			add_influence_to_adm_faction = {
				influence = 20
			}
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				adm_advisor = {
					add_ruler_modifier = {
						name = "Adm_Advisor"
						duration = 1825
					}
				}
				adm_stabcost = {
					add_ruler_modifier = {
						name = "Adm_Stabcost"
						duration = 1825
					}
				}
				adm_pope = {
					add_papal_influence = 10
					add_church_power = 15
					add_fervor = 20
				}
			}
			set_ruler_flag = adm_ruler
		}
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			trigger_switch = {
				on_trigger = has_country_flag
				adm_advisor = {
					add_ruler_modifier = {
						name = "VP_Tax"
						duration = -1
					}
				}
				adm_stabcost = {
					add_ruler_modifier = {
						name = "VP_Pious"
						duration = -1
					}
				}
				adm_pope = {
					add_patriarch_authority = 0.05
				}
			}
			set_ruler_flag = adm_ruler
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty_by_class_adm = {
				loyalty = 10
			}
		}
		if = {
			limit = { has_government_attribute = has_candidate_bonus }
			assign_ruler_focus = {
				type = adm
			}
		}
	}
	option = {
		name = "EVTOPTC700"	# A diplomat
		trigger = {
			NOT = { has_government_attribute = enables_caucasus_candidates }
		}
		ai_chance = { factor = 30 }
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			define_ruler = {
				change_mil = -1
				change_adm = -1
				change_dip = 1
				min_age = 40
				max_age = 60
			}
		}
		else_if = {
			limit = { republic_with_female_rulers_trigger = yes }
			define_ruler = {
				dip = 4
				adm = 1
				mil = 1
				random_gender = yes # Allows random gender for republics
			}
		}
		else = {
			define_ruler = {
				dip = 4
				adm = 1
				mil = 1
			}
		}
		if = {
			limit = { has_government_attribute = elections_increase_factions_influence }
			add_influence_to_dip_faction = {
				influence = 20
			}
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				dip_trade = {
					add_ruler_modifier = {
						name = "Dip_Trade"
						duration = 1825
					}
				}
				dip_gold = {
					add_years_of_income = 0.4
				}
				dip_invest = {
					add_ruler_modifier = {
						name = "Dip_Invest"
						duration = 1825
					}
				}
			}
			set_ruler_flag = dip_ruler
		}
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			trigger_switch = {
				on_trigger = has_country_flag
				dip_trade = {
					add_ruler_modifier = {
						name = "VP_Production"
						duration = -1
					}
				}
				dip_gold = {
					add_ruler_modifier = {
						name = "VP_Trade"
						duration = -1
					}
				}
				dip_invest = {
					add_ruler_modifier = {
						name = "VP_Diprep"
						duration = -1
					}
				}
			}
			set_ruler_flag = dip_ruler
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty_by_class_dip = {
				loyalty = 10
			}
		}
		if = {
			limit = { has_government_attribute = has_candidate_bonus }
			assign_ruler_focus = {
				type = dip
			}
		}
	}
	option = {
		name = "EVTOPTD700"	# A military man
		trigger = {
			NOT = { has_government_attribute = enables_caucasus_candidates }
		}
		ai_chance = { factor = 30 }
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			define_ruler = {
				change_mil = 1
				change_adm = -1
				change_dip = -1
				min_age = 40
				max_age = 60
			}
		}
		else_if = {
			limit = { republic_with_female_rulers_trigger = yes }
			define_ruler = {
				mil = 4
				adm = 1
				dip = 1
				random_gender = yes # Allows random gender for republics
			}
		}
		else = {
			define_ruler = {
				mil = 4
				adm = 1
				dip = 1
			}
		}
		if = {
			limit = { has_government_attribute = elections_increase_factions_influence }
			add_influence_to_mil_faction = {
				influence = 20
			}
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				mil_army = {
					add_ruler_modifier = {
						name = "Mil_Tradition"
						duration = -1
					}
				}
				mil_republic = {
					add_republican_tradition = 3
				}
				mil_infantry = {
					add_ruler_modifier = {
						name = "Mil_Infantry"
						duration = 1825
					}
				}
			}
			set_ruler_flag = mil_ruler
		}
		if = {
			limit = { has_government_attribute = enables_veche_parties }
			trigger_switch = {
				on_trigger = has_country_flag
				mil_army = {
					add_ruler_modifier = {
						name = "VP_Claims"
						duration = -1
					}
				}
				mil_republic = {
					add_ruler_modifier = {
						name = "VP_Boyar"
						duration = -1
					}
				}
				mil_infantry = {
					add_ruler_modifier = {
						name = "VP_Endurance"
						duration = -1
					}
				}
			}
			set_ruler_flag = mil_ruler
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty_by_class_mil = {
				loyalty = 10
			}
		}
		if = {
			limit = { has_government_attribute = has_candidate_bonus }
			assign_ruler_focus = {
				type = mil
			}
		}
	}
	option = { # Nepotism choice, re-electing within dynasty
		name = "EVTOPTE700"
		trigger = {
			has_government_attribute = enables_nepotism
			NOT = { has_government_attribute = enables_demedici }
		}
		ai_chance = { factor = 10 }
		if = {
			limit = {
				has_country_flag = strengthened_signoria_flag
			}
			custom_tooltip = strengthened_signoria_election_tt
			clr_country_flag = strengthened_signoria_flag
		}
		else = {
			add_scaled_republican_tradition = -4
		}
		if = {
			limit = { 
				republic_with_female_rulers_trigger = yes
				NOT = { has_reform = signoria_reform }
			}
			define_ruler = {
				change_mil = -2
				change_adm = -2
				change_dip = -2
				min_age = 30
				max_age = 50
				name = "lastname"
				random_gender = yes # Allows random gender for republics
			}
		}
		else_if = {
			limit = { 
				republic_with_female_rulers_trigger = yes
				has_reform = signoria_reform
			}
			define_ruler = {
				min_age = 30
				max_age = 50
				name = "lastname"
				random_gender = yes # Allows random gender for republics
			}
		}
		else_if = {
			limit = { 
				has_reform = signoria_reform
			}
			define_ruler = {
				min_age = 30
				max_age = 50
				name = "lastname"
				random_gender = yes # Allows random gender for republics
			}
		}
		else = {
			define_ruler = {
				change_mil = -2
				change_adm = -2
				change_dip = -2
				min_age = 30
				max_age = 50
				name = "lastname"
			}
		}
		if = {
			limit = { 
				has_faction = mr_aristocrats 
			}
			add_faction_influence = {
				faction = mr_aristocrats
				influence = 10
			}				
		}
		hidden_effect = {
			if = {
				limit = {
					OR = {
						has_government_attribute = enable_factional_elections
						 has_government_attribute = enables_veche_parties
					}
				}
				random_list = {
					10 = { set_ruler_flag = adm_ruler }
					10 = { set_ruler_flag = dip_ruler }
					10 = { set_ruler_flag = mil_ruler }
				}
			}
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty = {
				estate = all
				loyalty = 10
			}
		}
		if = {
			limit = { has_government_attribute = has_candidate_bonus }
			assign_ruler_focus = {
				type = rng
			}
		}
	}
	option = { # Nepotism choice, de'Medici
		name = "EVTOPTF700"
		trigger = {
			has_government_attribute = enables_demedici
		}
		ai_chance = { factor = 10 }
		add_scaled_republican_tradition = -5

		define_ruler = {
			change_dip = 1
			min_age = 40
			max_age = 50
			dynasty = "de' Medici"
		}
		hidden_effect = {
			if = {
				limit = { has_government_attribute = enable_factional_elections }
				random_list = {
					10 = { set_ruler_flag = adm_ruler }
					10 = { set_ruler_flag = dip_ruler }
					10 = { set_ruler_flag = mil_ruler }
				}
			}
		}
	}
	option = { # dictator #Sforza
		name = "EVTOPTG700"
		trigger = {
			has_government_attribute = enables_sforza
		}
		ai_chance = { factor = 100 }
		add_republican_tradition = -20

		define_ruler = {
			change_mil = 2
			min_age = 30
			max_age = 50
		}
		add_ruler_modifier = {
			name = "Sforza_Lifetime"
			duration = -1
		}
		if = {
			limit = {
				has_country_flag = sforza_1
			}
			define_ruler_to_general = {
				fire = 3
				shock = 4
				manuever = 3
				siege = 1
			}
		}
		if = {
			limit = {
				has_country_flag = sforza_2
			}
			define_ruler_to_general = {
				fire = 4
				shock = 2
				manuever = 1
				siege = 3
			}
		}
		if = {
			limit = {
				has_country_flag = sforza_3
			}
			define_ruler_to_general = {
				fire = 2
				shock = 2
				manuever = 6
				siege = 2
			}
		}
		if = {
			limit = {
				has_country_flag = sforza_4
			}
			define_ruler_to_general = {
				fire = 5
				shock = 3
				manuever = 1
				siege = 1
			}
		}
		if = {
			limit = {
				has_country_flag = sforza_5
			}
			define_ruler_to_general = {
				fire = 5
				shock = 4
				manuever = 1
				siege = 1
			}
		}
	}

	option = { #Caucasus Elections
		name = "EVTOPTH700"
		trigger = {
			has_government_attribute = enables_caucasus_candidates
		}
		ai_chance = { factor = 10 }

		define_ruler = {
			min_age = 30
			max_age = 50
			ADM = 3
			DIP = 3
			MIL = 3
			culture = georgian
		}
		add_ruler_modifier = {
			name = "Georgian_Ruler" #-25% State Maintenance, +1 Diprep
			duration = -1
		}
		hidden_effect = {
			if = {
				limit = { has_government_attribute = enable_factional_elections }
				random_list = {
					10 = { set_ruler_flag = adm_ruler }
					10 = { set_ruler_flag = dip_ruler }
					10 = { set_ruler_flag = mil_ruler }
				}
			}
		}
	}

	option = { #Caucasus Elections
		name = "EVTOPTI700"
		trigger = {
			has_government_attribute = enables_caucasus_candidates
		}
		ai_chance = { factor = 10 }

		define_ruler = {
			min_age = 30
			max_age = 50
			ADM = 2
			DIP = 5
			MIL = 2
			culture = circassian
		}
		add_ruler_modifier = {
			name = "Circassian_Ruler" #25% Improve Relations
			duration = -1
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				dip_trade = {
					add_ruler_modifier = {
						name = "Dip_Trade"
						duration = -1
					}
				}
				dip_gold = {
					add_years_of_income = 0.4
				}
				dip_invest = {
					add_ruler_modifier = {
						name = "Dip_Invest"
						duration = -1
					}
				}
			}
			set_ruler_flag = dip_ruler
		}
	}

	option = { #Caucasus Elections
		name = "EVTOPTJ700"
		trigger = {
			has_government_attribute = enables_caucasus_candidates
		}
		ai_chance = { factor = 10 }

		define_ruler = {
			min_age = 30
			max_age = 50
			ADM = 2
			DIP = 2
			MIL = 5
			culture = dagestani
		}
		add_ruler_modifier = {
			name = "Dagestani_Ruler" #20% Force Limit
			duration = -1
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				mil_army = {
					add_ruler_modifier = {
						name = "Mil_Tradition"
						duration = -1
					}
				}
				mil_republic = {
					add_republican_tradition = 3
				}
				mil_infantry = {
					add_ruler_modifier = {
						name = "Mil_Infantry"
						duration = -1
					}
				}
			}
			set_ruler_flag = mil_ruler
		}
	}

	option = { #Caucasus Elections
		name = "EVTOPTK700"
		trigger = {
			has_government_attribute = enables_caucasus_candidates
		}
		ai_chance = { factor = 10 }

		define_ruler = {
			min_age = 30
			max_age = 50
			ADM = 5
			DIP = 2
			MIL = 2
			culture = armenian
		}
		if = {
			limit = { religion_group = christian }
			add_ruler_modifier = {
				name = "Armenian_Zealous_Ruler" #+1 Tolerance of the True Faith
				duration = -1
			}
		}
		if = {
			limit = { NOT = { religion_group = christian } }
			add_ruler_modifier = {
				name = "Armenian_Tolerant_Ruler" #+1 Tolerance of Heretics and Heathens
				duration = -1
			}
		}
		if = {
			limit = { has_government_attribute = enable_factional_elections }
			trigger_switch = {
				on_trigger = has_country_flag
				adm_advisor = {
					add_ruler_modifier = {
						name = "Adm_Advisor"
						duration = -1
					}
				}
				adm_stabcost = {
					add_ruler_modifier = {
						name = "Adm_Stabcost"
						duration = -1
					}
				}
				adm_pope = {
					add_papal_influence = 10
					add_church_power = 15
					add_fervor = 20
				}
			}
			set_ruler_flag = adm_ruler
		}
	}
}

########################################
# Colonial Nations					 #
########################################

# Election!
country_event = {
	id = elections.707
	title = "elections.EVTNAME707"
	desc = "elections.EVTDESC707"
	picture = ELECTION_REPUBLICAN_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = "elections.EVTOPTB707"	# Bureaucrat Candidate
		ai_chance = { factor = 20 }
		FROM = {
			define_ruler = {
				adm = 4
				mil = 2
				dip = 2
			}
			set_ruler_flag = appointed_by_overlord
		}
	}
	option = {
		name = "elections.EVTOPTC707"	# Diplomat Candidate
		ai_chance = { factor = 20 }
		FROM = {
			define_ruler = {
				adm = 2
				dip = 4
				mil = 2
			}
			set_ruler_flag = appointed_by_overlord
		}
	}
	option = {
		name = "elections.EVTOPTD707"	# Military Candidate
		ai_chance = { factor = 20 }
		FROM = {
			define_ruler = {
				adm = 2
				dip = 2
				mil = 4
			}	
			set_ruler_flag = appointed_by_overlord
		}
	}
}

# Colonial Assembly
country_event = {
	id = elections.711
	title = "elections.EVTNAME711"
	desc = "elections.EVTDESC711"
	picture = ELECTION_REPUBLICAN_eventPicture
	
	is_triggered_only = yes

	option = {
		name = "elections.EVTOPTB711"	# Suspicious indeed...
		tooltip = {
			FROM = {
				add_liberty_desire = 10
			}
		}
	}
}

## Winds of Liberty
#country_event = {
#	id = elections.712
#	title = "elections.EVTNAME712"
#	desc = "elections.EVTDESC712"
#	picture = ELECTION_REPUBLICAN_eventPicture
#	
#	is_triggered_only = yes
#
#	option = {
#		name = "elections.EVTOPTB712"	# Most worrisome...
#		tooltip = {
#			FROM = {
#				add_liberty_desire = -25
#			}
#		}
#	}
#}

country_event = {
	id = elections.7001
	title = "elections.EVTNAME7001"

	picture = ELECTION_REPUBLICAN_eventPicture

	is_triggered_only = yes

	desc = {
		trigger = { NOT = { has_ruler_flag = second_term } }
		desc = "elections.EVTDESCB7001"
	}

	desc = {
		trigger = { has_ruler_flag = second_term }
		desc = "elections.EVTDESCA7001"
	}

	trigger = {
		has_reform = american_government
	}

	option = {
		name = "elections.EVTOPTA7001"

		trigger = { NOT = { has_ruler_flag = second_term } }

		ai_chance = { factor = 60 }
		custom_tooltip = remains_ruler
		set_ruler_flag = second_term
		if = {
			limit = {
				has_ruler_flag = federalist_in_office
			}
			add_faction_influence = {
				faction = GE_federalists
				influence = 5
			}
		}
		if = {
			limit = {
				has_ruler_flag = republican_in_office
			}
			add_faction_influence = {
				faction = GE_republicans
				influence = 5
			}
		}
		add_republican_tradition = -10
	}

	option = {
		name = "elections.EVTOPTB7001"
		ai_chance = { factor = 20 }
			define_ruler = {

			}
		add_faction_influence = {
			faction = GE_federalists
			influence = 10
		}
		set_ruler_flag = federalist_in_office
	}
	option = {
		name = "elections.EVTOPTC7001"
		ai_chance = { factor = 20 }
			define_ruler = {

			}
		add_faction_influence = {
			faction = GE_republicans
			influence = 10
		}
		set_ruler_flag = republican_in_office
	}
}

country_event = {
	id = elections.7002
	title = "elections.EVTNAME7001"
	desc = "EVTDESC701"
	picture = ELECTION_REPUBLICAN_eventPicture

	is_triggered_only = yes

	trigger = {
		has_reform = american_government
	}

	option = {
		name = "elections.EVTOPTB7001"
		ai_chance = { factor = 20 }
			define_ruler = {

			}
		add_faction_influence = {
			faction = GE_federalists
			influence = 10
		}
		set_ruler_flag = federalist_in_office
	}
	option = {
		name = "elections.EVTOPTC7001"
		ai_chance = { factor = 20 }
			define_ruler = {

			}
		add_faction_influence = {
			faction = GE_republicans
			influence = 10
		}
		set_ruler_flag = republican_in_office
	}
}

# Dutch Republic
country_event = {
	id = elections.720
	title = elections.720.t
	desc = {
		trigger = {
			has_government_attribute = has_dutch_election
		}
		desc = elections.720.da
	}
	
	desc = {
		trigger = { has_reform = monastic_elections_reform }
		desc = elections.720.dc
	}
	
	desc = {
		trigger = { has_reform = feuillant_reform }
		desc = elections.720.de
	}
	
	desc = {
		trigger = { 
			NOT = {
				has_government_attribute = has_dutch_election
				has_reform = crown_of_saint_wenceslaus
			} 
		}
		desc = elections.720.db
	}

	desc = {
		trigger = {	has_reform = crown_of_saint_wenceslaus }
		desc = elections.721.dc
	}
	picture = ELECTION_REPUBLICAN_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		has_states_general_mechanic = yes
		NOT = { has_reform = empire_of_japan_reform }
		OR = {
			is_lesser_in_union = no
			is_statists_in_power = yes
		}
	}
	
	option = {
		name = elections.720.a
		trigger = { 
			NOT = { has_reform = monastic_elections_reform }
			NOT = { has_reform = feuillant_reform }
		}
		if = {
			limit = {
				has_government_attribute = republican_virtues
			}
			define_ruler = {
				change_adm = 1
				change_dip = 1
				change_mil = 1
			}
		}
		else = {
			define_ruler = {
			}
		}
		if = {
			limit = {
				has_country_flag = ned_buff_statists_candidates_flag
			}
			add_estate_loyalty = {
				estate = all
				loyalty = 5
			}
		}
		change_statists_vs_orangists = -0.33
	
	}
	
	option = {
		trigger = { has_reform = feuillant_reform }
		name = elections.720.g
		define_ruler = {
		}
		add_faction_influence = {
			faction = rr_jacobins
			influence = 20
		}
		change_statists_vs_orangists = -0.33
	}
	
	option = {
		trigger = { has_reform = feuillant_reform }
		name = elections.720.h
		define_ruler = {
		}
		add_faction_influence = {
			faction = rr_girondists
			influence = 20
		}
		change_statists_vs_orangists = -0.33
	}
	
	option = {
		trigger = { 
			has_government_attribute = has_dutch_election
		}
		name = elections.720.b
		if = {
			limit = {
				NOT = {
					has_country_flag = ned_buff_orangist_candidates_flag
				}
			}
			define_ruler = {
				dynasty = "van Oranje"
			}
		}
		else = {
			define_ruler = {
				change_adm = 1
				change_dip = 1
				change_mil = 1
				dynasty = "van Oranje"
			}
		}
		change_statists_vs_orangists = 0.33
		set_ruler_flag = ned_orangist_ruler_flag
	}

	option = {
		trigger = { 
			NOT = { 
				OR = {
					has_government_attribute = has_dutch_election
					has_reform = monastic_elections_reform
				}
			} 
		}
		name = elections.720.c
		if = {
			limit = {
				has_reform = feuillant_reform
				tag = FRA
			}
			define_ruler = {
				dynasty = "Bonaparte"
			}
		}
		else_if = {
			limit = {
				has_reform = feuillant_reform
				NOT = { tag = FRA }
			}
			define_ruler = {
			}
		}
		else = {
			define_ruler = {
				dynasty = historic_dynasty # Will pick one weighted by how many rulers a family has had
			}
		}
		if = {
			limit = {
				has_reform = feuillant_reform
			}
			add_faction_influence = {
				faction = rr_royalists
				influence = 20
			}
		}
		change_statists_vs_orangists = 0.33
	}
	
	option = {
		name = elections.720.e
		trigger = { has_reform = monastic_elections_reform }
		define_ruler = {
		}
		change_statists_vs_orangists = -0.33
	}

	option = {
		trigger = { has_reform = monastic_elections_reform }
		name = elections.720.f
		define_ruler = {
		}
		change_statists_vs_orangists = 0.33
	}
}

country_event = {
	id = elections.721
	title = elections.720.t
	desc = {
		trigger = {
			has_government_attribute = has_dutch_election
		}
		desc = elections.721.da
	}
	
	desc = {
		trigger = { has_reform = monastic_elections_reform }
		desc = elections.721.dc
	}
	
	desc = {
		trigger = { has_reform = feuillant_reform }
		desc = elections.721.de
	}
	
	desc = {
		trigger = {
			NOT = {
				has_government_attribute = has_dutch_election
			}
		}
		desc = elections.721.db
	}
	picture = ELECTION_REPUBLICAN_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		has_states_general_mechanic = yes
		NOT = { has_reform = empire_of_japan_reform }
		OR = {
			is_lesser_in_union = no
			is_statists_in_power = yes
		}
	}
	
	option = {
		name = elections.720.a
		trigger = { 
			NOT = { has_reform = monastic_elections_reform }
			NOT = { has_reform = feuillant_reform }
		}
		if = {
			limit = {
				has_government_attribute = republican_virtues
			}
			define_ruler = {
				change_adm = 1
				change_dip = 1
				change_mil = 1
			}
		}
		else = {
			define_ruler = {
			}
		}
		if = {
			limit = {
				has_country_flag = ned_buff_statists_candidates_flag
			}
			add_estate_loyalty = {
				estate = all
				loyalty = 5
			}
		}
		change_statists_vs_orangists = -0.33
	
	}
	
	option = {
		trigger = { has_reform = feuillant_reform }
		name = elections.720.g
		define_ruler = {
		}
		add_faction_influence = {
			faction = rr_jacobins
			influence = 20
		}
		change_statists_vs_orangists = -0.33
	}
	
	option = {
		trigger = { has_reform = feuillant_reform }
		name = elections.720.h
		define_ruler = {
		}
		add_faction_influence = {
			faction = rr_girondists
			influence = 20
		}
		change_statists_vs_orangists = -0.33
	}
	
	option = {
		trigger = {
			has_government_attribute = has_dutch_election
		}
		name = elections.720.b
		if = {
			limit = {
				NOT = {
					has_country_flag = ned_buff_orangist_candidates_flag
				}
			}
			define_ruler = {
				dynasty = "van Oranje"
			}
		}
		else = {
			define_ruler = {
				change_adm = 1
				change_dip = 1
				change_mil = 1
				dynasty = "van Oranje"
			}
		}
		change_statists_vs_orangists = 0.33
		set_ruler_flag = ned_orangist_ruler_flag
	}

	option = {
		trigger = { 
			NOT = { 
				OR = { 
					has_government_attribute = has_dutch_election
					has_reform = monastic_elections_reform 
				} 
			} 
		}
		name = elections.720.c
		if = {
			limit = {
				has_reform = feuillant_reform
				tag = FRA
			}
			define_ruler = {
				dynasty = "Bonaparte"
			}
		}
		else_if = {
			limit = {
				has_reform = feuillant_reform
				NOT = { tag = FRA }
			}
			define_ruler = {
			}
		}
		else = {
			define_ruler = {
				dynasty = historic_dynasty # Will pick one weighted by how many rulers a family has had
			}
		}
		if = {
			limit = {
				has_reform = feuillant_reform
			}
			add_faction_influence = {
				faction = rr_royalists
				influence = 20
			}
		}
		change_statists_vs_orangists = 0.33
	}
	
	option = {
		name = elections.720.e
		trigger = { has_reform = monastic_elections_reform }
		define_ruler = {
		}
		change_statists_vs_orangists = -0.33
	}

	option = {
		trigger = { has_reform = monastic_elections_reform }
		name = elections.720.f
		define_ruler = {
		}
		change_statists_vs_orangists = 0.33
	}
}

# Lottery Election by Daniel Tolman
country_event = {
	id = elections.800
	title = elections.800.t
	desc = elections.800.d
	picture = ELECTION_REPUBLICAN_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		has_government_attribute = lottery_election
		NOT = { has_disaster =  bonfire_of_the_vanities_disaster }
	}
	
	immediate = {
		hidden_effect = {
			if = {
				limit = {
					republic_with_female_rulers_trigger = yes
					NOT = { has_country_flag = ven_new_promissione_ducale }
				}
				define_exiled_ruler = {
					exiled_as = lottery_candidate_a_@ROOT
					random_gender = yes
					min_age = 50
					max_age = 75
					change_adm = 2
					change_dip = -1
					change_mil = -1
					option = 0
				}
			}
			else_if = {
				limit = {
					republic_with_female_rulers_trigger = yes
					has_country_flag = ven_new_promissione_ducale
				}
				define_exiled_ruler = {
					exiled_as = lottery_candidate_a_@ROOT
					random_gender = yes
					min_age = 50
					max_age = 75
					change_adm = 3
					change_dip = -1
					change_mil = -1
					option = 0
				}
			}
			else_if = {
				limit = {
					NOT = { republic_with_female_rulers_trigger = yes }
					has_country_flag = ven_new_promissione_ducale
				}
				define_exiled_ruler = {
					exiled_as = lottery_candidate_a_@ROOT
					min_age = 50
					max_age = 75
					change_adm = 3
					change_dip = -1
					change_mil = -1
					option = 0
				}
			}
			else = {
				define_exiled_ruler = {
					exiled_as = lottery_candidate_a_@ROOT
					min_age = 50
					max_age = 75
					change_adm = 2
					change_dip = -1
					change_mil = -1
					option = 0
				}
			}
			if = {
				limit = {
					republic_with_female_rulers_trigger = yes
					NOT = { has_country_flag = ven_new_promissione_ducale }
				}
				
				define_exiled_ruler = {
					exiled_as = lottery_candidate_b_@ROOT
					min_age = 50
					max_age = 75
					change_adm = -1
					change_dip = 2
					change_mil = -1
					random_gender = yes
					option = 1
				}
			}
			else_if = {
				limit = {
					republic_with_female_rulers_trigger = yes
					has_country_flag = ven_new_promissione_ducale
				}
				define_exiled_ruler = {
					exiled_as = lottery_candidate_b_@ROOT
					random_gender = yes
					min_age = 50
					max_age = 75
					change_adm = -1
					change_dip = 3
					change_mil = -1
					option = 0
				}
			}
			else_if = {
				limit = {
					NOT = { republic_with_female_rulers_trigger = yes }
					has_country_flag = ven_new_promissione_ducale
				}
				define_exiled_ruler = {
					exiled_as = lottery_candidate_b_@ROOT
					min_age = 50
					max_age = 75
					change_adm = -1
					change_dip = 3
					change_mil = -1
					option = 0
				}
			}
			else = {
				define_exiled_ruler = {
					exiled_as = lottery_candidate_b_@ROOT
					min_age = 50
					max_age = 75
					change_adm = -1
					change_dip = 2
					change_mil = -1
					option = 1
				}
			}
			if = {
				limit = {
					republic_with_female_rulers_trigger = yes
					NOT = { has_country_flag = ven_new_promissione_ducale }
				}
				
				define_exiled_ruler = {
					exiled_as = lottery_candidate_c_@ROOT
					min_age = 50
					max_age = 75
					change_adm = -1
					change_dip = -1
					change_mil = 2
					random_gender = yes
					option = 2
				}
			}
			else_if = {
				limit = {
					republic_with_female_rulers_trigger = yes
					has_country_flag = ven_new_promissione_ducale
				}
				define_exiled_ruler = {
					exiled_as = lottery_candidate_c_@ROOT
					random_gender = yes
					min_age = 50
					max_age = 75
					change_adm = -1
					change_dip = -1
					change_mil = 3
					option = 0
				}
			}
			else_if = {
				limit = {
					NOT = { republic_with_female_rulers_trigger = yes }
					has_country_flag = ven_new_promissione_ducale
				}
				define_exiled_ruler = {
					exiled_as = lottery_candidate_c_@ROOT
					min_age = 50
					max_age = 75
					change_adm = -1
					change_dip = -1
					change_mil = 3
					option = 0
				}
			}
			else = {
				define_exiled_ruler = {
					exiled_as = lottery_candidate_c_@ROOT
					min_age = 50
					max_age = 75
					change_adm = -1
					change_dip = -1
					change_mil = 2
					option = 2
				}
			}
		}
	}
	
	after = {
		clear_exiled_ruler = lottery_candidate_a_@ROOT
		clear_exiled_ruler = lottery_candidate_b_@ROOT
		clear_exiled_ruler = lottery_candidate_c_@ROOT
		if = {
			limit = {
				has_government_attribute = bonus_stats_for_elected_ruler
			}
			change_adm = 1
			change_dip = 1
			change_mil = 1
		}
	}
	
	option = {
		name = elections.800.a
		ai_chance = {
			factor = 0
		}
		set_ruler = lottery_candidate_a_@ROOT
		add_republican_tradition = -25
		if = {
			limit = { 
				has_faction = mr_guilds 
			}
			add_faction_influence = {
				faction = mr_guilds
				influence = 20
			}				
		}
		custom_tooltip = lottery_candidate_bonus_one
		if = {
			limit = {
				has_government_attribute = bonus_stats_for_elected_ruler
			}
			custom_tooltip = bonus_stats_for_elected_ruler_tt
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty_by_class_adm = {
				loyalty = 10
			}
		}
	}
	option = {
		name = elections.800.b
		ai_chance = {
			factor = 0
		}
		set_ruler = lottery_candidate_b_@ROOT
		add_republican_tradition = -25
		if = {
			limit = { 
				has_faction = mr_traders 
			}
			add_faction_influence = {
				faction = mr_traders
				influence = 20
			}				
		}
		custom_tooltip = lottery_candidate_bonus_one
		if = {
			limit = {
				has_government_attribute = bonus_stats_for_elected_ruler
			}
			custom_tooltip = bonus_stats_for_elected_ruler_tt
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty_by_class_dip = {
				loyalty = 10
			}
		}
	}
	option = {
		name = elections.800.c
		ai_chance = {
			factor = 0
		}
		set_ruler = lottery_candidate_c_@ROOT
		add_republican_tradition = -25
		if = {
			limit = { 
				has_faction = mr_aristocrats 
			}
			add_faction_influence = {
				faction = mr_aristocrats
				influence = 20
			}				
		}
		custom_tooltip = lottery_candidate_bonus_one
		if = {
			limit = {
				has_government_attribute = bonus_stats_for_elected_ruler
			}
			custom_tooltip = bonus_stats_for_elected_ruler_tt
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty_by_class_mil = {
				loyalty = 10
			}
		}
	}
	option = { # lottery
		name = elections.800.da
		ai_chance = {
			factor = 90
		}
		random_list = {
			33 = { 
				set_ruler = lottery_candidate_a_@ROOT 
				if = {
					limit = { 
						has_faction = mr_guilds 
					}
					add_faction_influence = {
						faction = mr_guilds
						influence = 20
					}				
				}
				if = {
					limit = { 
						has_faction = rr_jacobins 
					}
					add_faction_influence = {
						faction = rr_jacobins
						influence = 20
					}				
				}
				if = {
					limit = { has_government_attribute = elections_influence_estates }
					add_estate_loyalty_by_class_adm = {
						loyalty = 10
					}
				}
			}
			33 = { 
				set_ruler = lottery_candidate_b_@ROOT 
				if = {
					limit = { 
						has_faction = mr_traders 
					}
					add_faction_influence = {
						faction = mr_traders
						influence = 20
					}				
				}
				if = {
					limit = { 
						has_faction = rr_royalists 
					}
					add_faction_influence = {
						faction = rr_royalists
						influence = 20
					}				
				}
				if = {
					limit = { has_government_attribute = elections_influence_estates }
					add_estate_loyalty_by_class_dip = {
						loyalty = 10
					}
				}
			}
			33 = { 
				set_ruler = lottery_candidate_c_@ROOT 
				if = {
					limit = { 
						has_faction = mr_aristocrats 
					}
					add_faction_influence = {
						faction = mr_aristocrats
						influence = 20
					}				
				}
				if = {
					limit = { 
						has_faction = rr_girondists 
					}
					add_faction_influence = {
						faction = rr_girondists
						influence = 20
					}				
				}
				if = {
					limit = { has_government_attribute = elections_influence_estates }
					add_estate_loyalty_by_class_mil = {
						loyalty = 10
					}
				}
			}
		}
		custom_tooltip = lottery_candidate_bonus_plural
		if = {
			limit = {
				has_government_attribute = bonus_stats_for_elected_ruler
			}
			custom_tooltip = bonus_stats_for_elected_ruler_tt
		}
	}
	option = { # nepotism
		name = elections.800.e
		trigger = {
			has_government_attribute = enables_nepotism
			NOT = { has_reform = demedici_dynasty_reform }
		}
		ai_chance = { factor = 10 }
		if = {
			limit = {
				has_country_flag = strengthened_signoria_flag
			}
			custom_tooltip = strengthened_signoria_election_tt
			clr_country_flag = strengthened_signoria_flag
		}
		else = {
			add_republican_tradition = -15
		}
		if = {
			limit = { 
				republic_with_female_rulers_trigger = yes
				NOT = { has_reform = signoria_reform }
			}
			define_ruler = {
				min_age = 30
				max_age = 50
				change_mil = -1
				change_adm = -1
				change_dip = -1
				name = "lastname"
				random_gender = yes # Allows random gender for republics
			}
		}
		else_if = {
			limit = { 
				republic_with_female_rulers_trigger = yes
				has_reform = signoria_reform
			}
			define_ruler = {
				min_age = 30
				max_age = 50
				name = "lastname"
				random_gender = yes # Allows random gender for republics
			}
		}
		else_if = {
			limit = { 
				NOT = { republic_with_female_rulers_trigger = yes }
				has_reform = signoria_reform
			}
			define_ruler = {
				min_age = 30
				max_age = 50
				name = "lastname"
			}
		}
		else = {
			define_ruler = {
				min_age = 30
				max_age = 50
				change_mil = -1
				change_adm = -1
				change_dip = -1
				name = "lastname"
			}
		}
		if = {
			limit = { 
				has_faction = mr_aristocrats 
			}
			add_faction_influence = {
				faction = mr_aristocrats
				influence = 10
			}				
		}
		if = {
			limit = { has_government_attribute = elections_influence_estates }
			add_estate_loyalty = {
				estate = all
				loyalty = 10
			}
		}
		if = {
			limit = {
				has_government_attribute = bonus_stats_for_elected_ruler
			}
			custom_tooltip = bonus_stats_for_elected_ruler_tt
		}
	}
	option = { # Nepotism choice, de'Medici
		name = "EVTOPTF800f"
		trigger = {
			has_reform = demedici_dynasty_reform
		}
		ai_chance = { factor = 10 }
		add_republican_tradition = -15

		define_ruler = {
			change_mil = 1
			change_adm = 1
			change_dip = 1
			min_age = 45
			max_age = 55
			dynasty = "de' Medici"
		}
	}
}
