#Tooltips will be generated from these rules when they fail. Use of custom_tooltip is recommended
#There are still multiple hard-coded rules that apply in addition to these.
#If rules here evaluate to true, there might still be other rules that make the action unavailable.
#If a rule here evaluates to false the action will become unavailable


#This = country
can_release_vassal = {
	custom_tooltip = {
		fail_text = default
		NOT = { has_valid_civic = civic_fanatic_purifiers }
	}
	custom_tooltip = {
		fail_text = default
		NOT = { has_valid_civic = civic_machine_terminator }
	}
	custom_tooltip = {
		fail_text = default
		NOT = { has_valid_civic = civic_machine_assimilator }
	}
	custom_tooltip = {
		fail_text = default
		NOT = { has_valid_civic = civic_hive_devouring_swarm }
	}
	custom_tooltip = {
		fail_text = requires_domination_adopted
		has_tradition = tr_domination_adopt
	}
	custom_tooltip = {
		fail_text = CANNOT_RELEASE_CULTURE_SHOCK
		root = {
			NOT = {
				any_owned_pop = {
					has_culture_shock = yes
				}
			}
		}		
	}
	custom_tooltip = {
		fail_text = default
		NOT = { has_authority = auth_xilin_mind } #ϣ۹޷ͷŸӹ
	}
}


#Root = country
#This = planet
can_terraform_planet = {
	#δ
	custom_tooltip = {
		fail_text = "PRE_SAPIENTS_PROTECT_NOT_ALLOW_TERRAFORM"
		NAND = {
			root = { has_policy_flag = pre_sapients_protect }
			any_owned_pop = { is_sapient = no }
		}
	}
	#####
	#гȺʶֻܶԺѡת
	custom_tooltip = {
		fail_text = "HARMONY_HIVE_MIND_NOT_ALLOW_TERRAFORM"
		OR = {
			root = {
				NAND = {
					has_authority = auth_hive_mind
				  has_valid_civic = civic_harmonious			
				}
			}
	  	has_modifier = terraforming_candidate
		}
	}
	#гǻĹңʱܽת
	custom_tooltip = {
		fail_text = "PLANET_HAS_LIVE_TREE_NOT_ALLOW_TERRAFORM"
		NAND = {
			root ={
				OR = {
						has_valid_civic = civic_harmonious_tree
						has_modifier = m_kala_gift
				}
			}
			OR = {
				has_building_construction = building_life_tree_seed
				has_building = building_life_tree_seed
				has_blocker =  tb_growing_life_tree
				has_building = building_life_tree
				has_building = building_mother_life_tree
			}
		}
	}
	conditional_tooltip = {
			text = HARMANY0_PROGRESS
			trigger = {
			  OR = {
			       is_planet_class = pc_nuked
			       is_planet_class = pc_machine
			  }	
			  OR = {
			  		has_modifier = m_destroy_harmony
			  		has_modifier = m_build_harmony
			  }
			}
	}	
	conditional_tooltip = {
			text = HARMANY1_PROGRESS
			trigger = {
				NOR = { 
						AND = {
			      	has_modifier = m_harmony_1
			      	has_modifier = m_build_harmony
			      } 
			      has_modifier = m_harmony_2
			      has_modifier = m_harmony_3
			      has_modifier = m_harmony_4
			      has_modifier = m_harmony_5
			  }
			  OR = {
			  		has_modifier = m_destroy_harmony
			  		has_modifier = m_build_harmony
			  }
			  NOR = {
			      is_planet_class = pc_nuked
			      is_planet_class = pc_machine
			  }	
			 	NOR = {
			   		is_planet_class = pc_gaia
						habitable_structure = yes			   		    				
			  }	
			}
	}
	conditional_tooltip = {
			text = HARMANY2_PROGRESS
			trigger = {
				OR = {
				  	AND = {
			      		has_modifier = m_harmony_1
			      		has_modifier = m_build_harmony
			      }
			      AND = {
			      		has_modifier = m_harmony_2
			      		has_modifier = m_destroy_harmony
			      }
			  }
			  NOR = {
			   		is_planet_class = pc_gaia
						habitable_structure = yes			   		    				
			  }		
			}
	}	
	conditional_tooltip = {
			text = HARMANY3_PROGRESS
			trigger = {
				OR = {
				  	AND = {
			      		has_modifier = m_harmony_2
			      		has_modifier = m_build_harmony
			      }
			      AND = {
			      		has_modifier = m_harmony_3
			      		has_modifier = m_destroy_harmony
			      }
			  }
			  NOR = {
			   		is_planet_class = pc_gaia
						habitable_structure = yes			   		    				
			  }	
			}
	}	
	conditional_tooltip = {
			text = HARMANY4_PROGRESS
			trigger = {
				OR = {
				  	AND = {
			      		has_modifier = m_harmony_3
			      		has_modifier = m_build_harmony
			      }
			      AND = {
			      		has_modifier = m_harmony_4
			      		has_modifier = m_destroy_harmony
			      }
			  }
			  NOR = {
			   		is_planet_class = pc_gaia
						habitable_structure = yes			   		    				
			  }	
			}
	}	
	conditional_tooltip = {
			text = HARMANY5_PROGRESS
			trigger = {			
				OR = {
				  	AND = {
				  			#owner = { has_technology = "tech_gaia_creation" }
			      		OR = {
												has_modifier = m_harmony_4
												is_planet_class = pc_gaia
												habitable_structure = yes
								}
			      		has_modifier = m_build_harmony
			      }
			      AND = {
			      		has_modifier = m_harmony_5
			      		has_modifier = m_destroy_harmony
			      }
			  }
			}
	}
	#ֽȼ¼
	conditional_tooltip = {
			text = LIFE_TREE_SEED_PROGRESS
			trigger = {			
				 #ĸ
				 has_building = building_mother_life_tree
				 #<2000
				 owner = {
				 		NOT = { has_authority = auth_hive_mind }
				 		check_variable =  { which = "seed_num"  value < 2000 }
				 }
			}
	}

}

#Root = country
#This = pop
can_generate_leader_from_pop = {
	has_citizenship_rights = yes
	OR = {
		is_robot_pop = no
		root = {
		  NOT = { has_authority = auth_xilin_mind } #ϣ۹Уͨ޷λ
		  has_technology = tech_synthetic_leaders 
		}
		root = { has_authority = auth_machine_intelligence }
		root = { is_mechanical_empire = yes }
	}
}

# Can purge/disassembly be individually stopped by owner
# scope: pop
can_stop_purge_pop_manually = {
	custom_tooltip = {
		fail_text = "ENTIRE_SPECIES_BEING_PURGED"	
		NOT = { has_citizenship_type = { type = citizenship_purge } }
	}
	#ǷȺгңû
	custom_tooltip = {
		fail_text = "TREE_SPIRIT_LOST_LIFE_TREE"	
		NAND = {
				has_trait = trait_tree_spirit
				owner = { NOT = { has_authority = auth_hive_mind } }
				planet = { 
						NOR = {
							has_blocker =  tb_growing_life_tree
							has_building = building_life_tree
							has_building = building_mother_life_tree
						}
				}
		}
	}
}

# Can the pop be purged/disassembled individually by its owner
# scope: pop
can_purge_pop_manually = {
	custom_tooltip = {
		fail_text = "ALREADY_BEING_PURGED"	
		NOT = { has_citizenship_type = { type = citizenship_purge } }
	}
	custom_tooltip = {
		fail_text = "ACTION_CANNOT_PURGE_CITIZEN"	
		OR = {
			is_robot_pop = yes
			is_sapient = no
			owner = { has_authority = auth_hive_mind }
			AND = {
				 has_trait = trait_hive_mind
			   owner = {
			   		OR = {
			   				has_valid_civic = civic_harmonious_tree
			   				has_valid_civic = civic_harmonious
			   				has_modifier = m_kala_gift 
			   		} 
			   }
			}
			has_citizenship_type = { type = citizenship_slavery }
			has_citizenship_type = { type = citizenship_full_machine }
		}		
	}
	custom_tooltip = {
		fail_text = "ACTION_CANNOT_PURGE_POLICY"	
		OR = {
			is_robot_pop = yes
			AND = {
				is_sapient = no
				owner = { NOT = { has_policy_flag = pre_sapients_protect } }
			}
			owner = {  has_ethic = ethic_gestalt_consciousness  }
			AND = {
				 has_trait = trait_hive_mind
			   owner = {
			   		OR = {
			   				has_valid_civic = civic_harmonious_tree
			   				has_valid_civic = civic_harmonious
			   				has_modifier = m_kala_gift 
			   		} 
			   }
			}
			owner = { has_policy_flag = purge_allowed }
		}		
	}	
	#ϣ˲ܾ?
	custom_tooltip = {
		fail_text = "ACTION_DISASSEMBLE_SYNTHETICS"		
		OR = {
			is_robot_pop = no
			owner = { 
					has_authority = auth_hive_mind 
					NOT = { has_valid_civic = civic_harmonious }
			}
			NAND = {
				OR = { 
					has_trait = trait_robotic_3 
					has_trait = trait_robotic_xilin
				}
				owner = { has_policy_flag = ai_full_rights }
			}	
		}
	}
	#гȺֻȺ˿
	custom_tooltip = {
		fail_text = "ACTION_CANOT_PURGE_NO_HIVE_POP"		
		OR = {
			owner = { 
				NAND = {
						has_authority = auth_hive_mind  
						has_valid_civic = civic_harmonious 
				}					
			}
			has_trait = trait_hive_mind
		}
	}
	#г̫ʱֶ
	custom_tooltip = {
		fail_text = "ACTION_CANOT_PURGE_TOO_LITTLE_TREE_SPIRIT"		
		OR = {
			owner = { 
				NOR = {
						has_modifier = m_kala_gift 						
						has_valid_civic = civic_harmonious_tree						
				}					
			}
			AND = {
					has_trait = trait_hive_mind
					Planet = { tree_spirit_enough_num_to_purge = yes }
			}		
		}
	}
}

# Root = Pop
# From = Country
# This = Pop
pop_eats_energy = {
	OR = {
		pop_maintenance_cost > 0
		has_trait = trait_machine_unit # Native machine
		has_trait = trait_mechanical # Robot	
		AND = {
			exists = from
			from = { has_authority = auth_machine_intelligence }
			NOT = { 
				has_citizenship_type = {
					type = citizenship_organic_trophy
					country = from
				}			
			}
		}
		AND = {
			has_trait = trait_magic_machine
			has_pop_flag = f_pop_eat_energy
		}
	}
}

#ϣ۹ϳ˵ͨ￴ɻþλ
# root: country
# this: target species
can_species_have_rights = {
	exists = root
	exists = this
	is_sapient = yes
	NOT = {
		has_trait = trait_robotic_1
		has_trait = trait_robotic_2
		AND = {
		   has_trait = trait_robotic_3
		   root = { NOT = { has_authority = auth_xilin_mind } } #ϣ۹ϳ˵ͨ￴ɻþλ
		}
		has_trait = trait_robotic_xilin
	}
}

# Root = claimer
# This = system
can_add_claim = {	
	hidden_trigger = {
		if = {
			limit = {
				root = { NOT = { is_country_type = default } }
			}
			always = yes
		}
	}
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_POLICY
		OR = {
			root = { has_policy_flag = unrestricted_wars }		
			AND = {
				exists = owner
				owner = {
					any_war = {
						any_attacker = { is_same_value = prevprev }
						any_defender = { is_same_value = root }
					}			
				}				
			}			
		}
	}
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_NOT_VALID_EMPIRE 
		NAND = {
			exists = owner		
			owner = {
				NOR = {
					is_country_type = default
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
			}
		}
	}	
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_DEVOURING_SWARM
		NOT = { root = { has_valid_civic = civic_hive_devouring_swarm }	}
	}	
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_PURIFIERS		 
		NAND = {
			exists = owner
			root = { has_valid_civic = civic_fanatic_purifiers }		
			NOT = {	owner = { is_same_species = root } }
		}
	}
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_EXTERMINATOR
		NAND = {
			exists = owner
			root = { has_valid_civic = civic_machine_terminator }
			owner = {
				NOR = {
					is_same_species = root
					has_country_flag = synthetic_empire
					has_authority = auth_machine_intelligence
				}
			}
		}
	}
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_THEY_COLOSSUS
		NAND = {
			exists = owner
			NOT = { root = { has_ascension_perk = ap_colossus } }
			owner = { has_ascension_perk = ap_colossus }
			root = { is_rival = prev.owner }		
		}
	}	
	custom_tooltip = { #˴
		fail_text = CANNOT_ADD_CLAIM_COLOSSUS
		OR = {
			AND = {
				exists = owner
				NOT = { root = { is_rival = prev.owner } }
			}		
			NOT = { root = { has_ascension_perk = ap_colossus } }
		}	
	}
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_THEY_THREAT
		NAND = {
			exists = owner
			owner = {
				OR = {
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_machine_terminator
				}
			}
			root = {
				NOR = {
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_machine_terminator			
				}
			}			
		}
	}
	#ϣ۹ֻܶԵжԹҼ
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_XILIN
		NAND = {
			exists = owner
			root = {
					has_authority = auth_xilin_mind
			}
			owner = {
				is_xilin_enemy = no #rootΪϣ۹
			}						
		}
	}
	#ͬƵĹҲٶϣ龳
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_GREE_TO_XILIN
		NAND = {
			exists = owner
			root = {
					has_country_flag = f_agree_destroy_claim 
			}
			owner = {
				  has_authority = auth_xilin_mind
			}						
		}
	}
}

#޸
#Root = country, attacker
#This = country, target
#This rule is a condition for declaring war
can_declare_war = {
	custom_tooltip = {
		fail_text = "ACTION_DECLARE_WAR_OVERLORD_ON_SUBJECT"
		NOT = {
			AND = {
				OR = {
					is_subject_type = "vassal"
					is_subject_type = "protectorate"
					is_subject_type = "signatory"
					is_subject_type = "xilin_blessed"
					is_subject_type = "xilin_follower_vassal" 
					is_subject_type = "xilin_follower_protector" 
					is_subject_type = "xilin_servant"
					is_subject_type = "xilin_discipline"
				}
				overlord = {
					is_same_value = root
				}
			}
		}
	}
	custom_tooltip = {
		fail_text = "CAN_DECLARE_WAR_XILIN"
		OR = {
		  AND ={
		  	#ϣ۹
			  exists = root
	      ROOT = {
	         NOT= { has_authority = auth_xilin_mind }
	      }
		  }
			AND = {
			  #ϣ۹
			  exists = root
	      ROOT = {
	          has_authority = auth_xilin_mind
	      }
				#ս
				is_xilin_enemy = yes  #rootΪϣ۹
			} #NAND
		} #OR
	}
	if = {
		limit = {
			exists = root
			ROOT = {
				has_policy_flag = no_wars
				OR = {
					is_subject = no
					overlord = {
						is_same_value = root
					}
				}
			}
		}
		custom_tooltip = {
			text = "CAN_DECLARE_WAR_POLICY"
			always = no
		}
	}
	
}

#Root = country
#This = planet
can_colonize_planet = {
	Root = { NOT = { is_subject_type = xilin_discipline } } #ͽζ޷ֳ
}

# Checks if a pop can procreate
# This = Pop
can_pop_procreate = {
	is_sapient = yes
	is_being_purged = no
	has_population_control = no
	has_culture_shock = no
	pop_can_reproduce = yes
	exists = planet
	OR = {
		planet = { NOT = { has_modifier = land_appropriation } }
		has_citizenship_rights = yes
	}
	#мƻʱӦֹͣ
	NAND = {
			planet = { has_modifier = m_family_planning_major } 
			has_trait = trait_magic_machine
	}
	#û鱣ʱƻ
	NAND = {
			planet = { has_modifier = m_family_planning_minor } 
			NOT = { has_trait = trait_magic_machine }
			owner = { NOT = { has_modifier = m_protect_tree_spirit_edict } } 
	}
	#鱣ʱƻ
	NAND = {
			planet = { has_modifier = m_family_planning_minor } 
			NOT = { has_trait = trait_magic_machine }
			owner = { has_modifier = m_protect_tree_spirit_edict  } 
			OR = {
			    #ͨ
					NOT = { has_trait = trait_tree_spirit }
					#Ҵﵽɸ
					AND = {
							has_trait = trait_tree_spirit
							planet = { grown_harmonize_hive_is_enough = yes }
					}
			}
	}
	
	#鱣֤ռ1/3ռ
	#鱣֤ռ1/3ռ
	OR = {
	    #û
			planet = {
					NOR = {
							has_building = building_life_tree
							has_building = building_mother_life_tree
							has_blocker =  tb_growing_life_tree	
					}
			}
			#û鱣
			owner = { NOT = { has_modifier = m_protect_tree_spirit_edict } } 
			#
			has_trait = trait_hive_mind
			#㹻ռ
			planet = { 
					can_grow_no_affect_tree_spirit = yes #Ӱ
			}	
	}
	#˿ֹͣ
	NAND = {
			planet = { has_modifier = m_tree_spirit_population_control } 
			has_trait = trait_hive_mind
	}
}

# Check if a player can resettle a pop to a tile on another planet
# This = Pop
# From = Country
# FromFrom = Target tile, optional
can_resettle_pop = {
	custom_tooltip = {
		fail_text = "RESETTLE_POP_IS_GROWING"
		exists = this
		is_growing = no
	}
	#鲻Ǩ
	custom_tooltip = {
		fail_text = "RESETTLE_POP_IS_REFUSING"
		exists = this
		NOR = { 
				has_trait = trait_self_modified 
				has_trait = trait_tree_spirit 
		}
	}
	custom_tooltip = {
		fail_text = "RESETTLEMENT_POLICY_DISABLED"
		OR = {
			FROM = {
				has_policy_flag = resettlement_allowed
			}
			FROM = {
				has_ethic = "ethic_gestalt_consciousness"
			}
			AND = {
				exists = this
				OR = {
					has_trait = trait_robotic_1 # allow if non-sapient robot
					has_trait = trait_robotic_2 # allow if non-sapient robot
					is_enslaved = yes # allow if enslaved
				}
			}
		}
	}
}

#Root = country
#This = pop
#also evaluates true if pop_can_live_planet is false on current planet
can_auto_migrate_pop = {
	root = { is_country_type = default }
	is_sapient = yes
	is_enslaved = no
	is_being_purged = no
	has_migration_control = no
	is_robot_pop = no
	#2.0汾仯,ֻ岻ͬҸŲԶ
	OR = {
		NOT = { has_trait = trait_self_modified }
		is_same_species = root
	}
	NOT = { has_modifier = recently_migrated }	
	NOT = { has_modifier = recent_refugee }
	#鲻뿪
	NOT = { has_trait = trait_tree_spirit }
}

#Root = planet
#This = pop
pop_can_live_on_planet = {
	custom_tooltip = {
		fail_text = POP_HABITABILITY_TOO_LOW
		OR = {
			root = { NOT = { habitability = { who = prev value < 0.2 } } }
			AND = {
				has_citizenship_type = { type = citizenship_purge }
				NOT = { has_purge_type = { type = purge_displacement } }
			}		
		}	
	}
	custom_tooltip = {
		fail_text = POP_MAY_NOT_LIVE_ON_PLANET
		OR = {
			is_robot_pop = yes
			AND = {
				exists = owner
				owner = { NOT = { is_country_type = default } }
			}
			AND = {
				has_citizenship_type = { type = citizenship_purge }
				NOT = { has_purge_type = { type = purge_displacement } }
			}
			AND = {
				OR = {
					NOT = { has_citizenship_type = { type = citizenship_purge } }
					NOT = { has_purge_type = { type = purge_displacement } }
				}
				OR = {
					# everyone may live in sectors
					planet = { sector_controlled = yes }

					# citizens may always live in core worlds
					OR = {
						has_citizenship_type = { type = citizenship_full }
						has_citizenship_type = { type = citizenship_caste_system }
						has_citizenship_type = { type = citizenship_full_machine }
						has_citizenship_type = { type = citizenship_organic_trophy }
					}

					# core_worlds_all / hive minds let everyone live in core worlds
					AND = {
						exists = owner
						OR = {
							owner = { has_policy_flag = core_worlds_all }
							owner = { has_ethic = ethic_gestalt_consciousness }
						}		
						# stop non-citizens from moving to planets with recent land appropriation
						NAND = {
							root = { has_modifier = land_appropriation }
							planet = { NOT = { is_same_value = root } }
						}
					}				

					# core_worlds_citizens_and_slaves lets slaves live in core worlds
					AND = {
						exists = owner
						has_citizenship_type = { type = citizenship_slavery }
						owner = { has_policy_flag = core_worlds_citizens_and_slaves }
					}
				}
			}
		}			
	}
	#ǷȺ˿ڲ÷Ⱥ
	custom_tooltip = {
		fail_text = POP_NOT_ALLOW_MOVE_TO_TREE_FOLK_RESERV
		NAND = {
			NOT={ has_trait = trait_hive_mind }
			planet = { NOT = { is_same_value = root } }
			root = {  has_modifier = m_protect_tree_spirit  }
		}
	}
	#ϣ۹
	custom_tooltip = {
			fail_text = default
			NAND = {
					has_pop_flag = f_pop_of_crime
					root = { owner = { has_authority = auth_xilin_mind } }
			}
	}
}

#Root = country
#This = pop
can_colonize_with_pop = {
	has_colonization_control = no
	OR = {
		NOT = { has_trait = trait_self_modified }
		is_same_species = root
	}
	#鲻뿪
	NOT = { has_trait = trait_tree_spirit }
	if = {
		limit = { 
			OR = {
				has_culture_shock = yes
				is_sapient = no
			}
		}
		custom_tooltip = {
			always = no
		}
		else = {
			always = yes
		}
	}
}

#Root = country
#This = pop
should_abduct_pop = {
	NAND = {
		has_citizenship_type = { type = citizenship_purge country = root }
		NOR = { 
			has_purge_type = { type = purge_matrix country = root } 
			has_purge_type = { type = purge_processing country = root } 
			has_purge_type = { type = purge_labor_camps country = root } 
		}
	}	
	#鲻뿪
	NOT = { has_trait = trait_tree_spirit }
	#ʹͽᱻ
	NOR = {
			has_trait = trait_magic_machine
		  has_trait = trait_divinity
	}
}

#ϣ۹Ƽᱻ
# this = ship
# root = country that kills ship
can_spawn_debris = {	
	root = { is_country_type = default }
	exists = owner
	owner = { 
			NOR = { 
				has_ascension_perk = ap_enigmatic_engineering 
				has_technology = "tech_xilin_knowledge_architecture"
			} 
	}
}