
//**************************************************************
// BEOWULF ASSAULT VEHICLE
//**************************************************************

//**************************************************************
// SOUNDS
//**************************************************************

datablock AudioProfile(AssaultVehicleSkid)
{
   filename    = "fx/vehicles/tank_skid.wav";
   description = ClosestLooping3d;
   preload = true;
};

datablock AudioProfile(AssaultVehicleEngineSound)
{
   filename    = "fx/vehicles/tank_engine.wav";
   description = AudioDefaultLooping3d;
   preload = true;
};

datablock AudioProfile(AssaultVehicleThrustSound)
{
   filename    = "fx/vehicles/tank_boost.wav";
   description = AudioDefaultLooping3d;
   preload = true;
};

datablock AudioProfile(AssaultChaingunTurretBarrelFireSound)
{
   filename    = "fx/vehicles/tank_chaingun.wav";
   description = AudioDefaultLooping3d;
   preload = true;
};

datablock AudioProfile(AssaultChaingunTurretBarrelReloadSound)
{
   filename    = "fx/weapons/chaingun_dryfire.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(TankChaingunProjectile)
{
   filename    = "fx/weapons/chaingun_projectile.wav";
   description = ProjectileLooping3d;
   preload = true;
};

datablock AudioProfile(AssaultTurretActivateSound)
{
    filename    = "fx/vehicles/tank_activate.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(AssaultChaingunTurretBarrelDryFireSound)
{
   filename    = "fx/weapons/chaingun_dryfire.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(AssaultChaingunTurretBarrelIdleSound)
{
   filename    = "fx/misc/diagnostic_on.wav";
   description = ClosestLooping3d;
   preload = true;
};

datablock AudioProfile(AssaultCannonDryFireSound)
{
   filename    = "fx/weapons/mortar_dryfire.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(AssaultCannonFireSound)
{
   filename    = "fx/vehicles/tank_mortar_fire.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(AssaultCannonReloadSound)
{
   filename    = "fx/weapons/mortar_reload.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(AssaultCannonIdleSound)
{
   filename    = "fx/misc/diagnostic_on.wav";
   description = ClosestLooping3d;
   preload = true;
};

//**************************************************************
// LIGHTS
//**************************************************************
datablock RunningLightData(TankLight1)
{
   radius = 1.5;
   color = "1.0 1.0 1.0 0.2";
   nodeName = "Headlight_node01";
   direction = "0.0 1.0 0.0";
   texture = "special/headlight4";
};

datablock RunningLightData(TankLight2)
{
   radius = 1.5;
   color = "1.0 1.0 1.0 0.2";
   nodeName = "Headlight_node02";
   direction = "0.0 1.0 0.0";
   texture = "special/headlight4";
};

datablock RunningLightData(TankLight3)
{
   radius = 1.5;
   color = "1.0 1.0 1.0 0.2";
   nodeName = "Headlight_node03";
   direction = "0.0 1.0 0.0";
   texture = "special/headlight4";
};

datablock RunningLightData(TankLight4)
{
   radius = 1.5;
   color = "1.0 1.0 1.0 0.2";
   nodeName = "Headlight_node04";
   direction = "0.0 1.0 0.0";
   texture = "special/headlight4";
};

//**************************************************************
// VEHICLE CHARACTERISTICS
//**************************************************************

datablock HoverVehicleData(AssaultVehicle) : TankDamageProfile
{
   spawnOffset = "0 0 4";

   floatingGravMag = 4.5;

   catagory = "Vehicles";
   shapeFile = "vehicle_grav_tank.dts";
   multipassenger = true;
   computeCRC = true;
                                                 
   weaponNode = 1;

   debrisBase = 12;
   debrisVariance = 8;
   debrisShapeName = "vehicle_land_assault_debris.dts";
//   debris = ShapeDebris;
   debrisEjectionScale = 1.6;

   drag = 0.0;
   density = 0.9;

   mountPose[0] = sitting;
   mountPose[1] = sitting;
   numMountPoints = 2;
   isProtectedMountPoint[0] = true;
   isProtectedMountPoint[1] = true;

   cameraMaxDist = 20;
   cameraOffset = 3;
   cameraLag = 1.5;
   explosion = LargeGroundVehicleExplosion;
   explosionDamage = 2.5;
   explosionRadius = 35.0;
   explosionImpulse = 6500;

   maxSteeringAngle = 0.7;  // 20 deg.

   maxDamage = 3.45;
   destroyedLevel = 3.45;

   isShielded = true;
   rechargeRate = 0.55;
   energyPerDamagePoint = 80;
   maxEnergy = 425;
   minJetEnergy = 15;
   jetEnergyDrain = 1.6;

   ELFDrain  = 3.0;

   // Rigid Body
   mass = 1200;
   bodyFriction = 0.8;
   bodyRestitution = 0.5;
   minRollSpeed = 3;
   gyroForce = 450;
   gyroDamping = 0.3;
   stabilizerForce = 20;
   minDrag = 10;
   softImpactSpeed = 15;       // Play SoftImpact Sound
   hardImpactSpeed = 18;      // Play HardImpact Sound

   // Ground Impact Damage (uses DamageType::Ground)
   minImpactSpeed = 20;
   speedDamageScale = 0.045;

   // Object Impact Damage (uses DamageType::Impact)
   collDamageThresholdVel = 20;
   collDamageMultiplier   = 0.070;

   dragForce            = 40 / 20;
   vertFactor           = 0.0;
   floatingThrustFactor = 0.15;

   mainThrustForce    = 50;
   reverseThrustForce = 40;
   strafeThrustForce  = 40;
   turboFactor        = 1.5;

   brakingForce = 35;

   brakingActivationSpeed = 4;

   stabLenMin = 3.25;
   stabLenMax = 4;
   stabSpringConstant  = 50;
   stabDampingConstant = 20;

   gyroDrag = 20;
   normalForce = 20;
   restorativeForce = 10;
   steeringForce = 15;
   rollForce  = 5;
   pitchForce = 3;

   dustEmitter = TankDustEmitter;
   triggerDustHeight = 3.5;
   dustHeight = 1.0;
   dustTrailEmitter = TireEmitter;
   dustTrailOffset = "0.0 -1.0 0.5";
   triggerTrailHeight = 3.6;
   dustTrailFreqMod = 15.0;

   jetSound         = AssaultVehicleThrustSound;
   engineSound      = AssaultVehicleEngineSound;
   floatSound       = AssaultVehicleSkid;
   softImpactSound  = GravSoftImpactSound;
   hardImpactSound  = HardImpactSound;
   wheelImpactSound = WheelImpactSound;

   forwardJetEmitter = TankJetEmitter;
   
   //
   softSplashSoundVelocity = 5.0; 
   mediumSplashSoundVelocity = 10.0;   
   hardSplashSoundVelocity = 15.0;   
   exitSplashSoundVelocity = 10.0;
   
   exitingWater      = VehicleExitWaterMediumSound;
   impactWaterEasy   = VehicleImpactWaterSoftSound;
   impactWaterMedium = VehicleImpactWaterMediumSound;
   impactWaterHard   = VehicleImpactWaterMediumSound;
   waterWakeSound    = VehicleWakeMediumSplashSound; 

   minMountDist = 4;

   damageEmitter[0] = SmallLightDamageSmoke;
   damageEmitter[1] = SmallHeavyDamageSmoke;
   damageEmitter[2] = DamageBubbles;
   damageEmitterOffset[0] = "0.0 -1.5 3.5 ";
   damageLevelTolerance[0] = 0.3;
   damageLevelTolerance[1] = 0.7;
   numDmgEmitterAreas = 1;

   splashEmitter[0] = VehicleFoamDropletsEmitter;
   splashEmitter[1] = VehicleFoamEmitter;

   shieldImpact = VehicleShieldImpact;

   cmdCategory = "Tactical";
   cmdIcon = CMDGroundTankIcon;
   cmdMiniIconName = "commander/MiniIcons/com_tank_grey";
   targetNameTag = 'Beowulf';
   targetTypeTag = 'Assault Vehicle';
   sensorData = VehiclePulseSensor;
   
   checkRadius = 5.5535;
   observeParameters = "1 10 10";
};

//**************************************************************
// WEAPONS
//**************************************************************

//-------------------------------------
// ASSAULT TURRET
//-------------------------------------

datablock TurretData(AssaultTurret) : TurretDamageProfile
{
   className      = VehicleTurret;
   catagory       = "Turrets";
   shapeFile      = "Turret_tank_base.dts";
   preload        = true;

   mass           = 1.0;  // Not really relevant

   maxEnergy      = 1;
   maxDamage      = AssaultVehicle.maxDamage;
   destroyedLevel = AssaultVehicle.destroyedLevel;
   repairRate     = 0;

   thetaMin = 0;
   thetaMax = 100;

   reloadSound = AssaultCannonReloadSound;

   inheritEnergyFromMount = true;
   firstPersonOnly = true;
   useEyePoint = true;
   numWeapons = 2;

   cameraDefaultFov = 90.0;
   cameraMinFov = 5.0;
   cameraMaxFov = 120.0;

   targetNameTag = 'Beowulf Turret';
   targetTypeTag = 'Turret';
};

//-------------------------------------
// ASSAULT CHAINGUN
//-------------------------------------

datablock TracerProjectileData(AssaultChaingunBullet)
{
   doDynamicClientHits = true;

   projectileShapeName = "";
   directDamage        = 0.16;
   directDamageType    = $DamageType::Bullet;
   hasDamageRadius     = false;

   splash              = ChaingunSplash;

   kickbackstrength    = 50.0;
   sound               = TankChaingunProjectile;

   dryVelocity       = 425.0;
   wetVelocity       = 100.0;

   velInheritFactor  = 1.0;
   fizzleTimeMS      = 4000;
   lifetimeMS        = 4000;
   explodeOnDeath    = false;

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

   tracerLength    = 15.0;
   tracerAlpha     = false;
   tracerMinPixels = 6;
   tracerColor     = "0.83 0.84 0.48 0.75";
   tracerTex[0]    = "special/tracer00";
   tracerTex[1]    = "special/tracercross";
   tracerWidth     = 0.10;

   crossSize       = 0.20;
   crossViewAng    = 0.990;
   renderCross     = true;

   decalData[0] = ChaingunDecal1;
   decalData[1] = ChaingunDecal2;
   decalData[2] = ChaingunDecal3;
   decalData[3] = ChaingunDecal4;
   decalData[4] = ChaingunDecal5;
   decalData[5] = ChaingunDecal6;

   activateDelayMS   = 100;

   explosion = ChaingunExplosion;
};

datablock TurretImageData(AssaultChaingunImage)
{
   shapeFile = "turret_tank_barrelchain.dts";
   mountPoint = 1;

   offset = "0 0 0";
};

datablock TurretImageData(AssaultChaingunTurretBarrel)
{
   shapeFile = "turret_muzzlepoint.dts";
   mountPoint = 1;

   offset = "0 3.0 0";

   projectile = AssaultChaingunBullet;
   projectileType = TracerProjectile;

   casing              = ShellDebris;
   shellExitDir        = "1.0 0.3 1.0";
   shellExitOffset     = "0.15 -0.56 -0.1";
   shellExitVariance   = 15.0;
   shellVelocity       = 3.0;

   projectileSpread = 5.0 / 1000.0;

   usesEnergy = true;
   useMountEnergy = true;
   fireEnergy = 3.5;
   minEnergy = 12.0;

   // Turret parameters
   activationMS      = 4000;
   deactivateDelayMS = 500;
   thinkTimeMS       = 200;
   degPerSecTheta    = 360;
   degPerSecPhi      = 360;
   attackRadius      = 75;

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

   stateName[1]                  = "ActivateReady";
   stateSequence[1]              = "Activate";
   stateSound[1]                 = AssaultTurretActivateSound;
   stateTimeoutValue[1]          = 1;
   stateTransitionOnTimeout[1]   = "Ready";
   stateTransitionOnNotLoaded[1] = "Deactivate";

   stateName[2]                    = "Ready";
   stateTransitionOnNotLoaded[2]   = "Deactivate";
   stateTransitionOnTriggerDown[2] = "Fire";

   stateName[3]                  = "Fire";
   stateSequence[3]              = "Fire";
   stateSequenceRandomFlash[3]   = true;
   stateFire[3]                  = true;
   stateAllowImageChange[3]      = false;
   stateSound[3]                 = AssaultChaingunTurretBarrelFireSound;
   stateScript[3]                = "onFire";
   stateTimeoutValue[3]          = 0.15;
   stateTransitionOnTimeout[3]   = "Fire";
   stateTransitionOnTriggerUp[3] = "Reload";
   stateTransitionOnNoAmmo[3]    = "Reload";

   stateName[4]                  = "Reload";
   stateTimeoutValue[4]          = 0.08;
   stateAllowImageChange[4]      = false;
   stateSequence[4]              = "Reload";
   stateTransitionOnTimeout[4]   = "Ready";
   stateTransitionOnNotLoaded[4] = "Deactivate";
                                 
   stateName[5]                = "Deactivate";
   stateSequence[5]            = "Activate";
   stateDirection[5]           = false;
   stateTimeoutValue[5]        = 30;
   stateTransitionOnTimeout[5] = "ActivateReady";

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

   stateName[7]                = "DryFire";
   stateSound[7]               = AssaultChaingunTurretBarrelDryFireSound;
   stateTimeoutValue[7]        = 0.5;
   stateTransitionOnTimeout[7] = "NoAmmo";

   stateName[8]                      = "NoAmmo";
   stateTransitionOnAmmo[8]          = "Reload";
   stateSequence[8]                  = "NoAmmo";
   stateTransitionOnTriggerDown[8]   = "DryFire";

};

//-------------------------------------
// ASSAULT SHELL (projectile)
//-------------------------------------

datablock GrenadeProjectileData(AssaultShell)
{
   projectileShapeName = "grenade_projectile.dts";
   emitterDelay        = -1;
   directDamage        = 0.3;
   hasDamageRadius     = true;
   indirectDamage      = 1.4;
   damageRadius        = 25.0;
   radiusDamageType    = $DamageType::Explosion;
   kickBackStrength    = 6000;

   sound               = MortarProjectileSound;

   scale               = "2 2 2";

   explosion           = SatchelMainExplosion;
   underwaterExplosion = UnderwaterSatchelMainExplosion;

   velInheritFactor    = 1.0;

   grenadeElasticity   = 0.0;
   grenadeFriction     = 1.0;
   armingDelayMS       = 250;
   muzzleVelocity      = 500;
   drag                = 0.4;
};

datablock LinearProjectileData(AssaultLinearShell)
{
   projectileShapeName = "grenade_projectile.dts";
   emitterDelay        = -1;
   directDamage        = 0.3;
   hasDamageRadius     = true;
   indirectDamage      = 1.4;
   damageRadius        = 25.0;
   radiusDamageType    = $DamageType::Explosion;
   kickBackStrength    = 6000;

   sound               = MortarProjectileSound;

   scale               = "2.5 2.5 2.5";

   explosion           = SatchelMainExplosion;
   underwaterExplosion = UnderwaterSatchelMainExplosion;

   velInheritFactor    = 1.0;

   dryVelocity = 500;
   wetVelocity = 500;
};

//-------------------------------------
// ASSAULT CANNON CHARACTERISTICS
//-------------------------------------

datablock TurretImageData(AssaultCannonTurretBarrel)
{
   shapeFile = "turret_tank_barrelmortar.dts";
   mountPoint = 0;

   projectile = AssaultShell;
   projectileType = GrenadeProjectile;

   usesEnergy = true;
   useMountEnergy = true;
   fireEnergy = 1.00;
   minEnergy = 1.00;

   // Turret parameters
   activationMS      = 4000;
   deactivateDelayMS = 1500;
   thinkTimeMS       = 200;
   degPerSecTheta    = 360;
   degPerSecPhi      = 360;
   attackRadius      = 75;

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

   stateName[1]                    = "ActivateReady";
   stateSequence[1]                = "Activate";
   stateSound[1]                   = AssaultTurretActivateSound;
   stateTimeoutValue[1]            = 2.5;
   stateTransitionOnTimeout[1]     = "Ready";
   stateTransitionOnNotLoaded[1]   = "Deactivate";

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

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

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

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

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

   stateName[7]                    = "DryFire";
   stateTimeoutValue[7]            = 0.5;
   stateTransitionOnTimeout[7]     = "NoAmmo";

   stateName[8]                      = "NoAmmo";
   stateTransitionOnAmmo[8]          = "Reload";
   stateSequence[8]                  = "NoAmmo";
   stateTransitionOnTriggerDown[8]   = "DryFire";
};

datablock TurretImageData(AssaultTurretParam)
{
   mountPoint        = 2;
   shapeFile         = "turret_muzzlepoint.dts";

   // Turret parameters
   activationMS      = 1000;
   deactivateDelayMS = 1500;
   thinkTimeMS       = 200;
   degPerSecTheta    = 500;
   degPerSecPhi      = 500;

   projectile        = AssaultShell;
   projectileType    = GrenadeProjectile;
   
   attackRadius      = 150;
};

function AssaultCannonTurretBarrel::onFire(%Data, %Turret, %Slot)
{
   %TurretPosition = %Turret.getMuzzlePoint(%Slot);

   if (%Turret.NoFire == true)
   {
      serverPlay3D(AssaultCannonDryFireSound, %TurretPosition);
      return;
   }
   %Turret.NoFire = true;

   // Determine the vehicle the turret is attached to
   %Vehicle = %Turret.getObjectMount();

   // Search for an object in turrets's LOS to check for nearby collisions
   %MuzzleVector = %Turret.getMuzzleVector(%Slot);
   %ScaledVector = VectorScale(%MuzzleVector, 150);
   %End = VectorAdd(%TurretPosition, %ScaledVector);

   %Target = ContainerRayCast(%TurretPosition, %End, $EverythingMask, %Turret);

   // If nothing was found, we fire like normal.  If something was, then 
   // fire the linear version of it (explodes on contact, no arming needed).
   if(%Target !$= "0")
   {
      %Projectile = new LinearProjectile()
      {
         dataBlock        = AssaultLinearShell;
         initialDirection = %MuzzleVector;
         initialPosition  = %TurretPosition;
         scale            = AssaultLinearShell.scale;
         sourceObject     = %Turret;
         sourceSlot       = %Slot;
         vehicleObject    = %Vehicle;
      };
   } else {
      %Projectile = new GrenadeProjectile()
      {
         dataBlock        = AssaultShell;
         initialDirection = %MuzzleVector;
         initialPosition  = %TurretPosition;
         scale            = AssaultShell.scale;
         sourceObject     = %Turret;
         sourceSlot       = %Slot;
         vehicleObject    = %Vehicle;
      };
   }
   MissionCleanup.add(%Projectile);

   serverPlay3D(AssaultCannonFireSound, %TurretPosition);

   %Turret.lastProjectile = %Projectile;

   %EnergyRequired = AssaultVehicle.maxEnergy * 0.2 + 40;

   // Schedule the reloading later on
   schedule(5100, 0, ResetTurret, %Turret, %Vehicle, %EnergyRequired);
   
   return(%Projectile);
}
