###	游戏规则_泛用兼容框架	#######################################################################################################################
#	引用[script trigger]必须有placeholder
#	[if结构]尽量不要放在|OR|里面作为并列条件


###	mod_tag	##########################################################

#_|FW|		框架
#_|LCTR|	高级定位器
#_|kasPF|	performance plus
#_|AAR|		AAR
#_|UGRC|	一些flag
#_|LSP|		孤勇者

#_[ev]		太虚流浪									<3547492547>
#_[wsg]		舰妈										<1747099270>	|has_wsg_mod|	+定做trgr
#_[swg]		星舰娘										<2116422940>
#_[GF]		少女前线群星故事集							<2068768158>
#_[kuat]	星球大战：夸特的黎明						<2461014769>	|install_kuat_mod|
#_[kuatAG]	古代帝国									<2389589691>
#_[kc]		舰队collectiMon								<2174082869>
#_[azl]		碧蓝航线主题DLC								<1617872589>
#_[adf]		AshArms Aquarius History					<2234187039>
#_|nirv|	Nirvana Empire Project						<828731704>
#_[pkman]	伊布帝国v1.22								<2398450274>
#_|arkn|	Arknights:Near Future						<2047260446>	|arknights_swimming|
#_[mmNEW]	Madoka Magica NEW							<2027001560>
#_[TAC]		深渊协议									<2847901464>
#_[micro]	微械革命									<2738038455>
#_[SC]		stellarisCraft								<2677473144>
#_[Alily]	AL突击莉莉									<2785989313>
#_[kzvoy]	久远之旅：兽耳娘种族与故事包				<2766998502>
#_[tgeo]	星海皇帝起源								<2710894758>
#_|wv|		Wandering Witch: Voyagers					<3655874540>
#_[sra]		星规阵列									<2293827000>
#_[tmod]	TimeMod										<2735054420>
#_[spth]	Symphony of Phantasm						<1834433554>	|has_touhou_mod|
#_|nyto|	NytoSpeciesEventsPack						<2070082709>
#_|dsc|		遥远繁星									<3580815783>
#_|rmsl|	Rozen Maiden suigintou Leader Pack			<2776070504>
#_[MECR]	失控女仆	rogue maid						<2621840890>
#_[seooc]	Some Events of Outside Cluster				<1562501671>
#_[sxx]		群星修仙传									<2865408972>

#_[cglbu]	love_between_us								<2748029219>	|love_between_us|
#_[cgelf]	ELF_species									<3143322386>

#_[ZOFE]	The Zenith of Fallen Empires				<2958421797>	每个大版本都会换id
#_[Giga]	Gigastructural Engineering & More			<1121692237>	|gigastructures_enabled|
#_[MEM]		More Events Mod								<727000451>
#_[ECI]		更多社会形态：无限							<2280945168>	|ideological_revolution|
#_|ECC|		Ethics and Civics Classic					<1100284147>
#_|ECB|		Ethics & Civics: Bug Branch					<2517213262>	|bug_branch_active|
#_[ACOT]												<1419304439>	|acot_activated|
#_[SBTG]	始源										<1481972266>
#_[SOTS]	Secrets of the Shroud						<2820330517>
#_[AOT]		Acquisition of Technology					<2178603631>
#_[EE]		永恒										<2854596966>
#_[bwm]		LEX Temp Fix								<1320989536>
#_[Atlan]	Atlan Atlanteans							<3732584807>

#_[AUP]		~~Ariphaos Unofficial Patch					<1995601384>	|ariphaos_unofficial_patch_installed|
#_[EMB]		Expanded Mods Base							<2994821528>	|expanded_pops_active|
#_[PD]		Planetary Diversity							<819148835>		|planetarydiversity|
#_[PDew]	Planetary Diversity - Exotic Worlds			<1732437279>	|planetarydiversity|
#_[RSnf]	Real Space - New Frontiers					<2475617894>	|has_new_frontiers_mod|
#_[PSR]		Planet States Revived						<2998085316>
#_[MREC]	Machines & Robot Expansion Continued		<3163759042>
#_[HFE]		Human Fallen Empires						<901039859>		|hfe_installed|
#_[hiveDLC]	Expanded Gestalts: Forgotten Queens			<1715190550>	|complex_hive|
#_|IFE|		Forgotten Empires							<3728581560>
#_[Eevt]	Expanded_Events								<1641807098>
#_[EFevt]	Endless Frontier: An Event Mod				<2529105358>

#_[thl]		thl									<230720>
#_[ARP]		苍蓝钢铁的奇葩								<220826>
#_[UR]		Underground Realms							<210420>
#_[MCA]		More Corporate Authorities for 3.x			<210501>
#_[aFE]		A Deadly Tempest							<211029>
#_[SMCO]	Slightly More Celestial Objects				<200807>
#_[PTep]	Plentiful Traditions - Extra Perks			<200810>
#_[LithS]	Lithoid Supremacy							<250715>
#_[Sexp]	Sensor Expansion							<211029>
#_[Ereb]	ethic_rebuild								<200805>
#_[WS]		Wild Space									<200807>		sys_trgr[is_ws_system]




###	目录	##########################################################

#	是宿敌/可宣称*
#	星球生存*
#	UGRC参选
#	UGRC产生领袖/UGRC军事领袖
#	释放附庸种族*
#	可攻击*/发动战争*
#	殖民星球*/环境改造/殖民物种*
#	自由思潮/UGRC幸福感*
#	UGRC可繁殖*物种组装*
#	轨道轰炸*/全图视野*
#	UGRC修理*/产生残骸
#	UGRC星系管制/跃迁舰队*	/UGRC跃迁星系*
#	UGRC传感器
#	可迁移人口
#	UGRC新地
#	UGRC犯罪
#	强制灭绝*
#	国家可建公司*/国家支持公司*/UGRC分部星球*	/UGRC罪企
#	奴隶市场
#	加入社区/加入帝国/可见社区/加入议会
#	人口可自动迁移/可自动迁移
#	宜居修饰*/高级修饰*/负面修饰/移除高级*/头像修饰*
#	领袖解雇/领袖交易
#	UGRC灵能国家/UGRC灵能物种
#	UGRC捕捉
#	境外挖坟
#	UGRC虚空虫轰炸


#_tag		UGRC注意/UGRC标签
#_trgr		其他堕落/巨企国家
#_var		|UGRC_var_cntr_RULE_jump_self|自我跃迁		此类国家必然可在|自己境内|跃迁，且必然可以向|自己境内|跃迁
#_flg		|UGRC_flg_sstm_RULE_jump_no|星系禁止		无法进行任何跃迁，优先级不超过FW特殊机制等
#			|UGRC_flg_sstm_RULE_jump_block|禁止迁入		任何跃迁无法进入




###	是宿敌	########################################################################
#	V/ECC/ECI/AUP/EMB
#Root = target country
#This = country
is_valid_rival = {
	custom_tooltip = {
		fail_text = INVALID_RIVAL_DESC
		root = {
			OR = {
				prev = {
					NOR = {
						is_country_type = default
					}
				}
				AND = {
					relative_power = { who = prev value >= inferior }
					OR = {
						relative_power = { who = prev value <= superior }
						prev = {
							OR = {
								has_policy_flag = diplo_stance_animosity
								#	ECI
								has_valid_civic = civic_unrestrained_feuds
								has_valid_civic = civic_eternal_victory
							}
						}
					}
				}
				is_country_type = mirrored_country # Mirrored Empire doesn't have relative power but we want to be rivals anyway
				#	ECC
				is_country_type = PrimPlayer_ethic_fanatic_nation
				is_country_type = PrimPlayer_ethic_fanatic_nation_nomadic
				#	EMB
				is_rival = prev
				prev = { is_rival = prev }
			}
		}
	}
}

###	可宣称	########################################################################	|core|
#	V/AUP/EMB/sxx/SBTG
##	AAR
# Root = claimer
# This = system
can_add_claim = {
	hidden_trigger = {
		if = {
			limit = {
				root = { NOT = { is_country_type = default } }
			}
			always = yes
		}
	}
	## +EMB
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_POLICY
		OR = {
			root = {
				OR = {
					has_policy_flag = unrestricted_wars
					# EMB
					AND = {
						has_global_flag = expanded_pops_active
						OR = {
							NOT = { has_valid_civic = civic_closed_collective }
							NOT = { has_valid_civic = civic_closed_network }
						}
					}
				}
			}
			AND = {
				exists = owner
				owner = { is_gestalt = yes }
			}
			AND = {
				exists = owner
				owner = {
					any_war = {
						any_attacker = { is_same_value = prevprev }
						any_defender = { is_same_value = root }
					}
				}
			}
			
			# EMB
			AND = {
				has_global_flag = expanded_pops_active	#MOD激活
				root = {
					has_policy_flag = liberation_wars
					is_democratic_authority = yes
					has_valid_ai_personality = yes
					has_ai_personality = democratic_crusaders
				}
				owner = { is_democratic_authority = no }
				owner = { is_exp_cooperative = no }
			}
		}
	}
	## +EMB/SBTG
	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
					#	EMB
					is_playable = yes
					#	SBTG
					is_country_type = sbtg_stellarborne_empire_active	
					is_country_type = sbtg_light_seeker
					#	sxx
					is_sxx_fallen_1 = yes
				}
			}
		}
	}
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_DEVOURING_SWARM
		NAND = {
			root = { has_valid_civic = civic_hive_devouring_swarm }
			root = { is_lithoid_empire = no }
		}
	}
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_DEVOURING_SWARM_LITHOID
		NAND = {
			root = { has_valid_civic = civic_hive_devouring_swarm }
			root = { is_lithoid_empire = yes }
		}
	}
	#	+EMB
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_ASSIMILATOR
		NOT = {
			root = {
				OR = {
					has_valid_civic = civic_machine_assimilator
					#	EMB
					is_machine_assimilator = yes
					has_government = gov_parasitic_overmind
				}
			}
		}
	}
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_NOMAD
		NOT = { root = { is_nomadic = yes } }
	}
	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	#_|is_machine_empire|
					is_individual_machine = yes
				}
			}
		}
	}
	# +EMB
	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
					has_valid_civic = civic_machine_assimilator
					has_valid_civic = civic_scorched_earth
					has_valid_civic = civic_hive_scorched_earth
					# EMB
					has_government = gov_parasitic_overmind
				}
			}
			root = {
				NOR = {
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_machine_terminator
					has_valid_civic = civic_machine_assimilator
					has_valid_civic = civic_scorched_earth
					has_valid_civic = civic_hive_scorched_earth
					# EMB
					has_government = gov_parasitic_overmind
				}
			}
		}
	}

	##	EMB
	custom_tooltip = {
		fail_text = CANNOT_ADD_CLAIM_RENOUNCED
		exists = owner
		owner = {
			NOT = { has_country_flag = renounced_claims@ROOT }
		}
	}
	##	AAR
	custom_tooltip = {
		fail_text = AAR_failtip_PREROGATIVE_no_claim
		NOT = { has_star_flag = AAR_flg_sstm_NO_claim@ROOT }	# |AAR禁止宣称|
	}
}

###	can_get_claim_from_lost_system
### should_surrender_planets_to
### species_has_citizenship
### should_abduct_pop_group

###	星球生存	########################################################################	|core|防止宜居度归零
#	V/PD/ECC/AUP/GF/MECR/hiveDLC
##	tmod/thl	
#_scopes	<Root>=Colony	<This>=species
species_can_live_on_planet = {
	hidden_trigger = {
		exists = root #somehow this appeared in the error log. No idea how!
		##_|v机械世界|	+PD/GF
		if = {
			limit = {
				root = {
					OR = {
						is_planet_class = pc_machine
						pd_is_planet_class_machine = yes	#	PD
					}
				}
			}
			OR = {
				has_trait = trait_machine_unit
				has_trait = trait_mechanical
				has_trait = trait_cybernetic
				has_unplugged_positive_trait = yes
				#	GF
				has_trait = GF_trait_doll
				#	ECC
				has_trait = trait_machine_cult_cybernetic
				#	MECR
				AND = {
					has_citizenship_type = { type = citizenship_organic_trophy country = root.owner }
					root = {
						owner? = { is_generalized_servitor_empire = yes }
						OR = {
							has_active_building = building_organic_sanctuary
							has_active_building = building_organic_sanctuary_rural
							has_active_building = building_organic_paradise
							has_active_building = building_organic_paradise_rural
							has_active_building = building_fe_sky_dome
							has_active_building = building_fe_dome
						}
					}
				}
			}
		}
		##_|v蜂巢世界|	+PD/hiveDLC/ECC
		else_if = {
			limit = {
				root = {
					OR = {
						is_planet_class = pc_hive
						pd_is_planet_class_hive = yes	#	PD
					}
				}
			}
			OR = {
				has_trait = trait_hive_mind
				#Necrophage Hive Mind can have Necrophytes
				root.owner? = {
					is_hive_empire = yes
					#	V	+hiveDLC
					if = { limit = { prev = { species_can_be_necrophaged = yes } }
						OR = {
							has_origin = origin_necrophage
							has_valid_civic = civic_hive_parasitic	# hiveDLC
						}
					}
					#	ECC
					else = {
						has_ethic = ethic_xenophile
					}
				}
			}
		}
		##	GF
		NAND = {
			is_robotic = no
			root = { is_planet_class = pc_GF_sf_machine }
		}
	}
	#	V克隆大军	+ECC
	if = {
		limit = {
			exists = root.owner
			root.owner = {
				OR = {
					has_origin = origin_clone_army
					#	ECC
					has_civic = PrimPlayer_civic_barbaric_despoilers_khan
					has_civic = civic_barbaric_despoilers_khan
				}
			}
			OR = {
				has_trait = trait_clone_soldier_infertile
				has_trait = trait_clone_soldier_infertile_full_potential
			}
		}
		custom_tooltip = {
			fail_text = CLONE_ARMY_FORCE_DECLINE
			root = {
				check_variable = { which = clone_pops_missing value >= 0 }
			}
		}
	}
	#	v荒野帝国
	custom_tooltip = {
		fail_text = WILDERNESS_NATURAL_WORLDS_DECLINE
		if = {
			limit = {
				has_trait = trait_wilderness
			}
			root = { is_habitable_for_wilderness = yes }
		}
	}
	custom_tooltip = {
		fail_text = WILDERNESS_DEAD_WORLD
		if = {
			limit = {
				has_trait = trait_wilderness
				exists = root.owner
			}
			root.owner = { is_wilderness_empire = yes }
		}
	}

	##	tmod
	TIME_RULE_trgr_spcs_CAN_live_on_planet = yes
	##	thl
	THL_trgr_spcs_RULE_can_live_on_planet = yes
}

###	species_can_live_on_ship
###	species_has_uncapped_habitability_on_planet
###	species_has_uncapped_habitability_on_ship
###	pop_group_can_join_factions

###_|UGRC参选|	########################################################################	UGRC定制	提升不大|384|17%|
#	V/kuatP/AUP
#Note: this is also used in pop faction support calculations
#_scopes	<Root>=country	<This>=pop_group
can_vote_in_democratic_election = {
	has_pop_group_flag = UGRC_flg_pop_RULE_can_vote	# |UGRC标签|
}

### should_pay_for_leader_upkeep

###_|UGRC产生领袖|	########################################################################	UGRC注意|sxx环境若开具默认全人口都能产生领袖(DISABLE_flag条件)会CTD
#	V/kuatP/AUP/sxx/Alily
##	FW/GF/Ereb/hiveDLC/PTep/Eevt/EMB/ECI/MECR/wv
#Checks whether any leaders (scientists etc) can be formed from this pop
#Root = country
#This = pop_group
can_generate_leader_from_pop_group = {
	has_pop_group_flag = UGRC_flg_pop_RULE_can_generate_leader	# |UGRC标签|
}

###	can_generate_leader_from_species
###	can_create_espionage_asset_from_species

###_|UGRC军事领袖|	########################################################################
#	V/kuatP/AUP/sxx
#Root = country
#This = pop_group
can_generate_military_leader_from_pop_group = {
	has_pop_group_flag = UGRC_flg_pop_RULE_can_generate_military_leader	# |UGRC标签|
}

###	can_generate_army_from_colony
###	can_release_vassal

###	释放附庸种族	########################################################################	|core|
#	V/AUP/EMB/MECR/cglbu/MREC
##	PTep
#Root = species
#This = country
can_release_vassal_from_species = {
	root = {
		#	MREC
		if = { limit = { oxr_mdlc_can_release_vassal_from_species = yes }
			always = yes
		}
		else = {
			is_sapient = yes
			NOR = {
				##	|v智械|
				AND = {
					has_trait = trait_machine_unit
					prev.this = { is_individual_machine = no }
					#	MECR
					Maid_trigger_4_can_release_vassal_from_species = no
				}
				AND = {
					has_trait = trait_hive_mind
					NOR = {
						prev.this = { has_origin = origin_progenitor_hive }
						#	MECR
						Maid_trigger_7_can_release_vassal_from_species_release_hive = yes
					}
				}
				AND = {
					NOT = { has_trait = trait_hive_mind }
					prev.this = { has_authority = auth_hive_mind }
				}
				AND = {
					has_trait = trait_mechanical
					prev.this = {
						NOR = {
							is_mechanical_empire = yes
							has_technology = tech_synthetic_leaders
						}
					}
				}
				can_think = no
				has_trait = trait_clone_soldier_infertile
				has_trait = trait_clone_soldier_infertile_full_potential

				#	PTep
				has_trait = trait_plentiful_traditions_pt_cocoon
				#	cglbu
				is_cg_vassal_species = yes
			}
		}
	}
}

###	can_generate_army_from_species
###	can_modify_species
###	can_uplift_species
###	subject_can_expand

###	可攻击	########################################################################	|core|
#	V/seooc/AUP/ACOT/PSR
#Root = country, attacker
#This = country, target
#This rule is a condition for taking hostile actions towards neutral targets. Such as landing troops OR attacking their fleets
can_take_hostile_actions = {
	if = {
		limit = {
			ROOT = {
				NOT = { has_policy_flag = first_contact_attack_allowed }
			}
			NOR = {
				is_hostile = ROOT
				has_communications = ROOT
			}
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_FIRST_CONTACT_PROTOCOL"
			always = no
		}
	}
	else_if = {
		limit = {
			has_country_flag = fotd_seperatist_country@ROOT
			ROOT = {
				has_origin = origin_fear_of_the_dark
			}
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_FOTD"
			always = no
		}
	}
	else_if = {
		limit = {
			AND = {
				NOT = { has_country_flag = hostile_to_nomads }
				ROOT = {
					is_country_type = nomad
				}
			}
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_FIRST_CONTACT_PROTOCOL"
			always = no
		}
	}
	else_if = {
		#nomads have no borders, so require the target pre-FTL world to be surveyed in place of the in-borders requirement
		limit = {
			ROOT = {
				is_nomadic = yes
			}
			is_primitive = yes
			capital_scope = {
				NOT = {
					is_surveyed = {
						who = ROOT
						status = yes
					}
				}
			}
		}
		custom_tooltip = {
			text = "arkship_target_not_surveyed_fail_tt"
			always = no
		}
	}
	else_if = {
		#attacking primitives with non-interference
		limit = {
			ROOT = {
				is_country_type = default
				NOT = {
					has_policy_flag = interference_aggressive
				}
			}
			is_primitive = yes
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_NATIVE_INTERFERENCE"
			always = no
		}
	}
	else_if = {
		limit = {
			ROOT = { any_agreement = { agreement_preset = preset_satrapy } }
			is_country_type = faction
			root = {
				any_owned_planet = {
					exists = controller
					controller = {
						is_same_value = prevprevprev
					}
				}
			}
		}
		custom_tooltip = {
			text = ""
			always = yes
		}
	}
	else_if = {
		limit = {
			exists = overlord
			ROOT = { any_agreement = { agreement_preset = preset_satrapy } }
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_SATRAPY"
			always = no
		}
	}
	else_if = {
		limit = {
			exists = overlord
			overlord = { is_same_value = root }
			ROOT = { any_agreement = { agreement_preset = preset_satrapy } }
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_OVERLORD"
			always = no
		}
	}
	
	##	ACOT	##########################################################################################
	else_if = {
		limit = {
			this = {
				is_country_type = sbtg_stellarborne_empire_passive
			}
		}
		custom_tooltip = {
			always = no
		}
	}
	else_if = {
		limit = {
			OR = {
				is_country_type = void_lifeforms_1
				is_country_type = void_lifeforms_2
			}
		}
		custom_tooltip = {
			always = yes
		}
	}
	else_if = {
		limit = {
			root = {
				OR = {
					is_country_type = void_lifeforms_1
					is_country_type = void_lifeforms_2
				}
			}
		}
		custom_tooltip = {
			always = yes
		}
	}
	#	PSR	##########################################################################################
	else_if = {
		limit = {
			is_country_type = planet_state
			ROOT = { is_country_type = default }
			capital_scope = {
				root = {
					NOT = {
						any_planet_within_border = {
							is_same_value = prevprev
						}
					}
				}
			}
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_PLANET_STATE"
			always = no
		}
	}
	else_if = {
		limit = {
			is_country_type = planet_state
			ROOT = {
				OR = {
					is_country_type = dormant_marauders
					is_country_type = ruined_marauders
					is_country_type = awakened_marauders
				}
			}
		}
		always = no
	}
	#	seooc	##########################################################################################
	else_if = {
		limit = {
			OR = {
				AND = {
					root = { has_country_flag = nep_gaia_assist_war }
					has_country_flag = nep_highlander_country
				}
				AND = {
					root = { has_country_flag = nep_highlander_assist_war }
					has_country_flag = nep_gaia_country
				}
			}
		}
		always = yes
	}
	else_if = {
		#SEoOC_phantom
		limit = {
			ROOT = {
				NOT = { has_technology = tech_nep_phantom_phase_shift }
			}
			is_country_type = nep_phantom_passive
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_NEP_PHANTOM"
			always = no
		}
	}
	else_if = {
		#SEoOC_side_story
		limit = {
			root = { is_ai = no }
			OR = {
				AND = {
					root = { has_country_flag = nep_gaia_assist_war }
					has_country_flag = nep_gaia_country
				}
				AND = {
					has_country_flag = nep_gaia_assist_war
					root = { has_country_flag = nep_gaia_country }
				}
				AND = {
					root = { has_country_flag = nep_highlander_assist_war }
					has_country_flag = nep_highlander_country
				}
				AND = {
					has_country_flag = nep_highlander_assist_war
					root = { has_country_flag = nep_highlander_country }
				}
				AND = {
					has_country_flag = nep_gpc_country
					root = { has_country_flag = nep_caravaneer_fleet_country }
				}
				AND = {
					root = { has_country_flag = nep_gpc_country }
					has_country_flag = nep_caravaneer_fleet_country
				}
			}
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_NEP_GAIA"
			always = no
		}
	}
	else_if = {
		#SEoOC_side_2
		limit = {
			is_country_type = nep_arena_hologram
			is_country_type = nep_bounty_hologram
		}
		custom_tooltip = {
			text = "CAN_TAKE_HOSTILE_ACTION_NEP_HOLOGRAM"
			always = no
		}
	}
	#	其他
	else = {
		always = yes
	}
}


###	发动战争	########################################################################	|core|
#	V/AUP/EMB/MECR
##	S_tnatc/SSNI
#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 = {
			has_overlord = ROOT
		}
	}
	##	|战争政策|	+EMB/MECR
	if = {
		limit = {
			exists = root
			ROOT = {
				has_policy_flag = no_wars
				NOR = {
					has_casus_belli = {
						target = prev
						type = cb_stop_dyson_gun
					}
					has_casus_belli = {
						target = prev
						type = cb_expel_nomads
					}
				}
				OR = {
					is_subject = no
					overlord = {
						is_same_value = root
					}
				}
			}
		}
		custom_tooltip = {
			text = "CAN_DECLARE_WAR_POLICY"
			#	EMB
			if = {
				limit = { has_global_flag = better_diplo_installed }
				OR = {
					is_country_type = synth_queen
					has_valid_civic = civic_fanatic_purifiers
					has_valid_civic = civic_hive_devouring_swarm
					has_valid_civic = civic_machine_assimilator
					has_government = gov_parasitic_overmind
					has_valid_civic = civic_machine_terminator
					has_menace_perk = menp_behemoth_ever_hungry
				}
			}
			else = {
				#always = no
				Maid_trigger_3_can_declare_war = yes	# MECR
			}
		}
	}
	if = {
		limit = {
			exists = root
			ROOT = {
				is_ai = yes
			}
		}
		ROOT = {
			is_at_war = no
		}
	}
	
	##	S_tnatc
	if = {
		limit = { has_global_flag = nyblax_no_wars }
		custom_tooltip = {
			text = "NYBLAX_NO_WARS"
			always = no
		}
	}
	##	SSNI
	if = {
		limit = {
			use_for_game_mode_survival = yes
		}
		custom_tooltip = {
			fail_text = "WAR_BLOCKED_FOR_SURVIVAL"
			always = no
		}
	}
}

###	殖民星球	########################################################################	|core|
#	V/AUP/ev/ACOT
#Root = country
#This = planet
can_colonize_planet = {
	hidden_trigger = {
		exists = root
	}
	can_colonize_planet_trigger = {
		SCOPE = root
	}
	custom_tooltip = {
		fail_text = "BLANK_STRING"
		if = {
			limit = {
				exists = root
				root = {
					is_country_type = swarm
				}
			}
			is_artificial = no
		}
	}
	
	##	LSP
	custom_tooltip = {
		fail_text = LSP_failtip_country_solitary
		hidden_trigger = {
			root? = { NOT = { is_variable_set = LSP_var_cntr_solitary } }
		}
	}
	#	ev
	custom_tooltip = {
		fail_text = "EV_FORBIDDEN_COLONIZE"
		ROOT = {
			OR = {
				#	非ev普通
				is_default_ev_country_type = no
				#	ev普通
				has_origin = origin_ev_both_choosen
				has_origin = origin_ev_adf
				has_civic = civic_ev_and_other_mods
				has_country_flag = has_ev_to_planets
			}
		}
	}
	#	ACOT
	custom_tooltip = {
		fail_text = "ACOT_COLONIZATION_IMPOSSIBLE_NEED_FRACTURED_TECH"
		if = {
			limit = {
				exists = root
				is_planet_class = pc_dark_fractured
			}
			root = {
				has_technology = tech_acot_colonize_fractured
			}
		}
	}
}

###	can_colonize_outside_borders
###	has_borders
###	can_nomad_settle


###	环境改造	########################################################################
#	V/ECB/AUP/RSnf/IFE
##	thl
#Root = country
#This = planet
can_terraform_planet = {
	custom_tooltip = {
		fail_text = terraform_fail_consecrated
		NOT = {
			has_modifier = consecrated_world
		}
	}
	custom_tooltip = {
		fail_text = terraform_fail_no_presapient_protection_or_no_presapients
		NAND = {
			AND = {
				exists = root
				root = {
					has_policy_flag = pre_sapients_protect
				}
			}
			any_owned_species = {
				is_sapient = no
				NOT = { has_trait = trait_nascent_stage }
			}
		}
	}
	custom_tooltip = {
		fail_text = "requires_actor_not_devouring_swarm_lithoid"
		exists = root
		root = { is_lithoid_devouring_swarm = no }
	}
	custom_tooltip = {
		fail_text = "legendary_leader_planet_no_terraform"
		exists = root
		if = {
			limit = {
				root = { is_wilderness_empire = no }
			}
			this = {
				NOT = { has_planet_flag = legendary_leader_planet }
			}
		}
	}

	custom_tooltip = {
		fail_text = requires_not_relentless_industrialists_situation
		NOT = {
			any_targeting_situation = {
				is_situation_type = relentless_industrialists_situation
			}
		}
	}

	custom_tooltip = {
		fail_text = terraform_fail_is_metal_planet
		NOT = {
			has_modifier = metal_planet
		}
	}

	custom_tooltip = {
		fail_text = COLONIZATION_IMPOSSIBLE_DEFENDED_PLANET
		NOT = { has_planet_flag = planet_defended_forbid_colonization }
	}

	custom_tooltip = {
		fail_text = "COLONIZATION_IMPOSSIBLE_SMEEGIBB_PLANET"
		NOT = { has_planet_flag = cannot_colonize_smeegibb_shelter }
	}
	custom_tooltip = {
		fail_text = "COLONIZATION_IMPOSSIBLE_WILDERNESS_TECH"
		OR = {
			NAND = {
				owner? = {
					is_wilderness_empire = yes
					NOT = { has_technology = tech_terrestrial_sculpting }
				}
				OR = {
					AND = {
						root = { has_country_flag = started_wet }
						is_wet = no
					}
					AND = {
						root = { has_country_flag = started_dry }
						is_dry = no
					}
					AND = {
						root = { has_country_flag = started_cold }
						is_cold = no
					}
				}
			}
			is_planet_class = pc_gaia
		}
	}

	##	UGRC
	custom_tooltip = {
		fail_text = UGRC_failtip_RULE_can_terraform_planet_DISABLE
		NOT = { is_variable_set = UGRC_var_plnt_RULE_can_terraform_planet_DISABLE }
	}
	##	RSnf
	custom_tooltip = {
		fail_text = NO_TERRAFORM_HOLLOW_WORLD
		NOT = { is_planet_class = pc_hollow }
	}
	#	thl
	custom_tooltip = {
		fail_text = "sakura_planet_no_terraform"
		NOT = { has_carrier_flag = sakura_planet }
	}
	#	IFE
	# Forgotten Empires
	custom_tooltip = {
		fail_text = scfe_cant_terraform_special_planet
		NAND = {
			has_carrier_flag = cant_terraform_planet
			root = { is_wilderness_empire = no }
		}
	}
}


###	殖民物种	########################################################################	|core|
#	V/Giga/ECC/AUP/ev/Alily
##	PTep/LSP/LithS
#Root = country
#This = species
can_colonize_with_species = {
	##	MOD	####################################
	#	ev
	if = { limit = { root = { is_default_ev_country_type = yes } }
		root = {
			OR = {
				has_origin = origin_ev_both_choosen
				has_country_flag = has_ev_to_planets
				has_civic = civic_ev_planet_and_fleet
				has_country_flag = has_ev_to_planets
			}
		}
	}
	#	Giga
	giga_can_colonize_with_species = yes
	NOR = {
		#	PTep
		has_trait = trait_plentiful_traditions_pt_cocoon
		#	ECC
		has_trait = trait_slave_gene
		has_trait = trait_symbiotic
		has_trait = trait_machine_cult_cybernetic
		#	Alily
		is_species_class = PUFFER
	}
	
	##_|VANILLA|	####################################	+LSP/LithS
	has_colonization_control = {
		type = colonization_control_no
		country = root
	}
	OR = {
		NOT = { has_trait = trait_self_modified }
		is_same_species = root
	}
	NOT = { has_trait = trait_pathogenic_genes }
	if = {
		limit = {
			OR = {
				is_sapient = no
				has_trait = trait_zombie
				has_trait = LSP_trait_original	#LSP
				has_trait = trait_pearl_born_drone	#LithS
			}
		}
		custom_tooltip = {
			always = no
		}
	}
	else_if = {
		limit = { has_trait = trait_hive_mind }
		root = { is_hive_empire = yes }
	}
	else = {
		always = yes
	}
}


###	自由思潮	########################################################################	本身无需优化提升不大|384|17%|	但PF关闭可优化人口
#	V/kuatP/AUP/tmod/MECR
pop_group_has_random_ethics = {
	#	kasPF
	if = { limit = { has_global_flag = PF_flg_glbl_POP_ethic_DISABLE }
		always = no
	}
	#	vanilla
	else = {
		NOR = {
			has_citizenship_type = {
				country = from
				type = citizenship_organic_trophy
			}
			#	tmod
			has_citizenship_type = { country = from		type = citizenship_adeptus_mechanicus }	#	同步追踪|tmod	scripted_triggers	|TIME_RULE_trgr_Has_random_ethics|
		}
	}
}


###_|UGRC幸福感|	########################################################################	|core|逻辑复杂度高|
#	V/ECB/AUP/wsg/wv/tmod/MECR/cglbu
# Root = Species	可能是当前物种的主物种
# From = Country
# This = Species	当前物种的真实scope
species_has_happiness = {
	has_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@from		# 改为<@root.from>不会报错,但是子物种无法检测到flag
}


###_|UGRC可繁殖|	########################################################################	|core|-45%|
#	V/AUP/EMB/wv/mmNEW/cglbu/hiveDLC
# Checks if a pop can procreate
# This = Species
# Root = Colony
can_species_procreate = {
	species_can_grow_on_colony = {
		COLONY = root
	}
}


###	物种组装	########################################################################	|core|
#	V/AUP/GF/azl/kzvoy/arkn/kc/spth/EE/MREC/Alily
# This = Species
# Root = Colony
can_species_be_assembled = {
	#_|V基础|	+azl
	OR ={
		is_robotic = yes
		is_KANSEN_species = yes	# azl
		is_archetype = KANMUSU	# kc
		is_archetype = ASCENDED	# EE
		is_archetype = LILY		# Alily
		#	arkn
		AND = { has_global_flag = arknights_swimming
			AND = {
				has_trait = trait_ARK_ocean_seaborn
				root.owner? = { has_country_flag = arknights_ocean_country }
			}
		}
	}
	is_sapient = yes
	NOT = {
		has_trait = trait_exd
	}
	NAND = {
		has_trait = trait_mechanical
		root.owner = { is_individual_machine = yes }
	}
	NAND = {
		has_virtual_species_trait = yes
		root.owner = {
			is_fallen_empire = no
			has_active_tradition = tr_virtuality_finish
		}
	}
	NOT = {
		is_being_integrated_by = root.owner
	}
	has_population_control = {
		type = no
		country = root.owner
	}

	##	GF
	if = { limit = { has_trait = GF_trait_doll }
		root.owner? = { GF_can_build_doll_species = yes }
	}
	##	tmod
	TIME_RULE_trgr_CAN_spcs_be_assembled = yes
	better_ascension_traits_RULE_trgr_CAN_spcs_be_assembled = yes
	#	kzvoy
	KZ_VOY_can_species_be_assembled = yes
	#	MREC
	oxr_mdlc_can_species_be_assembled = yes
}


###	species_uses_bonus_growth
###	founder_species_uses_logistic_growth_mult
###	founder_species_uses_assembly
###	founder_species_uses_bonus_growth_mult


###	轨道轰炸	########################################################################	|core|
#	V/Giga/kuat/kuatAG/AUP/ev/wsg/adf/kzvoy/spth/cglbu/cgelf/ACOT/HFE/RSnf/sra/bwm
#This rule is a condition for bombarding planets
#Root = fleet, potential attacker
#From = planet, potential target
can_orbital_bombard = {
	exists = from.owner
	###_|绝对禁止|	+RSnf/kuat/cgelf	############################################################################
	NOR = {
		any_controlled_ship = {
			is_ship_size = colossus
		}
		from = {
			OR = {
				is_planet_class = pc_hollow		# RSnf
				is_ELF_can_not_be_orbital_bombard_planet = yes	# cgelf
				#	kuat
				has_carrier_flag = enable_kuat_shield
				owner = { is_country_type = kuat_fire_base_hositle }
				#	spth
				has_carrier_flag = enable_spth_plantary_shield
				has_carrier_flag = spth_lunar_repair_barrier
			}
		}
		ag_gamerule_stop_orbital_bombardment_trigger = yes	# kuatAG
		#	ACOT
		AND = {
			owner = { is_progenitor_empires = no }
			from = {
				OR = {
					is_planet_class = pc_acot_pmc_vault
					is_planet_class = pc_acot_enigmopolis
				}
			}
		}
	}
	
	###_|基本条件|	############################################################################
	OR = {
		##	AUP/HFE	####################	只要敌对都能炸
		ROOT.CONTROLLER = { is_hostile = FROM.CONTROLLER }

		##	vanilla	####################
		AND = {
			ROOT.CONTROLLER = {
				NOT = { has_communications = FROM.OWNER }
			}
			FROM.OWNER = {
				NOT = { is_country_type = primitive }
			}
		}
		AND = {
			ROOT.CONTROLLER = {
				NOR = {
					has_policy_flag = interference_not_allowed
					has_policy_flag = interference_subtle
				}
			}
			FROM.OWNER = { is_country_type = primitive }
		}
		ROOT.CONTROLLER = { is_at_war_with = FROM.CONTROLLER }
		#	V|可随意轰炸	+bwm
		FROM = {
			OR = {
				is_planet_class = pc_infested
				has_carrier_flag = bwm_ancestor_world			# bwm
			}
		}
		##_|可被轰炸|	+kuatAG/bwm/Giga/Ehof/kuat/cglbu
		FROM.CONTROLLER = {
			OR = {
				#	绝对通用
				is_variable_set = UGRC_var_cntr_RULE_can_be_bombed
				#	VANILLA
				is_country_type = swarm
				is_country_type = ai_empire
				is_country_type = cybrex_empire
				is_country_type = abandoned_hatchery
				AND = {
					OR = {
						is_country_type = awakened_marauders
						is_country_type = mechanocalibrator
					}
					ROOT.CONTROLLER = { is_hostile = prev }
				}

				is_country_type = mem_ancestor_guardian			# bwm
				ag_can_be_orbital_bombardment_country = yes		# kuatAG	安装=|has_ancient_empire_mod|
				kuat_can_be_orbital_bombarment_country = yes	# kuat		安装=|install_kuat_mod|
				#	cglbu
				is_country_type = ten_crisis_empire
				is_country_type = tearalaments
				is_country_type = destruction_light
				#	Giga
				is_country_type = compound_empire
				katzen_country_type = yes
				is_country_type = giga_eawaf_sirens
				#	ACOT
				is_country_type = sbtg_stellarborne_empire
				is_country_type = void_lifeforms_1
				is_country_type = void_lifeforms_2
				is_country_type = acot_exterminatus_victim
				is_country_type = acot_phanon_base
				is_country_type = acot_phanon_retaliator
			}
		}
		##_|允许轰炸|	+ev/wsg/swg/kuat/kuatAG/adf	/bwm/ACOT/MEM/sra/SSNI/kzvoy/cglbu/cgelf/thl
		ROOT.CONTROLLER = {
			OR = {
				#	UGRC通用
				is_variable_set = UGRC_var_cntr_RULE_can_bomb
				#	VANILLA
				is_country_type = extradimensional
				is_country_type = extradimensional_2
				is_country_type = extradimensional_3
				is_country_type = swarm
				is_country_type = ai_empire
				is_country_type = cybrex_empire					# <aup去除了此项>
				is_country_type = synth_queen
				is_country_type = awakened_synth_queen
				is_country_type = synth_queen_convoys
				is_country_type = synth_queen_outposts
				is_country_type = dormant_marauders
				is_country_type = marauder_raiders
				is_country_type = ruined_marauders
				is_country_type = debt_collectors
				is_country_type = gray_goo
				is_country_type = vol
				is_country_type = behemoth_hatchling
				is_country_type = abandoned_hatchery
				AND = {
					is_country_type = frenzied_voidworms
					has_country_flag = can_bombard
					FROM.CONTROLLER = { has_country_flag = tormented_by_frenzied_voidworms }
				}
				AND = {
					OR = {
						is_country_type = awakened_marauders
						is_country_type = formless
					}
					FROM.CONTROLLER = { is_hostile = prev }
				}
				AND = {
					is_voidworms_hostile_country_type = yes
					ROOT = {
						is_ship_size = voidworms_titan
					}
				}
				has_country_flag = revengeful_patron
				##	|MOD|
				is_default_ev_country_type = yes				# ev
				is_country_type = afk_crisis_country			# swg
				is_country_type = LsE_fallen_empire				# adf
				is_country_type = mem_ancestor_guardian			# bwm
				#	wsg
				is_country_type = wg_crisis_country
				is_khan_country_type = yes
				#	kuatAG
				ag_can_do_orbital_bombardment_country = yes
				#	kuat
				kuat_can_do_bombarment_country = yes
				#	Giga
				is_country_type = compound_empire
				katzen_country_type = yes
				is_country_type = giga_hypersiphon_major_incursion
				is_country_type = giga_eawaf_sirens
				#	ACOT
				is_country_type = void_lifeforms_1
				is_country_type = void_lifeforms_2
				is_country_type = acot_exterminatus_victim
				is_country_type = acot_crazed_stellarite
				is_country_type = acot_phanon_base
				is_country_type = acot_phanon_retaliator
				#	MEM
				is_country_type = mem_surveyor_country_red		# 瓦祖兰
				is_country_type = mem_vazurans
				#	sra
				SRA_can_do_orbital_bombardment_country = yes
				#	SSNI
				is_country_type = sentinel_hostile_expansion
				#	kzvoy
				KZ_VOY_can_unconditional_bombarment_country = yes
				#	cglbu
				is_country_type = ten_crisis_empire
				is_country_type = tearalaments
				is_country_type = destruction_light
				#	cgelf
				is_ELF_can_orbital_bombard_country_type = yes
				#	thl
				is_country_type = koishi_berserk_fleet
				#	spth
				has_country_flag = touhou_mod_country
			}
		}
		##	V|星球所有者轰炸被其他阵营占据的星球
		AND = {
			from.controller = {
				is_country_type = faction
				NOT = { is_same_value = ROOT.CONTROLLER }
			}
			from.owner = {
				is_same_value = ROOT.CONTROLLER
			}
		}
	}

	##	tmod	####################
	TIME_RULE_trgr_CAN_orbital_bombard = yes
	##	kuatAG
	ag_gamerule_allow_orbital_bombardment_trigger = yes
	##	ACOT
	if = { limit = { has_global_flag = acot_activated }	# mod激活
		NAND = {
			root.owner = { is_progenitor_empires = no }
			from = {
				OR = {
					is_planet_class = pc_acot_pmc_vault
					is_planet_class = pc_acot_enigmopolis
				}
			}
		}	
	}
}


###	can_planet_support_orbital_station


###_[全图视野]	########################################################################	|core|
#	V/kuatAG/AUP/ev/kzvoy/spth/SBTG/AOT
# Check if full sensor range in entire galaxy
# root: country
has_full_sensor_range = {
	##	绝对禁止
	NOT = { is_variable_set = FW_var_cntr_FULL_sensor_off }	#_|FW|开关
	##	激活
	OR = {
		#	vanilla
		has_megastructure = spy_orb_4
		has_megastructure = spy_orb_restored
		#	UGRC
		check_modifier_value = { modifier = UGRC_smod_cntr_RULE_full_sensor		value > 0 }
		has_country_flag = FW_flg_cntr_CHT_orrery_ON				#_|FW|璀璨星图
		has_country_flag = FW_flg_cntr_CHT_beacon_ON				#_|FW|永恒星炬
		has_country_flag = LCTR_flg_cntr_RELIC_activated_full		#_|LCTR|暗能量传感器
		
		#	mod
		has_megastructure = sbtg_omega_spy_orb_center		# SBTG
		has_megastructure = acot_precursor_sentry_orb_stage_three	# AOT
		KZ_VOY_has_full_sensor_range = yes		# kzvoy
		ag_has_full_sensor_range = yes			# kuatAG
		#	nirv
	#	AND = { ag_is_ai = yes		has_country_flag = nirvana }
	#	has_country_flag = ai_dragon
	#	has_country_flag = ai_council
	}
	##	特殊禁止
	OR = {
		#	禁止skip
		sg_has_full_sensor_range_trigger = yes
		#	禁止
		NOR = {
			check_modifier_value = { modifier = ag_no_full_sensor_range		value > 0 }
			has_country_flag = ag_no_full_sensor_range	# kuatAG
		}
	}
}


###	show_notification_for_ground_combat
###	has_planet_specific_war_attack_priority
###	calc_system_specific_war_attack_priority
###	should_apply_neighbor_rival_modifier
###	are_rebels_hostile
###	should_colony_be_destroyed_on_pc_change
###	is_extradimensional_portal
###	is_extradimensional_anchor
###	will_anger_fallen_empire
###	can_have_robot_pops
###	fleet_uses_templates


###_|UGRC修理|	########################################################################	|core|
#	V/Giga/ECC/AUP/ACOT/AOT/Alily
# this = starbase, megastructure OR planet
can_orbitable_repair_ships = {
	#	|UGRC维修轨道|
	is_variable_set = UGRC_var_all_RULE_can_orbitable_repair_ships
}



###_[产生残骸]	########################################################################
#	V/AUP/Atlan/hiveDLC
##	FW/ZCM
#_glbl_flg	[FW_flg_glbl_TECH_overwhelm]	科技壁垒
# this = ship
# root = country that kills ship
can_spawn_debris = {
	root = {
		is_country_type = default
		NOT = { has_policy_flag = debris_destruction }
	}
	exists = owner
	owner = {
		NAND = {#_科技限制
			has_global_flag = FW_flg_glbl_TECH_overwhelm	#_|FW|科技壁垒
			relative_power = { who = root category = technology value >= superior }	#_[FW]神一般的科技=superior
		}
		#NAND = {# ZCM	无法获取堕落科技
		#	has_global_flag = z_cm_fallen_technology
		#	OR = {
		#		is_country_type = fallen_empire
		#		is_country_type = awakened_fallen_empire
		#	}
		#}
		## +hiveDLC/Atlan
		NOR = {
			has_ascension_perk = ap_enigmatic_engineering
			
			has_civic = civic_hive_strong_connection		# hiveDLC
			has_civic = civic_tw_atlantis					# Atlan
		}
	}
}


###_|UGRC星系管制|	########################################################################	|检测cntr|-55%,|单flag@root|-88%
#	V/Giga/kuatAG/AUP/EMB/SBTG/IFE
#_list	普通/掠夺者/嘉年华/堕落/觉醒/SBTG永恒/虚空虫/天灾/古代守望/其他
#_note	sstm条件优化为flg标签, 有必要的话一些国家类型也收束到flg标签
# this = system
# root = country
# Determines if AI-controlled empires should restrict (and thus avoid) a system
# Used by regular empires, fallen empires & crises
ai_should_restrict_system = {
	##	按阵营
	ROOT = {
		##	|普通|
		if = { limit = { is_variable_set = UGRC_var_cntr_RULE_restrict_DEFAULT }
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_CRISIS
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
		##	|掠夺者|
		else_if = { limit = { is_variable_set = UGRC_var_cntr_RULE_restrict_RAIDER }
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_CRISIS
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
					owner? = {
						OR = {
							is_variable_set = UGRC_var_cntr_RULE_restrict_FALLEN
							is_variable_set = UGRC_var_cntr_RULE_restrict_SBTG
						}
					}
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
		##	|嘉年华|
		else_if = { limit = { is_country_type = caravaneer_fleet }
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_CRISIS
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
					owner? = {
						OR = {
							is_variable_set = UGRC_var_cntr_RULE_restrict_SBTG
							is_variable_set = UGRC_var_cntr_RULE_restrict_CRISIS
							is_country_type = dormant_marauders
							is_country_type = awakened_marauders
						}
					}
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
		##	|堕落|
		else_if = { limit = { is_variable_set = UGRC_var_cntr_RULE_restrict_FALLEN }
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_CRISIS
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
					owner? = { is_country_type = awakened_marauders }
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
		##	|觉醒|
		else_if = { limit = { is_variable_set = UGRC_var_cntr_RULE_restrict_AFE }
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
		##	|SBTG永恒|
		else_if = { limit = { is_variable_set = UGRC_var_cntr_RULE_restrict_SBTG }
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
					owner? = { is_country_type = awakened_marauders }
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
		##	|虚空虫|
		else_if = { limit = { is_country_type = voidworms }
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
					owner? = {
						OR = {
							is_country_type = dormant_marauders
							is_country_type = awakened_marauders
						}
					}
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
		##	|天灾|
		else_if = { limit = { is_variable_set = UGRC_var_cntr_RULE_restrict_CRISIS }
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
		##	|古代守望|
		else_if = { limit = { is_country_type = ag_ancient_psi_guardian }
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
					has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
					has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
		##	|其他|	不可进入禁地
		else = {
			prev = {
				OR = {
					has_star_flag = UGRC_flg_sstm_RESTRICT_ai	#默认避开
					has_star_flag = FW_flg_sstm_CHEAT_restrict_ugrc	#FW
				}
			}
		}
	}
}


###	ai_should_not_restrict_system
###	can_subjugate_empires
###	can_leader_get_council_trait
###	can_leader_get_normal_trait
###	can_leader_get_subclass_trait
###	can_leader_get_destiny_trait
###	has_extra_council_position


###	跃迁舰队	########################################################################	|core|
#	V/kuatAG/seooc/AUP/dsc/spth/cgelf/sra/Alily
# THIS = Fleet
can_jump_drive = {
	# Cooldown handled by code
	is_system_locked = no
	exists = solar_system
	
	##	FW
	if = {
		limit = {
			OR = {
				has_fleet_flag = FW_flg_flt_JUMP	# FW特殊跃迁flt
				controller = {
					OR = {
						has_country_flag = FW_flg_cntr_CHT_orrery_ON		# 璀璨星图
						has_country_flag = FW_flg_cntr_CHT_beacon_ON		# 永恒星炬
					}
				}
			}
		}
		always = yes
	}
	#	|自我跃迁|
	else_if = {
		limit = {
			exists = space_owner
			space_owner = { is_variable_set = UGRC_var_cntr_RULE_jump_self }
		}
		custom_tooltip = { fail_text = "UGRC_fail_RULE_can_jump_drive_SELF"
			controller = { is_same_value = prev.space_owner }
		}
	}
	##	|UGRC禁止|
	else_if = { limit = { solar_system = { has_star_flag = UGRC_flg_sstm_RULE_jump_no } }
		always = no
	}
	#	kuatAG
	else_if = { limit = { solar_system = { has_star_flag = ag_no_jump_out_system } }
		custom_tooltip = { fail_text = "ag_jump_drive_unable_system_tooltip"
			always = no
		}
	}
	#	seooc
	else_if = { limit = { solar_system = { has_star_flag = nep_Scrus_cluster } }
		custom_tooltip = { fail_text = "CAN_NOT_JUMP_WHEN_IN_SCRUS"
			always = no
		}
	}
	else_if = {
		limit = {
			solar_system = {
				OR = {
					has_star_flag = nep_whitegoo_1
					has_star_flag = nep_whitegoo_2
					has_star_flag = nep_whitegoo_3
				}
			}
			controller = { NOT = { has_technology = tech_nep_whitegoo_3_2 } }
		}
		custom_tooltip = { fail_text = "CAN_NOT_JUMP_IN_WHITEGOO"
			always = no
		}
	}
	#	dsc
	else_if = { limit = { solar_system = { has_star_flag = DSC_NOT_allow_jump_drive } }
		custom_tooltip = { fail_text = "DSC_NOT_allow_jump_drive"
			always = no		# 简化了,禁止<any_system_planet>
		}
	}
	#	spth
	else_if = {
		limit = {
			solar_system = {
				OR = {
					has_star_flag = touhou_no_jump_out_system
					check_modifier_value = { modifier = system_can_not_jump_drive	value != 0 }
				}
			}
		}
		custom_tooltip = {
			fail_text = mod_system_can_not_jump_drive
			always = no
		}
	}
	#	Alily
	else_if = {
		limit = {
			solar_system.starbase? = {
				has_starbase_building = AL_AntiFTL
				owner? = { is_hostile = prevprev.controller }
			}
		}
		custom_tooltip = {
			fail_text = AL_cannot_start_jump
			always = no
		}
	}
	#	cgelf
	else_if = {
		limit = { solar_system? = { has_star_flag = ELF_Singularity_System } }
		custom_tooltip = {
			fail_text = cannot_jump_to_ELF_Singularity_System
			owner? = { has_country_flag = ELF_Singularity_System_entry_permit }
		}
	}
	#	其他
	else = {
		always = yes
	}
}

###	can_spawn_occupation_armies

###_|UGRC传感器|	########################################################################
#	V/kuatAG/kuatP/AUP/kzvoy/spth/IFE/Alily
# this = system
# root = country
system_blocks_sensors = {
	#NOT = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors_IGNORE@root }	# |UGRC传感穿透|预留给一些暂时开图的功能
	has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@root	# |UGRC传感阻碍|83%|
}


###_|UGRC跃迁星系|	########################################################################	|core|
#	V/seooc/AUP/kzvoy/dsc/spth/ACOT/SBTG/IFE/Alily
# Root = country attempting to target system for movement
# This = system being targeted
can_enter_system_by_jump = {
	can_enter_system_by_jump_trigger = {
		SCOPE = root
	}
}


###	可迁移人口	########################################################################
#	V/AUP/EMB/MECR/cglbu
# This = pop_group
can_resettle_pop_group = {
	##	MECR
	Maid_trigger_9_can_resettle_pop = yes
	#	EMB
	custom_tooltip = {
		fail_text = "caretaker_refuse"
		is_exp_tree_caretaker = no
	}
	##	cglbu
	NOT = {
		owner = {
			has_origin = origin_female_in_shadow
			hidden_trigger = {
				any_country = { has_country_flag = origin_female_in_shadow@prev }
			}
			NOR = {
				has_ascension_perk = ap_bumpy_cg_road_ahead_yield
				has_ascension_perk = ap_bumpy_cg_road_ahead_coexistence
			}
		}
	}

	## Self-modified Pops won't leave
	custom_tooltip = {
		fail_text = "self_modified_refuse"
		NAND = {
			has_trait = trait_self_modified
			is_enslaved = no	# AUP
		}
	}
	# Pathogenic Pops Can't Resettle
	custom_tooltip = {
		fail_text = "pathogenic_genes_warning"
		NOT = { has_trait = trait_pathogenic_genes }
	}
	custom_tooltip = {
		fail_text = "origin_egalitarian_refuse"
		NAND = {
			has_ethic = ethic_egalitarian
			is_enslaved = no
			planet = { has_modifier = paragon_origin_reformists }
		}
	}
	custom_tooltip = {
		fail_text = "no_resettling_apps"
		if = {
			limit = {
				has_virtual_species_trait = yes
			}
			exists = owner
			owner = {
				is_fallen_empire = no
				NOT = {
					has_active_tradition = tr_virtuality_adopt
				}

			}
		}
	}
	if = { #Done as an IF/ELSE so the tooltip isn't hideous and unreadable
		limit = { is_shackled_robot = yes }
		always = yes
	}
	#	+EMB
	else_if = {
		limit = {
			planet = {
				OR = {
					is_doomsday_planet = yes
					#	EMB
					has_modifier = deteriorating_ecosystem
					has_modifier = catastrophe_approach
					has_modifier = apocalypse
					has_modifier = ravenous_locusts
					has_modifier = planet_active_worm
				}
			}
		}
		always = yes
	}
	else_if = {
		limit = {
			planet = {
				has_modifier = planet_culture_shock
			}
		}
		OR = {
			is_same_species = planet.owner
			planet = {
				NOT = { has_modifier = planet_culture_shock }
			}
		}
	}
	else_if = {
		limit = {
			planet = {
				is_capital = yes
				pop_amount < 200
			}
			NOT = {
				owner = {
					any_owned_colony = {
						is_capital = no
						NOT = {
							planet = {
								is_planet_class = pc_cosmogenesis_world
							}
						}
					}
				}
			}
		}
		custom_tooltip = {
			fail_text = "no_abandon_capital_for_unviable_planet"
			always = no
		}
	}
	else_if = {
		limit = {
			planet = {
				is_planet_class = pc_cosmogenesis_world
				owner = {
					has_ascension_perk = ap_cosmogenesis
				}
				pop_amount < 200
			}
		}
		custom_tooltip = {
			fail_text = "no_unfueled_lathe"
			always = no
		}
	}
	else_if = {
		limit = {
			planet = {
				has_deposit = d_genesis_preserve
				sapient_pop_amount < 200
			}
			owner = {
				is_guided_sapience_empire = yes
			}
		}
		custom_tooltip = {
			fail_text = "no_abandon_genesis_preserve"
			always = no
		}
	}
	else_if = {
		limit = {
			owner = {
				has_ascension_perk = ap_cosmogenesis
			}
		}
		always = yes
	}
	else_if = {
		limit = {
			owner = {
				is_gestalt = yes
			}
		}
		always = yes
	}
	else = {
		custom_tooltip = {
			fail_text = RESETTLEMENT_POLICY_FAIL
			owner = {
				has_policy_flag = resettlement_allowed
			}
		}
	}
}
### can_country_resettle
### can_resettle_colony
### should_spawn_deposits
###	can_get_colony_events


###_|UGRC新地|	########################################################################
#	V/kuatP/AUP
# This = Planet
is_new_colony = {
	NOT = { has_carrier_flag = UGRC_flg_plnt_RULE_is_new_colony_NON }	# |UGRC标签|
}


###_|UGRC犯罪|	########################################################################	|-50%|
#	V/kuatP/AUP
# This = pop_group
pop_group_generates_crime = {
	has_pop_group_flag = UGRC_flg_pop_RULE_generates_crime	# |UGRC标签|	wsg/swg/kc/adf/PTep
#	is_sapient = yes
#	is_non_sapient_robot = no
#	is_being_assimilated = no
}


###	can_pops_grow_on_colony
###	can_pops_assemble_on_colony
###	can_pops_decline_on_colony


###	强制灭绝	########################################################################	|core|
#	V/ECC/ECI/AUP/EMB/wv/nyto
## If this returns true, the species will be set to decline even if it is not being purged
# This = species
# From = planet
## Note: success text tooltips are shown in alert_pops_declining alert.
should_force_decline_species = {
	OR = {
		#_|V克隆大军|	+ECC
		# Infertile Clone Army pops should decline if in Country that can't have Vats, or there is a Vat shortage.
		custom_tooltip = {
			success_text = CLONE_ARMY_FORCE_DECLINE
			exists = this
			OR = {
				has_trait = trait_clone_soldier_infertile
				has_trait = trait_clone_soldier_infertile_full_potential
			}
			from = {
				OR = {
					# Check if country is unable to build Vats for this species.
					AND = {
						exists = owner
						owner = {
							OR = {
								has_country_flag = clone_army_fertility_unlocked			# Can't have Vats anymore.
								NOR = {
									has_origin = origin_clone_army	# Can't have Vats.
									owner_main_species = { is_same_species = root }	# Our Vats can't build this species.
									#	ECC
									has_civic = PrimPlayer_civic_barbaric_despoilers_khan	# Can't have Vats.
									has_civic = civic_barbaric_despoilers_khan				# Can't have Vats.
								}
							}
						}
					}
					# Vats check out, but are there more pops than Vats support?
					check_variable = { which = clone_pops_missing value < 0 }
				}
			}
		}
		#_|V虚空孳孽|	+ECI
		from = {
			custom_tooltip = {
				success_text = VOIDSPAWN_FORCE_DECLINE
				exists = this
				#	ECI
				if = { limit = { has_global_flag = ideological_revolution }
					OR = {
						free_housing <= -1000
						planet_crime >= 90
						planet_stability <= 10
						has_modifier = voidspawn_colony_mod
						has_modifier = eci_life_for_the_nation
						owner = {
							OR = {
								has_country_flag = cultural_revolution
								has_country_flag = situation_social_balance_stage_1
								has_country_flag = situation_social_balance_stage_2
								has_country_flag = situation_social_balance_stage_9
								has_country_flag = situation_social_balance_stage_10
							}
						}
					}
				}
				#	V
				else = {
					has_modifier = voidspawn_colony_mod
				}
			}
		}

		##	wv	####################
		custom_tooltip = {
			success_text = OBJ_MASTER_FORCE_DECLINE
			exists = this
			has_trait = trait_reanimated_materials
			NOR = {
				has_trait = trait_psyborg_efficient_processors
				has_trait = trait_cro_implants_psionics
				has_trait = trait_psionic
				AND = {
					exists = from.owner
					from.owner = {
						has_technology = tech_self_adaptive_arcane_matrix
					}
				}
			}
			from = {
				OR = {
					# Check if country is unable to build Vats for this species.
					AND = {
						exists = owner
						owner = {
							OR = {
								NOT = { has_origin = origin_obj_master }					# Can't have Obj-avatars.
								has_country_flag = synthetic_empire			# Can't have Vats anymore.
							}
						}
					}
					# Vats check out, but are there more pops than Vats support?
					num_assigned_jobs = { job = matter_reanimator value = 0 }
				}
			}
		}
		#	nyto
		custom_tooltip = {
			success_text = "GF_nyto_decline"
			from = { colony_type = col_GF_nyto_capital }
		}
		#	EMB
		custom_tooltip = {
			success_text = TREEFOLK_FORCE_DECLINE
			is_exp_tree_caretaker = yes
			from = {
				NOR = {
					has_deposit = d_tree_of_life_colony
					has_deposit = d_tree_of_life_home
				}
			}
		}
		custom_tooltip = {
			success_text = UNIT04CHILDREN_FORCE_DECLINE
			OR = {
				has_trait = trait_organic_fourschildren
				has_trait = trait_organic_fourschildren_2
			}
			from = {
				OR = {
					AND = {
						exists = owner
						owner = {
							OR = {
								NOT = {
									has_origin = origin_techno_world
								}
								NOT = {
									owner_main_species = {
										is_same_species = root
									}
								}
							}
						}
					}
					check_variable = {
						which = techno_pops_missing
						value < 0
					}
				}
			}
		}
	}
}




###	国家可建公司	########################################################################	|core|
#	V/ECI/AUP/wsg/azl/kzvoy/arkn/kc/MECR/SC/cglbu/cgelf/HFE/hiveDLC/Alily
##	MCA/cgelf/ARP
# This = country
can_build_branch_offices = {
	custom_tooltip = {
		fail_text = BRANCH_OFFICE_NOT_MEGACORP
		OR = {
			#	V
			is_megacorp = yes
			has_civic = civic_galactic_sovereign_megacorp

			##	wsg
			has_authority = auth_warshipgirls
			has_civic = civic_sh_criminal_syndicate
			#	ECI		|全部可建|
			has_civic = civic_world_cooperative
			has_civic = civic_hive_capital_creates_gods
			has_civic = civic_machine_financial_investment
			#	azl
			azurlane_default_govement_trigger = yes
			#	kzvoy
			KZ_VOY_can_build_branch_offices = yes
			#	arkn
			has_civic = civic_business_union
			#	kc
			has_civic = civic_business_union
			AND = {
				has_authority = auth_kancolle
				has_tradition = tr_akashi_shop_open_the_kanmusu_company
			}
			#	MECR		|外派服务飞升|
			Maid_trigger_0_can_build_branch_offices = yes
			#	SC
			has_civic = civic_taldarim_marauder
			#	cglbu
			has_authority = auth_brothel	#淫渊企业
			has_origin = origin_INN_destruction_light	#破灭之光
			has_valid_civic = civic_parasite_rise_and_all	#迭起兴衰
			has_valid_civic = civic_master
			has_valid_civic = civic_lust_analysis
			#	HFE
			is_country_type = hfe_pirate
			#	hiveDLC
			has_valid_civic = civic_mutualistic_behavior
			#	Alily
			has_authority = auth_AL_democratic

			#	MCA
			has_authority = auth_corporate_fiefdom
			has_authority = auth_cooperative
			#	cgelf
			is_ELF_can_build_branch_offices = yes
			#	ARP
			has_authority = auth_Arp_0

		}
	}
}


###	国家支持公司	########################################################################	|core|
#	V/ECI/ECB/AUP/wsg/arkn/kc/MECR/cglbu/Alily
##	aFE
# This = country
can_support_branch_offices = {
	##_|禁止_国家类型|
	custom_tooltip = {
		fail_text = BRANCH_OFFICE_NOT_FALLEN_EMPIRES
		NOR = {
			is_country_type = fallen_empire
			is_country_type = awakened_fallen_empire

			#	wsg
			is_wg_fallen_empire = yes
			is_sh_fallen_empire = yes
			#	kc
			has_authority = auth_kc_fe
			#	ev
			is_country_type = fallen_empire_ev
			#	cglbu
			has_origin = origin_INN_destruction_light	#破灭之光
			has_valid_civic = civic_parasite_rise_and_all	#迭起兴衰
			has_valid_civic = civic_lust_analysis
			#	Alily
			is_country_type = al_fallen_empire
			is_country_type = al_fallen_empire_no_ai

			#	aFE	|afe|
			is_country_type = awakened_gate_builders
		}
	}
	#custom_tooltip = {
	#	fail_text = BRANCH_OFFICE_NOT_ON_MEGACORP_PLANET
	#	NOR = {
	#		is_megacorp = yes
	#		has_civic = civic_galactic_sovereign_megacorp
	#	}
	#}
	
	##_|非普通国家|	+MECR/ECI/ECB
	custom_tooltip = {
		fail_text = BRANCH_OFFICE_NOT_REGULAR_EMPIRE
		OR = {
			is_gestalt = no
			#	MECR
			Maid_trigger_1_can_support_branch_offices = yes
			#	ECI		|修正资+资本蜂群+资本智械|
			has_civic = civic_world_cooperative
			has_civic = civic_hive_capital_creates_gods
			has_civic = civic_machine_financial_investment
		}
		OR = {
			is_country_type = default
			is_country_type = primitive
			#	ECB
			has_global_flag = bug_branch_active
		}
	}
	##_|土著|	+ECI/ECB
	custom_tooltip = {
		fail_text = BRANCH_OFFICE_NOT_ADVANCED_PRE_FTL
		if = {
			limit = {
				is_primitive = yes
				OR = {
					is_gestalt = no
					#	ECI		|资本蜂群+资本智械|
					has_civic = civic_hive_capital_creates_gods
					has_civic = civic_machine_financial_investment
				}
			}
			OR = {
				has_pre_ftl_age = atomic_age
				has_pre_ftl_age = early_space_age
				#	ECB
				capital_scope? = { has_global_flag = bug_branch_active
					space_owner? = { is_criminal_syndicate = yes }
				}
			}
		}
	}
}


###_|UGRC分部星球|	########################################################################	|core|
#	V/ECC/EMB/wsg/azl/kzvoy/cglbu/cgelf/Alily
#_|未更新|	arkn/kc/kzvoy/HFE/MECR
##	MCA
# This = planet
# Root = country
can_build_branch_office_on_colony = {
	
	###_|非灭绝政体|
	custom_tooltip = {
		fail_text = requires_recipient_not_fanatic_purifiers
		exists = owner
		owner = {
			OR = {
				is_same_species = root
				NOT = { has_civic = civic_fanatic_purifiers }
			}
		}
	}
	###_|未被观察|	+ECC
	custom_tooltip = {
		fail_text = BRANCH_OFFICE_NO_OBSERVATION_OUTPOST
		if = {
			limit = {
				root = { is_criminal_syndicate = yes }
				owner = { is_primitive = yes }
			}
			has_observation_outpost = yes
			observation_outpost_owner = {
				is_same_value = root
			}
		}
		#	ECC
		else_if = { limit = { has_global_flag = ethic_civic_classic_active }
			if = {
				limit = {
					root = { is_worker_coop_empire = yes }
					owner = { is_primitive = yes }
				}
				has_observation_outpost = yes
				observation_outpost_owner = {
					is_same_value = root
				}
			}
			else_if = {
				limit = {
					root = { has_civic = civic_ruthless_competition }
					owner = { is_primitive = yes }
				}
				has_observation_outpost = yes
				observation_outpost_owner = {
					is_same_value = root
				}
			}
		}
	}
	###_|core商业协定|	+wsg/ECC/EMB/azl/cglbu	/kc/HFE/Alily/kzvoy/MECR/arkn
	custom_tooltip = {
		fail_text = BRANCH_OFFICE_NOT_COMMERCIAL_PACT
		exists = owner
		OR = {
			##_|简单root条件|	无需签订贸易协议
			root = {
				OR = {
					is_criminal_syndicate = yes
					#	|UGRC分部星球|自设分部	+azl/ARP/cglbu
					AND = { is_variable_set = UGRC_var_cntr_RULE_branch_self_ENABLE
						is_same_value = prev.owner
					}

					#	wsg
					has_civic = civic_sh_criminal_syndicate
					#	kzvoy
					KZ_VOY_can_build_branch_offices = yes
					#	MECR
					Maid_trigger_0_can_build_branch_offices = yes
					#	arkn
					has_civic = civic_business_union
					#	kc
					has_authority = auth_kancolle
					#	ARP
					has_authority = auth_Arp_0
				}
			}
			owner = { has_commercial_pact = root }	# |贸易协定|	基本条件,除此之外都可以视为特例
			owner = { is_in_federation_with = root }
			AND = {
				has_observation_outpost = yes
				observation_outpost = {
					has_modifier = preftl_action_trade_pact
				}
			}
			# allow branch offices in subsidiaries and vice versa (and fellow subjects)
			##_|附庸国建造|
			root = {
				is_subject = yes
				OR = {
					is_megacorp = yes
					has_civic = civic_galactic_sovereign_megacorp
				}
				overlord = {
					OR = {
						is_same_value = prevprev.owner
						is_same_value = prevprev.owner.overlord
					}
				}
			}
			##_|宗主国建造| +wsg
			owner = {
				is_subject = yes
				overlord = {
					OR = {
						is_same_value = root
						is_same_value = root.overlord
					}
					OR = {
						is_megacorp = yes
						has_civic = civic_galactic_sovereign_megacorp
						# 	wsg	|宗主必然建造|
						has_authority = auth_warshipgirls
					}
				}
			}
			AND = {
				root = { has_civic = civic_galactic_sovereign_megacorp }
				owner = { is_galactic_community_member = yes }
			}
			AND = {
				root = { has_modifier = imperial_charter }
				owner = { is_galactic_community_member = yes }
			}
			

			##	wsg		|贸易战争|
			AND = {
				owner = { has_country_flag = lose_wg_shop_war }
				root = { has_country_flag = pantsu_shop_origin }
			}
			#	ECC
			AND = { has_global_flag = ethic_civic_classic_active
				OR = {#
					root = { has_civic = civic_ruthless_competition }
					AND = {
						root = { is_worker_coop_empire = yes }
						owner = { 
							OR = {
								has_policy_flag = slavery_allowed 
								any_owned_pop_group = { has_living_standard = { type = living_standard_stratified } }
							}
						}
					}
					AND = {
						ROOT = { has_origin = origin_slavers }	#MSI Branch Offices
						owner = { has_modifier = preftl_action_trade_pact_msi }
						has_modifier = PrimPlayer_the_obelisk
					}
				}
			}
			#	EMB
			owner = { has_country_flag = cb_markets_opened@root }
			#	cglbu
			root = { has_global_flag = love_between_us
				OR = {
					#爱欲盛宴
					has_valid_civic = civic_master
					#破灭之光
					has_origin = origin_INN_destruction_light
					#迭起兴衰
					has_valid_civic = civic_parasite_rise_and_all
					has_valid_civic = civic_lust_analysis
				}
			}

			#	HFE
			root = { is_country_type = hfe_pirate		is_forced_friendly = prev.owner }
		}
	}
	###_|巨企附庸|
	custom_tooltip = {
		fail_text = BRANCH_OFFICE_MEGACORP_OVERLORD
		exists = owner
		# failure message for having a corporate overlord

		if = {
			limit = {
				OR = {
					# Not valid if you aren't a subject.
					root = {
						is_subject = no
					}
					# Or if your overlord isn't a megacorp.
					root = {
						is_subject = yes
						overlord = {
							NOR = {
								is_megacorp = yes
								has_civic = civic_galactic_sovereign_megacorp
							}
						}
					}
				}
			}
			always = yes
		}
		else = {
			AND = {
				root = {
					is_subject = yes
					overlord = {
						OR = {
							is_megacorp = yes
							has_civic = civic_galactic_sovereign_megacorp
						}
					}
				}
				owner = {
					OR = {
						is_subject = no
						AND = {
							is_subject = yes
							overlord = { NOT = { is_same_value = root.overlord } }
						}
					}
				}
			}
		}
	}
	###_|贸易协议| +wsg/Aliliy
	custom_tooltip = {
		fail_text = BRANCH_OFFICE_CRIMINAL_HERITAGE_HAS_TRUCE
		exists = owner
		OR = {
			##	|非罪企|
			root = { is_criminal_syndicate = no }
			##	|和平状态|
			owner = {
				NOR = {
					has_truce = root
					is_at_war_with = root
				}
			}

			##	wsg
			owner = { has_civic = civic_sh_criminal_syndicate }	# 深海罪企
			AND = {#贸易战争
				owner = { has_country_flag = lose_wg_shop_war }
				root = { has_country_flag = pantsu_shop_origin }
			}
			#	Aliliy
			root = { has_authority = auth_AL_democratic }
		}
	}
	###_|罪企查封|	+wsg/Aliliy
	custom_tooltip = {
		fail_text = BRANCH_OFFICE_CRIMINAL_COOLDOWN
		exists = owner
		OR = {
			##	|非罪企|
			root = { is_criminal_syndicate = no }
			#	|当前星球未查封| +wsg
			AND = {
				root = {
					OR = {
						is_criminal_syndicate = yes
						has_civic = civic_sh_criminal_syndicate	# wsg
					}
				}
				NOT = { has_carrier_flag = criminal_branch_closed_cooldown_planet@root }
			}

			##	wsg	|贸易战争|
			AND = {
				owner = { has_country_flag = lose_wg_shop_war }
				root = { has_country_flag = pantsu_shop_origin }
			}
			#	Aliliy
			root = { has_authority = auth_AL_democratic }
		}
	}
	###	无分部世界
	custom_tooltip = {
		fail_text = NO_BRANCH_OFFICE_ON_AI_WORLD
		NOT = { is_planet_class = pc_ai }
	}
	custom_tooltip = {
		fail_text = NO_BRANCH_OFFICE_ON_NANITE_WORLD
		NOT = { is_planet_class = pc_gray_goo }
	}
	custom_tooltip = {
		fail_text = NO_BRANCH_OFFICE_ON_SYNAPTIC_LATHE
		NOT = { is_planet_class = pc_cosmogenesis_world }
	}
	###	自我建造
	custom_tooltip = {
		fail_text = NO_BRANCH_OFFICE_ON_SELF
		OR = {
			owner = { NOT = { is_same_value = root } }	#|非己方殖民地|
			root = { is_variable_set = UGRC_var_cntr_RULE_branch_self_ENABLE }	#_|UGRC分部星球|自设分部
		}
	}

	###	mod	##############################
	## MCA
	hidden_trigger = {
		if = { limit = { has_global_flag = using_mod_more_corporate_authorities }
			NOR = {
				NOT = { root = { has_ai_personality = principled_rogues		is_ai = yes } }	
				owner = { their_opinion = { who = root value < 0 } }
				owner = {
					their_opinion = { who = root value < 20 }
					NOT = { has_opinion_modifier = { who = root modifier = opinion_new_contact is_reverse = yes } }
				}
			}
		}
	}
	## wsg
	if = { limit = { has_global_flag = has_wsg_mod }	#_|舰r激活|
		custom_tooltip = {
			fail_text = requires_recipient_not_warshipgirls
			owner? = {
				NOR = {
					has_authority = auth_warshipgirls	# 舰r=不接受分公司
					AND = {
						has_authority = auth_shenhai	# 深海|战利品商店||罪企|=不接受分公司
						OR = {
							has_country_flag = pantsu_shop_origin
							has_civic = civic_sh_criminal_syndicate
						}
					}
				}
			}
		}
	}
	##	ECC
	if = { limit = { has_global_flag = ethic_civic_classic_active }
		custom_tooltip = {
			fail_text = INTEL_INFO_intel_economy_systems_low
			if = {
				limit = { ROOT = { has_civic = civic_ruthless_competition } }
				ROOT = { intel_level = { level > low system = PREV.solar_system } }
			}
		}
		custom_tooltip = {
			fail_text = BRANCH_OFFICE_NO_UNDERGROUND_RAILROAD
			if = {
				limit = {
					root = { is_worker_coop_empire = yes }
					OWNER = {
						is_primitive = no
						OR = {
							has_policy_flag = slavery_allowed
							any_owned_pop_group = {
								has_living_standard = { type = living_standard_stratified }
							}
						}
					}
				}
				OWNER = {
					has_country_flag = EaC_operation_complete_establish_underground_railroad@root
				}
			}
		}
	}
	##	MECR	|失控女仆|写得挺精致√
	Maid_trigger_2_can_build_branch_office_on_planet = yes
	##	cgelf
	ELF_can_build_branch_office_on_planet_rules = yes
	##	kzvoy
	KZ_VOY_can_build_branch_office_on_planet = yes
}


###_|UGRC罪企|	########################################################################
#	V/ECC/ECI/AUP/ev/wsg/SC/cgelf
# This = country
# Checked by is_criminal_syndicate trigger
is_criminal_syndicate_rule = {
	#	|政体|
	OR = {
		is_megacorp = yes
		has_valid_civic = civic_galactic_sovereign_megacorp
		#	wsg
		has_authority = auth_warshipgirls
		#	UGRC
		is_variable_set = UGRC_var_cntr_RULE_criminal_syndicate
	}
	#	|国策|
	OR = {
		has_valid_civic = civic_criminal_heritage
		#	UGRC
		is_variable_set = UGRC_var_cntr_RULE_criminal_syndicate

		#	ECC
		has_valid_civic = civic_military_dictatorship_corporate
	}
}

###	can_crossbreed_species_on_colony
###	can_crossbreed_species
###	can_win_timed_victory
###	can_use_galactic_market

###	奴隶贩卖	########################################################################	如果有问题就恢复vanilla
#	V/AUP/EMB/wv/cglbu
##	SC/PTep
#_pop_trgr	[ariphaos_patch_slaves_expel]
# ROOT = country
# This = pop_group
can_be_sold_on_slave_market = {
	exists = owner
	OR = {
		is_enslaved = yes
		is_non_sapient_robot = yes
		is_shackled_robot = yes
		is_being_purged = yes	# AUP
	}
	#	SC
	species = { UGRC_trgr_spcs_SC = no }
	#	PTep
	NOT = { has_trait = trait_plentiful_traditions_pt_cocoon }
	
	##	VANILLA	################################################################################	+EMB
	OR ={
		root? = { is_ai = no }
		has_citizenship_rights = no
		is_on_slave_market = yes	# pops that were already on the market should stay there
		AND = {
			is_unemployed = yes
			planet = {
				num_unemployed > 300
			}
		}
		#	EMB
		AND = { has_global_flag = expanded_pops_active
			is_civilian_pop_group = yes
			is_being_assimilated = no
			planet = {
				count_owned_pop_amount = {
					limit = {
						is_civilian_pop_group = yes
					}
					count > 1000
				}
			}
			OR = {
				NOT = { has_trait = trait_syncretic_proles }
				ROOT = { NOT = { has_origin = origin_syncretic_evolution } }
			}
		}
	}
	if = {
		limit = {
			has_global_flag = organic_slave_trade_banned_flag
		}
		is_organic_species = no
	}
	if = {
		limit = {
			has_global_flag = sentient_slave_trade_banned_flag
		}
		is_sapient = no
	}
	#	+EMB
	NOR = {
		# Since they can't reproduce, they die out too fast for anyone to want to buy them.
		has_trait = trait_clone_soldier_infertile
		has_trait = trait_clone_soldier_infertile_full_potential
		has_virtual_species_trait = yes
		#	EMB
		has_trait = trait_tree_caretaker
		has_trait = trait_organic_fourschildren
		has_trait = trait_organic_fourschildren_2
		#	wv
		has_trait = trait_servitude
		has_trait = trait_reanimated_materials
	}
}




###	加入社区	########################################################################
#	V/AUP/wsg/SBTG
##	UR
# This = country
can_be_part_of_galactic_community = {
	##	+SBTG
	custom_tooltip = {
		fail_text = "community_default_failtext"
		OR = {
			is_country_type = default
			AND = {
				is_country_type = awakened_fallen_empire
				has_country_flag = fallen_empire_hive_control
			}
			#	SBTG
			is_country_type = sbtg_stellarborne_empire_active
		}
	}
	##	+UR
	custom_tooltip = {
		fail_text = "community_homicidal_failtext"
		NOR = {
			has_civic = civic_fanatic_purifiers
			has_civic = civic_hive_devouring_swarm
			has_civic = civic_machine_terminator
			has_menace_perk = menp_behemoth_ever_hungry
			has_civic = civic_scorched_earth
			has_civic = civic_hive_scorched_earth
			has_country_flag = heir_of_the_khan_khan
			#	UR
			has_country_flag = dark_side
		}
	}
	custom_tooltip = {
		fail_text = "community_declared_crisis_failtext"
		has_been_declared_crisis = no
		NOT = { has_country_flag = malevolent_aura_empire }
	}
	custom_tooltip = {
		fail_text = "community_declared_crisis_failtext"
		#fail_text = "community_overlord_declared_crisis_failtext"
		OR = {
			NOT = { exists = overlord }
			overlord = {
				has_been_declared_crisis = no
				NOT = { has_country_flag = malevolent_aura_empire }
			}
		}
	}
	
	##	wsg
	custom_tooltip = { #焚飞齐宣王被踢出共同体
		fail_text = "community_declared_crisis_failtext"
		NOT = { has_country_flag = wgfm_quit_community }
	}
}

###	加入帝国	########################################################################
#	V/AUP/wsg
##	UR
# This = country
can_be_part_of_galactic_empire = {
	custom_tooltip = {
		fail_text = "community_default_failtext"
		OR = {
			is_country_type = default
			AND = {
				is_country_type = awakened_fallen_empire
				has_country_flag = fallen_empire_hive_control
			}
		}
	}
	##	+UR
	custom_tooltip = {
		fail_text = "community_homicidal_failtext"
		NOR = {
			has_civic = civic_fanatic_purifiers
			has_civic = civic_hive_devouring_swarm
			has_civic = civic_machine_terminator
			has_menace_perk = menp_behemoth_ever_hungry
			has_civic = civic_scorched_earth
			has_civic = civic_hive_scorched_earth
			#	UR
			has_country_flag = dark_side
		}
	}
	custom_tooltip = {
		fail_text = "community_declared_crisis_failtext"
		has_been_declared_crisis = no
	}
	custom_tooltip = {
		fail_text = "community_declared_crisis_failtext"
		#fail_text = "community_overlord_declared_crisis_failtext"
		OR = {
			NOT = { exists = overlord }
			overlord = { has_been_declared_crisis = no }
		}
	}
	
	##	wsg
	custom_tooltip = { #焚飞齐宣王被踢出共同体
		fail_text = "community_declared_crisis_failtext"
		NOT = { has_country_flag = wgfm_quit_community }
	}
}

###	可见社区	########################################################################
#	V/AUP/wsg/SBTG
##	UR
# This = country
can_see_galactic_community = {
	##	+SBTG/UR
	OR = {
		has_country_flag = galcom_form_aye
		has_country_flag = galcom_form_nay
		is_galactic_community_member = yes
		#	SBTG
		is_country_type = sbtg_stellarborne_empire_active
		has_country_flag = dark_side		# UR
	}

	#	wsg
	custom_tooltip = { #焚飞齐宣王被踢出共同体
		fail_text = "community_declared_crisis_failtext"
		NOT = { has_country_flag = wgfm_quit_community }
	}
}

###	加入议会	########################################################################
#	V/AUP/wsg/SBTG
##	UR
# This = country
can_be_part_of_galactic_council = {
	##	+SBTG
	OR = {
		is_country_type = default
		has_country_flag = fallen_empire_hive_control
		#	SBTG
		is_country_type = sbtg_stellarborne_empire_active
	}
	##	+UR
	NOR = {
		has_civic = civic_fanatic_purifiers
		has_civic = civic_hive_devouring_swarm
		has_civic = civic_machine_terminator
		has_menace_perk = menp_behemoth_ever_hungry
		has_civic = civic_scorched_earth
		has_civic = civic_hive_scorched_earth
		#	UR
		has_country_flag = dark_side
	}
	
	##	wsg
	custom_tooltip = {#焚飞齐宣王被踢出共同体
		fail_text = "community_declared_crisis_failtext"
		NOT = { has_country_flag = wgfm_quit_community }
	}
}


###	must_be_advanced_empire
###	is_allowed_to_be_advanced_empire
###	has_enough_pops_for_necrophage_on_colony




###	人口可自动迁移	########################################################################
#	V/AUP/EMB/cglbu
#	HFE
# Root = current planet
# This = pop_group
# Purge, Sapience, Migration Controls policy (ignored by Gestalts and Synths), and target habitability are checked in code.
can_pop_group_auto_migrate = {
	## +EMB/HFE
	OR = {
		is_unemployed = yes
		is_pop_category = civilian
		is_pop_category = maintenance_drone
		is_shackled_robot = yes
		# EMB
		AND = { has_global_flag = expanded_pops_active
			is_enslaved = yes
			ROOT = {
				has_modifier = slave_colony
				num_assigned_jobs = {
					job = slave_toiler
					value > 500
				}
			}
		}
		#	HFE
		hfe_trigger_unemployed_auto_migrate = yes
	}
	custom_tooltip = {
		fail_text = AUTO_MIGRATE_ASSIMILATED
		is_being_assimilated = no
	}
	custom_tooltip = {
		fail_text = AUTO_MIGRATE_ROOTED
		NOT = { has_trait = trait_rooted }
	}
	custom_tooltip = {
		fail_text = AUTO_MIGRATE_VIRTUALITY
		OR = {
			has_virtual_species_trait = no
			AND = {
				has_virtual_species_trait = yes
				exists = owner
				owner = {
					OR = {
						is_individual_machine = no
						is_machine_empire = no
					}
				}
			}
		}
	}

	##	EMB
	if = {
		limit = { is_exp_tree_caretaker = yes }
		custom_tooltip = {
			fail_text = caretaker_refuse
			always = no
		}
	}
	#	cglbu	-雌伏于阴影之下
	if = {
		limit = { owner = { has_origin = origin_female_in_shadow } }
		NAND = {
			hidden_trigger = {
				any_country = { has_country_flag = origin_female_in_shadow@prev }
			}
			NOT = { has_ascension_perk = ap_bumpy_cg_road_ahead_yield }
		}
	}
}

###	可自动迁移	########################################################################
#	V/EMB/tmod/spth
# This = planet
# Checked before can_pop_auto_migrate to save performance
can_colony_auto_migrate = {
	hidden_trigger = {
		is_colony = yes
	}
	custom_tooltip = {
		fail_text = AUTO_MIGRATE_CULTURE_SHOCK
		NOT = { has_modifier = planet_culture_shock }
	}
	#	+EMB
	custom_tooltip = {
		fail_text = AUTO_MIGRATE_COLONY_TOO_NEW
		OR = {
			AND = {
				is_under_colonization = no
				colony_age > 60
			}
			is_capital = yes # Don't break Doomsday!
			#	EMB
			pop_amount > 2000
			has_modifier = deteriorating_ecosystem
			has_modifier = catastrophe_approach
			has_modifier = apocalypse
			has_modifier = ravenous_locusts
			has_modifier = planet_active_worm
		}
	}
	custom_tooltip = {
		fail_text = AUTO_MIGRATE_ONLY_HAS_ONE_POP
		sapient_pop_amount > 100
	}
	hidden_trigger = {
		exists = owner
		owner = {
			OR = {
				is_country_type = default
				is_country_type = awakened_fallen_empire
			}
		}
	}

	##	tmod
	TIME_RULE_trgr_Can_planet_auto_migrate = yes
	#	spth
	if = { limit = { has_global_flag = has_touhou_mod }
		custom_tooltip = {
			fail_text = modifier_colony_cannot_auto_migrate_failed
			check_modifier_value = { modifier = colony_cannot_auto_migrate	value = 0 }
		}
	}
}

###	接收自动移民	########################################################################
#	V/EMB/tmod
can_colony_receive_auto_migration = {
	NOR = {
		planet_devastation >= 10
		has_modifier = planet_culture_shock
		is_doomsday_planet = yes
		is_planet_class = pc_cosmogenesis_world

		# Eevt
		has_modifier = deteriorating_ecosystem
		has_modifier = catastrophe_approach
		has_modifier = apocalypse
		has_modifier = ravenous_locusts
		has_modifier = planet_active_worm
		# EFevt
		has_modifier = mzilli_events_dying_world
	}
	
	##	tmod
	TIME_RULE_trgr_Can_planet_receive_auto_migrate = yes
}


###	宜居修饰	########################################################################
#	V/AUP
##	kasPF
#This, root = country
can_gene_mod_habitability = {
	always = yes
	# See can_change_habitability_preference in 05__scripted_triggered_traits.txt
	#	kasPF
	NOT = { is_variable_set = PF_var_cntr_STOP_ai_species_mod }
}
###	高级修饰	########################################################################	|core|
#	V/kuatP/AUP/wsg/swg/azl/adf/mmNEW/spth/cgelf
##	FW/kasPF
#This, root = country
can_add_advanced_traits = {
	OR = {
		has_tradition = tr_genetics_enhanced_expression
		has_active_tradition = tr_purity_exemplary_genetics
		has_active_tradition = tr_cloning_somatic_synthesization
		has_active_tradition = tr_cloning_somatic_synthesization_clone_army
		has_active_tradition = tr_mutation_unnatural_selection

		is_variable_set = UGRC_var_cntr_RULE_all_genemodding	# UGRC
		is_variable_set = FW_var_cntr_CHT_genemodding	# FW
		##	wsg/swg/azl/adf/spth
		check_modifier_value = { modifier = can_add_negative_traits_organic value != 0 }
		#	mmNEW
		is_nirvana_empire = yes
		has_str_genemodding_tech = yes
		#	cgelf
		has_ascension_perk = ap_perfect_pantyhose_body
	}
	#	kasPF
	if = { limit = { is_ai = yes }
		NOT = { is_variable_set = PF_var_cntr_STOP_ai_species_mod }
	}
}
###	负面修饰	########################################################################	|core|
#	V/kuatP/AUP/wsg/swg/azl/adf/wv/kc/mmNEW/spth/cgelf
##	FW/kasPF
#This, root = country
can_add_negative_traits_organic = {
	OR = {
		has_tradition = tr_genetics_resequencing
		has_active_tradition = tr_cybernetics_integrated_anatomy
		has_active_tradition = tr_cybernetics_assimilator_integrated_anatomy
		has_active_tradition = tr_purity_genotype_regeneration
		has_active_tradition = tr_purity_genotype_regeneration_wilderness
		has_active_tradition = tr_mutation_unnatural_selection

		is_variable_set = UGRC_var_cntr_RULE_all_genemodding	# UGRC
		is_variable_set = FW_var_cntr_CHT_genemodding	# FW
		##	wsg/swg/azl/adf/wv/spth
		check_modifier_value = { modifier = can_add_negative_traits_organic value != 0 }
		#	kc
		has_active_tradition = tr_shipbuilding_adjustment
		#	mmNEW
		is_nirvana_empire = yes
		has_str_genemodding_tech = yes
		#	cgelf
		has_ascension_perk = ap_perfect_pantyhose_body
	}
	#	kasPF
	if = { limit = { is_ai = yes }
		NOT = { is_variable_set = PF_var_cntr_STOP_ai_species_mod }
	}
}
###	移除高级	########################################################################	|core|
#	V/kuatP/AUP/wsg/swg/azl/adf/wv/kc/mmNEW/spth
##	FW/kasPF
#This, root = country
can_remove_positive_traits_organic = {
	OR = {
		has_tradition = tr_genetics_resequencing
		has_active_tradition = tr_cybernetics_integrated_anatomy
		has_active_tradition = tr_cybernetics_assimilator_integrated_anatomy
		has_active_tradition = tr_purity_genotype_regeneration
		has_active_tradition = tr_purity_genotype_regeneration_wilderness
		has_active_tradition = tr_cloning_somatic_synthesization
		has_active_tradition = tr_cloning_somatic_synthesization_clone_army
		has_active_tradition = tr_mutation_unnatural_selection
		AND = {
			has_toxoids = yes
			has_origin = origin_overtuned
		}
		has_technology = tech_gene_expressions
		has_technology = tech_epigenetic_triggers

		is_variable_set = UGRC_var_cntr_RULE_all_genemodding	# UGRC
		is_variable_set = FW_var_cntr_CHT_genemodding	# FW
		##	wsg/swg/azl/adf/wv/spth
		check_modifier_value = { modifier = can_add_negative_traits_organic value != 0 }
		#	kc
		has_active_tradition = tr_shipbuilding_adjustment
		#	mmNEW
		is_nirvana_empire = yes
		has_str_genemodding_tech = yes
	}
	#	kasPF
	if = { limit = { is_ai = yes }
		NOT = { is_variable_set = PF_var_cntr_STOP_ai_species_mod }
	}
}
###	头像修饰	########################################################################	|core|
#	V/kuatP/AUP/wsg/swg/azl/adf/kc/mmNEW/spth/cgelf/Alily
##	FW/kasPF
#This, root = country
can_modify_organic_portraits = {
	OR = {
		has_tradition = tr_genetics_creation
		has_tradition = tr_purity_exemplary_genetics
		has_active_tradition = tr_cloning_somatic_synthesization
		has_active_tradition = tr_cloning_somatic_synthesization_clone_army
		has_tradition = tr_mutation_unnatural_selection

		is_variable_set = UGRC_var_cntr_RULE_all_genemodding	# UGRC
		is_variable_set = FW_var_cntr_CHT_genemodding	# FW
		##	wsg/swg/azl/adf/wv/spth
		check_modifier_value = { modifier = can_add_negative_traits_organic value != 0 }
		#	kc
		has_active_tradition = tr_shipbuilding_transform
		#	mmNEW
		is_nirvana_empire = yes
		has_str_genemodding_tech = yes
		#	cgelf
		has_ascension_perk = ap_perfect_pantyhose_body
		#	Alily
		is_lily_goverments = yes
	}
	#	kasPF
	if = { limit = { is_ai = yes }
		NOT = { is_variable_set = PF_var_cntr_STOP_ai_species_mod }
	}
}


### can_have_contact
### can_have_first_contact
### can_use_envoys_to_raise_imperial_authority
### can_use_envoys_to_lower_imperial_authority
### can_fill_drone_job
### can_fill_worker_job 
### can_fill_specialist_job
### can_fill_ruler_job
### can_fill_precursor_job
### should_colony_automate
### dismiss_leader_cost


###	领袖解雇	########################################################################
#	V/AUP/kc/SC/cgelf/Alily
# this = leader
can_dismiss_leader = {
	if = {
		limit = {
			leader_class = commander
			is_idle = no
			# Rulers and heirs can't be dismissed any way and can be non-idle
			is_ruler = no
			is_heir = no
			NOT = {
				exists = planet
			}
		}
		custom_tooltip = {
			fail_text = "requires_fleet_control"
			exists = fleet
			fleet = {
				controller = {
					is_same_value = prev.owner
					is_same_value = prevprev.owner
				}
			}
		}
	}
	if = {
		limit = {
			OR = {
				is_heir = yes
				is_ruler = yes
			}
		}
		custom_tooltip = {
			always = no
			fail_text = "can_not_dismiss_rulers"
		}
	}
	if = {
		limit = {
			leader_class = scientist
		}
		custom_tooltip = {
			fail_text = "can_not_dismiss_rift_explorer"
			NAND = {
				exists = fleet
				fleet = {
					has_fleet_order = explore_astral_rift_fleet_order
				}
			}
		}
	}
	if = {
		limit = {
			leader_class = commander
		}
		custom_tooltip = {
			fail_text = "no_dismissing_tacs"
			NOT = { has_trait = leader_trait_tactical_algorithms }
		}
	}
	if = {
		limit = {
			has_leader_flag = manifesti_divine_leader
		}
		custom_tooltip = {
			fail_text = "manifesti_leader_tt"
			NOT = { has_leader_flag = manifesti_divine_leader }
		}
	}
	if = {
		limit = {
			has_leader_flag = nomadic_princess # The princess should not be dismissed before finishing her event chain
			owner = {
				has_country_flag = hired_nomadic_princess
			}
		}
		custom_tooltip = {
			fail_text = "nomadic_princess_tt"
			NOT = {
				has_leader_flag = nomadic_princess
				owner = {
					has_country_flag = hired_nomadic_princess
				}
			}
		}
	}
	if = {
		limit = {
			has_leader_flag = eternal_chorus_researcher
			owner = {
				has_event_chain = arkship_eternal_chorus_chain
			}
		}
		custom_tooltip = {
			always = no
			fail_text = "leader_no_dismiss_tt"
		}
	}
	if = {
		limit = {
			has_leader_flag = diplomatic_envoy_official
			owner = {
				has_event_chain = arkship_diplomatic_envoy_chain
			}
		}
		custom_tooltip = {
			always = no
			fail_text = "leader_no_dismiss_tt"
		}
	}

	#	kc
	custom_tooltip = {
		fail_text = "cannot_fire_kancolle_leader"
		is_special_kancolle_leader = no
	}
	#	SC
	custom_tooltip = {
		fail_text = "cannot_fire_StellarisCraft_leader"
		NOT = { has_leader_flag = StellarisCraft_event_leader }
	}
	#	Alily
	custom_tooltip = {
		fail_text = "requires_not_special_lily_leader"
		NOT = { has_leader_flag = AL_special_lily_leader }
	}
	#	cgelf
	custom_tooltip_fail = {
		text = ELF_leader_can_not_dismiss_working
		NOT = { has_leader_flag = ICE_MOON_ELF_leader_can_not_dismiss_working }
	}
}


###	can_country_change_councilors
###	should_count_towards_leader_cap
###	can_country_connect_to_relay_network
###	should_ai_build_stronghold_on_vulnerable_colony
###	will_leader_retire
###	will_leader_survive
###	can_get_external_leader_pool_candidate


###	领袖交易	########################################################################
#	V/AUP/GF/sxx/MECR
##	FW
# This = leader, leader we'd like to trade
# Root = country, country that owns the leader currently
# From = country, country that would receive the leader
can_trade_leader = {
	##_|mod特殊|	FW/sxx
	hidden_trigger = {
		NOR = {
			FW_trgr_ldr_SP = yes	# |FW特殊领袖|
			is_variable_set = sxx_leader_state	# sxx
		}
	}

	##_|特殊任务|	+MECR/GF/AUP
	# The leader must have a trait from a specialist subject type.
	this = {
		OR = {
			has_specialist_subject_leader_trait = yes
			has_specialist_subject_leader_trait_maid = yes	# MECR
			GF_can_trade_robotic_leader = yes	# GF
		}
		is_councilor = no
		is_heir = no
		#	AUP
		is_ruler = no
		NOT = { has_leader_flag = legendary_leader }
	}
	##_|战术算法|
	OR = {
		AND = { # Either from subject to Overlord
			ROOT = {
				is_subject = yes
			}
			FROM = {
				is_overlord_to = ROOT
			}
		}
		AND = { # Or from a tactical cogitator empire to a NON tactical cogitator empire
			ROOT = { has_valid_civic = civic_machine_tactical_algorithms }
			FROM = {
				NOT = { has_valid_civic = civic_machine_tactical_algorithms }
				is_fallen_empire = no
				NOT = {
					any_owned_leader = {
						has_trait = leader_trait_tactical_algorithms
					}
				}
			}
		}
	}
	##_|同类政体|
	# The subject and overlord must both be regular empires, machine intelligences or hive-minds.
	OR = {
		AND = {
			ROOT = {
				is_regular_empire = yes
			}
			FROM = {
				is_regular_empire = yes
			}
		}
		AND = {
			ROOT = {
				has_authority = auth_machine_intelligence
			}
			FROM = {
				has_authority = auth_machine_intelligence
			}
		}
		AND = {
			ROOT = {
				has_authority = auth_hive_mind
			}
			FROM = {
				has_authority = auth_hive_mind
			}
		}
		AND = { # Tactical Cogitator option
			ROOT = {
				has_valid_civic = civic_machine_tactical_algorithms
			}
			FROM = {
				OR = {
					is_regular_empire = yes
					has_authority = auth_hive_mind
					has_authority = auth_machine_intelligence
				}
				NOT = { has_country_flag = no_murdering_tactical_leaders }
				NOT = {
					any_owned_leader = {
						has_trait = leader_trait_tactical_algorithms
					}
				}
			}
		}
	}
	##	|国家类型|
	# The overlord can't be a fallen or awakened empire.
	ROOT = {
		NAND = {
			is_overlord = yes
			OR = {
				is_country_type = fallen_empire
				is_country_type = awakened_fallen_empire
			}
		}
	}
	NOR = { 
		has_trait = leader_trait_fotd_scientist
		has_trait = leader_trait_fotd_commander
	}
}

###	can_trade_fleet
###	can_leader_be_ruler
###	can_leader_be_councilor

###_|UGRC灵能国家|	########################################################################
#	V/kuatP/AUP/cgelf
is_country_psionic = {
	#is_psionic = yes
	is_variable_set = UGRC_var_cntr_RULE_is_country_psionic
}

###_|UGRC灵能物种|	########################################################################
#	V/AUP
# this = species
is_psionic_species = {
	#has_psionic_species_trait = yes
	has_species_flag = UGRC_flg_spcs_RULE_is_psionic_species
}

###	chance_for_external_leader_pool
###	council_agenda_early_activation_cost
###	building_automation_unemployment_threshold
###	building_automation_civilians_threshold
###	shroud_delve_cooldown_days
###	count_shroud_worlds_to_display
###	leader_election_elect_cost
###	emergency_election_cost_rule
###	leader_election_support_cost
###	leader_election_weight
###	are_pre_ftls_unaware

###_|地改候选|
###	is_terraforming_candidate
###	has_ascension_for_terraforming_candidate

###	can_be_renamed_by

###_|空间站建设许可|
###	can_build_station_around
###	can_build_mining_station_around
###	can_build_research_station_around
###	can_build_observation_station_around
###	can_build_starbase_around

###	has_inworld_capital
###	has_relative_economy_power
###	can_trade_sensor
###	can_trade_favor
###	can_interact_with_astral_rift	# 优化价值不高,以最高代价,最多提升42%
###	can_explore_astral_rift
###	can_leader_explore_astral_rift

###	can_ai_assign_governor
###	should_ai_support_galactic_empire
###	should_ai_undermine_galactic_empire

###	can_country_initiate_storm
###	can_initiate_storm_on_planet
###	can_force_see_fleets_in_system
###	has_breached_shroud_storm

###	is_science_fleet_gravity_snare_on_cooldown


###_|UGRC捕捉|	########################################################################	面向野怪舰队
#	V/kuatP/AUP/Atlan
# THIS = Fleet
# FROM = Country / Snare sender
can_fleet_be_captured_by_snares = {
	custom_tooltip = {
		fail_text = "FLEETORDER_GRAVITY_SNARE_NO_COMMUNICATIONS"
		exists = from
		exists = owner
		from = {
			has_communications = root.owner
		}
	}
	custom_tooltip = {
		fail_text = "FLEETORDER_MUST_BE_SPACE_CRITTER"
		exists = owner
		#owner = {
		#	OR = {
		#		is_capturable_space_critter_country_type = yes
		#		is_country_type = grave_guardian
		#		is_country_type = lured_fauna_faction
		#	}
		#	is_guardian_country = no
		#}
		#any_owned_ship = {
		#	is_space_fauna = yes
		#}
		#	UGRC优化
		owner = { is_variable_set = UGRC_var_cntr_RULE_can_fleet_be_captured_by_snares }
		NOT = { has_fleet_flag = UGRC_flg_flt_RULE_can_fleet_be_captured_by_snares_DISABLED }
	}

	##	Atlan
	custom_tooltip = {
		fail_text = "ATLANTEANS_ORANOS_FAUNA_BLOCKED"
		from? = { atlanteans_is_oranos_worshipper = no }
	}
}


###	can_fauna_grow
###	can_use_exhibits
###	can_access_vivarium
###	can_scavenge_and_research_debris
###	can_scavenge_debris
###	can_explore_rifts_outside_borders
###	can_lock_bypass


###	境外挖坟	########################################################################
#	V/kuat/ECC/AUP/cgelf
#	FW
# this = country
# from = location (galactic_object)
can_excavate_outside_borders = {
	exists = this
	exists = from
	#	+ECC/cgelf
	OR = {
		has_tradition = tr_archivism_frontier_archaeology
		is_nomadic = yes
		#	ECC
		NOT = { has_technology = "tech_starbase_1" }
		#	cgelf
		ELF_can_excavate_outside_borders_rules = yes	#自挖
		#	FW|作弊
		is_variable_set = FW_var_cntr_CHT_dig_outside_border
	}
	#	+cgelf
	OR = {
		from = { # regular case
			solar_system = { NOT = { exists = owner } }
		}
		AND = { # Nomadic with Research Agreement
			OR = {
				AND = {
					is_ai = no
					from = { solar_system = { exists = owner } }
				}
				from.solar_system.owner? = { # AI nomads will only poach sites from other AI empires
					is_ai = yes
				}
			}
			is_nomadic = yes
			has_research_agreement = from.solar_system.owner
		}
		# Nomadic empire with Archivism - will upset the system owner
		AND = {
			is_ai = no
			from = {
				solar_system = { exists = owner }
			}
			is_nomadic = yes
			has_tradition = tr_archivism_frontier_archaeology
		}
		#	cgelf
		ELF_can_excavate_outside_borders_rules = yes
		#	FW|作弊
		is_variable_set = FW_var_cntr_CHT_dig_outside_border
	}

	#	kuat
	from = {
		solar_system = {
			NOR = { 
				#exists = owner 
				has_star_flag = myst_system_1
				has_star_flag = myst_system_2
				has_star_flag = myst_system_3
				has_star_flag = myst_system_4
				has_star_flag = myst_system_5
				has_star_flag = myst_system_6
				has_star_flag = myst_system_7
				kuat_is_kuat_system = yes
			} 
		} 
	}
}


###_|UGRC虚空虫轰炸|	########################################################################
#	V/AUP
# this = country
can_voidworms_bombard_country = {
	is_variable_set = UGRC_var_cntr_RULE_can_voidworms_bombard_country	#UGRC优化
	#hidden_trigger = {
	#	exists = event_target:voidworms_country
	#	exists = this
	#}
	#OR = {
	#	is_country_type = default
	#	is_country_type = primitive
	#}
	## During crisis, they should bombard no matter what, otherwise check tech and max voidworms
	#if = {
	#	limit = {
	#		event_target:voidworms_country = {
	#			is_country_type = voidworms_crisis
	#		}
	#	}
	#	always = yes
	#}
	#else = {
	#	NOT = { has_technology = tech_voidworm_immunity }
	#	event_target:voidworms_country = {
	#		check_variable_arithmetic = {
	#			which = value:voidworm_ships_owned
	#			value < value:voidworm_maximum_population
	#		}
	#	}
	#}
}

###	can_use_mutations
###	can_use_artificial_breeding
###	can_trade_specimens
###	force_create_default_ship_design
###	is_organic_leader
###	is_seeded
###	is_organic_pop_group
###	empire_diplomacy_leads_to_shroud
###	can_capture_ship
###	is_planetary_ascension_free
###	count_as_split_fallen_empire
###	should_colonize_use_terraform
###	are_all_leaders_forced_immortal
###	can_be_sent_to_war
###	can_open_shroud_tab
###	can_unlock_accords
###	can_delve
###	is_delve_blocked
###	can_see_aura_intensity
###	is_hostile_to_aura_owner
###	should_reduce_aura_hostile_effect
###	should_hide_pop_group_size
###	should_hide_planet_sector_pop_amount
###	should_leader_gain_trait_every_level
###	unbidden_additional_conquer_desire
###	is_mercenary
###	is_mindwarden_exiled_first_contact
###	has_shroud_insights
###	needs_psionic_aura_insights
###	is_ending_cycle
###	has_custom_diplomacy

###	can_issue_contracts
###	can_accept_contracts
###	benefits_from_waystation_network
###	can_toggle_encampment
###	is_star_seeker_empire
###	can_access_decisions
###	ai_will_join_wars
###	ai_will_leave_wars
###	ai_will_join_offensive_wars
###	ai_will_accept_ally
###	ai_will_accept_enemy
###	is_expelled_from
###	can_reform_government_for_free
