###	UGRC标签EFT

#	UGRC安装自检/UGRC开局DB
#	UGRC轨道维修标签DB		---UGRC修理|若pdx修复轨道维修的优化问题,禁用|
#	UGRC星系标签DB
#	UGRC国家标签DB
#	UGRC全局人口标签DB	/UGRC物种标签DB/UGRC人口标签DB




###	UGRC安装自检	################################################################################################################################################################
#_evt	<ugrc开局>
#_eft	<FW_MOD安装自检>
UGRC_eft_npc0_INSTALL_DB = {
	set_global_flag = UGRC_installed
}

###	UGRC开局DB	####################################################################################################
#_evt	<ugrc开局框架>
UGRC_eft_glbl_START = {}





###	UGRC轨道维修标签DB	################################################################################################################################################################
#_evt	<ugrc开局框架/ugrc开局延时	/ugrc读档框架	/ugrc年检框架	/ugrc接战修船检测/ugrc星基失效循环	/ugrc巨构建设>
##_list		星基/巨构
##_问题spot		如果出现<舰队入轨>将本|维修轨道|DB变成|无维修轨道|,会不会造成舰队指令卡主的问题?
UGRC_eft_mix_RULE_can_orbitable_repair_ships_DB = {
	optimize_memory	#内存

	##	|星基|	+ZOFE/ACOT/AOT/Aliliy/ECC/Giga
	if = {
		limit = { is_scope_type = starbase
			NOT = { has_starbase_flag = UGRC_flg_sb_RULE_can_orbitable_repair_ships_CD }
			fleet = { is_disabled = no }	# 未失效
		}
		starbase? = {
			#	设置触发CD
			set_timed_starbase_flag = { flag = UGRC_flg_sb_RULE_can_orbitable_repair_ships_CD days = 7 }
			#	添加
			if = {
				limit = {
					OR = {
						has_starbase_size >= starbase_starport
						has_starbase_size >= starbase_deep_space_citadel_1
						has_starbase_size = juggernaut
						has_starbase_size = enclave_mercenary_station
						is_arkship_starbase = yes
						has_starbase_module = waystation_repair_bay
						#	ZOFE
						has_starbase_size = fe_goliath
						#	ACOT
						is_acot_advanced_starbase = yes
						#	AOT
						is_ascended_juggernaut = yes
						is_deep_space_enigmatic_fortress = yes
						#	Aliliy
						has_starbase_size = lily_super_college_ship
						has_starbase_size = lily_college_ship
						#	ECC
						has_starbase_size = enclave_pirate_mercenary_station
					}
				}
				#	|UGRC维修轨道|添加
				set_variable = { which = UGRC_var_all_RULE_can_orbitable_repair_ships value = 1 }
			}
			#	清除
			else_if = { limit = { is_variable_set = UGRC_var_all_RULE_can_orbitable_repair_ships }
				clear_variable = UGRC_var_all_RULE_can_orbitable_repair_ships
			}
		}
	}
	##	|巨构|	+ACOT/Giga
	else_if = {
		limit = { is_scope_type = megastructure
			NOT = { has_megastructure_flag = UGRC_flg_mega_RULE_can_orbitable_repair_ships_CD }
		}
		#	设置触发CD
		set_timed_megastructure_flag = { flag = UGRC_flg_mega_RULE_can_orbitable_repair_ships_CD days = 7 }
		#	添加
		if = {
			limit = {
				OR = {
					is_megastructure_type = mega_shipyard_1
					is_megastructure_type = mega_shipyard_2
					is_megastructure_type = mega_shipyard_3
					#	ACOT
					is_megastructure_type = acot_precursor_colossus_base
					is_megastructure_type = acot_precursor_colossus_stage_two
					is_megastructure_type = acot_amerigo
					is_megastructure_type = acot_amerigo_ae
					is_megastructure_type = acot_amerigo_se
					is_megastructure_type = acot_amerigo_oe
					is_megastructure_type = acot_phanon_master_reactor_sphere
					#	Giga
					is_megastructure_type = the_vat_1
					is_megastructure_type = the_vat_2
					is_megastructure_type = the_vat_3
					is_megastructure_type = the_vat_4
				}
			}
			#	|UGRC维修轨道|添加
			set_variable = { which = UGRC_var_all_RULE_can_orbitable_repair_ships value = 1 }
		}
		#	清除
		else_if = { limit = { is_variable_set = UGRC_var_all_RULE_can_orbitable_repair_ships }
			clear_variable = UGRC_var_all_RULE_can_orbitable_repair_ships
		}
	}
}




###	UGRC星系标签DB	################################################################################################################################################################
#_evt	<ugrc开局框架/ugrc开局延时	/ugrc读档框架	/ugrc年检框架>
#_evt	<ugrc星系月检>
#_list	UGRC跃迁星系	/UGRC传感器/UGRC星系管制	/UGRC星系提示
#_国家	PC/普通帝国/
UGRC_eft_sstm_RULE_flg_DB = {
	optimize_memory	#内存

	##	UGRC跃迁星系	########################################	|can_enter_system_by_jump_trigger|
	#	ACOT/seooc/wsg/kuat/cglbu/cgelf/Alily/arkn/spth/kzvoy/dsc
	if = {
		limit = {
			OR = {
				#	ACOT
				has_star_flag = phanon_home_base
				any_neighbor_system = { has_star_flag = phanon_home_base }
				has_star_flag = outercluster
				#	seooc
				has_star_flag = nep_Krahen_cluster
				has_star_flag = nep_Scrus_cluster
				has_star_flag = nep_arena
				AND = {
					has_global_flag = nep_not_pass_Aemethms 
					OR = {
						has_star_flag = nep_dragon_system
						has_star_flag = nep_heptagram_cluster
					}
				}
				##	wsg
				has_star_flag = wg_sealed_system
				has_star_flag = wg_psionic_systems
				#	kuat
				has_star_flag = ag_no_jump_in_system
				has_star_flag = kuat_initial_system
				has_star_flag = Kuat_empire_system
				has_star_flag = ag_kae_e_area_system
				#	cglbu
				AND = { has_global_flag = love_between_us	# |安装|
					OR = {
						has_star_flag = ten_crisis_system
						any_neighbor_system = { has_star_flag = ten_crisis_system }
						exists = event_target:holylight_god_heaven_empire 
						OR = {
							has_star_flag = SUC_lustgod_ring_world_system
							has_star_flag = init_sample_of_death
							has_star_flag = init_sample_of_prosperity
							has_star_flag = init_INN_holylight_god_system2
						}
					}
				}
				#	cgelf
				has_star_flag = ELF_Singularity_System
				has_star_flag = wtmnb_star_11th		# wtmnb
				#	Alily
				has_star_flag = al_huge_home_bed
				#	arkn
				has_star_flag = ark_isolated
				#	spth
				has_star_flag = spth_no_jump_in_system
				#	kzvoy
				has_star_flag = KZ_VOY_system_blocks_jump	# 同步追踪|kzvoy	scripted_triggers	|KZ_VOY_can_enter_system_by_jump|
				#	dsc
				has_star_flag = DSC_NOT_allow_enter_system_by_jump	# 简化了,禁止<any_system_planet>
			}
		}
		set_star_flag = UGRC_flg_sstm_RULE_jump_block
	}
	else_if = { limit = { has_star_flag = UGRC_flg_sstm_RULE_jump_block }
		remove_star_flag = UGRC_flg_sstm_RULE_jump_block
	}


	##	UGRC传感器	########################################	|国家指向|	他国阻碍	/简单阻碍/Sexp阻碍/vanilla阻碍	/自我穿透
	#	INIT		=阻碍flg归零, 他应当是	sstm_flg@cntr
	if = { limit = { has_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET }
		remove_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
		every_country = {
			limit = { prev = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev } }
			prev = { remove_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev }
		}
	}
	##	他国阻碍	+AAR/S_tnatc
	if = {
		limit = { exists = space_owner
			space_owner = {
				OR = {
					has_country_flag = AAR_flg_cntr_MIST	# AAR
					has_relic = r_invisibility_rune		# S_tnatc
				}
			}
		}
		every_country = {
			limit = {
				OR = { is_ai = no		is_country_type = default }
				NOT = { is_same_value = prev.space_owner }
			}
			prev = {
				set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
				set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
			}
		}
	}
	##	简单阻碍
	if = {
		limit = {
			OR = {
				#	UGRC
				check_modifier_value = { modifier = UGRC_smod_sstm_RULE_block_sensor	value > 0 }

				#	WS
				is_ws_system = yes
				#	wsg
				has_star_flag = wg_sealed_system
				has_star_flag = wg_psionic_systems
				#	kuatAG
				has_star_flag = ag_no_sensor_system
				#	SMCO
				has_star_flag = bok_globules
				has_star_flag = star_flag_GAPS_sealed_system
				#	Alily
				has_star_flag = Uberzain
				#	thl
				has_modifier = tengu_storm
				has_modifier = bat_swarm
				has_modifier = red_fog
				#	spth
				check_modifier_value = { modifier = touhou_system_block_sensor	value > 0 }
			}
		}
		every_country = {
			limit = { OR = { is_ai = no		is_country_type = default } }
			prev = {
				set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
				set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
			}
		}
	}
	##	IFE阻碍
	else_if = {
		limit = {
			space_owner? = {
				has_relic = r_scfe_invisibility_rune
				has_modifier = scfe_invisibility_rune
			}
		}
		every_country = {
			limit = {
				OR = { is_ai = no		is_country_type = default }
				NOT = { is_same_empire = prev.space_owner }	#
				NOR = {
					prev = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev }
					has_country_flag = UGRC_flg_cntr_RULE_blocks_sensors_NEBULA_ignore
				}
			}
			prev = {
				set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
				set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
			}
		}
	}
	##	Sexp阻碍
	else_if = {
		limit = { has_global_flag = ariphaos_sensors_installed }
		#	vanilla|星云|
		if = {
			limit = {
				OR = {
					is_inside_nebula = yes
					is_star_class = sc_collapsar	# RS
					is_star_class = sc_p_purple
					is_star_class = sc_p_green
					is_star_class = sc_p_red
				}
			}
			every_country = {
				limit = {
					OR = { is_ai = no		is_country_type = default }
					NOR = {
						has_technology = tech_ariphaos_sensors_nebula
						has_country_flag = UGRC_flg_cntr_RULE_blocks_sensors_NEBULA_ignore
					}
				}
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
		#	vanilla|风暴|
		if = {
			limit = {
				OR = {
					has_modifier = space_storm
					has_modifier = zroni_storm
					has_modifier = queen_scorn_storm
					has_star_flag = storm_system
				}
			}
			every_country = {
				limit = {
					OR = { is_ai = no		is_country_type = default }
					NOR = {
						has_technology = tech_ariphaos_sensors_storm
						has_country_flag = UGRC_flg_cntr_RULE_blocks_sensors_NEBULA_ignore
					}
				}
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
		#	vanilla|封印星系|
		if = {
			limit = {
				OR = {
					has_star_flag = lcluster
					has_star_flag = sealed_system
				}
			}
			every_country = {
				limit = {
					OR = { is_ai = no		is_country_type = default }
					NOR = {
						has_technology = tech_ariphaos_sensors_sealed
						prev = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev }
					}
				}
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
		#	|虫洞|
		if = {
			limit = { has_natural_wormhole = yes }
			every_country = {
				limit = {
					OR = { is_ai = no		is_country_type = default }
					NOR = {
						has_technology = tech_ariphaos_sensors_wormhole
						prev = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev }
					}
				}
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
		#	|星际基地|
		if = {
			limit = { starbase? = { has_starbase_building = ariphaos_sensors_jammer_starbase } }
			every_country = {
				limit = {
					OR = { is_ai = no		is_country_type = default }
					NOR = {
						has_technology = tech_ariphaos_sensors_jammed
						prev = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev }
					}
				}
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
		#	|星系类型|
		if = {#中子星
			limit = {
				OR = {
					is_star_class = sc_binary_2
					is_star_class = sc_neutron_star
				}
			}
			every_country = {
				limit = {
					OR = { is_ai = no		is_country_type = default }
					NOR = {
						has_technology = tech_sensors_4
						prev = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev }
					}
				}
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
		else_if = {#脉冲星
			limit = {
				OR = {
					is_star_class = sc_binary_1
					is_star_class = sc_pulsar
				}
			}
			every_country = {
				limit = {
					OR = { is_ai = no		is_country_type = default }
					NOR = {
						has_technology = tech_ariphaos_sensors_pulsar
						prev = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev }
					}
				}
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
		else_if = {#黑洞
			limit = {
				OR = {
					is_star_class = sc_black_hole
				}
			}
			every_country = {
				limit = {
					OR = { is_ai = no		is_country_type = default }
					NOR = {
						has_technology = tech_ariphaos_sensors_black_hole
						prev = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev }
					}
				}
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
	}
	#	vanilla阻碍
	else = {
		#	封印
		if = {
			limit = {
				OR = {
					has_star_flag = lcluster
					has_star_flag = sealed_system
				}
			}
			every_country = {
				limit = { OR = { is_ai = no		is_country_type = default } }
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
		#	星云
		else_if = {
			limit = {
				OR = {
					is_inside_nebula = yes
					has_modifier = space_storm
					has_modifier = zroni_storm
					has_modifier = queen_scorn_storm
					has_star_flag = storm_system
					is_star_class = sc_collapsar	# RS
					is_star_class = sc_p_purple
					is_star_class = sc_p_green
					is_star_class = sc_p_red
				}
			}
			every_country = {
				limit = {
					OR = { is_ai = no		is_country_type = default }
					NOR = {
						prev = { has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev }
						has_country_flag = UGRC_flg_cntr_RULE_blocks_sensors_NEBULA_ignore
					}
				}
				prev = {
					set_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
					set_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@prev
				}
			}
		}
	}
	##	自我穿透		传感阻碍不会阻碍<自己>
	if = {
		limit = { exists = space_owner		has_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@space_owner }
		remove_star_flag = UGRC_flg_sstm_RULE_flg_blocks_sensors_SET
		remove_star_flag = UGRC_flg_sstm_RULE_blocks_sensors@space_owner
	}


	##	UGRC星系管制	########################################	|星系通用|	禁地	/TAC/kuatAG	/V野生保护/V神秘堡垒/V利维坦/V威胁与天灾
	#	禁地
	if = {
		limit = {
			OR = {
				has_star_flag = eawaf_faust_killzone
				AND = {
					has_star_flag = eawaf_system
					has_global_flag = giga_eawaf_sirens_guaranteed
				}
			}
		}
		set_star_flag = UGRC_flg_sstm_RESTRICT_forbidden
	}
	else_if = { limit = { has_star_flag = UGRC_flg_sstm_RESTRICT_forbidden }
		remove_star_flag = UGRC_flg_sstm_RESTRICT_forbidden
	}
	#	TAC
	if = {
		limit = {
			OR = {
				has_star_flag = AI_system1
				has_star_flag = AI_system2
				has_star_flag = AI_system3
				has_star_flag = AI_system4
			}
		}
		set_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
	}
	else_if = { limit = { has_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC }
		remove_star_flag = UGRC_flg_sstm_RESTRICT_mod_TAC
	}
	#	kuatAG
	if = {
		limit = {
			OR = {
				has_star_flag = ag_zeta_crisis_psionic_storm_system
				has_star_flag = ag_zeta_crisis_psionic_singularity_system
			}
		}
		set_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
	}
	else_if = { limit = { has_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta }
		remove_star_flag = UGRC_flg_sstm_RESTRICT_mod_AG_zeta
	}
	#	V野生保护
	if = {
		limit = {
			OR = {
				AND = { has_star_flag = crystal_home_system		any_fleet_in_system = { exists = owner		owner = { is_country_type = crystal } } }
				AND = { has_star_flag = amoeba_home_system		any_fleet_in_system = { exists = owner		owner = { is_country_type = amoeba_garrison } } }
				AND = { has_star_flag = drone_home_system		any_fleet_in_system = { exists = owner		owner = { is_country_type = drone } } }
				AND = { has_star_flag = great_wound				any_fleet_in_system = { exists = owner		owner = { is_country_type = cloud } } }
			}
		}
		set_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE
	}
	else_if = { limit = { has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE }
		remove_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_WILDLIFE
	}
	#	V神秘堡垒
	if = {
		limit = { has_star_flag = guardian		any_fleet_in_system = { exists = owner		owner = { is_country_type = guardian_fortress } } }
		set_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
	}
	else_if = { limit = { has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress }
		remove_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN_fortress
	}
	#	V利维坦
	if = {
		limit = {
			has_star_flag = guardian
			exists = owner
			OR = {
				any_fleet_in_system = { exists = owner		owner = { is_guardian_country = yes } }
				any_fleet_in_system = { exists = owner		owner = { is_country_type = sbtg_sentinel_active } }	# SBTG
			}
		}
		set_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN
	}
	else_if = { limit = { has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN }
		remove_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_GUARDIAN
	}
	#	V威胁与天灾
	if = {
		limit = {
			has_global_flag = gray_goo_crisis_active
			OR = {
				has_star_flag = lgate
				has_star_flag = lcluster
			}
		}
		set_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_CRISIS
	}
	else_if = { limit = { has_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_CRISIS }
		remove_star_flag = UGRC_flg_sstm_RESTRICT_vanilla_CRISIS
	}



	##	UGRC星系提示	########################################
	#	电弧焊机
	inline_script = { script = "system_tooltips/UGRC_eft_sstm_TRGR_arc_furnace_tooltip" }
}






###	UGRC国家标签DB	################################################################################################################################################################
#_evt	<ugrc开局框架/ugrc开局延时	/ugrc读档框架	/ugrc年检框架>
#_evt	<ugrc政府变动>
#_list	UGRC灵能国家	/UGRC幸福感/UGRC殖民地/UGRC星系管制		/UGRC自设分部/UGRC罪企	/UGRC捕捉	/UGRC虚空虫轰炸
UGRC_eft_cntr_RULE_flg_DB = {
	optimize_memory

	##	UGRC灵能国家	########################################
	if = { limit = { is_psionic = yes }
		set_country_flag = UGRC_flg_cntr_RULE_is_country_psionic
	}
	else = {
		remove_country_flag = UGRC_flg_cntr_RULE_is_country_psionic
	}

	##	UGRC幸福感		########################################	将复杂国家条件收缩为flag,减少检测消耗
	if = { limit = { pop_amount > 0 }
		##	vanilla|无情机器人|	+wv/thl
		if = {
			limit = {
				OR = {
					is_machine_empire = yes
					NOR = {
						has_technology = tech_synthetic_workers
						has_technology = tech_dummy_leaders	# wv
						has_technology = tech_sapient_dolls	# thl
					}
					has_policy_flag = ai_outlawed
				}
			}
			set_country_flag = UGRC_flg_cntr_RULE_happiness_DISABLE_robot
		}
		else = {
			remove_country_flag = UGRC_flg_cntr_RULE_happiness_DISABLE_robot
		}
		#	vanilla|无情合成人|	+ECB
		if = {
			limit = {
				OR = {
					AND = {
						has_civic = civic_machine_assimilator # Assimilator empire
						is_machine_empire = yes
					}
					AND = {
						has_country_flag = cyber_collectivist
						is_democratic_authority = yes
					}
					#	ECB
					AND = {
						has_country_flag = cyber_collectivist
						is_bugged_group_firm = yes
					}
				}
			}
			set_country_flag = UGRC_flg_cntr_RULE_happiness_DISABLE_cybernetic
		}
		else = {
			remove_country_flag = UGRC_flg_cntr_RULE_happiness_DISABLE_cybernetic
		}

		##	wv
		if = {
			limit = {
				OR = {
					NOR = { 
						has_technology = tech_synthetic_workers 
						has_technology = tech_dummy_leaders
						has_origin = origin_garbage_princesses
						has_country_flag = synthetic_empire
					} 
					has_policy_flag = ai_outlawed
				}
			}
			set_country_flag = UGRC_flg_cntr_RULE_happiness_DISABLE_dummy
		}
		else = {
			remove_country_flag = UGRC_flg_cntr_RULE_happiness_DISABLE_dummy
		}
	}

	##	UGRC殖民地		########################################
	if = { limit = { num_owned_colonies > 0 }
		every_owned_colony = {
			#	UGRC新地|is_new_colony
			set_carrier_flag = UGRC_flg_plnt_RULE_is_new_colony_NON
			if = {
				limit = {
					is_colony = yes
					is_under_colonization = no
					NOT = { has_carrier_flag = synth_queen_bastille }
					colony_age < 180
					pop_amount < 1000
				}
				remove_carrier_flag = UGRC_flg_plnt_RULE_is_new_colony_NON
			}
		}
	}

	##	UGRC星系管制	########################################
	remove_country_flag = UGRC_flg_cntr_RULE_restrict_DEFAULT
	remove_country_flag = UGRC_flg_cntr_RULE_restrict_FALLEN
	remove_country_flag = UGRC_flg_cntr_RULE_restrict_AFE
	remove_country_flag = UGRC_flg_cntr_RULE_restrict_CRISIS
	remove_country_flag = UGRC_flg_cntr_RULE_restrict_EE
	if = {#普通
		limit = {
			OR = {
				is_country_type = default
				is_country_type = default_ev	# ev
				is_country_type = ascended_empire	# ZOFE
			}
		}
		set_country_flag = UGRC_flg_cntr_RULE_restrict_DEFAULT
	}
	else_if = {#堕落
		limit = {
			OR = {
				is_country_type = fallen_empire
				is_country_type = fallen_empire_ev	# ev
				is_country_type = kuat_fallen_empire	# kuat
				is_country_type = LsE_fallen_empire	# adf
				is_country_type = lost_empire		# ZOFE
				is_country_type = al_fallen_empire	# AL
			}
		}
		set_country_flag = UGRC_flg_cntr_RULE_restrict_FALLEN
	}
	else_if = {#觉醒
		limit = {
			OR = {
				is_country_type = awakened_fallen_empire
				is_country_type = awakened_fallen_empire_ev	# ev
				is_country_type = kuat_awakened_fallen_empire	# kuat
			}
		}
		set_country_flag = UGRC_flg_cntr_RULE_restrict_AFE
	}
	else_if = {#危机
		limit = {
			is_blokkat_country_type = no	# Giga|猫块不受限制
			OR = {
				is_crisis_faction = yes
				is_country_type = sbtg_stellarborne_empire	# SBTG
			}
		}
		set_country_flag = UGRC_flg_cntr_RULE_restrict_CRISIS
	}
	else_if = {#永恒
		limit = {
			OR = {
				is_country_type = eternal_empire	# EE
				#	SBTG
				AND = { is_progenitor_empires = yes
					NOT = { is_country_type = sbtg_stellarborne_empire }
				}
			}
		}
		set_country_flag = UGRC_flg_cntr_RULE_restrict_EE
	}


	##	UGRC分部星球	########################################
	if = {
		limit = {
			pop_amount > 0
			OR = {
				#	azl
				azurlane_default_govement_trigger = yes	# 同步追踪|azl	scripted_triggers	|azurlane_default_govement_trigger|
				#	ARP
				has_authority = auth_Arp_0
				#	cglbu
				has_valid_civic = civic_master	#爱欲盛宴
			}
		}
		set_country_flag = UGRC_flg_cntr_RULE_branch_self_ENABLE
	}
	else_if = { limit = { has_country_flag = UGRC_flg_cntr_RULE_branch_self_ENABLE }
		remove_country_flag = UGRC_flg_cntr_RULE_branch_self_ENABLE
	}
	##	UGRC罪企	####################
	if = {
		limit = {
			pop_amount > 0
			OR = {
				#	wsg
				has_civic = civic_sh_criminal_syndicate
				#	ECI
				has_valid_civic = civic_underworld_society
				has_civic = civic_hive_capital_creates_gods
				has_civic = civic_machine_financial_investment
				#	ev
				has_valid_civic = civic_ev_criminal_ship
				#	hiveDLC
				has_valid_civic = civic_mutualistic_behavior
				has_valid_civic = civic_machine_trading
				#	MCA
				has_authority = auth_corporate_fiefdom
				has_authority = auth_cooperative
				#	EMB
				has_authority = auth_private
				#	精灵
				is_ELF_criminal_syndicate_rule = yes
				#	SC
				has_civic = civic_taldarim_marauder
			}
		}
		set_country_flag = UGRC_flg_cntr_RULE_criminal_syndicate
	}
	else_if = { limit = { has_country_flag = UGRC_flg_cntr_RULE_criminal_syndicate }
		remove_country_flag = UGRC_flg_cntr_RULE_criminal_syndicate
	}


	##	UGRC捕捉	########################################
	if = {
		limit = {
			num_fleets > 0
			is_guardian_country = no
			OR = {
				is_country_type = grave_guardian
				is_country_type = lured_fauna_faction
				is_capturable_space_critter_country_type = yes
			}
		}
		every_owned_fleet = {
			limit = { any_owned_ship = { is_space_fauna = yes } }
			set_timed_fleet_flag = { flag = UGRC_flg_flt_RULE_can_fleet_be_captured_by_snares	days = 360 }
		}
	}
	##	UGRC虚空虫轰炸	########################################	全部条件都可以复制
	if = {
		limit = {
			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 = {
					has_country_flag = UGRC_flg_cntr_RULE_can_voidworms_bombard_country
					check_variable_arithmetic = {
						which = value:voidworm_ships_owned
						value < value:voidworm_maximum_population
					}
				}
			}
		}
		set_timed_fleet_flag = { flag = UGRC_flg_flt_RULE_can_fleet_be_captured_by_snares	days = 360 }
	}
}






###	UGRC全局人口标签DB	################################################################################################################################################################
#_算法	首先对<全银河物种>进行检测, 然后调用检测结果对<全银河人口组>进行检测
#_evt	<ugrc开局框架/ugrc开局延时	/ugrc读档框架	/ugrc年检框架>
UGRC_eft_glbl_RULE_pop_flg_DB = {
	##	UGRC物种标签DB
	every_galaxy_species = {
		UGRC_eft_spcs_RULE_flg_DB = yes
	}

	##	UGRC人口标签DB
	#	[CD触发]含instant	=参选/犯罪/产生领袖
	if = { limit = { NOT = { has_global_flag = UGRC_flg_glbl_RULE_pop_flg_db_CD } }
		set_timed_global_flag = { flag = UGRC_flg_glbl_RULE_pop_flg_db_CD	days = 540 }
		every_country = {
			limit = { pop_amount > 0 }
			every_owned_pop_group = {
				UGRC_eft_pop_RULE_flg_DB_instant = yes	# |每年触发|
				UGRC_eft_pop_RULE_flg_DB_cd = yes	# |2年触发|
			}
		}
	}
	#	[立刻触发]	=参选/犯罪
	else = {
		every_country = {
			limit = { pop_amount > 0 }
			every_owned_pop_group = {
				UGRC_eft_pop_RULE_flg_DB_instant = yes	# |每年触发|
			}
		}
	}
}

###	UGRC物种标签DB	####################################################################################################
#_evt	<ugrc物种改良>
#_eft	<UGRC_eft_glbl_RULE_pop_flg_DB>
#_list	UGRC幸福感/UGRC可繁殖/UGRC犯罪	/UGRC产生领袖	/UGRC灵能物种
UGRC_eft_spcs_RULE_flg_DB = {
	optimize_memory	#内存

	##	|UGRC幸福感|	########################################	wsg/PTep/Eevt/无言/ECI/wv/时空
	#	INTI		幸福度归零, 后续检测是否添加幸福度
	if = { limit = { has_species_flag = UGRC_flg_spcs_RULE_happiness_SET }	# |可能存在幸福度标签|, 只要存在, 该物种一定存在某个国家的幸福度, 所以现对其归零
		remove_species_flag = UGRC_flg_spcs_RULE_happiness_SET
		every_country = {
			limit = {
				pop_amount > 0
				prev = { has_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
			}
			prev = { remove_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
		}
	}
	#	条件检测	
	if = {
		##	|基本条件|	单一物种条件, nor条件, 符合条件的默认[一定没有幸福度]
		limit = {
			NOR = {
				#	vanilla
				#has_trait = trait_hive_mind
				can_think = no

				#	wsg
				has_trait = sh_trait_shenhai
				has_trait = sh_trait_shenhai1
				has_trait = sh_trait_shenhai2
				has_trait = sh_trait_silent
				has_trait = sh_trait_silent1
				#	PTep
				has_trait = trait_plentiful_traditions_pt_cocoon
				#	Eevt
				has_trait = trait_memorex_comatos
				#	wv
				has_trait = trait_servitude
				#	cglbu
				is_species_need_happiness_dcyh = no
			}
		}
		#	所有通过|基本条件|的物种, 先默认添加所有国家的幸福度, 通过后续细致检测去除
		set_species_flag = UGRC_flg_spcs_RULE_happiness_SET	# |可能存在幸福度标签|
		every_country = { limit = { pop_amount > 0 }
			prev = { set_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
		}

		##	各mod规则中带有root的项目, 进行逐一筛选. 它们必然在一个NOR里面, 所以这里用if/else重构NOR内的并列项目. 只要符合rule写的条件, 那就去掉<物种>对<目标国家>的"幸福度"
		#	vanilla|智械|排除
		if = { limit = { has_trait = trait_machine_unit }
			every_country = {
				limit = {
					has_authority = auth_machine_intelligence
					is_bugged_happy_gestalt = no	#ECB
					prev = {
						Maid_trigger_8_species_has_happiness = yes	#MECR
						has_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev
					}
				}
				prev = { remove_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
			}
		}
		#	vanilla|蜂群|排除
		if = { limit = { has_trait = trait_hive_mind }
			every_country = {
				limit = {
					is_bugged_happy_gestalt = no	#ECB
					prev = { has_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
				}
				prev = { remove_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
			}
		}
		#	vanilla|机器人|排除
		else_if = { limit = { has_trait = trait_mechanical }
			every_country = {
				limit = {
					has_country_flag = UGRC_flg_cntr_RULE_happiness_DISABLE_robot
					prev = { has_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
				}
				prev = { remove_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
			}
		}
		#	vanilla|同化|排除
		else_if = { limit = { has_trait = trait_cybernetic }
			every_country = {
				limit = {
					has_country_flag = UGRC_flg_cntr_RULE_happiness_DISABLE_cybernetic
					prev = { has_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
				}
				prev = { remove_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
			}
		}
		#	mod|thl|排除
		if = { limit = { has_trait = trait_thl_doll }
			every_country = {
				limit = { NOT = { has_technology = tech_sapient_dolls } }
				prev = { remove_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
			}
		}
		#	mod|wv|排除
		if = { limit = { has_trait = trait_dummy }
			every_country = {
				limit = {
					has_country_flag = UGRC_flg_cntr_RULE_happiness_DISABLE_dummy
					prev = { has_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
				}
				prev = { remove_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
			}
		}
		if = { limit = { has_full_crovis_implants = yes }
			every_country = {
				limit = {
					has_policy_flag = production_emotion_deprivation
					has_policy_flag = unity_emotion_deprivation
					prev = { has_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
				}
				prev = { remove_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev }
			}
		}
	}
	##	强制幸福	无视前面的检测, 所有符合条件的<国家>强制<当前物种>拥有其"幸福度"
	every_country = {
		limit = { pop_amount > 0
			#	同步追踪|tmod	scripted_triggers	|TIME_RULE_trgr_Force_has_happiness|
			prev = { has_citizenship_type = { type = citizenship_adeptus_mechanicus	country = prev } }
		}
		prev = {
			set_species_flag = UGRC_flg_spcs_RULE_happiness_ENABLE@prev
			set_species_flag = UGRC_flg_spcs_RULE_happiness_SET
		}
	}


	##	|UGRC可繁殖|	########################################
	#	V否决条件
	if = {
		limit = {
			is_sapient = yes
			##	+mmNEW/HFE/hiveDLC/PTep/Eevt/wv
			NOR = {
				has_trait = trait_machine_unit
				has_trait = trait_mechanical
				has_trait = trait_limited_cybernetic

				##	mmNEW
				has_trait = trait_mahoshoujo
				#	HFE
				has_trait = hfe_species_trait_brainworm
				#	hiveDLC
				has_trait = trait_hive_mind_overlord
				#	PTep
				has_trait = trait_plentiful_traditions_pt_cocoon
				#	Eevt
				has_trait = trait_memorex_comatos
				#	LithS
				has_trait = trait_pearl_born_drone
				#	精灵
				ELF_species_procreate_rules = yes
			}
			NOT = { has_species_flag = nivlac_no_procreation }	# |V禁用繁殖|
		}
		remove_species_flag = UGRC_flg_spcs_RULE_procreate_DISABLE
	}
	else = {
		set_species_flag = UGRC_flg_spcs_RULE_procreate_DISABLE
	}
	##	mod|wv	+UGRC标签
	if = {
		limit = {
			OR = {
				has_trait = trait_reanimated_materials
				has_trait = trait_houki
				has_trait = trait_witch
				has_trait = trait_victorika
				has_trait = trait_elaina_descendant
			}
		}
		set_species_flag = UGRC_flg_spcs_RULE_wv
	}
	else = {
		remove_species_flag = UGRC_flg_spcs_RULE_wv
	}


	##	|UGRC犯罪|	########################################	wsg/swg/kc/adf/PTep
	if = {
		limit = {
			OR = {
				#	wsg/swg
				is_archetype = WARSHIPGIRL
				is_archetype = SHENHAI
				is_archetype = UNITED_FLEET
				is_archetype = NANITES_CROP
				has_wg_traits = yes
				has_trait = sh_trait_silent
				has_trait = trait_intelligent_galo
				#	kc
				has_trait = kancolle_trait_kanmusu
				has_trait = kancolle_trait_kanmusu1
				has_trait = kancolle_trait_kanmusu2
				#	adf
				has_trait = adf_trait_dolls
				#	PTep
				has_trait = trait_plentiful_traditions_pt_cocoon
			}
		}
		if = { limit = { NOT = { has_species_flag = UGRC_flg_species_RULE_no_crime } }
			set_species_flag = UGRC_flg_species_RULE_no_crime
		}
	}
	else_if = { limit = { has_species_flag = UGRC_flg_species_RULE_no_crime }
		remove_species_flag = UGRC_flg_species_RULE_no_crime
	}


	##	|UGRC产生领袖|物种条件	########################################	+ECB/ECI/Ereb/hiveDLC/PTep/Eevt/EMB
	if = {
		limit = {
			can_think = yes
			NOR = {
				#	ECB
				is_bugged_slave_gene = yes
				#	ECI
				has_trait = trait_flesh_components
				#	Ereb
				has_trait = trait_slave_gene
				#	PTep
				has_trait = trait_plentiful_traditions_pt_cocoon
				#	Eevt/EMB
				has_trait = trait_tree_caretaker
				has_trait = trait_infested_basic
				is_exp_tree_caretaker = yes
				has_trait = trait_presapient_docile_livestock
				#	莉莉
				has_trait = trait_AL_puffer
				#	wv
				has_trait = trait_servitude
			}
		}
		set_species_flag = UGRC_flg_spcs_RULE_can_generate_leader
	}
	else = {
		remove_species_flag = UGRC_flg_spcs_RULE_can_generate_leader
	}

	##	|UGRC灵能物种|	########################################
	if = { limit = { has_psionic_species_trait = yes }
		set_species_flag = UGRC_flg_spcs_RULE_is_psionic_species
	}
	else = {
		remove_species_flag = UGRC_flg_spcs_RULE_is_psionic_species
	}
}

###	UGRC人口标签DB	####################################################################################################
#_eft	<UGRC全局人口标签DB>
#_list	UGRC参选/UGRC犯罪
UGRC_eft_pop_RULE_flg_DB_instant = {
	optimize_memory	#内存

	##	|UGRC参选|	########################################	can_vote_in_democratic_election
	#_list	V
	if = {
		limit = {
			has_citizenship_rights = yes
			is_sapient = yes
			is_enslaved = no
			is_being_purged = no
		}
		set_pop_group_flag = UGRC_flg_pop_RULE_can_vote
	}
	else = {
		remove_pop_group_flag = UGRC_flg_pop_RULE_can_vote
	}


	##	|UGRC犯罪|	########################################	pop_generates_crime
	#_list	wsg/swg/kc/adf/PTep
	if = {
		limit = {
			exists = planet
			is_sapient = yes
			is_non_sapient_robot = no
			is_being_assimilated = no
			NOT = { species = { has_species_flag = UGRC_flg_species_RULE_no_crime } }
		}
		set_pop_group_flag = UGRC_flg_pop_RULE_generates_crime
	}
	else_if = { limit = { has_pop_group_flag = UGRC_flg_pop_RULE_generates_crime }
		remove_pop_group_flag = UGRC_flg_pop_RULE_generates_crime
	}
}
#_eft	<UGRC全局人口标签DB>
#_list	UGRC产生领袖/UGRC军事领袖
UGRC_eft_pop_RULE_flg_DB_cd = {
	optimize_memory	#内存

	##	|UGRC产生领袖|人口条件	########################################	同步追踪|V/hiveDLC/spth/AUP/ECI/wv/ECB/cglbu/EMB	scripted_triggers	|can_be_leader|		<root>替换为<owner>
	#	scopes	=<原root>改<owner>
	set_pop_group_flag = UGRC_flg_pop_RULE_can_generate_leader_DISABLED
	if = {
		limit = {
			species = { has_species_flag = UGRC_flg_spcs_RULE_can_generate_leader }	# |物种条件|通过	ECB/EMB/wv
			##	|基础条件|	+ECI
			OR = {
				has_citizenship_rights = yes
				has_citizenship_type = { type = citizenship_shroud_touched country = owner }
				#	ECI
				owner = {
					OR = {
						has_valid_civic = civic_du_contrat_social
						has_valid_civic = civic_ideal_slavery
						has_valid_civic = civic_flower_of_evil
					}
				}
			}
			##	|机器人| +spth/GF/wv
			OR = {
				is_robot_pop_group = no
				owner = {
					OR = {
						has_technology = tech_synthetic_leaders
						has_authority = auth_machine_intelligence
						is_mechanical_empire = yes
						is_individual_machine = yes
						has_country_flag = synthetic_fertility_no_bodies_left
						
						GF_allow_doll_leaders = yes	# GF
						AND = { has_authority = auth_gensokyo		prev = { has_trait = trait_th_alice_doll } }	# spth
					}
				}
			}
			##	|主物种|
			OR = {
				is_same_species = owner
				owner = {
					NAND = {
						has_origin = origin_necrophage
						has_trait = trait_necrophage
					}
				}
			}

			##	rmaid
			if = {
				limit = {
					has_global_flag = flag_rogue_maid_mod_activated
					owner = { has_civic = civic_machine_servitor }
				}
				is_same_species = owner
			}
			#	cglbu
			if = { limit = { is_species_class = PAR }
				owner? = {
					has_country_flag = parasite_mind_flag
					has_technology = tech_tentacle_coop
				}
			}
			#	hiveDLC
			NOT = { owner = { has_origin = origin_hive_overmind } }
		}
		remove_pop_group_flag = UGRC_flg_pop_RULE_can_generate_leader_DISABLED
	}


	##	|UGRC军事领袖|	########################################	
	set_pop_group_flag = UGRC_flg_pop_RULE_can_generate_military_leader_DISABLED
	if = {
		limit = {
			##	|can_be_leader|
			NOT = { has_pop_group_flag = UGRC_flg_pop_RULE_can_generate_leader_DISABLED }

			##	同步追踪|V	scripted_triggers	|can_be_military_leader|
			is_enslaved = no
			is_sapient = yes
			#	|机器人|	+GF
			OR = {
				is_robot_pop_group = no
				owner = {
					OR = {
						has_policy_flag = ai_full_rights
						has_authority = auth_machine_intelligence
						is_individual_machine = yes
						has_authority = auth_GF_paradeus	# nyto
					}
				}
			}
			OR = {
				AND = { # MIs only accept Fully Integrated leaders
					owner = { has_authority = auth_machine_intelligence }
					OR = {
						has_citizenship_type = { type = citizenship_full_machine country = owner }
						has_citizenship_type = { type = citizenship_cruise_crew country = owner }
						has_citizenship_type = { type = citizenship_shroud_touched country = root }
					}
					has_military_service_type = { type = military_service_full }
				}
				AND = { # non-MIs accept whatever
					NOT = { owner = { has_authority = auth_machine_intelligence } }
					has_military_service_type = { type = military_service_full }
				}
			}
		}
		remove_pop_group_flag = UGRC_flg_pop_RULE_can_generate_military_leader_DISABLED
	}
}

