
datablock ShapeBaseImageData(SpringboardImage)
{
   mass = 16;
//   emap = true;

   shapeFile = "NexusCap.dts";

   item = SpringboardPack;
   deployed = Springboard;

   mountPoint = 1;

   rotation = "-1 0 0 90";
   offset = "0 0 -0.5";

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

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

   maxDepSlope = 35;
   deploySound = SensorDeploySound;
};

function SpringboardImage::onActivate(%data, %Player, %slot)
{
   ShapeBaseImageData::onActivate(%data, %Player, %slot);
}

datablock ItemData(SpringboardPack)
{
   className = Pack;
   catagory = "Deployables";

   shapeFile = "NexusCap.dts";
   mass = 2;

   elasticity = 0.2;
   friction = 0.5;
   pickupRadius = 2;

   rotate = true;

   image = SpringboardImage;
   pickUpName = "an undeployed springboard";

   computeCRC = true;
   emap = true;
};

datablock StaticShapeData(SpringboardExtra) : StaticShapeDamageProfile
{
   className = Sensor;
   shapeFile = "ammo_disc.dts";

   maxDamage = 0.6;
   destroyedLevel = 0.6;

   item = SpringboardPack;
   image = SpringboardImage;

   scale = "3 3 0.8";

   explosion = DeployablesExplosion;

   name = "Springboard";

   debrisShapeName = "debris_generic_small.dts";
   debris = DeployableDebris;

   heatSignature = 0;
};

datablock StaticShapeData(Springboard) : StaticShapeDamageProfile
{
   className = Sensor;
   shapeFile = "NexusCap.dts";

   maxDamage = 0.6;
   destroyedLevel = 0.6;

   item = SpringboardPack;
   image = SpringboardImage;

   scale = "0.85 0.85 1";

   explosion = DeployablesExplosion;

   name = "Springboard";

   deployedObject = true;

   targetNameTag = 'Springboard';
   targetTypeTag = '';

   debrisShapeName = "debris_generic_small.dts";
   debris = DeployableDebris;

   heatSignature = 0;
};

// Schedule the board to pop up.
function Springboard::onAdd(%data, %Springboard, %Position)
{
   parent::onAdd(%data, %Springboard, %Position);

   schedule(150, 0, CompleteSpringBoard, %SpringBoard);
}

function CompleteSpringBoard(%SpringBoard)
{
   %Rotation = rotFromTransform(%SpringBoard.getTransform());
   %SpringBoard.rotation = %Rotation;

   %Position = posFromTransform(%SpringBoard.getTransform());
   %PositionXY = getWords(%Position, 0, 1);
   %PositionZ = getWord(%Position, 2);

   %PositionZ = %PositionZ + 0.3;
   %Springboard.schedule(1650, "setTransform", %PositionXY @ " " @ %PositionZ @ " " @ %Rotation);

   %PositionZ = %PositionZ + 0.15;
   %Springboard.schedule(2550, "setTransform", %PositionXY @ " " @ %PositionZ @ " " @ %Rotation);

   %PositionZ = %PositionZ - 0.6;
   %Emitter = new ParticleEmissionDummy()
   {
      position = %PositionXY @ " " @ %PositionZ;
      scale = "1 1 1";
      dataBlock = "defaultEmissionDummy";
      emitter = "SpringboardHoverEmitter";
   };
   MissionCleanup.add(%Emitter);

   %Springboard.Slave = %Emitter;

   %PositionZ = %PositionZ + 0.25;
   %Springboard.schedule(1650, "setTransform", %PositionXY @ " " @ %PositionZ);

   %PositionZ = %PositionZ + 0.2;
   %Springboard.schedule(2550, "setTransform", %PositionXY @ " " @ %PositionZ);

   %Trigger = new Trigger()
   {
      dataBlock = SpringboardTrigger;
      polyhedron = "-0.125 0.0 0.1 0.25 0.0 0.0 0.0 -0.7 0.0 0.0 0.0 1.0"; 
      position = %PositionXY @ " " @ %PositionZ;
      scale = "1.5 1.5 2";
   };             
   MissionCleanUp.add(%Trigger);

   %Springboard.Trigger = %Trigger;
   %Trigger.Springboard = %Springboard;
}

function SpringBoard::onDestroyed(%this, %Springboard, %prevState)
{
   // Allow it to be repurchased
   $TeamDeployedCount[%Springboard.team, SpringboardPack]--;

   // Remove the board
   %Slave = %Springboard.Slave;
   %Slave.Delete();

   // Remove the trigger
   %Trigger = %Springboard.Trigger;
   %Trigger.Delete();

   // Schedule the Deletion of the board
   %Springboard.schedule(150, delete);
}

function Springboard::ItemSwap(%Object)
{
   %Transform = %Object.getTransform();
   %Position = posFromTransform(%Transform);

   %Item = %Object.getDataBlock().item;

   %NewItem = new Item()
   {
      dataBlock = %Item;
      position = %Position;
   };
   MissionCleanup.add(%NewItem);

   $TeamDeployedCount[%Object.team, %Item]--;

   %Object.Slave.delete();
   %Object.Trigger.delete();
   %Object.delete();

   %NewItem.applyImpulse(%Position, "0 0 10");
   %NewItem.schedulePop();
}

function Player::Springboard(%Player)
{
   // Get the Players Mass
   %Mass = %Player.getDataBlock().mass;

   // Get the players current velocity
   %Velocity = %Player.getVelocity();

   // Scale the Velocity 2.25 times (to reverse the motion plus some)
   %NewVelocityXY = getWords(%Velocity, 0, 1);
   %NewVelocityZ = getWord(%Velocity, 2) * -1;
   %NewVelocity = %NewVelocityXY @ " " @ %NewVelocityZ;
   %NewVelocity = VectorAdd(VectorNormalize(%NewVelocity), "0 0 0.8");

   %SpringBoardVelocity = VectorScale(%NewVelocity, (2.5 * %Mass) + 3600);
   %NewVelocity = VectorAdd(%NewVelocity, %SpringBoardVelocity);

   // Get the Players Position
   %Position = posFromTransform(%Player.getTransform());

   // Apply the Impulse
   %Player.applyImpulse(%Position, %NewVelocity);

   // Make some sound effect
   serverPlay3D(MortarDryFireSound, %Position);
}