
datablock ShapeBaseImageData(SpeedBoosterImage)
{
   shapeFile = "pack_upgrade_satchel.dts";
   item = SatchelCharge;
   mountPoint = 4;
   offset = "0 0 -0.1";
};

datablock ItemData(SpeedBooster)
{
   className = Specials;
   catagory = "Specials";
   image = SpeedBoosterImage;
   shapeFile = "pack_upgrade_satchel.dts";
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 1;
   rotate = true;
   pickUpName = "a speed booster";
};

// This function moves the player in the direction that the player is facing
// It takes 90% of thier power and requires 10-20 energy to activate (based on armor mass).

function Player::SpeedBoost(%this)
{
   // If the booster is not recharged, give sound and message.
   if (%this.BoosterInActive $= "Y")
   {
      messageClient(%this.client, 'MsgCantSitHere', 'Booster is not recharged. ~wfx/powered/turret_outdoor_fire.wav');
      return(0);
   }

   // If not enough power for that armor, then give a message to the player and beep at them.
   %MinimumEnergy = ((%this.getDataBlock().mass / 90) * 5) + 5;
   if (%this.getEnergyLevel() < %MinimumEnergy)
   {
      messageClient(%this.client, 'MsgCantSitHere', 'You do not have enough energy to activate the speed booster. ~wfx/misc/misc.error.wav');
      return(0);
   }

   // Set the Booster in use/recharging, start the smoke, and then schedule the boost
   %this.BoosterInActive = "Y";
   %this.BoosterSmokeEffect();
   %this.schedule(120, SpeedBoosterBoost);   
}

// Does the Actual boost
function Player::SpeedBoosterBoost(%this)
{
   // Drain 90% of thier energy
   %EnergyLevel = %this.getEnergyLevel();
   %EnergyDrain = %EnergyLevel * 0.9;
   %EnergyMax = %this.getDataBlock().maxEnergy;

   // Figure out the power of the boost
   %EnergyModifier = %EnergyDrain / %EnergyMax;
   %Mass = %this.getDataBlock().mass;
   %ImpulseStrength = %Mass * (55 - ((%Mass / 85) * 11));
   %ImpulseStrength *= %EnergyModifier;

   %Heat = %this.getHeat();

   if (%Heat > 0.65)
   {
      %DamageAmount = 0.1 * %EnergyModifier;
      Armor::damageObject(%this, %this, "0 0 0", %this, %DamageAmount, 1);
   }

   %Heat += %EnergyModifier * 1.5;
   %this.setHeat(%Heat);

   // Play the booster sound.
   %this.setEnergyLevel(%EnergyLevel - %EnergyDrain);

   // Get the vector and position for the directed thrust.
   %Transform = %this.getTransform();
   %CurrentFacing = %this.getMuzzleVector($WeaponsSlot);
   %CurrentFacing = VectorNormalize(%CurrentFacing);

   if (%Player.InWater == true)
      %ImpulseStrength *= 2.5;

   if (%this.getDataBlock().getName() $= "Hero")
   {
      %this.BoosterInActive = "";
      %IMpulseStrength = 35000;
   }

   %ImpulseVector = vectorScale(%CurrentFacing, %ImpulseStrength);
   %VerticalVector = vectorScale("0 0 1", %ImpulseStrength / 2.6);
   %ImpulseVector = VectorAdd(%ImpulseVector, %VerticalVector);

   %CurrentPosition = posFromTransform(%Transform);
   %this.playAudio(0, SpeedBoosterSound);
   %this.applyImpulse(%CurrentPosition, %ImpulseVector);
   %this.schedule(6000, SpeedBoosterRestart);
}

// This reactives the speed boosters
function Player::SpeedBoosterRestart(%this)
{
   %this.BoosterInActive = "N";
}