namespace = dpe_scandal

country_event = {
	id = dpe_scandal.1
	title = dpe_scandal.1.name
	desc = dpe_scandal.1.desc
	
	picture = GFX_evt_news_room
	is_triggered_only = yes
	
	# mean_time_to_happen = { years = 100 }
		
	# 	modifier = {
	# 		factor = 0.75
	# 		OR = {
	# 			has_ethic = ethic_fanatic_authoritarian
	# 			has_ethic = ethic_authoritarian
	# 		}
	# 	}
	# 	modifier = {
	# 		factor = 1.5
	# 		NOT = { has_faction = progressive }
	# 	}
	# 	modifier = {
	# 		factor = 0.5
	# 		exists = ruler
	# 		ruler = { has_ethic = ethic_egalitarian }
	# 	}
	# }
	
	trigger = {
		is_country_type = default
		is_materialist = yes
		is_authoritarian = yes
		NOR = {
			has_civic = civic_shared_burden
			has_country_flag = dpe_recent_charity_scandal
		}
		ruler? = { NOT = { has_ethic = ethic_authoritarian } }

		count_pop_faction = {
			limit = {
				is_pop_faction_type = progressive
				support > 0.1
				faction_approval > 0.50
			}
			count = 0
		}

		any_owned_pop_group = {
			is_enslaved = no
			is_being_purged = no
			NOT = {
				is_gestalt = yes
			}
			NOR = {
				has_living_standard = {
					type = living_standard_academic_privilege
				}
				has_living_standard = {
					type = living_standard_utopian
				}
				has_living_standard = {
					type = living_standard_good
				}
			}
		}
	}
	
	immediate = {
		set_timed_country_flag = {
			flag = dpe_recent_charity_scandal
			years = 80
		}
	}
	
	option = {
		name = dpe_scandal.1.A
		
		add_modifier = {
			modifier = dpe_charity_unpopular_ruler
			years = 10
		}
		
		random_pop_faction = {
			limit = { is_pop_faction_type = technologist }
			add_modifier = {
				modifier = dpe_charity_faction_undeserving
				years = 10
			}
		}
		
		ai_chance = {
			factor = 1.5
			modifier = {
				factor = 0.25
				any_pop_faction = {
					is_pop_faction_type = technologist
					support > 0.3
				}
			}
		}
	}

	option = {
		name = dpe_scandal.1.B
		shift_ethic = ethic_egalitarian
		
		random_pop_faction = {
			limit = { is_pop_faction_type = technologist }
			add_modifier = {
				modifier = dpe_charity_faction_undeserving
				years = 10
			}
		}
		
		
		random_pop_faction = {
			limit = { is_pop_faction_type = progressive }
			add_modifier = { modifier = embraced_faction years = 10 }
			hidden_effect = { 
				add_modifier = { modifier = embraced_faction_timer years = 10 }
				owner = {
					every_pop_faction = {
						limit = {
							NOR = {
								is_same_value = prevprev
								is_pop_faction_type = technologist
							}
						}
						add_modifier = { modifier = embraced_another_faction years = 10 }
					}
				}
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				has_ethic = ethic_fanatic_authoritarian
			}
			modifier = {
				factor = 0.5
				has_ethic = ethic_authoritarian
			}
			modifier = {
				factor = 2
				any_pop_faction = {
					is_pop_faction_type = progressive
					support > 0.15
				}
			}
		}
		
		allow = { has_faction = progressive }
	}

	option = {
		name = dpe_scandal.1.C
		custom_tooltip = dpe_scandal.1.C.tooltip
		hidden_effect = {
			kill_leader = { show_notification = no }
		}
		
		ai_chance = {
			factor = 2
			modifier = {
				factor = 5
				any_pop_faction = {
					is_pop_faction_type = technologist
					support > 0.3
				}
			}
		}
	}
}


#Corruption Scandal (adapted from cc_events_blackmail.201)
country_event = {
	id = dpe_scandal.2002
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		NOR = {
			is_gestalt = yes
			has_country_flag = dpe_recent_corruption_scandal
		}
		is_at_war = no
		
		OR = {
			has_monthly_income = {
				resource = minerals
				value > 250
			}
			has_monthly_income = {
				resource = energy
				value > 250
			}
		}
	}

	# mean_time_to_happen = { years = 67 }
	
	immediate = {
		random_list = {
			1 = { #nothing
				modifier = {
					factor = 0.8
					is_materialist = yes
				}
				modifier = {
					factor = 0.8
					OR = {
						has_monthly_income = {
							resource = minerals
							value > 500
						}
						has_monthly_income = {
							resource = energy
							value > 500
						}
					}
				}
				modifier = {
					factor = 0.8
					OR = {
						has_monthly_income = {
							resource = minerals
							value > 750
						}
						has_monthly_income = {
							resource = energy
							value > 750
						}
					}
				}
				modifier = {
					factor = 0
					OR = {
						has_monthly_income = {
							resource = minerals
							value > 1000
						}
						has_monthly_income = {
							resource = energy
							value > 1000
						}
					}
				}
			}
			2 = {
				country_event = { id = dpe_scandal.2 }
			}
		}
	}
}
	
country_event = {
	id = dpe_scandal.2
	title = dpe_scandal.2.name
	desc = dpe_scandal.2.desc
	picture = GFX_evt_news_room
	
	is_triggered_only = yes

	immediate = {
		set_timed_country_flag = {
			flag = dpe_recent_corruption_scandal
			years = 80
		}
		random_owned_leader = {
			limit = {
				NOR = {
					is_same_value = root.ruler
					has_leader_flag = paragon_origin_legendary_leader
				}
			}
			save_event_target_as = cc_first_corrupt
		}
		random_owned_leader = {
			limit = {
				NOR = {
					is_same_value = root.ruler
					has_leader_flag = paragon_origin_legendary_leader
					is_same_value = event_target:cc_first_corrupt
				}
			}
			save_event_target_as = cc_second_corrupt
		}
	}
			
	
	option = {
		name = dpe_scandal.2.A
		
		custom_tooltip = dpe_scandal.2.A.tooltip
		
		hidden_effect = {
			event_target:cc_first_corrupt = { kill_leader = { show_notification = no } }
			event_target:cc_second_corrupt = { kill_leader = { show_notification = no } }
		}
		
		ai_chance = {
			factor = 2
			modifier = {
				factor = 0.5
				resource_stockpile_compare = {
					resource = influence
					value < 200
				}
			}
			modifier = {
				factor = 0.8
				if = {
					limit = { exists = event_target:cc_first_corrupt }
					event_target:cc_first_corrupt = { has_base_skill > 4 }
				}
			}
			modifier = {
				factor = 0.8
				if = {
					limit = { exists = event_target:cc_second_corrupt }
					event_target:cc_second_corrupt = { has_base_skill > 4 }
				}
			}
		}
	}
	option = {
		name = dpe_scandal.2.B
		
		add_modifier = {
			modifier = cc_outrage_at_corruption
			years = 10
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				NOT = { any_owned_planet = { planet_stability < @dpe_normal_unrest_value } }
			}
			modifier = {
				factor = 0.5
				resource_stockpile_compare = {
					resource = influence
					value > 200
				}
			}
			modifier = {
				factor = 0.5
				if = {
					limit = { exists = event_target:cc_first_corrupt }
					event_target:cc_first_corrupt = { has_base_skill < 4 }
				}
				if = {
					limit = { exists = event_target:cc_second_corrupt }
					event_target:cc_second_corrupt = { has_base_skill < 4 }
				}
			}
			modifier = {
				factor = 1.2
				if = {
					limit = { exists = event_target:cc_first_corrupt }
					event_target:cc_first_corrupt = { has_base_skill > 5 }
				}
			}
			modifier = {
				factor = 1.2
				if = {
					limit = { exists = event_target:cc_second_corrupt }
					event_target:cc_second_corrupt = { has_base_skill > 5 }
				}
			}
		}
	}
}



#Ruler does not Believe
country_event = {
	id = dpe_scandal.299
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_spiritualist = yes
		NOR = {
			has_tradition = tr_psionics_psionic_assimilation
			has_country_flag = dpe_recent_disbelief_scandal
			has_civic = civic_imperial_cult
			has_modifier = cc_ruler_cult
		}
		ruler? = {
			NOR = {
				has_ethic = ethic_spiritualist
				has_leader_flag = mem_neochadanus
			}
		}
		
		has_faction = traditionalist
		has_faction = technologist
		
		any_pop_faction = {
			is_pop_faction_type = traditionalist
			support > 0.3
		}
	}

	# mean_time_to_happen = {
	# 	years = 100
	# }

	immediate = {
		random_list = {
			2 = {
				country_event = { id = dpe_scandal.3 }

				modifier = {
					factor = 0.5
					any_pop_faction = {
						is_pop_faction_type = technologist
						support < 0.07
					}
				}
			}
			1 = {
				modifier = {
					factor = 0
					ruler = { has_ethic = ethic_materialist }
				}
			}
		}
	}
}


country_event = {
	id = dpe_scandal.3
	title = dpe_scandal.3.name
	desc = dpe_scandal.3.desc
	picture = GFX_evt_cc_priesthood

	is_triggered_only = yes

	immediate = {
		set_timed_country_flag = {
			flag = dpe_recent_disbelief_scandal
			years = 150
		}
	}

	option = {
		name = dpe_scandal.3.A
		
		allow = { has_faction = technologist }
		
		shift_ethic = ethic_materialist

		random_pop_faction = {
			limit = { is_pop_faction_type = technologist }
			add_modifier = { modifier = embraced_faction years = 10 }
			hidden_effect = { 
				add_modifier = { modifier = embraced_faction_timer years = 10 }
				owner = {
					every_pop_faction = {
						limit = {
							NOR = { is_same_value = prevprev }
							is_pop_faction_type = traditionalist
						}
						add_modifier = { modifier = embraced_another_faction years = 10 }
					}
				}
			}
		}

		custom_tooltip = dpe_scandal.3.A.tooltip
		
		hidden_effect = {
			country_event = { id = dpe_scandal.4 days = 15 }
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					any_pop_faction = {
						is_pop_faction_type = traditionalist
						support > 0.5
					}
					NOT = { 
						any_pop_faction = {
							is_pop_faction_type = technologist
							support > 0.15
						}
					}
				}
			}
			modifier = {
				factor = 2
				has_country_flag = cc_many_materialists
			}
		}
	}
	option = {
		name = dpe_scandal.3.B
		custom_tooltip = dpe_scandal.3.B.tooltip
		
		add_modifier = {
			modifier = dpe_unbelief_empire
			years = 10
		}
		
		random_pop_faction = {
			limit = { is_pop_faction_type = traditionalist }
			add_modifier = { modifier = dpe_unbelief_faction years = 10 }
		}
		
		ai_chance = {
			factor = 2
			modifier = {
				factor = 0.5
				OR = {
					any_pop_faction = {
						is_pop_faction_type = traditionalist
						support > 0.5
					}
					NOT = { 
						any_pop_faction = {
							is_pop_faction_type = technologist
							support > 0.15
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				ruler = { has_base_skill < 4 }
			}
			modifier = {
				factor = 2
				ruler = { has_base_skill > 4 }
			}
			modifier = {
				factor = 2
				ruler = { has_base_skill > 6 }
			}
		}
	}
	option = {
		name = dpe_scandal.3.C
		custom_tooltip = dpe_scandal.3.C.tooltip
		hidden_effect = {
			kill_leader = { show_notification = no }
		}
		
		ai_chance = {
			factor = 2
			modifier = {
				factor = 5
				any_pop_faction = {
					is_pop_faction_type = traditionalist
					support > 0.5
				}
			}
			modifier = {
				factor = 2
				ruler = { has_base_skill < 4 }
			}
			modifier = {
				factor = 0.5
				ruler = { has_base_skill > 4 }
			}
			modifier = {
				factor = 0.5
				ruler = { has_base_skill > 6 }
			}
		}
	}
}

#Ruler does not Believe
country_event = {
	id = dpe_scandal.4
	title = dpe_scandal.4.name
	desc = dpe_scandal.4.desc
	picture = GFX_evt_cc_priesthood
	
	is_triggered_only = yes
	
	trigger = { has_faction = traditionalist }
	
	option = {
		name = UNFORTUNATE
		
		add_modifier = {
			modifier = dpe_damned_to_hell_empire
			years = 10
		}
		
		random_pop_faction = {
			limit = { is_pop_faction_type = traditionalist }
			add_modifier = { modifier = dpe_damned_to_hell_faction years = 10 }
		}
	}
}


#Ruler is an ex-slave
country_event = {
	id = dpe_scandal.10
	title = dpe_scandal.10.name
	desc = dpe_scandal.10.desc
	
	diplomatic = yes

	is_triggered_only = yes
	
	picture_event_data = {
		portrait = root
		room = root.ruler
	}
	
	trigger = {
		is_country_type = default
		is_gestalt = no
		years_passed > 25
		allows_slavery = yes
		
		NOT = { has_country_flag = dpe_recent_escaped_slave_ruler }
		
		is_imperial_authority =no
		NOT = { has_tradition = tr_psionics_psionic_assimilation }
		any_owned_pop_group = {
			is_same_species = root.ruler
			is_enslaved = yes
		}

		ruler? = {
			NOT = {
				has_trait = leader_trait_chosen
			}
		}
	}
	
	# mean_time_to_happen = { years = 115 }
	
	immediate = {
		set_timed_country_flag = {
			flag = dpe_recent_escaped_slave_ruler
			years = 120
		}
		
		random_list = {
			1 = {
				set_timed_country_flag = {
					flag = dpe_escaped_slave_ruler_generic
					months = 1
				}
			}
			2 = {
				set_timed_country_flag = {
					flag = dpe_escaped_slave_ruler_egal
					months = 1
				}
				modifier = {
					factor = 0
					OR = {
						is_egalitarian = yes
						NOT = { has_faction = progressive }
						is_democratic_authority = yes
					}
				}
				modifier = {
					factor = 2
					any_pop_faction = {
						is_pop_faction_type = progressive
						support > 0.15
					}
				}
			}
			1 = {
				set_timed_country_flag = {
					flag = dpe_escaped_slave_ruler_spir
					months = 1
				}
				modifier = {
					factor = 0
					OR = {
						is_spiritualist = yes
						NOT = { has_faction = traditionalist }
					}
				}
				modifier = {
					factor = 2
					any_pop_faction = {
						is_pop_faction_type = traditionalist
						support > 0.15
					}
				}
			}
			1 = {
				set_timed_country_flag = {
					flag = dpe_escaped_slave_ruler_mil
					months = 1
				}
				modifier = {
					factor = 0
					OR = {
						is_militarist = yes
						NOT = { has_faction = imperialist }
					}
				}
				modifier = {
					factor = 2
					any_pop_faction = {
						is_pop_faction_type = imperialist
						support > 0.15
					}
				}
			}
			1 = {
				set_timed_country_flag = {
					flag = dpe_escaped_slave_ruler_pac
					months = 1
				}
				modifier = {
					factor = 0
					OR = {
						is_pacifist = yes
						NOT = { has_faction = prosperity }
					}
				}
				modifier = {
					factor = 2
					any_pop_faction = {
						is_pop_faction_type = prosperity
						support > 0.15
					}
				}
			}
			1 = {
				set_timed_country_flag = {
					flag = dpe_escaped_slave_ruler_mat
					months = 1
				}
				modifier = {
					factor = 0
					OR = {
						is_materialist = yes
						NOT = { has_faction = technologist }
					}
				}
				modifier = {
					factor = 2
					any_pop_faction = {
						is_pop_faction_type = technologist
						support > 0.15
					}
				}
			}
			1 = {
				set_timed_country_flag = {
					flag = dpe_escaped_slave_ruler_phobe
					months = 1
				}
				modifier = {
					factor = 0
					OR = {
						is_xenophobe = yes
						NOT = {
							has_faction = supremacist
						}
					}
				}
				modifier = {
					factor = 2
					any_pop_faction = {
						is_pop_faction_type = supremacist
						support > 0.15
					}
				}
			}
			1 = {
				set_timed_country_flag = {
					flag = dpe_escaped_slave_ruler_phile
					months = 1
				}
				modifier = {
					factor = 0
					OR = {
						is_xenophile = yes
						NOT = { has_faction = xenoist }
					}
				}
				modifier = {
					factor = 2
					any_pop_faction = {
						is_pop_faction_type = xenoist
						support > 0.15
					}
				}
			}
		}
	}
	
	option = {
		name = dpe_scandal.10.A
		custom_tooltip = dpe_scandal.10.A.tooltip
		
		hidden_effect = {
			random_list = {
				1 = { country_event = { id = dpe_scandal.11 days = 5 } }
				3 = { country_event = { id = dpe_scandal.12 days = 1 } }
			}
		}
	}
	option = {
		name = dpe_scandal.10.B
		
		hidden_effect = {
			country_event = { id = dpe_scandal.14 }
		}
	}
}

country_event = {
	id = dpe_scandal.11
	title = dpe_scandal.11.name
	desc = dpe_scandal.11.desc
	
	picture = GFX_evt_smugglers_in_bar
	
	is_triggered_only = yes
	
	option = {
		name = CCEXCELLENT
		
		if = {
			limit = { ruler? = { NOT = { has_trait = leader_trait_dpe_ruthless } } }
			ruler = {
				add_trait = {
					trait = leader_trait_dpe_ruthless
					show_message = no
				}
			}
		}
	}
}

country_event = {
	id = dpe_scandal.12
	title = dpe_scandal.12.name
	desc = dpe_scandal.12.desc
	
	picture = GFX_evt_throne_room
	
	is_triggered_only = yes
	
	immediate = {
		random_owned_leader = {
			limit = { NOT = { is_same_value = root.ruler } }
			save_event_target_as = random_guy
		}
	}
	
	option = {
		name = dpe_scandal.12.A
		
		custom_tooltip = dpe_scandal.12.A.tooltip
		
		hidden_effect = {
			kill_leader = { show_notification = no }
		}
	}
	option = {
		name = dpe_scandal.12.B
		
		custom_tooltip = dpe_scandal.12.B.tooltip
		
		hidden_effect = {
			kill_leader = { show_notification = no }
		}
	}
}


country_event = {
	id = dpe_scandal.14
	title = dpe_scandal.14.name
	desc = {
		trigger = {
			switch = {
				trigger = has_country_flag
				dpe_escaped_slave_ruler_generic = { text = dpe_scandal.14.desc.generic }
				dpe_escaped_slave_ruler_phile = { text = dpe_scandal.14.desc.phile }
				dpe_escaped_slave_ruler_phobe = { text = dpe_scandal.14.desc.phobe }
				dpe_escaped_slave_ruler_mat = { text = dpe_scandal.14.desc.mat }
				dpe_escaped_slave_ruler_pac = { text = dpe_scandal.14.desc.pac }
				dpe_escaped_slave_ruler_egal = { text = dpe_scandal.14.desc.egal }
				dpe_escaped_slave_ruler_spir = { text = dpe_scandal.14.desc.spir }
				dpe_escaped_slave_ruler_mil = { text = dpe_scandal.14.desc.mil }
				default = { text = dpe_scandal.14.desc.generic }
			}
		}
	}
	
	diplomatic = yes
	
	picture_event_data = {
		portrait = root
		room = root.ruler
	}
	
	is_triggered_only = yes

	option = {
		name = dpe_scandal.14.A
		
		if = {
			limit = { has_country_flag = dpe_escaped_slave_ruler_generic }

			add_modifier = {
				modifier = cc_paid_blackmail
				years = 1
			}
		}
		
		if = {
			limit = { has_country_flag = dpe_escaped_slave_ruler_egal }
			custom_tooltip = CCREMOVERULER.tooltip
			hidden_effect = {
				kill_leader = { show_notification = no }
			}
			shift_ethic = ethic_egalitarian
#			change_government = { authority = auth_democratic }
			
			random_pop_faction = {
				limit = { is_pop_faction_type = progressive }
				add_modifier = { modifier = embraced_faction years = 10 }
				hidden_effect = { 
					add_modifier = { modifier = embraced_faction_timer years = 10 }
					owner = {
						every_pop_faction = {
							limit = {
								NOT = { is_same_value = prevprev }
							}
							add_modifier = { modifier = embraced_another_faction years = 10 }
						}
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = dpe_escaped_slave_ruler_phile }
			
			shift_ethic = ethic_xenophile
			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				add_modifier = { modifier = embraced_faction years = 10 }
				hidden_effect = { 
					add_modifier = { modifier = embraced_faction_timer years = 10 }
					owner = {
						every_pop_faction = {
							limit = {
								NOT = { is_same_value = prevprev }
							}
							add_modifier = { modifier = embraced_another_faction years = 10 }
						}
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = dpe_escaped_slave_ruler_phobe }
			
			shift_ethic = ethic_xenophobe
			random_pop_faction = {
				limit = { is_pop_faction_type = supremacist }
				add_modifier = { modifier = embraced_faction years = 10 }
				hidden_effect = { 
					add_modifier = { modifier = embraced_faction_timer years = 10 }
					owner = {
						every_pop_faction = {
							limit = {
								NOT = { is_same_value = prevprev }
							}
							add_modifier = { modifier = embraced_another_faction years = 10 }
						}
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = dpe_escaped_slave_ruler_mat }
			
			shift_ethic = ethic_materialist
			random_pop_faction = {
				limit = { is_pop_faction_type = technologist }
				add_modifier = { modifier = embraced_faction years = 10 }
				hidden_effect = { 
					add_modifier = { modifier = embraced_faction_timer years = 10 }
					owner = {
						every_pop_faction = {
							limit = {
								NOT = { is_same_value = prevprev }
							}
							add_modifier = { modifier = embraced_another_faction years = 10 }
						}
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = dpe_escaped_slave_ruler_pac }
			
			shift_ethic = ethic_pacifist
			random_pop_faction = {
				limit = { is_pop_faction_type = progressive }
				add_modifier = { modifier = embraced_faction years = 10 }
				hidden_effect = { 
					add_modifier = { modifier = embraced_faction_timer years = 10 }
					owner = {
						every_pop_faction = {
							limit = {
								NOT = { is_same_value = prevprev }
							}
							add_modifier = { modifier = embraced_another_faction years = 10 }
						}
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = dpe_escaped_slave_ruler_spir }
			
			shift_ethic = ethic_spiritualist
			random_pop_faction = {
				limit = { is_pop_faction_type = traditionalist }
				add_modifier = { modifier = embraced_faction years = 10 }
				hidden_effect = { 
					add_modifier = { modifier = embraced_faction_timer years = 10 }
					owner = {
						every_pop_faction = {
							limit = {
								NOT = { is_same_value = prevprev }
							}
							add_modifier = { modifier = embraced_another_faction years = 10 }
						}
					}
				}
			}
		}
		if = {
			limit = { has_country_flag = dpe_escaped_slave_ruler_mil }
			
			shift_ethic = ethic_militarist
			random_pop_faction = {
				limit = { is_pop_faction_type = imperialist }
				add_modifier = { modifier = embraced_faction years = 10 }
				hidden_effect = { 
					add_modifier = { modifier = embraced_faction_timer years = 10 }
					owner = {
						every_pop_faction = {
							limit = {
								NOT = { is_same_value = prevprev }
							}
							add_modifier = { modifier = embraced_another_faction years = 10 }
						}
					}
				}
			}
		}
	}
	option = {
		name = dpe_scandal.14.B
		custom_tooltip = dpe_scandal.14.B.tooltip
		
		hidden_effect = {
			random_list = {
				1 = { country_event = { id = dpe_scandal.11 days = 5 } }
				3 = { country_event = { id = dpe_scandal.12 days = 1 } }
			}
		}
	}
}




#Ruler is a Cultist
country_event = {
	id = dpe_scandal.16
	title = dpe_scandal.16.name
	desc = dpe_scandal.16.desc
	picture = GFX_evt_psionics

	is_triggered_only = yes
	
	trigger = {
		is_country_type = default
		is_materialist = yes
		has_faction = traditionalist
		NOR = {
			has_country_flag = dpe_recent_cultist_scandal
			has_modifier = cc_ruler_cult
		}
		
		ruler? = { NOT = { has_ethic = ethic_materialist } }
	}
		
		
	# mean_time_to_happen = {
	# 	years = 100
	# }
	
	immediate = {
		set_timed_country_flag = {
			flag = dpe_recent_cultist_scandal
			years = 65
		}
		create_leader = {
			class = commander
			name = random
			species = owner_main_species
			skill = 1
		}
		last_created_leader = {
			save_event_target_as = dpe_cultist
			exile_leader_as = dpe_cultist
		}

		random_pop_faction = {
			limit = { is_pop_faction_type = technologist }
			save_event_target_as = dpe_matfaction
		}
		random_pop_faction = {
			limit = { is_pop_faction_type = traditionalist }
			save_event_target_as = dpe_spirfaction
		}
	}
			
	
	option = {
		name = dpe_scandal.16.A
		
		shift_ethic = ethic_spiritualist

		random_pop_faction = {
			limit = { is_pop_faction_type = technologist }
			add_modifier = { modifier = dpe_cultist_embraced years = 10 }
		}

		random_pop_faction = {
			limit = { is_pop_faction_type = traditionalist }
			add_modifier = { modifier = embraced_faction years = 10 }
			hidden_effect = { 
				add_modifier = { modifier = embraced_faction_timer years = 10 }
				owner = {
					every_pop_faction = {
						limit = {
							NOR = { is_same_value = prevprev }
							is_pop_faction_type = technologist
						}
						add_modifier = { modifier = embraced_another_faction years = 10 }
					}
				}
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					any_pop_faction = {
						is_pop_faction_type = technologist
						support > 0.5
					}
					any_pop_faction = {
						is_pop_faction_type = traditionalist
						support < 0.12
					}
				}
			}
			modifier = {
				factor = 2
				any_pop_faction = {
					is_pop_faction_type = traditionalist
					support > 0.18
				}
			}
		}
	}
	option = {
		name = dpe_scandal.16.B
		
		add_modifier = {
			modifier = dpe_cultist_scandal_empire
			years = 10
		}
		
		random_pop_faction = {
			limit = { is_pop_faction_type = technologist }
			add_modifier = { modifier = dpe_cultist_faction years = 10 }
		}
		
		ai_chance = {
			factor = 2
			modifier = {
				factor = 0.5
				OR = {
					any_pop_faction = {
						is_pop_faction_type = technologist
						support > 0.5
					}
					any_pop_faction = {
						is_pop_faction_type = traditionalist
						support < 0.12
					}
				}
			}
			modifier = {
				factor = 0.5
				ruler = { has_base_skill < 4 }
			}
			modifier = {
				factor = 2
				ruler = { has_base_skill > 4 }
			}
			modifier = {
				factor = 2
				ruler = { has_base_skill > 6 }
			}
		}
	}
	option = {
		name = dpe_scandal.16.C
		custom_tooltip = CCREMOVERULER.tooltip
		hidden_effect = {
			kill_leader = { show_notification = no }
		}
		
		ai_chance = {
			factor = 2
			modifier = {
				factor = 5
				any_pop_faction = {
					is_pop_faction_type = technologist
					support > 0.5
				}
			}
			modifier = {
				factor = 2
				ruler = { has_base_skill < 4 }
			}
			modifier = {
				factor = 0.5
				ruler = { has_base_skill > 4 }
			}
			modifier = {
				factor = 0.5
				ruler = { has_base_skill > 6 }
			}
		}
	}
}



#remove modifiers if ruler changes
country_event = {
	id = dpe_scandal.99
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_imp_or_dict = no
	}			
	
	immediate = {
		if = {
			limit = { has_modifier = dpe_charity_unpopular_ruler }
			remove_modifier = dpe_charity_unpopular_ruler
		}
		
		if = {
			limit = {
				any_pop_faction = {
					is_pop_faction_type = technologist
					has_modifier = dpe_charity_faction_undeserving
				}
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = technologist }
				remove_modifier = dpe_charity_faction_undeserving
			}
		}
		
		if = {
			limit = { has_modifier = cc_ruler_humiliated }
			remove_modifier = cc_ruler_humiliated
		}
		
		if = {
			limit = {
				any_pop_faction = {
					is_pop_faction_type = xenoist
					has_modifier = cc_xenophobic_offence_1
				}
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				remove_modifier = cc_xenophobic_offence_1
			}
		}
		
		if = {
			limit = {
				any_pop_faction = {
					is_pop_faction_type = xenoist
					has_modifier = cc_xenophobic_offence_2
				}
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				remove_modifier = cc_xenophobic_offence_2
			}
		}
		
		
		if = {
			limit = { has_modifier = dpe_unbelief_empire }
			remove_modifier = dpe_unbelief_empire
		}
		
		if = {
			limit = {
				any_pop_faction = {
					is_pop_faction_type = traditionalist
					has_modifier = dpe_unbelief_faction
				}
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = traditionalist }
				remove_modifier = dpe_unbelief_faction
			}
		}
		
		if = {
			limit = { has_modifier = dpe_damned_to_hell_empire }
			remove_modifier = dpe_damned_to_hell_empire
		}
		
		if = {
			limit = {
				any_pop_faction = {
					is_pop_faction_type = traditionalist
					has_modifier = dpe_damned_to_hell_faction
				}
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = traditionalist }
				remove_modifier = dpe_damned_to_hell_faction
			}
		}
	}
}

