 //---------------------------------------------------------
// Deployable Spine, Code by Mostlikely
//---------------------------------------------------------
//Losts of useless stuff... wait for me to update..


datablock StaticShapeData(Deployedspine) : StaticShapeDamageProfile
{
className = spine;
shapeFile = "Pmiscf.dts"; // dmiscf.dts, alternate

   maxDamage = 2.0;
   destroyedLevel = 2.0;
   disabledLevel = 2.0;
    
   explosion      = HandGrenadeExplosion;

      expDmgRadius = 20.0;
      expDamage = 0.05;
      expImpulse = 2000.0;



dynamicType = $TypeMasks::StaticShapeObjectType;
deployedObject = true;
cmdCategory = "DSupport";
cmdIcon = CMDSensorIcon;
cmdMiniIconName = "commander/MiniIcons/com_deploymotionsensor";
targetNameTag = 'Light Support Beam';
deployAmbientThread = true;
debrisShapeName = "debris_generic_small.dts";
debris = DeployableDebris;
heatSignature = 0;
};



datablock ShapeBaseImageData(spineDeployableImage)
{
mass = 20;
emap = true;
shapeFile = "Stackable1s.dts";
item = spineDeployable;
mountPoint = 1;
offset = "0 0 0";
deployed = Deployedspine;
heatSignature = 0;

stateName[0] = "Idle";
stateTransitionOnTriggerDown[0] = "Activate";

stateName[1] = "Activate";
stateScript[1] = "onActivate";
stateTransitionOnTriggerUp[1] = "Idle";

//isLarge = False;
maxDepSlope = 360; // 30
deploySound = ItemPickupSound;

minDeployDis = 0.1;
maxDeployDis = 50.0;
};

datablock ItemData(spineDeployable)
{
className = Pack;
catagory = "Deployables";
shapeFile = "Stackable1s.dts";
mass = 5.0;
elasticity = 0.2;
friction = 0.6;
pickupRadius = 1;
rotate = true;
image = "spineDeployableImage";
pickUpName = "a small support beam";
heatSignature = 0;
emap = true;
};

function spineDeployableImage::testObjectTooClose(%item)
{
//%mask = $TypeMasks::PlayerObjectType;
//%pos = %item.surfacePt;
//return !ContainerBoxEmpty (%mask, %pos, %item.minDeployDis);
return "";
}

function spineDeployableImage::testNoTerrainFound(%item)
{
//don't check this for non-Landspike turret deployables
}

function spineDeployable::onPickup(%this, %obj, %shape, %amount)
{
// created to prevent console errors
}


/////////////////////////////////////
function spineDeployableImage::onDeploy(%item, %plyr, %slot)
{
////////////////Get settings

//Object
//%Data = %item.getDataBlock();
%className = "StaticShape";
//normal beam

%Beamx = 0.5; //%item.getDataBlock().BeamX;
%Beamy = 0.5; //%item.getDataBlock().BeamY;
%Beamz = 8; //%item.getDataBlock().BeamHeight;
%LBeamz = 40; //%item.getDataBlock().LargeBeamHeight;
%HBeamz = 160; // %item.getDataBlock().HugeBeamHeight;
//Smart
%SBeamz = 4; //%item.getDataBlock().smartHeight;
%SBeamzt = 16; //%item.getDataBlock().smartMaxHeight;
%SBeamzb = 0.5; //%item.getDataBlock().smartMinHeight;
//Pad
%PBeamz = 4; //%item.getDataBlock().padHieght;
%PBeamy = 4; //%item.getDataBlock().padWidth; 
%PBeamzt = 16; //%item.getDataBlock().padMaxHeight;
%PBeamzb = 0.5; //%item.getDataBlock().padMinHeight;
%PBeamyt = 16; //%item.getDataBlock().padMaxWidth;
%PBeamyb = 0.5; //%item.getDataBlock().padMinWidth;

//Player
%playerrot = %item.getInitialRotation(%plyr);
%playerrotxy = -1 * GetWord(%playerrot,2) * GetWord(%playerrot,3);
%playervec = %plyr.getEyeVector();
%playerrotvec = GetWord(%playervec,0) SPC GetWord(%playervec,1) SPC "0";
%packset = %plyr.packset; 

//Surface
%surface = %item.surface;
%surfaceAngle = getTerrainAngle(%item.surfaceNrm);
%surfacenrm = %item.surfaceNrm;
%surfacePT = %item.surfacePT;

if (%surface.needsfit == 1)
   {
   %surfaceclass = %item.surface.getDataBlock().className; // TerrainBlock,InteriorInstance
   %surfacetrans = %surface.gettransform();
   %surfacepos = posFromTransform(%surfacetrans);
   %surfacerot = rotFromTransform(%surfacetrans);
   %surfaceup = %surface.up;
   %surfacefo = %surface.fo;
   }
if (%item.surface.getClassName() $= TerrainBlock)
   %surfacepos = %surfacePT;
%testaxes=0;

////////////////Derive Settings




%scale = %Beamx / 4.0 @ " " @ %Beamy / 3.0 @ " " @ %Beamz / 0.5; 
%scale = scaleright(scalelibrary(%item.item,%packset,-1),"plug");
%scalex = scalelibrary(%item.item,%packset,0);
%scaley = scalelibrary(%item.item,%packset,1);
%scalez = scalelibrary(%item.item,%packset,2);



//%deplObj = new (%className)()
//               { 
//               dataBlock = %item.deployed; 
//               scale = %scale; 
//               };    

%rotate = 0;
%Dplacement = %surfacept;
%DNormal = %surfacenrm;
%upward = %DNormal;

//%deplObj.setDeployRotation(%Dplacement, %DNormal); 

//%newrot = rotFromTransform(%deplObj.gettransform());
                
                %xr = Getword(%newrot,0)*Getword(%newrot,3);
                %yr = Getword(%newrot,1)*Getword(%newrot,3);                
                %zr = Getword(%newrot,2)*Getword(%newrot,3) + -1 * 1.57 + 3.14;


%newup = %upward;
//messageClient(%plyr.client, 'MsgDeployFailed',scaleright(scalelibrary(%item.item,%packset,-1),"plug") , %errorSnd);         
if (%item.surfaceinher == 0)
{
if (Abs(GetWord(%newup,2)) < 0.90)
        {
	//%newfo = VectorCross("0 0 1",%newup);
        //%xv = GetWord(%item.surfaceNrm,0);
        //%yv = -1*GetWord(%item.surfaceNrm,1);
	%rot = slopfromnrm(%upward);
        %yrot = GetWord(%rot,1);
        %zrot = -1 * GetWord(%rot,2) - 1.57;
        %newfo = MSin(%zrot) * MCos(%yrot) SPC  MCos(%zrot) * MCos(%yrot) SPC  MSin(%yrot);
        //%rot = "1.57 0 " @ MAtan(%xv,%yv);
        //messageClient(%plyr.client, 'MsgDeployFailed',%rot, %errorSnd);
       }
else
       {
       %newup = "0 0 1";
       %newfo = Vectorright(%newup,%playerrotvec);
       if (%packset == 4)
        %rot = rotfromnrm(%newfo,%newup,%plyr);
        else 
        %rot = rotfromnrm(%newup,%newfo,%plyr);
       }
}
else
{
if (GetWord(%newup,2) < 0.01 && GetWord(%newup,2) > -0.01)
        {
        %new = "0 0 1";//GetWord(%item.surfaceNrm2,0) SPC GetWord(%item.surfaceNrm2,1) SPC "0";
	%newfo = %new; //VectorCross(%new,%newup);
        %xv = GetWord(%item.surfaceNrm,0);
        %yv = -1*GetWord(%item.surfaceNrm,1);
        %zrot = MAtan(%xv,%yv);
        %xv = GetWord(%item.surfaceNrm2,0);
        %yv = GetWord(%item.surfaceNrm2,1);
        %zv = GetWord(%item.surfaceNrm2,2);
        %xyv = Mpow(Mpow(%xv,2)+Mpow(%yv,2),0.5);
        %xrot = MAtan(%zv,%xyv);
        //messageClient(%plyr.client, 'MsgDeployFailed',%xrot, %errorSnd);
        if (%packset == 4)
        {
        %rot =  %xrot SPC "0" SPC  %zrot - 1.57; //;
        %new = %item.surfaceNrm2;//,0) SPC GetWord(%item.surfaceNrm2,1) SPC "0";
	%newfo = Vectorright(%newup,%new);
        }
        else
        %rot =  "0 1.57" SPC  %zrot - 1.57; //;
        
        }
else
        {
	%newfo = VectorRight(%newup,%item.surfacenrm2);
        if (%packset == 4)
        %rot = rotfromnrm(VectorCross(%newfo,%newup),%newup,%plyr);
        else 
        %rot = rotfromnrm(%newup,%newfo,%plyr);
        }                
}
%upward = %newup;//rotatenormal("0 0 1",GetWord(%rot,0),GetWord(%rot,1),GetWord(%rot,2));//%newup;
%forward = %newfo;//rotatenormal("0 1 0",GetWord(%rot,0),GetWord(%rot,1),GetWord(%rot,2));//%newfo;

if (%packset == 4)
{
%rotate = 0;
%Dplacement = %surfacept;
%DNormal = %surfacenrm;
%upward = %DNormal;

//%deplObj.setDeployRotation(%Dplacement, %DNormal); 

//%newrot = rotFromTransform(%deplObj.gettransform());
                
                %xr = Getword(%newrot,0)*Getword(%newrot,3);
                %yr = Getword(%newrot,1)*Getword(%newrot,3);                
                %zr = Getword(%newrot,2)*Getword(%newrot,3) + -1 * 1.57 + 3.14;
         %newfo = %upward;
if (%item.surfaceinher == 0)
{
if (Abs(GetWord(%newfo,2)) < 0.90)
        {
	//%newfo = VectorCross("0 0 1",%newup);
        //%xv = GetWord(%item.surfaceNrm,0);
        //%yv = -1*GetWord(%item.surfaceNrm,1);
	%rot = slopfromnrm(%item.surfacenrm);
        %rot = GetWord(%rot,0)+1.57 SPC GetWord(%rot,1) SPC GetWord(%rot,2);
        //%yrot = GetWord(%rot,1);
        //%zrot = -1 * GetWord(%rot,2) - 1.57;
        %newfo = %DNormal;
        %newle = VectorCross(%newfo,"0 0 -1");
        //%newfo = MSin(%zrot) * MCos(%yrot) SPC  MCos(%zrot) * MCos(%yrot) SPC  MSin(%yrot);
        //%rot = "1.57 0 " @ MAtan(%xv,%yv);
        //messageClient(%plyr.client, 'MsgDeployFailed',%rot, %errorSnd);
        //%rot = GetWord(%rot,0)+ 1.57 SPC GetWord(%rot,1) SPC GetWord(%rot,2)+ 1.57;
       }
else
       {
       //%new = %newup;
       %newle = VectorRight(%newfo,%playerrotvec);
       //if (%packset == 4)
       %rot = rotfromnrm(%newle,%newfo,%plyr);
       %newle = VectorCross(%newfo,%playerrotvec);
       // else 
       // %rot = rotfromnrm(%newup,%newfo,%plyr);
       %rot = GetWord(%rot,0)+1.57 SPC GetWord(%rot,1) SPC GetWord(%rot,2);
       }

}
else
{
if (GetWord(%newfo,2) < 0.01 && GetWord(%newfo,2) > -0.01)
        {
        %new = "0 0 1";//GetWord(%item.surfaceNrm2,0) SPC GetWord(%item.surfaceNrm2,1) SPC "0";
	%newle = %new; //VectorCross(%new,%newup);
        %xv = GetWord(%item.surfaceNrm,0);
        %yv = -1*GetWord(%item.surfaceNrm,1);
        %zrot = MAtan(%xv,%yv);
        %xv = GetWord(%item.surfaceNrm2,0);
        %yv = GetWord(%item.surfaceNrm2,1);
        %zv = GetWord(%item.surfaceNrm2,2);
        %xyv = Mpow(Mpow(%xv,2)+Mpow(%yv,2),0.5);
        %xrot = MAtan(%zv,%xyv);
        //messageClient(%plyr.client, 'MsgDeployFailed',%xrot, %errorSnd);
        //if (%packset == 1)
        //{
        %rot =  %xrot SPC "0" SPC  %zrot - 1.57; //;
        %new = %item.surfaceNrm2;//,0) SPC GetWord(%item.surfaceNrm2,1) SPC "0";
	%newle = Vectorright(%newfo,%new);
        //}
        //else
        //%rot =  "0 1.57" SPC  %zrot - 1.57; //;
        
        }
else
        {
	%newle = VectorRight(%newfo,%item.surfacenrm2);
        //if (%packset == 2)
        %rot = rotfromnrm(VectorCross(%newle,%newfo),%newfo,%plyr);
        //else 
        //%rot = rotfromnrm(%newup,%newfo,%plyr);
        }                
}
%upward = %newfo;//rotatenormal("0 0 1",GetWord(%rot,0),GetWord(%rot,1),GetWord(%rot,2));//%newup;
%forward = %newle;//rotatenormal("0 1 0",GetWord(%rot,0),GetWord(%rot,1),GetWord(%rot,2));//%newfo;

}


%Dtransform = %Dplacement SPC setrot(%rot);

if (%packset == 3)
 {        
         %up=VectorScale(vectorNormalize(%upward),64);
         %mask = $TypeMasks::InteriorObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::VehicleObjectType | $TypeMasks::StaticObjectType;
         %endpos = VectorAdd(%item.surfacePt, %up);         
         %res = containerRayCast(%item.surfacePt, %endpos, %mask, 0);         
         if(%res)
            {
            %part2 = GetWord(%res,1) SPC GetWord(%res,2) SPC GetWord(%res,3);
            %zscale= VectorDist(%part2,%item.SurfacePt);
            if (%zscale < 0.5)
                %zscale = 0.5;            
            }
         else
            %zscale=%scalez;
         %scale = %scalex / 4 @ " " @ %scaley / 3 @ " " @ %zscale / 0.5; 
         %scalez = %zscale;
         }


if (%packset == 4)
         {

         %placmod = VectorScale(VectorNormalize(VectorCross(%newfo,%newle)),%scalex/2);
         //messageClient(%plyr.client, 'MsgDeployFailed', %placmod, %errorSnd);             
         if (getWord(%placmod,2) > 0.1)
            %placmod = VectorScale(%placmod,-1);
         //messageClient(%plyr.client, 'MsgDeployFailed', %placmod, %errorSnd);             
                  %Dplacement = VectorAdd(%Dplacement,%placmod);
         %maxwidth = 24/2; // Max Width of blastwall
         %maxheight = 24; // Max Width of blastwall
         %upways = VectorScale(vectorNormalize(%upward), %maxheight);
         %sideways = VectorScale(vectorNormalize(%forward),%maxwidth);
         %mask = $TypeMasks::InteriorObjectType | $TypeMasks::PlayerObjectType |$TypeMasks::VehicleObjectType| $TypeMasks::StaticObjectType;
         %endpos =  VectorAdd(%item.surfacePt, %upways);
         %res = containerRayCast(%item.surfacePt, %endpos, %mask, 0);              
         if(%res)
            {
            %part2 = GetWord(%res,1) SPC GetWord(%res,2) SPC GetWord(%res,3);
            %zscale= VectorDist(%part2,%item.SurfacePt);           
            if (%zscale < %PBeamzb)
                {
            %zscale = %PBeamzb;            
             }
            }
         else
            %zscale=%scalez;     

         %zscale = %zscale + %adjust*2;

         %placft = VectorScale(vectorNormalize(%upways),%zscale/2);
         %initpos = VectorAdd(%item.SurfacePt,%placft);
         %endpos =  VectorAdd(%initpos,%sideways);

         %res = containerRayCast(%initpos, %endpos, %mask, 0);         
         if(%res)
            {
             %part2 = GetWord(%res,1) SPC GetWord(%res,2) SPC GetWord(%res,3);
             %left= VectorDist(%part2,%initpos);
	   
            }
         else
            %left=%scaley/2;

         %endpos =  VectorAdd(%initpos, VectorScale(%sideways, -1));
         %res = containerRayCast(%initpos, %endpos, %mask, 0);
         if(%res)
            {
            %part2 = GetWord(%res,1) SPC GetWord(%res,2) SPC GetWord(%res,3);
            %right= VectorDist(%part2,%initpos);
           
            }
         else
         %right=%scaley/2; 
         
        if ((%left + %right)>24)
            {
            %left = %left-(((%left+%right)-64)/2);
            %left = %right-(((%left+%right)-64)/2);
            }
        

         %right = %right + %adjust;
         %left = %left + %adjust;

         
         %wid = %left + %right;      
         %av = %wid / 2;
         %movedist = (%av - %left) ;//*1.3;           
         //%scale = %zscale / 3.85 @ " " @ %wid / 3.1 @ " 1";    
        %surfaceAngle = getTerrainAngle(%item.surfaceNrm);               
        %scalez = %Beamx;
        if (GetWord(%upward,2) < 0.01 && GetWord(%upward,2) > -0.01)
              {
              %scale =  %zscale / 4 @ " " @ %wid / 3 @ " " @ %Beamx/0.5; 
              %scalex = %zscale;
              %scaley = %wid;
              //%placmod = "0 0 -0.25";
              }
         else 
              {
              //%placmod = VectorScale(%vec1,-0.23);
              %scale =  %wid / 4 @ " " @ %zscale / 3 @ " " @ %Beamx/0.5; 
              %scaley = %zscale;
              %scalex = %wid;   
              }
         %placf = VectorScale(vectorNormalize(%upways),%zscale/2-(%adjust));         
         %placs = VectorScale(vectorNormalize(%sideways),-1* %movedist);

         %plac = VectorAdd(%placs,%placf);//,%placmod);    
         %Dplacement = VectorAdd(%Dplacement,%plac);
         if (%item.surfaceinher == 0)
         %upward = %sideways;
         else
         %upward = VectorNormalize(VectorCross(%upways,%sideways));
         %forward = VectorNormalize(%upways);

}            




      if (%testaxes)
             {
         %xas = new (%className)()
               { 
               dataBlock = %item.deployed; 
               scale = 0.1 / 3.85 @ " " @ 0.1 / 3.1 @ " " @ 10 / 0.5;  
               }; 
         %zas = new (%className)()
               { 
               dataBlock = %item.deployed; 
               scale = 0.1 / 3.85 @ " " @ 0.1 / 3.1 @ " " @ 10 / 0.5;  
              };                                   
           %yas = new (%className)()
               { 
               dataBlock = %item.deployed; 
               scale = 0.1 / 3.85 @ " " @ 0.1 / 3.1 @ " " @ 10 / 0.5; 
               }; 
           %plac = %surfacept;
           %xas.setDeployRotation(%plac,  %surfacenrm); 
           //%yas.setDeployRotation(%plac, VectorCross(%upward,%forward); 
           %zas.setDeployRotation(%plac, Vectorright(%surfacenrm,"0 0 1")); 
            }

%grounded = 0;
if (%item.surface.getClassName() $= TerrainBlock)
      %grounded = 1;

%Dtransform = %Dplacement SPC setrot(%rot);

%deplObj = new (%className)()
               { 
               dataBlock = %item.deployed; 
               scale = %scale; 
               }; 



//////////////////////////Aply settings//////////////////////////////



//[[Location]]:


//exact:
	if (%rotate)
		%deplObj.setDeployRotation(%Dplacement, %DNormal); 
	else
		%deplObj.setTransform(%Dtransform);




//misc info
        %deplObj.dSurface = %surface;
	%deplObj.dSurfaceNrm = %surfaceNrm;
	%deplObj.dUpward = %upward;
	%deplObj.dforward = %forward;
	%deplObj.dleft = %left;

	%deplObj.lUpward = %scalez;
	%deplObj.lforward = %scalex;
	%deplObj.lleft = %scaley;

//[[Settings]]:

	%deplObj.grounded = %grounded;
        %deplObj.Needsfit = 1;
        %deplObj.lastSurfaceNrm = %item.surfaceNrm;

//[Normal Stuff]]:


// set team, owner, and handle
	%deplObj.team = %plyr.client.Team;
	%deplObj.owner = %plyr.client;

// set the sensor group if it needs one
	if(%deplObj.getTarget() != -1)
		setTargetSensorGroup(%deplObj.getTarget(), %plyr.client.team);
	

// place the deployable in the MissionCleanup/Deployables group (AI reasons)
	addToDeployGroup(%deplObj);

//let the AI know as well...
	AIDeployObject(%plyr.client, %deplObj);

// play the deploy sound
	serverPlay3D(%item.deploySound, %deplObj.getTransform());

// increment the team count for this deployed object
	$TeamDeployedCount[%plyr.team, %item.item]++;

%deplObj.deploy();

if (%testaxes)
	{
	%deplObj.x = %xas;
	%deplObj.y = %yas;
	%deplObj.z = %zas;
	%xas.deploy();
	%yas.deploy();
	%zas.deploy();
	}

%animate = 1;
if (%animate)
{
if ((%grounded) || ((%surface.grounded) && (%packset != 4)))
   {     
   if (%surface.grounded)
      %upward = %surface.dupward;
   if (%packset == 4)
	   %start = VectorAdd(%Dplacement,"0 0 " @ -1 * %zscale);
   else
	   %start = VectorAdd(%surfacepos,VectorScale(%upward,-1 * %scalez));

   %pace = VectorScale(VectorSub(%start,%Dplacement),-0.1);
   //messageClient(%plyr.client, 'MsgDeployFailed',VectorScale(%upward,-1 * %zscale) , %errorSnd);             
   %newtrans = %start SPC setrot(%rot);	
   %DeplObj.setTransform(%newtrans);
    schedule(50 ,%deplObj, "dynamicmove", %deplObj, 50, %pace,  %Dplacement);
   //schedule(50 ,%deplObj, "dynamicRotate", %deplObj, 50, "0 0 0",  %Dplacement,%plyr);
   }
else
   {
   %scale = scaleright(%scalex  SPC %scaley  SPC %scalez,"plug");
   if (%packset == 4)
        {
	%start = %surfacePt;
        %end = %Dplacement;
        %pace = VectorScale(VectorSub(%start,%end),-0.1);
        %newtrans = %start SPC setrot(%rot);	
        %DeplObj.setTransform(%newtrans);
        schedule(50 ,%deplObj, "dynamicMove", %deplObj, 50, %pace,  %Dplacement);
        %newscale = "0.1 0.1 " @ GetWord(%scale,2);
        }
    else
	%newscale = GetWord(%scale,0) SPC GetWord(%scale,1) SPC "0.1";

    %scalepace = GetWord(%scale,0) * 0.01 SPC GetWord(%scale,1) * 0.01 SPC GetWord(%scale,2) * 0.01;
    %Deplobj.setScale(%newscale);
    schedule(50,%DeplObj, "dynamicScale", %deplObj, 5 , %scalepace, %scale);
    }
    //schedule(%time, %obj, "dynamicScale", %obj, %time, %pace, %end);
    //schedule(50 ,%DeplObj, "dynamicMove", %deplObj, 5, %pace, %pos);
}
return %deplObj;  
}
/////////////////////////////////////


function Deployedspine::onDestroyed(%this, %obj, %prevState)
{
Parent::onDestroyed(%this, %obj, %prevState);
$TeamDeployedCount[%obj.team, spineDeployable]--;
%obj.schedule(500, "delete");
//%obj.x.schedule(500, "delete");
//%obj.y.schedule(500, "delete");
//%obj.z.schedule(500, "delete");


for (%i=0;%i < Deployables.getCount();%i++)
   {
      %dep = Deployables.getObject(%i);
       if (%dep.dSurface == %obj)
         {
         %random = getRandom() * 1000+10;
         %dep.schedule(%random, setDamageState , Destroyed);
         }
   }

for (%ti=0;%ti < 2;%ti++)
 {
%nteam = "Team" @ %ti;
%group = nameToId("MissionGroup/Teams/"@ %nteam @"/Base0");
//echo(%group);
if (%group > 0)
  {
   %count = %group.getCount();
       for (%i = 0; %i < %count; %i++)
		 {
                 %dep = %group.getObject(%i);
	          if (%dep.dSurface == %obj)
                     {
                     %random = getRandom() * 1000+10;
                     %dep.schedule(%random, setDamageState , Destroyed);
                     }           
         }
  }
 }

//if (%expode)
//{
                  //if(%this.expDmgRadius)
                  //     RadiusExplosion(%obj, %obj.getWorldBoxCenter(), %this.expDmgRadius, %this.expDamage, %this.expImpulse, %obj, $DamageType::Explosion);
                  %source = %obj;

	          for (%i=0;%i<1;%i++)
                  {
	               %x = (getRandom() * 0.4) - 0.2;
          	       %y = (getRandom() * 0.4) - 0.2;
                       %z = getRandom() / 2;
                       %vec = %x SPC %y SPC %z;
                       %pos = VectorAdd(posFromTransform(%obj.getTransform()), VectorScale(%vec, 3));
                       %p = new (GrenadeProjectile)() {
                                                      dataBlock        = DeployableFireball;
                                                       initialDirection = %vec;
			                               initialPosition  = %pos;
                                                       sourceObject     = %source;
                                                       sourceSlot       = 1;
                                                       vehicleObject    = %obj;
                                                      };
                       MissionCleanup.add(%p);
                   }
//}
}



function spineDeployableImage::onMount(%data, %obj, %node)
{

   %obj.client.player.hasspine = true; // set for spinecheck
   %obj.client.player.packset = 0;
}

function spineDeployableImage::onUnmount(%data, %obj, %node)
{
  %obj.client.player.packset = 0;
  %obj.client.player.hasspine = "";
}



function calcBunkerInWay(%position, %targetObject)
{
   %mask = $TypeMasks::StaticObjectType;
   %found = containerRayCast(%position, posFromTransform(%targetObject.getTransform()), %mask);
   if (%found)
   {
      if ((%found.getClassName() $= InteriorInstance) || (%found.getClassName() $= TerrainBlock) || (%found.getClassName() $= TSStatic))
         return 1;
      if (%found == %targetObject)
         return 1;
      if (%found.getDataBlock().className $= "spine" || %found.getDataBlock().className $= "wwall")
         return 0;
      else
      {
         %found = containerRayCast(%position, posFromTransform(%targetObject.getTransform()), %mask, %found);
         if (%found)
         {
            if ((%found.getClassName() $= InteriorInstance) || (%found.getClassName() $= TerrainBlock) || (%found.getClassName() $= TSStatic))
               return 1;
            if (%found == %targetObject)
               return 1;
            if (%found.getDataBlock().className $= "spine" || %found.getDataBlock().className $= "wWall")
               return 0;
         }
      }
   }
   return 1;
}


