

datablock ShapeBaseImageData(FlameTurretBarrelImage)
{
   mass = 1.5;
   emap = true;

   item = FlameTurretBarrelPack;
   deployed = FlameTurretBarrel;

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

   image = FlameTurretBarrelImage;

   mass = 1.5;
   elasticity = 0.2;
   friction = 0.6;

   pickupRadius = 1;
   pickUpName = "a Flame Turret barrel";

   DeployPercent = 0.4;

   rotate = false;

   computeCRC = true;
   emap = true;

   lightOnlyStatic = true;
   lightType = "PulsingLight";
   lightColor = "0.9 0.54 0 0.8";
   lightTime = 800;
   lightRadius = 3;

   isSmallBarrel = true;
};

datablock ShockwaveData(FlameTurretMuzzleFlash)
{
   width = 0.5;
   numSegments = 13;
   numVertSegments = 1;
   velocity = 2.0;
   acceleration = -1.0;
   lifetimeMS = 500;
   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] = "1 0.75 0.25 1.0";
   colors[1] = "1 0.75 0.25 1.0";
   colors[2] = "1 0.75 0.25 0.0";
};

datablock LinearFlareProjectileData(FlameTurretBall)
{
   projectileShapeName       = "plasmabolt.dts";
   scale                     = "0.55 0.55 0.65";
   faceViewer                = true;

   directDamage              = 0.0;
   hasDamageRadius           = true;
   indirectDamage            = 0.05;
   damageRadius              = 2.5;
   kickBackStrength          = 0.0;
   BurnStrength              = 0.03;
   BurnDuration              = 6;
   radiusDamageType          = $DamageType::Fire;

   explosion                 = "PlasmaBoltExplosion";
   splash                    = PlasmaSplash;

   dryVelocity               = 55.0;
   wetVelocity               = -1;
   velInheritFactor          = 0.3;
   fizzleTimeMS              = 2000;
   lifetimeMS                = 3000;
   explodeOnDeath            = false;
   reflectOnWaterImpactAngle = 0.0;
   explodeOnWaterImpact      = true;
   deflectionOnWaterImpact   = 0.0;
   fizzleUnderwaterMS        = -1;

   activateDelayMS           = -1;

   size[0]                   = 0.1;
   size[1]                   = 0.3;
   size[2]                   = 0.05;

   numFlares                 = 35;
   flareColor                = "1 0.75 0.25";
   flareModTexture           = "flaremod";
   flareBaseTexture          = "flarebase";

   sound                      = PlasmaProjectileSound;
   fireSound                 = PlasmaFireSound;
   wetFireSound              = PlasmaFireWetSound;
   
   hasLight                  = true;
   lightRadius               = 1.6;
   lightColor                = "1 0.75 0.25";
};

datablock TurretImageData(FlameTurretBarrel)
{
   shapeFile = "grenade.dts"; //grenade_projectile.dts
   item      = FlameTurretBarrelPack;

   projectile = FlameTurretBall;
   projectileType = LinearFlareProjectile;

   offset = "0 -0.05 -0.15";

   usesEnergy = true;
   fireEnergy = 1.4;
   minEnergy = 5;

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

   muzzleFlash = FlameTurretMuzzleFlash;

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

   // 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]                   = PlasmaSwitchSound;

   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]               = PlasmaFireSound;
   stateScript[3]              = "onFire";

   stateName[4]                  = "Reload";
   stateTimeoutValue[4]          = 2.5;
   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 FlameTurretBarrelImage::onActivate(%Data, %Pack, %Slot)
{
   checkSmallTurretMount(%Data, %Pack, %Slot);
}

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

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

function FlameTurretBall::onExplode(%Data, %Projectile, %Position, %Modifier)
{
   %Radius = %Data.damageRadius;
   %Damage = %Data.indirectDamage;
   %KickBack = %Data.kickBackStrength;
   %SourceObject = %Projectile.sourceObject;
   %DamageStrength = %Data.BurnStrength;
   %DamageDuration = %Data.BurnDuration;

   %DamageType = %Data.radiusDamageType;

   IncendiaryCheck(%Position, %Radius, %DamageDuration, %DamageStrength, %Owner);
   schedule(1000, 0, IncendiaryCheck, %Position, %Radius, %DamageDuration * 0.45, %DamageStrength * 0.35, %Owner);

   RadiusExplosion(%Projectile, %Position, %Radius, %Damage, %KickBack, %SourceObject, %DamageType);
}