
//----------------------------------------------------------------------------
// Burn Function
//----------------------------------------------------------------------------
// This controls the Burning of a player.  It sets three variables at the player
// level, the strength of the Burn, the duration of it's effects, and the last
// player responsible for Burning (to give the kill credit).  Time should
// passed in intervals of 1 second, that is how it cycles.  The strength of the 
// Burn drops off over time at a rate of 20% every cycle.  If you are being 
// Burned and you are currently Burned, then 80% of the duration and strength
// is added to the current duration and strength.  It is possible, but very 
// difficult to torch a player.  The parameters for Duration and Strength
// should be tweeked for each use of it, not within this function.  

// Usage:  PlayerID.Burn([Burn Duration], [Initial Burn Damage], [Player who Burned them]);

function Player::Burn(%this, %Duration, %Damage, %Damager)
{
   //Make sure the user is not invincible (Initial Spawn).
   if(%this.invincible)
   {
      return;
   }

   %this.BurnDamager = %Damager;
   if (%this.BurnTime > 0)
   {
      // If already Burned, then increase the time a bit and the damage it does.
      %this.BurnTime += (%Duration * 0.8);
      %this.BurnStrength += (%Damage * 0.8);

   } else {

      %this.BurnTime = %Duration;
      %this.BurnStrength = %Damage;
 
      // Schedule a Burn check
      messageClient(%this.client, '', 'You caught on fire.');
      %this.BurnCheck = %this.schedule(750, BurnCheck);
   }
}

function Player::BurnCheck(%this)
{
   // This function loops through every second and applies the Burn damage.
   %this.getDataBlock().damageObject(%this, %this.BurnDamager, "0 0 0", %this.BurnStrength, $DamageType::Fire);
   %this.BurnTime --;

   // Add heat to player so that they can easier to fire upon
   %Heat = %this.getHeat();
   %this.setHeat(%Heat + 35);

   if (%this.BurnTime > 2)
   {
      // Do the flare up effect around a player
      %this.OnFireEffect();
      %this.schedule(330, OnFireEffect);
      %this.schedule(665, OnFireEffect);
   } else {
      // If 2 seconds from the fire going out do the smoke instead and continue the smoke
      // 2 seconds after the fire goes out. (Smoldering).
      %this.PlayerSmokeEffect();
      %this.schedule(350, PlayerSmokeEffect);
      %this.schedule(650, PlayerSmokeEffect);
   }

   if (%this.BurnTime > 0)
   {
      // The Burn gets less and less effective as time goes on.
      %this.BurnStrength *= 0.92;
      %this.BurnCheck = %this.schedule(1000, BurnCheck);
   } else {
      if (%this.client.player == %this)
         messageClient(%this.client, "", "You stop Burning.");

      %this.schedule(750, PlayerSmokeEffect);
      %this.schedule(1500, PlayerSmokeEffect);
      %this.schedule(2500, PlayerSmokeEffect);
   }
}

function IncendiaryCheck(%Position, %Radius, %DamageDuration, %DamageStrength, %Owner)
{
   // check the damageRadius for objects we can damage/set on fire
   InitContainerRadiusSearch(%Position, %Radius, $TypeMasks::PlayerObjectType);

   while ((%Object = containerSearchNext()) != 0)
   {
      %DistanceFromBlast = containerSearchCurrRadDamageDist();

      if (%DistanceFromBlast > %Radius)
         continue;

      %PercentExposed = calcExplosionCoverage(%Position, %Object,
                                         ($TypeMasks::InteriorObjectType |
                                          $TypeMasks::TerrainObjectType |
                                          $TypeMasks::ForceFieldObjectType));

      // If the player, item, deployable, whatever is covered then resume the loop.
      if (%PercentExposed == 0)
         continue;

      %Object.lastDamagedBy = %Owner;
      %Object.lastDamagedByTeam = %Owner.team;
      %DamagePercentage = (1.0 - ((%DistanceFromBlast * %DistanceFromBlast) / (%Radius * %Radius)));
      %DamagePercentage *= %PercentExposed;
      // If the player is shielded or underwater, then they can not be burned
      if (%Object.CheckforShields() > 0 || %Object.InWater == true)
      {
         if (%Object.InWater != true)
            %Object.getDatablock().damageObject(%Object, %Owner, "0 0 0", %DamageStrength * %DamagePercentage, $DamageType::Fire, "0 0 0");

      } else {
         %BurnStrength = %DamageStrength * %DamagePercentage;
         %BurnDuration = %DamageDuration * %DamagePercentage;
         %Object.Burn(%BurnDuration, %BurnStrength, %Owner);
      }
   }
}

function IncendiaryFire(%Position)
{
   %Item = new Explosion() 
   {
      dataBlock = IncendiaryGrenadeExplosion;
      position = %Position;
   };
   MissionCleanup.add(%Item);
}

function IncendiarySparks(%Position)
{
   %Item = new Explosion() 
   {
      dataBlock = IncendiarySparksExplosion;
      position = %Position;
   };
   MissionCleanup.add(%Item);
}

function UnderwaterIncendiary(%Position)
{
   %Item = new Explosion() 
   {
      dataBlock = UnderwaterHandGrenadeExplosion;
      position = %Position;
   };
   MissionCleanup.add(%Item);
}