
datablock SensorData(SensorJammerSensor)
{
   detects                      = true;
   detectFOVPercent             = 1.3;
   detectRadius                 = 35;

   detectionPings               = true;
   detectsActiveJammed          = true;
   detectsCloaked               = true;
   detectsFOVOnly               = true;
   detectsPassiveJammed         = true;
   detectsUsingLOS              = false;

   jams                         = true;
   jamRadius                    = 30;
   jamsOnlyGroup                = true;
   jamsUsingLOS                 = false;

   useObjectFOV                 = false;
};

datablock StaticShapeData(JammerCap) : StaticShapeDamageProfile
{
   className = Sensor;
   shapeFile = "ammo_disc.dts";
   maxDamage = 0.5;
   destroyedLevel = 0.5;
   disabledLevel = 0.3;

   sticky = true;
   mass = 0;
   friction = 1.0;

   explosion             = DeployablesExplosion;
   dynamicType           = $TypeMasks::SensorObjectType;

   deployedObject        = true;
   deployAmbientThread = true;

   cmdCategory           = "DSupport";
   cmdIcon               = CMDSensorIcon;
   cmdMiniIconName       = "commander/MiniIcons/com_deploymotionsensor";

   targetNameTag         = 'Deployable Jammer';
   targetTypeTag         = '';

   sensorData            = SensorJammerSensor;
   sensorRadius          = SensorJammerSensor.detectRadius;
   sensorColor           = "0 128 0";

   name                  = "Deployed Sensor Jammer";
   item                  = DeployableSensorJammerPack;

   isShielded            = true;
   energyPerDamagePoint  = 80;
   maxEnergy             = 25;
   rechargeRate          = 0.01;

   lightType = "PulsingLight";
   lightColor = "1.0 1.0 0.25 0.6";
   lightTime = "3000";
   lightRadius = "2.5";

   debrisShapeName = "debris_generic_small.dts";
   debris = DeployableDebris;
   heatSignature = 0;
};

// This ignores damage to the cap as part of the whole or it would take damage
// twice as quickly from splash weapons.
function JammerCap::damageObject(%Data, %Cap, %SourceObject, %Position, %Amount, %DamageType)
{
   %Cap.Master.damageObject(%Data, %Cap.Master, %SourceObject, %Position, %Amount, %DamageType);
}

function JammerCap::ItemSwap(%Data, %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.Master.delete();
   %Object.delete();

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

function JammerCap::onAdd(%this, %obj)
{
   Parent::onAdd(%this, %obj);
}

datablock StaticShapeData(DeployedSensorJammer) : StaticShapeDamageProfile
{
   className = Sensor;
   shapeFile = "ammo_plasma.dts";
   maxDamage = 0.5;
   destroyedLevel = 0.5;
   disabledLevel = 0.3;

   explosion             = DeployablesExplosion;
   dynamicType           = $TypeMasks::SensorObjectType;

   deployedObject        = true;
   deployAmbientThread = true;

   cmdCategory           = "DSupport";
   cmdIcon               = CMDSensorIcon;
   cmdMiniIconName       = "commander/MiniIcons/com_deploymotionsensor";

   targetNameTag         = 'Deployable Jammer';
   targetTypeTag         = '';

   sensorData            = SensorJammerSensor;
   sensorRadius          = SensorJammerSensor.detectRadius;
   sensorColor           = "0 128 0";

   name                  = "Deployed Sensor Jammer";
   item                  = DeployableSensorJammerPack;
   image = DeployableSensorJammerImage;

   isShielded            = true;
   energyPerDamagePoint  = 80;
   maxEnergy             = 25;
   rechargeRate          = 0.01;

   debrisShapeName = "debris_generic_small.dts";
   debris = DeployableDebris;
   heatSignature = 0;
};

// Schedule the cap to pop up and start the sensor jamming
function DeployedSensorJammer::onAdd(%data, %Jammer, %Position)
{
   parent::onAdd(%data, %Jammer, %Position);

   echo("Jammer: " @ %Jammer);
   schedule(750, 0, MakeCap, %Jammer);
}

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

   // Remove the Jammer Cap.
   %Slave = %Jammer.Slave;
   %Slave.Delete();

   // Schedule the Deletion of the generator
   %Jammer.schedule(150, delete);
}

function DeployedSensorJammer::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.delete();

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

datablock ShapeBaseImageData(DeployableSensorJammerImage)
{
   mass = 5;
   emap = true;

   shapeFile = "ammo_plasma.dts";
   item = DeployableSensorJammerPack;
   deployed = DeployedSensorJammer;

   mountPoint = 1;
   offset = "0 -0.2 -0.65";

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

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

   maxDepSlope = 15;
   deploySound = SensorDeploySound;
};

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

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

   shapeFile = "ammo_plasma.dts";
   mass = 5;

   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 2;

   rotate = true;

   image = DeployableSensorJammerImage;
   deployed = DeployedSensorJammer;
   pickUpName = "a deployable sensor jammer";

   computeCRC = true;
   emap = true;
};

// The jamming, color, effects come from the cap and so we add it 3/4ths of a
// second after placing the base so that it appears to be deploying.
function MakeCap(%Jammer)
{
   %Transform = %Jammer.getTransform();
   %Position = posFromTransform(%Transform);

   // Create the other part of the jammer and link the two parts together
   %PositionXY = getWords(%Position, 0, 1);
   %PositionZ = getWord(%Position, 2) + 0.4;
   %Position = %PositionXY @ " " @ %PositionZ;

   %Item = new StaticShape()
   {
      dataBlock = JammerCap;
      position = %Position;
      team = %Jammer.team;
   };
   MissionCleanup.add(%Item);

   %Jammer.Slave = %Item;
   %Item.Master = %Jammer;
   %Item.owner = %Jammer.owner;

   setTargetSensorData(%Jammer.getTarget(), SensorJammerSensor);
}