# Check if a planet can be targetd by a planet killer weapon
# Scope:
#	this = planet being targeted
#	from = fleet
#can_destroy_planet_with_PLANET_DESTRUCTION_COMPONENT = {
#	...
#}
can_destroy_planet_with_RG_PLANET_KILLER = {
	custom_tooltip = {
		fail_text = "RG_requires_a_star_star_killer"
		NOR = {
			is_planet_class = pc_ag_void_star
			is_planet_class = pc_ag_void_planet
		}
	}
	custom_tooltip = {
		fail_text = "RG_requires_outside_border_star_killer"
		NOR = {
			AND = {
				is_inside_border = from.owner
				solar_system = {
					any_system_planet = {
						OR = {
							is_colony = yes
							is_under_colonization = yes
						}
					}
				}
			}
			AND = {
				exists = owner
				owner = {
					is_same_value = from.owner
				}
			}
		}
	}
	custom_tooltip = {
		fail_text = "RG_requires_no_pacifist_star_killer"
		from.owner = {
			NOR = {
				has_ethic = ethic_fanatic_pacifist
				has_ethic = ethic_pacifist
			}
		}
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_SMALL = {
	custom_tooltip = {
		fail_text = "RG_requires_a_star_star_killer"
		NOR = {
			is_star = yes
			is_planet_class = pc_ag_void_star
			is_planet_class = pc_ag_void_planet
		}
	}
	custom_tooltip = {
		fail_text = "RG_requires_outside_border_star_killer"
		NOR = {
			AND = {
				is_inside_border = from.owner
				solar_system = {
					any_system_planet = {
						OR = {
							is_colony = yes
							is_under_colonization = yes
						}
					}
				}
			}
			AND = {
				exists = owner
				owner = {
					is_same_value = from.owner
				}
			}
		}
	}
	custom_tooltip = {
		fail_text = "RG_requires_no_pacifist_star_killer"
		from.owner = {
			NOR = {
				has_ethic = ethic_fanatic_pacifist
				has_ethic = ethic_pacifist
			}
		}
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_SP = {
	custom_tooltip = {
		fail_text = "RG_requires_a_star_star_killer"
		NOR = {
			is_star = yes
			is_planet_class = pc_ag_void_star
			is_planet_class = pc_ag_void_planet
		}
	}
	custom_tooltip = {
		fail_text = "RG_requires_inside_border_star_killer"
		is_inside_border = from.owner
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_NANO_SP = {
	custom_tooltip = {
		fail_text = "RG_requires_a_star_star_killer"
		NOR = {
			is_star = yes
			is_planet_class = pc_ag_void_star
			is_planet_class = pc_ag_void_planet
		}
	}
	custom_tooltip = {
		fail_text = "RG_requires_inside_border_star_killer"
		is_inside_border = from.owner
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_CRACKER = {
	custom_tooltip = {
		fail_text = is_not_a_standard_planet_or_megastructure
		is_a_planet_megastructure = yes
	}
	custom_tooltip = {
		fail_text = is_shielded
		NOR = {
			is_planet_class = pc_shielded
			is_planet_class = pc_ringworld_shielded
			is_planet_class = pc_habitat_shielded
		}
	}
	custom_tooltip = {
		fail_text = fotd_cant_collossus
		NOT = { has_planet_flag = fotd_seperatist_planet@from.owner }
		exists = from.owner
		from.owner = { 
			NOT = { has_country_flag = fotd_seperatist_country@from.owner }
		}
	}
	OR = {
		custom_tooltip = {
			text = is_not_hostile_cracker
			OR = {
				AND = {
					exists = space_owner
					space_owner = {
						OR = {
							is_at_war_with = from.owner
							is_country_type = swarm
							is_country_type = extradimensional
							is_country_type = extradimensional_2
							is_country_type = extradimensional_3
							is_country_type = ai_empire
						}
					}
				}
				AND = { # colony
					exists = owner
					owner = {
						OR = {
							is_at_war_with = from.owner
							is_country_type = swarm
							is_country_type = extradimensional
							is_country_type = extradimensional_2
							is_country_type = extradimensional_3
							is_country_type = ai_empire
						}
					}
				}
			}
		}
		AND = {
			# primitive target
			custom_tooltip = {
				text = cannot_crack_pre_ftl_planet_ownership
				exists = space_owner
				exists = owner
				owner = {
					is_primitive = yes
				}
				space_owner = {
					OR = {
						is_same_value = from.owner
						is_at_war_with = from.owner
						is_country_type = swarm
						is_country_type = extradimensional
						is_country_type = extradimensional_2
						is_country_type = extradimensional_3
						is_country_type = ai_empire
					}
				}
			}
			custom_tooltip = {
				text = cannot_crack_pre_ftl_planet_interference
				# primitive
				exists = owner
				owner = {
					is_primitive = yes
				}
				from.owner = {
					has_policy_flag = interference_aggressive
				}
			}
		}
		custom_tooltip = {
			text = not_barren_molten_frozen_toxic_test_fire
			NOT = { exists = owner }
			OR = {
				NOT = { exists = space_owner }
				AND = {
					exists = space_owner
					space_owner = { is_same_value = from.owner }
				}
			}
			OR = {
				is_planet_class = pc_barren
				is_planet_class = pc_barren_cold
				is_planet_class = pc_frozen
				is_planet_class = pc_molten
				is_planet_class = pc_toxic
				is_planet_class = pc_desert
				is_planet_class = pc_tropical
				is_planet_class = pc_arid
				is_planet_class = pc_continental
				is_planet_class = pc_ocean
				is_planet_class = pc_tundra
				is_planet_class = pc_arctic
				is_planet_class = pc_alpine
				is_planet_class = pc_savannah
				is_planet_class = pc_gaia
				is_planet_class = pc_relic
				is_planet_class = pc_nuked
				is_planet_class = pc_ringworld_habitable
				is_planet_class = pc_habitat
			}
		}
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_SHIELDER = {
	custom_tooltip = {
		fail_text = is_not_a_habitable_planet_or_megastructure
		OR = {
			is_a_habitable_planet_megastructure = yes
			is_planet_class = pc_ai
		}
	}
	custom_tooltip = {
		fail_text = is_not_hostile_or_primitive
		OR = {
			planet_is_hostile_or_crisis = yes
			AND = {
				exists = owner
				owner = {
					is_country_type = primitive
				}
			}
		}
	}
	if = {
		limit = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
		custom_tooltip = {
			fail_text = primitives_not_active_or_full_interference
			from.owner = {
				OR = {
					has_policy_flag = interference_active
					has_policy_flag = interference_aggressive
				}
			}
		}
	}
	custom_tooltip = {
		fail_text = is_shielded
		NOR = {
			is_planet_class = pc_shielded
			is_planet_class = pc_ringworld_shielded
			is_planet_class = pc_habitat_shielded
		}
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_NEUTRON = {
	custom_tooltip = {
		fail_text = is_not_a_habitable_planet_or_megastructure
		is_a_habitable_planet_megastructure = yes
	}
	custom_tooltip = {
		fail_text = is_shielded
		NOR = {
			is_planet_class = pc_shielded
			is_planet_class = pc_ringworld_shielded
			is_planet_class = pc_habitat_shielded
		}
	}
	custom_tooltip = {
		fail_text = is_not_hostile
		OR = {
			planet_is_hostile_or_crisis = yes
			AND = {
				exists = owner
				owner = {
					is_country_type = primitive
				}
				from.owner = {
					OR = {
						has_ethic = ethic_xenophobe
						has_ethic = ethic_fanatic_xenophobe
					}
				}
			}
			AND = {
				# at war with primitive space owner
				exists = space_owner
				exists = owner
				owner = {
					is_primitive = yes
				}
				space_owner = {
					OR = {
						is_at_war_with = from.owner
						is_country_type = swarm
						is_country_type = extradimensional
						is_country_type = extradimensional_2
						is_country_type = extradimensional_3
						is_country_type = ai_empire
					}
				}
			}
		}
	}
	custom_tooltip = {
		fail_text = is_unpopulated
		OR = {
			pop_amount > 0
			is_planet_class = pc_infested
		}
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_GODRAY = {
	custom_tooltip = {
		fail_text = is_not_a_habitable_planet_or_megastructure
		OR = {
			is_a_habitable_planet_megastructure = yes
			is_planet_class = pc_ai
		}
	}
	custom_tooltip = {
		fail_text = is_shielded
		NOR = {
			is_planet_class = pc_shielded
			is_planet_class = pc_ringworld_shielded
			is_planet_class = pc_habitat_shielded
		}
	}
	custom_tooltip = {
		#success_text = "is at war with player"
		fail_text = is_not_hostile_or_primitive
		OR = {
			planet_is_hostile = yes
			is_planet_class = pc_ai
			AND = {
				exists = owner
				owner = {
					is_country_type = primitive
				}
			}
			AND = {
				exists = owner
				owner = {
					is_same_value = from.owner
				}
			}
		}
	}
	if = {
		limit = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
		custom_tooltip = {
			fail_text = primitives_not_active_or_full_interference
			from.owner = {
				OR = {
					has_policy_flag = interference_active
					has_policy_flag = interference_aggressive
				}
			}
		}
	}
	# target own colony
	if = {
		limit = {
			NOR = {
				planet_is_hostile = yes
				AND = {
					exists = owner
					owner = {
						is_country_type = primitive
					}
				}
			}
			exists = owner
			owner = {
				is_same_value = from.owner
			}
		}
		custom_tooltip = {
			text = not_owned_test_fire
			exists = owner
			owner = {
				is_same_value = from.owner
			}
		}
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_NANOBOTS = {
	custom_tooltip = {
		fail_text = is_not_a_habitable_planet_or_megastructure
		is_a_habitable_planet_megastructure = yes
	}
	custom_tooltip = {
		fail_text = is_shielded
		NOR = {
			is_planet_class = pc_shielded
			is_planet_class = pc_ringworld_shielded
			is_planet_class = pc_habitat_shielded
		}
	}
	custom_tooltip = {
		fail_text = is_not_hostile_or_primitive
		OR = {
			planet_is_hostile = yes
			AND = {
				exists = owner
				owner = {
					is_country_type = primitive
				}
			}
		}
	}
	if = {
		limit = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
		custom_tooltip = {
			fail_text = primitives_not_in_borders
			exists = space_owner
			space_owner = {
				is_same_value = from.owner
			}
		}
		custom_tooltip = {
			fail_text = primitives_not_full_interference
			from.owner = {
				has_policy_flag = interference_aggressive
			}
		}
	}
	custom_tooltip = {
		fail_text = no_assimilatable_pops
		any_owned_pop_group = {
			is_valid_pop_for_PLANET_KILLER_NANOBOTS = yes
		}
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_DELUGE = {
	# custom_tooltip = { #feedback suggests this isn't fun, but leaving it here in case we need it
	# 	fail_text = requires_free_ice_mining_station
	# 	from.owner = {
	# 		any_owned_starbase = {
	# 			has_starbase_building = ice_mining_station
	# 			solar_system = {
	# 				OR = {
	# 					NOT = { has_star_flag = ice_mining_in_progress }
	# 					has_star_flag = ice_mining@root.from
	# 				}
	# 			}
	# 		}
	# 	}
	# }
	custom_tooltip = {
		fail_text = is_habitable_non_artificial
		OR = {
			is_colonizable = yes
			is_colony = yes
		}
		is_artificial = no
	}
	custom_tooltip = {
		fail_text = is_not_oceanic
		NOT = {
			is_planet_class = pc_ocean
		}
	}
	if = {
		limit = {
			is_inside_border = from.owner
		}
		if = {
			limit = {
				#Uninhabited and primitive planets are always fine, if own colony then check if pops would be purged
				exists = owner
				owner = {
					is_same_value = from.owner
				}
				any_owned_species = {
					NOT = {
						has_trait = trait_aquatic
					}
				}
			}
			custom_tooltip = {
				fail_text = requires_purge_allowed
				success_text = will_purge_non_aquatic_pops
				from.owner = {
					is_ai = no
					has_policy_flag = purge_allowed
				}
			}
		}
	}
	else = {
		custom_tooltip = {
			fail_text = is_not_hostile_or_primitive_or_ours
			OR = {
				planet_is_hostile = yes
				AND = {
					exists = owner
					owner = {
						is_country_type = primitive
					}
				}
			}
		}
	}
	if = {
		limit = {
			exists = owner
			owner = {
				is_country_type = primitive
			}
		}
		custom_tooltip = {
			fail_text = primitives_not_in_borders
			exists = space_owner
			space_owner = {
				is_same_value = from.owner
			}
		}
		custom_tooltip = {
			fail_text = primitives_not_full_interference
			from.owner = {
				has_policy_flag = interference_aggressive
			}
		}
	}
}

is_valid_pop_for_RG_PLANET_KILLER_NANOBOTS = {
	NOR = {
		has_trait = trait_hive_mind
		has_trait = trait_mechanical
		has_trait = trait_machine_unit
	}
}

can_destroy_planet_with_RG_PLANET_KILLER_STAR_CRACKER = {
	custom_tooltip = {
		fail_text = is_your_megastructure_system
		NOT = {
			solar_system = {
				has_star_flag = crisis_sphere_system@from.owner
				any_system_megastructure = {
					has_megastructure_flag = crisis_sphere
				}
			}
		}
	}
	custom_tooltip = {
		fail_text = is_not_star
		is_star = yes
	}
	custom_tooltip = {
		fail_text = is_black_hole
		NOT = {
			is_planet_class = pc_black_hole
		}
	}
	custom_tooltip = {
		fail_text = star_owner_is_not_hostile
		OR = {
			NOT = {
				exists = space_owner
			}
			space_owner = {
				is_hostile = from.owner
			}
			space_owner = {
				is_same_value = from.owner
			}
		}
	}
}
