; RA RBU-Rocket Doctrine /KPV_1974/

var Initx
var Inity
var apogei
var DropRng
var CurRng
var OrdCrs
VAR Y
VAR TEMP
VAR const2
var const3
var const4
var tenab
var delta
var altsbrosa
var spd

IF Init THEN {
	tenab = ( time - 1 )
	Initx = ownx
	Inity = owny
	OrdCrs = GetEntVar "PreenableCourse"

	DropRng = xyrng ( Tgtx - Initx ) ( Tgty - Inity )

;	DEBUGOUT "DROP RNG/TgtAlt="
;	debugvalueout ( DropRng / TgtAlt )

	IF ( ( DropRng / TgtAlt ) >= -4.66 ) THEN {
	Shutdown
	} ENDIF

	IF DropRng <= 0 THEN { DropRng = 1 } ENDIF
	apogei = ( DropRng / 4 )
	const2 = ( DropRng / 2 )
	const3 = ( const2 * const2 )
	const4 = ( 3.28 * apogei )

	altsbrosa = ( apogei / 2 )

;	spd = SQRT ( DropRng * 10 )
	spd = ( DropRng / 10 )
	IF ( spd < 200 ) THEN {
	spd = 200
	} ENDIF


} ELSEIF WeaponAway THEN { Shutdown
} ELSE {
	CurRng = xyrng ( ownx - Initx ) ( owny - Inity )

;	DEBUGOUT "CURRENT DATA MISSILE RNG / ALT:"
;	debugvalueout Currng
;	debugvalueout OwnAlt


	SETPRIORITY 250 SetCrs OrdCrs
	SETPRIORITY 253 SetSpd spd


		IF CurRng < const2 THEN {


			temp = ( CurRng - const2 )
			temp = ( temp * temp )
			temp = ( temp / const3 )
			temp = ( 1 - TEMP )
			
			if temp > 0 then {
			Y = ( const4 * SQRT temp )
			DELTA = ( y - OWNALT )
			temp = XYBRG ABS DELTA ( 2500 )
				if DELTA < 0 then {
				temp = ( -1 * temp )
				} endif
			SETPRIORITY 255
			SetPitch temp
			} endif
		} ELSE {
		DELTA = ( altsbrosa - OWNALT )
		temp = XYBRG ABS DELTA ( ( DropRng - CurRng ) * ( DropRng / CurRng ) * 3.28 )
		temp = ( -1 * temp )

			if ( ( DELTA >= 0 ) OR ( CurRng >= ( DropRng * 0.8 ) ) ) then {
			SETPRIORITY 255 firebest
			} endif

		SETPRIORITY 255
		SetPitch temp
		} ENDIF
} ENDIF