# from = country
# this = species

citizenship_full = {
	token = citizenship_full

	potential = {
		exists = from
		NOT = { from = { has_authority = auth_machine_intelligence } }		
	}

	allow = {
		hidden_trigger = { exists = from }

		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_citizenship"
			is_lonely_hive_mind_pop = no
		}
		custom_tooltip = {
			fail_text = "disconnected_machine_pops_kill_themselves_citizenship"
			is_disconnected_machine_pop = no
		}
		custom_tooltip = {
			fail_text = "HIVE_MIND_SPECIES_CITIZENS_ONLY"
			OR = {
			  #ǷǺгȺ
				NAND = { from = { 
										has_authority = auth_hive_mind 
										NOT = { has_valid_civic = civic_harmonious }
								} 
				}
				has_trait = trait_hive_mind
			}
		}
		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 = too_alien
			OR = {
				is_same_species = from
				from = {
					NOR = {
						has_ethic = ethic_xenophobe
						has_ethic = ethic_fanatic_xenophobe
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = no_service_no_citizenship
			OR = {
				NOT = { from = { has_valid_civic = civic_citizen_service } }
				has_military_service_type = { type = military_service_full country = from }
			}
		}
		custom_tooltip = {
		   fail_text = NO_MORTALS_TO_BE_CITIZENSHIP #֮𣬷л޷Ϊ
		   OR = {
		      NOT = { from = { has_authority = auth_xilin_mind } }
		      OR = {
		             has_trait = trait_magic_machine
		             has_trait = trait_divinity
		      }
		   }
		}
		#гȺȺܻȨ
		custom_tooltip = {
		   fail_text = HARMONY_HIVE_NEED_PSIONIC #гȺֻ˿ڻȺܳΪ
		   OR = {
		      NOT = { from = { 
		      		has_authority = auth_hive_mind 
		      		has_valid_civic = civic_harmonious
		      } }
		      OR = {
		             has_trait = trait_hive_mind
								 has_trait = trait_psionic
								 has_trait = trait_latent_psionic
		      }
		   }
		}
	}
	ai_will_do = {
		factor = 1
	}
}

citizenship_assimilation = {
	token = citizenship_assimilation

	potential = {
		OR = {
			host_has_dlc = "Synthetic Dawn Story Pack"
			host_has_dlc = "Utopia"
		}
		exists = from
		NOT = { from = { has_civic = civic_fanatic_purifiers } }
		OR = {
			from = { # machine assimilator
				AND = {
					has_authority = auth_machine_intelligence
					has_civic = civic_machine_assimilator
				}
			}
			from = { # non-devouring hive mind
				AND = {
					has_authority = auth_hive_mind
					NOR = { 
						has_civic = civic_hive_devouring_swarm 
						has_valid_civic = civic_harmonious #гȺͬ
					}
				}
			}
			from = { # synthetically ascended empire
				has_country_flag = synthetic_empire
			}
			from = { # cyborg empire
				has_country_flag = flesh_weakened
			}
			from = {
				OR = {
						has_ascension_perk = ap_evolutionary_mastery
						#ϣ۹ƿؽ
						has_modifier = m_evolutionary_mastery
				}
				NOT = { has_ethic = ethic_gestalt_consciousness }
			}
			# psionic assimilation
			from = {
				has_ascension_perk = ap_transcendence
			}
		}
		#ܶͬ
		NAND = {
				has_trait = trait_tree_spirit
				from = {
						OR = {
								has_valid_civic = civic_harmonious_tree
								has_modifier = m_kala_gift
						}
				}
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = MUST_NOT_BE_DOMINANT_SPECIES
			NOT = { is_same_species = from }
		}
		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_citizenship"
			OR = {
				is_lonely_hive_mind_pop = no
				AND = {
					is_lonely_hive_mind_pop = yes
					from = {
						has_ascension_perk = ap_evolutionary_mastery
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "disconnected_machine_pops_collapse_citizenship"
			is_disconnected_machine_pop = no
		}
		custom_tooltip = { # machine assimilator
			fail_text = MACHINE_SPECIES_MUST_BE_ORGANIC
			OR = {
				from = { NOT = { has_authority = auth_machine_intelligence } }
				AND = {
					from = {
						has_authority = auth_machine_intelligence
						has_civic = civic_machine_assimilator
					}
					NOR = {
						has_trait = trait_mechanical
						has_trait = trait_machine_unit
						has_trait = trait_cybernetic
					}
				}
			}
		}
		custom_tooltip = { # non-devouring hive mind
			fail_text = HIVE_SPECIES_MUST_BE_NON_HIVE
			OR = {
				from = { NOT = { has_authority = auth_hive_mind } }
				AND = {
					from = {
						has_authority = auth_hive_mind
						has_ascension_perk = ap_evolutionary_mastery
						NOT = { has_civic = civic_hive_devouring_swarm }
					}
					NOR = {
						has_trait = trait_hive_mind
						has_trait = trait_mechanical
						has_trait = trait_machine_unit
					}
				}
			}
		}
		custom_tooltip = { # synthetically ascended empire
			fail_text = SYNTH_SPECIES_MUST_BE_ORGANIC
			OR = {
				from = { NOT = { has_country_flag = synthetic_empire } }
				AND = {
					from = {
						has_country_flag = synthetic_empire
					}
					NOR = {
						has_trait = trait_mechanical
						has_trait = trait_machine_unit
					}
				}
			}
		}
		custom_tooltip = { # cyborg empire
			fail_text = CYBORG_SPECIES_MUST_BE_ORGANIC
			OR = {
				from = { NOT = { has_country_flag = flesh_weakened } }
				AND = {
					from = {
						has_country_flag = flesh_weakened
					}
					NOR = {
						has_trait = trait_mechanical
						has_trait = trait_mechanical
						AND = {
							has_trait = trait_cybernetic
							from = { NOT = { has_country_flag = synthetic_empire } }
						}
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = DEFAULT_SPECIES_MUST_BE_HIVE
			OR = {
				from = {
					OR = {
						has_country_flag = flesh_weakened
						has_country_flag = synthetic_empire
						has_ethic = ethic_gestalt_consciousness
						has_ascension_perk = ap_transcendence
					}
				}
				AND = {
					has_trait = trait_hive_mind
					from = {
						has_ascension_perk = ap_evolutionary_mastery
						NOR = {
							has_ethic = ethic_gestalt_consciousness
							has_country_flag = flesh_weakened
							has_country_flag = synthetic_empire
						}
					}
				}
			}
		}
		custom_tooltip = { # species must be organic to transcend
			fail_text = TRANSCENDING_SPECIES_MUST_BE_ORGANIC
			OR = {
				from = { NOT = { has_ascension_perk = ap_transcendence } }
				AND = {
					from = { has_ascension_perk = ap_transcendence }
					NOR = {
						has_trait = trait_mechanical
						has_trait = trait_cybernetic
						has_trait = trait_machine_unit
					}
				}
			}
		}
		custom_tooltip = { # species already has psionic trait
			fail_text = TRANSCENDING_SPECIES_IS_ALREADY_PSIONIC
			OR = {
				from = { NOT = { has_ascension_perk = ap_transcendence } }
				AND = {
					from = { has_ascension_perk = ap_transcendence }
					NOT = {
						has_trait = trait_psionic
					}
				}
			}
		}
		custom_tooltip = { # transcending species cannot be gestalt consciousness
			fail_text = TRANSCENDING_SPECIES_CANT_BE_HIVE
			OR = {
				from = { NOT = { has_ascension_perk = ap_transcendence } }
				AND = {
					from = { has_ascension_perk = ap_transcendence }
					NOT = {
						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
				}
			}
		}
	}
}

citizenship_limited = {
	token = citizenship_limited

	pop_modifier = {
		pop_happiness = -0.05
		pop_consumer_goods_mult = -0.20
	}

	potential = {
		exists = from
		from = {
			NOR = {
				AND = {
					has_authority = auth_hive_mind
					NOT = { has_valid_civic = civic_harmonious } #гȺлȨ
				}	
				has_authority = auth_machine_intelligence
			}
		}
	}

	allow = {
		custom_tooltip = {
			fail_text = "HIVE_MIND_SPECIES_CITIZENS_ONLY"
			OR = {
				NOT = { from = { 
										has_authority = auth_hive_mind 
										NOT = { has_valid_civic = civic_harmonious } #ǺгȺ
				} }
				has_trait = trait_hive_mind
			}
		}
		custom_tooltip = {
			fail_text = "HIVE_MIND_MAIN_SPECIES_ALWAYS_CITIZEN"
			NAND = {
				from = { has_authority = auth_hive_mind }
				is_same_species = from
			}
		}
		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 = "disconnected_machine_pops_kill_themselves_citizenship"
			is_disconnected_machine_pop = no
		}
		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 = yes_service_yes_citizenship
			OR = {
				NOT = { from = { has_valid_civic = civic_citizen_service } }
				NOT = { has_military_service_type = { type = military_service_full country = from } }
			}		
		}
	}
	ai_will_do = {
		factor = 3
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				has_ai_personality_behaviour = multispecies
			}
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = no
				OR = {
					has_ethic = ethic_xenophile
					has_ethic = ethic_fanatic_xenophile
				}
			}
		}		
	}
}

citizenship_caste_system = {
	token = citizenship_caste_system

	potential = {
		exists = from
		from = {
		    NOR ={
		       has_ethic = ethic_gestalt_consciousness
		       has_ethic = ethic_xilin_authoritarian_egalitarian
		    }
		}
		NAND = {
			exists = this
			OR = {
				has_trait = trait_mechanical
				has_trait = trait_machine_unit			
			}
		}		
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_citizenship"
			is_lonely_hive_mind_pop = no
		}
		custom_tooltip = {
			fail_text = "disconnected_machine_pops_kill_themselves_citizenship"
			is_disconnected_machine_pop = no
		}
		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 = too_alien
			OR = {
				is_same_species = from
				from = {
					NOR = {
						has_ethic = ethic_xenophobe
						has_ethic = ethic_fanatic_xenophobe
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = does_not_embrace_slavery
			from = {
				allows_slavery = yes
				OR = {
					has_ethic = ethic_authoritarian
					has_ethic = ethic_fanatic_authoritarian
				}
			}		
		}
		custom_tooltip = {
			fail_text = no_service_no_citizenship
			OR = {
				NOT = { from = { has_valid_civic = civic_citizen_service } }
				has_military_service_type = { type = military_service_full country = from }
			}
		}
	}
	ai_will_do = {
		factor = 5		
		modifier = {
			factor = 0
			from = {
				has_valid_civic = civic_syncretic_evolution
				OR = {
					has_ethic = ethic_xenophobe
					has_ethic = ethic_fanatic_xenophobe
				}
			}
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = caste_system
				}
			}
		}		
	}
}

citizenship_caste_system_limited = {
	token = citizenship_caste_system_limited
	
	pop_modifier = {
		pop_happiness = -0.1
		pop_consumer_goods_mult = -0.25	
	}

	potential = {
		exists = from
		from = { NOR = { 
		            has_ethic = ethic_gestalt_consciousness 
		            has_ethic = ethic_xilin_authoritarian_egalitarian
		       } 
		}
		NAND = {
			exists = this
			OR = {
				has_trait = trait_mechanical
				has_trait = trait_machine_unit			
			}
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		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 = "disconnected_machine_pops_kill_themselves_citizenship"
			is_disconnected_machine_pop = no
		}
		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_slavery
			from = {
				allows_slavery = yes
				OR = {
					has_ethic = ethic_authoritarian
					has_ethic = ethic_fanatic_authoritarian
				}
			}		
		}
		custom_tooltip = {
			fail_text = yes_service_yes_citizenship
			OR = {
				NOT = { from = { has_valid_civic = civic_citizen_service } }
				NOT = { has_military_service_type = { type = military_service_full country = from } }
			}
		}	
	}
	ai_will_do = {
		factor = 10
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				has_ai_personality_behaviour = multispecies
			}
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = no
				OR = {
					has_ethic = ethic_xenophile
					has_ethic = ethic_fanatic_xenophile
				}
			}
		}	
		modifier = {
			factor = 0
			from = {
				has_valid_civic = civic_syncretic_evolution
				OR = {
					has_ethic = ethic_xenophobe
					has_ethic = ethic_fanatic_xenophobe
				}
			}
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = caste_system
				}
			}
		}		
	}
}

citizenship_slavery = {
	token = citizenship_slavery

	potential = {
		NAND = {
			exists = this
			OR = {
				has_trait = trait_mechanical
				has_trait = trait_machine_unit		
				from = { has_authority = auth_xilin_mind } #ϣ۹ûū
			  from = { has_valid_civic = civic_harmonious }	#гȺûū
			}
		}			
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = "HIVE_MIND_MAIN_SPECIES_ALWAYS_CITIZEN"
			NAND = {
				from = { has_authority = auth_hive_mind }
				is_same_species = from
			}
		}
		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
		}
		from = { 
			NOR = { 
				has_valid_civic = civic_machine_servitor 
				has_valid_civic = civic_machine_assimilator
				has_valid_civic = civic_machine_terminator
				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
			OR = {
				NOT = { from = { has_valid_civic = civic_citizen_service } }
				NOT = { has_military_service_type = { type = military_service_full country = 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 = yes
				is_xenophobe = no
			}
		}
	}
}

citizenship_purge = {
	token = citizenship_purge
	
	potential = {
		exists = from
		NOT = { from = { has_authority = auth_machine_intelligence } }
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = "HIVE_MIND_MAIN_SPECIES_ALWAYS_CITIZEN"
			NAND = {
				from = { has_authority = auth_hive_mind }
				is_same_species = from
			}
		}
		custom_tooltip = {
			fail_text = same_species_disallowed
			NOT = { is_same_species = from }
		}
		#ӵкгǣ鲻ܲþ
		custom_tooltip = {
			fail_text = tree_spirit_disallowed
			NAND = {
						 from = { has_valid_civic = civic_harmonious_tree }
						 has_trait = trait_tree_spirit
			}
		}
		if = { 
			limit = { is_lonely_hive_mind_pop = yes } 
			always = yes
			
			else = {
				OR = {
					custom_tooltip = {
						#fail_text = default
						AND = {
							from = { has_authority = auth_hive_mind }
							from = { NOT = { has_valid_civic = civic_harmonious }	} #ǺгȺ
							NOT = { is_same_species = from }
						}
					}
					custom_tooltip = {
						#fail_text = default
						AND = {
							from = { has_valid_civic = civic_fanatic_purifiers }
							NOT = { is_same_species = from }
						}
					}					
					AND = {
						NOT = { is_same_species = from }
						OR = {
							from = { allows_purge = yes }
							root = { has_trait = trait_machine_unit }
							root = { has_trait = trait_mechanical }
						}
					}
				}
				custom_tooltip = {
					fail_text = yes_service_yes_citizenship
					OR = {
						NOT = { from = { has_valid_civic = civic_citizen_service } }
						NOT = { has_military_service_type = { type = military_service_full country = from } }
					}
				}
			}
		}
	}
	ai_will_do = {
		factor = 20
		modifier = {
			factor = 0
			has_trait = trait_machine_unit
			from = {
				has_authority = auth_machine_intelligence
			}
		}
		modifier = {
			factor = 0
			from = { 
				has_valid_ai_personality = no 
				NOT = { has_authority = auth_hive_mind }
			}
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOR = {
					has_ai_personality_behaviour = purger
					has_ai_personality_behaviour = displacer
				}
			}
		}
		modifier = {
			factor = 0
			from = {
				has_authority = auth_machine_intelligence
				has_government = gov_machine_industrial		
			}
		}		
		modifier = {
			factor = 0
			from = {
				has_authority = auth_hive_mind
				NOT = { has_valid_civic = civic_hive_devouring_swarm }
				OR = {
					has_valid_civic = civic_hive_one_mind
					has_valid_civic = civic_hive_subsumed_will
				}			
			}
		}
		modifier = {
			factor = 0	
			from = {
				has_civic = civic_syncretic_evolution		
			}
		}
	}
}

military_service_full = {
	token = military_service_full
	
	potential = {
		OR = {
			NAND = {
				from = { has_authority = auth_machine_intelligence }
				NOR = {
					has_trait = trait_machine_unit
					has_trait = trait_mechanical	
				}			
			}
			AND = {
				from = { has_authority = auth_machine_intelligence }
				has_trait = trait_cybernetic
			}
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = MACHINE_NO_PURE_ORGANIC_SOLDIERS
			OR = {
				NOT = { from = { has_authority = auth_machine_intelligence } }
				AND = {
					from = { has_authority = auth_machine_intelligence }
					OR = {
						has_trait = trait_mechanical
						has_trait = trait_machine_unit
					}
				}
				AND = {
					from = {
						has_authority = auth_machine_intelligence
						has_civic = civic_machine_assimilator
					}
					OR = {
						has_trait = trait_mechanical
						has_trait = trait_machine_unit
						has_trait = trait_cybernetic
					}
				}
			}
		}
		custom_tooltip = {
			NOT = { has_citizenship_type = { country = from type = citizenship_purge } }
			text = not_undesirables_tooltip
		}
		custom_tooltip = {
			NOT = { has_citizenship_type = { country = from type = citizenship_slavery } }
			text = not_slaves_tooltip
		}
		custom_tooltip = {
			fail_text = too_alien
			OR = {
				is_same_species = from
				from = {
					NOR = {
						has_ethic = ethic_xenophobe
						has_ethic = ethic_fanatic_xenophobe
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "HIVE_MIND_SPECIES_CITIZENS_ONLY"
			OR = {
				NAND = { 
						from = { has_authority = auth_hive_mind }
						from = { NOT = { has_valid_civic = civic_harmonious } } #ǺгȺ
				}
				has_trait = trait_hive_mind
			}
		}	
		#鲻뿪ǣܻȡȨ
		custom_tooltip = {
			fail_text = "Tree_Spirit_Can_Not_Leave_HomeLand"
			NOT = { has_trait = trait_tree_spirit  }
		}	
		#гȺȺӵܵ˿ڲȨ
		custom_tooltip = {
			fail_text = "HARMONY_HIVE_NEED_PSIONIC_FOR_FULL_MIL"
			OR = {
		      NOT = { from = { 
		      		has_authority = auth_hive_mind 
		      		has_valid_civic = civic_harmonious
		      } }
		      OR = {
		             has_trait = trait_hive_mind
								 has_trait = trait_psionic
								 has_trait = trait_latent_psionic
		      }
		   }
		}		
	}
	ai_will_do = {
		factor = 5
		modifier = {
			factor = 0
			from = { has_valid_ai_personality = no }
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = multispecies
				}
			}
		}
	}
}

military_service_limited = {
	token = military_service_limited
	name = military_service_limited_name

	potential = {
		from = { NAND = { 
				has_ethic = ethic_gestalt_consciousness 
				NOT = { has_valid_civic = civic_harmonious } #ǷǺгȺ
		} }
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = same_species_disallowed
			NOT = { is_same_species = from }
		}
		custom_tooltip = {
			fail_text = species_is_being_purged
			NOT = {
				has_citizenship_type = { country = from type = citizenship_purge }
			}
		}
	}
	ai_will_do = {
		factor = 1
	}
}

purge_normal = {
	token = purge_normal
	
	potential = {
		exists = from
		from = { NOT = { has_valid_civic = civic_hive_devouring_swarm } }
	}
	
	allow = {
		hidden_trigger = { exists = from }
		if = { 
			limit = { is_lonely_hive_mind_pop = yes } 
			always = yes
			
			else = {
				custom_tooltip = {
					fail_text = PURGES_ALLOWED
					from = {
						OR = {
							AND = {
						     has_ethic = ethic_gestalt_consciousness
						     NOT = { has_valid_civic = civic_harmonious } #ǺгȺ
						  }	
							has_valid_civic = civic_fanatic_purifiers
							has_policy_flag = purge_allowed
							root = { 
								OR = { 
									has_trait = trait_machine_unit 
									has_trait = trait_mechanical
								}
							}
						}			
					}
				}	
			}
		}
	}
	ai_will_do = {
		factor = 3
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = purger
				}
			}
		}		
	}
}



purge_processing = {
	token = purge_processing

	potential = {
		host_has_dlc = "Utopia"
		exists = from
		from = { NOT = { has_authority = auth_machine_intelligence } }
	}
	
	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = CAN_NOT_EAT_MACHINES
			NOR = {
				has_trait = trait_mechanical
				has_trait = trait_machine_unit
			}
		}
		custom_tooltip = {
			fail_text = "lonely_hive_mind_pops_kill_themselves_purge_type"
			is_lonely_hive_mind_pop = no
		}
		custom_tooltip = {
			fail_text = PURGES_ALLOWED
			from = {
				OR = {
					AND = {
					   has_ethic = ethic_gestalt_consciousness
					   NOT = { has_valid_civic = civic_harmonious } #ǺгȺ
					}
					has_valid_civic = civic_fanatic_purifiers
					has_policy_flag = purge_allowed
				}					
			}
		}
	}
	ai_will_do = {
		factor = 50
		modifier = {
			factor = 0
			NOR = { 
				has_trait = trait_delicious 
				from = { has_valid_civic = civic_hive_devouring_swarm }
			}
		}
		modifier = {
			factor = 0
			from = {
				has_valid_ai_personality = yes
				NOT = {
					has_ai_personality_behaviour = purger
				}
			}
		}
	}
}

#ͬ
living_standard_deassimilation = {
	token = living_standard_deassimilation
	name = living_standard_deassimilation

	pop_modifier = {
		pop_consumer_goods_add = 2.0
	}

	potential = {
		host_has_dlc = "Utopia"
		exists = from
		has_trait = trait_hive_mind
		from = {
			NOT = { has_ethic = ethic_gestalt_consciousness }
			OR = {
						has_ascension_perk = ap_evolutionary_mastery
						#ϣ۹ƿؽ
						has_modifier = m_evolutionary_mastery
			}
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = SPECIES_MUST_BE_ASSIMILATING
			has_citizenship_type = {
				type = citizenship_assimilation
				country = from
			}
		}
	}

	ai_will_do = {
		factor = 100
	}
}

#ͬ
living_standard_psi_assimilation = {
	token = living_standard_psi_assimilation
	name = living_standard_psi_assimilation

	pop_modifier = {
		pop_happiness = -0.25
		pop_consumer_goods_add = 2.0
	}

	potential = {
		host_has_dlc = "Utopia"
		exists = from
		from = {
			OR = {
					has_ascension_perk = ap_transcendence
					#ϣ۹ĳʤ
					has_country_flag =  f_transcendence
			}
		}
		#ʹͽͬ
		NOR ={
				has_trait = trait_magic_machine
		    has_trait = trait_divinity
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = SPECIES_MUST_BE_ASSIMILATING
			has_citizenship_type = {
				type = citizenship_assimilation
				country = from
			}
		}
	}

	ai_will_do = {
		factor = 100
	}
}


living_standard_chemical_bliss = {
	token = living_standard_chemical_bliss
	name = living_standard_chemical_bliss

	pop_modifier = {
		pop_happiness = 0.4
		pop_consumer_goods_add = 2.0
		pop_resource_output = -0.6
	}
	
	potential = {
	  #ϣ۹ʹûѧ
		from = { 
		   has_technology = tech_subdermal_stimulation 
		   NOT = { has_authority = auth_xilin_mind } 
		}
		NOT = { has_trait = trait_hive_mind }
		NOR = {
			has_trait = trait_mechanical
			has_trait = trait_machine_unit
			#ʹͽܻѧӰ
			has_trait = trait_magic_machine
			has_trait = trait_divinity
		}		
	}

	allow = {
		hidden_trigger = { exists = from }
		NOR = {
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_slavery }
					NOR = { 
						has_slavery_type = { country = from type = slavery_military } 
						has_slavery_type = { country = from type = slavery_livestock } 
						has_slavery_type = { country = from type = slavery_matrix } 
					}
				}
				text = is_slaves_not_battle_thralls_or_livestock
			}
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_purge }
					NOT = { has_purge_type = { country = from type = purge_neutering } }
				}
				text = is_purged_not_neutered
			}
		}
		custom_tooltip = {
			fail_text = SPECIES_MUST_NOT_BE_ASSIMILATING
			NOT = {
				has_citizenship_type = {
					type = citizenship_assimilation
					country = from
				}
			}
		}
	}

	ai_will_do = {
		factor = 0
	}
}

living_standard_academic_privilege = {
	token = living_standard_academic_privilege
	name = living_standard_academic_privilege_name

	pop_modifier = {
		pop_happiness = 0.1
		pop_consumer_goods_add = 1.5
		tile_resource_engineering_research_mult = 0.1
		tile_resource_physics_research_mult = 0.1
		tile_resource_society_research_mult = 0.1		
	}
	
	potential = {
		from = { NOT = { has_ethic = ethic_gestalt_consciousness } }
		NOT = { has_trait = trait_hive_mind }
	}
	
	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = species_is_not_organic
			NAND = {
				from = { is_mechanical_empire = no }
				OR = {
					has_trait = trait_mechanical
					has_trait = trait_machine_unit				
				}
			}
		}
		custom_tooltip = {
			fail_text = empire_not_materialist
			from = {
				OR = {
					has_ethic = ethic_materialist
					has_ethic = ethic_fanatic_materialist
					has_ethic = ethic_xilin_spiritualist_materialist  #ʾͳһ
				}
			}
		}
		NOR = {
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_slavery }
					NOT = { has_slavery_type = { country = from type = slavery_military } }
				}
				text = is_slaves_not_battle_thralls
			}
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_purge }
					NOT = { has_purge_type = { country = from type = purge_neutering } }
				}
				text = is_purged_not_neutered
			}
		}
		custom_tooltip = {
			fail_text = SPECIES_MUST_NOT_BE_ASSIMILATING
			NOT = {
				has_citizenship_type = {
					type = citizenship_assimilation
					country = from
				}
			}
		}
		#ϣ۹,޷
		custom_tooltip = {
			fail_text = MORTALS_CANT_RESHEACH_SUCH_DEEP_TECH
			NAND = {
				from = { has_ethic = ethic_xilin_spiritualist_materialist }
				NOR = {
				   has_trait = trait_magic_machine
				   has_trait = trait_divinity
				}
			}
		}
	}

	ai_will_do = {
		factor = 10
		modifier = {
			factor = 0
			NOT = { has_citizenship_type = { country = from type = citizenship_full } }
		}
		modifier = {
			factor = 0
			NOT = { has_living_standard = { country = from type = living_standard_academic_privilege } }
			NOT = {
				from = {
					has_monthly_income = {
						resource = minerals
						value > 300
					}	
				}
			}
		}
		modifier = {
			factor = 0
			has_living_standard = { country = from type = living_standard_academic_privilege }
			NOT = {
				from = {
					has_monthly_income = {
						resource = minerals
						value > 200
					}	
				}			
			}
		}		
	}
}

living_standard_utopian = {
	token = living_standard_utopian
	name = living_standard_utopian_name

	pop_modifier = {
		pop_happiness = 0.2
		pop_consumer_goods_add = 1.5
	}
	
	potential = {
		from = { NAND = { 
									has_ethic = ethic_gestalt_consciousness 
									NOT = { has_valid_civic = civic_harmonious }
						} }
		NOR = { 
		   has_trait = trait_hive_mind 
		   has_trait = trait_magic_machine
		}
	}
	
	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = species_is_not_organic
			NOR = {
				has_trait = trait_mechanical
				has_trait = trait_machine_unit
			}
		}
		custom_tooltip = {
			fail_text = empire_not_egalitarian
			from = {
				OR = {
					has_ethic = ethic_egalitarian
					has_ethic = ethic_fanatic_egalitarian
					#ϣ۹
					AND={
					    has_authority = auth_xilin_mind
					    has_ethic = ethic_xilin_spiritualist_materialist
					}
					#гȺ
					has_valid_civic = civic_harmonious
				}
			}
		}
		NOR = {
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_slavery }
					NOT = { has_slavery_type = { country = from type = slavery_military } }
				}
				text = is_slaves_not_battle_thralls
			}
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_purge }
					NOT = { has_purge_type = { country = from type = purge_neutering } }
				}
				text = is_purged_not_neutered
			}
		}
		custom_tooltip = {
			fail_text = SPECIES_MUST_NOT_BE_ASSIMILATING
			NOT = {
				has_citizenship_type = {
					type = citizenship_assimilation
					country = from
				}
			}
		}
	}

	ai_will_do = {
		factor = 15
		modifier = {
			factor = 0
			NOT = { has_citizenship_type = { country = from type = citizenship_full } }
		}
		modifier = {
			factor = 0
			NOT = { has_living_standard = { country = from type = living_standard_utopian } }
			NOT = {
				from = {
					has_monthly_income = {
						resource = minerals
						value > 300
					}	
				}
			}
		}
		modifier = {
			factor = 0
			has_living_standard = { country = from type = living_standard_utopian }
			NOT = {
				from = {
					has_monthly_income = {
						resource = minerals
						value > 200
					}	
				}			
			}
		}		
	}
}

living_standard_good = {
	token = living_standard_good
	name = living_standard_good_name

	pop_modifier = {
		pop_happiness = 0.1
		pop_consumer_goods_add = 1.25
	}
	
	potential = {
		from = { NAND = { 
										has_ethic = ethic_gestalt_consciousness
										NOT = { has_valid_civic = civic_harmonious } 
						 } }
		NOT = { 
		   has_trait = trait_hive_mind
		   has_trait = trait_magic_machine
	  }
	}
	
	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = species_is_not_organic
			NAND = {
				from = { is_mechanical_empire = no }
				OR = {
					has_trait = trait_mechanical
					has_trait = trait_machine_unit				
				}
			}
		}
		NOR = {
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_slavery }
					NOT = { has_slavery_type = { country = from type = slavery_military } }
				}
				text = is_slaves_not_battle_thralls
			}
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_purge }
					NOT = { has_purge_type = { country = from type = purge_neutering } }
				}
				text = is_purged_not_neutered
			}
		}
		custom_tooltip = {
			fail_text = SPECIES_MUST_NOT_BE_ASSIMILATING
			NOT = {
				has_citizenship_type = {
					type = citizenship_assimilation
					country = from
				}
			}
		}
	}
	ai_will_do = {
		factor = 5
		modifier = {
			factor = 0
			NOT = { has_citizenship_type = { country = from type = citizenship_full } }
		}
		modifier = {
			factor = 0
			from = {
				NOR = {
					has_ethic = ethic_pacifist
					has_ethic = ethic_fanatic_pacifist
					has_ethic = ethic_egalitarian
					has_ethic = ethic_fanatic_egalitarian
				}
			}
		}
		modifier = {
			factor = 0
			NOT = { has_living_standard = { country = from type = living_standard_good } }
			NOT = {
				from = {
					has_monthly_income = {
						resource = minerals
						value > 150
					}	
				}		
			}
		}
		modifier = {
			factor = 0
			has_living_standard = { country = from type = living_standard_good }
			NOT = {
				from = {
					has_monthly_income = {
						resource = minerals
						value > 100
					}	
				}			
			}
		}
	}
}

living_standard_normal = {
	token = living_standard_normal
	name = living_standard_normal_name

	pop_modifier = {
	 	pop_consumer_goods_add = 1.0
	}
	
	potential = {
		from = { NAND = { 
										has_ethic = ethic_gestalt_consciousness
										NOT = { has_valid_civic = civic_harmonious } 
						 } } #ǷǺгȺ
		NOT = { has_trait = trait_hive_mind }
	}
	
	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = SPECIES_MUST_NOT_BE_ASSIMILATING
			NOT = {
				has_citizenship_type = {
					type = citizenship_assimilation
					country = from
				}
			}
		}
		NOR = {
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_slavery }
					NOT = { has_slavery_type = { country = from type = slavery_military } }
				}
				text = is_slaves_not_battle_thralls
			}
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_purge }
					NOT = { has_purge_type = { country = from type = purge_neutering } }
				}
				text = is_purged_not_neutered
			}
		}
	}
	ai_will_do = {
		factor = 1
	}
}

living_standard_poor = {
	token = living_standard_poor
	name = living_standard_poor_name

	pop_modifier = {
	 	pop_consumer_goods_add = 0.75
		pop_happiness = -0.1
	}
	
	potential = {
		from = { NAND = { 
								has_ethic = ethic_gestalt_consciousness 
								NOT = { has_valid_civic = civic_harmonious }
						} }
		NOR = { 
		   has_trait = trait_hive_mind 
		   has_trait = trait_magic_machine
		}
	}
	
	allow = {
		hidden_trigger = { exists = from }
		OR = {
			NOT = { has_citizenship_type = { country = from type = citizenship_full } }
			custom_tooltip = {
				fail_text = empire_is_egalitarian
				from = {
					NOR = {
						has_ethic = ethic_egalitarian 
						has_ethic = ethic_fanatic_egalitarian 
					}
				}
			}
		}
		NOT = {
			custom_tooltip = {
				AND = {
					has_citizenship_type = { country = from type = citizenship_purge }
					NOT = { has_purge_type = { country = from type = purge_neutering } }
				}
				text = is_purged_not_neutered
			}
		}
		custom_tooltip = {
			fail_text = SPECIES_MUST_NOT_BE_ASSIMILATING
			NOT = {
				has_citizenship_type = {
					type = citizenship_assimilation
					country = from
				}
			}
		}
	}
	ai_will_do = {
		factor = 5
		modifier = {
			factor = 0
			NOR = { 
				has_citizenship_type = { country = from type = citizenship_limited } 
				has_citizenship_type = { country = from type = citizenship_caste_system_limited } 
			}
		}
		modifier = {
			factor = 0
			from = { has_ai_personality_behaviour = multispecies }
		}
	}
}

# Used for pops that have no happiness
living_standard_hive_mind = {
	token = living_standard_hive_mind
	name = living_standard_hive_mind_name

	pop_modifier = {
	 	pop_consumer_goods_add = 0.5
	}

	potential = {
		#ʽ֮
		OR = {
			from = { has_ethic = ethic_gestalt_consciousness }
			AND = {
					has_trait = trait_hive_mind
					from = {
						OR = {
								has_valid_civic = civic_harmonious_tree
								has_modifier = m_kala_gift
						}
					}
			}
		}
	}	
	
	allow = {
		hidden_trigger = { from = {	
		    #Ⱥһ֮
				OR = {
					has_ethic = ethic_gestalt_consciousness
					has_valid_civic = civic_harmonious_tree
					has_modifier = m_kala_gift
				} 
		} }
		#Ⱥ˿
		custom_tooltip = {
			fail_text = species_is_not_hive
			OR = {
				AND = {
					has_trait = trait_hive_mind
					from = {
						OR = {
								has_authority = auth_hive_mind 
								has_valid_civic = civic_harmonious_tree
								has_modifier = m_kala_gift
						}					
					}
				}
				NOT = { from = { 
						OR = {
								has_authority = auth_hive_mind 
								has_valid_civic = civic_harmonious_tree
								has_modifier = m_kala_gift
						}
				} }
			}
		}
		custom_tooltip = {
			fail_text = species_is_not_machine
			OR = {
				NOT = { from = { has_authority = auth_machine_intelligence } }
				AND = {
					from = { has_authority = auth_machine_intelligence }
					OR = {
						has_trait = trait_machine_unit
						has_trait = trait_mechanical
						AND = {
							from = { has_civic = civic_machine_assimilator }
							has_trait = trait_cybernetic
						}
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = SPECIES_MUST_NOT_BE_ASSIMILATING
			NOT = {
				has_citizenship_type = {
					type = citizenship_assimilation
					country = from
				}
			}
		}
	}
	
	ai_will_do = {
		factor = 1
	}
}

migration_control_yes = {
	token = migration_control_yes
	
	allow = {
		hidden_trigger = { exists = from }	
	}
	
	ai_will_do = {
		factor = 5
		modifier = {
			factor = 0
			is_same_species = from
			from = {
				is_country_type = default
				NOR = {
					has_ethic = ethic_authoritarian
					has_ethic = ethic_fanatic_authoritarian
					has_ethic = ethic_gestalt_consciousness
				}
			}
		}
		modifier = {
			factor = 0
			NOT = { is_same_species = from }
			from = {
				is_country_type = default
				has_valid_ai_personality = yes
				NOR = {
					has_ethic = ethic_gestalt_consciousness
					NOT = { has_ai_personality_behaviour = multispecies }
				}
			}
		}
		#гܿ
		modifier = {
			factor = 0
			from = {
				OR = {
					has_authority = auth_xilin_mind
					has_valid_civic = civic_harmonious 
					has_valid_civic = civic_harmonious_tree
				}
			}
			NOT = { has_trait = trait_tree_spirit }
		}
	}
}

migration_control_no = {
	token = migration_control_no

	potential = {
		exists = from
		NOR = {
			has_trait = trait_machine_unit
			#Ⱥ
			AND = {
				has_trait = trait_hive_mind
				NOT = { has_trait = trait_tree_spirit }
			}
		}
	}
	
	allow = {
		hidden_trigger = { exists = from }
		NOR = { 
			has_citizenship_type = { country = from type = citizenship_purge } 
			has_citizenship_type = { country = from type = citizenship_slavery } 
			has_citizenship_type = { country = from type = citizenship_caste_system } 
			has_citizenship_type = { country = from type = citizenship_caste_system_limited } 
		}	
		#
		NOT = { has_trait = trait_tree_spirit }
	}
	ai_will_do = {
		factor = 1
	}
}

population_control_yes = {
	token = population_control_yes

	potential = {
		#ϣ۹ϳò˿ڹ
		NAND = {
				from = { has_authority = auth_xilin_mind }
				has_trait = trait_robotic_3
		}
		#always = yes
	}

	pop_modifier = {
		biological_pop_happiness = -0.1
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = same_species_disallowed
			OR = {
				NOT = { is_same_species = from }
				from = { has_authority = auth_machine_intelligence }
			}
		}
		#г˿ڹܿ
		custom_tooltip = {
			fail_text = empire_xenophile
			from = {
				NOR = {
					has_ethic = ethic_xenophile
					has_ethic = ethic_fanatic_xenophile
					has_valid_civic = civic_harmonious
					has_valid_civic = civic_harmonious_tree
				}
			}
		}	
	}
	ai_will_do = {
		factor = 2
		modifier = {
			factor = 0
			from = {
				OR = {
					NOT = { has_authority = auth_machine_intelligence }
					AND = {
						has_authority = auth_machine_intelligence
						has_valid_civic = civic_machine_assimilator
					}
				}
			}
		}
		#ϣ۹򲻽˿ڿ
		modifier = {
			factor = 0
			from = {
				has_authority = auth_xilin_mind
			}
		}
	}
}

population_control_no = {
	token = population_control_no

	potential = {
		NAND = {
			from = { is_mechanical_empire = no }
			OR = {
				has_trait = trait_mechanical
				has_trait = trait_machine_unit				
			}
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		NOT = { has_citizenship_type = { country = from type = citizenship_purge } }
		custom_tooltip = {
			fail_text = "HIVE_MIND_SPECIES_CITIZENS_ONLY"
			OR = {
				NAND = { 
				   from = { has_authority = auth_hive_mind } 
				   from = { NOT = { has_valid_civic = civic_harmonious } } #ǺгȺ
				}
				has_trait = trait_hive_mind
			}
		}
	}
	ai_will_do = {
		factor = 1
	}
}

colonization_control_yes = {
	token = colonization_control_yes
	
	potential = {
		NAND = {
			from = { has_authority = auth_machine_intelligence }
			OR = {
				has_trait = trait_machine_unit
				has_trait = trait_mechanical	
			}			
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		custom_tooltip = {
			fail_text = same_species_disallowed
			NOT = { is_same_species = from }
		}		
	}

	ai_will_do = {
		factor = 2
		modifier = {
			factor = 0
			from = { 
				NOR = {
					has_ethic = ethic_xenophobe
					has_ethic = ethic_fanatic_xenophobe
					has_ethic = ethic_gestalt_consciousness
				}
			}
		}
		modifier = {
			factor = 0
			has_trait = trait_cybernetic
			from = { has_valid_civic = civic_machine_assimilator }		
		}
		#гȺaiڲֳܿ
		modifier = {
			factor = 0
			from = {  has_valid_civic = civic_harmonious }		
		}	
		#ϣ۹aiڲֳܿ
		modifier = {
			factor = 0
			from = {  has_authority = auth_xilin_mind  }		
		}
	}
}

colonization_control_no = {
	token = colonization_control_no

	potential = {
		NAND = {
			from = { has_authority = auth_machine_intelligence }
			NOR = {
				has_trait = trait_machine_unit
				has_trait = trait_mechanical	
				AND = {
					has_trait = trait_cybernetic
					from = { has_valid_civic = civic_machine_assimilator }		
				}
			}			
		}
	}

	allow = {
		hidden_trigger = { exists = from }
		#
		NOT = { has_trait = trait_tree_spirit }
		NOT = { has_citizenship_type = { country = from type = citizenship_purge } }
		custom_tooltip = {
			fail_text = "HIVE_MIND_SPECIES_CITIZENS_ONLY"
			OR = {
				NAND = { 
					from = { has_authority = auth_hive_mind } 
					from = { NOT = { has_valid_civic = civic_harmonious } } #ǺгȺ
				}
				has_trait = trait_hive_mind
			}
		}
	}
	ai_will_do = {
		factor = 1
	}
}
