

datablock ShapeBaseImageData(EMPTurretBarrelImage)
{
   mass = 2.5;
   emap = true;

   item = EMPTurretBarrelPack;
   deployed = EMPTurretBarrel;

   shapeFile = "turret_indoor_deployf.dts";
   offset = "0 0 -0.2";
   mountPoint = 1;

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

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

   SmallTurretBarrel = true;

   maxDepSlope = 360;
};

datablock ItemData(EMPTurretBarrelPack)
{
   className = Pack;
   catagory = "Deployables";
   shapeFile = "turret_outdoor_deploy.dts";

   image = EMPTurretBarrelImage;

   mass = 2.5;
   elasticity = 0.2;
   friction = 0.6;

   pickupRadius = 1;
   pickUpName = "an EMP turret barrel";

   DeployPercent = 0.4;

   rotate = false;

   computeCRC = true;
   emap = true;

   lightOnlyStatic = true;
   lightType = "PulsingLight";
   lightColor = "0.75 1.0 1.0 0.8";
   lightTime = 1800;
   lightRadius = 3;

   isSmallBarrel = true;
};

datablock LinearFlareProjectileData(EMPTurretBolt)
{
   directDamage        = 0.0;
   directDamageType    = $DamageType::Energy;
   explosion           = "EMPBlastExplosion";

   hasDamageRadius = false;
   indirectDamage = 0.0;
   damageRadius = 18.0;

   EMPDuration = 6.0;
   EMPStrength = 0.35;

   dryVelocity       = 140.0;
   wetVelocity       = 80.0;
   velInheritFactor  = 0.5;

   fizzleTimeMS      = 400;
   lifetimeMS        = 1000;
   explodeOnDeath    = true;

   reflectOnWaterImpactAngle = 0.0;
   explodeOnWaterImpact      = false;
   deflectionOnWaterImpact   = 0.0;
   fizzleUnderwaterMS        = 3000;

   numFlares         = 8;
   size              = 0.45;
   flareColor        = "0.8 1.0 1.0";
   flareModTexture   = "flaremod";
   flareBaseTexture  = "flarebase";

   sound = BlasterProjectileSound;

   hasLight    = true;
   lightRadius = 2.4;
   lightColor  = "0.8 1.0 1.0";
};


datablock TurretImageData(EMPTurretBarrel)
{
   shapeFile = "camera.dts";
   item      = EMPTurretBarrelPack;

   usesEnergy = true;
   fireEnergy = 3;
   minEnergy = 8;

   projectile = EMPTurretBolt;
   projectileType = LinearFlareProjectile;

   lightType = "WeaponFireLight";
   lightColor = "0.75 1.0 1.0 0.8";
   lightTime = "1000";
   lightRadius = "2";

   // Turret parameters
   activationMS      = 150;
   deactivateDelayMS = 300;
   thinkTimeMS       = 150;
   degPerSecTheta    = 580;
   degPerSecPhi      = 960;
   attackRadius      = 25;

   // State transitions
   stateName[0]                  = "Activate";
   stateTransitionOnNotLoaded[0] = "Dead";
   stateTransitionOnLoaded[0]    = "ActivateReady";

   stateName[1]                  = "ActivateReady";
   stateSequence[1]              = "Activate";
   stateTimeoutValue[1]          = 1;
   stateTransitionOnTimeout[1]   = "Ready";
   stateTransitionOnNotLoaded[1] = "Deactivate";
   stateTransitionOnNoAmmo[1]    = "NoAmmo";

   stateName[2]                    = "Ready";
   stateTransitionOnNotLoaded[2]   = "Deactivate";
   stateTransitionOnTriggerDown[2] = "Fire";
   stateTransitionOnNoAmmo[2]      = "NoAmmo";
   stateSound[2]                   = SniperRifleSwitchSound;

   stateName[3]                = "Fire";
   stateTransitionOnTimeout[3] = "Reload";
   stateTimeoutValue[3]        = 0.3;
   stateFire[3]                = true;
   stateShockwave[3]           = true;
   stateRecoil[3]              = LightRecoil;
   stateAllowImageChange[3]    = false;
   stateSequence[3]            = "Fire";
   stateSound[3]               = SniperRifleFireSound;
   stateScript[3]              = "onFire";

   stateName[4]                  = "Reload";
   stateTimeoutValue[4]          = 1.2;
   stateAllowImageChange[4]      = false;
   stateSequence[4]              = "Reload";
   stateTransitionOnTimeout[4]   = "Ready";
   stateTransitionOnNotLoaded[4] = "Deactivate";
   stateTransitionOnNoAmmo[4]    = "NoAmmo";

   stateName[5]                = "Deactivate";
   stateSequence[5]            = "Activate";
   stateDirection[5]           = false;
   stateTimeoutValue[5]        = 1;
   stateTransitionOnLoaded[5]  = "ActivateReady";
   stateTransitionOnTimeout[5] = "Dead";

   stateName[6]               = "Dead";
   stateTransitionOnLoaded[6] = "ActivateReady";

   stateName[7]             = "NoAmmo";
   stateTransitionOnAmmo[7] = "Reload";
   stateSequence[7]         = "NoAmmo";
};

function EMPTurretBarrelImage::onActivate(%Data, %Pack, %Slot)
{
   checkSmallTurretMount(%Data, %Pack, %Slot);
}

function EMPTurretBarrelImage::onDeactivate(%Data, %Pack, %Slot)
{
   %Pack.setImageTrigger($BackpackSlot, false);
}

function EMPTurretBarrelImage::onPickup(%This, %Pack, %Shape, %Amount)
{
   // created to prevent console errors
}

function EMPTurretBolt::onExplode(%Data, %Projectile, %Position, %Modifier)
{
   %Radius = %Data.damageRadius;
   %EMPStrength = %Data.EMPStrength;
   %EMPDuration = %Data.EMPDuration;

   echo("Projectile Type: " @ %Projectile.getDataBlock().getName());
   echo("Position: " @ %Position);
   echo("Radius: " @ %Radius);
   echo("Strength: " @ %EMPStrength);
   echo("Duration: " @ %EMPDuration);

   // Do the EMP checks
   EMPingCheck(%Position, %Radius, %EMPDuration, %EMPStrength, 0);
   schedule(800, 0, EMPingCheck, %Position, %Radius, %EMPDuration * 0.8, %EMPStrength * 1.2, 0);
   schedule(1600, 0, EMPingCheck, %Position, %Radius, %EMPDuration * 0.6, %EMPStrength * 1.4, 0);
}