; SS-N-14 Silex and MILAS ASW/ASUW Doctrine For -Reinforce Alert- DWX Add On ver 1.41.
; separate modes parameters added

var PreenableCourse
var RunToEnable
var Runout
var lastX
var lastY
var run
var Waypoints
var Empty
var initX
var initY
var Mode
var Recognition
VAR NUM_TH
VAR ZZZConf
var TX
VAR TY
var Spoofed
var DecoyLogic
var talt
var temp
var Delta
var zcrs
var FinalPhazeN
var AltCruise
var SpdCruise
var Offrun
var gothim

IF INIT THEN {
	NUM_TH = 0
	ZZZConf = 0
	Initx = ownx
	Inity = owny
	Empty = False
	lastX = OwnX
	lastY = OwnY
	RunToEnable = 100
	Spoofed = RND 100
	Runout = -1
	FinalPhazeN = 3000
	AltCruise = 330
	SpdCruise = 614
	Offrun = 50000
} elseIF ( Runout != -1 ) AND ( run >= Runout ) THEN {
	Runout = -1
	Detonate
} ELSE {
IF Recognition == 0 THEN {
	Recognition = 1
IF 5000 > XYrng ( WayPtX - Initx ) ( WayPtY - Inity ) Then {
	Mode = 1
} ELSE {
	Mode = 0
} Endif
If OwnName $= "MILAS ASROC User" Then {
		DecoyLogic = 70
	If Mode == 1 Then {
		AltCruise = 659
		SpdCruise = 525
		Offrun = 60000
	} ElseIf Mode == 0 Then {
		AltCruise = 36
		SpdCruise = 604
		Offrun = 150000
	} Endif
} Endif
If OwnName $= "SS-N-14 Silex [User]" Then {
		DecoyLogic = 50
	If Mode == 1 Then {
		AltCruise = 1317
		SpdCruise = 614
		Offrun = 55055
	} ElseIf Mode == 0 Then {
		AltCruise = 53
		SpdCruise = 614
		Offrun = 55055
	} Endif
} Endif
} ENDIF
run += xyrng ( OwnX - lastX ) ( OwnY - lastY )
	lastX = OwnX
	lastY = OwnY
IF run >= offrun THEN {
	Shutdown
} endif
IF RunToEnable != -1 THEN {
IF run >= ( RunToEnable - 500 ) THEN {
	RunToEnable = -1
If Mode Then {
	SensorEnable "WepsActivate1" 1
	SensorEnable "WepsActivate2" 1
} ELSE {
	SensorEnable "Wep Radar3" 1
	SensorEnable "Wep IR" 1
} ENDIF
} ENDIF
} ENDIF
IF NEWTRACK AND NOT ( TgtClass $= "Missile" ) THEN {
	IF MODE THEN {
		SETPRIORITY 255
		FireBest
	} ELSE {
		IF TgtType $= "CM" THEN {
			IF Spoofed > DecoyLogic THEN {
				SetTactic "TH_ST"
			} ELSEIF Spoofed <= DecoyLogic THEN {
				SetTactic "SBROS"
		} ENDIF
	} ELSE {
		gothim = 1
		SetTactic "TH_ST"
		} ENDIF
	} ENDIF
} ENDIF
IF WeaponAway THEN {
	zcrs = owncrs
	Empty = 1
} ENDIF
IF Empty THEN {
SETPRIORITY 254 Setcrs zcrs
SETPRIORITY 247 Setalt minalt
SETPRIORITY 254 Setpitch -3
IF Ownalt < 10 THEN { Detonate } ENDIF
} elseIF NUM_TH == 0 THEN {
IF Waypoints THEN { SETPRIORITY 247 TerminalHome
} ELSE { SETPRIORITY 247 SetCrs PreenableCourse } ENDIF
} ENDIF
IF NUM_TH != 0 THEN {
temp = XYRng ( tx - ownx ) ( ty - owny )
if ( temp > 1000 ) and ( temp < 5000 ) then {
SETPRIORITY 250 steerxy ( tx - ownx ) ( ty - owny )
DELTA = ( TALT - OWNALT + 30 )
temp = XYBRG ABS DELTA ( temp * 3.28 )
if DELTA < 0 then { temp = ( -1 * temp ) } endif
SETPRIORITY 253 SETPERSIST 1 SETPITCH TEMP
} endif
} ENDIF
} ENDIF
	SetPriority 255 SetSpd SpdCruise
If Not Gothim Then {
	SetPriority 255 SetAlt AltCruise
} endif
