#########################################
#
# on_action_events
#
#########################################

namespace = action

### First Contact Diplomatic Message
country_event = {
	id = action.1
	title = action.1.name
	message_desc = action.1.message
	location = event_target:contact_empire.capital_scope

	picture_event_data = {
		portrait = event_target:contact_empire
		planet_background = event_target:contact_empire
		graphical_culture = event_target:contact_empire
		city_level = event_target:contact_empire
		room = event_target:contact_empire.ruler
	}

	### Custom First Contact system flavour
	desc = {
		text = action.1.desc_hacking_01
		trigger = {
			event_target:contact_empire = {
				is_homicidal = no
				is_gestalt = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_caught_hacking
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hacking_02
		trigger = {
			event_target:contact_empire = {
				is_homicidal = no
				is_machine_empire = yes
				has_opinion_modifier = {
					who = root
					modifier = opinion_caught_hacking
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hacking_03
		trigger = {
			event_target:contact_empire = {
				is_homicidal = no
				is_hive_empire = yes
				has_opinion_modifier = {
					who = root
					modifier = opinion_caught_hacking
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_01
		trigger = {
			event_target:contact_empire = {
				is_pacifist = no
				is_xenophile = no
				OR = {
					is_xenophobe = no
					is_same_species = root
				}
				is_gestalt = no
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_02
		trigger = {
			event_target:contact_empire = {
				OR = {
					is_pacifist = yes
					is_xenophile = yes
				}
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_03
		trigger = {
			event_target:contact_empire = {
				is_machine_empire = yes
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_04
		trigger = {
			event_target:contact_empire = {
				is_hive_empire = yes
				is_wilderness_empire = no
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_05
		trigger = {
			event_target:contact_empire = {
				is_xenophobe = yes
				is_homicidal = no
				is_pacifist = no
				NOT = { is_same_species = root }
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_06
		trigger = {
			event_target:contact_empire = {
				is_wilderness_empire = yes
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact
				}
			}
		}
	}
	desc = {
		text = action.1.desc_they_hostile_01
		trigger = {
			event_target:contact_empire = {
				is_gestalt = no
			}
			has_opinion_modifier = {
				who = event_target:contact_empire
				modifier = opinion_hostile_first_contact_vivisection
			}
		}
	}
	desc = {
		text = action.1.desc_they_hostile_02
		trigger = {
			event_target:contact_empire = {
				is_machine_empire = yes
			}
			has_opinion_modifier = {
				who = event_target:contact_empire
				modifier = opinion_hostile_first_contact_vivisection
			}
		}
	}
	desc = {
		text = action.1.desc_they_hostile_03
		trigger = {
			event_target:contact_empire = {
				is_hive_empire = yes
			}
			has_opinion_modifier = {
				who = event_target:contact_empire
				modifier = opinion_hostile_first_contact_vivisection
			}
		}
	}
	desc = {
		text = action.1.desc_vivisection_01
		trigger = {
			event_target:contact_empire = {
				is_pacifist = no
				is_machine_empire = no
				is_hive_empire = no
				is_homicidal = no
				is_individual_machine = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact_vivisection
				}
			}
		}
	}
	desc = {
		text = action.1.desc_vivisection_02
		trigger = {
			event_target:contact_empire = {
				is_pacifist = yes
				is_machine_empire = no
				is_hive_empire = no
				is_homicidal = no
				is_individual_machine = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact_vivisection
				}
			}
		}
	}
	desc = {
		text = action.1.desc_vivisection_03
		trigger = {
			event_target:contact_empire = {
				OR = {
					is_machine_empire = yes
					is_individual_machine = yes
				}
				is_hive_empire = no
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact_vivisection
				}
			}
		}
	}
	desc = {
		text = action.1.desc_vivisection_04
		trigger = {
			event_target:contact_empire = {
				is_hive_empire = yes
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact_vivisection
				}
			}
		}
	}
	desc = {
		text = action.1.desc_they_vivisect_01
		trigger = {
			is_synthetic_empire = no
			has_opinion_modifier = {
				who = event_target:contact_empire
				modifier = opinion_hostile_first_contact_vivisection
			}
		}
	}
	desc = {
		text = action.1.desc_they_vivisect_02
		trigger = {
			is_synthetic_empire = yes
			has_opinion_modifier = {
				who = event_target:contact_empire
				modifier = opinion_hostile_first_contact_vivisection
			}
		}
	}
	desc = {
		text = action.1.desc_hungry_01
		trigger = {
			event_target:contact_empire = {
				is_pacifist = no
				is_lithoid = no
				is_machine_empire = no
				is_individual_machine = no
				is_hive_empire = no
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact_hungry
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hungry_02
		trigger = {
			event_target:contact_empire = {
				is_pacifist = yes
				is_lithoid = no
				is_hive_empire = no
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact_hungry
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hungry_03
		trigger = {
			event_target:contact_empire = {
				OR = {
					is_machine_empire = yes
					is_individual_machine = yes
				}
				is_lithoid = no
				is_hive_empire = no
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact_hungry
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hungry_04
		trigger = {
			event_target:contact_empire = {
				is_lithoid = yes
				is_hive_empire = no
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact_hungry
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hungry_05
		trigger = {
			event_target:contact_empire = {
				is_hive_empire = yes
				is_homicidal = no
				has_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_contact_hungry
				}
			}
		}
	}
	desc = {
		text = action.1.desc_they_hungry_01
		trigger = {
			is_synthetic_empire = no
			has_opinion_modifier = {
				who = event_target:contact_empire
				modifier = opinion_hostile_first_contact_hungry
			}
		}
	}
	desc = {
		text = action.1.desc_they_hungry_02
		trigger = {
			is_synthetic_empire = yes
			has_opinion_modifier = {
				who = event_target:contact_empire
				modifier = opinion_hostile_first_contact_hungry
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_to_homicidal_01
		trigger = {
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				has_valid_civic = civic_fanatic_purifiers
				OR = {
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_hungry
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_vivisection
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact
					}
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_to_homicidal_02
		trigger = {
			NOR = {
				is_individual_machine = yes
				is_machine_empire = yes
			}
			event_target:contact_empire = {
				has_valid_civic = civic_machine_terminator
				OR = {
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_hungry
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_vivisection
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact
					}
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_to_homicidal_03
		trigger = {
			OR = {
				is_individual_machine = yes
				is_machine_empire = yes
			}
			event_target:contact_empire = {
				has_valid_civic = civic_machine_terminator
				OR = {
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_hungry
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_vivisection
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact
					}
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_to_homicidal_04
		trigger = {
			event_target:contact_empire = {
				has_valid_civic = civic_hive_devouring_swarm
				OR = {
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_hungry
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_vivisection
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact
					}
				}
			}
		}
	}
	desc = {
		text = action.1.desc_hostile_to_homicidal_05
		trigger = {
			is_same_species = event_target:contact_empire
			event_target:contact_empire = {
				has_valid_civic = civic_fanatic_purifiers
				OR = {
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_hungry
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact_vivisection
					}
					has_opinion_modifier = {
						who = root
						modifier = opinion_hostile_first_contact
					}
				}
			}
		}
	}


	### Normal (Not Xenophobe or Xenophile)
	# Militarist Autocrat (Nomadic)
	desc = {
		text = action.1.desc_01_nomadic
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = yes
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_star_empire
					has_government = gov_military_dictatorship
					has_government = gov_martial_empire
					has_government = gov_martial_dictatorship
					has_government = gov_band_blood
				}
			}
		}
	}
	# Militarist Autocrat
	desc = {
		text = action.1.desc_01
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = no
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_star_empire
					has_government = gov_military_dictatorship
					has_government = gov_martial_empire
					has_government = gov_martial_dictatorship
					has_government = gov_band_blood
				}
			}
		}
	}
	# Spiritualist Autocrat (Nomadic)
	desc = {
		text = action.1.desc_02_nomadic
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = yes
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_theocratic_monarchy
					has_government = gov_theocratic_dictatorship
					has_government = gov_divine_empire
					has_government = gov_sacrificial_megachurch
					has_government = gov_mortal_empire
				}
			}
		}
	}
	# Spiritualist Autocrat
	desc = {
		text = action.1.desc_02
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = no
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_theocratic_monarchy
					has_government = gov_theocratic_dictatorship
					has_government = gov_divine_empire
					has_government = gov_sacrificial_megachurch
					has_government = gov_mortal_empire
				}
			}
		}
	}
	# Materialist Autocrat
	desc = {
		text = action.1.desc_03
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_despotic_hegemony
					has_government = gov_totalitarian_regime
					has_government = gov_illuminated_autocracy
					has_government = gov_technocratic_dictatorship
				}
			}
		}
	}
	# Pacifist Autocrat
	desc = {
		text = action.1.desc_04
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_irenic_monarchy
					has_government = gov_irenic_dictatorship
					has_government = gov_celestial_empire
				}
			}
		}
	}
	# Generic Autocrat
	desc = {
		text = action.1.desc_05
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_despotic_empire
					has_government = gov_feudal_empire
					has_government = gov_constitutional_dictatorship
					has_government = gov_enlightened_monarchy
					has_government = gov_elective_monarchy
				}
			}
		}
	}
	# Military Oligarch
	desc = {
		text = action.1.desc_06
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_military_junta
					has_government = gov_war_council
					has_government = gov_citizen_stratocracy
				}
			}
		}
	}
	# Spiritualist Oligarch
	desc = {
		text = action.1.desc_07
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_theocratic_oligarchy
					has_government = gov_holy_tribunal
					has_government = gov_grim_council
				}
			}
		}
	}
	# Materialist Oligarch
	desc = {
		text = action.1.desc_08
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_executive_committee
					has_government = gov_science_directorate
				}
			}
		}
	}
	# Pacifist Oligarch
	desc = {
		text = action.1.desc_09
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
					AND = {
						exists = event_target:ratling_country
						is_same_value = event_target:ratling_country
					}
				}
				has_government = gov_irenic_bureaucracy
			}
		}
	}
	# Generic Oligarch
	desc = {
		text = action.1.desc_10
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_megacorporation
					has_government = gov_plutocratic_oligarchy
				}
			}
		}
	}
	# Militarist Democrat
	desc = {
		text = action.1.desc_11
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_military_commissariat
					has_government = gov_assembly_of_clans
					has_government = gov_citizen_republic
				}
			}
		}
	}
	# Spiritualist Democrat
	desc = {
		text = action.1.desc_12
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				has_government = gov_theocratic_republic
			}
		}
	}
	# Materialist Democrat
	desc = {
		text = action.1.desc_13
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				OR = {
					has_government = gov_direct_democracy
					has_government = gov_rational_consensus
				}
			}
		}
	}
	# Pacifist Democrat
	desc = {
		text = action.1.desc_14
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				has_government = gov_moral_democracy
			}
		}
	}
	# Generic Democrat
	desc = {
		text = action.1.desc_15
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				NOR = {
					has_country_flag = special_intro_for@root
					is_xenophobe = yes
					is_xenophile = yes
				}
				has_government = gov_representative_democracy
			}
		}
	}

	### Xenophobe
	# Militarist Autocrat (Nomadic)
	desc = {
		text = action.1.desc_16_nomadic
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = yes
				is_xenophobe = yes
				OR = {
					has_government = gov_star_empire
					has_government = gov_military_dictatorship
					has_government = gov_martial_empire
					has_government = gov_martial_dictatorship
					has_government = gov_band_blood
				}
				NOR = {
					has_country_flag = special_intro_for@root
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
				}
			}
		}
	}
	# Militarist Autocrat
	desc = {
		text = action.1.desc_16
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = no
				is_xenophobe = yes
				OR = {
					has_government = gov_star_empire
					has_government = gov_military_dictatorship
					has_government = gov_martial_empire
					has_government = gov_martial_dictatorship
					has_government = gov_band_blood
				}
				NOR = {
					has_country_flag = special_intro_for@root
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
				}
			}
		}
	}
	# Spiritualist Autocrat (Nomadic)
	desc = {
		text = action.1.desc_17_nomadic
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = yes
				is_xenophobe = yes
				OR = {
					has_government = gov_theocratic_monarchy
					has_government = gov_theocratic_dictatorship
					has_government = gov_divine_empire
					has_government = gov_sacrificial_megachurch
					has_government = gov_mortal_empire
				}
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_country_flag = special_intro_for@root
				}
			}
		}
	}
	# Spiritualist Autocrat
	desc = {
		text = action.1.desc_17
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = no
				is_xenophobe = yes
				OR = {
					has_government = gov_theocratic_monarchy
					has_government = gov_theocratic_dictatorship
					has_government = gov_divine_empire
					has_government = gov_sacrificial_megachurch
					has_government = gov_mortal_empire
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Materialist Autocrat
	desc = {
		text = action.1.desc_18
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				OR = {
					has_government = gov_despotic_hegemony
					has_government = gov_totalitarian_regime
					has_government = gov_illuminated_autocracy
					has_government = gov_technocratic_dictatorship
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Pacifist Autocrat
	desc = {
		text = action.1.desc_19
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				OR = {
					has_government = gov_irenic_monarchy
					has_government = gov_irenic_dictatorship
					has_government = gov_celestial_empire
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Generic Autocrat
	desc = {
		text = action.1.desc_20
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				OR = {
					has_government = gov_despotic_empire
					has_government = gov_feudal_empire
					has_government = gov_constitutional_dictatorship
					has_government = gov_enlightened_monarchy
					has_government = gov_elective_monarchy
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Military Oligarch
	desc = {
		text = action.1.desc_21
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				OR = {
					has_government = gov_military_junta
					has_government = gov_war_council
					has_government = gov_citizen_stratocracy
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Spiritualist Oligarch
	desc = {
		text = action.1.desc_22
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				OR = {
					has_government = gov_theocratic_oligarchy
					has_government = gov_holy_tribunal
					has_government = gov_grim_council
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Materialist Oligarch
	desc = {
		text = action.1.desc_23
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				OR = {
					has_government = gov_executive_committee
					has_government = gov_science_directorate
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Pacifist Oligarch
	desc = {
		text = action.1.desc_24
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				has_government = gov_irenic_bureaucracy
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Generic Oligarch
	desc = {
		text = action.1.desc_25
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				OR = {
					has_government = gov_megacorporation
					has_government = gov_plutocratic_oligarchy
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Militarist Democrat
	desc = {
		text = action.1.desc_26
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				OR = {
					has_government = gov_military_commissariat
					has_government = gov_assembly_of_clans
					has_government = gov_citizen_republic
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Spiritualist Democrat
	desc = {
		text = action.1.desc_27
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				has_government = gov_theocratic_republic
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Materialist Democrat
	desc = {
		text = action.1.desc_28
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				OR = {
					has_government = gov_direct_democracy
					has_government = gov_rational_consensus
				}
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Pacifist Democrat (Nomadic)
	desc = {
		text = action.1.desc_29_nomadic
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = yes
				is_xenophobe = yes
				has_government = gov_moral_democracy
				NOR = {
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_country_flag = special_intro_for@root
				}
			}
		}
	}
	# Pacifist Democrat
	desc = {
		text = action.1.desc_29
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = no
				is_xenophobe = yes
				has_government = gov_moral_democracy
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Generic Democrat
	desc = {
		text = action.1.desc_30
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophobe = yes
				has_government = gov_representative_democracy
				NOT = { has_valid_civic = civic_fanatic_purifiers }
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	### Xenophile
	# Militarist Autocrat
	desc = {
		text = action.1.desc_31
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_star_empire
					has_government = gov_military_dictatorship
					has_government = gov_martial_empire
					has_government = gov_martial_dictatorship
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Spiritualist Autocrat (Nomadic)
	desc = {
		text = action.1.desc_32_nomadic
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = yes
				is_xenophile = yes
				OR = {
					has_government = gov_theocratic_monarchy
					has_government = gov_theocratic_dictatorship
					has_government = gov_divine_empire
					has_government = gov_sacrificial_megachurch
					has_government = gov_mortal_empire
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Spiritualist Autocrat
	desc = {
		text = action.1.desc_32
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_nomadic = no
				is_xenophile = yes
				OR = {
					has_government = gov_theocratic_monarchy
					has_government = gov_theocratic_dictatorship
					has_government = gov_divine_empire
					has_government = gov_sacrificial_megachurch
					has_government = gov_mortal_empire
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Materialist Autocrat
	desc = {
		text = action.1.desc_33
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_despotic_hegemony
					has_government = gov_totalitarian_regime
					has_government = gov_illuminated_autocracy
					has_government = gov_technocratic_dictatorship
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Pacifist Autocrat
	desc = {
		text = action.1.desc_34
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_irenic_monarchy
					has_government = gov_irenic_dictatorship
					has_government = gov_celestial_empire
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Generic Autocrat
	desc = {
		text = action.1.desc_35
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_despotic_empire
					has_government = gov_feudal_empire
					has_government = gov_constitutional_dictatorship
					has_government = gov_enlightened_monarchy
					has_government = gov_elective_monarchy
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Military Oligarch
	desc = {
		text = action.1.desc_36
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_military_junta
					has_government = gov_war_council
					has_government = gov_citizen_stratocracy
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Spiritualist Oligarch
	desc = {
		text = action.1.desc_37
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_theocratic_oligarchy
					has_government = gov_holy_tribunal
					has_government = gov_grim_council
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Materialist Oligarch
	desc = {
		text = action.1.desc_38
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_executive_committee
					has_government = gov_science_directorate
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Pacifist Oligarch
	desc = {
		text = action.1.desc_39
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				has_government = gov_irenic_bureaucracy
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Generic Oligarch
	desc = {
		text = action.1.desc_40
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_megacorporation
					has_government = gov_plutocratic_oligarchy
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Militarist Democrat
	desc = {
		text = action.1.desc_41
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_military_commissariat
					has_government = gov_assembly_of_clans
					has_government = gov_citizen_republic
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Spiritualist Democrat
	desc = {
		text = action.1.desc_42
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			is_individual_machine = no
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				has_government = gov_theocratic_republic
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Materialist Democrat
	desc = {
		text = action.1.desc_43
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				OR = {
					has_government = gov_direct_democracy
					has_government = gov_rational_consensus
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Pacifist Democrat
	desc = {
		text = action.1.desc_44
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				has_government = gov_moral_democracy
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}
	# Generic Democrat
	desc = {
		text = action.1.desc_45
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_xenophile = yes
				has_government = gov_representative_democracy
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Cruel Foxcat
	desc = {
		text = action.1.desc_49
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				has_valid_civic = civic_fanatic_purifiers
				species_portrait = mam3
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Hive Mind
	desc = {
		text = action.1.desc_50
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_hive_empire = yes
				NOR = {
					has_valid_civic = civic_hive_devouring_swarm
					has_country_flag = special_intro_for@root
					is_wilderness_empire = yes
				}
			}
		}
	}

	# Wilderness
	desc = {
		text = action.1.desc_53
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_wilderness_empire = yes
				NOT = { has_country_flag = special_intro_for@root } # unlikely, but failsafe
			}
		}
	}

	# Fanatic Purifier
	desc = {
		text = action.1.desc_51
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				has_valid_civic = civic_fanatic_purifiers
				NAND = {
					has_valid_civic = civic_fanatic_purifiers
					species_portrait = mam3
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Devouring Swarm
	desc = {
		text = action.1.desc_52
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_hive_empire = yes
				has_valid_civic = civic_hive_devouring_swarm
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}


	# Generic Machine Empire (To Organics)
	desc = {
		text = action.1.desc_70
		trigger = {
			first_contact_custom_greeting = no
			NOR = {
				is_same_species = event_target:contact_empire
				is_machine_empire = yes
				is_individual_machine = yes
				has_country_flag = synthetic_empire
			}
			event_target:contact_empire = {
				is_country_type = default
				OR = {
					has_government = gov_machine_empire
					has_government = gov_machine_research
					has_government = gov_machine_industrial
				}
				NOT = { has_country_flag = special_intro_for@root }
				is_individual_machine = no
			}
		}
	}

	# Generic Machine Empire (To Machines)
	desc = {
		text = action.1.desc_71
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			OR = {
				is_machine_empire = yes
				is_individual_machine = yes
				has_country_flag = synthetic_empire
			}
			event_target:contact_empire = {
				is_country_type = default
				OR = {
					has_government = gov_machine_empire
					has_government = gov_machine_research
					has_government = gov_machine_industrial
				}
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Terminator Machine Empire (To Organics)
	desc = {
		text = action.1.desc_72
		trigger = {
			first_contact_custom_greeting = no
			NOR = {
				is_same_species = event_target:contact_empire
				is_machine_empire = yes
				is_individual_machine = yes
				has_country_flag = synthetic_empire
			}
			event_target:contact_empire = {
				is_country_type = default
				has_government = gov_machine_terminator
				NOT = { has_country_flag = special_intro_for@root }
				is_individual_machine = no
			}
		}
	}

	# Terminator Machine Empire (To Machines)
	desc = {
		text = action.1.desc_73
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			OR = {
				is_machine_empire = yes
				is_individual_machine = yes
				has_country_flag = synthetic_empire
			}
			event_target:contact_empire = {
				is_country_type = default
				has_government = gov_machine_terminator
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Assimilator Machine Empire (To Organics)
	desc = {
		text = action.1.desc_74
		trigger = {
			first_contact_custom_greeting = no
			NOR = {
				is_same_species = event_target:contact_empire
				is_machine_empire = yes
				is_individual_machine = yes
				has_country_flag = synthetic_empire
			}
			event_target:contact_empire = {
				is_country_type = default
				has_government = gov_machine_assimilator
				NOT = { has_country_flag = special_intro_for@root }
				is_individual_machine = no
			}
		}
	}

	# Assimilator Machine Empire (To Machines)
	desc = {
		text = action.1.desc_75
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			OR = {
				is_machine_empire = yes
				is_individual_machine = yes
				has_country_flag = synthetic_empire
			}
			event_target:contact_empire = {
				is_country_type = default
				has_government = gov_machine_assimilator
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Servitor Machine Empire (To Organics)
	desc = {
		text = action.1.desc_76
		trigger = {
			first_contact_custom_greeting = no
			NOR = {
				is_same_species = event_target:contact_empire
				is_machine_empire = yes
				has_country_flag = synthetic_empire
				is_individual_machine = yes
			}
			event_target:contact_empire = {
				is_country_type = default
				has_government = gov_machine_servitor
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Servitor Machine Empire (To Machines)
	desc = {
		text = action.1.desc_77
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			OR = {
				is_machine_empire = yes
				has_country_flag = synthetic_empire
				is_individual_machine = yes
			}
			event_target:contact_empire = {
				is_country_type = default
				has_government = gov_machine_servitor
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	#Fallen Machine Empire (To Organics)
	desc = {
		text = action.1.desc_78
		trigger = {
			first_contact_custom_greeting = no
			NOR = {
				is_same_species = event_target:contact_empire
				is_machine_empire = yes
				has_country_flag = synthetic_empire
				is_individual_machine = yes
			}
			event_target:contact_empire = {
				is_country_type = fallen_empire
				is_machine_empire = yes
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Fallen Machine Empire (To Machines)
	desc = {
		text = action.1.desc_79
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			OR = {
				is_machine_empire = yes
				has_country_flag = synthetic_empire
				is_individual_machine = yes
			}
			event_target:contact_empire = {
				is_country_type = fallen_empire
				is_machine_empire = yes
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Junkheap Ratlings Empire (To those who have taken their systems)
	desc = {
		text = "action.1.desc_80"
		trigger = {
			first_contact_custom_greeting = no
			NOT = { is_same_species = event_target:contact_empire }
			exists = event_target:ratling_country
			event_target:contact_empire = {
				is_same_value = event_target:ratling_country
			}
			any_system_within_border = {
				has_star_flag = ratling_system
			}
		}
	}

	# Junkheap Ratlings Empire (To those who have not taken their systems)
	desc = {
		text = "action.1.desc_81"
		trigger = {
			first_contact_custom_greeting = no
			exists = event_target:ratling_country
			event_target:contact_empire = {
				is_same_value = event_target:ratling_country
			}
			NOR = {
				is_same_species = event_target:contact_empire
				any_system_within_border = {
					has_star_flag = ratling_system
				}
			}
		}
	}

	# Fallen Empire 1
	desc = {
		text = action.1.desc_60
		trigger = {
			event_target:contact_empire = {
				is_country_type = fallen_empire
				NOT = { has_ethic = ethic_gestalt_consciousness }
				NOT = { has_ethic = ethic_fanatic_xenophobe }
				is_fanatic_xenophile = no
				is_fanatic_materialist = no
				is_fanatic_spiritualist = no
			}
		}
	}
	# Fallen Empire 2
	desc = {
		text = action.1.desc_62
		trigger = {
			event_target:contact_empire = {
				is_country_type = fallen_empire
				is_fanatic_xenophile = yes
			}
		}
	}
	# Fallen Empire 3
	desc = {
		text = action.1.desc_63
		trigger = {
			event_target:contact_empire = {
				is_country_type = fallen_empire
				has_ethic = ethic_fanatic_xenophobe
			}
		}
	}
	# Fallen Empire 4
	desc = {
		text = action.1.desc_64
		trigger = {
			event_target:contact_empire = {
				is_country_type = fallen_empire
				is_fanatic_materialist = yes
			}
		}
	}
	# Fallen Empire 5
	desc = {
		text = action.1.desc_65
		trigger = {
			event_target:contact_empire = {
				is_country_type = fallen_empire
				is_fanatic_spiritualist = yes
			}
			NOR = {
				has_origin = origin_cybernetic_creed
				is_individual_machine = yes
			 }
		}
	}
	# Fallen Empire 6 (Cybernetic Creed)
	desc = {
		text = action.1.desc_111
		trigger = {
			event_target:contact_empire = {
				is_country_type = fallen_empire
				is_fanatic_spiritualist = yes
			}
			has_origin = origin_cybernetic_creed
		}
	}
	# Fallen Empire 7 (Individual Machine)
	desc = {
		text = action.1.desc_107
		trigger = {
			event_target:contact_empire = {
				is_country_type = fallen_empire
				is_fanatic_spiritualist = yes
			}
			NOT = { has_origin = origin_cybernetic_creed }
			is_individual_machine = yes
			is_spiritualist = no
		}
	}
	# Fallen Empire 8 (Individual Machine)
	desc = {
		text = action.1.desc_108
		trigger = {
			event_target:contact_empire = {
				is_country_type = fallen_empire
				is_fanatic_spiritualist = yes
			}
			is_individual_machine = yes
			is_spiritualist = yes
		}
	}
	# Fallen Hive Empire
	desc = {
		text = action.1.desc_109
		trigger = {
			event_target:contact_empire = {
				is_country_type = fallen_empire
				is_hive_empire = yes
			}
		}
	}
	# Awakened Fallen Empire 1
	desc = {
		text = action.1.desc_66
		trigger = {
			event_target:contact_empire = {
				is_country_type = awakened_fallen_empire
				is_fanatic_spiritualist = yes
			}
			NOR = {
				has_origin = origin_cybernetic_creed
				is_individual_machine = yes
			}
		}
	}
	# Awakened Fallen Empire 2
	desc = {
		text = action.1.desc_67
		trigger = {
			event_target:contact_empire = {
				is_country_type = awakened_fallen_empire
				is_fanatic_xenophile = yes
			}
		}
	}
	# Awakened Fallen Empire 3
	desc = {
		text = action.1.desc_68
		trigger = {
			event_target:contact_empire = {
				is_country_type = awakened_fallen_empire
				has_ethic = ethic_fanatic_xenophobe
			}
		}
	}
	# Awakened Fallen Empire 4
	desc = {
		text = action.1.desc_69
		trigger = {
			event_target:contact_empire = {
				is_country_type = awakened_fallen_empire
				is_fanatic_materialist = yes
			}
		}
	}
	# Awakened Fallen Empire 5 (Cybernetic Creed)
	desc = {
		text = action.1.desc_110
		trigger = {
			event_target:contact_empire = {
				is_country_type = awakened_fallen_empire
				is_fanatic_spiritualist = yes
			}
			OR = {
				has_origin = origin_cybernetic_creed
				is_individual_machine = yes
			}
		}
	}

	# Lost Colony Greetings (Generic)
	desc = {
		text = "action.1.desc_82"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				has_generic_government = yes
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_individual_machine = no
		}
	}

	# Lost Colony Greetings (Spiritualist)
	desc = {
		text = "action.1.desc_83"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				has_spiritualist_government = yes
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_individual_machine = no
		}
	}

	# Lost Colony Greetings (Militarist)
	desc = {
		text = "action.1.desc_84"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				has_militarist_government = yes
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_individual_machine = no
		}
	}

	# Lost Colony Greetings (Pacifist)
	desc = {
		text = "action.1.desc_85"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				has_pacifist_government = yes
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_individual_machine = no
		}
	}

	# Lost Colony Greetings (Materialist)
	desc = {
		text = "action.1.desc_86"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				has_materialist_government = yes
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_individual_machine = no
		}
	}

	# Lost Colony Greetings (MegaCorp)
	desc = {
		text = "action.1.desc_87"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				is_megacorp = yes
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_individual_machine = no
		}
	}

	# Lost Colony Greetings (Purifiers)
	desc = {
		text = "action.1.desc_88"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				has_valid_civic = civic_fanatic_purifiers
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
		}
	}

	# UNE to CoM
	desc = {
		text = "action.1.desc_89"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				#has_country_flag = lost_colony_parent_of@root
				has_country_flag = human_1
			}
			has_country_flag = human_2
			has_origin = origin_lost_colony
		}
	}

	# CoM to UNE
	desc = {
		text = "action.1.desc_90"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = human_2
			}
			has_country_flag = human_1
		}
	}

	# UNE to GRS
	desc = {
		text = "action.1.desc_112"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = human_1
			}
			has_country_flag = human_3
			has_origin = origin_lost_colony
		}
	}

	# GRS to UNE
	desc = {
		text = "action.1.desc_113"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				has_country_flag = special_intro_for@root
				has_country_flag = human_3
			}
			has_country_flag = human_1
		}
	}

	# MSI to Payback
	desc = {
		text = "action.1.desc_91"
		trigger = {
			first_contact_custom_greeting = yes
			NOT = { is_same_species = event_target:contact_empire }
			has_origin = origin_payback
			event_target:contact_empire = {
				is_country_type = default
				has_origin = origin_slavers
				has_country_flag = special_intro_for@root
			}
		}
	}

	# MSI to Broken Shackles
	desc = {
		text = "action.1.desc_92"
		trigger = {
			first_contact_custom_greeting = yes
			NOT = { is_same_species = event_target:contact_empire }
			has_origin = origin_broken_shackles
			event_target:contact_empire = {
				is_country_type = default
				has_origin = origin_slavers
				has_country_flag = special_intro_for@root
			}
		}
	}

	# MSI to other empires
	desc = {
		text = "action.1.desc_93"
		trigger = {
			first_contact_custom_greeting = yes
			NOR = {
				is_same_species = event_target:contact_empire
				has_slave_origin = yes
			}
			event_target:contact_empire = {
				is_country_type = default
				has_origin = origin_slavers
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Lost Colony Greetings (Hive)
	desc = {
		text = "action.1.desc_94"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				is_country_type = default
				is_hive_empire = yes
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
			}
			has_origin = origin_lost_colony
			is_hive_empire = yes
		}
	}

	# Lost Colony Greetings (Devouring Swarm)
	desc = {
		text = "action.1.desc_95"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				is_country_type = default
				is_hive_empire = yes
				has_valid_civic = civic_hive_devouring_swarm
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
			}
			has_origin = origin_lost_colony
			is_hive_empire = yes
		}
	}

	# Lost Colony Greetings (Machines)
	desc = {
		text = "action.1.desc_96"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				is_country_type = default
				is_machine_empire = yes
				NOT = { has_valid_civic = civic_machine_terminator }
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_machine_empire = yes
		}
	}

	# Lost Colony Greetings (Exterminators)
	desc = {
		text = "action.1.desc_97"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				is_country_type = default
				is_machine_empire = yes
				has_valid_civic = civic_machine_terminator
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_machine_empire = yes
		}
	}

	# Lost Colony Greetings (Assimilators)
	desc = {
		text = "action.1.desc_98"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				is_country_type = default
				is_machine_empire = yes
				has_valid_civic = civic_machine_assimilator
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_machine_empire = yes
		}
	}

	# Lost Colony Greetings (Individualistic Machines)
	desc = {
		text = "action.1.desc_101"
		trigger = {
			first_contact_custom_greeting = no
			event_target:contact_empire = {
				is_country_type = default
				is_individual_machine = yes
				has_country_flag = special_intro_for@root
				has_country_flag = lost_colony_parent_of@root
				is_human_prescripted_empire = no
			}
			has_origin = origin_lost_colony
			is_individual_machine = yes
		}
	}

	# FTP to UNE
	desc = {
		text = "action.1.desc_99"
		trigger = {
			first_contact_custom_greeting = yes
			event_target:contact_empire = {
				has_country_flag = human_lithoid
				species_portrait = lith_human
			}
			has_country_flag = human_1
		}
	}

	# UNE to FTP
	desc = {
		text = "action.1.desc_100"
		trigger = {
			first_contact_custom_greeting = yes
			event_target:contact_empire = {
				has_country_flag = human_1
			}
			has_country_flag = human_lithoid
			species_portrait = lith_human
		}
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		event_target:contact_empire = {
			NOR = {
				is_tiyanki_country_type = yes
				is_country_type = neutral_faction
				is_country_type = faction
				is_country_type = pirate
				#is_country_type = nomad #triggered in a special case event
				is_amoeba_country_type = yes
				is_drone_country_type = yes
				is_crystal_country_type = yes
				is_country_type = cloud
				is_country_type = enclave
				has_relation_flag = { flag = AbandonedRefugees who = root }
				has_country_flag = second_hive_fe_fragment
				has_country_flag = third_hive_fe_fragment
			}
		}
	}

	# Spiritualist to IM
	desc = {
		text = "action.1.desc_102"
		trigger = {
			first_contact_custom_greeting = no
			is_individual_machine = yes
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_fanatic_spiritualist = yes
				is_individual_machine = no
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Spiritualists to spiritualist IM
	desc = {
		text = "action.1.desc_103"
		trigger = {
			first_contact_custom_greeting = no
			is_spiritualist = yes
			is_individual_machine = yes
			NOT = { is_same_species = event_target:contact_empire }
			event_target:contact_empire = {
				is_country_type = default
				is_fanatic_spiritualist = yes
				is_individual_machine = no
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# Machine Empires to IM
	desc = {
		text = "action.1.desc_104"
		trigger = {
			first_contact_custom_greeting = no
			is_individual_machine = yes
			event_target:contact_empire = {
				is_country_type = default
				is_machine_empire = yes
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# IM to Machine Empires
	desc = {
		text = "action.1.desc_105"
		trigger = {
			first_contact_custom_greeting = no
			is_machine_empire = yes
			event_target:contact_empire = {
				is_country_type = default
				is_individual_machine = yes
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	# IM to IM
	desc = {
		text = "action.1.desc_106"
		trigger = {
			first_contact_custom_greeting = no
			is_individual_machine = yes
			event_target:contact_empire = {
				is_country_type = default
				is_individual_machine = yes
				NOT = { has_country_flag = special_intro_for@root }
			}
		}
	}

	immediate = {
		if = {
			limit = { event_target:contact_empire = { is_country_type = default } }
			country_event = { id = tutorial.2006 } #"First Contact Established" (regular version)
		}
		else = {
			country_event = { id = tutorial.2007 } #"First Contact Established" (Marauder/FE version)
		}
		country_event = { id = anomaly.4016 }
		event_target:contact_empire = {
			save_event_target_as = contact_speaker
		}
		if = {
			limit = {
				event_target:contact_empire = {
					has_origin = origin_fallen_empire_hive
				}
			}
			establish_communications_no_message = event_target:fallen_empire_hive_war
			establish_communications_no_message = event_target:fallen_empire_hive_growth
			establish_communications_no_message = event_target:fallen_empire_hive_control
			if = {
				limit = {
					event_target:contact_empire = {
						has_country_flag = fallen_empire_hive_war
					}
				}
				set_country_flag = fe_hive_growth_second
				set_country_flag = fe_hive_control_third
			}
			else_if = {
				limit = {
					event_target:contact_empire = {
						has_country_flag = fallen_empire_hive_growth
					}
				}
				set_country_flag = fe_hive_war_second
				set_country_flag = fe_hive_control_third
			}
			else = {
				set_country_flag = fe_hive_war_second
				set_country_flag = fe_hive_growth_third
			}
		}
	}

	# For the event options:
	#	- Note 1: If multiple of the triggered option names return true, it'll pick a random one among those that are available.
	#	- Note 2: If none of them return true, it will pick the first one in the list. So it should be something suitably generic.

	option = { #friendly
		name = {
			text = action.1.selective
			trigger = {
				has_valid_civic = civic_selective_kinship
				event_target:contact_empire = {
					is_same_species_class = root
				}
			}
		}
		name = {
			text = action.1.u4
			exclusive_trigger = {
				has_slave_origin = yes
				event_target:contact_empire = { has_origin = origin_slavers }
			}
		}
		name = {
			text = action.1.e
			trigger = {
				NOT = { is_same_species = event_target:contact_empire }
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.c
			trigger = {
				NOT = { is_same_species = event_target:contact_empire }
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.h
			trigger = {
				is_egalitarian = yes
			}
		}
		name = {
			text = action.1.n
			trigger = {
				is_spiritualist = yes
				event_target:contact_empire = {
					NOR = {
						is_machine_empire = yes
						is_individual_machine = yes
					}
				}
			}
		}
		name = {
			text = action.1.ag
			trigger = {
				is_materialist = yes
			}
		}
		name = {
			text = action.1.ah
			trigger = {
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.ai
			trigger = {
				is_xenophile = yes
				is_egalitarian = yes
			}
		}
		name = {
			text = action.1.aj
			trigger = {
				is_xenophile = yes
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.ak
			trigger = {
				OR = {
					is_xenophile = yes
					is_militarist = yes
				}
			}
		}
		name = {
			text = action.1.al
			trigger = {
				is_egalitarian = yes
			}
		}
		name = {
			text = action.1.am
			trigger = {
				is_spiritualist = yes
				is_individual_machine = no
			}
		}
		name = {
			text = action.1.j
			trigger = {
				is_militarist = yes
			}
		}
		name = {
			text = action.1.l
			trigger = {
				is_pacifist = yes
			}
		}
		name = {
			text = action.1.p
			trigger = {
				is_materialist = yes
			}
		}
		name = {
			text = action.1.av
			trigger = {
				is_spiritualist = yes
			}
		}
		name = {
			text = action.1.aag
			trigger = {
				has_origin = origin_lost_colony
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
				}
			}
		}
		name = {
			text = action.1.aah
			exclusive_trigger = {
				has_origin = origin_lost_colony
				is_hive_empire = yes
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
				}
			}
		}
		name = {
			text = action.1.aai
			exclusive_trigger = {
				has_origin = origin_lost_colony
				is_machine_empire = yes
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
				}
			}
		}
		name = {
			text = action.1.aam
			exclusive_trigger = {
				has_origin = origin_lost_colony
				is_individual_machine = yes
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
				}
			}
		}
		name = {
			text = action.1.hm
			trigger = {
				is_hive_empire = yes
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
			}
		}
		name = {
			text = action.1.me
			trigger = {
				is_machine_empire = yes
				NOT = { has_valid_civic = civic_machine_terminator }
			}
		}
		name = {
			text = action.1.mtm
			trigger = {
				has_valid_civic = civic_machine_terminator
				event_target:contact_empire = {
					OR = {
						is_individual_machine = yes
						is_machine_empire = yes
					}
				}
			}
		}
		name = {
			text = action.1.o
			trigger = {
				is_spiritualist = yes
				event_target:contact_empire = {
					NOR = {
						is_individual_machine = yes
						is_machine_empire = yes
					}
				}
			}
		}
		name = {
			text = action.1.as
			trigger = {
				is_pacifist = yes
			}
		}
		name = {
			text = action.1.af
			trigger = {
				is_xenophobe = yes
				is_individual_machine = no
			}
		}
		name = {
			text = action.1.va
			exclusive_trigger = {
				has_origin = origin_payback
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_origin = origin_slavers
				}
			}
		}
		name = {
			text = action.1.vd
			exclusive_trigger = {
				has_origin = origin_broken_shackles
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_origin = origin_slavers
				}
			}
		}
		name = { # IM, spiritualist
			text = action.1.xa
			trigger = {
				is_spiritualist = no
				is_individual_machine = yes
				event_target:contact_empire = {
					is_spiritualist = yes
					is_individual_machine = no
				}
			}
		}
		name = { # Spiritualist, spiritualist IM
			text = action.1.xb
			trigger = {
				is_spiritualist = yes
				is_individual_machine = no
				event_target:contact_empire = {
					is_spiritualist = yes
					is_individual_machine = yes
				}
			}
		}
		name = { # IM, machine empire
			text = action.1.xd
			trigger = {
				is_individual_machine = yes
				event_target:contact_empire = {
					OR = {
						is_machine_empire = yes
						is_individual_machine = yes
					}
				}
			}
		}

		icon = {
			icon = GFX_option_icon_friendly
			text = seek_friends_tt
		}

		allow = {
			custom_tooltip_fail = {
				text = friendship_already_precluded
				event_target:contact_empire = {
					NOR = {
						has_opinion_modifier = {
							who = root
							modifier = opinion_caught_hacking
						}
						has_opinion_modifier = {
							who = root
							modifier = opinion_hostile_first_contact
						}
						has_opinion_modifier = {
							who = root
							modifier = opinion_hostile_first_contact_vivisection
						}
						has_opinion_modifier = {
							who = root
							modifier = opinion_hostile_first_contact_hungry
						}
						AND = {
							has_origin = origin_slavers
							has_country_flag = special_intro_for@root
						}
					}
				}
			}
		}

		if = {
			limit = {
				OR = {
					NOT = { is_country_type = default }
					event_target:contact_empire = { is_country_type = fallen_empire }
				}
			}
			custom_tooltip = action.1.fe_option
		}
		else = {
			custom_tooltip = seek_friends_tt

			event_target:contact_empire = {
				add_opinion_modifier = {
					who = root
					modifier = opinion_friendly_first_comms_greeting
				}
			}
		}
		if = {
			limit = {
				OR = {
					has_country_flag = human_1
					has_country_flag = human_lithoid
				}
				event_target:contact_empire = {
					OR = {
						has_country_flag = human_1
						has_country_flag = human_lithoid
					}
				}
			}
			event_target:contact_empire = {
				add_opinion_modifier = {
					who = root
					modifier = opinion_pre_hadean_relations
				}
			}
		}

		trigger = {
			OR = {
				is_homicidal = no
				AND = {
					has_valid_civic = civic_machine_terminator
					event_target:contact_empire = {
						OR = {
							is_individual_machine = yes
							is_machine_empire = yes
						}
					}
				}
			}
			NAND = {
				has_valid_civic = civic_selective_kinship
				event_target:contact_empire = { NOT = { is_same_species_class = root } }
			}
			NOT = { has_valid_civic = civic_inwards_perfection }
			NAND = {
				is_fanatic_spiritualist = yes
				event_target:contact_empire = {
					OR = {
						is_machine_empire = yes
						AND = {
							is_individual_machine = yes
							is_spiritualist = no
						}
					}
				}
			}
			OR = {
				is_fanatic_xenophobe = no
				event_target:contact_empire = { is_same_species = root }
				AND = {
					has_valid_civic = civic_selective_kinship
					event_target:contact_empire = { is_same_species_class = root.species }
				}
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				is_xenophile = yes
			}
			modifier = {
				factor = 0.5
				OR = {
					is_xenophobe = yes
					is_gestalt = yes
				}
			}
			modifier = {
				factor = 4 #actually *2 as it is multiplied by *0.5 in the above modifier
				OR = {
					AND = {
						is_machine_empire = yes
						event_target:contact_empire = { is_machine_empire = yes }
					}
					AND = {
						is_hive_empire = yes
						event_target:contact_empire = { is_hive_empire = yes }
					}
				}
			}
			modifier = {
				factor = 0.1
				first_contact_custom_greeting = yes #basically, various hostility
			}
		}
	}
	option = { #hostile - isolationist
		name = {
			text = action.1.u5
			exclusive_trigger = {
				has_slave_origin = yes
				event_target:contact_empire = { has_origin = origin_slavers }
			}
		}
		name = {
			text = action.1.ac
			trigger = {
				is_xenophobe = yes
			}
		}
		name = {
			text = action.1.aab
			trigger = {
				OR = {
					is_xenophobe = yes
					is_materialist = yes
				}
				NOT = { is_same_species = event_target:contact_empire }
			}
		}
		name = {
			text = action.1.ad
			trigger = {
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.d
			trigger = {
				NOT = { is_same_species = event_target:contact_empire }
				is_xenophobe = yes
			}
		}
		name = {
			text = action.1.i
			trigger = {
				is_egalitarian = yes
			}
		}
		name = {
			text = action.1.m
			trigger = {
				is_pacifist = yes
			}
		}
		name = {
			text = action.1.r
			trigger = {
				is_spiritualist = yes
				event_target:contact_empire = {
					OR = {
						is_machine_empire = yes
						is_individual_machine = yes
					}
				}
			}
		}
		name = {
			text = action.1.aa
			trigger = {
				is_materialist = yes
			}
		}
		name = {
			text = action.1.ao
			trigger = {
				is_militarist = yes
			}
		}
		name = {
			text = action.1.aaa
			trigger = {
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.aae
			trigger = {
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.t1
			trigger = {
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.t2
			trigger = {
				is_spiritualist = yes
			}
		}
		name = {
			text = action.1.t3
			trigger = {
				is_hive_empire = yes
			}
		}
		name = {
			text = action.1.t4
			trigger = {
				is_machine_empire = yes
				NOR = {
					has_valid_civic = civic_machine_assimilator
					has_valid_civic = civic_machine_terminator
				}
			}
		}
		name = {
			text = action.1.t5
			trigger = {
				has_valid_civic = civic_machine_assimilator
			}
		}
		name = {
			text = action.1.t6
			trigger = {
				has_valid_civic = civic_machine_terminator
			}
		}
		name = {
			text = action.1.vb
			exclusive_trigger = {
				has_origin = origin_payback
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_origin = origin_slavers
				}
			}
		}
		name = {
			text = action.1.ve
			exclusive_trigger = {
				has_origin = origin_broken_shackles
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_origin = origin_slavers
				}
			}
		}
		name = {
			text = action.1.aak
			exclusive_trigger = {
				has_origin = origin_lost_colony
				is_gestalt = yes
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
				}
			}
		}
		name = {
			text = action.1.aan
			exclusive_trigger = {
				has_origin = origin_lost_colony
				is_individual_machine = yes
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
				}
			}
		}
		name = { # Spiritualist empire, IM
			text = action.1.xc
			trigger = {
				is_spiritualist = yes
				event_target:contact_empire = {
					is_individual_machine = yes
				}
			}
		}
		name = { # Machine empire, IM
			text = action.1.xe
			trigger = {
				is_machine_empire = yes
				event_target:contact_empire = {
					is_individual_machine = yes
				}
			}
		}

		icon = {
			icon = GFX_option_icon_isolationist
			text = seek_isolation_tt_short
		}

		if = {
			limit = {
				OR = {
					NOT = { is_country_type = default }
					event_target:contact_empire = { NOT = { is_country_type = default } }
				}
			}
			custom_tooltip = action.1.fe_option
		}
		else = {
			custom_tooltip = seek_isolation_tt

			hidden_effect = {
				event_target:contact_empire = {
					random_spynetwork = {
						limit = { target = { is_same_value = root } }
						add_modifier = {
							modifier = first_comms_defensive
							years = 15
						}
					}
				}
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 2
				is_xenophobe = yes
				is_militarist = no
			}
			modifier = {
				factor = 2
				has_valid_civic = civic_inwards_perfection
			}
		}
	}
	option = { #hostile - expansionist
		name = {
			text = action.1.u6
			exclusive_trigger = {
				has_slave_origin = yes
				event_target:contact_empire = { has_origin = origin_slavers }
			}
		}
		name = {
			text = action.1.ae
			trigger = {
				OR = {
					is_xenophobe = yes
					is_militarist = yes
				}
			}
		}
		name = {
			text = action.1.ds
			trigger = {
				has_valid_civic = civic_hive_devouring_swarm
			}
		}
		name = {
			text = action.1.mt
			trigger = {
				is_machine_empire = yes
			}
		}
		name = {
			text = action.1.aac
			trigger = {
				is_militarist = yes
				OR = {
					is_spiritualist = yes
					is_authoritarian = yes
				}
			}
		}
		name = {
			text = action.1.aad
			trigger = {
				is_spiritualist = yes
				NOT = { is_same_species = event_target:contact_empire }
			}
		}
		name = {
			text = action.1.b
			trigger = {
				NOT = { is_same_species = event_target:contact_empire }
				is_xenophobe = yes
			}
		}
		name = {
			text = action.1.s
			trigger = {
				is_spiritualist = yes
				event_target:contact_empire = {
					OR = {
						is_machine_empire = yes
						is_individual_machine = yes
					}
				}
			}
		}
		name = {
			text = action.1.ab
			trigger = {
				is_spiritualist = yes
				NOT = { is_same_species = event_target:contact_empire }
			}
		}
		name = {
			text = action.1.an
			trigger = {
				is_militarist = yes
			}
		}
		name = {
			text = action.1.at
			trigger = {
				is_militarist = yes
			}
		}
		name = {
			text = action.1.au
			trigger = {
				is_spiritualist = yes
				is_militarist = yes
			}
		}
		name = {
			text = action.1.k
			trigger = {
				OR = {
					is_militarist = yes
					is_authoritarian = yes
				}
			}
		}
		name = {
			text = action.1.ax
			trigger = {
				OR = {
					is_materialist = yes
					is_egalitarian = yes
					is_pacifist = yes
				}
			}
		}
		name = {
			text = action.1.u1
			trigger = {
				is_xenophile = yes
			}
		}
		name = {
			text = action.1.u2
			trigger = {
				is_authoritarian = yes
			}
		}
		name = {
			text = action.1.u3
			trigger = {
				is_gestalt = yes
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
			}
		}
		name = {
			text = action.1.vc
			exclusive_trigger = {
				has_origin = origin_payback
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_origin = origin_slavers
				}
			}
		}
		name = {
			text = action.1.vf
			exclusive_trigger = {
				has_origin = origin_broken_shackles
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_origin = origin_slavers
				}
			}
		}
		name = {
			text = action.1.aaj
			exclusive_trigger = {
				has_origin = origin_lost_colony
				is_hive_empire = yes
				has_valid_civic = civic_hive_devouring_swarm
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
					has_valid_civic = civic_hive_devouring_swarm
				}
			}
		}
		name = {
			text = action.1.aal
			exclusive_trigger = {
				has_origin = origin_lost_colony
				is_gestalt = yes
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
				}
			}
		}
		name = {
			text = action.1.aao
			exclusive_trigger = {
				has_origin = origin_lost_colony
				is_individual_machine = yes
				event_target:contact_empire = {
					has_country_flag = special_intro_for@root
					has_country_flag = lost_colony_parent_of@root
				}
			}
		}
		name = { # Machine empire, IM
			text = action.1.xf
			trigger = {
				is_machine_empire = yes
				event_target:contact_empire = {
					is_individual_machine = yes
				}
			}
		}
		name = { # IM, machine empire
			text = action.1.xg
			trigger = {
				is_individual_machine = yes
				event_target:contact_empire = {
					is_machine_empire = yes
				}
			}
		}

		icon = {
			icon = GFX_option_icon_hostile
			text = seek_enemies_tt_short
		}

		if = {
			limit = {
				OR = {
					NOT = { is_country_type = default }
					event_target:contact_empire = { NOT = { is_country_type = default } }
				}
			}
			custom_tooltip = action.1.fe_option
		}
		else = {
			custom_tooltip = seek_enemies_tt

			event_target:contact_empire = {
				add_opinion_modifier = {
					who = root
					modifier = opinion_hostile_first_comms_greeting
				}
			}
			hidden_effect = {
				random_spynetwork = {
					limit = {
						owner = { is_same_value = root }
						target = { is_same_value = event_target:contact_empire }
					}
					add_modifier = {
						modifier = first_comms_hostility_preparations
						years = 15
					}
				}
			}
		}

		trigger = {
			NOR = {
				is_fanatic_pacifist = yes
				has_valid_civic = civic_inwards_perfection
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 100
				is_homicidal = yes
			}
			modifier = {
				factor = 2
				is_militarist = yes
			}
			modifier = {
				factor = 0.5
				is_pacifist = yes
			}
			modifier = {
				factor = 2
				first_contact_custom_greeting = yes #basically, various hostility
			}
			modifier = {
				factor = 0.1
				is_in_federation_with = event_target:contact_empire #just in case
			}
		}
	}

	after = {
		if = {
			limit = {
				NOT = {
					event_target:contact_empire = { has_relation_flag = { flag = no_coms who = root } }
				}
			}
			hidden_effect = {
				if = {
					limit = {
						NOT = {
							event_target:contact_empire = {
								is_same_species = root
							}
						}
					}
					country_event = { id = progress.4 }
					country_event = { id = progress.5 }
					country_event = { id = progress.6 }
					country_event = { id = progress.9 } # special event for Payback origin
					#country_event = { id = story.7 days = 30 } REMOVED DUE TO ON_ACTIONS ALSO TRIGGERING THIS, CAUSING SCOPING ISSUES
				}
				if = {
					limit = {
						event_target:contact_empire = {
							OR = {
								is_country_type = fallen_empire
								is_country_type = awakened_fallen_empire
							}
						}
					}
					set_country_flag = Story7
					set_country_flag = has_encountered_other_empire
					if = {
						limit = { NOT = { has_country_flag = StoryFirst } }
						set_country_flag = StoryFirst
					}
				}
			}
		}
	}
}

### First Contact Diplomatic Message - pre-FTL version
country_event = {
	id = action.2
	title = action.1.name
	message_desc = action.1.message
	location = event_target:contact_empire.capital_scope

	picture_event_data = {
		portrait = event_target:contact_empire
		planet_background = event_target:contact_empire
		graphical_culture = event_target:contact_empire
		city_level = event_target:contact_empire
		room = event_target:contact_empire.ruler
	}

	### Custom First Contact system flavour
	desc = {
		text = action.2.desc_01
		trigger = {
			event_target:contact_empire = {
				is_country_type = primitive
				current_awareness_level = none
				has_special_pre_ftl_diplo = no
			}
		}
	}
	desc = {
		text = action.2.desc_02
		trigger = {
			event_target:contact_empire = {
				is_country_type = primitive
				current_awareness_level = low
				has_special_pre_ftl_diplo = no
			}
		}
	}
	desc = {
		text = action.2.desc_03
		trigger = {
			event_target:contact_empire = {
				is_country_type = primitive
				current_awareness_level = medium
				has_special_pre_ftl_diplo = no
			}
		}
	}
	desc = {
		text = action.2.desc_04
		trigger = {
			event_target:contact_empire = {
				is_country_type = primitive
				current_awareness_level = high
				has_special_pre_ftl_diplo = no
			}
		}
	}
	desc = {
		text = action.2.desc_05
		trigger = {
			event_target:contact_empire = {
				is_country_type = primitive
				current_awareness_level = full
				NOT = { has_country_flag = pre_ftl_initiating_contact }
				has_special_pre_ftl_diplo = no
			}
		}
	}
	desc = {
		text = action.2.desc_06
		trigger = {
			event_target:contact_empire = {
				is_country_type = primitive
				current_awareness_level = full
				has_country_flag = pre_ftl_initiating_contact
				has_special_pre_ftl_diplo = no
			}
		}
	}
	desc = {
		text = action.2.desc_solarpunk
		trigger = {
			event_target:contact_empire = {
				is_country_type = primitive
				has_special_pre_ftl_diplo = yes
				has_country_flag = solarpunk_country
			}
		}
	}
	desc = {
		text = action.2.desc_07
		exclusive_trigger = {
			event_target:contact_empire = {
				is_country_type = primitive
				current_awareness_level = full
				has_country_flag = pre_ftl_being_invaded
			}
		}
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		event_target:contact_empire = {
			is_country_type = primitive
		}
	}

	immediate = {
		country_event = { id = tutorial.2150 } #"First Contact Established" (pre-FTL version)
		event_target:contact_empire = {
			save_event_target_as = contact_speaker
		}
	}

	# For the event options:
	#	- Note 1: If multiple of the triggered option names return true, it'll pick a random one among those that are available.
	#	- Note 2: If none of them return true, it will pick the first one in the list. So it should be something suitably generic.

	option = { # xenophile
		name = action.2.a

		trigger = {
			is_xenophile = yes
		}
	}

	option = { # xenophobe
		name = action.2.b

		trigger = {
			is_xenophobe = yes
		}
	}

	option = { # spiritualist
		name = action.2.c

		trigger = {
			is_spiritualist = yes
		}
	}

	option = { # materialist
		name = action.2.d

		trigger = {
			is_materialist = yes
		}
	}

	option = { # militarist
		name = action.2.e

		trigger = {
			is_militarist = yes
		}
	}

	option = { # pacifist
		name = action.2.f

		trigger = {
			is_pacifist = yes
		}
	}

	option = { # egalitarian
		name = action.2.g

		trigger = {
			is_egalitarian = yes
		}
	}

	option = { # authoritarian
		name = action.2.h

		trigger = {
			is_authoritarian = yes
		}
	}

	option = { # gestalt
		name = action.2.i

		trigger = {
			has_ethic = ethic_gestalt_consciousness
		}
	}

	option = { # gestalt meeting other gestalt
		name = action.2.j

		trigger = {
			has_ethic = ethic_gestalt_consciousness
			event_target:contact_empire = {
				has_ethic = ethic_gestalt_consciousness
			}
		}
	}

	option = { # megacorp
		name = action.2.k

		trigger = {
			is_megacorp = yes
		}
	}

	after = {
		add_intel = {
			who = event_target:contact_empire
			amount = 100
		}
		if = {
			limit = {
				NOT = {
					event_target:contact_empire = { has_relation_flag = { flag = no_coms who = root } }
				}
			}
			hidden_effect = {
				country_event = { id = progress.4 }
				country_event = { id = progress.5 }
				country_event = { id = progress.6 }
				country_event = { id = progress.9 } # special event for Payback origin
			}
		}
		if = {
			limit = {
				event_target:contact_empire = {
					is_primitive = yes
				}
			}
			event_target:contact_empire = {
				set_awareness = 100
			}
		}
	}
}

# Primitive Medieval Civilization Encountered
country_event = {
	id = action.5
	title = "action.5.name"
	picture = {
		trigger = { event_target:primitive_civ = { is_gestalt = no } }
		picture = GFX_evt_medieval_alien_civilization
	}
	picture = {
		trigger = { event_target:primitive_civ = { is_gestalt = yes } }
		picture = GFX_evt_hive_mind_pre_ftl
	}
	location = FROMFROM
	show_sound = event_pre_ftl_civilization

	desc = { # Stone Age Regular
		text = action.5.desc_00
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = stone_age
				is_gestalt = no
			}
		}
	}
	desc = { # Stone Age Hive
		text = action.5.desc_00_hive
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = stone_age
				is_gestalt = yes
			}
		}
	}
	desc = { # Bronze Age Regular
		text = action.5.desc_01
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = bronze_age
				is_gestalt = no
			}
		}
	}
	desc = { # Bronze Age Hive
		text = action.5.desc_01_hive
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = bronze_age
				is_gestalt = yes
			}
		}
	}
	desc = { # Iron Age Regular
		text = action.5.desc_02
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = iron_age
				is_gestalt = no
			}
		}
	}
	desc = { # Iron Age Hive
		text = action.5.desc_02_hive
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = iron_age
				is_gestalt = yes
			}
		}
	}
	desc = { # Late Medieval Regular
		text = action.5.desc_03
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = late_medieval_age
				is_gestalt = no
			}
		}
	}
	desc = { # Late Medieval Hive
		text = action.5.desc_03_hive
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = late_medieval_age
				is_gestalt = yes
			}
		}
	}
	desc = { # Renaissance
		text = action.5.desc_04
		trigger = { event_target:primitive_civ = { has_country_flag = renaissance_age } }
	}
	desc = { # Steam Age
		text = action.5.desc_05
		trigger = { event_target:primitive_civ = { has_country_flag = steam_age } }
	}

	is_triggered_only = yes

	trigger = {
		is_ai = no
		NAND = {
			has_origin = origin_broken_shackles
			event_target:primitive_civ = {
				OR = {
					has_country_flag = broken_shackles_parent_country
					has_country_flag = broken_shackles_abductees_country
				}
			}
		}
		event_target:primitive_civ = {
			NOR = {
				has_country_flag = broken_shackles_parent_country
				has_country_flag = broken_shackles_abductees_country
				has_country_flag = humans_late_medieval_age
				has_country_flag = benefactor_empire
				has_country_flag = fotd_hunter@root
				has_country_flag = solarpunk_country
			}
			OR = {
				has_country_flag = stone_age
				has_country_flag = bronze_age
				has_country_flag = iron_age
				has_country_flag = late_medieval_age
				has_country_flag = renaissance_age
				has_country_flag = steam_age
			}
		}
	}

	option = {
		name = INTERESTING
		hidden_effect = { country_event = { id = story.6 days = 30 } }
	}
}

# Primitive Industrial Civilization Encountered
country_event = {
	id = action.6
	title = "action.5.name"
	picture = {
		trigger = { event_target:primitive_civ = { is_gestalt = no } }
		picture = GFX_evt_metropolis
	}
	picture = {
		trigger = { event_target:primitive_civ = { is_gestalt = yes } }
		picture = GFX_evt_hive_mind_pre_ftl
	}
	location = FROMFROM
	show_sound = event_scanner

	desc = { # Industrial Age
		text = action.6.desc_01
		trigger = { event_target:primitive_civ = { has_country_flag = industrial_age } }
	}
	desc = { # Machine Age
		text = action.6.desc_02
		trigger = { event_target:primitive_civ = { has_country_flag = machine_age } }
	}
	desc = { # Atomic Age
		text = action.6.desc_03
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = atomic_age
				is_gestalt = no
			}
		}
	}
	desc = { # Atomic Age
		text = action.6.desc_03_hive
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = atomic_age
				is_gestalt = yes
			}
		}
	}
	desc = { # Early Space Age
		text = action.6.desc_04
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = early_space_age
				is_gestalt = no
			}
		}
	}
	desc = { # Early Space Age
		text = action.6.desc_04_hive
		trigger = {
			event_target:primitive_civ = {
				has_country_flag = early_space_age
				is_gestalt = yes
			}
		}
	}

	is_triggered_only = yes

	trigger = {
		is_ai = no
		NAND = {
			has_origin = origin_broken_shackles
			event_target:primitive_civ = {
				OR = {
					has_country_flag = broken_shackles_parent_country
					has_country_flag = broken_shackles_abductees_country
				}
			}
		}
		event_target:primitive_civ = {
			NOR = {
				has_country_flag = humans_machine_age
				has_country_flag = humans_early_space_age
				has_country_flag = benefactor_empire
				has_country_flag = solarpunk_country
				has_country_flag = fotd_hunter@root
			}
			OR = {
				has_country_flag = industrial_age
				has_country_flag = machine_age
				has_country_flag = atomic_age
				has_country_flag = early_space_age
			}
		}
	}

	option = {
		name = INTERESTING
		hidden_effect = { country_event = { id = story.6 days = 30 } }
	}
}

# Add a opinion modifier if we are hostile when communications are established
country_event = {
	id = action.7
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		is_hostile = from
	}

	immediate = {
		if = {
			limit = {
				num_killed_ships = {
					target = from
					value < 10
				}
				num_taken_planets = {
					target = from
					value = 0
				}
			}
			add_opinion_modifier = {
				modifier = opinion_first_contact_hostility
				who = from
			}
		}
		if = {
			limit = {
				OR = {
					num_killed_ships = {
						target = from
						value > 9
					}
					num_taken_planets = {
						target = from
						value > 0
					}
				}
			}
			add_opinion_modifier = {
				modifier = opinion_first_contact_war
				who = from
			}
			set_country_flag = shoot_to_kill_achievement
		}
	}
}

# Conquest
country_event = {
	id = action.8
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = default
		FROM = { is_country_type = default }
		NOT = { has_communications = from }
		is_hostile = from
	}

	immediate = {
		establish_communications = from
		fromfrom = {
			conquer = root
			set_controller = root
		}
	}
}

# Communication Established
country_event = {
	id = action.11
	title = "action.11.name"
	desc = {
		text = "action.11.desc"
		trigger = {
			fromfrom = { NOT = { has_relation_flag = { who = root flag = AbandonedRefugees } } }
		}
	}
	desc = {
		text = action.11.abandoned.desc
		trigger = {
			fromfrom = { has_relation_flag = { who = root flag = AbandonedRefugees } }
		}
	}
	picture = GFX_evt_throne_room
	show_sound = event_radio_chatter

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = day_0
		}
		fromfrom = {
			NOT = {
				has_country_flag = day_0
			}
			OR = {
				is_country_type = default
				is_country_type = enclave
			}
		}
		NOT = { has_country_flag = first_contact_completed@fromfrom }
	}

	immediate = {
		fromfrom = {
			country_event = { id = action.13 }
			save_event_target_as = contact_empire
		}
		country_event = { id = distar.238 days = 1 }
	}

	after = {
		hidden_effect = {
			if = {
				limit = {
					fromfrom = {
						is_country_type = enclave
					}
				}
				fromfrom = {
					switch = {
						trigger = has_country_flag
						trader_enclave_country = { country_event = { id = leviathans.101 } }
						artist_enclave_country = { country_event = { id = leviathans.290 } }
						curator_enclave_country = { country_event = { id = leviathans.501 } }
						mercenary_enclave_country = { country_event = { id = enclave.204 } }
						salvager_enclave_country = { country_event = { id = enclave.304 } }
						shroudwalker_enclave_country = { country_event = { id = enclave.404 } }
						mindwarden_enclave_country = { country_event = { id = shroud.4199 } }
						champions_forge_enclave_country = { country_event = { id = nomads.155 } }
						default = { log_error = "Unexpected enclave type or missing script flag" }
					}
				}
			}
		}
	}

	option = {
		trigger = {
			fromfrom = { NOT = { has_relation_flag = { who = root flag = AbandonedRefugees } } }
		}
		name = "action.11.a"
		if = {
			limit = {
				is_xenophile = yes
			}
			add_monthly_resource_mult = {
				resource = influence
				value = @tier2influencecontactxenophile
				min = @tier2influencecontactmin
				max = @tier2influencecontactmax
			}
		}
		else = {
			add_monthly_resource_mult = {
				resource = influence
				value = @tier2influencecontact
				min = @tier2influencecontactmin
				max = @tier2influencecontactmax
			}
		}
		hidden_effect = {
			country_event = { id = action.1 }
		}
	}
	option = {
		trigger = {
			fromfrom = { has_relation_flag = { who = root flag = AbandonedRefugees } }
			is_xenophobe = no
		}
		name = WORRYING
		if = {
			limit = {
				is_xenophile = yes
			}
			add_monthly_resource_mult = {
				resource = influence
				value = @tier2influencecontactxenophile
				min = @tier2influencecontactmin
				max = @tier2influencecontactmax
			}
		}
		else = {
			add_monthly_resource_mult = {
				resource = influence
				value = @tier2influencecontact
				min = @tier2influencecontactmin
				max = @tier2influencecontactmax
			}
		}
		hidden_effect = {
			country_event = { id = action.1 }
		}
	}
	option = {
		trigger = {
			fromfrom = { has_relation_flag = { who = root flag = AbandonedRefugees } }
			is_xenophobe = yes
		}
		name = OK
		if = {
			limit = {
				is_xenophile = yes
			}
			add_monthly_resource_mult = {
				resource = influence
				value = @tier2influencecontactxenophile
				min = @tier2influencecontactmin
				max = @tier2influencecontactmax
			}
		}
		else = {
			add_monthly_resource_mult = {
				resource = influence
				value = @tier2influencecontact
				min = @tier2influencecontactmin
				max = @tier2influencecontactmax
			}
		}
		hidden_effect = {
			country_event = { id = action.1 }
		}
	}
}

# Primitive planet surveyed
ship_event = {
	id = action.12
	is_triggered_only = yes
	hide_window = yes

	trigger = {
		FROM = {
			AND = {
				has_owner = yes
				owner = { is_country_type = primitive }
			}
			NOT = { has_planet_flag = fotd_hunter@root.owner }
		}
	}

	immediate = {
		owner = {
			save_event_target_as = ship_owner
			if = {
				limit = {
					NOT = { has_country_flag = encountered_first_primitive }
				}
				set_country_flag = encountered_first_primitive
			}
		}
		FROM = {
			if = {
				limit = {
					exists = owner
				}
				owner = {
					establish_contact = { who = event_target:ship_owner }
					save_event_target_as = primitive_civ
				}
				save_event_target_as = primitive_planet
			}
		}
		if = {
			limit = {
				exists = event_target:primitive_civ
				event_target:primitive_civ = {
					NOT = { has_country_flag = humans_late_medieval_age }
					NOT = { has_country_flag = benefactor_empire }
					NOT = { has_country_flag = primitive_cousins_of_@root.owner }
					OR = {
						has_country_flag = stone_age
						has_country_flag = bronze_age
						has_country_flag = iron_age
						has_country_flag = late_medieval_age
						has_country_flag = renaissance_age
						has_country_flag = steam_age
					}
				}
			}
			owner = { country_event = { id = action.5 } }
			break = yes
		}
		if = {
			limit = {
				exists = event_target:primitive_civ
				event_target:primitive_civ = {
					NOR = {
						has_country_flag = humans_machine_age
						has_country_flag = humans_early_space_age
						has_country_flag = benefactor_empire
					}
					OR = {
						has_country_flag = industrial_age
						has_country_flag = machine_age
						has_country_flag = atomic_age
						has_country_flag = early_space_age
					}
				}
			}
			owner = { country_event = { id = action.6 } }
			break = yes
		}
		if = {
			limit = {
				exists = event_target:primitive_civ
				event_target:primitive_civ = { has_country_flag = humans_late_medieval_age }
			}
			owner = { country_event = { id = galactic_features.101 } }
			break = yes
		}
		if = {
			limit = {
				exists = event_target:primitive_civ
				event_target:primitive_civ = { has_country_flag = humans_machine_age }
			}
			owner = { country_event = { id = galactic_features.102 } }
			break = yes
		}
		if = {
			limit = {
				exists = event_target:primitive_civ
				event_target:primitive_civ = { has_country_flag = humans_early_space_age }
			}
			owner = { country_event = { id = galactic_features.103 } }
			break = yes
		}
		if = {
			limit = {
				exists = event_target:primitive_civ
				event_target:primitive_civ = { has_country_flag = benefactor_empire }
			}
			owner = { country_event = { id = origin.1355 } }
			break = yes
		}
		if = {
			limit = {
				exists = event_target:primitive_civ
				event_target:primitive_civ = { has_country_flag = primitive_cousins_of_@root.owner }
			}
			#owner = { country_event = { id = origin.410 } }
			break = yes
		}
	}
}

# Aliens Establish Communications
country_event = {
	id = action.13
	title = "action.13.name"
	desc = {
		text = "action.13.desc"
		trigger = {
			from = {
				NOT = { has_relation_flag = { who = root flag = AbandonedRefugees } }
			}
		}
	}
	desc = {
		text = "action.13.abandoned.desc"
		trigger = {
			from = { has_relation_flag = { who = root flag = AbandonedRefugees } }
		}
	}
	picture = GFX_evt_throne_room
	show_sound = event_radio_chatter

	is_triggered_only = yes

	trigger = {
		NOT = {
			has_country_flag = day_0
		}
		from = {
			NOT = {
				has_country_flag = day_0
			}
			OR = {
				is_country_type = default
				is_country_type = enclave
			}
		}
	}

	immediate = {
		from = {
			save_event_target_as = contact_empire
		}
		country_event = { id = distar.239 days = 1 }
	}

	option = {
		trigger = {
			from = { NOT = { has_relation_flag = { who = root flag = AbandonedRefugees } } }
		}
		name = "action.13.a"
		hidden_effect = {
			country_event = { id = action.1 }
		}
	}
	option = {
		trigger = {
			from = { has_relation_flag = { who = root flag = AbandonedRefugees } }
		}
		name = WORRYING
		hidden_effect = {
			country_event = { id = action.1 }
		}
	}
	option = {
		trigger = {
			from = { has_relation_flag = { who = root flag = AbandonedRefugees } }
			is_xenophobe = yes
		}
		name = "action.13.c"
		hidden_effect = {
			country_event = { id = action.1 }
		}
	}
}

# Primitive Civilization Conquered - HIDDEN
country_event = {
	id = action.14
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		FROM = { is_country_type = primitive }
		is_country_type = default
	}

	immediate = {
		if = {
			limit = {
				OR = {
					AND = {
						from = { is_hive_empire = yes}
						is_hive_empire = YES
					}
					AND = {
						from = { is_hive_empire = no }
						is_regular_empire = yes
					}
				}
			}
			FROMFROM = {
				add_modifier = {
					modifier = planet_culture_shock
					years = 10
				}
			}
		}
		FROMFROM = {
			set_owner = ROOT
		}

		every_country = {
			limit = {
				has_communications = root
				is_country_type = default
				NOT = { is_same_value = root }
			}
			add_opinion_modifier = {
				who = root
				modifier = opinion_primitive_violation
			}
		}

		if = {
			limit = {
				is_ai = no
			}
			fromfrom = {
				save_event_target_as = conquered_primitive_world
			}
			from = {
				owner_species = {
					save_event_target_as = conquered_primitive_species
					set_timed_species_flag = {
						flag = primitive_species
						years = 10
					}
				}
			}
			country_event = { id = action.140 }
		}

		reset_years_of_peace = yes
	}
}

# Primitive Civilization Conquered - Player info
# fromfrom = pre-FTL country | event_target:conquered_primitive_world = pre-FTL world
country_event = {
	id = action.140
	title = action.14.name
	desc = { #Non-Purge Policy Regular Empires
		text = action.14.desc
		trigger = {
			NOR = {
				has_ethic = ethic_gestalt_consciousness
				event_target:conquered_primitive_species = {
					has_citizenship_type = { country = root type = citizenship_purge }
				}
			}
		}
	}
	desc = { #Purge Policy Regular Empires
		text = action.14.desc.purge
		trigger = {
			NOT = { has_ethic = ethic_gestalt_consciousness }
			event_target:conquered_primitive_species = {
				has_citizenship_type = { country = root type = citizenship_purge }
			}
		}
	}
	desc = { #Servitors
		text = action.14.desc.serv
		trigger = {
			has_civic = civic_machine_servitor
		}
	}
	desc = { #Assimilators
		text = action.14.desc.assim
		trigger = {
			has_civic = civic_machine_assimilator
		}
	}
	desc = { #Exterminators
		text = action.14.desc.term
		trigger = {
			has_civic = civic_machine_terminator
		}
	}
	desc = { #Purge Policy MIs
		text = action.14.desc.mach.purge
		trigger = {
			is_machine_empire = yes
			event_target:conquered_primitive_species = {
				has_citizenship_type = { country = root type = citizenship_purge }
			}
			NOR = {
				has_civic = civic_machine_servitor
				has_civic = civic_machine_assimilator
				has_civic = civic_machine_terminator
			}
		}
	}
	desc = { #Enslave Policy MIs
		text = action.14.desc.mach.slave
		trigger = {
			is_machine_empire = yes
			event_target:conquered_primitive_species = {
				has_citizenship_type = { country = root type = citizenship_slavery }
			}
			NOR = {
				has_civic = civic_machine_servitor
				has_civic = civic_machine_assimilator
				has_civic = civic_machine_terminator
			}
		}
	}
	desc = { #Purge Policy Hiveminds
		text = action.14.desc.hive.purge
		trigger = {
			is_hive_empire = yes
			event_target:conquered_primitive_species = {
				has_citizenship_type = { country = root type = citizenship_purge }
			}
		}
	}
	desc = { #Enslave Policy Hiveminds
		text = action.14.desc.hive.slave
		trigger = {
			is_hive_empire = yes
			event_target:conquered_primitive_species = {
				has_citizenship_type = { country = root type = citizenship_slavery }
			}
		}
	}
	picture = GFX_evt_ground_combat
	show_sound = event_alien_signal
	location = event_target:conquered_primitive_world
	is_triggered_only = yes

	immediate = {
		event_target:conquered_primitive_world = {
			set_timed_carrier_flag = {
				flag = ignore_ai_building_limitations
				days = 1
			}
			# Add appropriate capital
			if = {
				limit = {
					is_planet_class = pc_habitat
					has_building = building_capital
				}
				remove_building = building_capital
				add_building = building_hab_capital
			}
			# Add districts (Ringworlds & Habitats first)
			if = {
				limit = {
					is_planet_class = pc_ringworld_habitable
				}
				add_district = district_rw_city
				break = yes
			}
			if = {
				limit = {
					is_planet_class = pc_habitat
				}
				break = yes
			}
			# Add districts (planets)
			if = {
				limit = {
					pop_amount <= 500
				}
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				break = yes
			}
			if = {
				limit = {
					pop_amount >= 500
					pop_amount <= 1000
				}
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				break = yes
			}
			if = {
				limit = {
					pop_amount >= 1000
					pop_amount <= 1500
				}
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				add_district = { district_type = district_mining type_conversion = yes }
				break = yes
			}
			if = {
				limit = {
					pop_amount >= 1500
					pop_amount <= 2000
				}
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				add_district = { district_type = district_mining type_conversion = yes }
				add_district = { district_type = district_mining type_conversion = yes }
				break = yes
			}
			if = {
				limit = {
					pop_amount >= 2000
					pop_amount <= 2500
				}
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				add_district = { district_type = district_mining type_conversion = yes }
				add_district = { district_type = district_mining type_conversion = yes }
				break = yes
			}
			if = {
				limit = {
					pop_amount >= 2500
					pop_amount <= 3000
				}
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				add_district = { district_type = district_mining type_conversion = yes }
				add_district = { district_type = district_mining type_conversion = yes }
				add_district = { district_type = district_generator type_conversion = yes }
				break = yes
			}
			if = {
				limit = {
					pop_amount >= 3000
				}
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_city type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				add_district = { district_type = district_farming type_conversion = yes }
				add_district = { district_type = district_mining type_conversion = yes }
				add_district = { district_type = district_mining type_conversion = yes }
				add_district = { district_type = district_generator type_conversion = yes }
				break = yes
			}
		}
	}

	option = {
		name = action.14.a.phobe
		custom_tooltip = action.14.a.tooltip
		trigger = {
			is_xenophobe = yes
		}
	}
	option = {
		name = action.14.a.military
		custom_tooltip = action.14.a.tooltip
		trigger = {
			is_militarist = yes
			is_xenophobe = no
		}
	}
	option = {
		name = action.14.a.spirit
		custom_tooltip = action.14.a.tooltip
		trigger = {
			is_spiritualist = yes
			NOR = {
				is_xenophobe = yes
				is_militarist = yes
			}
		}
	}
	option = {
		name = action.14.a.material
		custom_tooltip = action.14.a.tooltip
		trigger = {
			is_materialist = yes
			is_xenophobe = no
			is_militarist = no
		}
	}
	option = {
		name = action.14.a
		custom_tooltip = action.14.a.tooltip
		trigger = {
			is_xenophobe = no
			is_militarist = no
			is_spiritualist = no
			is_materialist = no
			is_machine_empire = no
			is_hive_empire = no
		}
	}
	option = {
		name = action.14.a
		trigger = {
			is_hive_empire = yes
		}
	}
	option = {
		name = action.14.a.serv
		trigger = {
			has_civic = civic_machine_servitor
		}
	}
	option = {
		name = action.14.a.assim
		trigger = {
			has_civic = civic_machine_assimilator
		}
	}
	option = {
		name = action.14.a.term
		trigger = {
			has_civic = civic_machine_terminator
		}
	}
	option = {
		name = action.14.a.mach
		trigger = {
			is_machine_empire = yes
			NOR = {
				has_civic = civic_machine_servitor
				has_civic = civic_machine_assimilator
				has_civic = civic_machine_terminator
			}
		}
	}
}

# New Contact opinion modifier added
country_event = {
	id = action.19
	hide_window = yes

	is_triggered_only = yes

	trigger = { is_country_type = default }

	immediate = {
		if = {
			limit = {
				NOR = {
					exists = overlord
					AND = {
						exists = overlord
						overlord = {
							is_same_value = from
						}
					}
				}
			}
			add_opinion_modifier = {
				modifier = opinion_new_contact
				who = from
			}
		}
	}
}

# Other Empires react to a Pop dying in a purge
carrier_event = {
	id = action.21

	hide_window = yes

	is_triggered_only = yes

	trigger = {
		exists = fromfrom #crisis.202 can remove the last pop
		FROMFROM = {
			is_robot_pop_group = no
			is_sapient = yes
			NOT = { has_trait = "trait_hive_mind" }
			OR = {
				NOT = { has_citizenship_type = { country = from type = citizenship_purge } }
				NOT = { has_purge_type = { country = from type = purge_neutering } }
			}
			NOR = {
				has_purge_type = { country = from type = purge_necrophage }
				AND = {
					has_purge_type = { country = from type = purge_cosmogenesis_lathe_resettle }
					planet = {
						NOT = {
							has_designation = col_cosmogenesis_world
						}
					}
				}
			}
		}
		is_controlled_by = FROM
	}

	immediate = {
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				NOT = { is_same_species = FROMFROM }
				NOT = { has_ai_personality_behaviour = purger }
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile
				}
				has_intel_level = {
					who = FROM
					category = economy
					level >= 1
				}
			}
			if = {
				limit = {
					from = {
						has_origin = origin_nomadic_purger
						exists = overlord
					}
				}
				while = {
					count = root.local_pop_amount
					add_opinion_modifier = { who = FROM.overlord modifier = opinion_genocidal }
				}
			}
			else = {
				while = {
					count = root.local_pop_amount
					add_opinion_modifier = { who = FROM modifier = opinion_genocidal }
				}
			}
		}
		every_country = {
			limit = {
				has_communications = FROM
				NOT = { is_country = FROM }
				is_same_species = FROMFROM
				has_intel_level = {
					who = FROM
					category = economy
					level >= 1
				}
			}
			if = {
				limit = {
					from = {
						has_origin = origin_nomadic_purger
						exists = overlord
					}
				}
				while = {
					count = root.local_pop_amount
					add_opinion_modifier = { who = FROM.overlord modifier = opinion_genocidal_our_species }
				}
			}
			else = {
				while = {
					count = root.local_pop_amount
					add_opinion_modifier = { who = FROM modifier = opinion_genocidal_our_species }
				}
			}
		}
	}
}

# Purging: Gain resources from forced labor etc
carrier_event = {
	id = action.22
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = fromfrom #crisis.202 can remove the last pop
		fromfrom = {
			OR = {
				has_purge_type = { country = from type = purge_labor_camps }
				has_purge_type = { country = from type = purge_matrix }
				has_purge_type = { country = from type = purge_processing }
			}
		}
		is_controlled_by = FROM
	}

	immediate = {
		if = {
			limit = {
				exists = leader
				leader = {
					has_trait = leader_trait_judicial_execution
				}
			}
			if = {
				limit = {
					fromfrom = { has_purge_type = { country = from type = purge_labor_camps } }
				}
				if = {
					limit = {
						fromfrom = {
							is_robotic_species = no
							is_lithoid = no
							is_infernal = no
						}
					}
					from = {
						add_resource = {
							food = 0.48
							mult = local_pop_amount
						}
					}
				}
				else_if = {
					limit = {
						fromfrom = { is_lithoid = yes }
					}
					from = {
						add_resource = {
							minerals = 0.32
							mult = local_pop_amount
						}
					}
				}
				else_if = {
					limit = {
						fromfrom = { is_infernal = yes }
					}
					from = {
						add_resource = {
							alloys = 0.24
							mult = local_pop_amount
						}
					}
				}
				else_if = {
					limit = {
						fromfrom = { is_robotic_species = yes }
					}
					from = {
						add_resource = {
							alloys = 0.12
							mult = local_pop_amount
						}
					}
				}
			}
			else_if = {
				limit = {
					fromfrom = { has_purge_type = { country = from type = purge_matrix } }
				}
				from = {
					add_resource = {
						energy = 0.48
						mult = local_pop_amount
					}
				}
			}
			else_if = {
				limit = {
					fromfrom = { has_purge_type = { country = from type = purge_processing } }
				}
				from = {
					add_resource = {
						food = 0.24
						minerals = 0.24
						mult = local_pop_amount
					}
				}
			}
		}
		else_if = {
			limit = {
				is_sector_capital = no
				NOT = { exists = leader }
				exists = sector
				sector.sector_capital = {
					exists = leader
					leader = {
						has_trait = leader_trait_judicial_execution
					}
				}
			}
			if = {
				limit = {
					fromfrom = { has_purge_type = { country = from type = purge_labor_camps } }
				}
				if = {
					limit = {
						fromfrom = {
							is_robotic_species = no
							is_lithoid = no
							is_infernal = no
						}
					}
					from = {
						add_resource = {
							food = 0.36
							mult = local_pop_amount
						}
					}
				}
				else_if = {
					limit = {
						fromfrom = { is_lithoid = yes }
					}
					from = {
						add_resource = {
							minerals = 0.24
							mult = local_pop_amount
						}
					}
				}
				else_if = {
					limit = {
						fromfrom = { is_infernal = yes }
					}
					from = {
						add_resource = {
							alloys = 0.18
							mult = local_pop_amount
						}
					}
				}
				else_if = {
					limit = {
						fromfrom = { is_robotic_species = yes }
					}
					from = {
						add_resource = {
							alloys = 0.12
							mult = local_pop_amount
						}
					}
				}
			}
			else_if = {
				limit = {
					fromfrom = { has_purge_type = { country = from type = purge_matrix } }
				}
				from = {
					add_resource = {
						energy = 0.36
						mult = local_pop_amount
					}
				}
			}
			else_if = {
				limit = {
					fromfrom = { has_purge_type = { country = from type = purge_processing } }
				}
				from = {
					add_resource = {
						food = 0.18
						minerals = 0.18
						mult = local_pop_amount
					}
				}
			}
		}
		else = {
		# Values are monthly amount * 4
			if = {
				limit = {
					fromfrom = { has_purge_type = { country = from type = purge_labor_camps } }
				}
				if = {
					limit = {
						fromfrom = {
							is_robotic_species = no
							is_lithoid = no
							is_infernal = no
						}
					}
					from = {
						if = {
							limit = {
								has_origin = origin_nomadic_purger
								exists = overlord
							}
							overlord = {
								add_resource = {
									food = 0.24
									mult = local_pop_amount
								}
							}
						}
						else = {
							add_resource = {
								food = 0.24
								mult = local_pop_amount
							}
						}
					}
				}
				else_if = {
					limit = {
						fromfrom = { is_lithoid = yes }
					}
					from = {
						if = {
							limit = {
								has_origin = origin_nomadic_purger
								exists = overlord
							}
							overlord = {
								add_resource = {
									minerals = 0.16
									mult = local_pop_amount
								}
							}
						}
						else = {
							add_resource = {
								minerals = 0.16
								mult = local_pop_amount
							}
						}
					}
				}
				else_if = {
					limit = {
						fromfrom = { is_infernal = yes }
					}
					from = {
						add_resource = {
							alloys = 0.12
							mult = local_pop_amount
						}
					}
				}
				else_if = {
					limit = {
						fromfrom = { is_robotic_species = yes }
					}
					from = {
						if = {
							limit = {
								has_origin = origin_nomadic_purger
								exists = overlord
							}
							overlord = {
								add_resource = {
									alloys = 0.12
									mult = local_pop_amount
								}
							}
						}
						else = {
							add_resource = {
								alloys = 0.12
								mult = local_pop_amount
							}
						}
					}
				}
			}
			else_if = {
				limit = {
					fromfrom = { has_purge_type = { country = from type = purge_matrix } }
				}
				from = {
					if = {
						limit = {
							has_origin = origin_nomadic_purger
							exists = overlord
						}
						overlord = {
							add_resource = {
								energy = 0.24
								mult = local_pop_amount
							}
						}
					}
					else = {
						add_resource = {
							energy = 0.24
							mult = local_pop_amount
						}
					}
				}
			}
			else_if = {
				limit = {
					fromfrom = { has_purge_type = { country = from type = purge_processing } }
				}
				from = {
					if = {
						limit = {
							has_origin = origin_nomadic_purger
							exists = overlord
						}
						overlord = {
							add_resource = {
								food = 0.12
								minerals = 0.12
								mult = local_pop_amount
							}
						}
					}
					else = {
						add_resource = {
							food = 0.12
							minerals = 0.12
							mult = local_pop_amount
						}
					}
				}
			}
		}
	}
}

# A rebel country has taken their initial planet, switch their country type.
country_event = {
	id = action.30
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_country_type = rebel
	}

	immediate = {
		set_country_type = default
		if = {
			limit = {
				has_country_flag = slave_rebels
			}
			random_playable_country = {
				limit = {
					reverse_has_relation_flag = {
						flag = rebelling_slaves_former_owner
						who = root
					}
				}
				save_event_target_as = rsfo
			}
			random_list = {
				1 = { country_add_ethic = ethic_fanatic_materialist		modifier = { factor = 0 event_target:rsfo = { is_fanatic_materialist = yes } } }
				1 = { country_add_ethic = ethic_fanatic_spiritualist	modifier = { factor = 0 event_target:rsfo = { is_fanatic_spiritualist = yes } } }
				1 = { country_add_ethic = ethic_fanatic_militarist		modifier = { factor = 0 event_target:rsfo = { has_ethic = ethic_fanatic_militarist } } }
				1 = { country_add_ethic = ethic_fanatic_pacifist		modifier = { factor = 0 event_target:rsfo = { is_fanatic_pacifist = yes } } }
				1 = { country_add_ethic = ethic_fanatic_xenophile		modifier = { factor = 0 event_target:rsfo = { is_fanatic_xenophile = yes } } }
				1 = { country_add_ethic = ethic_fanatic_xenophobe		modifier = { factor = 0 event_target:rsfo = { has_ethic = ethic_fanatic_xenophobe } } }
				1 = { country_add_ethic = ethic_fanatic_egalitarian		modifier = { factor = 0 event_target:rsfo = { is_fanatic_egalitarian = yes } } }
				1 = { country_add_ethic = ethic_fanatic_authoritarian	modifier = { factor = 0 event_target:rsfo = { is_fanatic_authoritarian = yes } } }
			}
			random_list = {
				1 = { country_add_ethic = ethic_materialist modifier = { factor = 0
				OR = { is_fanatic_materialist = yes is_fanatic_spiritualist = yes event_target:rsfo = { is_fanatic_materialist = yes } } } }

				1 = { country_add_ethic = ethic_spiritualist modifier = { factor = 0
				OR = { is_fanatic_spiritualist = yes is_fanatic_materialist = yes event_target:rsfo = { is_fanatic_spiritualist = yes } } } }

				1 = { country_add_ethic = ethic_militarist modifier = { factor = 0
				OR = { has_ethic = ethic_fanatic_militarist is_fanatic_pacifist = yes event_target:rsfo = { has_ethic = ethic_fanatic_militarist } } } }

				1 = { country_add_ethic = ethic_pacifist modifier = { factor = 0
				OR = { is_fanatic_pacifist = yes has_ethic = ethic_fanatic_militarist event_target:rsfo = { is_fanatic_pacifist = yes } } } }

				1 = { country_add_ethic = ethic_xenophile modifier = { factor = 0
				OR = { is_fanatic_xenophile = yes has_ethic = ethic_fanatic_xenophobe event_target:rsfo = { is_fanatic_xenophile = yes } } } }

				1 = { country_add_ethic = ethic_xenophobe modifier = { factor = 0
				OR = { has_ethic = ethic_fanatic_xenophobe is_fanatic_xenophile = yes event_target:rsfo = { has_ethic = ethic_fanatic_xenophobe } } } }

				1 = { country_add_ethic = ethic_egalitarian modifier = { factor = 0
				OR = { is_fanatic_egalitarian = yes is_fanatic_authoritarian = yes event_target:rsfo = { is_fanatic_egalitarian = yes } } } }

				1 = { country_add_ethic = ethic_authoritarian modifier = { factor = 0
				OR = { is_fanatic_authoritarian = yes is_fanatic_egalitarian = yes event_target:rsfo = { is_fanatic_authoritarian = yes } } } }
			}
		}
		from = {
			solar_system = {
				if = {
					limit = { exists = starbase }
					starbase = {
						set_owner = root
					}
				}
			}
		}
		add_resource = {
			minerals = 200 # Should be atleast the required amount for a spaceport
			alloys = 200
			energy = 200
			influence = 250
		}
	}
}

# Encountered Fallen Empire, comms established
#country_event = {
#	id = action.31
#	hide_window = yes
#	is_triggered_only = yes
#
#	trigger = {
#		is_country_type = default
#		from = { is_country_type = fallen_empire }
#	}
#
#	immediate = {
#		establish_communications = from
#		from = { save_event_target_as = contact_empire }
#		country_event = { id = action.1 }
#	}
#}

# Won war
country_event = {
	id = action.32
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_country_flag = has_won_war
	}
}


# Observation Posts set to Passive study when policy is downgraded to Passive
country_event = {
	id = action.35
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		last_changed_policy = interference
		has_policy_flag = interference_not_allowed
	}
	immediate = {
		every_controlled_ship = {
			limit = {
				fleet = {
					is_ship_size = observation_station
				}
			}

			fleet = {
				if = {
					limit = {
						OR = {
							has_mission = specimen_collection
						}
					}
					set_mission = passive_observation
				}
			}
		}
	}
}

# Post owner switch for on_rebels_take_planet
country_event = {
	id = action.36
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		from = {
			every_owned_pop_group = {
				remove_modifier = "pop_recently_conquered"
			}
		}
	}
}

# Won War
country_event = {
	id = action.37
	title = action.37.name
	message_desc = action.37.message

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	desc = {
		trigger = {
			hidden:from = {
				exists = event_target:ratling_country
				is_same_empire = event_target:ratling_country
			}
		}
		text = action.37.desc.ketlings
	}

	desc = {
		trigger = {
			hidden:from = {
				is_megacorp = yes
			}
		}
		text = action.37.desc.corporate
	}

	desc = {
		trigger = {
			hidden:from = {
				switch = {
					trigger = has_ai_personality
					honorbound_warriors = { text = action.37.desc.hw }
					ruthless_capitalists = { text = action.37.desc.rc }
					peaceful_traders = { text = action.37.desc.pt }
					hegemonic_imperialists = { text = action.37.desc.hi }
					federation_builders = { text = action.37.desc.fb }
					xenophobic_isolationists = { text = action.37.desc.xi }
					hive_mind = { text = action.37.desc.hm }
					migrating_flock = { text = action.37.desc.mf }
					evangelising_zealots = { text = action.37.desc.ez }
					fanatic_purifiers = { text = action.37.desc.fp }
					democratic_crusaders = { text = action.37.desc.dc }
					slaving_despots = { text = action.37.desc.sd }
					decadent_hierarchy = { text = action.37.desc.dh }
					erudite_explorers = { text = action.37.desc.ee }
					spiritual_seekers = { text = action.37.desc.ss }
					harmonious_hierarchy = { text = action.37.desc.hc }
					fallen_empire_spiritualist = { text = action.37.desc.hg }
					fallen_empire_materialist = { text = action.37.desc.kk }
					fallen_empire_xenophobe = { text = action.37.desc.mi }
					fallen_empire_xenophile = { text = action.37.desc.eo }
					fallen_empire_machine = { text = action.37.desc.fme }
					awakened_fallen_empire_machine = { text = action.37.desc.fme }
					berserk_fallen_empire_machine = { text = action.37.desc.bme }
					metalhead = { text = action.37.desc.mh }
					fallen_empire_hive_mind = { text = action.37.desc.feh }
					awakened_fallen_empire_hive_mind_war = { text = action.37.desc.aew }
					awakened_fallen_empire_hive_mind_control = { text = action.37.desc.aew }
					awakened_fallen_empire_hive_mind_growth = { text = action.37.desc.aew }
					default = { text = action.37.desc.default }
				}
			}
		}
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no

		# These war goals have separate events
		fromfrom = {
			NOR = {
				using_war_goal = {
					type = wg_imperial_crusade
					owner = root
				}
				using_war_goal = {
					type = wg_galactic_civil_war_loyalists
					owner = root
				}
				using_war_goal = {
					type = wg_galactic_civil_war_rebels
					owner = root
				}
				#using_war_goal = {
				#	type = wg_seize_imperial_throne
				#	owner = root
				#}
				using_war_goal = {
					type = wg_restore_the_community
					owner = root
				}
			}
		}

		# If all of loser's systems are claimed, action.48 is fired instead
		AND = {
			fromfrom = {
				OR = {
					using_war_goal = {
						type = wg_conquest
						owner = root
					}
					using_war_goal = {
						type = wg_counterattack
						owner = root
					}
					using_war_goal = {
						type = wg_independence
						owner = root
					}
					using_war_goal = {
						type = wg_proxy_war
						owner = root
					}
				}
			}
			OR = {
				AND = {
					fromfrom = {
						any_attacker = { is_same_value = root }
					}
					from = {
						any_owned_planet = {
							is_colony = yes
							NOT = {
								fromfrom = {
									any_attacker = { has_claim = prevprev.solar_system }
								}
							}
						}
					}
				}
				AND = {
					fromfrom = {
						any_defender = { is_same_value = root }
					}
					from = {
						any_owned_planet = {
							is_colony = yes
							NOT = {
								fromfrom = {
									any_defender = { has_claim = prevprev.solar_system }
								}
							}
						}
					}
				}
			}
		}
	}

	option = {
		name = action.37.a
	}
}

# Lost War
country_event = {
	id = action.38
	title = action.38.name
	message_desc = action.38.message

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	desc = {
		trigger = {
			hidden:from = {
				exists = event_target:ratling_country
				is_same_empire = event_target:ratling_country
			}
		}
		text = action.38.desc.ketlings
	}

	desc = {
		trigger = {
			hidden:from = {
				is_megacorp = yes
			}
		}
		text = action.38.desc.corporate
	}

	desc = {
		trigger = {
			hidden:from = {
				switch = {
					trigger = has_ai_personality
					honorbound_warriors = { text = action.38.desc.hw }
					ruthless_capitalists = { text = action.38.desc.rc }
					peaceful_traders = { text = action.38.desc.pt }
					hegemonic_imperialists = { text = action.38.desc.hi }
					federation_builders = { text = action.38.desc.fb }
					xenophobic_isolationists = { text = action.38.desc.xi }
					hive_mind = { text = action.38.desc.hm }
					migrating_flock = { text = action.38.desc.mf }
					evangelising_zealots = { text = action.38.desc.ez }
					fanatic_purifiers = { text = action.38.desc.fp }
					democratic_crusaders = { text = action.38.desc.dc }
					slaving_despots = { text = action.38.desc.sd }
					decadent_hierarchy = { text = action.38.desc.dh }
					erudite_explorers = { text = action.38.desc.ee }
					spiritual_seekers = { text = action.38.desc.ss }
					harmonious_hierarchy = { text = action.38.desc.hc }
					fallen_empire_spiritualist = { text = action.38.desc.hg }
					fallen_empire_materialist = { text = action.38.desc.kk }
					fallen_empire_xenophobe = { text = action.38.desc.mi }
					fallen_empire_xenophile = { text = action.38.desc.eo }
					fallen_empire_machine = { text = action.38.desc.fme }
					awakened_fallen_empire_spiritualist = { text = action.38.desc.hg }
					awakened_fallen_empire_materialist = { text = action.38.desc.kk }
					awakened_fallen_empire_xenophobe = { text = action.38.desc.mi }
					awakened_fallen_empire_xenophile = { text = action.38.desc.eo }
					fallen_empire_machine = { text = action.38.desc.fme }
					awakened_fallen_empire_machine = { text = action.38.desc.fme }
					berserk_fallen_empire_machine = { text = action.38.desc.bme }
					metalhead = { text = action.38.desc.mh }
					fallen_empire_hive_mind = { text = action.38.desc.feh }
					awakened_fallen_empire_hive_mind_war = { text = action.38.desc.aew }
					awakened_fallen_empire_hive_mind_control = { text = action.38.desc.aec }
					awakened_fallen_empire_hive_mind_growth = { text = action.38.desc.aeg }
					default = { text = action.38.desc.default }
				}
			}
		}
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no

		# These war goals have separate events
		fromfrom = {
			NOR = {
				using_war_goal = {
					type = wg_imperial_crusade
					owner = root.from
				}
				using_war_goal = {
					type = wg_galactic_civil_war_loyalists
					owner = root.from
				}
				using_war_goal = {
					type = wg_galactic_civil_war_rebels
					owner = root.from
				}
				#using_war_goal = {
				#	type = wg_seize_imperial_throne
				#	owner = root.from
				#}
				using_war_goal = {
					type = wg_restore_the_community
					owner = root.from
				}
			}
		}
	}

	option = {
		name = {
			trigger = {
				from = {
					NOT = {
						has_ai_personality = awakened_fallen_empire_hive_mind_war
					}
				}
			}
			text = action.38.a
		}
		name = {
			trigger = {
				from = {
					has_ai_personality = awakened_fallen_empire_hive_mind_war
				}
			}
			text = action.38.b
		}
	}
}

# White Peace
country_event = {
	id = action.39
	title = action.39.name
	message_desc = action.39.message

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	desc = {
		trigger = {
			hidden:from.owner = {
				exists = event_target:ratling_country
				is_same_empire = event_target:ratling_country
			}
		}
		text = action.39.desc.ketlings
	}

	desc = {
		trigger = {
			hidden:from.owner = {
				switch = {
					trigger = has_ai_personality
					honorbound_warriors = { text = action.39.desc.hw }
					ruthless_capitalists = { text = action.39.desc.rc }
					peaceful_traders = { text = action.39.desc.pt }
					hegemonic_imperialists = { text = action.39.desc.hi }
					federation_builders = { text = action.39.desc.fb }
					xenophobic_isolationists = { text = action.39.desc.xi }
					hive_mind = { text = action.39.desc.hm }
					migrating_flock = { text = action.39.desc.mf }
					evangelising_zealots = { text = action.39.desc.ez }
					fanatic_purifiers = { text = action.39.desc.fp }
					democratic_crusaders = { text = action.39.desc.dc }
					slaving_despots = { text = action.39.desc.sd }
					decadent_hierarchy = { text = action.39.desc.dh }
					erudite_explorers = { text = action.39.desc.ee }
					spiritual_seekers = { text = action.39.desc.ss }
					harmonious_hierarchy = { text = action.39.desc.hc }
					fallen_empire_spiritualist = { text = action.39.desc.hg }
					fallen_empire_materialist = { text = action.39.desc.kk }
					fallen_empire_xenophobe = { text = action.39.desc.mi }
					fallen_empire_xenophile = { text = action.39.desc.eo }
					awakened_fallen_empire_spiritualist = { text = action.39.desc.hg }
					awakened_fallen_empire_materialist = { text = action.39.desc.kk }
					awakened_fallen_empire_xenophobe = { text = action.39.desc.mi }
					awakened_fallen_empire_xenophile = { text = action.39.desc.eo }
					fallen_empire_machine = { text = action.39.desc.fme }
					awakened_fallen_empire_machine = { text = action.39.desc.fme }
					berserk_fallen_empire_machine = { text = action.39.desc.bme }
					metalhead = { text = action.39.desc.mh }
					fallen_empire_hive_mind = { text = action.39.desc.feh }
					awakened_fallen_empire_hive_mind_war = { text = action.39.desc.aew }
					awakened_fallen_empire_hive_mind_control = { text = action.39.desc.aec }
					awakened_fallen_empire_hive_mind_growth = { text = action.39.desc.aeg }
					default = { text = action.39.desc.default }
				}
			}
		}
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
	}

	option = {
		name = action.39.a
	}
}

# Establish comms when entering Fallen Empire borders
fleet_event = {
	id = action.40
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		owner = { is_country_type = default }
		from = {
			OR = {
				AND = {
					exists = space_owner
					space_owner = {
						OR = {
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
						NOT = { has_communications = root.owner }
					}
				}
				any_neighbor_system = {
					exists = space_owner
					space_owner = {
						OR = {
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
						NOT = { has_communications = root.owner }
					}
				}
			}
		}
	}

	immediate = {
		from = {
			if = {
				limit = {
					exists = space_owner
					space_owner = {
						OR = {
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
						NOT = { has_communications = root.owner }
					}
				}
				space_owner = {
					save_event_target_as = contact_empire
				}
			}
			else = {
				random_neighbor_system = {
					limit = {
						exists = space_owner
						space_owner = {
							OR = {
								is_country_type = fallen_empire
								is_country_type = awakened_fallen_empire
							}
							NOT = { has_communications = root.owner }
						}
					}
					space_owner = {
						save_event_target_as = contact_empire
					}
				}
			}
		}
		owner = {
			establish_communications_no_message = event_target:contact_empire
			country_event = { id = action.1 }
		}
	}
}

# War is starting, notify people why their ships have gone MIA or why their wormhole stations got destroyed
country_event = {
	id = "action.41"
	title = "action.41.name"
	picture = "GFX_evt_federation_fleet"
	is_triggered_only = yes

	trigger = {
		from = {
			OR = {
				war_begun_num_fleets_gone_mia = {
					who = prev
					value > 0
				}
			}
		}
	}

	desc = {
		trigger = {
			text = "action.41.desc.a"
			text = "newline"
			hidden:from = {
				success_text = {
					text = "action.41.desc.b.1"
					war_begun_num_fleets_gone_mia = {
						who = prev
						value = 1
					}
				}
				success_text = {
					text = "action.41.desc.b"
					war_begun_num_fleets_gone_mia = {
						who = prev
						value > 1
					}
				}
			}
		}
	}

	option = {
		name = "OK"
	}
}


# Land appropriation
carrier_event = {
	id = action.42
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		owner = {
			OR = {
				has_policy_flag = appropriation_allowed
				has_ethic = ethic_gestalt_consciousness
			}
		}
		OR = {
			pop_amount > 1000
			AND = {
				pop_amount > 300
				free_housing < 100
			}
		}
	}

	immediate = {
		set_variable = {
			which = land_appropriated
			value = 0
		}
		random_list = {
			25 = {
				while = {
					count = 5
					if = {
						limit = {
							OR = {
								pop_amount > 1000
								AND = {
									pop_amount > 300
									free_housing < 100
								}
							}
						}
						random_owned_pop_group = {
							limit = {
								is_sapient = yes
								has_citizenship_rights = no
								NOT = {
									has_citizenship_type = {
										type = citizenship_assimilation
										country = owner
									}
								}
							}
							displace_pop_amount = {
								amount = 100
								random = 10
							}
							root = {
								change_variable = {
									which = land_appropriated
									value = 1
								}
							}
						}
					}
				}
			}
			25 = {
				while = {
					count = 4
					if = {
						limit = {
							OR = {
								pop_amount > 1000
								AND = {
									pop_amount > 300
									free_housing < 100
								}
							}
						}
						random_owned_pop_group = {
							limit = {
								is_sapient = yes
								has_citizenship_rights = no
								NOT = {
									has_citizenship_type = {
										type = citizenship_assimilation
										country = owner
									}
								}
							}
							displace_pop_amount = {
								amount = 100
								random = 10
							}
							root = {
								change_variable = {
									which = land_appropriated
									value = 1
								}
							}
						}
					}
				}
			}
			25 = {
				while = {
					count = 3
					if = {
						limit = {
							OR = {
								pop_amount > 1000
								AND = {
									pop_amount > 300
									free_housing < 100
								}
							}
						}
						random_owned_pop_group = {
							limit = {
								is_sapient = yes
								has_citizenship_rights = no
								NOT = {
									has_citizenship_type = {
										type = citizenship_assimilation
										country = owner
									}
								}
							}
							displace_pop_amount = {
								amount = 100
								random = 10
							}
							root = {
								change_variable = {
									which = land_appropriated
									value = 1
								}
							}
						}
					}
				}
			}
		}

		while = {
			count = land_appropriated

			owner = {
				if = {
					limit = {
						any_owned_planet = {
							free_housing < 100
							any_owned_pop_group = {
								is_sapient = yes
								has_citizenship_rights = yes
								OR = {
									is_pop_category = worker
									is_pop_category = simple_drone
								}
								can_live_on_planet = root
							}
						}
					}

					random_owned_planet = {
						limit = {
							free_housing < 100
							any_owned_pop_group = {
								is_sapient = yes
								has_citizenship_rights = yes
								OR = {
									is_pop_category = worker
									is_pop_category = simple_drone
								}
								can_live_on_planet = root
							}
						}

						random_owned_pop_group = {
							limit = {
								is_sapient = yes
								has_citizenship_rights = yes
								OR = {
									is_pop_category = worker
									is_pop_category = simple_drone
								}
								can_live_on_planet = root
							}

							resettle_pop_group = {
								POP_GROUP = this
								PLANET = root
								AMOUNT = 100
							}
						}
					}
				}
				else_if = {
					limit = {
						any_owned_planet = {
							any_owned_pop_group = {
								is_sapient = yes
								has_citizenship_rights = yes
								OR = {
									is_pop_category = worker
									is_pop_category = simple_drone
								}
								can_live_on_planet = root
							}
						}
					}

					random_owned_planet = {
						limit = {
							any_owned_pop_group = {
								is_sapient = yes
								has_citizenship_rights = yes
								OR = {
									is_pop_category = worker
									is_pop_category = simple_drone
								}
								can_live_on_planet = root
							}
						}

						random_owned_pop_group = {
							limit = {
								is_sapient = yes
								has_citizenship_rights = yes
								OR = {
									is_pop_category = worker
									is_pop_category = simple_drone
								}
								can_live_on_planet = root
							}

							resettle_pop_group = {
								POP_GROUP = this
								PLANET = root
								AMOUNT = 100
							}
						}
					}
				}
			}
		}
		clear_variable = land_appropriated

		if = {
			limit = {
				owner = { NOT = { has_ethic = ethic_gestalt_consciousness } }
			}
			add_modifier = {
				modifier = "land_appropriation"
				years = 5
			}
		}
	}
}

# A war has ended, give war participants of opposite side forced open borders.
# Root = Winner Warleader
# From = Loser Warleader
# FromFrom = War
country_event = {
	id = action.44
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		fromfrom = {
			every_war_participant = {
				limit = {
					fromfrom = {
						is_war_participant = {
							who = prev
							side = Root
						}
					}
				}
				fromfrom = {
					every_war_participant = {
						limit = {
							fromfrom = {
								is_war_participant = {
									who = prev
									side = Root.from
								}
							}
						}
						set_closed_borders = {
							who = prevprev
							status = no
							forced = 5
						}
					}
				}
			}
		}
	}
}

# A white peace has been signed, give both sides forced open borders towards the opponents.
# Root = Recipient
# From = Actor
# FromFrom = Main Attacker
# FromFromFrom = Main Defender
# FromFromFromFrom = War
country_event = {
	id = action.45
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		# First Country
		country_event = {
			id = action.44
			scopes = {
				from = from
				fromfrom = fromfromfromfrom
			}
		}
		# Second Country
		from = {
			country_event = {
				id = action.44
				scopes = {
					from = root
					fromfrom = fromfromfromfrom
				}
			}
		}
	}
}

# Star Charts have been traded
carrier_event = {
	id = action.46
	hide_window = yes
	is_triggered_only = yes

	pre_triggers = {
		has_owner = yes
	}

	trigger = {
		NOT = { exists = fromfrom }
		exists = owner
		owner = {
			OR = {
				is_country_type = default
				is_country_type = fallen_empire
			}
			NOT = { has_established_contact = from }
		}
	}

	immediate = {
		owner = {
			from = {
				establish_contact = { who = prev location = prevprev }
			}
		}
	}
}

# Remove election-filler leaders when ruler is set
country_event = {
	id = action.47
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		every_owned_leader = {
			limit = {
				has_leader_flag = temp_election_leader
				is_ruler = no
			}
			kill_leader = {
				show_notification = no
			}
		}
	}
}

# Country is destroyed after losing war
country_event = {
	id = action.48
	title = action.37.name
	message_desc = action.37.message

	picture_event_data = {
		portrait = FROM
		planet_background = FROM
		graphical_culture = FROM
		city_level = FROM
		room = FROM.ruler
	}

	desc = {
		trigger = {
			from = {
				has_generic_government = yes
				is_galactic_emperor = no
			}
		}
		text = action.48.desc.generic.1
		text = action.48.desc.generic.2
		text = action.48.desc.generic.3
	}
	desc = {
		trigger = {
			from = {
				has_spiritualist_government = yes
				is_galactic_emperor = no
			}
		}
		text = action.48.desc.spiritualist.1
		text = action.48.desc.spiritualist.2
		text = action.48.desc.spiritualist.3
	}
	desc = {
		trigger = {
			from = {
				has_militarist_government = yes
				is_galactic_emperor = no
			}
		}
		text = action.48.desc.militarist.1
		text = action.48.desc.militarist.2
		text = action.48.desc.militarist.3
	}
	desc = {
		trigger = {
			from = {
				has_pacifist_government = yes
				is_galactic_emperor = no
			}
		}
		text = action.48.desc.pacifist.1
		text = action.48.desc.pacifist.2
		text = action.48.desc.pacifist.3
	}
	desc = {
		trigger = {
			from = {
				has_materialist_government = yes
				is_galactic_emperor = no
			}
		}
		text = action.48.desc.materialist.1
		text = action.48.desc.materialist.2
		text = action.48.desc.materialist.3
	}
	desc = {
		trigger = {
			from = {
				is_megacorp = yes
				is_galactic_emperor = no
			}
		}
		text = action.48.desc.megacorp.1
		text = action.48.desc.megacorp.2
		text = action.48.desc.megacorp.3
	}
	desc = {
		trigger = {
			from = {
				is_hive_empire = yes
				is_galactic_emperor = no
			}
		}
		text = action.48.desc.hive.1
		text = action.48.desc.hive.2
		text = action.48.desc.hive.3
	}
	desc = {
		trigger = {
			from = {
				is_machine_empire = yes
				is_galactic_emperor = no
			}
		}
		text = action.48.desc.machine.1
		text = action.48.desc.machine.2
		text = action.48.desc.machine.3
	}
	desc = {
		trigger = {
			from = { has_ai_personality = fallen_empire_spiritualist }
		}
		text = action.48.desc.fe_spiritualist
	}
	desc = {
		trigger = {
			from = { has_ai_personality = fallen_empire_materialist }
		}
		text = action.48.desc.fe_materialist
	}
	desc = {
		trigger = {
			from = { has_ai_personality = fallen_empire_xenophobe }
		}
		text = action.48.desc.fe_xenophobe
	}
	desc = {
		trigger = {
			from = { has_ai_personality = fallen_empire_xenophile }
		}
		text = action.48.desc.fe_xenophile
	}
	desc = {
		trigger = {
			from = {
				OR = {
					has_ai_personality = fallen_empire_machine
					has_ai_personality = awakened_fallen_empire_machine
					has_ai_personality = berserk_fallen_empire_machine
				}
			}
		}
		text = action.37.desc.fme
	}
	desc = {
		trigger = {
			from = { is_galactic_emperor = yes }
		}
		text = action.48.desc.gal_emperor
	}
	desc = { # Fallback
		trigger = {
			from = {
				has_generic_government = no
				has_spiritualist_government = no
				has_militarist_government = no
				has_pacifist_government = no
				has_materialist_government = no
				is_megacorp = no
				is_hive_empire = no
				is_machine_empire = no
				is_galactic_emperor = no
				NOR = {
					has_ai_personality = fallen_empire_spiritualist
					has_ai_personality = fallen_empire_materialist
					has_ai_personality = fallen_empire_xenophobe
					has_ai_personality = fallen_empire_xenophile
					has_ai_personality = fallen_empire_machine
					has_ai_personality = awakened_fallen_empire_machine
					has_ai_personality = berserk_fallen_empire_machine
				}
			}
		}
		text = action.37.desc.default
	}

	diplomatic = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		fromfrom = {
			OR = {
				using_war_goal = {
					type = wg_conquest
					owner = root
				}
				using_war_goal = {
					type = wg_counterattack
					owner = root
				}
				using_war_goal = {
					type = wg_independence
					owner = root
				}
				using_war_goal = {
					type = wg_proxy_war
					owner = root
				}
			}
		}
		OR = {
			AND = {
				fromfrom = {
					any_attacker = { is_same_value = root }
				}
				NOT = {
					from = {
						any_owned_planet = {
							is_colony = yes
							NOT = {
								fromfrom = {
									any_attacker = { has_claim = prevprev.solar_system }
								}
							}
						}
					}
				}
			}
			AND = {
				fromfrom = {
					any_defender = { is_same_value = root }
				}
				NOT = {
					from = {
						any_owned_planet = {
							is_colony = yes
							NOT = {
								fromfrom = {
									any_defender = { has_claim = prevprev.solar_system }
								}
							}
						}
					}
				}
			}
		}
	}

	option = {
		name = action.48.a
		trigger = { has_generic_government = yes }
	}
	option = {
		name = action.48.b
		trigger = { has_spiritualist_government = yes }
	}
	option = {
		name = action.48.c
		trigger = { has_militarist_government = yes }
	}
	option = {
		name = action.48.d
		trigger = { has_pacifist_government = yes }
	}
	option = {
		name = action.48.e
		trigger = { has_materialist_government = yes }
	}
	option = {
		name = action.48.f
		trigger = { is_megacorp = yes }
	}
	option = {
		name = action.48.g
		trigger = { is_hive_empire = yes }
	}
	option = {
		name = action.48.h
		trigger = { is_machine_empire = yes }
	}
	option = { # Fallback
		name = action.48.i
		trigger = {
			has_generic_government = no
			has_spiritualist_government = no
			has_militarist_government = no
			has_pacifist_government = no
			has_materialist_government = no
			is_megacorp = no
			is_hive_empire = no
			is_machine_empire = no
		}
	}
}

# Outside Context
country_event = {
	id = action.51
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		from = {
			is_country_type = primitive
			has_country_flag = humans_machine_age
			has_country_flag = machine_age
		}
	}

	immediate = {
		set_country_flag = outsidecontext
	}
}

# If robots are unlocked, create built species
country_event = {
	id = action.56
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_built_species = no
		has_technology = tech_robotic_workers
	}

	immediate = {
		create_built_robot_species = yes
	}
}

# Country Destroyed Notification Gatekeeper
country_event = {
	id = action.61
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		NOR = {
			has_global_flag = synth_queen_victorious
			has_country_flag = supress_country_destroyed_message
		}
	}

	immediate = {
		if = {
			limit = {
				exists = from
			}
			from = {
				save_global_event_target_as = destroyer_country
				set_country_flag = has_won_war
			}
		}
		if = {
			limit = {
				is_nomadic = yes
				any_subject = {
					has_origin = origin_nomadic_purger
				}
			}
			every_subject = {
				limit = {
					has_origin = origin_nomadic_purger
				}
				destroy_country = yes
			}
		}
		# If the MSI got destroyed by someone else, payback empires will get a follow-up
		# after action.62
		if = {
			limit = {
				OR = {
					has_country_flag = payback_stole_revenge
					has_origin = origin_slavers
				}
			}
			every_playable_country = {
				limit = {
					has_origin = origin_payback
					NOT = { is_same_value = event_target:destroyer_country }
				}
				set_country_flag = payback_stolen_revenge
			}
		}
		# If MSI gets destroyed by Payback, fire the on_war_won event after the country destroyed notification
		if = {
			limit = {
				OR = {
					has_country_flag = payback_stole_revenge
					has_origin = origin_slavers
				}
				event_target:destroyer_country = {
					has_origin = origin_payback
					has_event_chain = payback_make_them_pay_swords_chain
					is_at_war_with = prev
				}
			}
			event_target:destroyer_country = { set_country_flag = payback_killed_MSI }
		}

		if = {
			limit = {
				exists = event_target:destroyer_country
				event_target:destroyer_country = {
					has_origin = origin_evolutionary_predators
					is_mutation_authority = yes
					is_dictatorial_authority = yes
				}
				is_country_type = default
			}
			species = {
				apex_predator_switch = {
					COUNTRY = event_target:destroyer_country
				}
			}
		}

		if = {
			limit = {
				has_country_flag = targeted_by_fe_hive_war_task
			}
			random_playable_country = {
				limit = {
					reverse_has_relation_flag = {
						who = prev
						flag = targeted_by_fe_hive_war_task
					}
				}
				create_happy_hive_fe_task_message = { FALLEN_EMPIRE = event_target:fallen_empire_hive_war }
			}
		}

		every_subject = {
			set_subject_of = {
				who = none
			}
		}
		if = {
			limit = {
				any_war = {
					using_war_goal = {
						owner = root
						type = wg_leave_hegemony
					}
				}
			}
			random_country = {
				limit = {
					is_at_war_with = root
					any_war = {
						using_war_goal = {
							owner = root
							type = wg_leave_hegemony
						}
						is_war_participant = { who = prev side = defenders }
						is_war_participant = { who = root side = attackers }
					}
				}
				federation = {
					change_variable = {
						which = federation_secession_war
						value = -1
					}
				}
			}
		}
		if = {
			limit = {
				is_subject = no
				OR = {
					is_country_type = default
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
				NOT = { has_country_flag = silence_destroy_event }
			}
			if = {
				limit = {
					is_country_type = default
					NOT = {
						any_war = {
							using_war_goal = {
								owner = root
								type = wg_machine_uprising
							}
						}
					}
				}
				every_playable_country = {
					limit = {
						has_communications = root
						NOT = { is_same_value = root }
					}
					country_event = { id = action.62 }
				}
				random_playable_country = {
					observer_event = { id = observer.2 }
				}
			}
			if = {
				limit = {
					is_country_type = default
					any_war = {
						using_war_goal = {
							owner = root
							type = wg_machine_uprising
						}
					}
				}
				every_playable_country = {
					limit = {
						has_communications = root
						NOT = {
							is_same_value = event_target:destroyer_country
						}
					}
					if = {
						limit = {
							event_target:destroyer_country = {
								OR = {
									is_machine_empire = yes
									is_individual_machine = yes
								}
							}
						}
						country_event = { id = syndaw.1030 }
					}
					else = {
						country_event = { id = syndaw.1035 }
					}
				}
				event_target:destroyer_country = {
					if = {
						limit = {
							OR = {
								is_machine_empire = yes
								is_individual_machine = yes
							}
						}
						country_event = { id = syndaw.1201 }
					}
					else = {
						country_event = { id = syndaw.1206 }
					}
				}
			}
			else_if = {
				limit = {
					is_fallen_empire = yes
					NOT = { has_country_flag = got_assimialted }
				}
				every_playable_country = {
					limit = {
						has_communications = root
						NOT = { is_same_value = root }
					}
					country_event = { id = action.63 }
				}
				random_playable_country = {
					observer_event = { id = observer.3 }
				}
			}
		}
	}
}

# Country Destroyed Notification (default countries)
country_event = {
	id = action.62
	title = "action.62.name"
	desc = "action.62.desc"
	show_sound = event_default
	picture = "GFX_evt_city_ruins"
	is_triggered_only = yes

	option = {
		name = OK
	}

	option = {
		name = "action.62.memorialist.a"
		exclusive_trigger = {
			is_memorialist_empire = yes
		}
	}

	after = {
		if = {
			limit = {
				has_country_flag = payback_stolen_revenge
			}
			country_event = { id = origin.4070 days = 15 }
		}
		else_if = {
			limit = {
				has_country_flag = payback_killed_MSI
			}
			country_event = { id = origin.4061 }
		}
	}
}

# Country Destroyed Notification (fallen/awakened empires)
country_event = {
	id = action.63
	title = "action.63.name"
	desc = "action.63.desc"
	show_sound = event_default
	picture = "GFX_evt_city_ruins"
	is_triggered_only = yes

	option = {
		name = OK
	}

	option = {
		name = "action.62.memorialist.a"
		exclusive_trigger = {
			OR = {
				has_valid_civic = civic_memorialist
				has_valid_civic = civic_hive_memorialist
				has_valid_civic = civic_machine_memorialist
			}
		}
	}
}

# Clear deposits after some terraforming actions
carrier_event = {
	id = action.68
	is_triggered_only = yes
	hide_window = yes

	immediate = {
		if = {
			limit = {
				is_planet_class = pc_machine
			}
			#clear_deposits = yes
			every_deposit = {
				limit = {
					NOR = { # rare non-event deposits should not be cleared
						is_deposit_type = d_dust_caverns
						is_deposit_type = d_dust_desert
						is_deposit_type = d_bubbling_swamp
						is_deposit_type = d_fuming_bog
						is_deposit_type = d_crystalline_caverns
						is_deposit_type = d_crystal_forest
						is_deposit_type = d_crystal_reef
						is_deposit_type = d_betharian_deposit
						is_deposit_type = d_alien_pets_deposit
						is_deposit_type = d_nanites_medium			# Tranformation situation
						is_deposit_type = d_nanites_small			# Tranformation situation
						is_deposit_type = d_nanites_tiny			# Tranformation situation
						is_deposit_type = d_living_metal_medium		# Tranformation situation
						is_deposit_type = d_living_metal_medium		# Tranformation situation
						is_deposit_type = d_living_metal_tiny		# Tranformation situation
						is_deposit_type = d_virtual_power_medium	# Tranformation situation
						is_deposit_type = d_virtual_power_small		# Tranformation situation
						is_deposit_type = d_virtual_power_tiny		# Tranformation situation
						has_deposit_flag = keep_deposit_on_terraform
					}
				}
				remove_deposit = yes
			}
			remove_modifier = "natural_beauty"
			remove_modifier = "atmospheric_aphrodisiac"
			remove_modifier = "atmospheric_hallucinogen"
			remove_modifier = "lush_planet"
			remove_modifier = "paradise_made"
			remove_modifier = "death_world"
			if = {
				limit = {
					any_owned_pop_group = {
						NOR = {
							has_trait = trait_cybernetic
							has_trait = trait_machine_unit
							has_trait = trait_mechanical
						}
					}
				}
				add_deposit = d_organic_slurry
				every_owned_pop_group = {
					limit = {
						NOR = {
							has_trait = trait_cybernetic
							has_trait = trait_machine_unit
							has_trait = trait_mechanical
						}
					}
					if = {
						limit = {
							planet.owner = { has_valid_civic = civic_machine_terminator }
						}
						planet.owner = {
							add_resource = { unity = 100 }
						}
					}
					kill_single_pop = yes
				}
			}
		}
		if = {
			limit = {
				is_planet_class = pc_nanotech
			}
			every_deposit = {
				limit = {
					NOT = {
						is_deposit_type = d_nanotech_devastation
					}
				}
				remove_deposit = yes
			}
			remove_modifier = "natural_beauty"
			remove_modifier = "atmospheric_aphrodisiac"
			remove_modifier = "atmospheric_hallucinogen"
			remove_modifier = "lush_planet"
			remove_modifier = "paradise_made"
		}
		if = {
			limit = {
				is_planet_class = pc_hive
			}
			#clear_deposits = yes
			every_deposit = {
				limit = {
					NOR = { # rare non-event deposits should not be cleared
						is_deposit_type = d_dust_caverns
						is_deposit_type = d_dust_desert
						is_deposit_type = d_bubbling_swamp
						is_deposit_type = d_fuming_bog
						is_deposit_type = d_crystalline_caverns
						is_deposit_type = d_crystal_forest
						is_deposit_type = d_crystal_reef
						is_deposit_type = d_betharian_deposit
						is_deposit_type = d_alien_pets_deposit
						is_deposit_type = d_tree_of_life_home
						is_deposit_type = d_tree_of_life_colony
						is_deposit_type = d_lithoid_crater
						is_deposit_type = d_progenitor
					}
				}
				remove_deposit = yes
			}
			remove_modifier = "natural_beauty"
			remove_modifier = "atmospheric_aphrodisiac"
			remove_modifier = "atmospheric_hallucinogen"
			remove_modifier = "lush_planet"
		}

		if = {
			limit = {
				is_planet_class = pc_volcanic
				has_modifier = "obsidian_lakes"
			}
			remove_modifier = "obsidian_lakes_volcanic"
			add_modifier = { modifier = obsidian_lakes_volcanic }
		}

		if = {
			limit = {
				is_same_planet_class = no #If we didn't change planet class we don't need to clear modifiers
			}
			remove_modifier = "bleak_planet"
			remove_modifier = "dangerous_wildlife"
			remove_modifier = "hazardous_weather"
			remove_modifier = "wild_storms"
			remove_modifier = "irradiated_planet"
			remove_modifier = "second_home"
			remove_modifier = "hyper_ecosystem"
			remove_modifier = "docile_fauna"
			remove_modifier = "obsidian_lakes"
			remove_modifier = "previously_terraformed_planet"
			remove_modifier = "wooden_planet"
			remove_modifier = "crimson_crawlers"
			remove_deposit = d_radiotrophic_preserve
			remove_modifier = "molten_mineral_rivers"
			remove_modifier = "ship_junkyard"
			remove_modifier = "hostile_planet"
			remove_modifier = "terraforming_candidate"
			remove_modifier = "frozen_terraforming_candidate"
			remove_modifier = "toxic_terraforming_candidate"
			remove_modifier = "pm_wenkwort_gardens"
			remove_modifier = "pm_wenkwort_zen"
			remove_modifier = "pm_wenkwort_custodian"
			set_carrier_flag = colony_event #Make it so that colony events don't fire on terraformed worlds
		}

		if = {
			limit = {
				NOT = {
					is_planet_class = pc_gaia
				}
				OR = {
					is_active_resolution = "resolution_ecology_environmental_control_board"
					is_active_resolution = "resolution_ecology_paradise_initiative"
				}
			}
			from.owner = {
				set_timed_country_flag = { flag = resolution_breached_terraformed days = 3600 }
			}
		}
		if = {
			limit = {
				exists = mining_station
			}
			mining_station = {
				delete_fleet = this
			}
		}
		if = {
			limit = {
				exists = research_station
			}
			research_station = {
				delete_fleet = this
			}
		}

		if = {
			limit = {
				has_modifier = holy_planet
				any_country = {
					has_ai_personality_behaviour = holy_planets # not awakened
					NOT = { is_at_war_with = from }
				}
				is_planet_class = pc_nuked
			}
			remove_modifier = holy_planet
			random_country = {
				limit = {
					has_ai_personality_behaviour = holy_planets
					NOT = { is_at_war_with = from }
				}
				save_event_target_as = outraged_FE
			}
			from = {
				save_event_target_as = FE_outrager
				country_event = { id = toxoids.40 days = 5 }
			}
		}
		if = {
			limit = { is_variable_set = relentless_industrialists_var }
			clear_variable = relentless_industrialists_var
		}
	}
}

####################
# SYNTH LEADERS DIE
####################

# via 'on_synth_leader_malfunction'

# Science Vessel Leader dies (see also: syndaw.21)
country_event = {
	id = action.71
	title = action.71.name
	desc = action.71.desc
	inline_script = {
		script = events/biogenesis_event_art
		OWNER = owner
		REGULAR_PICTURE = GFX_evt_ship_in_orbit
		BIOSHIP_PICTURE = GFX_evt_bio_ships_orbiting
	}
	show_sound = event_ship_bridge
	location = event_target:malfunctioning_leader_fleet
	is_triggered_only = yes

	trigger = {
		any_owned_leader = {
			NOT = { has_leader_flag = leader_death_events_blocked }
			leader_class = scientist
			exists = fleet
			is_mechanical_species = yes
		}
	}

	immediate = {
		random_owned_leader = {
			limit = {
				NOT = { has_leader_flag = leader_death_events_blocked }
				leader_class = scientist
				exists = fleet
				is_mechanical_species = yes
			}
			save_event_target_as = malfunctioning_leader
			fleet = {
				save_event_target_as = malfunctioning_leader_fleet
			}
			kill_leader = { show_notification = no }
		}
	}

	option = {
		name = UNFORTUNATE
	}
}

# Head of Research dies (see also: 'syndaw.22')
country_event = {
	id = action.72
	title = action.72.name
	desc = action.72.desc
	# desc = action.73.desc
	desc = action.74.desc
	picture = GFX_evt_news_room
	show_sound = event_ship_bridge
	location = capital_scope
	is_triggered_only = yes

	trigger = {
		any_owned_leader = {
			NOT = { has_leader_flag = leader_death_events_blocked }
			is_councilor_type = councilor_research
			is_ruler = no
			is_mechanical_species = yes
		}
	}

	immediate = {
		random_owned_leader = {
			limit = {
				NOT = { has_leader_flag = leader_death_events_blocked }
				leader_class = scientist
				is_councilor = yes
				is_ruler = no
				is_mechanical_species = yes
			}
			save_event_target_as = malfunctioning_leader
			kill_leader = { show_notification = no }
		}
	}

	option = {
		name = UNFORTUNATE
	}
}

# Admiral dies (see also: 'syndaw.25')
country_event = {
	id = action.75
	title = action.75.name
	desc = action.75.desc
	picture = GFX_evt_space_debris
	show_sound = event_ship_bridge
	location = event_target:malfunctioning_leader_fleet
	is_triggered_only = yes

	trigger = {
		any_owned_leader = {
			NOT = { has_leader_flag = leader_death_events_blocked }
			leader_class = commander
			exists = fleet
			is_mechanical_species = yes
		}
	}

	immediate = {
		random_owned_leader = {
			limit = {
				leader_class = commander
				exists = fleet
				is_mechanical_species = yes
			}
			save_event_target_as = malfunctioning_leader
			fleet = {
				save_event_target_as = malfunctioning_leader_fleet
			}
			kill_leader = { show_notification = no }
		}
	}

	option = {
		name = UNFORTUNATE
	}
}

# Governor dies (see also: 'action.76')
country_event = {
	id = action.76
	title = action.76.name
	desc = action.76.desc
	picture = GFX_evt_throne_room
	show_sound = event_ship_bridge
	location = event_target:malfunctioning_leader_planet
	is_triggered_only = yes

	trigger = {
		any_owned_planet = {
			exists = leader
			leader = {
				NOT = { has_leader_flag = leader_death_events_blocked }
				is_ruler = no
				is_mechanical_species = yes
			}
		}
	}

	immediate = {
		random_owned_planet = {
			limit = {
				exists = leader
				leader = {
					is_ruler = no
					is_mechanical_species = yes
				}
			}
			save_event_target_as = malfunctioning_leader_planet
			leader = {
				save_event_target_as = malfunctioning_leader
				kill_leader = { show_notification = no }
			}
		}
	}

	option = {
		name = UNFORTUNATE
	}
}


# Removes existing Android Armies when AI is Outlawed, and Robotic Armies when Robot Workers are Outlawed
country_event = {
	id = action.80
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		OR = {
			AND = {
				last_changed_policy = artificial_intelligence_policy
				has_policy_flag = ai_outlawed
				any_owned_army = {
					OR = {
						army_type = robotic_army
						army_type = robotic_defense_army
					}
				}
			}
			AND = {
				last_changed_policy = robot_pop_policy
				has_policy_flag = robots_outlawed
				any_owned_army = {
					OR = {
						army_type = robotic_army
						army_type = robotic_defense_army
					}
				}
			}
		}
	}

	immediate = {
		if = {
			limit = { last_changed_policy = artificial_intelligence_policy has_policy_flag = ai_outlawed }
			every_owned_army = {
				limit = {
					OR = {
						army_type = robotic_army
						army_type = robotic_defense_army
					}
				}
				remove_army = yes
			}
		}
		else_if = {
			limit = { last_changed_policy = robot_pop_policy has_policy_flag = robots_outlawed }
			every_owned_army = {
				limit = {
					OR = {
						army_type = robotic_army
						army_type = robotic_defense_army
					}
				}
				remove_army = yes
			}
		}
	}
}

# Planet is turned into tomb world by special bombing stance
carrier_event = {
	id = action.81
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		OR = {
			has_orbital_bombardment_stance = armageddon
			has_orbital_bombardment_stance = pox
		}
		from = {
			NOT = {
				is_country_type = awakened_marauders
			}
		}
		habitable_planet = yes
		count_owned_pop_amount = {
			count <= 50
		}
	}

	immediate = {
		owner = {
			if = {
				limit = {
					owner = {
						is_at_war_with = from
					}
				}
				add_static_war_exhaustion = {
					attacker = from
					location = root
					value_for_planet_destruction = 0.5
				}
			}
			if = {
				limit = {
					NAND = {
						has_origin = origin_progenitor_hive
						root = { is_capital = yes }
					}
				}
				country_event = { id = action.82 }
			}
			else = {
				country_event = { id = origin.3265 }
			}
		}
		from = { country_event = { id = action.83 } }
		change_pc = pc_nuked
		set_planet_flag = nuked_planet_anomalies_disabled
		remove_all_buildings = yes
		reroll_deposits = yes
		tomb_world_modifier_cleanup = yes
		set_carrier_flag = armageddon_nuked
	}
}

# Planet is turned into tomb world by Armageddon bombing stance (former owner)
country_event = {
	id = action.82
	title = "action.82.name"
	picture = GFX_evt_nuclear_explosion
	desc = action.82.desc
	show_sound = event_super_explosion
	location = from

	is_triggered_only = yes

	option = {
		name = action.82.a
		custom_tooltip = bombed_to_tomb_world
	}
}

# Planet is turned into tomb world by Armageddon bombing stance (bombarder)
country_event = {
	id = action.83
	title = "action.82.name"
	picture = GFX_evt_nuclear_explosion
	desc = action.83.desc
	show_sound = event_super_explosion
	location = from

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				has_ascension_perk = ap_become_the_crisis
			}
			complete_crisis_objective = crisobj_destroy_worlds
		}
	}

	option = {
		name = EXCELLENT
		custom_tooltip = bombed_to_tomb_world
	}
}

# Planet conquered
carrier_event = {
	id = action.84
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		owner = {
			set_timed_country_flag = { flag = imperialist_conquest_timed_flag days = 3600 }
		}
	}
}

# Planets in mixed-ownership systems fall to starbase owner
event = {
	id = action.85
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		any_country = {
			NOT = { is_country_type = primitive }
			any_owned_planet = {
				exists = starbase
				starbase = {
					owner = {
						NOR = {
							is_same_value = prevprevprev
							is_at_war_with = prevprevprev
						}
					}
				}
			}
		}
	}

	immediate = {
		every_galaxy_planet = {
			limit = {
				exists = owner
				owner = {
					OR = {
						is_country_type = default
						is_country_type = fallen_empire
						is_country_type = awakened_fallen_empire
					}
				}
				is_nomadic_synaptic_lathe = no
				exists = starbase
				starbase = {
					exists = owner
					owner = {
						OR = {
							is_country_type = default
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
						NOR = {
							is_same_value = prevprev.owner
							is_at_war_with = prevprev.owner
						}
						NOT = {
							has_active_event = {
								preftl.180 #event to decide fate of pre-ftl civ
							}
						}
					}
				}
			}
			carrier_event = { id = action.86 } # planet flips to starbase owner
		}
	}
}

carrier_event = {
	id = action.86
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		owner = { save_event_target_as = former_planet_owner }
		starbase.owner = { save_event_target_as = new_planet_owner }

		set_owner = event_target:new_planet_owner # flip planet

		event_target:former_planet_owner = {
			country_event = { id = action.87 } # notification to former owner
		}

		#owner = {
		#	country_event = { id = action.87 } # notification to former owner
		#}

		event_target:new_planet_owner = {
			country_event = { id = action.88 } # notification to new owner
		}

		#starbase.owner = {
		#	country_event = { id = action.88 } # notification to new owner
		#}

		#set_owner = event_target:new_planet_owner # flip planet
	}
}

country_event = {
	id = action.87
	title = action.87.name
	desc = action.87.desc
	picture = GFX_evt_star_chart
	show_sound = event_default
	location = from

	is_triggered_only = yes

	option = {
		name = UNFORTUNATE
		tooltip = {
			from = {
				set_owner = event_target:new_planet_owner
			}
		}
	}
}

country_event = {
	id = action.88
	title = action.88.name
	desc = action.88.desc
	picture = GFX_evt_star_chart
	show_sound = event_default
	location = from

	is_triggered_only = yes

	immediate = {
		event_target:new_planet_owner = {
			if = {
				limit = {
					has_origin = origin_mindwardens
					from = {
						OR = {
							has_carrier_flag = exiled_planet_1
							has_carrier_flag = exiled_planet_2
						}
					}
				}
				from = {
					save_event_target_as = current_planet
				}
				country_event = { id = shroud.6700 days = 1 }
			}
		}
	}

	option = {
		name = OK
		tooltip = {
			from = {
				set_owner = event_target:new_planet_owner
			}
		}
	}
}

# Remove modifiers on owner change
carrier_event = {
	id = action.89
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		remove_modifier = planet_population_control
		remove_modifier = planet_growth_discouraged
		remove_modifier = hunter_killer_drones
		remove_modifier = compliance_protocols
		remove_modifier = martial_law
		remove_modifier = martial_law_knights
		remove_modifier = crime_lord_deal
		remove_modifier = crime_lord_deal_broken
		remove_modifier = anticrime_campaign
		remove_modifier = penal_colony
		remove_modifier = resort_colony
		remove_modifier = slave_colony
		remove_modifier = gang_wars
		remove_modifier = gang_wars_experimenters
		remove_modifier = drone_corruption
		remove_modifier = drone_deviancy
		remove_modifier = drone_deviancy_experimenters
		remove_modifier = criminal_underworld
		remove_modifier = criminal_underworld_experimenters
		remove_modifier = center_of_drug_trade
		remove_modifier = center_of_drug_trade_experimenters
		remove_modifier = mob_rule
		remove_modifier = mob_rule_experimenters
		remove_modifier = crime_wave
		remove_modifier = smuggler_activity
		remove_modifier = substance_abuse
		remove_modifier = bribed_officials
		remove_modifier = cartel_war
		remove_modifier = travel_advisory
		remove_modifier = trade_pilfering
		remove_modifier = protection_racket
		remove_modifier = cartel_war
		remove_modifier = ringleader_killed
		remove_modifier = corrupt_network_terminated
		remove_modifier = unemployment_benefits
		remove_modifier = activity_program
		remove_modifier = standby_mode
		if = {
			limit = { exists = owner }
			owner = {
				try_remove_penal_experimental_mod = yes
			}
		}
	}
}

event = {
	id = action.90
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		any_country = {
			is_nomadic = no
			OR = {
				is_country_type = default
				is_fallen_empire = yes
			}
			any_owned_planet = {
				is_controlled_by = PREV
				solar_system = {
					NOT = {
						exists = starbase
					}
				}
			}
		}
	}
	immediate = {
		every_system = {
			limit = {
				NOT = { exists = starbase }
				any_system_planet_colony = {
					carrier_is_type = planet
					exists = owner
					has_ground_combat = no
					OR = {
						has_shroud_dlc = no
						AND = {
							has_shroud_dlc = yes
							NOT = {
								has_planet_flag = exile_planet
							}
						}
					}
					owner = {
						OR = {
							AND = {
								is_country_type = default
								is_nomadic = no
							}
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
					}
					solar_system = {
						NOR = {
							any_fleet_in_system = {
								exists = owner
								owner = {
									NOT = { is_same_value = prevprevprev.owner }
									OR = {
										is_hostile = prevprevprev.owner
										is_at_war_with = prevprevprev.owner
									}
								}
								is_cloaked = no
							}
							any_fleet_in_system = {
								exists = controller
								controller = {
									NOT = { is_same_value = prevprevprev.owner }
									OR = {
										is_hostile = prevprevprev.owner
										is_at_war_with = prevprevprev.owner
									}
								}
								is_cloaked = no
							}
							any_system_planet_colony = {
								exists = owner
								NOT = { is_same_value = prevprev }
								owner = {
									NOT = { is_same_value = prevprevprev.owner }
									OR = {
										is_country_type = default
										is_country_type = fallen_empire
										is_country_type = awakened_fallen_empire
									}
								}
							}
						}
					}
				}
			}
			random_system_planet = {
				limit = {
					is_colony = yes
					exists = owner
					has_ground_combat = no
					OR = {
						has_shroud_dlc = no
						AND = {
							has_shroud_dlc = yes
							NOT = {
								has_planet_flag = exile_planet
							}
						}
					}
					owner = {
						OR = {
							is_country_type = default
							is_country_type = fallen_empire
							is_country_type = awakened_fallen_empire
						}
					}
					solar_system = {
						NOR = {
							any_fleet_in_system = {
								exists = owner
								owner = {
									NOT = { is_same_value = prevprevprev.owner }
									OR = {
										is_hostile = prevprevprev.owner
										is_at_war_with = prevprevprev.owner
									}
								}
								is_cloaked = no
							}
							any_fleet_in_system = {
								exists = controller
								controller = {
									NOT = { is_same_value = prevprevprev.owner }
									OR = {
										is_hostile = prevprevprev.owner
										is_at_war_with = prevprevprev.owner
									}
								}
								is_cloaked = no
							}
							any_system_planet_colony = {
								exists = owner
								owner = {
									NOT = { is_same_value = prevprevprev.owner }
									OR = {
										is_country_type = default
										is_country_type = fallen_empire
										is_country_type = awakened_fallen_empire
									}
								}
							}
						}
					}
				}
				# Fruitful Origin - the outpost is being created for the first time
				if = {
					limit = {
						has_planet_flag = seed_pods_colonization
					}
					carrier_event = { id = origin.7400 }
				}
				# else, fire the normal "Outpost Rebuilt!" event
				else = {
					carrier_event = { id = action.91 }
				}
			}
		}
	}
}

carrier_event = {
	id = action.91
	title = action.91.name
	desc = action.91.desc
	picture = GFX_evt_star_chart
	show_sound = event_default
	location = root

	is_triggered_only = yes

	immediate = {
		solar_system = {
			create_starbase = {
				size = starbase_outpost
				owner = root.owner
			}
			if = {
				limit = { root.owner = { is_specialist_subject_type = { TYPE = bulwark } } }
				starbase = {
					add_starbase_component = {
						component = "STARBASE_AURA_BULWARK_ARRAY"
					}
				}
			}
		}
	}

	option = {
		name = OK
		tooltip = {
			solar_system = {
				create_starbase = {
					size = starbase_outpost
					owner = root.owner
				}
			}
		}
	}
}

# Make sure Swarm-owned planets are Infested and megastructures wiped
event = {
	id = action.92
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		any_country = { is_country_type = swarm }
	}

	immediate = {
		random_country = {
			limit = {
				is_country_type = swarm
			}
			save_event_target_as = prethoryn_swarm
		}
		every_galaxy_planet = {
			limit = {
				exists = owner
				owner = { is_country_type = swarm }
				NOT = { is_planet_class = pc_infested }
			}
			if = {
				limit = {
					is_under_colonization = no
					is_planet_class = pc_habitat
				}
				destroy_colony = yes
				remove_planet = yes
			}
			else_if = {
				limit = {
					is_under_colonization = no
					OR = {
						is_planet_class = pc_ringworld_habitable
						is_planet_class = pc_shattered_ring_habitable
					}
				}
				destroy_colony = yes
				change_pc = pc_ringworld_habitable_damaged
				reset_planet = yes
			}
			else_if = {
				limit = {
					is_under_colonization = yes
					NOR = {
						is_planet_class = pc_habitat
						is_planet_class = pc_ringworld_habitable
					}
				}
				change_pc = pc_infested
				set_owner = event_target:prethoryn_swarm
			}
		}
	}
}

# Make sure Extradimensionals own no planets or megastructures
event = {
	id = action.93
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		any_country = {
			OR = {
				is_country_type = extradimensional
				is_country_type = extradimensional_2
				is_country_type = extradimensional_3
			}
		}
	}

	immediate = {
		every_galaxy_planet = {
			limit = {
				exists = owner
				owner = {
					OR = {
						is_country_type = extradimensional
						is_country_type = extradimensional_2
						is_country_type = extradimensional_3
					}
				}
			}
			if = {
				limit = {
					OR = {
						is_planet_class = pc_habitat
						is_planet_class = pc_ringworld_habitable
					}
				}
				destroy_colony = yes
			}
			else = {
				random_list = {
					50 = { change_pc = pc_barren }
					50 = { change_pc = pc_barren_cold }
				}
				add_modifier = {
					modifier = "terraforming_candidate"
					days = -1
				}
			}
		}
	}
}

ship_event = {
	id = action.941
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		from = { # basically a pre-trigger
			has_strategic_resource = yes
			if = {
				limit = {
					is_scope_type = planet
				}
				has_anomaly = no
			}
		}
		owner = {
			OR = {
				has_resource_for_discovery = {
					RESOURCE = volatile_motes
				}
				has_resource_for_discovery = {
					RESOURCE = exotic_gases
				}
				has_resource_for_discovery = {
					RESOURCE = rare_crystals
				}
				has_resource_for_discovery = {
					RESOURCE = sr_living_metal
				}
				has_resource_for_discovery = {
					RESOURCE = sr_zro
				}
				has_resource_for_discovery = {
					RESOURCE = sr_dark_matter
				}
				has_resource_for_discovery = {
					RESOURCE = astral_threads
				}
			}
		}
	}

	immediate = {
		if = {
			limit = {
				owner = {
					NOT = { has_country_flag = strategic_resource_found }
				}
			}
			owner = {
				set_country_flag = strategic_resource_found
			}
			if = {
				limit = {
					from = {
						NOT = { is_scope_type = country }
					}
				}
				if = {
					limit = {
						owner = { has_origin = origin_shroud_forged }
						from = { has_resource = { type = sr_zro amount > 0 } }
					}
					ship_event = { id = action.942 scopes = { from = from } }
				}
				else_if = {
					limit = {
						owner = { has_origin = origin_mindwardens }
						from = { has_resource = { type = sr_zro amount > 0 } }
					}
					ship_event = { id = action.943 scopes = { from = from } }
				}
				else = {
					ship_event = { id = action.94 scopes = { from = from } }
				}
			}
			else = {
				if = {
					limit = {
						owner = { has_origin = origin_shroud_forged }
						fromfrom = { has_resource = { type = sr_zro amount > 0 } }
					}
					ship_event = { id = action.942 scopes = { from = fromfrom } }
				}
				else_if = {
					limit = {
						owner = { has_origin = origin_mindwardens }
						fromfrom = { has_resource = { type = sr_zro amount > 0 } }
					}
					ship_event = { id = action.943 scopes = { from = fromfrom } }
				}
				else = {
					ship_event = { id = action.94 scopes = { from = fromfrom }  }
				}
			}
		}
		else = {
			from = {
				if = {
					limit = { has_resource = { type = rare_crystals amount > 0 } }
					root.owner = {
						set_country_flag =	rare_crystals_found
						create_strategic_resource_message = {
							RESOURCE_TYPE = MESSAGE_STRATEGIC_RESOURCE_FOUND_RARE_CRYSTALS
							RESOURCE_DESC = MESSAGE_STRATEGIC_RESOURCE_FOUND_RARE_CRYSTALS_DESC
						}
					}
				}
				else_if = {
					limit = { has_resource = { type = exotic_gases amount > 0 } }
					root.owner = {
						set_country_flag =	exotic_gases_found
						create_strategic_resource_message = {
							RESOURCE_TYPE = MESSAGE_STRATEGIC_RESOURCE_FOUND_EXOTIC_GASES
							RESOURCE_DESC = MESSAGE_STRATEGIC_RESOURCE_FOUND_EXOTIC_GASES_DESC
						}
					}
				}
				else_if = {
					limit = { has_resource = { type = volatile_motes amount > 0 } }
					root.owner = {
						set_country_flag =	volatile_motes_found
						create_strategic_resource_message = {
							RESOURCE_TYPE = MESSAGE_STRATEGIC_RESOURCE_FOUND_VOLATILE_MOTES
							RESOURCE_DESC = MESSAGE_STRATEGIC_RESOURCE_FOUND_VOLATILE_MOTES_DESC
						}
					}
				}
				else_if = {
					limit = { has_resource = { type = sr_zro amount > 0 } }
					root.owner = {
						set_country_flag =	sr_zro_found
						create_strategic_resource_message = {
							RESOURCE_TYPE = MESSAGE_STRATEGIC_RESOURCE_FOUND_ZRO
							RESOURCE_DESC = MESSAGE_STRATEGIC_RESOURCE_FOUND_ZRO_DESC
						}
					}
				}
				else_if = {
					limit = { has_resource = { type = sr_dark_matter amount > 0 } }
					root.owner = {
						set_country_flag =	sr_dark_matter_found
						create_strategic_resource_message = {
							RESOURCE_TYPE = MESSAGE_STRATEGIC_RESOURCE_FOUND_DARK_MATTER
							RESOURCE_DESC = MESSAGE_STRATEGIC_RESOURCE_FOUND_DARK_MATTER_DESC
						}
					}
				}
				else_if = {
					limit = { has_resource = { type = sr_living_metal amount > 0 } }
					root.owner = {
						set_country_flag =	sr_living_metal_found
						create_strategic_resource_message = {
							RESOURCE_TYPE = MESSAGE_STRATEGIC_RESOURCE_FOUND_LIVING_METAL
							RESOURCE_DESC = MESSAGE_STRATEGIC_RESOURCE_FOUND_LIVING_METAL_DESC
						}
					}
				}
				else_if = {
					limit = { has_resource = { type = astral_threads amount > 0 } }
					root.owner = {
						set_country_flag =	astral_threads_found
						create_strategic_resource_message = {
							RESOURCE_TYPE = MESSAGE_STRATEGIC_RESOURCE_FOUND_ASTRAL_THREADS
							RESOURCE_DESC = MESSAGE_STRATEGIC_RESOURCE_FOUND_ASTRAL_THREADS_DESC
						}
					}
				}
			}
		}
	}
}

# Resource specialization for Shroud-Forged discovering Zro
ship_event = {
	id = action.942
	title = action.942.name
	desc = action.942.desc
	picture = GFX_evt_surreal_visions
	show_sound = event_default
	location = from

	is_triggered_only = yes

	immediate = {
		owner = { set_country_flag = sr_zro_found }
	}

	option = {
		name = action.942.a
		custom_tooltip = action.92.zro.tooltip
	}
}

# Resource specialization for Mindwarden discovering Zro
ship_event = {
	id = action.943
	title = action.92.name
	desc = action.92.zro.mindwarden
	picture = GFX_evt_surreal_visions
	show_sound = event_default
	location = from

	is_triggered_only = yes

	immediate = {
		owner = { set_country_flag = sr_zro_found }
	}

	option = {
		name = action.92.a
		owner = {
			add_tech_option_or_research_effect = {
				TECH = tech_mine_zro
				PROGRESS = 0.1
				CATEGORY = society_research
			}
		}
		custom_tooltip = action.92.zro.tooltip
	}
}

ship_event = {
	id = action.94
	title = action.92.name
	desc = {
		trigger = {
			success_text = {
				text = action.92.rare_crystals
				hidden:from = { has_resource = { type = rare_crystals amount > 0 } }
			}
			success_text = {
				text = action.92.exotic_gases
				hidden:from = { has_resource = { type = exotic_gases amount > 0 } }
			}
			success_text = {
				text = action.92.volatile_motes
				hidden:from = { has_resource = { type = volatile_motes amount > 0 } }
			}
			success_text = {
				text = action.92.zro
				hidden:from = { has_resource = { type = sr_zro amount > 0 } }
			}
			success_text = {
				text = action.92.dark_matter
				hidden:from = { has_resource = { type = sr_dark_matter amount > 0 } }
			}
			success_text = {
				text = action.92.living_metal
				hidden:from = { has_resource = { type = sr_living_metal amount > 0 } }
			}
			success_text = {
				text = action.92.astral_threads
				hidden:from = { has_resource = { type = astral_threads amount > 0 } }
			}
			success_text = {
				text = action.92.has_tech
				OR = {
					AND = {
						hidden:from = { has_resource = { type = rare_crystals amount > 0 } }
						hidden:owner = { has_technology = tech_rare_crystals }
					}
					AND = {
						hidden:from = { has_resource = { type = exotic_gases amount > 0 } }
						hidden:owner = { has_technology = tech_exotic_gases }
					}
					AND = {
						hidden:from = { has_resource = { type = volatile_motes amount > 0 } }
						hidden:owner = { has_technology = tech_volatile_motes }
					}
					AND = {
						hidden:from = { has_resource = { type = sr_zro amount > 0 } }
						hidden:owner = { has_technology = tech_mine_zro }
					}
					AND = {
						hidden:from = { has_resource = { type = sr_dark_matter amount > 0 } }
						hidden:owner = { has_technology = tech_mine_dark_matter }
					}
					AND = {
						hidden:from = { has_resource = { type = sr_living_metal amount > 0 } }
						hidden:owner = { has_technology = tech_mine_living_metal }
					}
					AND = {
						hidden:from = { has_resource = { type = astral_threads amount > 0 } }
						hidden:owner = { has_technology = tech_astral_harvesting }
					}
				}
			}
			success_text = {
				text = action.92.no_tech
				# same trigger as above
				NOR = {
					AND = {
						hidden:from = { has_resource = { type = rare_crystals amount > 0 } }
						hidden:owner = { has_technology = tech_rare_crystals}
					}
					AND = {
						hidden:from = { has_resource = { type = exotic_gases amount > 0 } }
						hidden:owner = { has_technology = tech_exotic_gases }
					}
					AND = {
						hidden:from = { has_resource = { type = volatile_motes amount > 0 } }
						hidden:owner = { has_technology = tech_volatile_motes }
					}
					AND = {
						hidden:from = { has_resource = { type = sr_zro amount > 0 } }
						hidden:owner = { has_technology = tech_mine_zro }
					}
					AND = {
						hidden:from = { has_resource = { type = sr_dark_matter amount > 0 } }
						hidden:owner = { has_technology = tech_mine_dark_matter }
					}
					AND = {
						hidden:from = { has_resource = { type = sr_living_metal amount > 0 } }
						hidden:owner = { has_technology = tech_mine_living_metal }
					}
					AND = {
						hidden:from = { has_resource = { type = astral_threads amount > 0 } }
						hidden:owner = { has_technology = tech_astral_harvesting }
					}
				}
			}
		}
	}
	picture = GFX_evt_surreal_visions
	show_sound = event_default
	location = from

	is_triggered_only = yes

	immediate = {
		from = {
			if = {
				limit = { has_resource = { type = rare_crystals amount > 0 } }
				root.owner = { set_country_flag = rare_crystals_found }
			}
			else_if = {
				limit = { has_resource = { type = exotic_gases amount > 0 } }
				root.owner = { set_country_flag = exotic_gases_found }
			}
			else_if = {
				limit = { has_resource = { type = volatile_motes amount > 0 } }
				root.owner = { set_country_flag = volatile_motes_found }
			}
			else_if = {
				limit = { has_resource = { type = sr_zro amount > 0 } }
				root.owner = { set_country_flag = sr_zro_found }
			}
			else_if = {
				limit = { has_resource = { type = sr_dark_matter amount > 0 } }
				root.owner = { set_country_flag = sr_dark_matter_found }
			}
			else_if = {
				limit = { has_resource = { type = sr_living_metal amount > 0 } }
				root.owner = { set_country_flag = sr_living_metal_found }
			}
			else_if = {
				limit = { has_resource = { type = astral_threads amount > 0 } }
				root.owner = { set_country_flag = astral_threads_found }
			}
		}
	}

	option = {
		name = action.92.a
		from = {
			hidden_effect = {
				if = {
					limit = { has_resource = { type = rare_crystals amount > 0 } }
					custom_tooltip = action.92.rare_crystals.tooltip
				}
				else_if = {
					limit = { has_resource = { type = exotic_gases amount > 0 } }
					custom_tooltip = action.92.exotic_gases.tooltip
				}
				else_if = {
					limit = { has_resource = { type = volatile_motes amount > 0 } }
					custom_tooltip = action.92.volatile_motes.tooltip
				}
				else_if = {
					limit = { has_resource = { type = sr_zro amount > 0 } }
					custom_tooltip = action.92.zro.tooltip
				}
				else_if = {
					limit = { has_resource = { type = sr_dark_matter amount > 0 } }
					custom_tooltip = action.92.dark_matter.tooltip
				}
				else_if = {
					limit = { has_resource = { type = sr_living_metal amount > 0 } }
					custom_tooltip = action.92.living_metal.tooltip
				}
				else_if = {
					limit = { has_resource = { type = astral_threads amount > 0 } }
					custom_tooltip = action.92.astral_threads.tooltip
				}
			}
		}
	}
}

carrier_event = {
	id = action.95
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_modifier = planet_culture_shock
		FromFrom.species = { has_species_flag = primitive_species }
		NOT = {
			any_owned_pop_group = {
				species = {
					has_species_flag = primitive_species
				}
				NOT = { is_same_value = fromfrom }
			}
		}
	}

	immediate = {
		remove_modifier = planet_culture_shock
	}

}

# Other Empires react to a Pop dying due to massive orbital bombardment
# This = Planet where the pop was bombed to death
# From = Country which is raining down fire and brimstone
carrier_event = {
	id = action.100
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		from? = {
			is_country_type = default
		}
		owner? = {
			is_country_type = default
			NOT = { is_same_value = from }
		}
	}

	immediate = {
		owner = {
			add_opinion_modifier = { who = root.from modifier = opinion_nuker }
		}
		every_country = {
			limit = {
				has_communications = root.from
				has_communications = root.owner
				NOR = {
					is_country = root.from
					has_ai_personality_behaviour = purger
					is_fanatic_xenophobe = yes
					is_harming_relations_with = root.owner
					is_at_war_with = root.owner
					has_rival = root.owner
				}
				OR = {
					is_country_type = default
					has_ai_personality = awakened_fallen_empire_xenophile
				}
			}
			add_opinion_modifier = { who = root.from modifier = opinion_nuker }
		}
	}
}

# Remove ascension tier on owner change
carrier_event = {
	id = action.350
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_planetary_ascension_tier = 0
		set_timed_carrier_flag = {
			flag = 3_year_owner_change_flag
			days = 1080
		}
	}
}

# Add urban districts on planet colonized
carrier_event = {
	id = action.360
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			check_modifier_value = {
				modifier = colony_start_urban_districts_add
				value > 0
			}
		}
	}

	immediate = {
		colony = {
			colony_event = {
				id = action.361
				days = 1
			}
		}
	}
}
colony_event = {
	id = action.361
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		exists = owner
		owner = {
			check_modifier_value = {
				modifier = colony_start_urban_districts_add
				value > 0
			}
		}
	}

	immediate = {
		set_timed_carrier_flag = {
			flag = ignore_ai_building_limitations
			days = 1
		}
		if = {
			limit = {
				planet_is_ring_world_equivalent = yes
			}
			while = {
				count = owner.modifier:colony_start_urban_districts_add
				add_district = {
					district_type = district_rw_city
					type_conversion = yes
				}
			}
		}
		else_if = {
			limit = {
				planet_is_habitat_equivalent = yes
			}
			while = {
				count = owner.modifier:colony_start_urban_districts_add
				add_district = {
					district_type = district_hab_housing
					type_conversion = yes
				}
			}
		}
		else = {
			while = {
				count = owner.modifier:colony_start_urban_districts_add
				add_district = {
					district_type = district_city
					type_conversion = yes
				}
			}
			validate_planet_buildings_and_districts = yes
			if = {
				limit = {
					owner = {
						is_regular_empire = yes
					}
					NOT = {
						has_building = building_colony_shelter
					}
				}
				add_building = building_colony_shelter
			}
			else_if = {
				limit = {
					owner = {
						is_machine_empire = yes
					}
					NOT = {
						has_building = building_deployment_post
					}
				}
				add_building = building_deployment_post
			}
			else_if = {
				limit = {
					owner = {
						is_hive_empire = yes
						is_wilderness_empire = no
					}
					NOT = {
						has_building = building_hive_capital
					}
				}
				add_building = building_hive_capital
			}
			else_if = {
				limit = {
					owner = {
						is_wilderness_empire = yes
					}
					NOR = {
						has_building = building_colony_shelter_wilderness
						has_building = building_capital_wilderness
						has_building = building_major_capital_wilderness
						has_building = building_system_capital_wilderness
						has_building = building_imperial_capital_wilderness
					}
				}
				add_building = building_colony_shelter_wilderness
			}
		}
	}
}

# An ally leaves a war early - force a truce with the opposing side so they cannot immediately rejoin the war.
# Root = Main Ally, From = Actor (leaver), FromFrom = War
country_event = {
	id = action.43
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		from = {
			save_event_target_as = leaving_ally
		}
		if = {
			limit = {
				event_target:leaving_ally = {
					is_war_participant = {
						war = fromfrom
						side = attackers
					}
				}
			}
			fromfrom = {
				every_defender = {
					event_target:leaving_ally = {
						set_truce = {
							target = prev
							type = war
						}
					}
					set_truce = {
						target = event_target:leaving_ally
						type = war
					}
				}
			}
		}
		else = {
			fromfrom = {
				every_attacker = {
					event_target:leaving_ally = {
						set_truce = {
							target = prev
							type = war
						}
					}
					set_truce = {
						target = event_target:leaving_ally
						type = war
					}
				}
			}
		}
	}
}
