@name QuadCopter
@inputs [Pod Cam G TURR]:wirelink 
@outputs X Y Z Pitch Turret:entity Start GT:array
@persist W A S D M2 Shift Space Act Y2 R P E:entity GL:array Des:entity
@model models/hunter/plates/plate025x075.mdl 
runOnTick(1)

if (first()){
    Start=0
    entity():setAlpha(0)
    E = entity()
    E:propFreeze(1)
    E:setMass(1)

#Body
    holoCreate(1)
    holoModel(1,"models/hunter/tubes/tube1x1x1.mdl")
    holoMaterial(1,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(1,vec(0.15,0.1,0.5))
    holoPos(1,entity():toWorld(vec(0,12,2)))
    holoAng(1,entity():toWorld(ang(0,0,90)))
    holoParent(1,entity())
    
    holoCreate(100)
    holoModel(100,"hq_hdome_thin")
    holoMaterial(100,"models/weapons/v_stunbaton/w_shaft01a")
    holoAng(100,ang(0,0,-90))
    holoPos(100,entity():toWorld(vec(0,12,2)))
    holoScale(100,vec(0.6,0.4,1))
    holoParent(100,entity())
    holoClipEnabled(100,1)
    holoClip(100,vec(0,0,0),vec(0,1,0),0)

    holoCreate(101)
    holoModel(101,"hq_hdome_thin")
    holoMaterial(101,"phoenix_storms/glass")
    holoAng(101,ang(0,0,-90))
    holoPos(101,entity():toWorld(vec(0,12,2)))
    holoScale(101,vec(0.6,0.4,1))
    holoParent(101,entity())
    holoClipEnabled(101,1)
    holoClip(101,vec(0,0,0),vec(0,-1,0),0)
    
    holoCreate(102)
    holoModel(102,"hq_hdome_thin")
    holoMaterial(102,"models/weapons/v_stunbaton/w_shaft01a")
    holoAng(102,ang(0,0,90))
    holoPos(102,entity():toWorld(vec(0,-11.7,2)))
    holoScale(102,vec(0.6,0.4,0.5))
    holoParent(102,entity())
    
    holoCreate(109)
    holoModel(109,"hq_cubinder")
    holoMaterial(109,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(109,vec(0.2,0.2,0.4))
    holoAng(109,ang(0,-90,90))
    holoPos(109,entity():toWorld(vec(-5,0.5,2)))
    holoParent(109,entity())
    
    holoCreate(112)
    holoModel(112,"hq_cubinder")
    holoMaterial(112,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(112,vec(0.2,0.2,0.4))
    holoAng(112,ang(0,90,90))
    holoPos(112,entity():toWorld(vec(5,0.5,2)))
    holoParent(112,entity())
    
    holoCreate(113)
    holoModel(113,"torus")
    holoMaterial(113,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(113,vec(0.7,0.7,0.76))
    holoPos(113,entity():toWorld(vec(0,0,2)))
    holoParent(113,entity())
    
    holoCreate(114)
    holoModel(114,"models/Mechanics/gears2/vert_12t1.mdl")
    holoScale(114,vec(0.1,0.1,0.1))
    holoPos(114,entity():toWorld(vec(0,0,-1)))
    holoAng(114,ang(180,0,0))
    holoParent(114,entity())
    
#Cockpit
    #Seat
    holoCreate(105)
    holoModel(105,"models/nova/jeep_seat.mdl")
    holoScale(105,vec(0.1,0.1,0.1))
    holoPos(105,entity():toWorld(vec(0,13,0)))
    holoParent(105,entity())
    
    #Dashboard
    holoCreate(106)
    holoModel(106,"models/hunter/tubes/circle2x2c.mdl")
    holoMaterial(106,"models/weapons/v_stunbaton/w_shaft01a")
    holoAng(106,ang(0,-90,0))
    holoPos(106,entity():toWorld(vec(0,12,2)))
    holoScale(106,vec(0.127,0.076,0.01))
    holoParent(106,entity())
    holoClipEnabled(106,1)
    holoClip(106,vec(-3,0,0),vec(-1,0,0),0)
    
    #Controls
    holoCreate(107)
    holoModel(107,"models/props_lab/reciever01b.mdl")
    holoAng(107,ang(0,-90,0))
    holoPos(107,entity():toWorld(vec(1,15.3,1.836)))
    holoScale(107,vec(0.03,0.05,0.05))
    holoParent(107,entity())
    
    holoCreate(108)
    holoModel(108,"models/props_lab/reciever01a.mdl")
    holoAng(108,ang(0,-90,0))
    holoPos(108,entity():toWorld(vec(-1,15.3,1.83)))
    holoScale(108,vec(0.03,0.05,0.05))
    holoParent(108,entity())
    
    #Joystick
    holoCreate(110)
    holoModel(110,"models/props_c17/TrapPropeller_Lever.mdl")
    holoAng(110,ang(30,-90,-90))
    holoScale(110,vec(0.1,0.1,0.1))
    holoPos(110,entity():toWorld(vec(0,15,1)))
    holoParent(110,entity())
    
    holoCreate(111)
    holoModel(111,"models/props_c17/signpole001.mdl")
    holoAng(111,ang(0,0,-30))
    holoScale(111,vec(0.06,0.06,0.003))
    holoPos(111,entity():toWorld(vec(0,14.7,1.5)))
    holoParent(111,entity())
    
#Left/Right Wing
    #Left
    holoCreate(5)
    holoModel(5,"models/hunter/plates/platehole1x1.mdl")
    holoMaterial(5,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(5,vec(0.2,0.2,0.2))
    holoAng(5,ang(0,90,0))
    holoPos(5,entity():toWorld(vec(-13,10,2)))
    holoParent(5,entity())
    
    holoCreate(6)
    holoModel(6,"models/hunter/plates/platehole1x1.mdl")
    holoMaterial(6,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(6,vec(0.2,0.2,0.2))
    holoAng(6,ang(0,180,0))
    holoPos(6,entity():toWorld(vec(-13,-9,2)))
    holoParent(6,entity())
    
    #Right
    holoCreate(103)
    holoModel(103,"models/hunter/plates/platehole1x1.mdl")
    holoMaterial(103,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(103,vec(0.2,0.2,0.2))
    holoAng(103,ang(0,0,0))
    holoPos(103,entity():toWorld(vec(13,10,2)))
    holoParent(103,entity())
    
    
    holoCreate(104)
    holoCreate(104)
    holoModel(104,"models/hunter/plates/platehole1x1.mdl")
    holoMaterial(104,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(104,vec(0.2,0.2,0.2))
    holoAng(104,ang(0,-90,0))
    holoPos(104,entity():toWorld(vec(13,-9,2)))
    holoParent(104,entity())
    
    
#FrontRight
    holoCreate(11)
    holoModel(11,"models/hunter/tubes/tube2x2x025.mdl")
    holoMaterial(11,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(11,vec(0.2,0.2,0.1))
    holoPos(11,entity():toWorld(vec(13,10,2)))
    holoParent(11,entity())
    
    holoCreate(15)
    holoModel(15,"models/mechanics/wheels/wheel_smooth_48.mdl")
    holoScale(15,vec(0.38,0.38,0.05))
    holoPos(15,entity():toWorld(vec(13,10,2)))
    holoParent(15,entity())
    
#BackRight
    holoCreate(12)
    holoModel(12,"models/hunter/tubes/tube2x2x025.mdl")
    holoMaterial(12,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(12,vec(0.2,0.2,0.1))
    holoPos(12,entity():toWorld(vec(13,-9,2)))
    holoParent(12,entity())
    
    holoCreate(16)
    holoModel(16,"models/mechanics/wheels/wheel_smooth_48.mdl")
    holoScale(16,vec(0.38,0.38,0.05))
    holoPos(16,entity():toWorld(vec(13,-9,2)))
    holoParent(16,entity())

#FrontLeft
    holoCreate(13)
    holoModel(13,"models/hunter/tubes/tube2x2x025.mdl")
    holoMaterial(13,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(13,vec(0.2,0.2,0.1))
    holoPos(13,entity():toWorld(vec(-13,10,2)))
    holoParent(13,entity())
    
    holoCreate(17)
    holoModel(17,"models/mechanics/wheels/wheel_smooth_48.mdl")
    holoScale(17,vec(0.38,0.38,0.05))
    holoPos(17,entity():toWorld(vec(-13,10,2)))
    holoParent(17,entity())
    
#BackLeft
    holoCreate(14)
    holoModel(14,"models/hunter/tubes/tube2x2x025.mdl")
    holoMaterial(14,"models/weapons/v_stunbaton/w_shaft01a")
    holoScale(14,vec(0.2,0.2,0.1))
    holoPos(14,entity():toWorld(vec(-13,-9,2)))
    holoParent(14,entity())
    
    holoCreate(18)
    holoModel(18,"models/mechanics/wheels/wheel_smooth_48.mdl")
    holoScale(18,vec(0.38,0.38,0.05))
    holoPos(18,entity():toWorld(vec(-13,-9,2)))
    holoParent(18,entity())
    
#Weapons
    holoCreate(19)
    holoScale(19,vec(0.1,0.8,0.2))
    holoPos(19,entity():toWorld(vec(-4,5,-10)))
    holoAng(19,entity():toWorld(ang(0,+0,0)))
    holoParent(19,21)
    holoAlpha(19,0)
    
    holoCreate(20)
    holoAlpha(20,0)
    
    holoCreate(21)
    holoModel(21,"models/airboatgun.mdl")
    holoScale(21,vec(0.4,0.3,0.4))
    holoPos(21,entity():toWorld(vec(0,-3,-1.5)))
    holoParent(21,entity())

    function entity:turnTo(Tarang:angle){
V = This:toLocal(rotationVector(quat(Tarang)/quat(This))+This:pos())
This:applyTorque((100*V - 30*This:angVelVector())*This:inertia()/3)
}
function entity:goto(Vector:vector){
 This:applyForce(((Vector-This:pos())*10-entity():vel())*entity():mass())   
}   
}

Seat = Pod["Entity",entity]
Driver = Seat:driver()
W = Pod["W",number]
A = Pod["A",number]
S = Pod["S",number]
D = Pod["D",number]
Space = Pod["Space",number]
Shift = Pod["Shift",number]
Act = Pod["Active",number]
M2 = Pod["Mouse2",number]
E = Pod["Entity",entity]
Turret = TURR:entity()
TURR["Fire",number]=Pod["Mouse1",number]
Active = Driver:isPlayer()
On = Active
Cam["Activated",number] = Active
HoloEnd = entity()
G:entity():setPos(HoloEnd:pos()+vec(0,0,-3))
G:entity():setAng(HoloEnd:toWorld(ang(0,90,180)))

if(first()) {
    G:entity():setAlpha(0)
    G:entity():propFreeze(1)
    G:entity():setMass(50000)
}

if (Act==1)
{
    Y2+=10
    holoAng(15,entity():toWorld(ang(0,Y2,0)))
    holoAng(16,entity():toWorld(ang(0,Y2,0)))
    holoAng(17,entity():toWorld(ang(0,Y2,0)))
    holoAng(18,entity():toWorld(ang(0,Y2,0)))
    
    entity():goto(holoEntity(20):toWorld(vec(X,Y,Z)))
    entity():turnTo(ang(P,E:driver():eyeAngles():yaw()-90,R))
    if (W==1&S==0){Y+=0.5
        R=-20
        Pitch+=0.5}
    if (S==1&W==0){Y-=0.5
        R=20
        Pitch+=0.5}
    if (A==1&D==0){X-=0.5
        P=-20
        Pitch+=0.5}
    if (D==1&A==0){X+=0.5
        P=20
        Pitch+=0.5}
    if (Space==1&Shift==0){Z+=0.25
        Pitch+=0.25}
    if (Shift==1&Space==0){Z-=0.25
        Pitch-=0.25}
    if (W==0&S==0&A==0&D==0&Space==0&Shift==0){Pitch-=1}
    
    if (W==0&S==0){
        R=0
        if (Y<0){Y+=1}
        if (Y>0){Y-=1}
    }
    if (A==0&D==0){
        P=0
        if (X<0){X+=1}
        if (X>0){X-=1}
    }
    if (Space==0&Shift==0){
        if (Z<0.75){Z+=0.25}
        if (Z>0.75){Z-=0.25}
    }
    
    if (Y>=100){Y=100}
    if (Y<=-100){Y=-100}
    if (Z>=10){Z=10}
    if (Z<=-10){Z=-10}
    if (X>=100){X=100}
    if (X<=-100){X=-100}
    if (Pitch<=0){Pitch=0}
    if (Pitch>=100){Pitch=100}
}
if (changed(Act)&Act==1){
    soundPlay(1,0,"/npc/combine_gunship/dropship_onground_loop1.wav")
}
if (changed(Act)&Act==0){soundStop(1)}
   soundPitch(1,Pitch+150)
holoPos(20,entity():pos())
holoAng(20,ang(0,entity():angles():yaw(),0)) 
holoAng(21,entity():toWorld(ang(E:driver():eyeAngles():pitch(),90,E:driver():eyeAngles():roll()-180)))
Turret:setPos(holoEntity(21):toWorld(vec(20,0,2)))
Turret:setAlpha(0)
Turret:setAng(holoEntity(19):angles())
Turret:propFreeze(1)
Turret:propNotSolid(1)
if (changed(Pod["Mouse1",number])&Pod["Mouse1",number]==1){
    soundPlay(2,0,"/npc/combine_gunship/gunship_fire_loop1.wav")
    soundPitch(2,250)
}
if (changed(Pod["Mouse1",number])&Pod["Mouse1",number]==0){
    soundStop(2)
}
if (first()){
Cam["Parent", entity] = entity()
Cam["Position", vector] = entity():pos() + vec(0,0,-1)
}
entity():setAng(Cam["CamAng", angle])
