###############################################
# === xenomorph_captive_events.txt ===
###############################################
###############################################
# XENOMORPH CAPTIVE PITS - browse & interact menu
#
# Opened by edict_xenomorph_captive_pits -> xeno_captive.1
#
# Flow:
#   .1   Main menu: are there captives? -> browse, else "no captives"
#   .2   Browse one captive (shows portrait): Interact / Next / Exit
#   .3   Interact submenu for the shown captive: Fuck / Share with Hive / Back
#   .10  "Fuck" scene + reward (amenity boost)
#   .20  "Share with the Hive" scene (gender-branched) + reward (egg boost)
#
# Browsing model: we cycle through captive leaders one at a time. Each "Next"
# saves the next captive as event_target:xeno_browsed_captive and re-shows .2.
# Captives are leaders flagged xeno_captured_leader (set on capture).
###############################################

namespace = xeno_captive

# ---- .1 MAIN MENU ----------------------------------------------------------------
country_event = {
	id = xeno_captive.1
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			# Any captive leaders held?
			limit = { any_owned_leader = { has_leader_flag = xeno_captured_leader } }
			# Save the first captive as the currently-browsed one.
			random_owned_leader = {
				limit = { has_leader_flag = xeno_captured_leader }
				save_event_target_as = xeno_browsed_captive
			}
			country_event = { id = xeno_captive.2 }
		}
		else = {
			country_event = { id = xeno_captive.5 }
		}
	}
}

# ---- .5 NO CAPTIVES --------------------------------------------------------------
country_event = {
	id = xeno_captive.5
	title = "xeno_captive.title"
	desc = "xeno_captive.5.desc"
	diplomatic = yes
	is_triggered_only = yes

	option = {
		name = "xeno_captive.exit"
	}
}

# ---- .2 BROWSE ONE CAPTIVE -------------------------------------------------------
country_event = {
	id = xeno_captive.2
	title = "xeno_captive.title"
	desc = "xeno_captive.2.desc"
	diplomatic = yes
	is_triggered_only = yes

	# Show the captive's portrait in the event window.
	picture_event_data = {
		portrait = event_target:xeno_browsed_captive
		planet_background = root.capital_scope
		graphical_culture = root.owner
		city_level = root.capital_scope
		room = root.ruler
	}

	# Interact with this captive. Opens the leader-card popup (leader_story window)
	# scoped to the captive, where the two interaction options live.
	option = {
		name = "xeno_captive.2.interact"
		hidden_effect = {
			event_target:xeno_browsed_captive = {
				leader_event = { id = xeno_captive.3 }
			}
		}
	}

	# Cycle to the next captive (if more than one).
	option = {
		name = "xeno_captive.2.next"
		trigger = {
			any_owned_leader = {
				has_leader_flag = xeno_captured_leader
				NOT = { is_same_value = event_target:xeno_browsed_captive }
			}
		}
		hidden_effect = {
			# Pick a different captive than the one currently shown.
			random_owned_leader = {
				limit = {
					has_leader_flag = xeno_captured_leader
					NOT = { is_same_value = event_target:xeno_browsed_captive }
				}
				save_event_target_as = xeno_browsed_captive
			}
			country_event = { id = xeno_captive.2 }
		}
	}

	option = {
		name = "xeno_captive.exit"
	}
}

# ---- .3 INTERACT - LEADER CARD POPUP (leader_story window) -----------------------
# Fired as a leader_event on the captive, so it renders as the leader detail card
# (portrait, traits, age, class) - like the paragon leader panel - but with our two
# interaction options where "Dismiss Leader" would normally be. Selecting an option
# closes the card and fires the follow-up story+reward on the owner country.
leader_event = {
	id = xeno_captive.3
	title = "xeno_captive.title"
	show_sound = event_default
	is_triggered_only = yes
	fire_only_once = no

	event_window_type = leader_story
	event_picture_background = "GFX_leader_recruitment_bg_renowned"

	picture_event_data = { portrait = root }

	# Desc shows the captive's current submission stage + vitality (stage text;
	# raw numbers available via the stage description tooltips).
	desc = {
		trigger = { xeno_captive_is_defiant = yes }
		text = "xeno_captive.3.desc.defiant"
	}
	desc = {
		trigger = { xeno_captive_is_yielding = yes }
		text = "xeno_captive.3.desc.yielding"
	}
	desc = {
		trigger = { xeno_captive_is_submissive = yes }
		text = "xeno_captive.3.desc.submissive"
	}
	desc = {
		trigger = { xeno_captive_is_broken = yes }
		text = "xeno_captive.3.desc.broken"
	}
	desc = {
		trigger = { xeno_captive_is_devoted = yes }
		text = "xeno_captive.3.desc.devoted"
	}

	# 1) FUCK -> opens the Fuck sub-panel (needs vitality >= 10)
	option = {
		name = "xeno_captive.3.fuck"
		trigger = { root = { xeno_captive_vitality_atleast_10 = yes } }
		hidden_effect = {
			owner = { country_event = { id = xeno_captive.30 } }
		}
	}

	# 2) SHARE WITH THE HIVE -> opens the Share sub-panel (needs vitality >= 20)
	option = {
		name = "xeno_captive.3.share"
		trigger = { root = { xeno_captive_vitality_atleast_20 = yes } }
		hidden_effect = {
			owner = { country_event = { id = xeno_captive.40 } }
		}
	}

	# 3) IMPREGNATE -> opens the Impregnate sub-panel (needs vitality >= 25)
	option = {
		name = "xeno_captive.3.impregnate"
		trigger = { root = { xeno_captive_vitality_atleast_25 = yes } }
		hidden_effect = {
			owner = { country_event = { id = xeno_captive.50 } }
		}
	}

	# 4) RELEASE -> returns the captive to their empire of origin (Layer 2 fills in)
	option = {
		name = "xeno_captive.3.release"
		hidden_effect = {
			owner = { country_event = { id = xeno_captive.60 } }
		}
	}

	# Back to the browse menu
	option = {
		name = "xeno_captive.back"
		hidden_effect = {
			owner = { country_event = { id = xeno_captive.2 } }
		}
	}
}

# ---- .10 FUCK (scene + amenity reward) -------------------------------------------
country_event = {
	id = xeno_captive.10
	title = "xeno_captive.title"
	desc = "xeno_captive.10.desc"
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:xeno_browsed_captive
		planet_background = root.capital_scope
		graphical_culture = root.owner
		city_level = root.capital_scope
		room = root.ruler
	}

	immediate = {
		# Reward: temporary amenity / pleasure-caste boost (10 years).
		add_modifier = {
			modifier = xeno_captive_pleasure_boost
			days = 3600
		}
	}

	option = {
		name = "xeno_captive.continue"
		hidden_effect = { country_event = { id = xeno_captive.2 } }
	}
}

# ---- .20 SHARE WITH THE HIVE (gender-branched scene + egg reward) -----------------
country_event = {
	id = xeno_captive.20
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		# Reward: temporary egg-production boost (10 years).
		add_modifier = {
			modifier = xeno_captive_breeding_boost
			days = 3600
		}
		# Branch the story by hive gender first, then captive origin.
		if = {
			limit = { xeno_is_matriarchal_hunger_empire = yes }
			country_event = { id = xeno_captive.21 }   # female hive
		}
		else_if = {
			limit = { xeno_is_patriarchal_dominion_empire = yes }
			country_event = { id = xeno_captive.22 }   # male hive
		}
		else = {
			# Neither trait: branch on captive origin, else pick one.
			if = {
				limit = { event_target:xeno_browsed_captive = { has_leader_flag = xeno_captive_from_male_origin } }
				country_event = { id = xeno_captive.21 }   # female-hive-style story vs male captive
			}
			else_if = {
				limit = { event_target:xeno_browsed_captive = { has_leader_flag = xeno_captive_from_female_origin } }
				country_event = { id = xeno_captive.22 }
			}
			else = {
				random_list = {
					50 = { country_event = { id = xeno_captive.21 } }
					50 = { country_event = { id = xeno_captive.22 } }
				}
			}
		}
	}
}

# ---- .21 SHARE - female-hive variant ---------------------------------------------
country_event = {
	id = xeno_captive.21
	title = "xeno_captive.title"
	desc = "xeno_captive.21.desc"
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:xeno_browsed_captive
		planet_background = root.capital_scope
		graphical_culture = root.owner
		city_level = root.capital_scope
		room = root.ruler
	}

	option = {
		name = "xeno_captive.continue"
		hidden_effect = { country_event = { id = xeno_captive.2 } }
	}
}

# ---- .22 SHARE - male-hive variant -----------------------------------------------
country_event = {
	id = xeno_captive.22
	title = "xeno_captive.title"
	desc = "xeno_captive.22.desc"
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:xeno_browsed_captive
		planet_background = root.capital_scope
		graphical_culture = root.owner
		city_level = root.capital_scope
		room = root.ruler
	}

	option = {
		name = "xeno_captive.continue"
		hidden_effect = { country_event = { id = xeno_captive.2 } }
	}
}


# ============================================================================
# CAPTIVE DEVELOPMENT - SUB-PANELS & LEAF STORIES (Layer 1)
#
# Sub-panels (.30 Fuck, .40 Share, .50 Impregnate, .60 Release) present the
# second tier of choices. Each leaf fires a stubbed story event that:
#   - applies the action cost to the captive (vitality down, submission up)
#   - grants a stage-scaled reward to the empire
#   - returns to the browse menu
# Stories are short placeholders for now (Layer 3 fills in full prose).
# Gendered story routing is handled per-leaf via xeno_captive_route_* events
# in Layer 3; Layer 1 uses single stub descs.
# ============================================================================


# ---- .30 FUCK SUB-PANEL ----------------------------------------------------------
country_event = {
	id = xeno_captive.30
	title = "xeno_captive.title"
	desc = "xeno_captive.30.desc"
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:xeno_browsed_captive
		planet_background = root.capital_scope
		graphical_culture = root.owner
		room = root.ruler
	}

	option = {	# Use mouth
		name = "xeno_captive.30.mouth"
		hidden_effect = { country_event = { id = xeno_captive.31 } }
	}
	option = {	# Fuck vaginal
		name = "xeno_captive.30.vaginal"
		hidden_effect = { country_event = { id = xeno_captive.32 } }
	}
	option = {	# Fuck anal
		name = "xeno_captive.30.anal"
		hidden_effect = { country_event = { id = xeno_captive.33 } }
	}
	option = {	# Breastfuck
		name = "xeno_captive.30.breast"
		hidden_effect = { country_event = { id = xeno_captive.34 } }
	}
	option = {	# Back
		name = "xeno_captive.back"
		hidden_effect = { event_target:xeno_browsed_captive = { leader_event = { id = xeno_captive.3 } } }
	}
}

# Fuck leaves (.31-.34): cost 10 vitality, +5 submission, scaled pleasure reward.
country_event = {
	id = xeno_captive.31
	title = "xeno_captive.title"
	desc = "xeno_captive.31.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 10 SUB = 5 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_pleasure_boost }
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}
country_event = {
	id = xeno_captive.32
	title = "xeno_captive.title"
	desc = "xeno_captive.32.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 10 SUB = 5 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_pleasure_boost }
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}
country_event = {
	id = xeno_captive.33
	title = "xeno_captive.title"
	desc = "xeno_captive.33.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 10 SUB = 5 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_pleasure_boost }
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}
country_event = {
	id = xeno_captive.34
	title = "xeno_captive.title"
	desc = "xeno_captive.34.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 10 SUB = 5 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_pleasure_boost }
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}


# ---- .40 SHARE SUB-PANEL ---------------------------------------------------------
country_event = {
	id = xeno_captive.40
	title = "xeno_captive.title"
	desc = "xeno_captive.40.desc"
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:xeno_browsed_captive
		planet_background = root.capital_scope
		graphical_culture = root.owner
		room = root.ruler
	}

	option = {	# Queen joins the hive in using the captive
		name = "xeno_captive.40.queen_joins"
		hidden_effect = { country_event = { id = xeno_captive.41 } }
	}
	option = {	# Leave free for use
		name = "xeno_captive.40.free_use"
		hidden_effect = { country_event = { id = xeno_captive.42 } }
	}
	option = {	# Swarm them
		name = "xeno_captive.40.swarm"
		hidden_effect = { country_event = { id = xeno_captive.43 } }
	}
	option = {	# Back
		name = "xeno_captive.back"
		hidden_effect = { event_target:xeno_browsed_captive = { leader_event = { id = xeno_captive.3 } } }
	}
}

# Share leaves (.41-.43): cost 20 vitality, +10 submission, scaled breeding reward.
country_event = {
	id = xeno_captive.41
	title = "xeno_captive.title"
	desc = "xeno_captive.41.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 20 SUB = 10 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_breeding_boost }
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}
country_event = {
	id = xeno_captive.42
	title = "xeno_captive.title"
	desc = "xeno_captive.42.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 20 SUB = 10 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_breeding_boost }
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}
country_event = {
	id = xeno_captive.43
	title = "xeno_captive.title"
	desc = "xeno_captive.43.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 20 SUB = 10 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_breeding_boost }
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}


# ---- .50 IMPREGNATE SUB-PANEL ----------------------------------------------------
country_event = {
	id = xeno_captive.50
	title = "xeno_captive.title"
	desc = "xeno_captive.50.desc"
	diplomatic = yes
	is_triggered_only = yes

	picture_event_data = {
		portrait = event_target:xeno_browsed_captive
		planet_background = root.capital_scope
		graphical_culture = root.owner
		room = root.ruler
	}

	# Facehugger impregnation -> kills captive, spawns leader pop (Layer 2). Needs vitality >= 40.
	option = {
		name = "xeno_captive.50.facehugger"
		trigger = { event_target:xeno_browsed_captive = { xeno_captive_vitality_atleast_40 = yes } }
		hidden_effect = { country_event = { id = xeno_captive.51 } }
	}
	# Oral impregnation -> kills captive, spawns leader pop (Layer 2). Needs vitality >= 35.
	option = {
		name = "xeno_captive.50.oral"
		trigger = { event_target:xeno_browsed_captive = { xeno_captive_vitality_atleast_35 = yes } }
		hidden_effect = { country_event = { id = xeno_captive.52 } }
	}
	# Risk-free impregnation -> captive survives. Needs vitality >= 25.
	option = {
		name = "xeno_captive.50.risk_free"
		trigger = { event_target:xeno_browsed_captive = { xeno_captive_vitality_atleast_25 = yes } }
		hidden_effect = { country_event = { id = xeno_captive.53 } }
	}
	# Convert to espionage asset -> only if Devoted (Layer 2 adds tradition/tech gate).
	option = {
		name = "xeno_captive.50.espionage"
		trigger = { event_target:xeno_browsed_captive = { xeno_captive_is_devoted = yes } }
		hidden_effect = { country_event = { id = xeno_captive.54 } }
	}
	option = {	# Back
		name = "xeno_captive.back"
		hidden_effect = { event_target:xeno_browsed_captive = { leader_event = { id = xeno_captive.3 } } }
	}
}

# Facehugger (.51): kills captive + spawns leader pop. Layer 1 stub: applies cost,
# grants reward; the kill + spawn is wired in Layer 2.
country_event = {
	id = xeno_captive.51
	title = "xeno_captive.title"
	desc = "xeno_captive.51.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 40 SUB = 0 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_breeding_boost }
		# Layer 2: kill captive, create_leader with copied traits + XP scaled by submission.
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}
# Oral (.52): same as facehugger, different story.
country_event = {
	id = xeno_captive.52
	title = "xeno_captive.title"
	desc = "xeno_captive.52.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 35 SUB = 0 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_breeding_boost }
		# Layer 2: kill captive, create_leader with copied traits + XP scaled by submission.
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}
# Risk-free (.53): captive survives, cost 25, +15 submission, scaled breeding reward.
country_event = {
	id = xeno_captive.53
	title = "xeno_captive.title"
	desc = "xeno_captive.53.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		event_target:xeno_browsed_captive = { xeno_captive_apply_action = { COST = 25 SUB = 15 } }
		xeno_captive_grant_scaled_reward = { MOD = xeno_captive_breeding_boost }
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}
# Espionage conversion (.54): Layer 2 wires the operative/intel grant + consumes captive.
country_event = {
	id = xeno_captive.54
	title = "xeno_captive.title"
	desc = "xeno_captive.54.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		# Layer 2: convert captive into an espionage asset, remove from roster.
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}


# ---- .60 RELEASE -----------------------------------------------------------------
# Returns the captive to their empire of origin. Layer 2 wires the set_owner-back
# + roster decrement. Layer 1 stub closes the loop.
country_event = {
	id = xeno_captive.60
	title = "xeno_captive.title"
	desc = "xeno_captive.60.desc"
	diplomatic = yes
	is_triggered_only = yes
	picture_event_data = { portrait = event_target:xeno_browsed_captive room = root.ruler }
	immediate = {
		# Layer 2: return captive to origin empire, decrement roster count.
	}
	option = { name = "xeno_captive.continue" hidden_effect = { country_event = { id = xeno_captive.2 } } }
}


# ---- .90 MONTHLY MAINTENANCE (hidden) --------------------------------------------
# Fired by on_monthly_pulse_country. Regenerates captive vitality (until Broken).
country_event = {
	id = xeno_captive.90
	hide_window = yes
	is_triggered_only = yes
	immediate = {
		if = {
			limit = { any_owned_leader = { has_leader_flag = xeno_captured_leader } }
			xeno_captive_monthly_regen = yes
		}
	}
}

###############################################
# === xenomorph_captor_capture_events.txt ===
###############################################
###############################################
# XENOMORPH CAPTOR CAPTURE EVENTS (non-hive empires)
#
# Lets a NON-HIVE empire capture Xenomorph leaders by defeating Xenomorph
# empires. Mirrors the Xeno side (xeno_capture.*) but reversed: ROOT is the
# non-hive victor, FROM is the destroyed Xeno fleet.
#
# Gated by the Xeno Dominion tradition (tr_xeno_xeno_dominion_capture_protocols).
# Captured Xeno leaders become captives the empire can develop using the
# existing captive interaction system.
#
#  .300 - battle victory GATE (hidden, from on_fleet_destroyed_perp)
#  .301 - capture choice (shown)
#  .302 - prisoner confirm (shown)
#  .310 - battle victory flavour (shown) - fires on beating a Xeno fleet
###############################################

namespace = xeno_captor

# ---- .300 BATTLE-VICTORY CAPTURE GATE (hidden) -----------------------------------
# ROOT = victorious non-hive country, FROM = destroyed fleet (should be Xeno-owned).
country_event = {
	id = xeno_captor.300
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_gestalt = no
		has_technology = tech_xeno_containment
		from = {
			exists = owner
			owner = {
				is_xenomorph_empire = yes
				NOT = { is_same_value = root }
			}
		}
	}

	immediate = {
		# Always fire the flavour beat for beating a Xeno fleet.
		country_event = { id = xeno_captor.310 }

		# If the empire has unlocked capture, a chance to take a Xeno leader.
		if = {
			limit = { has_tradition = tr_xeno_xeno_dominion_capture_protocols }
			random_list = {
				70 = { }
				30 = {
					from = {
						owner = {
							save_event_target_as = xeno_captor_source
							save_event_target_as = xeno_capture_source_country
							random_owned_leader = {
								limit = { is_ruler = no }
								save_event_target_as = xeno_captor_candidate
							}
						}
					}
					if = {
						limit = { exists = event_target:xeno_captor_candidate }
						country_event = { id = xeno_captor.301 }
					}
				}
			}
		}
	}
}

# ---- .301 CAPTURE CHOICE (shown) -------------------------------------------------
country_event = {
	id = xeno_captor.301
	title = "xeno_captor.301.title"
	desc = "xeno_captor.301.desc"
	picture = GFX_evt_ship_in_orbit
	is_triggered_only = yes

	# Take the Xeno leader captive (into the development system).
	option = {
		name = "xeno_captor.301.capture"
		event_target:xeno_captor_candidate = {
			set_owner = root
			xeno_flag_captured_leader = yes
		}
		hidden_effect = { country_event = { id = xeno_captor.302 } }
	}

	# Put it down - a research / society boon instead.
	option = {
		name = "xeno_captor.301.dissect"
		add_resource = { society_research = 300 }
	}
}

# ---- .302 PRISONER TAKEN (shown) -------------------------------------------------
country_event = {
	id = xeno_captor.302
	title = "xeno_captor.301.title"
	desc = "xeno_captor.302.desc"
	picture = GFX_evt_alien_planet
	is_triggered_only = yes
	option = { name = "xeno_captor.302.ok" }
}

# ---- .310 BATTLE-VICTORY FLAVOUR (shown) -----------------------------------------
# A non-hive empire that beats a Xenomorph fleet in the void.
country_event = {
	id = xeno_captor.310
	title = "xeno_captor.310.title"
	desc = "xeno_captor.310.desc"
	picture = GFX_evt_ship_in_orbit
	is_triggered_only = yes

	# Only show once in a while so it does not spam.
	trigger = {
		NOT = { has_country_flag = xeno_captor_recent_victory }
	}

	immediate = {
		set_country_flag = { flag = xeno_captor_recent_victory days = 720 }
	}

	option = {
		name = "xeno_captor.310.ok"
	}
}

###############################################
# === xenomorph_captor_origin_events.txt ===
###############################################
###############################################
# XENOMORPH CAPTOR ORIGIN START EVENTS (non-hive empires)
#
# At game start, enslaves the Xenomorph secondary species as livestock for
# the two captor origins. Fired from on_game_start_country.
#  - origin_xeno_traffickers (Megacorp): Xenos as trade-stock livestock
#  - origin_xeno_keepers (any non-hive): Xenos as kept livestock
###############################################

namespace = xeno_captor_start

# --- .1 Xeno Traffickers start: enslave the Xeno secondary species ---
country_event = {
	id = xeno_captor_start.1
	hide_window = yes
	is_triggered_only = yes
	fire_only_once = yes

	trigger = {
		has_origin = origin_xeno_traffickers
	}

	immediate = {
		# Enslave every Xenomorph species in the empire as livestock stock-in-trade.
		every_owned_species = {
			limit = {
				has_trait = trait_xenomorph
			}
			set_species_rights = {
				type = slavery_livestock
				country = root
			}
		}
		set_country_flag = xeno_traffickers_origin
	}
}

# --- .2 Xeno Keepers start: enslave the Xeno secondary species ---
country_event = {
	id = xeno_captor_start.2
	hide_window = yes
	is_triggered_only = yes
	fire_only_once = yes

	trigger = {
		has_origin = origin_xeno_keepers
	}

	immediate = {
		every_owned_species = {
			limit = {
				has_trait = trait_xenomorph
			}
			set_species_rights = {
				type = slavery_livestock
				country = root
			}
		}
		set_country_flag = xeno_keepers_origin
	}
}

###############################################
# === xenomorph_capture_choice_events.txt ===
###############################################
###############################################
# XENOMORPH FLESH HARVEST - capture choice events
#
# Fired when a Flesh Harvest empire wins a battle and an enemy leader can be
# taken. Presents the CHOICE: keep them as a prisoner (into the Captive Pits
# development system) or put them with the slaves (a slave pop / labor).
#
# .10  Planet capture choice  (from on_planet_attackers_win; FromFrom = planet)
# .20  Space capture choice   (from on_fleet_destroyed_perp; gated by AP)
# .1   Planet trigger gate     (hidden; checks tradition + eligible leader)
# .2   Space trigger gate      (hidden; checks AP + eligible leader)
###############################################

namespace = xeno_capture

# ---- .1 PLANET CAPTURE GATE (hidden) ---------------------------------------------
# Fired on on_planet_attackers_win. ROOT = winning country, FROMFROM = planet.
# If ROOT is a Flesh Harvest hive and the planet's former owner has a non-ruler
# leader to take, save the pieces and offer the choice.
country_event = {
	id = xeno_capture.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_xenomorph_empire = yes
		has_tradition = tradition_xenomorph_flesh_harvest
		fromfrom = {
			exists = owner
			NOT = { owner = { is_same_value = root } }
		}
	}

	immediate = {
		# Roster room check first.
		xeno_recompute_captive_capacity = yes
		xeno_count_captives = yes
		if = {
			limit = { check_variable = { which = xeno_captive_count value < xeno_captive_capacity } }
			fromfrom = {
				owner = {
					save_event_target_as = xeno_capture_source_country
					random_owned_leader = {
						limit = { is_ruler = no }
						save_event_target_as = xeno_capture_candidate
					}
				}
			}
			if = {
				limit = { exists = event_target:xeno_capture_candidate }
				country_event = { id = xeno_capture.10 }
			}
		}
	}
}

# ---- .10 PLANET CAPTURE CHOICE (shown) -------------------------------------------
country_event = {
	id = xeno_capture.10
	title = "xeno_capture.10.title"
	desc = "xeno_capture.10.desc"
	picture = GFX_evt_army_stance_offensive
	is_triggered_only = yes

	option = {	# Keep as prisoner -> into the Captive Pits
		name = "xeno_capture.choice.prisoner"
		event_target:xeno_capture_candidate = {
			set_owner = root
			xeno_flag_captured_leader = yes
		}
		hidden_effect = { country_event = { id = xeno_capture.11 } }
	}
	option = {	# Put with the slaves -> a slave pop / labor
		name = "xeno_capture.choice.slaves"
		xeno_capture_send_to_slaves = yes
	}
}

# ---- .11 Prisoner taken confirm --------------------------------------------------
country_event = {
	id = xeno_capture.11
	title = "xeno_capture.10.title"
	desc = "xeno_capture.11.desc"
	picture = GFX_evt_alien_planet
	is_triggered_only = yes
	option = { name = "xeno_capture.11.ok" }
}

# ---- .2 SPACE CAPTURE GATE (hidden) ----------------------------------------------
# Fired on on_fleet_destroyed_perp. ROOT = victorious country, FROM = destroyed
# fleet. Requires the Void Reavers ascension perk. A CHANCE to recover a leader
# from the survivors of the destroyed fleet's owner.
country_event = {
	id = xeno_capture.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_xenomorph_empire = yes
		has_ascension_perk = ap_xenomorph_void_reavers
		from = {
			exists = owner
			NOT = { owner = { is_same_value = root } }
		}
	}

	immediate = {
		# 25% chance to recover a leader from the wreckage.
		random_list = {
			75 = { }
			25 = {
				xeno_recompute_captive_capacity = yes
				xeno_count_captives = yes
				if = {
					limit = { check_variable = { which = xeno_captive_count value < xeno_captive_capacity } }
					from = {
						owner = {
							save_event_target_as = xeno_capture_source_country
							random_owned_leader = {
								limit = { is_ruler = no }
								save_event_target_as = xeno_capture_candidate
							}
						}
					}
					if = {
						limit = { exists = event_target:xeno_capture_candidate }
						country_event = { id = xeno_capture.20 }
					}
				}
			}
		}
	}
}

# ---- .20 SPACE CAPTURE CHOICE (shown) --------------------------------------------
country_event = {
	id = xeno_capture.20
	title = "xeno_capture.20.title"
	desc = "xeno_capture.20.desc"
	picture = GFX_evt_ship_in_orbit
	is_triggered_only = yes

	option = {	# Keep as prisoner
		name = "xeno_capture.choice.prisoner"
		event_target:xeno_capture_candidate = {
			set_owner = root
			xeno_flag_captured_leader = yes
		}
		hidden_effect = { country_event = { id = xeno_capture.11 } }
	}
	option = {	# Put with the slaves
		name = "xeno_capture.choice.slaves"
		xeno_capture_send_to_slaves = yes
	}
}
