@name Cenn's Hovercraft
@inputs ADVPOD:wirelink
@outputs Lig
@persist [O PE EIW]:entity Heat Heatmul MovSpeed FanRot StrY EsP EpI MaxSpeed Mode MiPit CRS
@trigger 
@model models/Gibs/airboat_broken_engine.mdl
runOnTick(1)
if (dupefinished()) {reset()}
if (first()) {O=owner() EIW=entity():isWeldedTo()
holoCreate(1)
holoPos(1,EIW:toWorld(vec(0,EIW:boxSize():y(),0)))
holoCreate(2)
holoPos(2,EIW:toWorld(vec(0,-EIW:boxSize():y(),0)))
holoParent(1,EIW)
holoParent(2,EIW)



#models/hunter/misc/platehole1x1a.mdl
holoCreate(3)
holoModel(3,"models/hunter/misc/platehole1x1a.mdl")
holoPos(3,entity():toWorld(vec(30,0,0)))
holoAng(3,entity():toWorld(ang(90,0,0)))
holoScale(3,vec(0.5,0.5,0.5))
holoParent(3,entity())
#models/mechanics/wheels/wheel_smooth_24f.mdl
holoCreate(4)
holoModel(4,"models/mechanics/wheels/wheel_smooth_24f.mdl")
holoPos(4,entity():toWorld(vec(30,0,0)))
holoAng(4,entity():toWorld(ang(90,0,0)))
holoScale(4,vec(0.95,0.95,0.2))
holoParent(4,entity())

holoAlpha(1,0)
holoAlpha(2,0)
MaxSpeed = 1
}
function number altitude(Pos:vector){
rangerHitEntities(0)
Rangetemp = rangerOffset(20000,Pos,vec(0,0,-1))
return Rangetemp:distance()    
}
function vector groundAltitude(Pos:vector){
rangerHitEntities(0)
Rangetemp = rangerOffset(20000,Pos,vec(0,0,-1))
return Rangetemp:position()    
}
function entity:moveTo(Tarpos:vector){
This:applyForce(((Tarpos-This:pos())*15-This:vel())*(This:mass()*MovSpeed))    
}
function entity:hover(Altitude:number){
if(This:pos():z() < groundAltitude(This:pos()):z()+Altitude){
This:applyForce(((vec(This:pos():x(),This:pos():y(),groundAltitude(This:pos()):z()+Altitude)-This:pos())*15-This:vel())*(This:mass()*0.1))    
}
}
function entity:turnTo(Tarang:angle){
V = This:toLocal(rotationVector(quat(Tarang)/quat(This))+This:pos())
This:applyTorque((150*V - 15*This:angVelVector())*This:inertia()/3)  
}
runOnTick(1)
Active = ADVPOD:number("Active")
W  = ADVPOD:number("W")
S  = ADVPOD:number("S")
A  = ADVPOD:number("A")
D  = ADVPOD:number("D")
Pitch = (entity():vel():length() * 0.1 ) 
SH = ADVPOD:number("Shift")
SP = ADVPOD:number("Space")
M1 = ADVPOD:number("Mouse1")
M2 = ADVPOD:number("Mouse2")
Alt = ADVPOD:number("Alt")
PE = ADVPOD:entity("Entity")
EsP = Pitch + EpI
if (Active) {
if (changed(Alt) & Alt==1) {Mode++
PE:printDriver("Mode change to : " +Mode)
}
if (Lig < 255) {Lig++} 

if (Mode > 2) {Mode=1}
if (Mode==1) {MiPit = 0}
if (Mode==2) {
if (SP==1) {MiPit++} elseif (SH==1) {MiPit--}
}

holoAng(4,entity():toWorld(ang(90,0,0)):rotateAroundAxis(entity():forward(),FanRot)) 
EIW:hover(50) EIW:setMass(3000)
EIW:turnTo(ang(0,StrY,MiPit))
if (changed(M1)) {MaxSpeed = MaxSpeed + 0.5}
if (changed(M2)) {MaxSpeed = MaxSpeed - 0.5}
if (changed(W) & W==1) {MovSpeed=0}

if (W) {EIW:moveTo(holoEntity(1):pos())
if (MovSpeed < MaxSpeed) {MovSpeed = MovSpeed +0.0005}} elseif (S) {EIW:moveTo(holoEntity(2):pos()) MovSpeed = 0.01}
if (!W) {if (MovSpeed > 0) {MovSpeed = MovSpeed - 0.001}}
if (A) {StrY = StrY + 2} elseif (D) {StrY = StrY - 2}
if (EpI < 78) {EpI = EpI + 0.8}
} else {

}
if (!Active) {
if (CRS!=0) {CRS = CRS-0.1}
if (EpI > 0 ) {EpI = EpI - 0.5} else {soundStop(2) soundStop(1) }
if (Lig > 0) {Lig--}
}
if (changed(Active) & Active) {
CRS = 15
holoEntity(4):soundPlay(1,999,"ambient/fans/huge_fan-01.wav")
#ambient/machines/big_truck.wav
entity():soundPlay(2,999,"ambient/machines/big_truck.wav")
}
soundPitch(2,EsP)
soundPitch(1,EsP)
FanRot = FanRot > 360 ?  1 : FanRot + CRS + (Pitch *0.01)

holoAng(4,entity():toWorld(ang(90,0,0)):rotateAroundAxis(entity():forward(),FanRot)) 
