
//---------------------------------------------------------------------------
// Explosion
//---------------------------------------------------------------------------

datablock ItemData(IncendiaryGrenadeThrown)
{
   className = Weapon;
   shapeFile = "grenade_projectile.dts";
   mass = 0.6;

   elasticity = 0.6;
   friction = 0.3;

   pickupRadius = 1;
   maxDamage = 0.5;
   indirectDamage = 0.075;
   damageRadius = 8.0;
   radiusDamageType = $DamageType::Grenade;
   kickBackStrength = 0;
   BurnStrength = 0.04;
   BurnDuration = 9;

   explosion = IncendiaryGrenadeExplosion;
   underwaterExplosion = UnderwaterHandGrenadeExplosion;

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

datablock ItemData(IncendiaryGrenade)
{
   className = HandInventory;
   catagory = "Handheld";
   shapeFile = "grenade_projectile.dts";

   mass = 1.0;
   trueMass = 0.08;

   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 1;
   thrownItem = IncendiaryGrenadeThrown;
   pickUpName = "some incendiary grenades";
};

function IncendiaryGrenadeThrown::onAdd(%this, %Grenade)
{
   schedule(2250, %Grenade, "detonateIncendiaryGrenade", %Grenade);
   %Grenade.InWater = %Grenade.sourceObject.InWater;
}

function detonateIncendiaryGrenade(%Grenade)
{
   %Transform = %Grenade.getTransform();
   %Position = posFromTransform(%Transform);
   %PositionXY = getWords(%Position, 0, 1);
   %PositionZ = getWord(%Position, 2) + 0.2;
   %Position = %PositionXY @ " " @ %PositionZ;

   // If the grenade is in the water, fizzle out
   if (%Grenade.InWater == true || CheckinWater(%Grenade) == true)
   {
      UnderwaterIncendiary(%Position);
      %Grenade.schedule(50, "delete");
      return;
   }

   %Grenade.setDamageState(Destroyed);

   %Owner = %Grenade.sourceObject;
   %IndirectDamage = %Grenade.getDatablock().indirectDamage;
   %DamageType = %Grenade.getDatablock().radiusDamageType;
   %Radius = %Grenade.getDatablock().damageRadius;
   %DamageStrength = %Grenade.getDatablock().BurnStrength;
   %DamageDuration = %Grenade.getDatablock().BurnDuration;

   %Number = (getRandom(4.0) + 1);

   // Do the OnFire checks
   IncendiaryCheck(%Position, %Radius, %DamageDuration, %DamageStrength, %Owner);
   schedule(750, 0, IncendiaryCheck, %Position, %Radius, %DamageDuration * 0.8, %DamageStrength * 0.6, %Owner);
   schedule(1500, 0, IncendiaryCheck, %Position, %Radius, %DamageDuration * 0.6, %DamageStrength * 0.5, %Owner);
   schedule(2250, 0, IncendiaryCheck, %Position, %Radius, %DamageDuration * 0.4, %DamageStrength * 0.4, %Owner);
   schedule(3000, 0, IncendiaryCheck, %Position, %Radius * 0.8, %DamageDuration * 0.2, %DamageStrength * 0.2, %Owner);
   schedule(3600, 0, FillAreaSmoke, %Position, %Number * 0.8, 450);

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

   %Grenade.schedule(200, "delete");

   if ($Host::MaxBotDifficulty > 0.9)
      MakeAvoidObject(%Position, 4200);
}