; Reinforce Alert Shkval Doctrine for add-on v.1.42

var RunToEnable
var PreenableCourse
var SearchDepth
var Homing
var run
var Enabled
var FFF
var lastX
var lastY
var ImpactTime
var CrushDpth
var Explode
var TorpMaxDepth
var Regime
Var OrdSpd
var WNA
var MxRng
var DELTA
var SSS
Var temp
var ceiling
var AcousticMode
var wps

IF INIT THEN {
	Explode = RND 10
	ImpactTime = 0
	Homing = 0
	Enabled = 0
	FFF = 1
	MxRng = 1
} elseIF RUN > MxRng THEN {
	SETPRIORITY 255 SHUTDOWN
} ELSE {
	IF FFF THEN {
		FFF = 0
		WNA = 1
		lastX = OwnX
		lastY = OwnY
If Ceiling == 0 Then {
	IF ( OwnName $= "Shkval Torpedo U" ) Then { TorpMaxDepth = -1435 MxRng = 12501 SearchDepth = ( SearchDepth * 3.28 )
		} ELSEif ( OwnName $= "Great Prophet Torpedo U" ) Then { TorpMaxDepth = -656 MxRng = 9999 SearchDepth = ( SearchDepth * 3.28 )
			} ELSEif ( OwnName $= "Barracuda Torpedo U" ) Then { TorpMaxDepth = -984 SearchDepth = ( SearchDepth * 3.28 ) MxRng = 10995
		} ENDIF
} ELSE {
	IF ( OwnName $= "Shkval Torpedo U" ) Then { TorpMaxDepth = -1435 MxRng = 12501 SearchDepth = ( SearchDepth )
		} ELSEif ( OwnName $= "Great Prophet Torpedo U" ) Then { TorpMaxDepth = -656 MxRng = 9999 SearchDepth = ( SearchDepth )
			} ELSEif ( OwnName $= "Barracuda Torpedo U" ) Then { TorpMaxDepth = -984 SearchDepth = ( SearchDepth ) MxRng = 10995 } ENDIF
	If Not AcousticMode Then {
		SearchDepth = ( SearchDepth - 3280 )
	} Endif
} ENDIF
IF ( OwnAlt <= TorpMaxDepth ) THEN { CrushDpth = 1 ImpactTime = ( Time + 10 ) } ENDIF
If RunToEnable < 1828 Then { RunToEnable = 1828 } endif

If SearchDepth < TorpMaxDepth Then {
	Regime = 2
	SearchDepth = ( SearchDepth + 3280 )
IF SearchDepth < TorpMaxDepth THEN {
	SearchDepth = ( TorpMaxDepth + 10 )
	} ENDIF
} ELSE {
	Regime = 1
	} Endif
} Endif
run += xyrng ( OwnX - lastX ) ( OwnY - lastY )
lastX = OwnX
lastY = OwnY
SETPRIORITY 240 SetCrs PreEnableCourse
; ------------------------------------------------------------
IF NEWTRACK AND ( Homing == 0 ) AND ( REGIME == 1 ) THEN {
	IF ( ( TgtClass $= "Weap" ) AND ( TgtType $= "CM" ) ) THEN {
		wps = 1
		Detonate
		TimedDetonateTgt ( Time + 1 )
	} ENDIF
IF ( ( TgtClass $= "Mine" ) AND ( TgtType $= "Mine" ) ) THEN {
		wps = 1
		Detonate
} ENDIF
	IF NOT WPS THEN {
		SetTactic "ShkvalAttack" Homing = 1
	} ENDIF
} ENDIF
; -------------------------------------------------------------
if WNA THEN {
SETPRIORITY 240 SetSpd 20
IF ( abs ( OwnCrs - PreEnableCourse ) < 1 ) AND ( abs ( OwnAlt - SearchDepth ) < 30 ) AND ( 3 > abs pitch ) THEN {
	WNA = 0
	SETPRIORITY 240 SetSpd MaxSpd
	SETPRIORITY 252 Setalt SearchDepth
} else {
	DELTA = ( SearchDepth - OWNALT )
	sss = ABS DELTA
if sss > 300 then { temp = 45 } else { temp = XYBRG sss ( 300 * 3.28 ) } endif
	if DELTA < 0 then { temp = ( -1 * temp ) } endif
	SETPRIORITY 250 SETPITCH TEMP
	} ENDIF
} ENDIF
IF ( CrushDpth == 1 ) AND ( TIME >= ImpactTime ) THEN {
	IF Explode >= 5 THEN { Detonate } ELSE { Shutdown } ENDIF
} ENDIF
if NOT Enabled AND ( run > RunToEnable ) THEN {
	If Regime == 2 Then {
		SETPRIORITY 255 Detonate
	} ELSE {
		Enabled = 1
		ENABLE
	} ENDIF 
} ENDIF
} ENDIF
