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

   item = ImpulseTurretBarrelPack;
   deployed = ImpulseTurretBarrel;

   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(ImpulseTurretBarrelPack)
{
   className = Pack;
   catagory = "Deployables";
   shapeFile = "turret_outdoor_deploy.dts";

   image = ImpulseTurretBarrelImage;

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

   pickupRadius = 1;
   pickUpName = "a Impulse turret barrel";

   rotate = false;

   computeCRC = true;
   emap = true;

   lightOnlyStatic = true;
   lightType = "PulsingLight";
   lightColor = "0.68 0.6 0.54 0.8";
   lightTime = 1200;
   lightRadius = 3;

   isSmallBarrel = true;
};

datablock ShockwaveData(ImpulseTurretMuzzleFlash)
{
   width = 0.5;
   numSegments = 13;
   numVertSegments = 1;
   velocity = 2.0;
   acceleration = -1.0;
   lifetimeMS = 400;
   height = 0.1;
   verticalCurve = 0.5;

   mapToTerrain = false;
   renderBottom = false;
   orientToNormal = true;
   renderSquare = true;
   
   texture[0] = "special/blasterHit";
   texture[1] = "special/gradient";
   texWrap = 3.0;

   times[0] = 0.0;
   times[1] = 0.5;
   times[2] = 1.0;

   colors[0] = "0.68 0.6 0.54 1.0";
   colors[1] = "0.5 0.44 0.39 1.0";
   colors[2] = "0.68 0.6 0.54 0.0";
};

datablock SniperProjectileData(ImpulseTurretBeam)
{
   directDamage        = 0.0;
   hasDamageRadius     = false;
   kickBackStrength    = 3200;
   velInheritFactor    = 1.0;
   sound               = SniperRifleProjectileSound;
   explosion           = "SniperExplosion";
   splash              = SniperSplash;
   directDamageType    = $DamageType::Ground;

   maxRifleRange       = 50;
   beamColor           = "0.68 0.6 0.54 1.0";
   fadeTime            = 0.9;

   startBeamWidth      = 0.145;
   endBeamWidth        = 0.25;
   pulseBeamWidth      = 0.5;
   beamFlareAngle      = 3.0;
   minFlareSize        = 0.0;
   maxFlareSize        = 400.0;

   pulseSpeed          = 6.0;
   pulseLength         = 0.150;

   lightRadius         = 1.5;
   lightColor          = "0.68 0.6 0.54";

   textureName[0]      = "special/flare";
   textureName[1]      = "special/nonlingradient";
   textureName[2]      = "special/laserrip01";
   textureName[3]      = "special/laserrip02";
   textureName[4]      = "special/laserrip03";
   textureName[5]      = "special/laserrip04";
   textureName[6]      = "special/laserrip05";
   textureName[7]      = "special/laserrip06";
   textureName[8]      = "special/laserrip07";
   textureName[9]      = "special/laserrip08";
   textureName[10]     = "special/laserrip09";
//   textureName[11]     = "special/sniper00";

};

datablock TurretImageData(ImpulseTurretBarrel)
{
   shapeFile = "turret_belly_barrell.dts";
   item      = ImpulseTurretBarrelPack;

   offset = "0.0 0.0 0.0";

   projectile = ImpulseTurretBeam;
   projectileType = SniperProjectile;

   usesEnergy = true;
   fireEnergy = 2;
   minEnergy = 10;

   lightType = "WeaponFireLight";
   lightColor = "0.68 0.6 0.54 0.8";
   lightTime = "1000";
   lightRadius = "2";

   muzzleFlash = ImpulseTurretMuzzleFlash;

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

   // 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]          = 0.7;
   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 ImpulseTurretBarrel::onFire(%Data, %Turret, %Slot)
{   
   %Vector = %Turret.getMuzzleVector(%Slot);
   %Position = %Turret.getMuzzlePoint(%Slot);

   %Projectile = new SniperProjectile() 
   {
      dataBlock        = ImpulseTurretBeam;
      initialDirection = %Vector;
      initialPosition  = %Position;
      sourceObject     = %Turret;
      damageFactor     = 1;
      sourceSlot       = %Slot;
   };
   %Projectile.setEnergyPercentage(1.0);
   MissionCleanup.add(%Projectile);

   %Turret.lastProjectile = %Projectile;
}


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

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

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