###############################################
# XENOMORPH ESPIONAGE OPERATIONS
###############################################

# =============================================
# HIVE RAID — Abduct Pops
# Steals 1-3 pops from a target planet and
# delivers them to the Xenomorph empire's
# Host Processing Bay / Breeding Pit.
# =============================================
operation_xenomorph_raid_pop = {
	icon = "GFX_espionage_operation_icon_default"
	category = "subterfuge"

	resources = {
		category = espionage_operations
		cost = {
			energy = 200
			influence = 25
		}
	}

	# Requires the Xenomorph species trait
	potential = {
		owner = {
			any_owned_species = { has_trait = trait_xenomorph }
		}
	}

	# Can only target empires that have pops
	target_potential = {
		any_owned_planet = { num_pops >= 5 }
	}

	# Difficulty scales with target empire's intel level
	base_success_chance = 0.55
	base_detection_chance = 0.20

	# Outcome: Success
	on_success = {
		owner_country = {
			save_event_target_as = xeno_raid_attacker
			country_event = { id = xeno_pic_events.26 }
			add_resource = { influence = -25 }
		}
		target_country = {
			save_event_target_as = xeno_raid_defender
			random_owned_planet = {
				limit = {
					is_colony = yes
					any_owned_pop_group = { is_xenomorph = no }
				}
				save_event_target_as = xeno_raid_planet
			}
			add_resource = { unity = -150 }
		}
		owner_country = {
			hidden_effect = { xeno_kidnap_saved_planet_pops = yes }
		}
	}

	# Outcome: Failure (detected)
	on_critical_failure = {
		owner_country = {
			add_resource = { influence = -50 }
		}
		target_country = {
			add_opinion_modifier = {
				who = root.owner_country
				modifier = opinion_xenomorph_raid_detected
			}
		}
	}

	# Outcome: Partial success (not detected but reduced reward)
	on_failure = {
		owner_country = {
			add_resource = { food = 200 unity = 50 }
		}
	}
}

# =============================================
# HIVE CELL INFILTRATION — Branch Office Setup
# Establishes a covert Hive Cell on a target world,
# unlocking the Infestation Relay branch office building.
# =============================================
operation_xenomorph_hive_cell = {
	icon = "GFX_espionage_operation_icon_default"
	category = "infiltration"

	resources = {
		category = espionage_operations
		cost = {
			energy = 300
			influence = 50
		}
	}

	potential = {
		owner = {
			any_owned_species = { has_trait = trait_xenomorph }
		}
	}

	target_potential = {
		any_owned_planet = { num_pops >= 8 }
	}

	base_success_chance = 0.45
	base_detection_chance = 0.30

	on_success = {
		owner_country = {
			country_event = { id = xeno_pic_events.23 }
		}
		# Target planet gets a stability hit from the infiltration
		target_planet = {
			add_modifier = { modifier = xenomorph_post_battle_shock days = 360 }
		}
	}

	on_critical_failure = {
		owner_country = {
			add_resource = { influence = -75 }
		}
	}

	on_failure = {
		owner_country = {
			add_resource = { influence = -25 }
		}
	}
}
