@name mortar
@inputs Rdy La
@outputs F
@persist [E B TB T]:entity RL BZ:array P V:vector
@model models/hunter/blocks/cube1x1x05.mdl
if(first()|dupefinished())
{
    E = entity()
    E:setColor(0,0,0,0)
    
    function vector bezierC(Src:vector,End:vector,CurvePoint:vector,Progress:number)
    {
        return mix(mix(Src,CurvePoint,Progress),mix(CurvePoint,End,Progress),Progress)
    }
    
    runOnTick(1)
    
    holoCreate(200)
    holoModel(200,"hq_sphere")
    holoScale(200,vec(4))
    holoColor(200,vec4(255,100,0,150))
    
    B = holoCreate(100,E:toWorld(vec()))
    holoModel(100,"hq_rcube")
    holoScale(100,vec(4,4,2))
    holoColor(100,vec(150))
    holoMaterial(100,"phoenix_storms/grey_chrome")
    holoParent(100,E)
    
    TB = holoCreate(1,B:toWorld(vec(0,0,12)))
    holoModel(1,"hq_sphere")
    holoScale(1,vec(2))
    holoColor(1,vec(150))
    holoMaterial(1,"phoenix_storms/grey_chrome")
    holoParent(1,E)
    
    holoCreate(2,TB:toWorld(vec(42,0,0)))
    holoAng(2,TB:toWorld(ang(-90,0,0)))
    holoModel(2,"hq_tube_thin")
    holoScale(2,vec(1.5,1.5,7))
    holoColor(2,vec(150))
    holoMaterial(2,"phoenix_storms/grey_chrome")
    holoParent(2,TB)
    
}

holoVisible(200,players(),0)
holoVisible(200,owner(),1)

if(T:isValid())
{
    if(RL)
    {
        P+=0.0075
        P = clamp(P,0,1)
        T:setPos(bezierC(BZ[2,vector],BZ[1,vector],BZ[3,vector],P))
        F = P==1
        if(F)
        {
            timer("rl",100)
            if(clk("rl"))
            {
                stoptimer("rl")
                T = noentity()
                RL = 0
                P = 0
                F = 0
            }
        }
    }else
    {
        if(La)
        {
            if(Rdy)
            {
                BZ[1,vector] = TB:pos()
                BZ[2,vector] = V
                BZ[3,vector] = ((TB:pos()+V)/2):setZ(TB:pos():z()+15000)
                T:setTrails(10,10,10,"trails/smoke",vec(255,100,0),255)
                RL = 1
            }
        }else
        {
            Bezier = bezierC(V,B:pos(),((TB:pos()+V)/2):setZ(TB:pos():z()+7000),0.01)
            holoAng(1,(Bezier-B:pos()):toAngle())
        }
        T:setPos(TB:toWorld(vec(25,0,0)))
        T:setAng(TB:toWorld(ang(90,0,0)))
    }
}else
{
    findByClass("gmod_wire_expression2")
    findByModel("models/sprops/misc/domes/size_1/dome_12x48.mdl")
    findSortByDistance(E:pos())
    if(find():pos():distance(E:pos())<300&find():getMaterial()=="phoenix_storms/bomb")
    {
        T = find()
        #T:createWire(E,"Detonate","F")
        #E:createWire(T,"Rdy","Rdy")
    }
}

if(changed(owner():keyReload())&owner():keyReload())
{
    V = owner():aimPos()
    holoPos(200,V)
}
