
//--------------------------------------------------------------------------
// Projectile
//--------------------------------------
datablock GrenadeProjectileData(MortarShot)
{
   projectileShapeName = "mortar_projectile.dts";

   directDamage        = 0.0;
   hasDamageRadius     = true;
   indirectDamage      = 1.0;
   damageRadius        = 20.0;
   radiusDamageType    = $DamageType::Explosion;
   kickBackStrength    = 2500;

   explosion           = "MortarExplosion";
   underwaterExplosion = "UnderwaterMortarExplosion";
   velInheritFactor    = 0.5;
   splash              = MortarSplash;
   depthTolerance      = 10.0; // depth at which it uses underwater explosion

   emitterDelay        = -1;   
   baseEmitter         = MortarSmokeEmitter;
   bubbleEmitter       = MortarBubbleEmitter;
   
   grenadeElasticity = 0.15;
   grenadeFriction   = 0.4;
   armingDelayMS     = 2000;
   muzzleVelocity    = 63.7;
   drag              = 0.1;

   sound             = MortarProjectileSound;

   hasLight    = true;
   lightRadius = 4;
   lightColor  = "0.05 0.2 0.05";

   rearDamageFactor    = 1.2;

   hasLightUnderwaterColor  = true;
   underWaterLightColor     = "0.05 0.075 0.2";

   PrematureProjectile      = MortarShotItem;
   PrematureWetTime         = 3500;
   PrematureWetTimeVariance = 3000;
};

datablock ItemData(MortarShotItem)
{
   Shapefile = "mortar_projectile.dts";

   hasDamageRadius     = true;
   indirectDamage      = 1.0;
   damageRadius        = 20.0;
   radiusDamageType    = $DamageType::Explosion;
   kickBackStrength    = 4000;

   explosion           = "MortarExplosion";
   underwaterExplosion = "UnderwaterMortarExplosion";
   velInheritFactor    = 0.5;
   splash              = MortarSplash;

   sound               = MortarProjectileSound;

   rearDamageFactor    = 1.2;

   hasLight    = true;
   lightRadius = 4;
   lightColor  = "0.05 0.2 0.05";

   hasLightUnderwaterColor = true;
   underWaterLightColor = "0.05 0.075 0.2";
};

datablock GrenadeProjectileData(MortarEMPShot)
{
   projectileShapeName = "mortar_projectile.dts";

   directDamage        = 0.0;
   hasDamageRadius     = true;
   damageRadius        = 18.0;

   velInheritFactor    = 0.5;

   EMPDuration = 16.0;
   EMPStrength = 0.07;

   underwaterExplosion = "UnderwaterMortarExplosion";
   explosion = EMPBlastExplosion;
   splash = DiscSplash;

   radiusDamageType = $DamageType::Grenade;
   kickBackStrength = 0;

   hasLight    = true;
   lightType = "PulsingLight";
   lightColor = "0.5 1.0 1.0 0.75";
   lightTime = "1000";
   lightRadius = 2;

   hasLightUnderwaterColor  = true;
   underWaterLightColor     = "0.5 1 1";

   depthTolerance      = 6.0;

   emitterDelay        = -1;
   baseEmitter         = LargeEMPHazeEmitter;
   bubbleEmitter       = MortarBubbleEmitter;
   
   grenadeElasticity = 0.15;
   grenadeFriction   = 0.4;
   armingDelayMS     = 2000;
   muzzleVelocity    = 63.7;
   drag              = 0.1;

   sound             = MortarProjectileSound;

   PrematureProjectile      = MortarEMPShotItem;
   PrematureWetTime         = 3500;
   PrematureWetTimeVariance = 3000;
};

datablock ItemData(MortarEMPShotItem)
{
   Shapefile = "mortar_projectile.dts";

   directDamage        = 0.0;
   hasDamageRadius     = true;
   damageRadius        = 18.0;

   velInheritFactor    = 0.5;

   EMPDuration = 16.0;
   EMPStrength = 0.07;

   explosion           = EMPBlastExplosion;
   underwaterExplosion = "UnderwaterMortarExplosion";
   velInheritFactor    = 0.5;
   splash              = DiscSplash;

   sound               = MortarProjectileSound;

   hasLight    = true;
   lightType = "PulsingLight";
   lightColor = "0.5 1.0 1.0 0.75";
   lightTime = "1000";
   lightRadius = 2;

   hasLightUnderwaterColor  = true;
   underWaterLightColor     = "0.5 1 1";
};

function MortarEMPShot::onExplode(%Data, %Projectile, %Position, %Modifier)
{
   %PositionXY = getWords(%Position, 0, 1);
   %PositionZ = getWord(%Position, 2) + 0.4;
   %Position = %PositionXY @ " " @ %PositionZ;

   %Owner = %Projectile.sourceObject;
   %Radius = %Data.damageRadius;
   %EMPStrength = %Data.EMPStrength;
   %EMPDuration = %Data.EMPDuration;

   // If the grenade is in the water, make it more potent
   if (%Projectile.InWater == true || CheckinWater(%Projectile) == true)
   {
      %EMPStrength *= 0.6;
      %EMPDuration *= 1.4;
      %Radius *= 1.2;
   }

   // Do the EMP checks
   EMPingCheck(%Position, %Radius, %EMPDuration, %EMPStrength, %Owner);
   schedule(1000, 0, EMPingCheck, %Position, %Radius, %EMPDuration * 0.8, %EMPStrength * 1.15, %Owner);
   schedule(2000, 0, EMPingCheck, %Position, %Radius, %EMPDuration * 0.55, %EMPStrength * 1.35, %Owner);
   schedule(3200, 0, EMPingCheck, %Position, %Radius, %EMPDuration * 0.35, %EMPStrength * 1.65, %Owner);

   AreaEMP(%Position);
   schedule(1250, 0, AreaEMP, %Position);

   if ($Host::MaxBotDifficulty > 0.8)
      MakeAvoidObject(%Position, 3800);
}

function MortarEMPShotItem::onDestroyed(%Data, %Projectile, %lastState)
{
   %Transform = %Projectile.getTransform();
   %Position = posFromTransform(%Transform);
   %PositionXY = getWords(%Position, 0, 1);
   %PositionZ = getWord(%Position, 2) + 0.4;
   %Position = %PositionXY @ " " @ %PositionZ;

   %Owner = %Projectile.sourceObject;
   %Radius = %Data.damageRadius;
   %EMPStrength = %Data.EMPStrength;
   %EMPDuration = %Data.EMPDuration;

   // If the grenade is in the water, make it more potent
   if (%Projectile.InWater == true || CheckinWater(%Projectile) == true)
   {
      %EMPStrength *= 0.6;
      %EMPDuration *= 1.4;
      %Radius *= 1.2;
   }

   // Do the EMP checks
   EMPingCheck(%Position, %Radius, %EMPDuration, %EMPStrength, %Owner);
   schedule(1100, 0, EMPingCheck, %Position, %Radius, %EMPDuration * 0.8, %EMPStrength * 1.15, %Owner);
   schedule(2200, 0, EMPingCheck, %Position, %Radius, %EMPDuration * 0.6, %EMPStrength * 1.3, %Owner);
   schedule(3500, 0, EMPingCheck, %Position, %Radius, %EMPDuration * 0.45, %EMPStrength * 1.55, %Owner);
   schedule(5000, 0, EMPingCheck, %Position, %Radius, %EMPDuration * 0.35, %EMPStrength * 1.8, %Owner);

   AreaEMP(%Position);
   schedule(1850, 0, AreaEMP, %Position);

   if ($Host::MaxBotDifficulty > 0.8)
      MakeAvoidObject(%Position, 5800);
}

datablock ExplosionData(IncendiaryMortarExplosion)
{
   explosionShape = "effect_plasma_explosion.dts";
   faceViewer = true;

   soundProfile   = plasmaExpSound;
   playSpeed = 0.14;

   emitter[0] = IncendiarySparkEmitter;
};

datablock GrenadeProjectileData(MortarIncShot)
{
   projectileShapeName = "mortar_projectile.dts";

   directDamage        = 0.0;
   hasDamageRadius     = true;
   damageRadius        = 15.0;

   velInheritFactor    = 0.5;

   BurnStrength = 0.07;
   BurnDuration = 18;

   explosion = "IncendiaryMortarExplosion";
   underwaterExplosion = "UnderwaterGrenadeExplosion";

   hasLight    = true;
   lightType = "PulsingLight";
   lightColor = "0.95 0.82 0.48 0.4";
   lightTime = "1000";
   lightRadius = "0.75";

   depthTolerance      = 2;

   emitterDelay        = -1;
   baseEmitter         = "onFireEmitter";
   bubbleEmitter       = MortarBubbleEmitter;
   
   explodeOnDeath    = false;
   reflectOnWaterImpactAngle = 0.0;
   explodeOnWaterImpact      = true;
   deflectionOnWaterImpact   = 0.0;
   fizzleUnderwaterMS        = -1;

   grenadeElasticity = 0.15;
   grenadeFriction   = 0.4;
   armingDelayMS     = 2000;
   muzzleVelocity    = 63.7;
   drag              = 0.1;

   sound             = MortarProjectileSound;
};

function MortarIncShot::onExplode(%Data, %Projectile, %Position, %Modifier)
{
   %PositionXY = getWords(%Position, 0, 1);
   %PositionZ = getWord(%Position, 2) + 0.2;
   %Position = %PositionXY @ " " @ %PositionZ;

   // If the grenade is in the water, fizzle out
   if (%Projectile.InWater == true || CheckinWater(%Projectile) == true)
      return;

   %Owner = %Projectile.sourceObject;
   %IndirectDamage = %Data.indirectDamage;
   %DamageType = %Data.radiusDamageType;
   %Radius = %Data.damageRadius;
   %DamageStrength = %Data.BurnStrength;
   %DamageDuration = %Data.BurnDuration;

   %Number = (getRandom(6.0) + 2);

   // Do the OnFire checks
   IncendiaryCheck(%Position, %Radius, %DamageDuration, %DamageStrength, %Owner);
   schedule(1000, 0, IncendiaryCheck, %Position, %Radius, %DamageDuration * 0.9, %DamageStrength * 0.9, %Owner);
   schedule(2000, 0, IncendiaryCheck, %Position, %Radius, %DamageDuration * 0.75, %DamageStrength * 0.75, %Owner);
   schedule(3000, 0, IncendiaryCheck, %Position, %Radius, %DamageDuration * 0.6, %DamageStrength * 0.6, %Owner);
   schedule(4000, 0, IncendiaryCheck, %Position, %Radius * 0.8, %DamageDuration * 0.4, %DamageStrength * 0.4, %Owner);

   schedule(5000, 0, FillAreaSmoke, %Position, %Number * 0.8, 450);

   FillAreaFire(%Position, %Radius * 0.8, %Number * 0.7);

   if ($Host::MaxBotDifficulty > 0.8)
      MakeAvoidObject(%Position, 4800);
}

datablock GrenadeProjectileData(MortarConcShot)
{
   projectileShapeName = "mortar_projectile.dts";

   hasDamageRadius   = true;
   damageRadius      = 25.0;
   radiusDamageType  = $DamageType::Explosion;
   kickBackStrength  = 6200;

   velInheritFactor    = 0.5;

   ApplyConcussion = true;

   explosion = ConcussionGrenadeExplosion;
   underwaterExplosion = UnderwaterHandGrenadeExplosion;

   hasLight    = true;
   lightType = "PulsingLight";
   lightColor = "0.8 0.8 1.0 0.4";
   lightTime = "1000";
   lightRadius = "0.75";

   depthTolerance      = 1.0;

   emitterDelay        = -1;
   baseEmitter         = ConcHazeEmitter;
   bubbleEmitter       = MortarBubbleEmitter;
   
   grenadeElasticity = 0.15;
   grenadeFriction   = 0.4;
   armingDelayMS     = 2000;
   muzzleVelocity    = 63.7;
   drag              = 0.1;

   sound             = MortarProjectileSound;

   PrematureProjectile      = MortarConcShotItem;
   PrematureWetTime         = 3500;
   PrematureWetTimeVariance = 3000;
};

datablock ItemData(MortarConcShotItem)
{
   Shapefile = "mortar_projectile.dts";

   hasDamageRadius   = true;
   damageRadius      = 25.0;
   radiusDamageType  = $DamageType::Explosion;
   kickBackStrength  = 6200;

   velInheritFactor    = 0.5;

   ApplyConcussion = true;

   explosion = ConcussionGrenadeExplosion;
   underwaterExplosion = UnderwaterHandGrenadeExplosion;

   hasLight    = true;
   lightType = "PulsingLight";
   lightColor = "0.5 0.0 0.5 0.4";
   lightTime = 1000;
   lightRadius = 2;

   hasLightUnderwaterColor = true;
   underWaterLightColor = "0.5 0.0 0.5";
};

function MortarConcShot::onExplode(%Data, %Projectile, %Position, %Modifier)
{
   %Radius = %Data.damageRadius;
   %Damage = %Data.indirectDamage;
   %KickBack = %Data.kickBackStrength;
   %Owner = %Projectile.sourceObject;
   %DamageType = %Data.radiusDamageType;

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

function MortarConcShotItem::onDestroyed(%data, %Projectile, %lastState)
{
   %Transform = %Projectile.getTransform();
   %Position = posFromTransform(%Transform);

   %Radius = %Data.damageRadius;
   %Damage = %Data.indirectDamage;
   %KickBack = %Data.kickBackStrength;
   %Owner = %Projectile.sourceObject;
   %DamageType = %Data.radiusDamageType;

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

//--------------------------------------------------------------------------
// Ammo
//--------------------------------------

datablock ItemData(MortarAmmo)
{
   className = Ammo;
   catagory = "Ammo";

   shapeFile = "ammo_mortar.dts";
   mass = 1;
   trueMass = 0.01;

   elasticity = 0.2;
   friction = 0.6;

   pickupRadius = 2;
   pickUpName = "some mortar ammo";

   computeCRC = true;

};

//--------------------------------------------------------------------------
// Weapon
//--------------------------------------
datablock ItemData(Mortar)
{
   className = Weapon;
   catagory = "Spawn Items";
   shapeFile = "weapon_mortar.dts";
   image = MortarImage;

   mass = 1;
   trueMass = 8;

   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 2;
   pickUpName = "a mortar";

   computeCRC = true;
   emap = true;
};

datablock ShapeBaseImageData(MortarImage)
{
   className = WeaponImage;
   shapeFile = "weapon_mortar.dts";

   item = Mortar;
   ammo = MortarAmmo;

   offset = "0 0 0";
   emap = true;

   WCS = true;

   ProjectileType = GrenadeProjectile;
   Projectile = MortarShot;
   EMPProjectile = MortarEMPShot;
   IncProjectile = MortarIncShot;
   ConcProjectile = MortarConcShot;

   FailSound = MortarDryFireSound;

   stateName[0] = "Activate";
   stateTransitionOnTimeout[0] = "ActivateReady";
   stateTimeoutValue[0] = 0.5;
   stateSequence[0] = "Activate";

   stateName[1] = "ActivateReady";
   stateTransitionOnLoaded[1] = "Ready";
   stateTransitionOnNoAmmo[1] = "NoAmmo";
   stateSound[1] = MortarSwitchSound;

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

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

   stateName[4] = "Reload";
   stateTransitionOnNoAmmo[4] = "NoAmmo";
   stateTransitionOnTimeout[4] = "ActivateReady";
   stateTimeoutValue[4] = 2.0;
   stateAllowImageChange[4] = false;
   stateSequence[4] = "Reload";
   stateSound[4] = MortarReloadSound;

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

   stateName[6]       = "DryFire";
   stateSound[6]      = MortarDryFireSound;
   stateTimeoutValue[6]        = 1.5;
   stateTransitionOnTimeout[6] = "NoAmmo";
};
