# operation_type_name = {			# Key of the site, used for name lookup etc.
#	target = <target type>			# Valid target types are country, megastructure, starbase, fleet, army, pop_faction, spynetwork, federation and none (spy network target is the target then)
#	picture = <sprite key>			# GFX_* sprite key for the operation image
#	desc = <triggered event desc>	# Description generator for the operation, with scope this=spy network
#	stages = <int>					# Should match number of defined stages below.
#	potential = <trigger>			# Trigger checking if a scope with this=spy network is potential to use (this will add/remove this operation without giving the player a reason).
#	allow = <trigger>				# Trigger checking if a scope with this=spy network is allowed to use (this will toggle enable/disabled mode on buttons etc).
#	stage = {						# Stage definition, order dependent.
#		difficulty = <interval int>	# min max interval type. interval is defined either by '<int>' or '{ min = <int> max=<int> }' where the later will randomize a value between min and max.
#		icon = <string>				# icon gfx type.
#		event = <string>			# event to fire when finished the state.
#	}
#	stage = {...}					# Second stage, the total number of 'stage' entries should match value of 'stages'
#	on_roll_failed = <effect>		# Effect to fire when a roll fails, with scope this=spy operation.
#	on_create = <effect>			# Effect to fire upon operation creation, with scope this=spy operation.
#}

@diff_t0 = 4
@diff_t1 = 5
@diff_t2 = 6
@diff_t3 = 7
@diff_t4 = 8
@diff_t5 = 9
@diff_t6 = 10
@diff_t7 = 11
@diff_t8 = 12
@diff_t9 = 13

@operationTargetedByTimer = 10800 #30 years during which the effects of an operation may be felt by select Spy Network events

# this = operation
# from = operation target

operation_gather_information = {
	target = none
	categories = { op_cat_subterfuge }
	picture = GFX_evt_spymaster
	desc = {
		trigger = { has_nemesis = yes }
		text = operation_gather_information_desc
	}
	desc = {
		trigger = { has_nemesis = no }
		text = operation_gather_information_no_dlc_desc
	}
	stages = 1

	resources = {
		category = operations
		cost = {
			influence = 20
		}
		upkeep = {
			energy = 4
		}
	}

	spy_power_cost = 10
	potential = {
		target = { is_country_type = default }
	}
	allow = {
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t0
		icon = GFX_espionage_chapter_icon_document
		event = operation.7000
	}

	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = {
			RANDOM_EVENTS = operation_random_events_low_stakes
		}
	}
	on_create = {
		target = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

operation_diplomatic_incident = {
	target = none
	categories = { op_cat_manipulation op_cat_diplomacy }
	picture = GFX_evt_tradedeal
	desc = operation_diplomatic_incident_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 30
		}
		upkeep = {
			energy = 5
		}
	}

	spy_power_cost = 25
	potential = {
		has_nemesis = yes
		owner = { num_communications > 3 }
		target = {
			is_country_type = default
			is_homicidal = no
		}
	}
	allow = {
		custom_tooltip = {
			fail_text = saturated_with_scandals
			NOT = { has_spynetwork_flag = operation_diplomatic_incident_timer }
		}
		target = {
			num_communications > 3
			custom_tooltip = {
				fail_text = gestalts_are_boring
				is_gestalt = no
			}
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_surveillance
		event = operation.8200
	}
	stage = {
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_motion
		event = operation.8205
	}
	stage = {
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_target
		event = operation.8210
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}
	on_create = {
	}
}

operation_sleeper_cells = {
	target = none
	categories = { op_cat_subterfuge op_cat_government }
	picture = GFX_evt_spy_network
	desc = operation_sleeper_cells_desc
	stages = 2

	spy_power_cost = 30

	resources = {
		category = operations
		cost = {
			influence = 45
		}
		upkeep = {
			energy = 6
		}
	}
	potential = {
		has_nemesis = yes
		owner = { is_wilderness_empire = no } # see 'operation_embed_planetary_roots'
		target = { is_country_type = default }
	}
	allow = {
		custom_tooltip = {
			fail_text = operation_sleeper_cells_dont_stack_this
			NOT = { has_modifier = sleeper_cell_operation_success } #I.e. don't try to stack this
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t2
		icon = GFX_espionage_chapter_icon_surveillance
		event = operation.8000
	}
	stage = {
		difficulty = @diff_t2
		icon = GFX_espionage_chapter_icon_motion
		event = operation.8001
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}
	on_create = {
	}
}

operation_embed_planetary_roots = { # based on 'operation_sleeper_cells' above
	target = none
	categories = { op_cat_subterfuge op_cat_military }
	picture = GFX_evt_alien_nature
	desc = operation_embed_planetary_roots_desc
	stages = 2

	spy_power_cost = 30

	resources = {
		category = operations
		cost = {
			influence = 45
		}
		upkeep = {
			energy = 6
		}
	}

	potential = {
		has_nemesis = yes
		owner = { is_wilderness_empire = yes }
		target = { is_primitive = no }
	}

	allow = {
		custom_tooltip = {
			fail_text = operation_embed_planetary_roots_requires_blocker
			target = {
				count_owned_planet = {
					limit = {
						is_colony = yes
						has_natural_blocker = yes
					}
					count > 0
				}
			}
		}
		custom_tooltip = {
			fail_text = operation_embed_planetary_roots_dont_stack_this
			NOT = { has_modifier = espionage_planetary_roots }
		}
		custom_tooltip = {
			fail_text = operation_embed_planetary_roots_not_cleared
			NOT = {
				target = {
					any_owned_planet = {
						has_deposit = d_wilderness_root_blocker
					}
				}
			}
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}

	stage = {
		difficulty = @diff_t2
		icon = GFX_espionage_chapter_icon_surveillance
		event = wilderness.4500
	}
	stage = {
		difficulty = @diff_t2
		icon = GFX_espionage_chapter_icon_motion
		event = wilderness.4505
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}

	on_create = {
	}
}

operation_acquire_asset = {
	target = none
	categories = { op_cat_subterfuge op_cat_government }
	picture = GFX_evt_acquire_asset
	desc = operation_acquire_asset_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 45
		}
		upkeep = {
			energy = 6
		}
	}

	spy_power_cost = 30
	potential = {
		has_nemesis = yes
		target = {
			is_country_type = default
			is_wilderness_empire = no
		}
	}
	allow = {
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = { #Install operatives
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_surveillance
		event = operation.1000
	}
	stage = { #Target identified
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_target
		event = operation.1001
	}
	stage = { #Result
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_motion
		event = operation.1002
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}
	on_create = {
		target = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

operation_evolutionary_predator_procure_dna = {
	target = none
	categories = { op_cat_subterfuge op_cat_government }
	picture = GFX_evt_genetic_modification
	desc = operation_evolutionary_predator_procure_dna_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 45
		}
		upkeep = {
			energy = 6
		}
	}

	spy_power_cost = 30
	potential = {
		owner = { has_origin = origin_evolutionary_predators }
		target = {
			is_primitive = no
			is_synthetic_empire = no #Robots don't have DNA
			species = { NOT = { is_same_species = root.owner.species } }
		}
	}
	allow = {
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = { #Install operatives
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_surveillance
		event = bio.1050
	}
	stage = { #Target identified
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_target
		event = bio.1055
	}
	stage = { #Result
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_motion
		event = bio.1060
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}
	on_create = {
		target = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

operation_extort_favors = {
	target = none
	categories = { op_cat_manipulation op_cat_diplomacy }
	picture = GFX_evt_galactic_senate
	desc = operation_extort_favors_desc
	stages = 3
	spy_power_cost = 35
	resources = {
		category = operations
		cost = {
			influence = 60
		}
		upkeep = {
			energy = 7
		}
	}

	potential = {
		has_nemesis = yes
		owner = { is_homicidal = no }
		target = {
			is_homicidal = no
			is_country_type = default
		}
	}
	allow = {
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t2
		icon = GFX_espionage_chapter_icon_surveillance
		event = operation.6250
	}
	stage = {
		difficulty = @diff_t2
		icon = GFX_espionage_chapter_icon_target
		event = operation.6251
	}
	stage = {
		difficulty = @diff_t2
		icon = GFX_espionage_chapter_icon_document
		event = operation.6252
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}
	on_create = {}
}

operation_smear_campaign = {
	target = none
	categories = { op_cat_manipulation op_cat_diplomacy }
	picture = GFX_evt_smear_campaign
	desc = operation_smear_campaign_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 60
		}
		upkeep = {
			energy = 7
		}
	}

	spy_power_cost = 35
	potential = {
		has_nemesis = yes
		owner = {
			num_communications > 3
		}
		target = { is_country_type = default }
	}
	allow = {
		target = {
			num_communications > 3
			is_fallen_empire = no
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_target
		event = operation.3000
	}
	stage = {
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_document
		event = operation.3001
	}
	stage = {
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_motion
		event = operation.3002
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}
	on_create = {
		target = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

operation_steal_technology = {
	target = none
	categories = { op_cat_subterfuge op_cat_technology }
	picture = GFX_evt_physics_research
	desc = operation_steal_technology_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 80
		}
		upkeep = {
			energy = 8
		}
	}

	spy_power_cost = 40
	potential = {
		has_nemesis = yes
		target = { is_country_type = default }
	}
	allow = {
		custom_tooltip = {
			fail_text = operation_steal_technology_enigmatic_engineering
			owner = {
				NOT = { has_country_flag = cannot_steal_enigmatic_tech@root.target } #set after failing this operation before, due to Enigmatic Engineering
			}
		}
		custom_tooltip = {
			fail_text = operation_steal_technology_too_recent
			NOT = { has_spynetwork_flag = recently_stole_technology }
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t4
		icon = GFX_espionage_chapter_icon_surveillance
		event = operation.1020
	}
	stage = {
		difficulty = @diff_t4
		icon = GFX_espionage_chapter_icon_target
		event = operation.1021
	}
	stage = {
		difficulty = @diff_t4
		icon = GFX_espionage_chapter_icon_security
		event = operation.1022
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = {
			RANDOM_EVENTS = operation_random_events_generic
		}
	}
	on_create = {
		target = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

operation_sabotage_starbase = {
	categories = { op_cat_sabotage op_cat_military }
	picture = GFX_evt_space_station
	desc = {
		trigger = { has_overlord_dlc = no }
		text = operation_sabotage_starbase_desc
	}
	desc = {
		trigger = { has_overlord_dlc = yes }
		text = operation_sabotage_starbase_orbring_desc
	}
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 100
		}
		upkeep = {
			energy = 9
		}
	}

	spy_power_cost = 45
	target = starbase

	potential = {
		has_nemesis = yes
		target = { owner = { is_country_type = default } }
		target = { owner = { is_nomadic = no } }
	}
	target_potential = {
		OR = {
			is_normal_starbase = yes
			is_orbital_ring = yes
		}
	}
	allow = {
		custom_tooltip = {
			fail_text = operation_sabotage_starbase_no_targets
			target = {
				any_owned_starbase = {
					OR = {
						AND = {
							count_starbase_modules = {
								type != shipyard
								count > 0
							}
							count_starbase_modules = {
								type != orbital_ring_shipyard
								count > 0
							}
						}
						has_nonshipyard_starbase_buildings = yes
					}
				}
			}
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	target_allow = {
		custom_tooltip = {
			fail_text = operation_sabotage_starbase_no_targets
			OR = {
				AND = {
					count_starbase_modules = {
						type != shipyard
						count > 0
					}
					count_starbase_modules = {
						type != orbital_ring_shipyard
						count > 0
					}
				}
				has_nonshipyard_starbase_buildings = yes
			}
		}
	}
	stage = {
		difficulty = @diff_t5
		icon = GFX_espionage_chapter_icon_motion
		event = operation.2000
	}
	stage = {
		difficulty = @diff_t5
		icon = GFX_espionage_chapter_icon_target
		event = operation.2001
	}
	stage = {
		difficulty = @diff_t5
		icon = GFX_espionage_chapter_icon_success
		event = operation.2002
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_sabotage_targeted } #Requires a bespoke set of trigger scopes given 'target' is not a country
	}
	on_create = {
		target.owner = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

operation_smuggle_pops = {
	target = none
	categories = { op_cat_provocation op_cat_government }
	picture = GFX_evt_conclave
	desc = operation_smuggle_pops_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 120
		}
		upkeep = {
			energy = 10
		}
	}

	spy_power_cost = 55
	potential = {
		has_biogenesis_dlc = yes
		target = {
			OR = {
				is_country_type = default
				is_country_type = primitive
			}
		}
	}
	allow = {
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}

		custom_tooltip = {
			NAND = {
				owner = {
					is_fanatic_egalitarian = yes
				}
				target = {
					is_fanatic_egalitarian = yes
				}
			}
			fail_text = smuggle_pops_also_fanatic_egalitarians
		}

		custom_tooltip = {
			target = {
				count_owned_pop_amount = {
					limit = {
						can_be_smuggled = yes
					}
					count > 500
				}
			}
			fail_text = smuggle_pops_not_enough_pops
		}
	}

	stage = { #Install operatives
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_surveillance
		event = bio.900
	}
	stage = { #Hide dissidents
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_target
		event = bio.905
	}
	stage = { #Exfiltration
		difficulty = @diff_t5
		icon = GFX_espionage_chapter_icon_motion
		event = bio.910
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}
	on_create = {
		target = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

operation_arm_privateers = {
	categories = { op_cat_provocation op_cat_economy }
	picture = GFX_evt_pirate_armada
	desc = operation_arm_privateers_desc
	stages = 3
	spy_power_cost = 60

	resources = {
		category = operations
		cost = {
			influence = 180
		}
		upkeep = {
			energy = 12
		}
	}

	potential = {
		has_nemesis = yes
		target = {
			is_country_type = default
		}
	}
	allow = {
		custom_tooltip = {
			fail_text = operation_arm_privateers_existing_activity
			target = { NOT = { has_country_flag = target_of_operation_arm_privateers } }
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t6
		icon = GFX_espionage_chapter_icon_surveillance
		event = operation.6200
	}
	stage = {
		difficulty = @diff_t6
		icon = GFX_espionage_chapter_icon_target
		event = operation.6201
	}
	stage = {
		difficulty = @diff_t6
		icon = GFX_espionage_chapter_icon_motion
		event = operation.6202
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}
	on_create = {}
}

operation_crisis_beacon = {
	target = none
	categories = { op_cat_provocation op_cat_technology }
	picture = GFX_evt_unidentified_monster
	desc = operation_crisis_beacon_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 320
		}
		upkeep = {
			energy = 16
		}
	}

	spy_power_cost = 80

	potential = {
		has_nemesis = yes
		target = { is_country_type = default }
		OR = {
			has_crisis = yes #Contingency, Extradimensionals or Prethoryn
			has_global_flag = marauder_crisis_ongoing #Khan
			has_global_flag = gray_goo_crisis_active #Gray Tempest
		}
		NOR = {
			crisis_happened_and_defeated = yes #Contingency, Extradimensionals or Prethoryn
			AND = { #If the Khan is defeated, Crisis Beacon should be hidden until a new crisis happens
				has_global_flag = great_khan_dead
				has_crisis = no
			}
			AND = { #If the Gray Tempest is defeated, Crisis Beacon should be hidden until a new crisis happens
				has_global_flag = graygoo_defeated
				has_crisis = no
			}
		}
	}

	allow = {
		if = {
			limit = {
				owner = { has_country_flag = crisis_beacon_timer }
			}
			custom_tooltip = {
				NOT = {
					any_country = { has_country_flag = crisis_beacon_from@root.owner }
				}
				fail_text = operation_crisis_beacon_too_recent_timer
			}
		}
		else = {
			custom_tooltip = {
				NOT = {
					any_country = { has_country_flag = crisis_beacon_from@root.owner }
				}
				fail_text = operation_crisis_beacon_too_recent
			}
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}

	stage = {
		difficulty = @diff_t8
		icon = GFX_espionage_chapter_icon_target
		event = operation.4000
	}
	stage = {
		difficulty = @diff_t8
		icon = GFX_espionage_chapter_icon_motion
		event = operation.4001
	}
	stage = {
		difficulty = @diff_t8
		icon = GFX_espionage_chapter_icon_success
		event = operation.4002
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_deepcover }
	}
	on_create = {}
}

### Galactic Imperium
operation_weaken_galactic_empire = {
	target = none
	categories = { op_cat_subterfuge op_cat_technology }
	picture = GFX_evt_galactic_empire
	desc = operation_weaken_galactic_empire_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 60
		}
		upkeep = {
			energy = 7
		}
	}

	spy_power_cost = 35
	potential = {
		has_nemesis_or_control_fragment = yes
		has_galactic_emperor = yes
		target = { is_galactic_emperor = yes }
		root.owner = {
			is_galactic_community_member = yes
			is_galactic_emperor = no
		}
	}
	allow = {
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_motion
		event = operation.6000
	}
	stage = {
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_surveillance
		event = operation.6005
	}
	stage = {
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_target
		event = operation.6010
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = {
			RANDOM_EVENTS = operation_random_events_generic
		}
	}
	on_create = { }
}

operation_target_seditionists = {
	target = none
	categories = { op_cat_subterfuge op_cat_diplomacy }
	picture = GFX_evt_smear_campaign
	desc = operation_target_seditionists_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 60
		}
		upkeep = {
			energy = 7
		}
	}

	spy_power_cost = 35
	potential = {
		has_nemesis_or_control_fragment = yes
		has_galactic_emperor = yes
		root.owner = { is_galactic_emperor = yes }
		target = { is_galactic_community_member = yes }
	}
	allow = {
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
		custom_tooltip = {
			target = {
				OR = {
					is_rival = root.owner
					root.owner = { is_rival = prev }
					any_owned_leader = {
						is_undermining_imperial_authority = yes
					}
				}
			}
			fail_text = operation_target_seditionists_requires_sedition
		}
	}
	abort = {
		OR = {
			has_galactic_emperor = no
			root.owner = { is_galactic_emperor = no }
			target = { is_galactic_community_member = no }
		}
	}

	stage = {
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_motion
		event = operation.6300
	}
	stage = {
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_surveillance
		event = operation.6305
	}
	stage = {
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_target
		event = operation.6310
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = {
			RANDOM_EVENTS = operation_random_events_target_seditionists
		}
	}
	on_create = { }
}

operation_spark_rebellion = {
	target = none
	categories = { op_cat_subterfuge op_cat_technology }
	picture = GFX_evt_open_revolt
	desc = operation_spark_rebellion_desc
	stages = 5

	resources = {
		category = operations
		cost = {
			influence = 250
		}
		upkeep = {
			energy = 14
		}
	}

	spy_power_cost = 70
	potential = {
		has_nemesis_or_control_fragment = yes
		has_galactic_emperor = yes
		target = { is_galactic_emperor = yes }
		root.owner = {
			is_galactic_community_member = yes
			is_galactic_emperor = no
		}
	}
	allow = {
		imperial_authority <= 50
		# civil war is not currently ongoing
		custom_tooltip = {
			fail_text = spark_rebellion_already_sparked
			NOT = {
				any_playable_country = {
					any_war = {
						using_war_goal = {
							type = wg_galactic_civil_war_loyalists
							owner = attacker
						}
					}
				}
			}
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	abort = {
		has_global_flag = abort_spark_rebellion # set for 10 days by emperor.101
	}
	stage = {
		difficulty = @diff_t7
		icon = GFX_espionage_chapter_icon_motion
		event = operation.6100
	}
	stage = {
		difficulty = @diff_t7
		icon = GFX_espionage_chapter_icon_target
		event = operation.6105
	}
	stage = {
		difficulty = @diff_t7
		icon = GFX_espionage_chapter_icon_motion
		event = operation.6110
	}
	stage = {
		difficulty = @diff_t7
		icon = GFX_espionage_chapter_icon_motion
		event = operation.6115
	}
	stage = {
		difficulty = @diff_t7
		icon = GFX_espionage_chapter_icon_success
		event = operation.6120
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = {
			RANDOM_EVENTS = operation_random_events_generic
		}
	}
	on_create = { }
}

#Stellar Devourer
operation_consume_star = {
	categories = { op_cat_sabotage op_cat_military }
	picture = GFX_evt_stellarites
	desc = operation_consume_star_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 250
		}
		upkeep = {
			energy = 9
		}
	}

	spy_power_cost = 60

	potential = {
		owner = {
			any_owned_planet = {
				has_modifier = stellar_devourer_trophy
			}
		}
		target = { is_primitive = no }
		target = { is_nomadic = no }
	}
	allow = {
		custom_tooltip = {
			fail_text = operation_consume_star_black_hole
			target = {
				capital_star = {
					NOT = { is_planet_class = pc_black_hole }
				}
			}
		}
		custom_tooltip = {
			fail_text = operation_consume_star_already_know
			target = {
				NOT = { has_country_flag = studied_stellarite_infestation }
			}
		}
		custom_tooltip = {
			fail_text = operation_consume_star_already_infested
			target = {
				NOT = { has_country_flag = infested_star }
			}
		}
		custom_tooltip = {#Techincally you can't have a colony in a system with a dysonsphere but I just want to make sure no weirdness happens.
			fail_text = operation_consume_star_no_dysonsphere
			target = {
				capital_star = {
					solar_system = {
						NOT = { has_star_flag = dyson_sphere_built }
					}
				}
			}
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t7
		icon = GFX_espionage_chapter_icon_motion
		event = situation.1125
	}
	stage = {
		difficulty = @diff_t7
		icon = GFX_espionage_chapter_icon_target
		event = situation.1130
	}
	stage = {
		difficulty = @diff_t7
		icon = GFX_espionage_chapter_icon_success
		event = situation.1135
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_deepcover }
	}
	on_create = {
		target = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

#Kaleidoscope event chain
operation_kaleidoscope = {
	categories = { op_cat_sabotage op_cat_economy }
	picture = GFX_evt_vortex
	desc = operation_kaleidoscope_desc
	stages = 2

	resources = {
		category = operations
		cost = {
			influence = 20
		}
		upkeep = {
			energy = 5
		}
	}

	spy_power_cost = 10
	potential = {
		has_global_flag = kaleidoscope_started
		owner = { country_has_situation = { SITUATION = situation_kaleidoscope } }
		target = { is_primitive = no }
		target = { is_nomadic = no }
		target = { is_wilderness_empire = no }
	}
	allow = {
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
		target = {
			custom_tooltip = {
				fail_text = operation_kaleidoscope_previous_owner
				capital_scope = {
					NOT = { has_active_building = building_planetary_shield_generator }
				}
			}
			custom_tooltip = {
				fail_text = operation_kaleidoscope_previous_owner
				NOT = { has_country_flag = previous_kaleidoscope_owner }
			}
		}
	}
	stage = {
		difficulty = @diff_t0
		icon = GFX_espionage_chapter_icon_target
		event = situation.2020
	}
	stage = {
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_success
		event = situation.2021
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_deepcover }
	}
	on_create = {
		root.owner = {
			set_timed_country_flag = {
				flag = previous_kaleidoscope_owner
				days = @operationTargetedByTimer
			}
			set_timed_country_flag = {
				flag = gave_kaleidoscope_to@root.target
				days = @operationTargetedByTimer
			}
		}
		target = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

operation_bodysnatcher_prepare_invasion = {
	target = none
	categories = { op_cat_sabotage op_cat_military }
	picture = GFX_evt_hive_mind
	desc = operation_bodysnatcher_prepare_invasion_desc
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 180
		}
		upkeep = {
			energy = 12
		}
	}

	spy_power_cost = 100

	potential = {
		owner = { has_valid_civic = civic_hive_bodysnatcher }
		target = {
			is_nomadic = no
			is_primitive = no
			is_synthetic_empire = no
			is_nomadic = no
		}
	}
	allow = {
		custom_tooltip = {
			target = { NOT = { has_active_tradition = tr_subterfuge_nda } }
			fail_text = operation_invasion_impossible
		}

		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}

		custom_tooltip = {
			target = {
				NOR = {
					has_country_flag = infiltrated_bodysnatcher_0@root.owner
					has_country_flag = infiltrated_bodysnatcher_1@root.owner
					has_country_flag = infiltrated_bodysnatcher_3@root.owner
					has_country_flag = infiltrated_bodysnatcher_5@root.owner
					has_country_flag = infiltrated_bodysnatcher_20@root.owner
				}
			}
			fail_text = operation_invasion_prepared
		}
	}
	stage = { #Install operatives
		difficulty = @diff_t1
		icon = GFX_espionage_chapter_icon_surveillance
		event = bio.800
	}
	stage = { #Target identified
		difficulty = @diff_t3
		icon = GFX_espionage_chapter_icon_target
		event = bio.805
	}
	stage = { #Result
		difficulty = @diff_t4
		icon = GFX_espionage_chapter_icon_motion
		event = bio.810
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
	}
	on_create = {
		target = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}

operation_seize_waystation = {
	categories = { op_cat_provocation op_cat_military }
	picture = GFX_evt_waystation
	desc = operation_seize_waystation_desc
	
	stages = 3

	resources = {
		category = operations
		cost = {
			influence = 150
		}
		upkeep = {
			energy = 20
		}
	}

	spy_power_cost = 75
	target = starbase

	potential = {
		has_nomads_dlc = yes
		target = { owner = { is_country_type = default } }
		target = { owner = { is_nomadic = yes } }
	}
	target_potential = {
		is_waystation_starbase = yes
		fleet = { is_in_sensor_range_of_country = root.owner }
	}
	allow = {
		custom_tooltip = {
			fail_text = operation_seize_waystation_no_targets
			target = {
				owner = {
					any_owned_fleet = {
						is_waystation_ship = yes
					}
				}
			}
		}
		custom_tooltip = {
			is_running_espionage_operation = no
			fail_text = operation_one_at_a_time
		}
	}
	stage = {
		difficulty = @diff_t4
		icon = GFX_espionage_chapter_icon_motion
		event = nomads.8010
	}
	stage = {
		difficulty = @diff_t6
		icon = GFX_espionage_chapter_icon_target
		event = nomads.8015
	}
	stage = {
		difficulty = @diff_t7
		icon = GFX_espionage_chapter_icon_success
		event = nomads.8020
	}
	on_roll_failed = {
		standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_sabotage_targeted } #Requires a bespoke set of trigger scopes given 'target' is not a country
	}
	on_create = {
		target.owner = {
			set_timed_country_flag = {
				flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
				days = @operationTargetedByTimer
			}
		}
	}
}
