@name Helicopter Base
@inputs [C EP]:wirelink P:entity
@persist Dri:entity Act W A S D R Spc Alt Shift M1 M2
@persist [E]:entity
@persist [CA]:angle
@persist ISt VSt IMl FMl FMs
@model models/hunter/plates/plate1x1.mdl
if(first())
{
    function number entity:cm()
    {
        local Mass = 0
        foreach(I,K:entity = This:getConstraints())
        {
            Mass+=K:mass()
        }
        return This:mass()+Mass
    }
    
    soundPlay("Ign",0,"NPC_AttackHelicopter.Rotors")
    soundPitch("Ign",0)
    
    runOnTick(1)
    E = entity()
    
    E:propFreeze(0)
    E:setMass(2000)
    FMs = E:cm()
    
    FMl = 9.011625
    
    holoCreate(1,E:toWorld(vec(0,0,60)))
    holoScale(1,vec(15,0.65,0.05))
    holoParent(1,E)
    
    holoCreate(2,E:toWorld(vec(-125,-2,35)))
    holoScale(2,vec(3.25,0.35,0.05))
    holoAng(2,E:toWorld(ang(0,0,90)))
    holoParent(2,E)
    
    holoCreate(10,E:toWorld(vec(0,0,5)))
    holoModel(10,"hq_cone")
    holoAng(10,E:toWorld(ang(90,0,0)))
    holoParent(10,E)
}

if(changed(E:cm()))
{
    FMs = E:cm()
}

if(P:isValid())
{
    Dri = P:driver()
    Act = P:driver():isValid()
    W = Dri:keyForward()
    A = Dri:keyLeft()
    S = Dri:keyBack()
    D = Dri:keyRight()
    R = Dri:keyReload()
    Spc = Dri:keyJump()
    Alt = Dri:keyWalk()
    Shift = Dri:keySprint()
    M1 = Dri:keyAttack1()
    M2 = Dri:keyAttack2()
	
    if(Act)
    {
        if(changed(R)&R)
        {
            ISt = !ISt
            EP["Enable",number] = ISt
        }
    }
    
    if(ISt)
    {
        IMl+=0.00125
        EP["Enable",number] = !M2
    }else
    {
        IMl-=0.00125
    }
    IMl = clamp(IMl,0,1)

    holoAng(1,holoEntity(1):toWorld(ang(0,IMl*100,0)))
    holoAng(2,holoEntity(2):toWorld(ang(0,IMl*50,0)))

    applyForce(((E:up()*(FMl+((W-S)*(1+Shift)*2)))-(E:vel()*0.0025))*FMs*IMl)

    applyAngForce((ang(EP["Y",number]*0.75,(A-D)*8,EP["X",number]*0.75)-E:angVel()/15)*FMs*IMl)

    soundPitch("Ign",IMl*115)

    if(changed(Alt)&Alt)
    {
        VSt = !VSt
        C["Activated",number] = VSt
        C["Parent",entity] = E
    }
    if(VSt)
    {
        C["Position",vector] = E:pos()+vec(-cos(E:angles():yaw())*300,-sin(E:angles():yaw())*300,25)
        C["Angle",angle] = E:angles():setPitch(0):setRoll(0)
    }
}
