#N@FRED3 Controller 
#I@Distance Bearing Elevation Ranger Sky Water Friend FRED Attack Hunt Move No Not Dive
#O@Thrust Fire Turn NextTarg Hovoff FL FR AR AL Strength Grab
#MaxDist=200 MaxDist2=1000 MinDist=100 Afterburn=5 
#Maxhov=30 Minhov=20 Maxhov2=200 ABHov=5 Hovoff=Moveout Strength=10000 
#FRED & Hunt ? NextTarg=1 : NextTarg=0
#FRED & Move & !No -> Moveout=1;
#FRED & Move & No -> Moveout=0;
#FRED & Attack & !Not -> Wep=1;
#FRED & Attack & Not -> Wep=0;
#FRED & Dive ? Drop=1 : Drop=0
#Distance<MaxDist -> Maxang=15 Minang=-15;
#Distance>MaxDist2 -> Maxang=1 Minang=-1;
#Distance>MaxDist2 -> Maxang=7 Minang=-7;
#Friend==18017844 ? Holdfire=1 : Holdfire=0
#(Ranger == 10000) & (Water != 10000) -> Ranger = Water ;
#(Ranger<10)&(Moveout==0) ? Grab=1 : Grab=0
#Thrust = (((Distance > MaxDist) * (Distance < MaxDist2) + ((Distance > MaxDist2) * Afterburn)) -
#(Distance < MinDist) * (Distance != 0)) * Moveout
#Turn=sgn(Bearing) * Moveout
#Fire=((Minang < Bearing)*(Bearing < Maxang) * (Distance != 0) * (Minang < Elevation) * 
#(Elevation < Maxang)) * Wep * !Holdfire
#Drop==1 ? Divedown=-10 : Divedown=0
#Flip=Sky <40 
#Height=sin(Elevation)*Distance
#(Height < 20) & (Height > -40) ? Chaser=1 : Chaser=3
#Chased=(Distance != 0)*0.01
#Chase=(( (Height>=(-30))*Chaser-(Height<=(-20))*Chaser))*(Distance != 0)*!(Ranger<Minhov | Flip)+Chased
#Hovercontroller=((Ranger<Minhov)-((Ranger>Maxhov)*(Ranger<Maxhov2)+
#((Ranger>Maxhov2)*ABHov)))*!Chase+Chase+Divedown

######Self Correction Hover Code E1

#Pitch=extangp()
#Roll=extangr()
#
#Sc = 4 
#Pitch1=-3.5 
#Pitch2=3.5 
#Roll1=-3.5 
#Roll2= 3.5
#PC =(Pitch > Pitch1) - (Pitch < Pitch2)
#RC = (Roll > Roll1) - (Roll < Roll2)
#Ha = PC == 0 & RC == 0
#Hover = Ha * Hovercontroller + Flip
#I= -((90 < Roll) | (-90 > Roll))
#I= ((90 > Roll) | (-90 < Roll))
#Flipover = Roll > 170 | Roll < -170
#Flipover == 1 -> F=6;
#Flipover == 0 -> F=0;
#FL = sgn(PC - RC*I)/Sc + Hover - F
#FR = sgn(PC + RC*I)/Sc + Hover + F
#AR= sgn(-PC + RC*I)/Sc + Hover+ F
#AL = sgn(-PC - RC*I)/Sc + Hover -F

E=entity()
HoverController=0 #This is the user's input replace this
rangerFilter(E:getConstraints())
rangerDefaultZero(0)
Sky=rangerOffset(100,E:pos(),E:up()):distance()


Scale=4
Toll=3.5 #Tollerance
Roll=E:angles():roll()
Pitch=E:angles():pitch()
PC=(Pitch>-Toll)-(Pitch<Toll)
RC=(Roll>-Toll)-(Roll<Toll)
Ha=!PC & !RC
Flip=Sky <40 
Hover=Ha * HoverController + Flip
I= -((90<Roll)|(-90>Roll))
I= ((90>Roll)|(-90<Roll))
Flipover= Roll>170 | Roll<-170
if(Flipover){F=6}else{F=0}
FL=sign(PC-RC*I)/Scale+Hover-F
FR=sign(PC+RC*I)/Scale+Hover+F
AR=sign(-PC+RC*I)/Scale+Hover+F
AL=sign(-PC-RC*I)/Scale+Hover-F

