citizenship_full_machine = {
	is_full_citizenship = yes

	potential = {
		OR = {
			has_synthetic_dawn = yes
			has_machine_age_dlc = yes
		}
		exists = from
		from = { has_authority = auth_machine_intelligence }
	}

	allow = {
		hidden_trigger = { exists = from }
		if = {
			limit = {
				from = { NOT = { has_valid_civic = civic_machine_assimilator } }
			}
			custom_tooltip = {
				fail_text = MACHINE_SPECIES_NOT_MACHINE
				OR = {
					has_trait = trait_mechanical
					has_trait = trait_machine_unit
					AND = {
						FROM = {
							has_ascension_perk = ap_mechromancy
						}
						has_trait = trait_cybernetic
						has_trait = trait_zombie
					}
                    AND = {
						FROM = {
							has_ascension_perk = ap_organo_machine_interfacing_assimilator
						}
						has_trait = trait_cybernetic
					}
				}
			}
		}
		else = {
			custom_tooltip = {
				fail_text = ASSIMILATOR_SPECIES_NOT_CYBORG
				OR = {
					has_trait = trait_cybernetic
					has_trait = trait_machine_unit
					has_trait = trait_mechanical
				}
			}
		}
	}
	ai_will_do = {
		factor = 30
	}
}

citizenship_assimilation = {
	is_assimilation = yes

	potential = {
		OR = {
			has_synthetic_dawn = yes
			has_utopia = yes
			has_machine_age_dlc = yes
		}
		exists = from
		from = {
			OR = {
				is_homicidal = no
				AND = {
					is_homicidal = yes
					root = {
						is_same_species = prev
					}
				}
				AND = {
					has_civic = civic_machine_terminator
					root = {
						is_robotic_species = yes
					}
				}
			}
			OR = {
				AND = { # machine cyborg assimilator
					has_authority = auth_machine_intelligence
					OR = {
                        has_valid_civic = civic_machine_assimilator
                        has_ascension_perk = ap_organo_machine_interfacing_assimilator
                    }
					OR = {
						AND = {
							root = {
								is_robotic_species = yes
							}
						}
						root = {
							NOR = {
								has_trait = trait_mechanical
								has_trait = trait_machine_unit
								has_trait = trait_cybernetic
							}
						}
					}
				}
				AND = { # machine synthetic assimilator
					has_authority = auth_machine_intelligence
					root = {
						is_robotic_species = yes
					}
				}
				AND = {
					OR = {
						AND = {
							# non-devouring hive mind
							has_authority = auth_hive_mind
							NOT = { has_civic = civic_hive_devouring_swarm }
						}
						# Regular empire
						AND = {
							NOT = { has_ethic = ethic_gestalt_consciousness }
							is_individual_machine = no
						}
					}
					OR = {
						has_active_tradition = tr_genetics_creation	# genetic assimilation
						has_active_tradition = tr_cybernetics_transubstantiation_synthesis # cybernetic assimilation
					}
					ROOT = { is_robotic_species = no }
				}
				AND = {
					has_country_flag = synth_assimilation # synth assimilation
					NOT = { has_authority = auth_machine_intelligence }
				}
				has_active_tradition = tr_psionics_psionic_assimilation # psionic assimilation
				AND = {
					is_individual_machine = yes
					ROOT = { is_robotic_species = yes }
				}
			}
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = MUST_NOT_BE_DOMINANT_SPECIES
			NOT = { is_exact_same_species = from }
		}
		custom_tooltip = {
			fail_text = "pre_sapients_citizenship"
			is_sapient = yes
		}
		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_citizenship_assimilation"
			if = {
				limit = { is_lonely_hive_mind_pop = yes }
				from = {
					OR = {
						has_active_tradition = tr_genetics_creation
						has_active_tradition = tr_cybernetics_transubstantiation_synthesis
						has_active_tradition = tr_cybernetics_assimilator_inevitable_assimilation
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "disconnected_machine_pops_collapse_citizenship"
			OR = {
				from = {
					has_country_flag = synth_assimilation
				}
				is_disconnected_machine_pop = no
			}
		}
		if = {
			limit = {
				from = {
					has_authority = auth_machine_intelligence
				}
			}
			custom_tooltip = { # machine assimilator
				fail_text = MACHINE_SPECIES_MUST_BE_ORGANIC
			}
			custom_tooltip = {
				fail_text = requires_tradition_tr_synthetics_adopt
			}
		}
		else_if = {
			limit = {
				from = {
					has_authority = auth_hive_mind
					has_active_tradition = tr_genetics_creation
				}
			}
			custom_tooltip = { # non-devouring hive mind
				fail_text = HIVE_SPECIES_MUST_BE_NON_HIVE
				NOR = {
					has_trait = trait_hive_mind
					has_trait = trait_mechanical
					has_trait = trait_machine_unit
				}
			}
		}
		else_if = {
			limit = {
				from = {
					has_authority = auth_hive_mind
					has_active_tradition = tr_cybernetics_transubstantiation_synthesis
				}
			}
			custom_tooltip = { # non-devouring hive mind
				fail_text = HIVE_SPECIES_MUST_BE_NON_HIVE
				NOR = {
					has_trait = trait_mechanical
					has_trait = trait_machine_unit
					AND = {
						has_trait = trait_hive_mind
						has_trait = trait_cybernetic
					}
				}
			}
		}
		else_if = {
			limit = {
				from = {
					NOT = { has_authority = auth_hive_mind }
					has_active_tradition = tr_cybernetics_transubstantiation_synthesis
				}
			}
			custom_tooltip = { # cyborg empire
				fail_text = CYBORG_SPECIES_MUST_BE_ORGANIC
				OR = {
					AND = {
						has_trait = trait_hive_mind
						from = {
							NOT = {
								has_authority = auth_hive_mind
							}
						}
					}
					AND = {
						NOT = {
							has_trait = trait_hive_mind
						}
						from = {
							has_authority = auth_hive_mind
						}
					}
					NOR = {
						has_trait = trait_mechanical
						has_trait = trait_machine_unit
						has_trait = trait_cybernetic
						has_trait = trait_limited_cybernetic
					}
				}
			}
		}
		else_if = {
			limit = {
				from = { has_active_tradition = tr_psionics_psionic_assimilation }
			}
			custom_tooltip = { # species must be organic to transcend
				fail_text = TRANSCENDING_SPECIES_MUST_BE_ORGANIC
				is_robotic_species = no
			}
			custom_tooltip = { # species already has psionic trait
				fail_text = TRANSCENDING_SPECIES_IS_ALREADY_PSIONIC
				NOT = { has_trait = trait_psionic }
			}
			custom_tooltip = { # transcending species cannot be gestalt consciousness
				fail_text = TRANSCENDING_SPECIES_CANT_BE_HIVE
				OR = { has_active_tradition = tr_genetics_creation NOT = { has_trait = trait_hive_mind } }
			}
		}
		else_if = {
			limit = {
				from = { has_active_tradition = tr_genetics_creation }
			}
			custom_tooltip = {
				fail_text = CAN_ONLY_ASSIMILATE_HIVES
				has_trait = trait_hive_mind
			}
		}
	}

	ai_will_do = {
		factor = 100
		modifier = {
			factor = 0
			from = {
				OR = {
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_machine_terminator
				}
			}
		}
		modifier = {
			factor = 0.3
			from = {
				is_individual_machine = yes
			}
		}
	}
}

citizenship_slavery = {
	is_slavery = yes

	in_breach_of = {
		{
			key = resolution_greatergood_balance_in_the_middle
		}
		{
			key = resolution_greatergood_universal_prosperity_mandate
		}
	}

	potential = {
		NAND = {
			exists = this
			OR = {
				AND = {
					from = { is_individual_machine = yes }
					OR = {
						has_trait = trait_machine_unit
						has_trait = trait_mechanical
					}
				}
				has_trait = trait_machine_unit
				has_trait = trait_mechanical
			}
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = "presapients_allowed_citizenship"
			OR = {
				is_sapient = yes
				from = {
					NOT = {
						has_policy_flag = pre_sapients_protect
						has_policy_flag = pre_sapients_allow
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "presapients_purged_citizenship"
			OR = {
				is_sapient = yes
				from = {
					NOT = {
						has_policy_flag = pre_sapients_purge
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "HIVE_MIND_MAIN_SPECIES_ALWAYS_CITIZEN"
			NAND = {
				from = { has_authority = auth_hive_mind }
				has_trait = trait_hive_mind
			}
		}
		custom_tooltip = {
			fail_text = same_species_disallowed
			NOT = { is_same_species = from }
		}
		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_citizenship"
			is_lonely_hive_mind_pop = no
		}
		custom_tooltip = {
			fail_text = SERVITORS_CANNOT_ENSLAVE
			from = {
				NOT = { has_valid_civic = civic_machine_servitor }
			}
		}
		custom_tooltip = {
			fail_text = ASSIMILATORS_CANNOT_ENSLAVE
			from = {
				NOT = { has_valid_civic = civic_machine_assimilator }
			}
		}
		custom_tooltip = {
			fail_text = MACHINE_CANNOT_ENSLAVE_CYBORGS
			from = {
				NOT = {
					AND = {
						has_ascension_perk = ap_organo_machine_interfacing_assimilator
						has_trait = trait_cybernetic
					}
				 }
			}
		}
		custom_tooltip = {
			fail_text = TERMINATORS_CANNOT_ENSLAVE
			from = {
				NOT = { has_valid_civic = civic_machine_terminator }
			}
		}
		custom_tooltip = {
			fail_text = DEVOURERS_CANNOT_ENSLAVE
			from = {
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
			}
		}
		custom_tooltip = {
			fail_text = empire_xenophile
			from = {
				NOR = {
					has_ethic = ethic_xenophile
					has_ethic = ethic_fanatic_xenophile
				}
			}
		}
		custom_tooltip = {
			fail_text = "FANATIC_PURIFIERS_MUST_PURIFY"
			OR = {
				NOT = { from = { has_valid_civic = civic_fanatic_purifiers } }
				is_same_species = from
			}
		}
		custom_tooltip = {
			fail_text = does_not_embrace_species_slavery
			from = {
				allows_slavery = yes
				OR = {
					has_ethic = ethic_xenophobe
					has_ethic = ethic_fanatic_xenophobe
					has_ethic = ethic_authoritarian
					has_ethic = ethic_fanatic_authoritarian
					has_ethic = ethic_gestalt_consciousness
				}
			}
		}
		custom_tooltip = {
			fail_text = yes_service_yes_citizenship
			if = {
				limit = {
					from = { has_valid_civic = civic_citizen_service }
				}
				NOT = { has_military_service_type = { type = military_service_full country = from } }
			}
		}
		custom_tooltip = {
			fail_text = selective_kinship_must_citizen
			if = {
				limit = {
					from = { has_valid_civic = civic_selective_kinship }
				}
				NOT = { is_same_species_class = from }
			}
		}
	}
	ai_will_do = {
		factor = 15
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = slaver
				}
				NAND = {
					is_ai = no
					is_xenophobe = yes
				}
			}
		}
		modifier = {
			factor = 0
			from = {
				is_authoritarian = no
				is_xenophobe = no
				is_hive_empire = no
			}
		}
		modifier = {
			factor = 0.1
			from = {
				is_galactic_community_member = yes
			}
			OR = {
				is_active_resolution = "resolution_greatergood_balance_in_the_middle"
				is_active_resolution = "resolution_greatergood_universal_prosperity_mandate"
			}
		}
		modifier = {
			factor = 2
			has_species_flag = syncretic_species@from
		}
	}
}