namespace = cc_events_mod


#Interspecies Marriage (country event)
country_event = {
	id = cc_events_mod.7
	title = cc_events_mod.7.name
	desc = {
		trigger = { NOT = { has_faction = supremacist } }
		text = cc_events_mod.7.desc_nophobe
	}
	desc = {
		trigger = { has_faction = supremacist }
		text = cc_events_mod.7.desc_phobe
	}
	picture = GFX_evt_dpe_alien_wedding
	is_triggered_only = yes
	
	trigger = {
		is_country_type = default
		
		has_faction = xenoist
		
		NOR = {
			is_gestalt = yes
			has_country_flag = cc_has_had_interspecies_marriage
		}
		
		pop_amount_percentage = {
			percentage > 0.02
			limit = {
				NOR = {
					is_enslaved = yes
					is_being_purged = yes
				}
				has_pop_group_flag = cc_literally_xenophile_manifested
			}
		}
	}
	
	# mean_time_to_happen = {
	# 	years = 20
	# }

	immediate = {
		random_pop_faction = {
			limit = { is_pop_faction_type = xenoist }
			save_event_target_as = xenophile_faction
		}
		
		if = {
			limit = { has_faction = supremacist }
			random_pop_faction = {
				limit = { is_pop_faction_type = supremacist }
				save_event_target_as = xenophobe_faction
			}
			set_country_flag = cc_im_supremacists
		}
		
		set_country_flag = cc_has_had_interspecies_marriage
		
		set_timed_country_flag = {
			flag = recent_im_first_decision
			years = 1
		}
	}
	
	option = {	#legalise it
		name = cc_events_mod.7.A
		
		set_policy = {
			policy = cc_interspecies_marriage
			option = allow_im
			cooldown = yes
		}
		
		random_pop_faction = {
			limit = { is_pop_faction_type = xenoist }
			add_modifier = {
				modifier = cc_xeno_marriage_allowed_xenoist
				days = -1
			}
		}
		
		if = {
			limit = { has_faction = supremacist }
			random_pop_faction = {
				limit = { is_pop_faction_type = supremacist }
				add_modifier = {
					modifier = cc_xeno_marriage_allowed_supremacist
					days = -1
				}
			}
		}
		if = {
			limit = { has_faction = isolationist }
			random_pop_faction = {
				limit = { is_pop_faction_type = isolationist }
				add_modifier = {
					modifier = cc_xeno_marriage_allowed_isolationist
					days = -1
				}
			}
		}
		
		
		hidden_effect = {
			every_owned_pop_group = {
				limit = {
					has_pop_group_flag = cc_literally_xenophile_manifested
					NOT = { has_modifier = cc_practising_xenophile }
				}
				add_modifier = {
					modifier = cc_practising_xenophile
					days = -1
				}
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_secretly_practising_xenophile }
				remove_modifier = cc_secretly_practising_xenophile
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_secret_xenophile }
				remove_modifier = cc_secret_xenophile
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 100
				is_xenophile = yes
			}
			modifier = {
				factor = 0
				OR = {
					is_xenophobe = yes
					NOT = { has_faction = xenoist }
				}
			}
		}
	}
	option = {	#do not legalise it
		name = cc_events_mod.7.B
		
		set_policy = {
			policy = cc_interspecies_marriage
			option = do_not_allow_im
			cooldown = yes
		}
		
		hidden_effect = {
			every_owned_pop_group = {
				limit = {
					has_pop_group_flag = cc_literally_xenophile_manifested
					NOT = { has_modifier = cc_secretly_practising_xenophile }
				}
				add_modifier = {
					modifier = cc_secretly_practising_xenophile
					days = -1
				}
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_practising_xenophile }
				remove_modifier = cc_practising_xenophile
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_secret_xenophile }
				remove_modifier = cc_secret_xenophile
			}
		}

		random_pop_faction = {
			limit = { is_pop_faction_type = xenoist }
			add_modifier = {
				modifier = cc_xeno_marriage_not_allowed_xenoist
				days = -1
			}
		}
		
		if = {
			limit = { has_faction = supremacist }
			random_pop_faction = {
				limit = { is_pop_faction_type = supremacist }
				add_modifier = {
					modifier = cc_xeno_marriage_not_allowed_supremacist
					days = -1
				}
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
	option = {	#illegalise intercourse
		name = cc_events_mod.7.C
		
		set_policy = {
			policy = cc_interspecies_marriage
			option = ban_im_completely
			cooldown = yes
		}
		
		hidden_effect = {
			every_owned_pop_group = {
				limit = {
					has_pop_group_flag = cc_literally_xenophile_manifested
					NOT = { has_modifier = cc_secret_xenophile }
				}
				add_modifier = {
					modifier = cc_secret_xenophile
					days = -1
				}
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_secretly_practising_xenophile }
				remove_modifier = cc_secretly_practising_xenophile
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_practising_xenophile }
				remove_modifier = cc_practising_xenophile
			}
		}

		random_pop_faction = {
			limit = { is_pop_faction_type = xenoist }
			add_modifier = {
				modifier = cc_xeno_marriage_banned_xenoist
				days = -1
			}
		}
		
		if = {
			limit = { has_faction = supremacist }
			random_pop_faction = {
				limit = { is_pop_faction_type = supremacist }
				add_modifier = {
					modifier = cc_xeno_marriage_banned_supremacist
					days = -1
				}
			}
		}
		
		ai_chance = {
			factor = 1
			modifier = {
				factor = 100
				is_xenophobe = yes
			}
			modifier = {
				factor = 0
				OR = {
					is_xenophile = yes
					NOR = {
						has_faction = supremacist
						has_faction = isolationist
					}
				}
			}
		}
	}
}

#decadely
event = {
	id = cc_events_mod.8
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		every_playable_country = {
			limit = {
				any_owned_species = {
					NOT = { is_same_species = prev }
					species_has_happiness_with_owner = prev
				}
			}
			every_owned_planet = {
				limit = {
					any_owned_species = {
						NOT = { is_same_species = prevprev }
						species_has_happiness_with_owner = prevprev
					}
				}
				carrier_event = { id = cc_events_mod.81 days = 1 random = 15 }
			}
		}
	}
}

carrier_event = {
	id = cc_events_mod.81
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		every_owned_pop_group = {
			limit = { pop_group_has_happiness = yes }
			pop_group_event = { id = cc_events_mod.9 }
		}
	}
}

pop_group_event = {
	id = cc_events_mod.9
	hide_window = yes
	is_triggered_only = yes
	
	trigger = { NOT = { has_ethic = ethic_xenophobe } }
	
	immediate = {
		if = {
			limit = {
				has_pop_group_flag = cc_not_literally_xenophile_3
				owner? = { has_policy_flag = allows_im }
			}
			remove_pop_group_flag = cc_not_literally_xenophile_3
			
			random_list = {
				1 = {
					set_pop_group_flag = cc_literally_xenophile
					modifier = {
						factor = 1.5
						has_ethic = ethic_xenophile
					}
					modifier = {
						factor = 1.5
						planet = {
							any_owned_species = {
								NOT = { is_same_species = root }
								species_has_happiness_with_owner = prev.owner
							}
						}
					}
				}
				15 = { set_pop_group_flag = cc_not_literally_xenophile_4 }
			}
		}
		if = {
			limit = {
				has_pop_group_flag = cc_not_literally_xenophile_2
				NOT = { has_ethic = ethic_xenophobe }
				OR = {
					owner = { has_policy_flag = allows_im }
					planet = {
						any_owned_species = {
							NOT = { is_same_species = root }
							species_has_happiness_with_owner = prev.owner
						}
					}
				}
			}
			remove_pop_group_flag = cc_not_literally_xenophile_2
			
			random_list = {
				1 = {
					set_pop_group_flag = cc_literally_xenophile
					modifier = {
						factor = 1.5
						has_ethic = ethic_xenophile
					}
					modifier = {
						factor = 1.5
						planet = {
							any_owned_species = {
								NOT = { is_same_species = root }
								species_has_happiness_with_owner = prev.owner
							}
						}
					}
				}
				15 = { set_pop_group_flag = cc_not_literally_xenophile_3 }
			}
		}
		if = {
			limit = {
				has_pop_group_flag = cc_not_literally_xenophile_1
				NOT = { has_ethic = ethic_xenophobe }
				OR = {
					has_ethic = ethic_xenophile
					owner = {
						OR = {
							is_xenophile = yes
							has_policy_flag = does_not_allow_im
							has_policy_flag = allows_im
						}
					}
					planet = {
						any_owned_species = {
							NOT = { is_same_species = root }
							species_has_happiness_with_owner = prev.owner
						}
					}
				}
			}
			remove_pop_group_flag = cc_not_literally_xenophile_1
			
			random_list = {
				1 = {
					set_pop_group_flag = cc_literally_xenophile
					modifier = {
						factor = 1.5
						has_ethic = ethic_xenophile
					}
					modifier = {
						factor = 1.5
						planet = {
							any_owned_species = {
								NOT = { is_same_species = root }
								species_has_happiness_with_owner = prev.owner
							}
						}
					}
				}
				15 = { set_pop_group_flag = cc_not_literally_xenophile_2 }
			}
		}
		if = {
			limit = {
				NOR = {
					has_pop_group_flag = cc_literally_xenophile
					has_pop_group_flag = cc_not_literally_xenophile_1
					has_pop_group_flag = cc_not_literally_xenophile_2
					has_pop_group_flag = cc_not_literally_xenophile_3
					has_pop_group_flag = cc_not_literally_xenophile_4
				}
			}
			random_list = {
				1 = {
					set_pop_group_flag = cc_literally_xenophile
					modifier = {
						factor = 1.5
						has_ethic = ethic_xenophile
					}
					modifier = {
						factor = 1.5
						planet = {
							any_owned_species = {
								NOT = { is_same_species = root }
								species_has_happiness_with_owner = prev.owner
							}
						}
					}
				}
				15 = { set_pop_group_flag = cc_not_literally_xenophile_1 }
			}
		}
	}
}


pop_group_event = {
	id = cc_events_mod.10
	hide_window = yes
	
	mean_time_to_happen = { years = 20 }
	
	trigger = {
		has_pop_group_flag = cc_literally_xenophile
		pop_group_has_happiness = yes
		NOT = { has_pop_group_flag = cc_literally_xenophile_manifested }
		owner? = {
			pop_amount_percentage = {
				percentage > 0.2
				limit = {
					NOT = { is_same_species = root }
					pop_group_has_happiness = yes
					NOR = {
						is_enslaved = yes
						is_being_purged = yes
					}
				}
			}
		}
	}
	
	immediate = {
		random_list = {
			100 = { #NOTHING
				modifier = {
					factor = 0.75
					owner = { has_country_flag = cc_has_had_interspecies_marriage }
				}
				modifier = {
					factor = 2
					has_ethic = ethic_xenophobe
				}
				modifier = {
					factor = 0.5
					has_ethic = ethic_xenophile
				}
				modifier = {
					factor = 0.75
					owner = { has_country_flag = cc_eventperf_founder_is_minority }
				}
			}
			100 = {
				set_pop_group_flag = cc_literally_xenophile_manifested
				
				if = {
					limit = { owner = { has_policy_flag = allows_im } }
					add_modifier = {
						modifier = cc_practising_xenophile
						days = -1
					}
				}
				if = {
					limit = {
						owner = {
							OR = {
								has_policy_flag = does_not_allow_im
								NOT = { has_country_flag = cc_has_had_interspecies_marriage }
							}
						}
					}
					add_modifier = {
						modifier = cc_secretly_practising_xenophile
						days = -1
					}
				}
				if = {
					limit = { owner = { has_policy_flag = bans_im_completely } }
					add_modifier = {
						modifier = cc_secret_xenophile
						days = -1
					}
				}
			}
		}
	}
}
	

#Gradually gets rid of modifiers if there are no longer foreigners
pop_group_event = {
	id = cc_events_mod.11
	hide_window = yes
	
	mean_time_to_happen = { years = 25 }

	trigger = {
		has_pop_group_flag = cc_literally_xenophile_manifested
		pop_group_has_happiness = yes
		owner? = { NOT = { has_country_flag = cc_eventperf_has_minority } }
	}
	
	immediate = {
		random_list = {
			3 = {
				remove_pop_group_flag = cc_literally_xenophile_manifested
				if = {
					limit = { has_modifier = cc_practising_xenophile }
					remove_modifier = cc_practising_xenophile
				}
				if = {
					limit = { has_modifier = cc_secretly_practising_xenophile }
					remove_modifier = cc_secretly_practising_xenophile
				}
				if = {
					limit = { has_modifier = cc_secret_xenophile }
					remove_modifier = cc_secret_xenophile
				}
			}			
			2 = {
				modifier = {
					factor = 2
					owner = { has_policy_flag = allows_im }
				}
			}
		}
	}
}

	
			
#yearly
event = {
	id = cc_events_mod.12
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		every_country = {
			if = {
				limit = {
					NOR = {
						has_modifier = cc_literally_xenophile_country
						has_ascension_perk = ap_xeno_compatibility
					}
					pop_amount_percentage = {
						percentage > 0.15
						limit = {
							has_pop_group_flag = cc_literally_xenophile_manifested
							is_robot_pop = no
						}
					}
				}
				add_modifier = {
					modifier = cc_literally_xenophile_country
					days = -1
				}
				if = {
					limit = { is_ai = no }
					country_event = { id = cc_events_mod.121 }
				}
			}
			if = {
				limit = {
					has_modifier = cc_literally_xenophile_country
					OR = {
						has_ascension_perk = ap_xeno_compatibility
						NOT = {
							pop_amount_percentage = {
								percentage > 0.15
								limit = {
									has_pop_group_flag = cc_literally_xenophile_manifested
									is_robot_pop = no
								}
							}
						}
					}
				}
				remove_modifier = cc_literally_xenophile_country
			}
			every_owned_pop_group = {
				limit = {
					pop_group_has_happiness = no
					OR = {
						has_pop_group_flag = cc_literally_xenophile
						has_pop_group_flag = cc_literally_xenophile_manifested
						has_modifier = cc_practising_xenophile
						has_modifier = cc_secretly_practising_xenophile
						has_modifier = cc_secret_xenophile
					}
				}
				if = {
					limit = { has_pop_group_flag = cc_literally_xenophile }
					remove_pop_group_flag = cc_literally_xenophile
				}
				if = {
					limit = { has_pop_group_flag = cc_literally_xenophile_manifested }
					remove_pop_group_flag = cc_literally_xenophile_manifested
				}
				if = {
					limit = { has_modifier = cc_practising_xenophile }
					remove_modifier = cc_practising_xenophile
				}
				if = {
					limit = { has_modifier = cc_secretly_practising_xenophile }
					remove_modifier = cc_secretly_practising_xenophile
				}
				if = {
					limit = { has_modifier = cc_secret_xenophile }
					remove_modifier = cc_secret_xenophile
				}
			}
			if = {
				limit = { has_policy_flag = allows_im }
				every_owned_pop_group = {
					limit = {
						OR = {
							has_modifier = cc_secretly_practising_xenophile
							has_modifier = cc_secret_xenophile
						}
					}
					if = {
						limit = { has_modifier = cc_secretly_practising_xenophile }
						remove_modifier = cc_secretly_practising_xenophile
						add_modifier = {
							modifier = cc_practising_xenophile
							days = -1
						}
					}
					else = {
						remove_modifier = cc_secret_xenophile
						add_modifier = {
							modifier = cc_practising_xenophile
							days = -1
						}
					}				
				}
			}
			if = {
				limit = {
					OR = {
						has_policy_flag = does_not_allow_im
						NOT = { has_country_flag = cc_has_had_interspecies_marriage }
					}
				}
				every_owned_pop_group = {
					limit = {
						OR = {
							has_modifier = cc_practising_xenophile
							has_modifier = cc_secret_xenophile
						}
					}
					if = {
						limit = { has_modifier = cc_practising_xenophile }
						remove_modifier = cc_practising_xenophile
						add_modifier = {
							modifier = cc_secretly_practising_xenophile
							days = -1
						}
					}
					else = {
						remove_modifier = cc_secret_xenophile
						add_modifier = {
							modifier = cc_secretly_practising_xenophile
							days = -1
						}
					}				
				}
			}
			if = {
				limit = { has_policy_flag = bans_im_completely }
				every_owned_pop_group = {
					limit = {
						OR = {
							has_modifier = cc_practising_xenophile
							has_modifier = cc_secretly_practising_xenophile
						}
					}
					if = {
						limit = { has_modifier = cc_practising_xenophile }
						remove_modifier = cc_practising_xenophile
						add_modifier = {
							modifier = cc_secret_xenophile
							days = -1
						}
					}
					else = {
						remove_modifier = cc_secretly_practising_xenophile
						add_modifier = {
							modifier = cc_secret_xenophile
							days = -1
						}
					}				
				}
			}
			
			

			if = {
				limit = {
					has_faction = isolationist
					has_country_flag = cc_has_had_interspecies_marriage
					has_policy_flag = allows_im
					NOT = { has_country_flag = cc_im_isolationists }			
				}
				set_country_flag = cc_im_isolationists
				
				random_pop_faction = {
					limit = { is_pop_faction_type = isolationist }
					add_modifier = {
						modifier = cc_xeno_marriage_allowed_supremacist
						days = -1
					}
				}
			}
			if = {
				limit = {
					has_faction = supremacist
					has_country_flag = cc_has_had_interspecies_marriage
					NOT = { has_country_flag = cc_im_supremacists }			
				}
				set_country_flag = cc_im_supremacists
				
				if = {
					limit = { has_policy_flag = allows_im }

					random_pop_faction = {
						limit = { is_pop_faction_type = supremacist }
						add_modifier = {
							modifier = cc_xeno_marriage_allowed_supremacist
							days = -1
						}
					}
				}
				if = {
					limit = { has_policy_flag = does_not_allow_im }

					random_pop_faction = {
						limit = { is_pop_faction_type = supremacist }
						add_modifier = {
							modifier = cc_xeno_marriage_not_allowed_supremacist
							days = -1
						}
					}
				}
				if = {
					limit = { has_policy_flag = bans_im_completely }

					random_pop_faction = {
						limit = { is_pop_faction_type = supremacist }
						add_modifier = {
							modifier = cc_xeno_marriage_banned_supremacist
							days = -1
						}
					}
				}
			}
		}
	}
}

country_event = {
	id = cc_events_mod.121
	title = cc_events_mod.121.name
	desc = cc_events_mod.121.desc
	
	picture = GFX_evt_dpe_alien_wedding
	
	is_triggered_only = yes
	
	option = {
		name = OK
		tooltip = {
			add_modifier = {
				modifier = cc_literally_xenophile_country
				days = -1
			}
		}
	}
}



pop_group_event = {
	id = cc_events_mod.1300
	hide_window = yes
	
	trigger = {
		owner? = { has_policy_flag = bans_im_completely }
		is_valid_xenophilia_refugee_pop = yes
	}

	mean_time_to_happen = { years = 30 }

	immediate = {
		random_list = {
			100 = {
				pop_group_event = { id = cc_events_mod.13 }
			}			
			30 = {
				modifier = {
					factor = 0
					NOT = { is_same_species = owner }
				}
			}
		}
	}
}

#triggered in performance
# Pop escapes into a country where it can be 'literally xenophile'
pop_group_event = {
	id = cc_events_mod.13
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {	
		is_valid_xenophilia_refugee_pop = yes
		owner? = {
			has_policy_flag = bans_im_completely
		}
	}
	
	immediate = {
		save_event_target_as = refugee_pop
		xenophilia_refugee_pop_effect = yes

#		log = "Xenophilia pop in the [root.owner.GetName] flees"
	}
}

# Refugees Arrive, fleeing persecution for xenophilia
pop_group_event = {
	id = cc_events_mod.131
	title = cc_events_mod.131.name	
	picture = GFX_evt_unknown_ships
	location = root
	
	desc = cc_events_mod.131.desc
	
	is_triggered_only = yes
	
	option = {
		name = cc_events_mod.131.a
	}
}



pop_group_event = {
	id = cc_events_mod.1400
	hide_window = yes
	mean_time_to_happen = { years = 38 }

	trigger = {
		has_modifier = cc_secret_xenophile
		owner? = {
			is_country_type = default
			has_policy_flag = bans_im_completely
			OR = {
				has_valid_civic = civic_fanatic_purifiers
				has_policy_flag = purge_allowed
				has_edict = cc_thought_police
			}
		}
	}
	
	immediate = {
		random_list = {
			80 = { pop_group_event = { id = cc_events_mod.14 } }
			20 = {
				modifier = {
					factor = 0
					is_same_species = owner
				}
			}
		}
	}
}

#triggered in performance
#pop purged for being 'literally xenophile'
pop_group_event = {
	id = cc_events_mod.14
	
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_modifier = cc_secret_xenophile
		
		owner? = {
			is_country_type = default
			has_policy_flag = bans_im_completely
			OR = {
				has_valid_civic = civic_fanatic_purifiers
				has_policy_flag = purge_allowed
			}
		}
	}
	
	immediate = {
		kill_pop_group = { pop_group = this amount = 75% }
	}
}


#On policy changing (resets the modifiers to the correct setting)
country_event = {
	id = cc_events_mod.15
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		last_changed_policy = cc_interspecies_marriage
		NOT = { has_country_flag = recent_im_first_decision }
	}
	
	immediate = {
		if = {
			limit = { has_policy_flag = allows_im }

			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				add_modifier = {
					modifier = cc_xeno_marriage_allowed_xenoist
					days = -1
				}
				if = {
					limit = { has_modifier = cc_xeno_marriage_banned_xenoist }
					remove_modifier = cc_xeno_marriage_banned_xenoist
				}
				if = {
					limit = { has_modifier = cc_xeno_marriage_not_allowed_xenoist }
					remove_modifier = cc_xeno_marriage_not_allowed_xenoist
				}
			}
			
			if = {
				limit = { has_faction = isolationist }
				random_pop_faction = {
					limit = { is_pop_faction_type = isolationist }
					add_modifier = {
						modifier = cc_xeno_marriage_allowed_isolationist
						days = -1
					}
				}
			}

			if = {
				limit = { has_faction = supremacist }
				random_pop_faction = {
					limit = { is_pop_faction_type = supremacist }
					add_modifier = {
						modifier = cc_xeno_marriage_allowed_supremacist
						days = -1
					}
					if = {
						limit = { has_modifier = cc_xeno_marriage_banned_supremacist }
						remove_modifier = cc_xeno_marriage_banned_supremacist
					}
					if = {
						limit = { has_modifier = cc_xeno_marriage_not_allowed_supremacist }
						remove_modifier = cc_xeno_marriage_not_allowed_supremacist
					}
				}
			}
		
			every_owned_pop_group = {
				limit = {
					has_pop_group_flag = cc_literally_xenophile_manifested
					NOT = { has_modifier = cc_practising_xenophile }
				}
				add_modifier = {
					modifier = cc_practising_xenophile
					days = -1
				}
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_secretly_practising_xenophile }
				remove_modifier = cc_secretly_practising_xenophile
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_secret_xenophile }
				remove_modifier = cc_secret_xenophile
			}
		}
		
		if = {
			limit = { has_policy_flag = does_not_allow_im }
			
			every_owned_pop_group = {
				limit = {
					has_pop_group_flag = cc_literally_xenophile_manifested
					NOT = { has_modifier = cc_secretly_practising_xenophile }
				}
				add_modifier = {
					modifier = cc_secretly_practising_xenophile
					days = -1
				}
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_practising_xenophile }
				remove_modifier = cc_practising_xenophile
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_secret_xenophile }
				remove_modifier = cc_secret_xenophile
			}

			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				add_modifier = {
					modifier = cc_xeno_marriage_not_allowed_xenoist
					days = -1
				}
				if = {
					limit = { has_modifier = cc_xeno_marriage_allowed_xenoist }
					remove_modifier = cc_xeno_marriage_allowed_xenoist
				}
				if = {
					limit = { has_modifier = cc_xeno_marriage_banned_xenoist }
					remove_modifier = cc_xeno_marriage_banned_xenoist
				}
			}
			
			if = {
				limit = {
					has_faction = isolationist
					any_pop_faction = {
						has_modifier = cc_xeno_marriage_allowed_isolationist
					}
				}
				random_pop_faction = {
					limit = { is_pop_faction_type = isolationist }
					remove_modifier = cc_xeno_marriage_allowed_isolationist
				}
			}
			
			if = {
				limit = { has_faction = supremacist }
				random_pop_faction = {
					limit = { is_pop_faction_type = supremacist }
					add_modifier = {
						modifier = cc_xeno_marriage_not_allowed_supremacist
						days = -1
					}
					if = {
						limit = { has_modifier = cc_xeno_marriage_allowed_supremacist }
						remove_modifier = cc_xeno_marriage_allowed_supremacist
					}
					if = {
						limit = { has_modifier = cc_xeno_marriage_banned_supremacist }
						remove_modifier = cc_xeno_marriage_banned_supremacist
					}
				}
			}
		}
		
		if = {
			limit = { has_policy_flag = bans_im_completely }
			
			every_owned_pop_group = {
				limit = {
					has_pop_group_flag = cc_literally_xenophile_manifested
					NOT = { has_modifier = cc_secret_xenophile }
				}
				add_modifier = {
					modifier = cc_secret_xenophile
					days = -1
				}
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_secretly_practising_xenophile }
				remove_modifier = cc_secretly_practising_xenophile
			}
			every_owned_pop_group = {
				limit = { has_modifier = cc_practising_xenophile }
				remove_modifier = cc_practising_xenophile
			}

			random_pop_faction = {
				limit = { is_pop_faction_type = xenoist }
				add_modifier = {
					modifier = cc_xeno_marriage_banned_xenoist
					days = -1
				}
				if = {
					limit = { has_modifier = cc_xeno_marriage_allowed_xenoist }
					remove_modifier = cc_xeno_marriage_allowed_xenoist
				}
				if = {
					limit = { has_modifier = cc_xeno_marriage_not_allowed_xenoist }
					remove_modifier = cc_xeno_marriage_not_allowed_xenoist
				}
			}
			
			if = {
				limit = {
					has_faction = isolationist
					any_pop_faction = {
						has_modifier = cc_xeno_marriage_allowed_isolationist
					}
				}
				random_pop_faction = {
					limit = { is_pop_faction_type = isolationist }
					remove_modifier = cc_xeno_marriage_allowed_isolationist
				}
			}
			
			if = {
				limit = { has_faction = supremacist }
				random_pop_faction = {
					limit = { is_pop_faction_type = supremacist }
					add_modifier = {
						modifier = cc_xeno_marriage_banned_supremacist
						days = -1
					}
					if = {
						limit = { has_modifier = cc_xeno_marriage_allowed_supremacist }
						remove_modifier = cc_xeno_marriage_allowed_supremacist
					}
					if = {
						limit = { has_modifier = cc_xeno_marriage_not_allowed_supremacist }
						remove_modifier = cc_xeno_marriage_not_allowed_supremacist
					}
				}
			}
		}
	}
}



##Prominent Interspecies Marriage
country_event = {
	id = cc_events_mod.16
	title = cc_events_mod.16.name
	desc = cc_events_mod.16.desc
	picture = GFX_evt_dpe_alien_wedding

	is_triggered_only = yes
	
	# mean_time_to_happen = { years = 35 }

	trigger = {
		is_country_type = default
		
		NOT = { has_country_flag = cc_recent_prominent_IM }
		has_policy_flag = allows_im
		
		any_owned_species = {
			NOT = { is_same_species = root }
			species_has_happiness_with_owner = root
			OR = {
				has_citizenship_type = { country = root type = citizenship_full }
				has_citizenship_type = { country = root type = citizenship_limited }
			}
		}
		any_owned_leader = {
			NOR = {
				is_same_value = root.ruler
				has_ethic = ethic_xenophobe
				has_leader_flag = cc_married
			}
			is_same_species = root
		}
	}
	
	immediate = {
		random_owned_leader = {
			limit = {
				NOR = {
					is_same_value = root.leader
					has_ethic = ethic_xenophobe
					has_leader_flag = cc_married
				}
				is_same_species = root
			}
			save_event_target_as = cc_happy_partner
			set_leader_flag = cc_married
		}
		
		random_owned_pop_group = {
			limit = {
				NOT = { is_same_species = root }
				pop_group_has_happiness = yes
				OR = {
					has_citizenship_type = { country = root type = citizenship_full }
					has_citizenship_type = { country = root type = citizenship_limited }
				}
			}
			save_event_target_as = marriage_species
		}
		
		create_leader = {
			class = scientist
			species = event_target:marriage_species.species
			name = random
			skill = 1
			event_leader = yes
		}
		last_created_leader = {
			save_event_target_as = cc_bride_or_groom
			exile_leader_as = cc_married_off
		}
		
		
		set_timed_country_flag = {
			flag = cc_recent_prominent_IM
			years = 15
		}
	}
	option = {
		name = cc_events_mod.16.option
		
		add_modifier = {
			modifier = cc_recent_xenophile_wedding
			years = 5
		}
		random_pop_faction = {
			limit = { is_pop_faction_type = xenoist }
			add_modifier = {
				modifier = cc_recent_xenophile_wedding_xenophile
				years = 5
			}
		}
		random_pop_faction = {
			limit = { is_pop_faction_type = supremacist }
			add_modifier = {
				modifier = cc_recent_xenophile_wedding_xenophobe
				years = 5
			}
		}
	}
}



