namespace = cc_events_mod

@tier3researchreward = 12
@tier3researchmin = 100
@tier3researchmax = 10000

#Xenophobic Comments Gatekeeper
country_event = {
	id = cc_events_mod.1009
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_country_type = default
		has_faction = xenoist
		
		has_country_flag = cc_eventperf_has_minority
		
		NOR = {
			has_country_flag = recent_xenophobic_comments
			is_gestalt = yes
			has_ethic = ethic_fanatic_xenophile
		}
		
		
		exists = ruler
		NOT = { ruler = { has_ethic = ethic_xenophile } }
	}
	
	# mean_time_to_happen = {
	# 	years = 40
	# }
	
	immediate = {
		random_list = {
			2 = {
				if = {
					limit = {
						OR = {
							is_democratic_authority = yes
							is_oligarchic_authority = yes
							is_dictatorial_authority = yes
						}
					}
					country_event = { id = cc_events_mod.1 }
				}
				if = {
					limit = { is_imperial_authority = yes }
					country_event = { id = cc_events_mod.2 }
				}
				modifier = {
					factor = 2
					ruler = { has_ethic = ethic_xenophobe }
				}
				modifier = {
					factor = 2
					is_xenophobe = yes
				}
			}
			2 = {
				modifier = {
					factor = 1.5
					has_ethic = ethic_xenophile
				}
				modifier = {
					factor = 1.25
					NOT = { has_country_flag = cc_eventperf_has_large_minority }
				}
				modifier = {
					factor = 1.25
					NOT = { has_country_flag = cc_eventperf_has_lots_of_xenophobes_min }
				}
			}
		}
	}
}

country_event = {
	id = cc_events_mod.1
	title = cc_events_mod.1.name
	desc = {
		trigger = {
			hidden:event_target:discriminated_species = {
				switch = {
					trigger = is_species_class
					HUM = { text = cc_events_mod.1.HUM }
					MAM = { text = cc_events_mod.1.MAM }
					REP = { text = cc_events_mod.1.REP }
					AVI = { text = cc_events_mod.1.AVI }
					ART = { text = cc_events_mod.1.ART }
					MOL = { text = cc_events_mod.1.MOL }
					FUN = { text = cc_events_mod.1.FUN }
					PLANT = { text = cc_events_mod.1.PLANT }
					default = { text = cc_events_mod.1.desc }
				}
			}
		}
	}
	picture = GFX_evt_alien_segregation
	
	is_triggered_only = yes
	
	trigger = {
		is_country_type = default
		
		has_faction = xenoist
		OR = {
			is_democratic_authority = yes
			is_oligarchic_authority = yes
			is_dictatorial_authority = yes
		}
		NOT = { has_country_flag = recent_xenophobic_comments }
		is_gestalt = no
		NOT = { has_ethic = ethic_fanatic_xenophile }
		
		exists = ruler
		NOT = { ruler = { has_ethic = ethic_xenophile } }

		any_owned_pop_group = {
			NOT = { is_same_species = root }
			pop_group_has_happiness = yes
			is_robot_pop = no
			OR = {
				has_citizenship_type = { country = root type = citizenship_full }
				has_citizenship_type = { country = root type = citizenship_limited }
			}
			root = {
				OR = {
					pop_amount_percentage = {
						percentage > 0.15
						limit = { is_same_species = prev }
					}
					AND = {
						num_owned_planets > 25
						pop_amount_percentage = {
							percentage > 0.05
							limit = { is_same_species = prev }
						}
						pop_amount_percentage = {
							percentage < 0.4
							limit = { is_same_species = root }
						}
					}
				}
			}
		}
	}
	
	immediate = {
		set_timed_country_flag = {
			flag = recent_xenophobic_comments
			years = 65
		}
		random_owned_pop_group = {
			limit = {
				NOT = { is_same_species = root }
				is_robot_pop = no
				pop_group_has_happiness = yes
				OR = {
					has_citizenship_type = { country = root type = citizenship_full }
					has_citizenship_type = { country = root type = citizenship_limited }
				}
				root = {
					OR = {
						pop_amount_percentage = {
							percentage > 0.15
							limit = { is_same_species = prev }
						}
						AND = {
							num_owned_planets > 25
							pop_amount_percentage = {
								percentage > 0.05
								limit = { is_same_species = prev }
							}
							pop_amount_percentage = {
								percentage < 0.4
								limit = { is_same_species = root }
							}
						}
					}
				}
			}
			save_event_target_as = discriminated_species
		}
		random_pop_faction = {
			limit = { is_pop_faction_type = xenoist }
			save_event_target_as = xenoist_faction
		}
	}
	
	option = {	#step down
		name = cc_events_mod.1.A
		custom_tooltip = cc_events_mod.1.A.tooltip
		default_hide_option = yes
		hidden_effect = {
			kill_leader = { show_notification = no }
		}
		add_modifier = {
			modifier = cc_acceeded_to_demands_xenophile
			years = 10
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 100
				has_ethic = ethic_xenophile
			}
			modifier = {
				factor = 0
				OR = {
					is_xenophobe = yes
					is_dictatorial_authority = yes
				}
			}
		}
	}
	option = {	#defend reputation (say what he said wasn't so bad)
		name = cc_events_mod.1.B
		custom_tooltip = cc_events_mod.1.B.tooltip
		
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_ethic = ethic_fanatic_xenophobe
					}
				}
				if = {
					limit = { has_faction = supremacist }
					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 = {
										NOR = {
											is_same_value = prevprev
											is_pop_faction_type = xenoist
											is_pop_faction_type = isolationist
										}
									}
									add_modifier = { modifier = embraced_another_faction years = 10 }
								}
							}
						}
					}
				}
				else = {
					random_pop_faction = {
						limit = { is_pop_faction_type = isolationist }
						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 = xenoist
										}
									}
									add_modifier = { modifier = embraced_another_faction years = 10 }
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					has_ethic = ethic_xenophobe
				}
				shift_ethic = "ethic_fanatic_xenophobe"
			}
			else_if = {
				limit = {
					is_xenophobe = no
				}
				shift_ethic = "ethic_xenophobe"
			}

			every_owned_pop_group = {
				limit = { is_same_species = event_target:discriminated_species }
				add_modifier = {
					modifier = cc_species_insulted_2
					years = 10
				}
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				add_modifier = {
					modifier = cc_xenophobic_offence_2
					years = 10
				}
			}
		}
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0
				is_xenophobe = no
			}
		}
	}
	option = {	#we have more important things to worry about
		name = cc_events_mod.1.C
		custom_tooltip = cc_events_mod.1.C.tooltip
		
		hidden_effect = {
			every_owned_pop_group = {
				limit = { is_same_species = event_target:discriminated_species }
				add_modifier = {
					modifier = cc_species_insulted_1
					years = 10
				}
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				add_modifier = {
					modifier = cc_xenophobic_offence_1
					years = 10
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 10
				is_xenophobe = yes
			}
		}
	}
}
	
	
#triggered in performance
#xenophobic comments
country_event = {
	id = cc_events_mod.2
	title = cc_events_mod.1.name
	desc = {
		trigger = {
			hidden:event_target:discriminated_species = {
				switch = {
					trigger = is_species_class
					HUM = { text = cc_events_mod.2.HUM }
					MAM = { text = cc_events_mod.2.MAM }
					REP = { text = cc_events_mod.2.REP }
					AVI = { text = cc_events_mod.2.AVI }
					ART = { text = cc_events_mod.2.ART }
					MOL = { text = cc_events_mod.2.MOL }
					FUN = { text = cc_events_mod.2.FUN }
					PLANT = { text = cc_events_mod.2.PLANT }
					default = { text = cc_events_mod.2.desc }
				}
			}
		}
	}
	picture = GFX_evt_alien_segregation
	
	trigger = {
		is_country_type = default
		
		has_faction = xenoist
		is_imperial_authority = yes
		NOR = {
			has_country_flag = recent_xenophobic_comments
			is_gestalt = yes
			has_ethic = ethic_fanatic_xenophile
		}
		
		exists = ruler
		NOT = { ruler = { has_ethic = ethic_xenophile } }

		
		any_owned_species = {
			NOT = { is_same_species = root }
			is_robotic_species = no
			species_has_happiness_with_owner = root
			OR = {
				has_citizenship_type = { country = root type = citizenship_full }
				has_citizenship_type = { country = root type = citizenship_limited }
			}
			root = {
				OR = {
					pop_amount_percentage = {
						percentage > 0.15
						limit = { is_same_species = prev }
					}
					AND = {
						num_owned_planets > 25
						pop_amount_percentage = {
							percentage > 0.05
							limit = { is_same_species = prev }
						}
						pop_amount_percentage = {
							percentage < 0.4
							limit = {
								is_same_species = root
							}
						}
					}
				}
			}
		}
	}
	
	is_triggered_only = yes
	
	
	immediate = {
		set_timed_country_flag = {
			flag = recent_xenophobic_comments
			years = 65
		}
		random_owned_species = {
			limit = {
				NOT = { is_same_species = root }
				is_robotic_species = no
				species_has_happiness_with_owner = root
				OR = {
					has_citizenship_type = { country = root type = citizenship_full }
					has_citizenship_type = { country = root type = citizenship_limited }
				}
				root = {
					OR = {
						pop_amount_percentage = {
							percentage > 0.15
							limit = { is_same_species = prev }
						}
						AND = {
							num_owned_planets > 25
							pop_amount_percentage = {
								percentage > 0.05
								limit = { is_same_species = prev }
							}
							pop_amount_percentage = {
								percentage < 0.4
								limit = {
									is_same_species = root
								}
							}
						}
					}
				}
			}
			save_event_target_as = discriminated_species
		}
		random_pop_faction = {
			limit = { is_pop_faction_type = xenoist }
			save_event_target_as = xenoist_faction
		}
	}
	
	option = { #offer a sincere apology
		name = cc_events_mod.2.A
		add_modifier = {
			modifier = cc_ruler_humiliated
			years = 10
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 100
				has_ethic = ethic_xenophile
			}
			modifier = {
				factor = 0
				is_xenophobe = yes
			}
		}
	}
	option = { #the king does not apologise
		name = cc_events_mod.2.B
		custom_tooltip = cc_events_mod.2.B.tooltip
		
		hidden_effect = {
			every_owned_pop_group = {
				limit = { is_same_species = event_target:discriminated_species }
				add_modifier = {
					modifier = cc_species_insulted_1
					years = 10
				}
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				add_modifier = {
					modifier = cc_xenophobic_offence_1
					years = 10
				}
			}
		}
		ai_chance = {
			factor = 10
		}
	}
	option = { #the king has made his opinion clear
		name = cc_events_mod.2.C
		custom_tooltip = cc_events_mod.2.C.tooltip
		
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_ethic = ethic_fanatic_xenophobe
					}
				}
				if = {
					limit = { has_faction = supremacist }
					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 = {
										NOR = {
											is_same_value = prevprev
											is_pop_faction_type = xenoist
											is_pop_faction_type = isolationist
										}
									}
									add_modifier = { modifier = embraced_another_faction years = 10 }
								}
							}
						}
					}
				}
				else = {
					random_pop_faction = {
						limit = { is_pop_faction_type = isolationist }
						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 = xenoist
										}
									}
									add_modifier = { modifier = embraced_another_faction years = 10 }
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					has_ethic = ethic_xenophobe
				}
				shift_ethic = "ethic_fanatic_xenophobe"
			}
			else_if = {
				limit = {
					is_xenophobe = no
				}
				shift_ethic = "ethic_xenophobe"
			}
			every_owned_pop_group = {
				limit = { is_same_species = event_target:discriminated_species }
				add_modifier = {
					modifier = cc_species_insulted_2
					years = 10
				}
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				add_modifier = {
					modifier = cc_xenophobic_offence_2
					years = 10
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				has_ethic = ethic_xenophile
			}
			modifier = {
				factor = 10
				is_xenophobe = yes
			}
		}
	}
}





# A war has been won
# Root = Winner Warleader
# From = Loser Warleader
# FromFrom = War
country_event = {
	id = cc_events_mod.3
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		is_country_type = default
		is_imp_or_dict = yes
		is_materialist = no
		has_faction	= traditionalist
		
		NOR = {
			has_civic = civic_imperial_cult
			has_modifier = cc_ruler_cult
		}
		NOT = { leader = { has_leader_flag = cc_leader_revered_event } }
		NOT = { has_country_flag = dpe_recent_disbelief_scandal }
	}
	
	immediate = {
		leader = { set_leader_flag = cc_leader_revered_event }
		
		country_event = { id = cc_events_mod.4 days = 180 random = 90 }
	}
}


country_event = {
	id = cc_events_mod.4
	title = cc_events_mod.4.name
	desc = cc_events_mod.4.desc
	
	picture = GFX_evt_cc_throne_room

	is_triggered_only = yes
	
	trigger = {
		is_imp_or_dict = yes
		is_materialist = no
		has_faction	= traditionalist

		NOT = { has_tradition = tr_psionics_psionic_assimilation }
		
		ruler? = { has_leader_flag = cc_leader_revered_event }
	}
	

	option = { #long live the king!
		name = cc_events_mod.4.A
		
		add_modifier = {
			modifier = cc_ruler_revered
			years = 15
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				is_spiritualist = yes
			}
		}
	}
	
	option = { #the king is a god!
		name = cc_events_mod.4.B
		
		add_modifier = {
			modifier = cc_ruler_cult
			days = -1
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				is_spiritualist = no
			}
		}
	}
}

# Executed as a leader has died
# This = Country
# From = Leader
country_event = {
	id = cc_events_mod.5
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		from = {
			is_same_value = root.leader
		}
	}
	
	immediate = {
		if = {
			limit = { has_modifier = cc_ruler_revered }
			remove_modifier = cc_ruler_revered
		}
		if = {
			limit = {
				is_imperial_authority =no
				has_modifier = cc_ruler_cult
			}
			remove_modifier = cc_ruler_cult
		}
		if = {
			limit = {
				is_imperial_authority = yes
				has_modifier = cc_ruler_cult
				NOT = { has_country_flag = cc_permanent_ruler_cult }
			}
			from = { save_event_target_as = cc_ruler_culted_ruler }
			country_event = { id = cc_events_mod.6 days = 10 }
		}
	}
}

#keep ruler cult or not
country_event = {
	id = cc_events_mod.6
	title = cc_events_mod.6.name
	desc = cc_events_mod.6.desc
	
	picture = GFX_evt_cc_throne_room

	is_triggered_only = yes
	
	
	option = { #permanent ruler cult
		name = cc_events_mod.6.A
		custom_tooltip = cc_events_mod.6.A.desc
		
		hidden_effect = {
			set_country_flag = cc_permanent_ruler_cult
			

			random_pop_faction = {
				limit = { is_pop_faction_type = traditionalist }
				add_modifier = {
					modifier = cc_ruler_cult_offended
					years = 5
				}
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				is_spiritualist = no
			}
		}
	}
	
	option = { #the ruler cult must be earned
		name = cc_events_mod.6.B
		
		remove_modifier = cc_ruler_cult
		
		ai_chance = {
			factor = 2
			modifier = {
				factor = 0
				is_spiritualist = yes
				NOT = {
					any_owned_planet = {
						planet_stability < @dpe_somewhat_unrest_value
						count_owned_pop_amount = {
							limit = { has_ethic = ethic_spiritualist }
							count > 700
						}
					}
				}
			}
		}
	}
}




#Xeno Sex Scandal Gatekeeper
country_event = {
	id = cc_events_mod.17018
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		is_country_type = default
		
		NOR = {
			is_gestalt = yes
			has_country_flag = cc_recent_sex_scandal
		}

		OR = {
			has_policy_flag = bans_im_completely
			is_xenophobe = yes
		}

		any_owned_species = {
			NOR = {
				is_subspecies = prev
				is_same_species = prev
				is_robotic_species = no
			}
			species_has_happiness_with_owner = root
		}
	}
	
	# mean_time_to_happen = {
	# 	years = 30
	# }
	
	immediate = {
		random_list = {
			1 = {
				random_list = {
					3 = {
						country_event = { id = cc_events_mod.17 }
						modifier = {
							factor = 0
							NOT = { exists = ruler }
						}
						modifier = {
							factor = 0.75
							ruler? = { has_ethic = ethic_xenophobe }
						}
						modifier = {
							factor = 3
							ruler? = { has_ethic = ethic_xenophile }
						}
					}
					4 = {
						country_event = { id = cc_events_mod.18 }
						modifier = {
							factor = 1.5
							any_owned_leader = {
								NOT = { is_same_value = prev.ruler }
								has_ethic = ethic_xenophile
							}
						}
					}
				}
			}
			1 = {
				modifier = {
					factor = 0.8
					has_country_flag = cc_eventperf_has_minority
				}
				modifier = {
					factor = 0.9
					has_policy_flag = bans_im_completely
				}
				modifier = {
					factor = 1.5
					NOT = { has_faction = xenoist }
				}
				modifier = {
					factor = 0.75
					has_faction = xenoist
					any_owned_leader = {
						has_ethic = ethic_xenophile
					}
				}
				modifier = {
					factor = 0.5
					has_faction = xenoist
					ruler? = { has_ethic = ethic_xenophile }
				}
				modifier = {
					factor = 1.25
					has_ethic = ethic_fanatic_xenophobe
				}
			}
		}
	}
}

country_event = {
	id = cc_events_mod.17
	title = cc_events_mod.17.name
	desc = cc_events_mod.17.desc
	
	picture = GFX_evt_cc_alien_intimacy
	
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		
		exists = ruler
		
		NOT = { has_country_flag = cc_recent_sex_scandal }
		
		OR = {
			has_policy_flag = bans_im_completely
			is_xenophobe = yes
		}
		
		is_gestalt = no
		
		any_owned_species = {
			NOR = {
				is_same_species = root
				is_robotic_species = yes
			}
			species_has_happiness_with_owner = root
		}
	}
	
	immediate = {
		set_timed_country_flag = {
			flag = cc_recent_sex_scandal
			years = 50
		}
	
		random_owned_leader = {
			limit = { is_same_value = root.leader }
			save_event_target_as = cc_scandal_leader
		}
		
		random_owned_pop_group = {
			limit = {
				NOT = {
					is_same_species = root
				}
				is_robot_pop = no
				pop_group_has_happiness = yes
			}
			save_event_target_as = xeno
		}
		
	}
	option = {
		name = cc_events_mod.17.A
		
		allow = { has_faction = xenoist }
		
		shift_ethic = ethic_xenophile

		random_pop_faction = {
			limit = { is_pop_faction_type = xenoist }
			add_modifier = { modifier = embraced_faction years = 10 }
			add_modifier = { modifier = embraced_faction_timer years = 10 }
			owner = {
				every_pop_faction = {
					limit = {
						NOR = {
							is_pop_faction_type = xenoist
							is_pop_faction_type = supremacist
						}
					}
					add_modifier = { modifier = embraced_another_faction years = 10 }
				}
			}
		}
		random_pop_faction = {
			limit = { is_pop_faction_type = supremacist }
			add_modifier = {
				modifier = cc_recent_sex_scandal_hostile
				years = 10
			}
		}
		ai_chance = {
			factor = 1
			
			modifier = {
				factor = 0.5
				has_ethic = ethic_xenophobe
			}
			modifier = {
				factor = 0.33
				has_ethic = ethic_fanatic_xenophobe
			}
		}
	}
	option = {
		name = cc_events_mod.17.B

		custom_tooltip = cc_events_mod.17.B.tooltip
		
		hidden_effect = {
			kill_leader = { show_notification = no }
		}
		
		if = {
			limit = { is_imp_or_dict = yes }
			add_modifier = {
				modifier = cc_ruler_humiliated1
				years = 10
			}
		}
		
		random_pop_faction = {
			limit = { is_pop_faction_type = supremacist }
			add_modifier = {
				modifier = cc_recent_sex_scandal_friendly
				years = 10
			}
		}
		ai_chance = {
			factor = 1
			
			modifier = {
				factor = 2
				has_ethic = ethic_xenophobe
			}
			modifier = {
				factor = 3
				has_ethic = ethic_fanatic_xenophobe
			}
			modifier = {
				factor = 0.5
				is_imp_or_dict = yes
			}
			modifier = {
				factor = 0.65
				ruler = { has_base_skill > 4 }
			}
			modifier = {
				factor = 0.65
				ruler = { has_base_skill > 6 }
			}
		}
	}
	option = {
		name = cc_events_mod.17.C
						
		allow = { NOT = { has_ethic = ethic_fanatic_egalitarian } }
		
		add_modifier = {
			modifier = cc_defiance_of_law
			years = 10
		}
		random_pop_faction = {
			limit = { is_pop_faction_type = supremacist }
			add_modifier = {
				modifier = cc_recent_sex_scandal_unfriendly
				years = 10
			}
		}
		if = {
			limit = { has_faction = progressive }
			random_pop_faction = {
				limit = { is_pop_faction_type = progressive }
				add_modifier = {
					modifier = cc_defiance_of_law_egals
					years = 10
				}
			}
		}
		
		ai_chance = {
			factor = 1
			
			modifier = {
				factor = 2
				has_ethic = ethic_authoritarian
			}
			modifier = {
				factor = 3
				has_ethic = ethic_fanatic_authoritarian
			}
			modifier = {
				factor = 1.5
				is_imp_or_dict = yes
			}
			modifier = {
				factor = 2
				ruler = { has_base_skill > 4 }
			}
			modifier = {
				factor = 2
				ruler = { has_base_skill > 6 }
			}
		}
	}
	
	option = {
		name = cc_events_mod.17.D
		custom_tooltip = cc_events_mod.17.D.tooltip
		
		if = {
			limit = { has_ethic = ethic_authoritarian }
			shift_ethic = ethic_fanatic_authoritarian
			random_pop_faction = {
				limit = { is_pop_faction_type = totalitarian }
				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 = supremacist
									is_pop_faction_type = progressive
								}
							}
							add_modifier = { modifier = embraced_another_faction years = 10 }
						}
					}
				}
			}
		
		}

		add_modifier = {
			modifier = cc_defiance_of_law_mega
			years = 10
		}
		random_pop_faction = {
			limit = { is_pop_faction_type = supremacist }
			add_modifier = {
				modifier = cc_recent_sex_scandal_unfriendly1
				years = 10
			}
		}
		if = {
			limit = { has_faction = progressive }
			random_pop_faction = {
				limit = { is_pop_faction_type = progressive }
				add_modifier = {
					modifier = cc_defiance_of_law_egal_mega
					years = 10
				}
			}
		}
		
		allow = {
			is_authoritarian = yes
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				is_evil_empire = yes
			}
			modifier = {
				factor = 2
				has_ethic = ethic_fanatic_authoritarian
			}
			modifier = {
				factor = 0.5
				has_faction = progressive
			}
		}
	}
}

#triggered in perf
#Same, but for a random leader that isn't the ruler
country_event = {
	id = cc_events_mod.18
	title = cc_events_mod.18.name
	desc = cc_events_mod.18.desc
	
	picture = GFX_evt_news_room
	
	is_triggered_only = yes

	trigger = {
		is_country_type = default

		NOT = { has_country_flag = cc_recent_sex_scandal }
	
		OR = {
			has_policy_flag = bans_im_completely
			is_xenophobe = yes
		}
	
		is_gestalt = no
	
		any_owned_species = {
			NOR = {
				is_same_species = root
			}
			is_robotic_species = no
			species_has_happiness_with_owner = root
		}
	}
	
	immediate = {
		set_timed_country_flag = {
			flag = cc_recent_sex_scandal
			years = 50
		}
		
		random_owned_pop_group = {
			limit = {
				NOT = {
					is_same_species = root
				}
				is_robot_pop = no
				pop_group_has_happiness = yes
			}
			save_event_target_as = xeno
		}
		if = {
			limit = {
				has_faction = xenoist
				any_owned_leader = { has_ethic = ethic_xenophile }
			}
			random_list = {
				1 = {
					random_owned_leader = {
						limit = { has_ethic = ethic_xenophile }
						save_event_target_as = cc_scandal_leader
					}
				}
				1 = { random_owned_leader = { save_event_target_as = cc_scandal_leader } }
			}
		}
		else = { random_owned_leader = { save_event_target_as = cc_scandal_leader } }
	}
	option = {
		name = cc_events_mod.18.A
		
		allow = { has_faction = xenoist }
		
		shift_ethic = ethic_xenophile

		random_pop_faction = {
			limit = { is_pop_faction_type = xenoist }
			add_modifier = { modifier = embraced_faction years = 10 }
			add_modifier = { modifier = embraced_faction_timer years = 10 }
			owner = {
				every_pop_faction = {
					limit = {
						NOR = {
							is_pop_faction_type = xenoist
							is_pop_faction_type = supremacist
						}
					}
					add_modifier = { modifier = embraced_another_faction years = 10 }
				}
			}
		}
		random_pop_faction = {
			limit = { is_pop_faction_type = supremacist }
			add_modifier = {
				modifier = cc_recent_sex_scandal_hostile1
				years = 10
			}
		}

		ai_chance = {
			factor = 0.5
			
			modifier = {
				factor = 0.5
				has_ethic = ethic_xenophobe
			}
			modifier = {
				factor = 0.33
				has_ethic = ethic_fanatic_xenophobe
			}
		}
	}
	option = {
		name = cc_events_mod.18.B
					
		event_target:cc_scandal_leader = { 
			hidden_effect = { kill_leader = { show_notification = no } }
		}
		custom_tooltip = cc_events_mod.18.B.tooltip
		
		random_pop_faction = {
			limit = { is_pop_faction_type = supremacist }
			add_modifier = {
				modifier = cc_recent_sex_scandal_friendly1
				years = 10
			}
		}

		ai_chance = {
			factor = 2
			
			modifier = {
				factor = 2
				has_ethic = ethic_xenophobe
			}
			modifier = {
				factor = 3
				has_ethic = ethic_fanatic_xenophobe
			}
			modifier = {
				factor = 0.65
				event_target:cc_scandal_leader = { has_base_skill > 4 }
			}
			modifier = {
				factor = 0.65
				event_target:cc_scandal_leader = { has_base_skill > 6 }
			}
		}
	}
	option = {
		name = cc_events_mod.18.C
						
		allow = { NOT = { has_ethic = ethic_fanatic_egalitarian } }
		
			add_modifier = {
				modifier = cc_defiance_of_law1
				years = 10
			}
			random_pop_faction = {
				limit = { is_pop_faction_type = supremacist }
				add_modifier = {
					modifier = cc_recent_sex_scandal_unfriendly1
					years = 10
				}
			}
			if = {
				limit = { has_faction = progressive }
				random_pop_faction = {
					limit = { is_pop_faction_type = progressive }
					add_modifier = {
						modifier = cc_defiance_of_law_egals1
						years = 10
					}
				}
			}
		
		ai_chance = {
			factor = 1
			
			modifier = {
				factor = 1.5
				has_ethic = ethic_authoritarian
			}
			modifier = {
				factor = 2
				has_ethic = ethic_fanatic_authoritarian
			}
			modifier = {
				factor = 2
				event_target:cc_scandal_leader = { has_base_skill > 4 }
			}
			modifier = {
				factor = 2
				event_target:cc_scandal_leader = { has_base_skill > 6 }
			}
		}
	}
}


#Materialists Patent Event
country_event = {
	id = cc_events_mod.57
	title = cc_events_mod.57.name
	desc = cc_events_mod.57.desc
	
	picture = GFX_evt_metropolis
	location = event_target:dpe_merchant_planet

	is_triggered_only = yes

	trigger = {
		is_country_type = default
		years_passed > 25
		NOT = { has_country_flag = dpe_has_had_patents_event }
		num_owned_planets > 1
		OR = {
			is_materialist = yes
			any_pop_faction = {
				is_pop_faction_type = technologist
				support > 0.15
				faction_approval > @cc_faction_happy_number
			}
		}
		any_owned_planet = {
			is_capital = no
			colony_age > 25
			NOR = {
				has_modifier = dpe_innovative_CEO
				has_modifier = dpe_disgruntled_CEO
			}
		}
	}
	
	# mean_time_to_happen = { years = 40 }
	
	immediate = {
		set_country_flag = dpe_has_had_patents_event
		random_owned_planet = {
			limit = {
				is_capital = no
				colony_age > 25
			}
			save_event_target_as = dpe_merchant_planet
		}
		
		create_leader = {
			class = commander 
			species = this
			name = random
			skill = 1
		}
		
		last_created_leader = {
			save_event_target_as = dpe_CEO
			exile_leader_as = dpe_CEO
		}
	}

	option = {
		name = cc_events_mod.57.A
		
		event_target:dpe_merchant_planet = {
			add_modifier = {
				modifier = dpe_innovative_CEO
				years = 20
			}
		}
		
		random_pop_faction = {
			limit = { is_pop_faction_type = technologist }
			add_modifier = {
				modifier = dpe_innovative_CEO_faction
				years = 10
			}
		}
		
		ai_chance = {
			factor = 2
			modifier = {
				factor = 1.5
				is_materialist = yes
			}
		}
	}

	option = {
		name = cc_events_mod.57.B
		
		allow = { has_faction = totalitarian }
		
		add_monthly_resource_mult = {
			resource = physics_research
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}

		add_monthly_resource_mult = {
			resource = consumer_goods
			value = @tier2researchreward
			min = @tier2researchmin
			max = @tier2researchmax
		}

		random_pop_faction = {
			limit = { is_pop_faction_type = totalitarian }
			add_modifier = {
				modifier = dpe_patents_national_interest
				years = 10
			}
		}

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

		event_target:dpe_merchant_planet = {
			add_modifier = {
				modifier = dpe_disgruntled_CEO
				years = 15
			}
		}

		ai_chance = {
			factor = 2
			modifier = {
				factor = 2
				is_authoritarian = yes
			}
		}
	}

	option = {
		name = cc_events_mod.57.C
		
		add_modifier = {
			modifier = dpe_encouraged_competition
			years = 10
		}

		event_target:dpe_merchant_planet = {
			add_modifier = {
				modifier = dpe_disgruntled_CEO
				years = 15
			}
		}
		
		ai_chance = {
			factor = 2
			modifier = {
				factor = 0
				event_target:dpe_merchant_planet = {
					planet_stability < @dpe_normal_unrest_value
				}
			}
		}
	}
}
