#	Example:
#
#	example_trigger = {
#		is_country_type = default
#		num_communications > 0
#	}
#
#
#	In a script file:
#
#	trigger = {
#		example_trigger = yes
#	}
#

#以下的SCOPE应当为SHIP

has_any_plnmg_pk_component = {
	OR = {
		has_component = PLANET_KILLER_PLNT_MULTIFUNC
		has_component = PLANET_KILLER_SYS_MULTIFUNC
		has_component = PLANET_KILLER_PLNMG_BRAIN_MERGER
		has_component = PLANET_KILLER_PLNMG_MIND_INTEGRATOR
		has_component = PLANET_KILLER_PLNMG_BRAIN_VANILLA
		has_component = PLANET_KILLER_PLNMG_MIND_VANILLA
	}
}

# is_plnmg_colossus_equivalent = { #is_ship_able2kill_plnmg_maginot
# 	optimize_memory
# 	OR = {
# 		is_ship_size = colossus
# 		is_ship_size = star_eater
# 		is_ship_size = toxic_god
# 		is_ship_size = synth_queen_titan
# 		is_ship_size = behemoth_03
# 		is_ship_size = behemoth_04
# 		if = { #多彩
# 			limit = { has_global_flag = love_between_us }
# 			or = {
# 				is_ship_size = TEN_Final_Core
# 				is_ship_size = tencrisis_park
# 			}
# 		}
# 		if = { #舰R
# 			limit = { has_global_flag = has_wsg_mod }
# 			or = {
# 				is_ship_size = graygoo_mothership #原版有这船，但没有W槽
# 				is_ship_size = SRA_SOGZ_UF
# 				is_ship_size = uf_glory_o
# 				is_ship_size = uf_star_eater
# 				is_ship_size = wg_boss_space_dragon_Yukikaze
# 				is_ship_size = star_eater_wg
# 				is_ship_size = wsg_lady_warship_imdesignable
# 				is_ship_size = planetary_ship_1
# 				is_ship_size = uf_navigator
# 				is_ship_size = uf_navigator_2
# 				is_ship_size = star_eater_uf
# 			}
# 		}
# 		if = {
# 			limit = { KZ_VOY_MOD = yes }
# 			or = {
# 				is_ship_size = KZ_VOY_battlestar_tier_1
# 				is_ship_size = KZ_VOY_battlestar_tier_2
# 				is_ship_size = KZ_VOY_battlestar_tier_3
# 				is_ship_size = KZ_VOY_rhodes_island_ark
# 			}
# 		}
# 		if = {
# 			limit = { has_global_flag = AOW_installed }
# 			is_ship_size = planetary_ship_1
# 		}
# 		if = {
# 			limit = { has_gigastructures = yes }
# 			or = {
# 				#is_ship_size = reshaper
# 				is_ship_size = giga_aeternum_colossus
# 				is_ship_size = giga_blokkat_harvester
# 				is_ship_size = giga_blokkat_individual
# 				is_ship_size = giga_systemcraft
# 			}
# 		}
# 		if = {
# 			limit = { has_global_flag = acot_activated }
# 			or = {
# 				is_ship_size = acot_fe_colossus
# 				is_ship_size = acot_behemoth
# 				is_ship_size = acot_behemoth_2
# 				is_ship_size = acot_star_decimator
# 				#is_ship_size = precursor_colonizer #?
# 				is_ship_size = precursor_colossus
# 				is_ship_size = acot_tuborek_flagship
# 			}
# 		}
# 	}
# }

#以下的SCOPE应当为POP_GROUP
can_be_plnmg_abducted = {
    has_virtual_species_trait = no
    NAND = {
        has_citizenship_type = { type = citizenship_purge country = root }
        NOR = {
            has_purge_type = { type = purge_matrix country = root }
            has_purge_type = { type = purge_processing country = root }
            has_purge_type = { type = purge_labor_camps country = root }
            has_purge_type = { type = purge_necrophage country = root }
            has_purge_type = { type = purge_cosmogenesis_lathe_resettle country = root }
        }
    }
}

#以下的SCOPE应当为MEGASTRUCTURE
is_plnmg_aeg_complete_supportive_mega = {
	or = {
		#is_megastructure_type = planetmega_colossus_assistant_1
		is_megastructure_type = planetmega_colossus_assistant_2
		is_megastructure_type = planetmega_colossus_assistant_restored
	}
}

#以下的SCOPE应当为PLANET

can_be_plnmg_fire_tested = { #should occur bug if targeting at special planets about event chain or project, so do not use it for now
	is_colony = no
	is_star = no
	is_asteroid = no
	is_astral_scar = no
	has_anomaly = no
	not = { is_planet_class = pc_cosmogenesis_world }
}

is_plnmg_common_planet = {
	or = {
		is_ideal = no
		if = {
			limit = { exists = owner }
			owner = { not = { any_owned_colony = { is_ideal = no } } }
		}
	}
	or = {
		is_artificial = no
		if = {
			limit = { exists = owner }
			owner = { not = { any_owned_colony = { is_artificial = no } } }
		}
	}
	hidden_trigger = {
		is_astral_scar = no
		is_asteroid = no
		is_star = no
		has_anomaly = no
	}
}

can_destroy_colony_general = {
	is_colony = yes
	#pop_amount > 0
	#not = { has_anomaly = yes }
	hidden_trigger = { exists = owner }
	or = {
		custom_tooltip = {
			fail_text = plnmg_not_our_colony
			owner = { is_same_value = from.owner }
		}
		custom_tooltip = {
			fail_text = is_not_hostile
			owner = { is_hostile = from.owner }
		}
		custom_tooltip = {
			fail_text = plnmg_not_subject
			owner = { has_overlord = from.owner }
		}
		if = {
			limit = { hidden_trigger = { owner = { is_country_type = primitive } } }
			and = {
				custom_tooltip = {
					fail_text = primitives_not_in_borders
					space_owner? = {
						or = {
							is_same_value = from.owner
							has_overlord = from.owner
						}
					}
				}
				custom_tooltip = {
					fail_text = primitives_not_full_interference
					from.owner = { has_policy_flag = interference_aggressive }
				}
			}
		}
	}
}

is_plnmg_common_star = {
	optimize_memory
	OR = {
		#O>B>A>F>G>K>M, hyper>super>giant>主序
		is_planet_class_pc_o_star = yes
		is_planet_class_pc_o_super_star = yes
		is_planet_class_pc_o_hyper_star = yes
		is_planet_class_pc_b_star = yes
		is_planet_class_pc_b_super_star = yes
		is_planet_class_pc_a_star = yes
		is_planet_class_pc_a_super_star = yes
		is_planet_class_pc_f_star = yes
		is_planet_class_pc_f_super_star = yes
		is_planet_class_pc_g_star = yes
		is_planet_class_pc_g_giant_star = yes
		is_planet_class_pc_g_super_star = yes
		is_planet_class_pc_k_star = yes
		is_planet_class_pc_k_giant_star = yes
		is_planet_class_pc_k_super_star = yes
		is_planet_class_pc_m_star = yes
		is_planet_class_pc_m_giant_star = yes
		is_planet_class_pc_m_super_star = yes
		is_planet_class_pc_m_hyper_star = yes
		is_planet_class_pc_l_star = yes #L型褐矮星
		#is_planet_class_pc_t_star = yes #T型褐矮星
		is_planet_class_pc_c_giant_star = yes #红恒星
		is_planet_class_pc_s_giant_star = yes #钴恒星
	}
}

#以下的SCOPE应当为SYSTEM

is_plnmg_single_common_star_system = {
	optimize_memory
	OR = {
		#O>B>A>F>G>K>M>T, hyper>super>giant>主序
		is_star_class_sc_o = yes
		is_star_class_sc_o_super = yes
		is_star_class_sc_o_hyper = yes
		is_star_class_sc_b = yes
		is_star_class_sc_b_super = yes
		is_star_class_sc_a = yes
		is_star_class_sc_a_super = yes
		is_star_class_sc_f = yes
		is_star_class_sc_f_super = yes
		is_star_class_sc_g = yes
		is_star_class_sc_g_giant = yes
		is_star_class_sc_g_super = yes
		is_star_class_sc_k = yes
		is_star_class_sc_k_giant = yes
		is_star_class_sc_k_super = yes
		is_star_class_sc_m = yes
		is_star_class_sc_m_giant = yes
		is_star_class_sc_m_super = yes
		is_star_class_sc_m_hyper = yes
		is_star_class_sc_l = yes #L型褐矮星
		# is_star_class_sc_t = yes #T型褐矮星
		is_star_class_sc_c_giant = yes #红恒星
		is_star_class_sc_s_giant = yes #钴恒星
	}
}

#以下的SCOPE应当为COUNTRY

has_plnmg_hakkou_ichiu = {
    any_owned_colony = {
        or = {
            has_deposit = d_hakkou_ichiu_tower
            has_carrier_flag = planet_has_hakkou_ichiu_tower
        }
    }
}

has_any_plnmg_aeg_supportive_structure = {
	check_modifier_value = { modifier = planetmega_aeg_support_base value > 0 }
	# or = {
	# 	any_owned_colony = { has_deposit = d_plnmg_colossus_assist }
	# 	count_starbase_buildings = {
	# 		type = colossus_assist_orbital_accessory
	# 		count > 0
	# 		include_being_constructed = no
	# 	}
	# 	has_megastructure = planetmega_colossus_assistant_1
	# 	has_megastructure = planetmega_colossus_assistant_2
	# 	has_megastructure = planetmega_colossus_assistant_restored
	# }
}

#巨像trigger，SCOPE应当为PLANET
can_destroy_planet_with_PLANET_KILLER_PLNT_MULTIFUNC = {
	is_asteroid = no
	is_astral_scar = no
	is_star = no
	not = { is_planet_class = pc_gas_giant }
	#not = { is_planet_class = pc_cosmogenesis_world }
}

can_destroy_planet_with_PLANET_KILLER_SYS_MULTIFUNC = {
	is_star = yes
}

can_destroy_planet_with_PLANET_KILLER_PLNMG_MIND_INTEGRATOR = {
	can_destroy_colony_general = yes
	not = { is_planet_class = pc_cosmogenesis_world }
	# weapon restrictions
	hidden_trigger = {
		from = {
			any_controlled_ship = { has_component = PLANET_KILLER_PLNMG_MIND_INTEGRATOR }
			not = {
				any_controlled_ship = {
					or = {
						has_component = PLANET_KILLER_PLNMG_BRAIN_MERGER
						has_component = PLANET_KILLER_PLNMG_MIND_VANILLA
						has_component = PLANET_KILLER_PLNMG_BRAIN_VANILLA
					}
				}
			}
		}
	}
}

can_destroy_planet_with_PLANET_KILLER_PLNMG_MIND_VANILLA = {
	can_destroy_colony_general = yes
	not = { is_planet_class = pc_cosmogenesis_world }
	hidden_trigger = {
		from = {
			any_controlled_ship = { has_component = PLANET_KILLER_PLNMG_MIND_VANILLA }
			not = {
				any_controlled_ship = {
					or = {
						has_component = PLANET_KILLER_PLNMG_BRAIN_VANILLA
						has_component = PLANET_KILLER_PLNMG_MIND_INTEGRATOR
						has_component = PLANET_KILLER_PLNMG_BRAIN_MERGER
					}
				}
			}
		}
	}
}

can_destroy_planet_with_PLANET_KILLER_PLNMG_BRAIN_MERGER = {
	can_destroy_colony_general = yes
	not = { is_planet_class = pc_cosmogenesis_world }
	hidden_trigger = {
		from = {
			any_controlled_ship = { has_component = PLANET_KILLER_PLNMG_BRAIN_MERGER }
			not = {
				any_controlled_ship = {
					or = {
						has_component = PLANET_KILLER_PLNMG_BRAIN_VANILLA
						has_component = PLANET_KILLER_PLNMG_MIND_INTEGRATOR
						has_component = PLANET_KILLER_PLNMG_MIND_VANILLA
					}
				}
			}
		}
	}
}

can_destroy_planet_with_PLANET_KILLER_PLNMG_BRAIN_VANILLA = {
	can_destroy_colony_general = yes
	not = { is_planet_class = pc_cosmogenesis_world }
	hidden_trigger = {
		from = {
			any_controlled_ship = { has_component = PLANET_KILLER_PLNMG_BRAIN_VANILLA }
			not = {
				any_controlled_ship = {
					or = {
						has_component = PLANET_KILLER_PLNMG_BRAIN_MERGER
						has_component = PLANET_KILLER_PLNMG_MIND_INTEGRATOR
						has_component = PLANET_KILLER_PLNMG_MIND_VANILLA
					}
				}
			}
		}
	}
}

### for button_effects ###

can_be_destroyed_with_any_plnmg_itss_ptt = {
	exists = solar_system
}
can_be_destroyed_with_any_plnmg_itss_allow = {
	custom_tooltip = {
		fail_text = not_any_plnmg_itss_fire_launcher
		exists = event_target:fire_launcher_of_@from
	}
}

is_plnmg_itss_weapon4plnt_ptt = {
	from = { check_variable = { which = plnmg_itss_selection_index value = 1 } }
	#effect set_variable = { which = plnmg_itss_selection_index value = 1 }
}
is_plnmg_itss_weapon4plnt_allow = {
	custom_tooltip = {
		fail_text = is_not_a_standard_planet
		is_scope_type = planet
	}
	custom_tooltip = {
		fail_text = cannot_be_any_plnmg_itss_weapon_enabled
		plnmg_itss_plnt_weapon_enabled_if_any = no
	}
}

is_plnmg_itss_weapon4star_ptt = {
	from = { check_variable = { which = plnmg_itss_selection_index value = 2 } }
	#effect set_variable = { which = plnmg_itss_selection_index value = 2 }
}
is_plnmg_itss_weapon4star_allow = {
	custom_tooltip = BLANK_STRING
	custom_tooltip = {
		fail_text = PLANET_IS_NOT_PRIMARY_STAR
		is_scope_type = planet
		is_primary_star = yes
	}
	custom_tooltip = {
		fail_text = cannot_be_any_plnmg_itss_weapon_enabled
		plnmg_itss_plnt_weapon_enabled_if_any = no
	}
}

is_plnmg_itss_weapon4others_ptt = {
	from = { check_variable = { which = plnmg_itss_selection_index value = 3 } }
}

plnmg_itss_plnt_weapon_enabled_if_any = {
	optimize_memory
	or = {
		has_planet_flag = plnmg_itss_PLANET_KILLER_CRACKER_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_SHIELDER_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_NEUTRON_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_GODRAY_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_NANOBOTS_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_DELUGE_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_TOXIFIER_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_DEVOLUTION_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_MAW_AEG_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_SMELTER_of_@from
		###
		has_planet_flag = plnmg_itss_PLANET_KILLER_STAR_CRACKER_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_STAR_CRACKER_LITE_PLNMG_of_@from
		has_planet_flag = plnmg_itss_PLANET_KILLER_PLNMG_STAR_OSCILLATOR_of_@from
	}
}
plnmg_itss_mega_weapon_enabled_if_any = {
	optimize_memory
	or = {
		#
	}
}
plnmg_itss_fleet_weapon_enabled_if_any = {
	optimize_memory
	or = {
		#
	}
}
