function CreateEngineSmoke(%id)
{
   echo("CREATED ENGINE SMOKE");

   %id.hasenginesmoke = true;
   
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "6 12";
      layer = 2;
   };

   switch$ (%id.vehiclename)
   {
      case "dunebuggy":
         %offset = "0 .2";
      case "bike":
         %offset = "0 2.5";
      case "jeep":
         %offset = "0 1.8";
      case "compact":
         %offset = "0 1.6";
      case "minivan":
         %offset = "0 1.1";
      case "towtruck":
         %offset = "0 .6";
      case "van":
         %offset = "0 .8";
      case "limo":
         %offset = "0 .2";
      case "sedan":
         %offset = "0 1";
      case "sportscar":
         %offset = "0 1.4";
      case "pickuptruck":
         %offset = "0 .7";
      case "musclecar":
         %offset = "0 1";
      case "stationwagon":
         %offset = "0 1";
      case "humvee":
         %offset = "0 1";
      case "suv":
         %offset = "0 .8";
      case "flatbedtruck":
         %offset = "0 1.2";
      case "trailertruck":
         %offset = "0 1.2";
      case "fireengine":
         %offset = "0 0";
      case "garbagetruck":
         %offset = "0 .7";
      case "bus":
         %offset = "0 -.3";
      case "boxtruck":
         %offset = "0 .5";
      case "cargovan":
         %offset = "0 .6";
      case "ambulance":
         %offset = "0 .7";
      case "construction":
         %offset = "0 .3";
   }
   
   %sprite.mount(%id, %offset, 0, true, true, true, true);   
   %sprite.PlayAnimation(enginesmokingAnimation, true, 0, false);
   %id.smoke = %sprite;
}

function CreateEngineFire(%id)
{
   %id.hasenginefire = true;
   
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "4 4";
      layer = 2;
   };

   %sprite.mount(%id, "0 -.8", 0, true, true, true, true);   
   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
   
   %id.enginefiresprite = %sprite;
}

function CreateRightGunFire(%id)
{
   if(isObject(%id) $= false)
      return;

   if(Screen2D.getIsWindowPoint(%id.GetPosition()) $= false)   
      return;

   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "2.3 1";
   };
   
   %yarray[1] = "-.3";
   %yarray[2] = "-.4";
   %yarray[3] = "-.5";
   %yarray[4] = "-.6";
   %yarray[5] = ".3";
   %yarray[6] = ".4";
   %yarray[7] = ".5";
   %yarray[8] = ".6";

   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
   %sprite.mount(%id, "1" SPC %yarray[getRandom(1, 8)], 0, true, true, true, true);   
   schedule(500, 0, "DeleteSprite", %sprite);
}

function CreateLeftGunFire(%id)
{
   if(isObject(%id) $= false)
      return;

   if(Screen2D.getIsWindowPoint(%id.GetPosition()) $= false)   
      return;

   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "2.3 1";
   };

   %yarray[1] = "-.3";
   %yarray[2] = "-.4";
   %yarray[3] = "-.5";
   %yarray[4] = "-.6";
   %yarray[5] = ".3";
   %yarray[6] = ".4";
   %yarray[7] = ".5";
   %yarray[8] = ".6";
   
   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
   %sprite.mount(%id, "-1" SPC %yarray[getRandom(1, 8)], 0, true, true, true, true);   
   schedule(500, 0, "DeleteSprite", %sprite);
}

function CreateFrontGunFire(%id)
{
   if(isObject(%id) $= false)
      return;

   if(Screen2D.getIsWindowPoint(%id.GetPosition()) $= false)   
      return;      

   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "1.2 1.7";
   };

   switch$ (%id.vehiclename)
   {
      case "dunebuggy":
         %offset = "-.6";
      case "bike":
         %offset = "-.6";
      case "jeep":
         %offset = "-.6";
      case "compact":
         %offset = "-.6";
      case "minivan":
         %offset = "-.6";
      case "towtruck":
         %offset = "-.6";
      case "van":
         %offset = "-.6";
      case "limo":
         %offset = "-.5";
      case "sedan":
         %offset = "-.3";
      case "sportscar":
         %offset = "-.6";
      case "pickuptruck":
         %offset = "-.3";
      case "musclecar":
         %offset = "-.2";
      case "stationwagon":
         %offset = "-.3";
      case "humvee":
         %offset = "-.5";
      case "suv":
         %offset = "-.5";
      case "flatbedtruck":
         %offset = ".2";
      case "trailertruck":
         %offset = ".2";
      case "fireengine":
         %offset = "-.7";
      case "garbagetruck":
         %offset = "-.7";
      case "bus":
         %offset = "-.9";
      case "boxtruck":
         %offset = "-.7";
      case "cargovan":
         %offset = "-.6";
      case "ambulance":
         %offset = "-.7";
      case "construction":
         %offset = "-.5";
   }

   %xarray[1] = "-.1";
   %xarray[2] = "-.2";
   %xarray[3] = "-.3";
   %xarray[4] = ".1";
   %xarray[5] = ".2";
   %xarray[6] = ".3";

   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
   %sprite.mount(%id, %xarray[getRandom(1, 6)] SPC %offset, 0, true, true, true, true);   
   schedule(500, 0, "DeleteSprite", %sprite);
}

function CreateBackGunFire(%id)
{
   if(isObject(%id) $= false)
      return;

   if(Screen2D.getIsWindowPoint(%id.GetPosition()) $= false)   
      return;

   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "1.2 1.7";
   };

   switch$ (%id.vehiclename)
   {
      case "dunebuggy":
         %offset = ".6";
      case "bike":
         %offset = ".6";
      case "jeep":
         %offset = ".8";
      case "compact":
         %offset = ".6";
      case "minivan":
         %offset = "1";
      case "towtruck":
         %offset = ".9";
      case "van":
         %offset = "1";
      case "limo":
         %offset = ".5";
      case "sedan":
         %offset = ".6";
      case "sportscar":
         %offset = ".6";
      case "pickuptruck":
         %offset = ".5";
      case "musclecar":
         %offset = ".6";
      case "stationwagon":
         %offset = "1";
      case "humvee":
         %offset = ".5";
      case "suv":
         %offset = ".9";
      case "flatbedtruck":
         %offset = "1";
      case "trailertruck":
         %offset = "1";
      case "fireengine":
         %offset = "1";
      case "garbagetruck":
         %offset = ".9";
      case "bus":
         %offset = "1";
      case "boxtruck":
         %offset = "1";
      case "cargovan":
         %offset = "1";
      case "ambulance":
         %offset = "1";
      case "construction":
         %offset = "1";
   }

   %xarray[1] = "-.1";
   %xarray[2] = "-.2";
   %xarray[3] = "-.3";
   %xarray[4] = ".1";
   %xarray[5] = ".2";
   %xarray[6] = ".3";

   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
   %sprite.mount(%id, %xarray[getRandom(1, 6)] SPC %offset, 0, true, true, true, true);   
   schedule(500, 0, "DeleteSprite", %sprite);
}

// this is when a vehicle is hit by machine gun fire

function CreateVehicleHit(%targetid)
{
   if(isObject(%targetid) $= false)
      return;
      
   %pos = %targetid.GetPosition();
   
   %xarray[1] = "-.1";
   %xarray[2] = "-.2";
   %xarray[3] = "-.3";
   %xarray[4] = "-.4";
   %xarray[5] = "-.5";
   %xarray[6] = "-.6";
   %xarray[7] = "-.7";
   %xarray[8] = "-.8";
   %xarray[9] = ".1";
   %xarray[10] = ".2";
   %xarray[11] = ".3";
   %xarray[12] = ".4";
   %xarray[13] = ".5";
   %xarray[14] = ".6";
   %xarray[15] = ".7";
   %xarray[16] = ".8";

   %yarray[1] = "-.1";
   %yarray[2] = "-.2";
   %yarray[3] = "-.3";
   %yarray[4] = "-.4";
   %yarray[5] = "-.5";
   %yarray[6] = "-.6";
   %yarray[7] = "-.7";
   %yarray[8] = "-.8";
   %yarray[9] = ".1";
   %yarray[10] = ".2";
   %yarray[11] = ".3";
   %yarray[12] = ".4";
   %yarray[13] = ".5";
   %yarray[14] = ".6";
   %yarray[15] = ".7";
   %yarray[16] = ".8";
      
   if(Screen2D.getIsWindowPoint(%pos) $= true)   
   {
      %x = getRandom(1, 16);
      %y = getRandom(1, 16);      
   
      %sprite = new t2dAnimatedSprite()
      {
         scenegraph = "sg";  
         size = "1.6 1.6";
      };

      %sprite.mount(%targetid, %xarray[%x] SPC %yarray[%y], 0, true, true, true, true);   
      %sprite.PlayAnimation(BulletHitsAnimation, true, 0, false);
      
      schedule(300, 0, "DeleteSprite", %sprite);
   }
}

function CreateMountedWeaponHit(%targetid)
{
   if(isObject(%targetid) $= false)
      return;
      
   %pos = %targetid.GetPosition();
         
   if(Screen2D.getIsWindowPoint(%pos) $= true)   
   {
      %sprite = new t2dAnimatedSprite()
      {
         scenegraph = "sg";  
         size = "3 3";
      };

      %sprite.mount(%targetid, "0 0", 0, true, true, true, true);   
      %sprite.PlayAnimation(BulletHitsAnimation, true, 0, false);
      
      schedule(300, 0, "DeleteSprite", %sprite);
   }
}

function CreatePeopleHit(%targetid)
{
   if(isObject(%targetid) $= false)
      return;
      
   %pos = %targetid.GetPosition();
      
   if(Screen2D.getIsWindowPoint(%pos) $= true)   
   {
      %x = getRandom(1, 2);
      %y = getRandom(1, 6);      
   
      %sprite = new t2dAnimatedSprite()
      {
         scenegraph = "sg";  
         size = "12 12";
         layer = 5;
      };

      %sprite.mount(%targetid, "0 0", 0, true, true, true, true);   
      %sprite.PlayAnimation(BloodAnimation, true, 0, false);
      
      schedule(300, 0, "DeleteSprite", %sprite);
   }
}

function CreateTireHit(%targetid)
{
   if(isObject(%targetid) $= false)
      return;
      
   %pos = %targetid.GetPosition();
   
   %xarray[1] = "-.9";
   %xarray[2] = ".9";

   %yarray[1] = "-.6";
   %yarray[2] = "-.7";
   %yarray[3] = "-.8";
   %yarray[4] = ".6";
   %yarray[5] = ".7";
   %yarray[6] = ".8";
      
   if(Screen2D.getIsWindowPoint(%pos) $= true)   
   {
      %x = getRandom(1, 2);
      %y = getRandom(1, 6);      
   
      %sprite = new t2dAnimatedSprite()
      {
         scenegraph = "sg";  
         size = "10 10";
         layer = 5;
      };

      %sprite.mount(%targetid, %xarray[%x] SPC %yarray[%y], 0, true, true, true, true);   
      %sprite.PlayAnimation(tireblowoutAnimation, true, 0, false);
      
      schedule(300, 0, "DeleteSprite", %sprite);
   }
}

function CreateEngineHit(%targetid)
{
   if(isObject(%targetid) $= false)
      return;
      
   %pos = %targetid.GetPosition();
         
   if(Screen2D.getIsWindowPoint(%pos) $= true)   
   {
      %x = getRandom(1, 2);
      %y = getRandom(1, 6);      
   
      %sprite = new t2dAnimatedSprite()
      {
         scenegraph = "sg";  
         size = "7 7";
      };

      %sprite.mount(%targetid, "0 -.7", 0, true, true, true, true);   
      %sprite.PlayAnimation(RpgAnimation, true, 0, false);
      
      schedule(300, 0, "DeleteSprite", %sprite);
   }
}

function CreateDeathExplosion(%id)
{
   alxPlay(VehicleExplosion);
   
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "25 25";
   };
   
   %sprite.SetPosition(%id.GetPosition());
   %sprite.PlayAnimation(VehicleExplosionAnimation, true, 0, false);
   
   schedule(1000, 0, "DeleteSprite", %sprite);
   
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "12 12";
      layer = 1;
   };

   %sprite.SetPosition(%id.GetPosition());

   %sprite.PlayAnimation(smolderingfire1Animation, true, 0, false);
}

function CreateGasTankFire(%id)
{
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "8 12";
      layer = 4;
   };

   switch$ (%id.vehiclename)
   {
      case "dunebuggy":
         %offset = "0 -.5";
      case "bike":
         %offset = "0 -.5";
      case "jeep":
         %offset = "0 -.1";
      case "compact":
         %offset = "0 -.2";
      case "minivan":
         %offset = "0 .3";
      case "towtruck":
         %offset = "0 .6";
      case "van":
         %offset = "0 .8";
      case "limo":
         %offset = "0 .5";
      case "sedan":
         %offset = "0 .7";
      case "sportscar":
         %offset = "0 .4";
      case "pickuptruck":
         %offset = "0 .7";
      case "musclecar":
         %offset = "0 .8";
      case "stationwagon":
         %offset = "0 .8";
      case "humvee":
         %offset = "0 .7";
      case "suv":
         %offset = "0 .7";
      case "flatbedtruck":
         %offset = "0 3.3";
      case "trailertruck":
         %offset = "0 3.5";
      case "fireengine":
         %offset = "0 .7";
      case "garbagetruck":
         %offset = "0 .7";
      case "bus":
         %offset = "0 .9";
      case "boxtruck":
         %offset = "0 .7";
      case "cargovan":
         %offset = "0 .6";
      case "ambulance":
         %offset = "0 .7";
      case "construction":
         %offset = "0 .6";
   }
   
   %id.gastankfire = %sprite;   
   %sprite.mount(%id, %offset, 0, true, true, true, true);   
   %sprite.PlayAnimation(gastankfireAnimation, true, 0, false);
}

function CreateRpgMuzzle(%id)
{
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "3 6";
   };
   
   %sprite.mount(%id.special, "0 -1", 0, true, true, true, true);   
   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
   
   schedule(500, 0, "DeleteSprite", %sprite);   
}

function CreateRpgExplosion(%target)
{
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "10 10";
   };
   
   // make it variate a bit
   
   %x = getWord(%target.GetPosition(), 0);
   %y = getWord(%target.GetPosition(), 1);
   
   %x = %x + getRandom(-10, 10);
   %y = %y + getRandom(-10, 10);
         
   %sprite.PlayAnimation(rpgAnimation, true, 0, false);
   %sprite.SetPosition(%x SPC %y);

   schedule(1000, 0, "DeleteSprite", %sprite);   
}

function CreateMachineGunMuzzle(%id)
{
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "1.4 5";
   };
   
   %sprite.mount(%id.special, "0 -1", 0, true, true, true, true);   
   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
   
   schedule(500, 0, "DeleteSprite", %sprite);   
}

function CreateFlameThrower(%id)
{
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "11 40";
   };
   
   %sprite.PlayAnimation(flamethrowerAnimation, true, 0, false);
   %sprite.mount(%id.special, "0 -7", 0, true, true, true, true);   
   
   schedule(2000, 0, "DeleteSprite", %sprite);      
}

function CreatePlayerInfantryFire(%id)
{
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "1.8 2.3";
   };

   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
   %sprite.mount(%id, "0 -1", 0, true, true, true, true);   
   schedule(500, 0, "DeleteSprite", %sprite);
}

function CreateEnemyInfantryFire(%id)
{
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "1.8 2.3";
   };

   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
   %sprite.mount(%id, "0 1", 0, true, true, true, true);   
   schedule(500, 0, "DeleteSprite", %sprite);
}

// this will be mounted on a vehicle when the mounted weapon is destroyed

function CreateMountedWeaponFire(%id)
{
   %sprite = new t2dAnimatedSprite()
   {
      scenegraph = "sg";  
      size = "3 3";
      layer = 2;
   };

   %sprite.mount(%id, "0 0", 0, true, true, true, true);   
   %sprite.PlayAnimation(smolderingfire2Animation, true, 0, false);
}

function DeleteSprite(%id)
{
   if(isObject(%id) $= true)
      %id.SafeDelete();
}

function ReloadScript()
{
   pausetext.visible = false;
   exec("./particles.cs");   
}