#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"
			} 
	}
}