var PreenableCourse
var RunToEnable
var Runout
var lastX
var lastY
var run
VAR IT
VAR ZALT
VAR NUM_TH
VAR ZZZConf
var TX
VAR TY
var talt
var temp
var Delta
var AltCruise
var PreSet
var DescentRNG
var fff
var TSD
var DOtkl
var temp1
var tname
var um
var FinalPhazeN
var FinalPhazeV

IF INIT THEN {
fff = 1
lastX = OwnX
lastY = OwnY
NUM_TH = 0
ZZZConf = 0
RunToEnable = 100000
Runout = -1
IT = ( TIME + 5 )
; ZALT = ( MAXALT * 3.28 )
ZALT = ( MAXALT )
PreSet = 1
tsd = -1
dotkl = 2000000
UM = 97
FinalPhazeN = 3000
FinalPhazeV = 7000
} ELSEIF ( ( Runout != -1 ) AND ( run >= Runout ) ) or ( RUN > 300024 ) THEN { SHUTDOWN
} ELSEIF ( OwnAlt >= ( ZALT + 300 ) ) THEN { SHUTDOWN
} ELSEif ( tsd != -1 ) AND ( TSD < TIME ) THEN { DETONATE
} else {
IF OwnAlt < 0 THEN { DETONATE } ENDIF
IF PreSet THEN {
SetPersist 2 SetPriority 240 SetSpd ( MaxSpd * 0.85 )
PreSet = 0
} ENDIF
run += xyrng ( OwnX - lastX ) ( OwnY - lastY )
lastX = OwnX lastY = OwnY

IF RunToEnable != -1 THEN {
	IF run > RunToEnable THEN {
		ENABLE
		RunToEnable = -1
	} ENDIF
} ENDIF

IF NEWTRACK then {
	TEMP = RND 100
	tx = tgtx
	ty = tgty
	talt = tgtalt
	IF fff Then { fff = 0
		Runout = ( tgtrng * 1.2 )
		PreenableCourse = XYBRG ( tx - ownx ) ( ty - owny )
		IF TgtRng >= 50000 Then { DescentRNG = ( TgtRng - 50000 ) } endif
		RunToEnable = ( TgtRNG - ( 20000 - ( RND 2260 ) ) )
		tname = targetname
		SETTACTIC "SBROS"
	} ELSEif targetname == tname then { UM = 101
		SetTactic "TH_ST_L"

	} elseif ( tgtconf >= ZZZConf ) AND ( UM < TEMP ) then {

		ZZZConf = tgtconf NUM_TH = time
		SetTactic "TH_ST_L"
	} else {
		SETTACTIC "SBROS"
	} endif
} ENDIF

IF NUM_TH == 0 THEN {
	IF IT < TIME THEN {
		SETPRIORITY 220 SetCrs PreenableCourse
		SETPRIORITY 220 SETSPD MAXSPD
		IF RUN < DescentRNG THEN { AltCruise = 32800 } ELSE { AltCruise = 50 } ENDIF
		SETPRIORITY 220 SETALT AltCruise
	} endif
} else {
	temp = XYRng ( tx - ownx ) ( ty - owny )
	temp1 = temp
	if ( TEMP > 7000 ) AND ( temp < 20000 ) 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 252 SetSpd MaxSpd
		SETPRIORITY 252 SETPITCH TEMP
	} ELSE {
		SETPRIORITY 220 SetCrs PreenableCourse
		SETPRIORITY 220 SETSPD MAXSPD
		SETPRIORITY 220 SETALT AltCruise
	} endif
	tsd = ( OWNSPD * 0.514444 )
	TEMP = ( pitch * 0.01745 )
	TEMP = cos TEMP
	tsd = ( tsd * TEMP )
	IF tsd == 0 then { tsd = 0.00001 } endif
	tsd = ( TEMP1 / tsd )
	tsd = ( time + tsd + 1 )
} endif
} ENDIF