; RA v.1.41 Torpedo Terminal Phase.

var N
var j
var Done

FUNC DATA {
SetEntVar "Trng" tgtrng
SetEntVar "tbrg" tgtbrg
SetEntVar "talt" tgtalt
SetEntVar "TSILOS" tgtsilos
SetEntVar "numbNG" N
SetEntVar "TConf" tgtconf
}
if init then { 
	if not j then { j = 1 N = ( time + rnd 100 + rnd 500 ) } endif
} ELSEIF LOSTTRACK and ( getEntVar "numbNG" == N ) THEN {
	SetEntVar "TConf" 0
} ELSE {
	IF ( TGTAGE > 14 ) or ( not getEntVar "enabled" ) THEN { DROP
} ELSEIF ( Tgtconf < getEntVar "tconf" ) and ( getEntVar "numbNG" != N ) THEN {
	SetEntVar "FDROPA" 0
	DROP
} ELSEIF ( getEntVar "numbNG" == N ) and getEntVar "FS" THEN {
	SetEntVar "TConf" 0
	SetEntVar "FS" 0
	DROP
} ELSE {
	SetEntVar "Homing" 1
	SetEntVar "Tage" tgtage
if ( TGTRNG < 180 ) or ( getEntVar "fterm" ) THEN {
	if getEntVar "FKORIDOR" then {
		DATA
		SetPriority 253 setcrs tgtbrg
} else {
;	If NOT Done AND ( GetEntVar "AcousticMode" == 1 ) Then {
	If NOT Done Then {
		SensorEnable "268" 1
		Done = 1
	} Endif
	SetPriority 255 TerminalHome
IF ( TgtRng < 50 ) AND ( TgtSilos > 0 ) THEN {
;	DebugOut "Contactless detonator"
	Drop
	SetPriority 255	Detonate
} endif
	} endif
} ELSE {
	DATA
		} endif
	} endif
} endif