namespace = cc_xeno_clashes

carrier_event = {
	id = cc_xeno_clashes.1
	hide_window = yes
	is_triggered_only = yes
	
	pre_triggers = {
		has_owner = yes
	}
	
	trigger = {
		owner = {
			is_country_type = default
			is_gestalt = no
		}
		pop_amount > 1000
		
		any_owned_pop_group = { has_ethic = ethic_xenophobe }
		pop_amount_percentage = {
			percentage > 0.2
			limit = { has_ethic = ethic_xenophobe }
		}

		NOR = {
			has_carrier_flag = cc_xeno_clashes
			# has_carrier_flag = pop_modification
			owner = {
				OR = {
					has_country_flag = cc_recent_xeno_empire_clashes
					has_country_flag = cc_recent_first_xeno_clashes
					is_gestalt = yes
				}
			}
		}

		num_species > 1

		any_owned_species = {
			species_has_happiness_with_owner = root.owner
			is_robotic_species = no
			OR = {
				has_citizenship_type = { country = root.owner type = citizenship_full }
				has_citizenship_type = { country = root.owner type = citizenship_limited }
			}
			root = {
				count_owned_pop_amount = {
					limit = { is_same_species = prev }
					count > 400
				}
				any_owned_species = {
					NOT = { is_same_species = prevprev }
					species_has_happiness_with_owner = root.owner
					is_robotic_species = no
					OR = {
						has_citizenship_type = { country = root.owner type = citizenship_full }
						has_citizenship_type = { country = root.owner type = citizenship_limited }
					}
					root = {
						count_owned_pop_amount = {
							limit = { is_same_species = prev }
							count > 400
						}
					}
				}
			}
		}
	}
	
	# mean_time_to_happen = {
	# 	years = 30
	# }
	
	immediate = {
		random_list = {
			1 = {
				modifier = {
					factor = 0.5
					planet_stability < @dpe_bit_unrest_value
				}
				modifier = {
					factor = 2
					owner = { NOT = { has_faction = supremacist } }
				}
				modifier = {
					factor = 0.75
					
					any_owned_species = {
						species_has_happiness_with_owner = root.owner
						is_robotic_species = no
						OR = {
							has_citizenship_type = { country = root.owner type = citizenship_full }
							has_citizenship_type = { country = root.owner type = citizenship_limited }
						}
						root = {
							count_owned_pop_amount = {
								limit = { is_same_species = prev }
								count > 1000
							}
							any_owned_species = {
								NOT = { is_same_species = prevprev }
								species_has_happiness_with_owner = root.owner
								is_robotic_species = no
								OR = {
									has_citizenship_type = { country = root.owner type = citizenship_full }
									has_citizenship_type = { country = root.owner type = citizenship_limited }
								}
								root = {
									count_owned_pop_amount = {
										limit = { is_same_species = prev }
										count > 1000
									}
								}
							}
						}
					}
				}
			}

			1 = {
				modifier = {
					factor = 0.5
					planet_stability > @dpe_normal_unrest_value
				}
				modifier = {
					factor = 0.75
					has_carrier_flag = ccrebel_perf_xenophiles_1
					NOR = {
						has_carrier_flag = ccrebel_perf_xenophiles_2
						has_carrier_flag = ccrebel_perf_xenophiles_3
					}
				}
				modifier = {
					factor = 0.5
					OR = {
						has_carrier_flag = ccrebel_perf_xenophiles_2
						has_carrier_flag = ccrebel_perf_xenophiles_3
					}
				}
				modifier = {
					factor = 1.25
					has_carrier_flag = ccrebel_perf_xenophobes_1
				}
				modifier = {
					factor = 1.25
					has_carrier_flag = ccrebel_perf_xenophobes_2
				}
				modifier = {
					factor = 1.25
					has_carrier_flag = ccrebel_perf_xenophobes_3
				}

				owner = {
					save_event_target_as = cc_owner
					set_timed_country_flag = {
						flag = cc_recent_first_xeno_clashes
						years = 5
					}
				}
				if = {
					limit = {
						any_owned_species = {
							species_has_happiness_with_owner = root.owner
							is_robotic_species = no
							OR = {
								has_citizenship_type = { country = root.owner type = citizenship_full }
								has_citizenship_type = { country = root.owner type = citizenship_limited }
							}
							root = {
								count_owned_pop_amount = {
									limit = { is_same_species = prev }
									count > 400
								}
								any_owned_species = {
									NOT = { is_same_species = prevprev }
									species_has_happiness_with_owner = root.owner
									is_robotic_species = no
									is_same_species = root.owner_species
									OR = {
										has_citizenship_type = { country = root.owner type = citizenship_full }
										has_citizenship_type = { country = root.owner type = citizenship_limited }
									}
									root = {
										count_owned_pop_amount = {
											limit = { is_same_species = prev }
											count > 400
										}
									}
								}
							}
						}
					}
					set_timed_carrier_flag = {
						flag = cc_eventperf_xeno_clashes_own_species_planet
						years = 1
					}
					owner_species = { save_event_target_as = species1 }
				}
				else = {
					random_owned_species = {
						limit = {
							species_has_happiness_with_owner = root.owner
							is_robotic_species = no
							OR = {
								has_citizenship_type = { country = root.owner type = citizenship_full }
								has_citizenship_type = { country = root.owner type = citizenship_limited }
							}
							root = {
								count_owned_pop_amount = {
									limit = { is_same_species = prev }
									count > 400
								}
							}
						}
						save_event_target_as = species1
					}
				}
				random_owned_species = {
					limit = {
						NOT = { is_same_value = event_target:species1 }
						species_has_happiness_with_owner = root.owner
						is_robotic_species = no
						OR = {
							has_citizenship_type = { country = root.owner type = citizenship_full }
							has_citizenship_type = { country = root.owner type = citizenship_limited }
						}
						root = {
							count_owned_pop_amount = {
								limit = { is_same_species = prev }
								count > 400
							}
						}
					}
					save_event_target_as = species2
				}
					
					
				if = {
					limit = {
						has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet
						planet_stability > @dpe_bit_unrest_value
					}
					carrier_event = { id = cc_xeno_clashes.2 }
				}
				if = {
					limit = {
						has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet
						NOT = { planet_stability > @dpe_bit_unrest_value }
					}
					carrier_event = { id = cc_xeno_clashes.3 }
				}
				if = {
					limit = {
						NOT = { has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet }
					}
					carrier_event = { id = cc_xeno_clashes.2 }
				}
			}
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.2
	title = cc_xeno_clashes.2.name
	desc = {
		trigger = {
			OR = {
				has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet
				owner = {
					is_xenophile = no
				}
			}
		}
		text = cc_xeno_clashes.2.desc
	}
	desc = {
		trigger = {
			NOT = { has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet }
			owner = {
				is_xenophile = yes
			}
		}
		text = cc_xeno_clashes.2.desc.phile
	}
	picture = GFX_evt_alien_segregation
	location = root
	
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = { has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet }
			carrier_event = { id = cc_xeno_clashes.3 days = 480 }
		}	
		else = { carrier_event = { id = cc_xeno_clashes.4 days = 480 } }
		set_timed_carrier_flag = {
			flag = cc_xeno_clashes
			years = 30
		}
	}
	
	option = {
		name = cc_xeno_clashes.2.phile.own
		
		add_modifier = {
			modifier = cc_planet_hate_speech
			years = 5
		}
		
		trigger = {
			has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet
		}
		allow = {
			owner = {
				is_xenophile = yes
			}
		}
	}
	
	option = {
		name = cc_xeno_clashes.2.phobe.own
		
		add_modifier = {
			modifier = cc_planet_hate_speech
			years = 5
		}
		
		trigger = {
			has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet
		}
		allow = {
			owner = {
				is_xenophobe = yes
			}
		}
	}
	
	option = {
		name = cc_xeno_clashes.2.own
		
		add_modifier = {
			modifier = cc_planet_hate_speech
			years = 5
		}
		
		trigger = {
			has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet
		}
		allow = {
			owner = {
				NOR = {
					is_xenophobe = yes
					is_xenophile = yes
				}
			}
		}
	}
	
	option = {
		name = cc_xeno_clashes.2.no_own
		
		add_modifier = {
			modifier = cc_planet_hate_speech
			years = 5
		}
		
		trigger = {
			NOT = { has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet }
		}
		allow = {
			owner = {
				is_xenophobe = no
			}
		}
	}
	
	option = {
		name = cc_xeno_clashes.2.phobe.no_own
		
		add_modifier = {
			modifier = cc_planet_hate_speech
			years = 5
		}
		
		trigger = {
			NOT = { has_carrier_flag = cc_eventperf_xeno_clashes_own_species_planet }
		}
		allow = {
			owner = {
				is_xenophobe = yes
			}
		}
	}
}


carrier_event = {
	id = cc_xeno_clashes.3
	
	title = cc_xeno_clashes.3.name
	desc = {
		trigger = { NOT = { has_modifier = cc_planet_hate_speech } }
		text = cc_xeno_clashes.3.desc.A
	}
	desc = {
		trigger = { has_modifier = cc_planet_hate_speech }
		text = cc_xeno_clashes.3.desc.B
	}
	picture = GFX_evt_alien_segregation
	location = root
	
	is_triggered_only = yes

	trigger = {
		planet_stability < @dpe_normal_unrest_value
		is_owned_by = event_target:cc_owner
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species1 } }
		}
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species2 } }
		}
	}
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_xeno_clashes
			years = 30
		}
	}
	
	option = {
		name = cc_xeno_clashes.3.A
		custom_tooltip = cc_xeno_clashes.3.A.tooltip
		
		allow = {
			owner = {
				is_xenophile = no
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				owner = { has_ethic = ethic_xenophobe }
			}
			modifier = {
				factor = 5
				owner = { has_ethic = ethic_xenophobe }
			}
			modifier = {
				factor = 0
				owner = { 
					OR = {
						is_xenophile = yes
						
						any_owned_pop_group = {
							NOT = { is_same_species = prev }
							has_citizenship_rights = no
						}
					}
				}
			}
		}
		
		hidden_effect = {
			if = {
				limit = { has_modifier = cc_planet_hate_speech }
				remove_modifier = cc_planet_hate_speech
			}
		}
		
		owner = {
			if = {
				limit = {
					is_xenophobe = no
				}
				shift_ethic = ethic_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 = isolationist
											is_pop_faction_type = xenoist
										}
									}
									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 }
								}
							}
						}
					}
				}
			}
		}
	
		add_modifier = {
			modifier = cc_planet_interspecies_tensions
			years = 10
		}
		
		owner = {
			if = {
				limit = { has_faction = xenoist }
				random_pop_faction = {
					limit = { is_pop_faction_type = xenoist }
					add_modifier = {
						modifier = cc_xenos_disparaged
						years = 10
					}
				}
			}
		}
		
		hidden_effect = {
			if = {
				limit = {
					owner = {
						any_owned_planet = {
							NOT = { is_same_value = root }
							count_owned_pop_amount = {
								count > 400
								limit = { species = { is_same_value = event_target:species2 } }
							}
						}
					}
				}
				owner = { country_event = { id = cc_xeno_clashes.31 days = 10 random = 10 } }
			}
			else = {
				every_owned_pop_group = {
					limit = { species = { is_same_value = event_target:species2 } }
					add_modifier = {
						modifier = cc_feels_unwelcome
						years = 10
					}
				}
			}
			carrier_event = { id = cc_xeno_clashes.37 days = 180 }
		}
	}
	option = {
		name = cc_xeno_clashes.3.B
		custom_tooltip = cc_xeno_clashes.3.B.tooltip
		
		allow = {
			owner = { NOT = { has_ethic = ethic_fanatic_xenophobe } }
		}
		
		ai_chance = {
			factor = 1
		}
		
		hidden_effect = {
			if = {
				limit = { has_modifier = cc_planet_hate_speech }
				remove_modifier = cc_planet_hate_speech
			}
		}
	
		add_modifier = {
			modifier = cc_planet_interspecies_tensions
			years = 10
		}
		
		hidden_effect = {
			random_list = {
				1 = {
					carrier_event = { id = cc_xeno_clashes.37 days = 180 }
					modifier = {
						factor = 1.5
						planet_stability < @dpe_normal_unrest_value
					}
					modifier = {
						factor = 2
						planet_stability < @dpe_bit_unrest_value
					}
					modifier = {
						factor = 4
						planet_stability < @dpe_somewhat_unrest_value
					}
					modifier = {
						factor = 10
						planet_stability < @dpe_risk_unrest_value
					}
				}
				4 = { }
			}
			owner = {
				every_owned_planet = {
					limit = {
						NOT = { is_same_value = root }
						count_owned_pop_amount = {
							count > 400
							limit = { species = { is_same_value = event_target:species1 } }
						}
						count_owned_pop_amount = {
							count > 400
							limit = { species = { is_same_value = event_target:species2 } }
						}
					}
					carrier_event = { id = cc_xeno_clashes.38 days = 15 }
				}
			}
		}
	}
	option = {
		name = cc_xeno_clashes.3.C
		custom_tooltip = cc_xeno_clashes.3.C.tooltip
		
		allow = {
			owner = {
				is_xenophobe = no
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				owner = { has_ethic = ethic_xenophile }
			}
			modifier = {
				factor = 10
				owner = { has_ethic = ethic_fanatic_xenophile }
			}
		}
		
		owner = {
			add_modifier = {
				modifier = cc_xeno_reconciliation
				years = 10
			}
		}
		hidden_effect = {
			if = {
				limit = { has_modifier = cc_planet_hate_speech }
				remove_modifier = cc_planet_hate_speech
			}
		}
#		add_modifier = {
#			modifier = cc_planet_interspecies_tensions
#			days = 3600
#		}
		add_modifier = {
			modifier = cc_investment_package
			years = 10
		}
		
		owner = {
			if = {
				limit = { has_faction = supremacist }
				random_pop_faction = {
					limit = { is_pop_faction_type = supremacist }
					add_modifier = {
						modifier = cc_xenos_encouraged
						years = 10
					}
				}
			}
		}
	}
}


country_event = {
	id = cc_xeno_clashes.31
	title = cc_xeno_clashes.31.name
	desc = cc_xeno_clashes.31.desc
	picture = GFX_evt_alien_segregation
	
	location = from	
	is_triggered_only = yes

	immediate = {
		create_leader = {
			class = commander 
			species = event_target:species2
			name = random
			skill = 1
		}
		last_created_leader = {
			save_event_target_as = annoyed_xeno
			exile_leader_as = cc_annoyed_xeno
		}
		set_timed_country_flag = {
			flag = cc_xeno_clashes_militia_formed
			years = 5
		}
	}
	
	option = {
		name = UNFORTUNATE
		
		if = {
			limit = {
				any_owned_planet = {
					count_owned_pop_amount = {
						count > 400
						limit = { species = { is_same_value = event_target:species1 } }
					}
					count_owned_pop_amount = {
						count > 400
						limit = { species = { is_same_value = event_target:species2 } }
					}
					owner = {
						any_owned_planet = {
							NOT = { is_same_value = prevprev }
							count_owned_pop_amount = {
								count > 400
								limit = { species = { is_same_value = event_target:species1 } }
							}
							count_owned_pop_amount = {
								count > 400
								limit = { species = { is_same_value = event_target:species2 } }
							}
							owner = {
								any_owned_planet = {
									NOR = {
										is_same_value = prevprev
										is_same_value = prevprevprevprev
									}
									count_owned_pop_amount = {
										count > 400
										limit = { species = { is_same_value = event_target:species1 } }
									}
									count_owned_pop_amount = {
										count > 400
										limit = { species = { is_same_value = event_target:species2 } }
									}
								}
							}
						}
					}
				}
			}					
			add_modifier = {
				modifier = cc_empire_interspecies_tensions
				years = 10
			}
			hidden_effect = {
				set_timed_country_flag = {
					flag = cc_recent_xeno_empire_clashes
					years = 50
				}
			}
		}

		every_owned_planet = {
			limit = {
				NOT = { has_modifier = cc_planet_interspecies_tensions }
				count_owned_pop_amount = {
					count > 400
					limit = { species = { is_same_value = event_target:species1 } }
				}
				count_owned_pop_amount = {
					count > 400
					limit = { species = { is_same_value = event_target:species2 } }
				}
			}
			add_modifier = {
				modifier = cc_planet_interspecies_tensions
				years = 10
			}
		}
		
		custom_tooltip = cc_xeno_clashes.31.tooltip
		hidden_effect = {
			every_owned_pop_group = {
				limit = { species = { is_same_value = event_target:species2 } }
				add_modifier = {
					modifier = cc_feels_unwelcome
					years = 10
				}
			}
			every_owned_planet = {
				limit = {
					count_owned_pop_amount = {
						count > 400
						limit = { species = { is_same_value = event_target:species1 } }
					}
					count_owned_pop_amount = {
						count > 400
						limit = { species = { is_same_value = event_target:species2 } }
					}
				}
				carrier_event = { id = cc_xeno_clashes.315 days = 30 }
			}
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.315
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_modifier = cc_planet_interspecies_tensions
#		any_owned_pop_group = { species = { is_same_value = event_target:species1 } }
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species2 } }
		}
		NOT = { has_carrier_flag = cc_interspecies_incident }
		is_owned_by = event_target:cc_owner
	}
	
	immediate = {
		if = {
			limit = {
				any_owned_pop_group = { species = { is_same_value = event_target:species1 } }
			}
			if = {
				limit = {
					pop_amount < 2000
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.32 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					149 = { }
				}
			}
			if = {
				limit = {
					NOT = {
						pop_amount < 2000
					}
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.33 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					1 = {
						carrier_event = { id = cc_xeno_clashes.34 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					297 = { }
				}
			}
		}
		else = {
			random_list = {
				1 = {
					carrier_event = { id = cc_xeno_clashes.35 }
					modifier = {
						factor = 1.5
						planet_stability < @dpe_normal_unrest_value
					}
					modifier = {
						factor = 1.5
						planet_stability < @dpe_bit_unrest_value
					}
					modifier = {
						factor = 1.5
						planet_stability < @dpe_somewhat_unrest_value
					}
					modifier = {
						factor = 1.5
						planet_stability < @dpe_risk_unrest_value
					}
				}
				149 = { }
			}
			if = {
				limit = {
					NOT = {
						pop_amount < 2000
					}
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.36 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
						modifier = {
							factor = 0
							NOR = {
								has_building = building_colony_shelter
								has_building = building_capital
								has_building = building_major_capital
								has_building = building_system_capital
								has_building = building_hab_capital
								has_building = building_hab_major_capital
							}
						}
					}
					1 = {
						carrier_event = { id = cc_xeno_clashes.34 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					297 = { }
				}
			}
		}
		carrier_event = { id = cc_xeno_clashes.315 days = 30 }
	}
}


carrier_event = {
	id = cc_xeno_clashes.32
	title = cc_xeno_clashes.32.name
	desc = cc_xeno_clashes.32.desc
	picture = GFX_evt_burning_settlement
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.32.option
		random_owned_pop_group = {
			limit = { species = { is_same_value = event_target:species1 } }
			kill_pop_group = { pop_group = this amount = 25% }
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.33
	title = cc_xeno_clashes.33.name
	desc = cc_xeno_clashes.33.desc
	picture = GFX_evt_mem_ost_terror_attack
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.33.option
		if = {
			limit = {
				has_district = district_city
			}
			remove_district = district_city
		}
		else_if = {
			limit = {
				has_district = district_arcology_housing
			}
			remove_district = district_arcology_housing
		}
		while = {
			limit = {
				count_owned_pop_amount = {
					limit = { species = { is_same_value = event_target:species1 } }
					count > 10000
				}
			}
			count = 600
			
			random_owned_pop_group = {
				limit = { species = { is_same_value = event_target:species1 } }
				kill_pop_group = { pop_group = this amount = 100% }
			}
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.34
	title = cc_xeno_clashes.34.name
	desc = cc_xeno_clashes.34.desc
	picture = GFX_evt_glitchy_matrix
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.34.option
		
		add_modifier = {
			modifier = cc_disrupted_government
			years = 5
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.35
	title = cc_xeno_clashes.35.name
	desc = cc_xeno_clashes.35.desc
	picture = GFX_evt_burning_settlement
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.35.option
		
		add_modifier = {
			modifier = cc_disrupted_government
			years = 5
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.36
	title = cc_xeno_clashes.36.name
	desc = cc_xeno_clashes.36.desc
	picture = GFX_evt_mem_ost_terror_attack
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.36.option
		
		switch = {
			trigger = has_building
			building_colony_shelter = { remove_building = building_colony_shelter }
			building_capital = { remove_building = building_capital }
			building_major_capital = { remove_building = building_major_capital }
			building_system_capital = { remove_building = building_system_capital }
			building_hab_capital = { remove_building = building_hab_capital }
			building_hab_major_capital = { remove_building = building_hab_major_capital }
		}
		
		add_modifier = {
			modifier = cc_disrupted_government
			years = 5
		}
	}
}


carrier_event = {
	id = cc_xeno_clashes.37
	title = cc_xeno_clashes.37.name
	desc = cc_xeno_clashes.37.desc
	picture = GFX_evt_city_ruins
	
	location = root
	is_triggered_only = yes
	
	trigger = {
		owner = { species = { is_same_value = event_target:species1 } }
		NOT = { owner = { has_country_flag = cc_interspecies_genocide } }
		NOT = { has_carrier_flag = cc_interspecies_incident }
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species1 } }
		}
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species2 } }
		}
	}
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
		owner = {
			set_timed_country_flag = {
				flag = cc_interspecies_genocide
				years = 10
			}
		}
	}
	
	option = {
		name = UNFORTUNATE
		
		random_owned_pop_group = {
			limit = { species = { is_same_value = event_target:species1 } }
			kill_pop_group = { pop_group = this amount = 100% }
		}
		hidden_effect = { carrier_event = { id = cc_xeno_clashes.371 days = 15 } }
	}
}

carrier_event = {
	id = cc_xeno_clashes.371
	title = cc_xeno_clashes.371.name
	desc = cc_xeno_clashes.371.desc
	picture = GFX_evt_city_ruins
	
	location = root
	is_triggered_only = yes
	
	option = {
		name = cc_xeno_clashes.371.A
		
		every_owned_pop_group = {
			limit = { species = { is_same_value = event_target:species2 } }
			kill_pop_group = { pop_group = this amount = 100% }
			
			hidden_effect = {
				every_country = {
					limit = {
						NOT = { species = { is_same_value = event_target:species2 } }
						has_communications = root.owner
						NOT = { is_same_empire = root.owner }
						NOT = { has_ai_personality_behaviour = purger }
						NOT = {
							OR = {
								has_ethic = ethic_fanatic_authoritarian
								AND = {
									has_ethic = ethic_authoritarian
									OR = {
										has_ethic = ethic_fanatic_xenophobe
										has_ethic = ethic_fanatic_militarist
										AND = {
											has_ethic = ethic_xenophobe
											has_ethic = ethic_militarist
										}
									}
								}
							}
						}
						OR = {
							is_country_type = default
							has_ai_personality = awakened_fallen_empire_xenophile				
						}	
					}
					add_opinion_modifier = { who = root.owner modifier = opinion_genocidal }
				}
			}
		}
		
		owner = {
			if = {
				limit = { has_faction = xenoist }
				random_pop_faction = {
					limit = { is_pop_faction_type = xenoist }
					add_modifier = {
						modifier = cc_xenos_massacred
						years = 10
					}
				}
			}
		}
		
		if = {
			limit = {
				any_country = { species = { is_same_value = event_target:species2 } }
			}
			every_country = {
				limit = {
					NOT = { is_same_empire = root.owner } #should be impossible, but just making sure
					species = { is_same_value = event_target:species2 }
				}
				add_opinion_modifier = {
					modifier = cc_allowed_genocide_of_us
					who = root.owner
				}
			}
		}
		custom_tooltip = CCKILLALL.tooltip
		
		hidden_effect = {
			owner = {
				if = {
					limit = {
						NOT = { has_country_flag = cc_xeno_clashes_militia_formed }
						any_owned_planet = {
							NOT = { is_same_value = root }
							count_owned_pop_amount = {
								count > 400
								limit = { species = { is_same_value = event_target:species2 } }
							}
						}
					}
					country_event = { id = cc_xeno_clashes.372 days = 10 random = 10 }
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				owner = { has_ethic = ethic_xenophobe }
			}
			modifier = {
				factor = 10
				owner = { has_ethic = ethic_fanatic_xenophobe }
			}
			modifier = {
				factor = 0
				NOT = { owner = { has_faction = supremacist } }
			}
			modifier = {
				factor = 0
				owner = {
					is_xenophile = no
				}
			}
		}
	}
	option = {
		name = cc_xeno_clashes.371.B
		
		add_modifier = {
			modifier = cc_martial_law
			years = 10
		}
		
		owner = {
			if = {
				limit = { has_faction = supremacist }
				random_pop_faction = {
					limit = { is_pop_faction_type = supremacist }
					add_modifier = {
						modifier = cc_xenos_spared_from_massacre
						years = 10
					}
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				owner = {
					is_xenophobe = no
				}
			}
			modifier = {
				factor = 0.5
				NOT = { owner = { has_faction = xenoist } }
			}
			modifier = {
				factor = 2
				owner = {
					any_pop_faction = {
						is_pop_faction_type = supremacist
						support > 0.2
					}
				}
			}
		}
	}
}


country_event = {
	id = cc_xeno_clashes.372
	title = cc_xeno_clashes.372.name
	desc = cc_xeno_clashes.372.desc
	picture = GFX_evt_alien_segregation
	
	location = from	
	is_triggered_only = yes

	immediate = {
		create_leader = {
			class = commander 
			species = event_target:species2
			name = random
			skill = 1
		}
		last_created_leader = {
			save_event_target_as = annoyed_xeno
			exile_leader_as = cc_annoyed_xeno
		}
		set_timed_country_flag = {
			flag = cc_xeno_clashes_militia_formed
			years = 5
		}
	}
	
	option = {
		name = UNFORTUNATE
		
		if = {
			limit = {
				NOT = { has_modifier = cc_empire_interspecies_tensions }
				
				any_owned_planet = {
					count_owned_pop_amount = {
						count > 400
						limit = { species = { is_same_value = event_target:species1 } }
					}
					count_owned_pop_amount = {
						count > 400
						limit = { species = { is_same_value = event_target:species2 } }
					}
					owner = {
						any_owned_planet = {
							NOT = { is_same_value = prevprev }
							count_owned_pop_amount = {
								count > 400
								limit = { species = { is_same_value = event_target:species1 } }
							}
							count_owned_pop_amount = {
								count > 400
								limit = { species = { is_same_value = event_target:species2 } }
							}
							owner = {
								any_owned_planet = {
									NOR = {
										is_same_value = prevprev
										is_same_value = prevprevprevprev
									}
									count_owned_pop_amount = {
										count > 400
										limit = { species = { is_same_value = event_target:species1 } }
									}
									count_owned_pop_amount = {
										count > 400
										limit = { species = { is_same_value = event_target:species2 } }
									}
								}
							}
						}
					}
				}
			}					
			add_modifier = {
				modifier = cc_empire_interspecies_tensions
				years = 10
			}
			hidden_effect = {
				set_timed_country_flag = {
					flag = cc_recent_xeno_empire_clashes
					years = 50
				}
			}
		}

		every_owned_planet = {
			limit = {
				NOT = { has_modifier = cc_planet_interspecies_tensions }
				count_owned_pop_amount = {
					count > 400
					limit = { species = { is_same_value = event_target:species1 } }
				}
				count_owned_pop_amount = {
					count > 400
					limit = { species = { is_same_value = event_target:species2 } }
				}
			}
			add_modifier = {
				modifier = cc_planet_interspecies_tensions
				years = 10
			}
		}
		
		custom_tooltip = cc_xeno_clashes.372.tooltip
		hidden_effect = {
			every_owned_pop_group = {
				limit = { species = { is_same_value = event_target:species2 } }
				add_modifier = {
					modifier = cc_pop_fears_genocide
					years = 10
				}
			}
			every_owned_planet = {
				limit = {
					count_owned_pop_amount = {
						count > 400
						limit = { species = { is_same_value = event_target:species2 } }
					}
				}
				carrier_event = { id = cc_xeno_clashes.373 days = 30 }
			}
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.373
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_modifier = cc_planet_interspecies_tensions
#		any_owned_pop_group = { species = { is_same_value = event_target:species1 } }
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species2 } }
		}
		NOT = { has_carrier_flag = cc_interspecies_incident }
		is_owned_by = event_target:cc_owner
	}
	
	immediate = {
		if = {
			limit = {
				any_owned_pop_group = { species = { is_same_value = event_target:species1 } }
			}
			if = {
				limit = {
					pop_amount < 2000
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.32 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					99 = { }
				}
			}
			if = {
				limit = {
					NOT = {
						pop_amount < 2000
					}
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.33 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					1 = {
						carrier_event = { id = cc_xeno_clashes.34 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					198 = { }
				}
			}
		}
		else = {
			if = {
				limit = {
					pop_amount < 2000
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.35 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					99 = { }
				}
			}
			if = {
				limit = {
					NOT = {
						pop_amount < 2000
					}
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.36 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
						modifier = {
							factor = 0
							NOR = {
								has_building = building_colony_shelter
								has_building = building_capital
								has_building = building_major_capital
								has_building = building_system_capital
								has_building = building_hab_capital
								has_building = building_hab_major_capital
							}
						}
					}
					1 = {
						carrier_event = { id = cc_xeno_clashes.34 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					198 = { }
				}
			}
		}
		carrier_event = { id = cc_xeno_clashes.373 days = 30 }
	}
}


carrier_event = {
	id = cc_xeno_clashes.38
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species1 } }
		}
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species2 } }
		}
		is_owned_by = event_target:cc_owner
		
		NOR = {
			has_modifier = cc_planet_interspecies_tensions
			owner = { has_modifier = cc_empire_interspecies_tensions }
		}
	}
	
	immediate = {
	
		random = {
			chance = 6
			carrier_event = { id = cc_xeno_clashes.381 days = 15 random = 10 }
		}
	
		if = {
			limit = { owner = { NOT = { has_country_flag = cc_enough_xenohostile_12 } } }
			carrier_event = { id = cc_xeno_clashes.38 days = 30 }
		}
		
		owner = {
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_11
					NOT = { has_country_flag = cc_enough_xenohostile_12 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_12
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_10
					NOT = { has_country_flag = cc_enough_xenohostile_11 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_11
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_9
					NOT = { has_country_flag = cc_enough_xenohostile_10 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_10
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_8
					NOT = { has_country_flag = cc_enough_xenohostile_9 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_9
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_7
					NOT = { has_country_flag = cc_enough_xenohostile_8 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_8
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_6
					NOT = { has_country_flag = cc_enough_xenohostile_7 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_7
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_5
					NOT = { has_country_flag = cc_enough_xenohostile_6 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_6
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_4
					NOT = { has_country_flag = cc_enough_xenohostile_5 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_5
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_3
					NOT = { has_country_flag = cc_enough_xenohostile_4 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_4
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_2
					NOT = { has_country_flag = cc_enough_xenohostile_3 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_3
					years = 3
				}
			}
			if = {
				limit = { 
					has_country_flag = cc_enough_xenohostile_1
					NOT = { has_country_flag = cc_enough_xenohostile_2 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_2
					years = 3
				}
			}
			if = {
				limit = { 
					NOT = { has_country_flag = cc_enough_xenohostile_1 }
				}
				set_timed_country_flag = {
					flag = cc_enough_xenohostile_1
					years = 3
				}
			}
		}
	}
}

#gatekeeper for second or third planet
carrier_event = {
	id = cc_xeno_clashes.381
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species1 } }
		}
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species2 } }
		}
		is_owned_by = event_target:cc_owner
		
		NOR = {
			has_modifier = cc_planet_interspecies_tensions
			owner = { has_modifier = cc_empire_interspecies_tensions }
		}
	}
	
	immediate = {
		if = {
			limit = {
				owner = { NOT = { any_owned_planet = { has_carrier_flag = cc_second_xenoclash_planet } } }
			}
			carrier_event = { id = cc_xeno_clashes.382 }
		}
		else = {
			owner = {
				if = {
					limit = { NOT = { has_modifier = cc_empire_interspecies_tensions } }
					country_event = { id = cc_xeno_clashes.383 }
				}
			}
		}
	}
}
	
carrier_event = {
	id = cc_xeno_clashes.382
	title = cc_xeno_clashes.382.name
	desc = cc_xeno_clashes.382.desc
	picture = GFX_evt_alien_segregation
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_second_xenoclash_planet
			years = 10
		}
	}
	
	option = {
		name = UNFORTUNATE
		add_modifier = {
			modifier = cc_planet_interspecies_tensions
			years = 10
		}
	}
}

country_event = {
	id = cc_xeno_clashes.383
	title = cc_xeno_clashes.383.name
	desc = cc_xeno_clashes.383.desc
	picture = GFX_evt_burning_settlement
	
	is_triggered_only = yes
	
	option = {
		name = cc_xeno_clashes.383.A
		add_modifier = {
			modifier = cc_empire_interspecies_tensions
			years = 10
		}
		hidden_effect = {
			set_timed_country_flag = {
				flag = cc_recent_xeno_empire_clashes
				years = 50
			}
		}
		every_owned_planet = {
			limit = {
				NOT = { has_modifier = cc_planet_interspecies_tensions }
				count_owned_pop_amount = {
					count > 400
					limit = { species = { is_same_value = event_target:species1 } }
				}
				count_owned_pop_amount = {
					count > 400
					limit = { species = { is_same_value = event_target:species2 } }
				}
			}
			add_modifier = {
				modifier = cc_planet_interspecies_tensions
				years = 10
			}
			add_modifier = {
				modifier = cc_martial_law
				years = 10
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				owner = {
					is_xenophobe = no
				}
			}
			modifier = {
				factor = 0.5
				NOT = { has_faction = xenoist }
			}
			modifier = {
				factor = 2
				any_pop_faction = {
					is_pop_faction_type = supremacist
					support > 0.2
				}
			}
		}
	}
	option = {
		name = cc_xeno_clashes.383.B
		add_modifier = {
			modifier = cc_empire_interspecies_tensions
			years = 10
		}
		hidden_effect = {
			set_timed_country_flag = {
				flag = cc_recent_xeno_empire_clashes
				years = 50
			}
		}
		
		every_owned_planet = {
			limit = {
				NOT = { has_modifier = cc_planet_interspecies_tensions }
				count_owned_pop_amount = {
					count > 400
					limit = { species = { is_same_value = event_target:species1 } }
				}
				count_owned_pop_amount = {
					count > 400
					limit = { species = { is_same_value = event_target:species2 } }
				}
			}
			add_modifier = {
				modifier = cc_planet_interspecies_tensions
				years = 10
			}
			hidden_effect = { carrier_event = { id = cc_xeno_clashes.384 days = 180 random = 90 } }
		}
		
		owner = {
			if = {
				limit = { has_faction = supremacist }
				random_pop_faction = {
					limit = {
						is_pop_faction_type = supremacist
					}
					add_modifier = {
						modifier = cc_xenos_disparaged_sup
						years = 10
					}
				}
			}
			if = {
				limit = {
					any_pop_faction = {
						is_pop_faction_type = xenoist
						NOT = { has_modifier = cc_xenos_disparaged }
					}
				}
				random_pop_faction = {
					limit = {
						is_pop_faction_type = xenoist
						NOT = { has_modifier = cc_xenos_disparaged }
					}
					add_modifier = {
						modifier = cc_xenos_disparaged
						years = 10
					}
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				owner = { has_ethic = ethic_xenophobe }
			}
			modifier = {
				factor = 10
				owner = { has_ethic = ethic_fanatic_xenophobe }
			}
			modifier = {
				factor = 0
				NOT = { owner = { has_faction = supremacist } }
			}
			modifier = {
				factor = 0
				owner = {
					is_xenophile = no
				}
			}
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.384
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		random = {
			chance = 33
			carrier_event = { id = cc_xeno_clashes.37 }
		}
	}
}



###############Two species that aren't your own


carrier_event = {
	id = cc_xeno_clashes.4
	title = cc_xeno_clashes.4.name
	desc = cc_xeno_clashes.4.desc
	
	picture = GFX_evt_alien_segregation
	location = root
	
	is_triggered_only = yes

	trigger = {
		planet_stability < @dpe_normal_unrest_value
		is_owned_by = event_target:cc_owner
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species1 } }
		}
		count_owned_pop_amount = {
			count > 400
			limit = { species = { is_same_value = event_target:species2 } }
		}
	}
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_xeno_clashes
			years = 30
		}
	}
	
	option = {
		name = cc_xeno_clashes.4.A
		custom_tooltip = cc_xeno_clashes.4.A.tooltip
		
		allow = {
			owner = {
				NOT = { has_ethic = ethic_fanatic_xenophobe }
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = {
					pop_amount_percentage = {
						percentage > 0.2
						limit = { species = { is_same_value = event_target:species1 } }
					}
					pop_amount_percentage = {
						percentage < 0.1
						limit = { species = { is_same_value = event_target:species2 } }
					}
				}
			}
		}
		
		hidden_effect = {
			owner = {
				every_owned_pop_group = {
					limit = { species = { is_same_value = event_target:species1 } }
					add_modifier = {
						modifier = cc_ruled_in_our_favour_pops
						years = 10
					}
				}
				every_owned_pop_group = {
					limit = { species = { is_same_value = event_target:species2 } }
					add_modifier = {
						modifier = cc_ruled_against_us_pops
						years = 10
					}
				}
			}
		
			if = {
				limit = { has_modifier = cc_planet_hate_speech }
				remove_modifier = cc_planet_hate_speech
			}
		}
	
		add_modifier = {
			modifier = cc_planet_interspecies_tensions
			years = 10
		}
	}
	option = {
		name = cc_xeno_clashes.4.B
		custom_tooltip = cc_xeno_clashes.4.B.tooltip
		
		allow = {
			owner = {
				NOT = { has_ethic = ethic_fanatic_xenophobe }
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				owner = {
					pop_amount_percentage = {
						percentage > 0.2
						limit = { species = { is_same_value = event_target:species2 } }
					}
					pop_amount_percentage = {
						percentage < 0.1
						limit = { species = { is_same_value = event_target:species1 } }
					}
				}
			}
		}
		
		hidden_effect = {
			owner = {
				every_owned_pop_group = {
					limit = { species = { is_same_value = event_target:species2 } }
					add_modifier = {
						modifier = cc_ruled_in_our_favour_pops
						years = 10
					}
				}
				every_owned_pop_group = {
					limit = { species = { is_same_value = event_target:species1 } }
					add_modifier = {
						modifier = cc_ruled_against_us_pops
						years = 10
					}
				}
			}
		
			if = {
				limit = { has_modifier = cc_planet_hate_speech }
				remove_modifier = cc_planet_hate_speech
			}
		}
	
		add_modifier = {
			modifier = cc_planet_interspecies_tensions
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.4.C
		
		allow = {
			owner = {
				NOT = { has_ethic = ethic_fanatic_egalitarian }
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 3
				owner = { has_ethic = ethic_authoritarian }
			}
			modifier = {
				factor = 6
				owner = { has_ethic = ethic_fanatic_authoritarian }
			}
		}
		
		add_modifier = {
			modifier = cc_planet_interspecies_tensions
			years = 10
		}
		add_modifier = {
			modifier = cc_martial_law
			years = 10
		}
	}

	option = {
		name = cc_xeno_clashes.4.D
		custom_tooltip = cc_xeno_clashes.4.D.tooltip
		
		allow = {
			owner = {
				NOT = { has_ethic = ethic_fanatic_xenophobe }
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				owner = { has_ethic = ethic_xenophile }
			}
			modifier = {
				factor = 5
				owner = { has_ethic = ethic_fanatic_egalitarian }
			}
			modifier = {
				factor = 10
				owner = { has_ethic = ethic_fanatic_authoritarian }
			}
		}
		
		add_modifier = {
			modifier = cc_planet_interspecies_tensions
			years = 10
		}
		hidden_effect = {
			random_list = {
				1 = { carrier_event = { id = cc_xeno_clashes.5 days = 90 } }
				1 = { carrier_event = { id = cc_xeno_clashes.51 days = 90 } }
			}
		}
	}

	option = {
		name = cc_xeno_clashes.4.E
		custom_tooltip = cc_xeno_clashes.4.E.tooltip
		
		allow = {
			owner = {
				is_xenophile = no
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 5
				owner = { has_ethic = ethic_xenophobe }
			}
			modifier = {
				factor = 5
				owner = { has_ethic = ethic_xenophobe }
			}
			modifier = {
				factor = 0
				owner = { 
					OR = {
						is_xenophile = yes
						
						any_owned_pop_group = {
							NOT = { is_same_species = prev }
							has_citizenship_rights = no
						}
					}
				}
			}
		}
		
		hidden_effect = {
			if = {
				limit = { has_modifier = cc_planet_hate_speech }
				remove_modifier = cc_planet_hate_speech
			}
		}
		
		owner = {
			if = {
				limit = {
					is_xenophobe = no
				}
				shift_ethic = ethic_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 = isolationist
											is_pop_faction_type = xenoist
										}
									}
									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 }
								}
							}
						}
					}
				}
			}
		}
	
		add_modifier = {
			modifier = cc_planet_interspecies_tensions
			years = 10
		}
		
		owner = {
			if = {
				limit = { has_faction = xenoist }
				random_pop_faction = {
					limit = { is_pop_faction_type = xenoist }
					add_modifier = {
						modifier = cc_xenos_disparaged
						years = 10
					}
				}
			}
		}
		
		hidden_effect = {
			if = {
				limit = {
					owner = {
						any_owned_planet = {
							NOT = { is_same_value = root }
							OR = {
								count_owned_pop_amount = {
									count > 400
									limit = { species = { is_same_value = event_target:species1 } }
								}
								count_owned_pop_amount = {
									count > 400
									limit = { species = { is_same_value = event_target:species2 } }
								}
							}
						}
					}
				}
				owner = { country_event = { id = cc_xeno_clashes.41 days = 10 random = 10 } }
			}	
			else = {
				every_owned_pop_group = {
					limit = {
						OR = {
							species = { is_same_value = event_target:species1 }
							species = { is_same_value = event_target:species2 }
						}
					}
					add_modifier = {
						modifier = cc_feels_unwelcome
						years = 10
					}
				}
			}
		}
	}
}






country_event = {
	id = cc_xeno_clashes.41
	title = cc_xeno_clashes.41.name
	desc = cc_xeno_clashes.41.desc
	picture = GFX_evt_alien_segregation
	
	location = from	
	is_triggered_only = yes

	immediate = {
		create_leader = {
			class = commander 
			species = event_target:species1
			name = random
			skill = 1
		}
		last_created_leader = {
			save_event_target_as = annoyed_xeno
			exile_leader_as = cc_annoyed_xeno
		}
		create_leader = {
			class = commander 
			species = event_target:species2
			name = random
			skill = 1
		}
		last_created_leader = {
			save_event_target_as = annoyed_xeno2
			exile_leader_as = cc_annoyed_xeno2
		}
		set_timed_country_flag = {
			flag = cc_xeno_clashes_militia_formed
			years = 5
		}
	}
	
	option = {
		name = UNFORTUNATE
		
		from = { remove_modifier = cc_planet_interspecies_tensions }
		if = {
			limit = {
				any_owned_planet = {
					any_owned_pop_group = { is_same_species = root.owner }
					OR = {
						count_owned_pop_amount = {
							count > 400
							limit = { species = { is_same_value = event_target:species1 } }
						}
						count_owned_pop_amount = {
							count > 400
							limit = { species = { is_same_value = event_target:species2 } }
						}
					}
					owner = {
						any_owned_planet = {
							NOT = { is_same_value = prevprev }
							any_owned_pop_group = { is_same_species = root.owner }
							OR = {
								count_owned_pop_amount = {
									count > 400
									limit = { species = { is_same_value = event_target:species1 } }
								}
								count_owned_pop_amount = {
									count > 400
									limit = { species = { is_same_value = event_target:species2 } }
								}
							}
							owner = {
								any_owned_planet = {
									NOR = {
										is_same_value = prevprev
										is_same_value = prevprevprevprev
									}
									any_owned_pop_group = { is_same_species = root.owner }
									OR = {
										count_owned_pop_amount = {
											count > 400
											limit = { species = { is_same_value = event_target:species1 } }
										}
										count_owned_pop_amount = {
											count > 400
											limit = { species = { is_same_value = event_target:species2 } }
										}
									}
								}
							}
						}
					}
				}
			}					
			add_modifier = {
				modifier = cc_empire_interspecies_tensions
				years = 10
			}
			hidden_effect = {
				set_timed_country_flag = {
					flag = cc_recent_xeno_empire_clashes
					years = 50
				}
			}
		}

		every_owned_planet = {
			limit = {
				NOT = { has_modifier = cc_planet_interspecies_tensions }
				any_owned_pop_group = { is_same_species = root.owner }
				OR = {
					count_owned_pop_amount = {
						count > 400
						limit = { species = { is_same_value = event_target:species1 } }
					}
					count_owned_pop_amount = {
						count > 400
						limit = { species = { is_same_value = event_target:species2 } }
					}
				}
			}
			add_modifier = {
				modifier = cc_planet_interspecies_tensions
				years = 10
			}
		}
		
		custom_tooltip = cc_xeno_clashes.41.tooltip
		hidden_effect = {
			every_owned_pop_group = {
				limit = {
					species = {
						OR = {
							is_same_value = event_target:species1
							is_same_value = event_target:species2
						}
					}
				}
				add_modifier = {
					modifier = cc_feels_unwelcome
					years = 10
				}
			}
			every_owned_planet = {
				limit = {
					any_owned_pop_group = {
						OR = {
							species = { is_same_value = event_target:species1 }
							species = { is_same_value = event_target:species2 }
						}
					}
				}
				carrier_event = { id = cc_xeno_clashes.415 days = 30 }
			}
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.415
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_modifier = cc_planet_interspecies_tensions
		any_owned_pop_group = { is_same_species = root.owner }
		OR = {
			count_owned_pop_amount = {
				count > 400
				limit = { species = { is_same_value = event_target:species1 } }
			}
			count_owned_pop_amount = {
				count > 400
				limit = { species = { is_same_value = event_target:species2 } }
			}
		}
		NOT = { has_carrier_flag = cc_interspecies_incident }
		is_owned_by = event_target:cc_owner
	}
	
	immediate = {
		if = {
			limit = {
				any_owned_pop_group = { species = { is_same_value = event_target:species1 } }
			}
			if = {
				limit = {
					pop_amount < 2000
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.42 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					149 = { }
				}
			}
			if = {
				limit = {
					NOT = {
						pop_amount < 2000
					}
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.43 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					1 = {
						carrier_event = { id = cc_xeno_clashes.44 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					297 = { }
				}
			}
		}
		else = {
			if = {
				limit = {
					pop_amount < 2000
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.45 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					149 = { }
				}
			}
			if = {
				limit = {
					NOT = {
						pop_amount < 2000
					}
				}
				random_list = {
					1 = {
						carrier_event = { id = cc_xeno_clashes.46 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
						modifier = {
							factor = 0
							NOR = {
								has_building = building_colony_shelter
								has_building = building_capital
								has_building = building_major_capital
								has_building = building_system_capital
								has_building = building_hab_capital
								has_building = building_hab_major_capital
							}
						}
					}
					1 = {
						carrier_event = { id = cc_xeno_clashes.44 }
						modifier = {
							factor = 1.5
							planet_stability < @dpe_normal_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_bit_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_somewhat_unrest_value
						}
						modifier = {
							factor = 1.5
							planet_stability < @dpe_risk_unrest_value
						}
					}
					297 = { }
				}
			}
		}
		carrier_event = { id = cc_xeno_clashes.415 days = 30 }
	}
}


carrier_event = {
	id = cc_xeno_clashes.42
	title = cc_xeno_clashes.42.name
	desc = cc_xeno_clashes.42.desc
	picture = GFX_evt_burning_settlement
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.42.option
		random_owned_pop_group = {
			limit = { is_same_species = root.owner }
			kill_pop_group = { pop_group = this amount = 100% }
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.43
	title = cc_xeno_clashes.43.name
	desc = cc_xeno_clashes.43.desc
	picture = GFX_evt_mem_ost_terror_attack
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.43.option
		if = {
			limit = {
				has_district = district_city
			}
			remove_district = district_city
		}
		else_if = {
			limit = {
				has_district = district_arcology_housing
			}
			remove_district = district_arcology_housing
		}
		while = {
			limit = {
				count_owned_pop_amount = {
					limit = { species = { is_same_value = root.owner_species } }
					count > 10000
				}
			}
			count = 600
			
			random_owned_pop_group = {
				limit = { species = { is_same_value = root.owner_species } }
				kill_pop_group = { pop_group = this amount = 100% }
			}
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.44
	title = cc_xeno_clashes.44.name
	desc = cc_xeno_clashes.44.desc
	picture = GFX_evt_glitchy_matrix
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.44.option
		
		add_modifier = {
			modifier = cc_disrupted_government
			years = 5
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.45
	title = cc_xeno_clashes.45.name
	desc = cc_xeno_clashes.45.desc
	picture = GFX_evt_burning_settlement
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.45.option
		
		add_modifier = {
			modifier = cc_disrupted_government
			years = 5
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.46
	title = cc_xeno_clashes.46.name
	desc = cc_xeno_clashes.46.desc
	picture = GFX_evt_mem_ost_terror_attack
	
	location = root
	is_triggered_only = yes
	
	immediate = {
		set_timed_carrier_flag = {
			flag = cc_interspecies_incident
			years = 10
		}
	}
	
	option = {
		name = cc_xeno_clashes.46.option
		
		switch = {
			trigger = has_building
			building_colony_shelter = { remove_building = building_colony_shelter }
			building_capital = { remove_building = building_capital }
			building_major_capital = { remove_building = building_major_capital }
			building_system_capital = { remove_building = building_system_capital }
			building_hab_capital = { remove_building = building_hab_capital }
			building_hab_major_capital = { remove_building = building_hab_major_capital }
		}
		
		add_modifier = {
			modifier = cc_disrupted_government
			years = 5
		}
	}
}




carrier_event = {
	id = cc_xeno_clashes.5
	title = cc_xeno_clashes.5.name
	desc = cc_xeno_clashes.5.desc
	picture = GFX_evt_burning_settlement
	
	location = root
	is_triggered_only = yes
	
	option = {
		name = cc_xeno_clashes.5.A
		
		add_modifier = {
			modifier = cc_martial_law
			months = 117
		}
	}
	option = {
		name = cc_xeno_clashes.5.B
	}
}

carrier_event = {
	id = cc_xeno_clashes.51
	title = cc_xeno_clashes.51.name
	desc = cc_xeno_clashes.51.desc
	picture = GFX_evt_cc_throne_room
	
	location = root
	is_triggered_only = yes
	
	option = {
		name = cc_xeno_clashes.51.A
		
		add_modifier = {
			modifier = cc_investment_package
			years = 10
		}
		remove_modifier = cc_planet_interspecies_tensions
	}
	option = {
		name = cc_xeno_clashes.51.B
		custom_tooltip = cc_xeno_clashes.51.B.tooltip
		
		hidden_effect = {
			random_list = {
				1 = { carrier_event = { id = cc_xeno_clashes.52 days = 90 } }
				1 = { carrier_event = { id = cc_xeno_clashes.53 days = 90 } }
			}
		}
	}
}

carrier_event = {
	id = cc_xeno_clashes.52
	title = cc_xeno_clashes.52.name
	desc = cc_xeno_clashes.52.desc
	picture = GFX_evt_burning_settlement
	
	location = root
	is_triggered_only = yes
	
	option = {
		name = cc_xeno_clashes.52.A
		
		add_modifier = {
			modifier = cc_martial_law
			months = 117
		}
	}
	option = {
		name = cc_xeno_clashes.52.B
	}
}

carrier_event = {
	id = cc_xeno_clashes.53
	title = cc_xeno_clashes.53.name
	desc = cc_xeno_clashes.53.desc
	picture = GFX_evt_arguing_senate
	
	location = root
	is_triggered_only = yes
	
	option = {
		name = CCEXCELLENT
		
		remove_modifier = cc_planet_interspecies_tensions
	}
}


