enable_operative_missions = {
	enable = {
		num_of_operatives > 0
	}
	abort = { always = no }

	# Low generic fallback only. Real enemy targeting comes from run_generic_operation.
	ai_strategy = {
		type = operative_mission
		mission = build_intel_network
		value = 60
	}

	# Do not let generic counter-intel compete too hard with foreign spying.
	ai_strategy = {
		type = operative_mission
		mission = counter_intelligence
		value = 65
		mission_target = ROOT
	}
}

run_generic_operation = {
	enable = {
		NOT = { check_variable = { generic_operation_target = 0 } }
		NOT = { check_variable = { ai_operations^num = 0 } }
		num_of_operatives > 0

		var:generic_operation_target = {
			exists = yes
			has_capitulated = no
			NOT = { is_ally_with = PREV }
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = operative_operation
		operation = var:generic_operation_type_to_run
		value = 1200
		operation_target = var:generic_operation_target
	}

	ai_strategy = {
		type = operation_equipment_priority
		value = 100
	}

	ai_strategy = {
		type = operative_mission
		mission = build_intel_network
		value = 1200
		mission_target = var:generic_operation_target
	}
}

run_generic_operation_add_more_operatives = {
	enable = {
		num_of_operatives > 2
		NOT = { check_variable = { generic_operation_target = 0 } }
		NOT = { check_variable = { ai_operations^num = 0 } }

		var:generic_operation_target = {
			exists = yes
			has_capitulated = no
			NOT = { is_ally_with = PREV }
		}
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = operative_mission
		mission = build_intel_network
		value = 1050
		mission_target = var:generic_operation_target
		num_operatives = 2
	}
}

run_generic_rescue_operation = {
	enable = {
		NOT = { check_variable = { rescue_operative_from = 0 } }
	}

	abort_when_not_enabled = yes

	ai_strategy = {
		type = operative_operation
		operation = operation_rescue_operative
		value = 1100
		operation_target = var:rescue_operative_from
	}

	ai_strategy = {
		type = operation_equipment_priority
		value = 100
	}

	ai_strategy = {
		type = operative_mission
		mission = build_intel_network
		value = 950
		mission_target = var:rescue_operative_from
	}
}

keep_counterintelligence_active = {
	enable = {
		num_of_operatives > 1
	}
	abort = { always = no }

	# Keep one defensive bias at home, not random allied countries.
	ai_strategy = {
		type = operative_mission
		mission = counter_intelligence
		value = 300
		mission_target = ROOT
	}
}
