
// ----------------------------------------------
// Standard Mine

// This is a single undeployed mine that can be used if picked up, the same as a regular one.
datablock ItemData(ConcussionMineSingle)
{     
   className = HandInventory;
   category = "Dropped";
   item = "ConcussionMine";
   shapeFile = "mine.dts";

   mass = 0.75;
   trueMass = 0.06;

   elasticity = 0.2;
   friction = 0.7;
   pickupRadius = 1;

   isMine = true;

   AlternateObject = ConcussionMine;
 
   thrownItem = ConcussionMineDeployed;
   pickUpName = "a concussion mine";
};

datablock ItemData(ConcussionMineDeployed)
{
   className = Weapon;
   category = "Mine";
   shapeFile = "mine.dts";
   item = "ConcussionMine";
   packedItem = "ConcussionMineSingle";

   mass = 0.75;
   elasticity = 0.3;
   friction = 0.6;
   ApplyConcussion = true;

   explosion = ConcussionGrenadeExplosion;

   hasDamageRadius   = true;
   damageRadius      = 15.0;
   radiusDamageType  = $DamageType::Explosion;
   kickBackStrength  = 3500;

   aiAvoidThis = true;
   dynamicType = $TypeMasks::DamagableItemObjectType;
   spacing = 6.0;
   proximity = 2.5;
   armTime = 2000;
};

datablock StaticShapeData(WallConcussionMine) : StaticShapeDamageProfile
{
   className = Weapon;
   category = "Mine";
   shapeFile = "mine.dts";
   item = "ConcussionMine";

   packedItem = "ConcussionMineSingle";
   DeployedItem = "WallConcussionMine";

   sticky = true;

   mass = 0;
   elasticity = 0;
   friction = 1;
   ApplyConcussion = true;

   explosion = ConcussionGrenadeExplosion;

   hasDamageRadius   = true;
   damageRadius      = 15.0;
   radiusDamageType  = $DamageType::Explosion;
   kickBackStrength  = 3500;

   aiAvoidThis = true;
   dynamicType = $TypeMasks::DamagableItemObjectType;
   spacing = 6.0;
   proximity = 2.5;
   armTime = 2000;
};

datablock ItemData(ConcussionMine)
{     
   className = HandInventory;
   catagory = "Handheld";
   shapeFile = "mine.dts";
   mass = 1;
   elasticity = 0.2;
   friction = 0.7;
   pickupRadius = 1;

   DeployedItem = "WallConcussionMine";

   isMine = true;

   thrownItem = ConcussionMineDeployed;
   pickUpName = "some concussion mines";
};

// This is the initial mine throw it starts several things, including a check for
// to stabilize the mine.  If a mine was thrown over an edge or slides for a long
// time we disable the mine.  We give the mine 12 seconds to arm itself or we
// remove it
function ConcussionMineDeployed::onThrow(%this, %Mine)
{
   %Mine.armed = false;
   %Mine.damaged = 0;
   %Mine.detonated = false;
   %Mine.team = %Mine.sourceObject.team;
   %Mine.MineCheck = schedule(1500, 0, "MineCheck", %Mine);
   %Mine.ArmCheck = schedule(12000, 0, "MineArmingCheck", %Mine);
}

// This makes the mine purely proximity, not contact.
function ConcussionMineDeployed::onCollision(%data, %Mine, %col)
{

}

// This function applied damage to the mine, it can cause it to explode.
// if the damage is sufficient.  One idea is to make the person who shot
// the mine responsible for the effect if that is what caused it to explode.
function ConcussionMineDeployed::damageObject(%Data, %Mine, %SourceObject, %Position, %Amount, %DamageType)
{
   if (%Mine.detonated == true)
      return(0);

   %Mine.damaged += %Amount;

   if (%Mine.damaged >= %Data.maxDamage)
   {
      // If it is not armed, just make a pop
      if (%Mine.armed == true)
      {
         %Mine.setDamageState(Destroyed);
      } else {
         %Position = posFromTransform(%Mine.getTransform());

         %Item = new Item()
         {
            datablock = MineFizzle;
            position = %Position;
         };
         MissionCleanUp.add(%Item);

         %Mine.schedule(450, delete);
         schedule(500, 0, detonateGrenade, %Item);
      }
   }
}

// This function does the actual explosion, gives credit to the one shooting it
function ConcussionMineDeployed::onDestroyed(%data, %Mine, %lastState)
{
   if (%Mine.detonated == true)
      return;

   // Mark the mine as blown so that all associated functions halt
   %Mine.detonated = true;

   // Cancel any potential schedules
   Cancel(%Mine.MineCheck);
   Cancel(%Mine.ArmCheck);
   Cancel(%Mine.MineArm);
   Cancel(%Mine.MineCheckVicinity);

   // Allow the mine to be replaced
   $TeamDeployedCount[%Mine.Team, MineDeployed]--;

   // Locate the mine and it's properties
   %Transform = %Mine.getTransform();
   %Position = posFromTransform(%Transform);
   %Source = %Mine.sourceObject;

   %DataBlock = %Mine.getDataBlock();
   %Radius = %DataBlock.damageRadius;
   %Damage = %DataBlock.indirectDamage;
   %Impulse = %DataBlock.kickBackStrength;
   %Type = %DataBlock.radiusDamageType;

   RadiusExplosion(%Mine, %Position, %Radius, %Damage, %Impulse, %Source, %Type);

   %Mine.schedule(450, "delete");
}


function WallConcussionMine::damageObject(%Data, %Mine, %SourceObject, %Position, %Amount, %DamageType)
{
   MineDeployed::damageObject(%Data, %Mine, %SourceObject, %Position, %Amount, %DamageType);
}

function WallConcussionMine::onDestroyed(%data, %Mine, %lastState)
{
   MineDeployed::onDestroyed(%data, %Mine, %lastState);
}